Skip to content

Instantly share code, notes, and snippets.

@locona
Last active May 10, 2017 03:50
Show Gist options
  • Save locona/4d586bf437a0c8ac5c095cfc7cccccbe to your computer and use it in GitHub Desktop.
Save locona/4d586bf437a0c8ac5c095cfc7cccccbe to your computer and use it in GitHub Desktop.
Gin読書会

Gin 読書会

Context

  • writermem: responseWriter
  • Request: *http.Request
  • Writer: ResponseWriter
  • Params: Params
  • handlers: HandlersChain
  • index: int8
  • engine: *Engine
  • Keys

Gin 読書会

Engine

  • RouterGroup -> routegroup.md
  • HTMLRender: render.HTMLRender
  • allNoRoute: HandlersChain
  • allNoMethod: HandlersChain
  • noRoute: HandlersChain
  • noMethod: HandlersChain
  • pool: sync.Pool
  • trees: methodTrees
  • RedirectTrailingSlash: bool
  • RedirectFixedPath: bool: /FOO, //FOO -> /foo というようにいい感じに直してくれる
  • HandleMethodNotAllowed: bool
  • ForwardedByClinetIP: bool

New() *Engine

  • RedirectTrailingSlash: true
  • RedirectFixedPath: false
  • HandleMethodNotAllowed: false
  • ForwardedByClientIP: true

Default() *Engine

New をベースとして以下2つのmiddlewareをUseしている

  • Logger()
  • Recovery()

(engine *Engine) Use(middleware ...HandlerFunc) IRoutes {

  • routergroup のUseを使用.このメソッドでは、middlewareを渡しているだけ.
  • 404, 405Handlers の追加

Gin 読書会

RouterGroup

  • Handlers: HandlersChain
  • basePath: string
  • engine: *Engine
  • root: bool

IRouter

  • IRoutes
  • Group(string, ...HandlerFunc) *RouterGroup

IRoutes

  • Use
  • Handle
  • Any
  • GET
  • POST
  • DELETE
  • PATCH
  • PUT
  • OPTIONS
  • HEAD
  • StaticFile
  • Static
  • StaticFS

(group *RouterGroup) Use(middleware ...HandlerFunc) IRoutes

group.Handlers = append(group.Handlers, middleware...)
return group.returnObj()

}

Gin 読書会

methodTree

  • method: string
  • root: node

methodTrees

[]methodTree

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment