[Gin] 传统 for 循环中的语义通用化,在 golang 中使用分号 ; 替代 && 流程控制

通过llama.cpp与羊驼聊天的网页界面- 详解 Serge 的启动使用

 

// gin.go

// HandlerFunc defines the handler used by gin middleware as return value.
type HandlerFunc func(*Context)

// HandlersChain defines a HandlerFunc array.
type HandlersChain []HandlerFunc

// Last returns the last handler in the chain. ie. the last handler is the main one.
func (c HandlersChain) Last() HandlerFunc {
  // 注意这里未使用 && 而是用的分号 ; 将传统 for 循环中的相似语义给通用化了
if length := len(c); length > 0 { return c[length-1] } return nil }

 

Refer:Golang语义

Link:https://www.cnblogs.com/farwish/p/12703925.html

posted on 2020-04-15 11:06  ercom  阅读(488)  评论(0编辑  收藏  举报