separate type define (#975)

This commit is contained in:
田欧 2017-07-05 15:47:36 +08:00 committed by Bo-Yi Wu
parent 22fc0284e3
commit d535fcd598
6 changed files with 125 additions and 133 deletions

10
auth.go
View File

@ -13,15 +13,15 @@ import (
// AuthUserKey is the cookie name for user credential in basic auth // AuthUserKey is the cookie name for user credential in basic auth
const AuthUserKey = "user" const AuthUserKey = "user"
type (
// Accounts defines a key/value for user/pass list of authorized logins // Accounts defines a key/value for user/pass list of authorized logins
Accounts map[string]string type Accounts map[string]string
authPair struct {
type authPair struct {
Value string Value string
User string User string
} }
authPairs []authPair
) type authPairs []authPair
func (a authPairs) searchCredential(authValue string) (string, bool) { func (a authPairs) searchCredential(authValue string) (string, bool) {
if len(authValue) == 0 { if len(authValue) == 0 {

View File

@ -23,15 +23,13 @@ const (
ErrorTypeNu = 2 ErrorTypeNu = 2
) )
type ( type Error struct {
Error struct {
Err error Err error
Type ErrorType Type ErrorType
Meta interface{} Meta interface{}
} }
errorMsgs []*Error type errorMsgs []*Error
)
var _ error = &Error{} var _ error = &Error{}

7
fs.go
View File

@ -9,14 +9,13 @@ import (
"os" "os"
) )
type ( type onlyfilesFS struct {
onlyfilesFS struct {
fs http.FileSystem fs http.FileSystem
} }
neuteredReaddirFile struct {
type neuteredReaddirFile struct {
http.File http.File
} }
)
// Dir returns a http.Filesystem that can be used by http.FileServer(). It is used internally // Dir returns a http.Filesystem that can be used by http.FileServer(). It is used internally
// in router.Static(). // in router.Static().

9
gin.go
View File

@ -33,17 +33,17 @@ func (c HandlersChain) Last() HandlerFunc {
return nil return nil
} }
type ( type RouteInfo struct {
RoutesInfo []RouteInfo
RouteInfo struct {
Method string Method string
Path string Path string
Handler string Handler string
} }
type RoutesInfo []RouteInfo
// Engine is the framework's instance, it contains the muxer, middleware and configuration settings. // Engine is the framework's instance, it contains the muxer, middleware and configuration settings.
// Create an instance of Engine, by using New() or Default() // Create an instance of Engine, by using New() or Default()
Engine struct { type Engine struct {
RouterGroup RouterGroup
delims render.Delims delims render.Delims
HTMLRender render.HTMLRender HTMLRender render.HTMLRender
@ -93,7 +93,6 @@ type (
// as url.Path gonna be used, which is already unescaped. // as url.Path gonna be used, which is already unescaped.
UnescapePathValues bool UnescapePathValues bool
} }
)
var _ IRouter = &Engine{} var _ IRouter = &Engine{}

View File

@ -16,8 +16,7 @@ const (
defaultStatus = 200 defaultStatus = 200
) )
type ( type ResponseWriter interface {
ResponseWriter interface {
http.ResponseWriter http.ResponseWriter
http.Hijacker http.Hijacker
http.Flusher http.Flusher
@ -40,12 +39,11 @@ type (
WriteHeaderNow() WriteHeaderNow()
} }
responseWriter struct { type responseWriter struct {
http.ResponseWriter http.ResponseWriter
size int size int
status int status int
} }
)
var _ ResponseWriter = &responseWriter{} var _ ResponseWriter = &responseWriter{}

View File

@ -11,13 +11,12 @@ import (
"strings" "strings"
) )
type ( type IRouter interface {
IRouter interface {
IRoutes IRoutes
Group(string, ...HandlerFunc) *RouterGroup Group(string, ...HandlerFunc) *RouterGroup
} }
IRoutes interface { type IRoutes interface {
Use(...HandlerFunc) IRoutes Use(...HandlerFunc) IRoutes
Handle(string, string, ...HandlerFunc) IRoutes Handle(string, string, ...HandlerFunc) IRoutes
@ -37,13 +36,12 @@ type (
// RouterGroup is used internally to configure router, a RouterGroup is associated with a prefix // RouterGroup is used internally to configure router, a RouterGroup is associated with a prefix
// and an array of handlers (middleware) // and an array of handlers (middleware)
RouterGroup struct { type RouterGroup struct {
Handlers HandlersChain Handlers HandlersChain
basePath string basePath string
engine *Engine engine *Engine
root bool root bool
} }
)
var _ IRouter = &RouterGroup{} var _ IRouter = &RouterGroup{}