id
int32 0
167k
| repo
stringlengths 5
54
| path
stringlengths 4
155
| func_name
stringlengths 1
118
| original_string
stringlengths 52
85.5k
| language
stringclasses 1
value | code
stringlengths 52
85.5k
| code_tokens
listlengths 21
1.41k
| docstring
stringlengths 6
2.61k
| docstring_tokens
listlengths 3
215
| sha
stringlengths 40
40
| url
stringlengths 85
252
|
---|---|---|---|---|---|---|---|---|---|---|---|
8,800 | lunny/tango | logger.go | Debugf | func (l *CompositeLogger) Debugf(format string, v ...interface{}) {
for _, log := range l.loggers {
log.Debugf(format, v...)
}
} | go | func (l *CompositeLogger) Debugf(format string, v ...interface{}) {
for _, log := range l.loggers {
log.Debugf(format, v...)
}
} | [
"func",
"(",
"l",
"*",
"CompositeLogger",
")",
"Debugf",
"(",
"format",
"string",
",",
"v",
"...",
"interface",
"{",
"}",
")",
"{",
"for",
"_",
",",
"log",
":=",
"range",
"l",
".",
"loggers",
"{",
"log",
".",
"Debugf",
"(",
"format",
",",
"v",
"...",
")",
"\n",
"}",
"\n",
"}"
]
| // Debugf implementes Logger interface | [
"Debugf",
"implementes",
"Logger",
"interface"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/logger.go#L37-L41 |
8,801 | lunny/tango | logger.go | Debug | func (l *CompositeLogger) Debug(v ...interface{}) {
for _, log := range l.loggers {
log.Debug(v...)
}
} | go | func (l *CompositeLogger) Debug(v ...interface{}) {
for _, log := range l.loggers {
log.Debug(v...)
}
} | [
"func",
"(",
"l",
"*",
"CompositeLogger",
")",
"Debug",
"(",
"v",
"...",
"interface",
"{",
"}",
")",
"{",
"for",
"_",
",",
"log",
":=",
"range",
"l",
".",
"loggers",
"{",
"log",
".",
"Debug",
"(",
"v",
"...",
")",
"\n",
"}",
"\n",
"}"
]
| // Debug implementes Logger interface | [
"Debug",
"implementes",
"Logger",
"interface"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/logger.go#L44-L48 |
8,802 | lunny/tango | logger.go | Info | func (l *CompositeLogger) Info(v ...interface{}) {
for _, log := range l.loggers {
log.Info(v...)
}
} | go | func (l *CompositeLogger) Info(v ...interface{}) {
for _, log := range l.loggers {
log.Info(v...)
}
} | [
"func",
"(",
"l",
"*",
"CompositeLogger",
")",
"Info",
"(",
"v",
"...",
"interface",
"{",
"}",
")",
"{",
"for",
"_",
",",
"log",
":=",
"range",
"l",
".",
"loggers",
"{",
"log",
".",
"Info",
"(",
"v",
"...",
")",
"\n",
"}",
"\n",
"}"
]
| // Info implementes Logger interface | [
"Info",
"implementes",
"Logger",
"interface"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/logger.go#L58-L62 |
8,803 | lunny/tango | logger.go | Warn | func (l *CompositeLogger) Warn(v ...interface{}) {
for _, log := range l.loggers {
log.Warn(v...)
}
} | go | func (l *CompositeLogger) Warn(v ...interface{}) {
for _, log := range l.loggers {
log.Warn(v...)
}
} | [
"func",
"(",
"l",
"*",
"CompositeLogger",
")",
"Warn",
"(",
"v",
"...",
"interface",
"{",
"}",
")",
"{",
"for",
"_",
",",
"log",
":=",
"range",
"l",
".",
"loggers",
"{",
"log",
".",
"Warn",
"(",
"v",
"...",
")",
"\n",
"}",
"\n",
"}"
]
| // Warn implementes Logger interface | [
"Warn",
"implementes",
"Logger",
"interface"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/logger.go#L72-L76 |
8,804 | lunny/tango | logger.go | Error | func (l *CompositeLogger) Error(v ...interface{}) {
for _, log := range l.loggers {
log.Error(v...)
}
} | go | func (l *CompositeLogger) Error(v ...interface{}) {
for _, log := range l.loggers {
log.Error(v...)
}
} | [
"func",
"(",
"l",
"*",
"CompositeLogger",
")",
"Error",
"(",
"v",
"...",
"interface",
"{",
"}",
")",
"{",
"for",
"_",
",",
"log",
":=",
"range",
"l",
".",
"loggers",
"{",
"log",
".",
"Error",
"(",
"v",
"...",
")",
"\n",
"}",
"\n",
"}"
]
| // Error implementes Logger interface | [
"Error",
"implementes",
"Logger",
"interface"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/logger.go#L86-L90 |
8,805 | lunny/tango | logger.go | NewLogger | func NewLogger(out io.Writer) Logger {
l := log.New(out, "[tango] ", log.Ldefault())
l.SetOutputLevel(log.Ldebug)
return l
} | go | func NewLogger(out io.Writer) Logger {
l := log.New(out, "[tango] ", log.Ldefault())
l.SetOutputLevel(log.Ldebug)
return l
} | [
"func",
"NewLogger",
"(",
"out",
"io",
".",
"Writer",
")",
"Logger",
"{",
"l",
":=",
"log",
".",
"New",
"(",
"out",
",",
"\"",
"\"",
",",
"log",
".",
"Ldefault",
"(",
")",
")",
"\n",
"l",
".",
"SetOutputLevel",
"(",
"log",
".",
"Ldebug",
")",
"\n",
"return",
"l",
"\n",
"}"
]
| // NewLogger use the default logger with special writer | [
"NewLogger",
"use",
"the",
"default",
"logger",
"with",
"special",
"writer"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/logger.go#L93-L97 |
8,806 | lunny/tango | logger.go | Logging | func Logging() HandlerFunc {
return func(ctx *Context) {
start := time.Now()
p := ctx.Req().URL.Path
if len(ctx.Req().URL.RawQuery) > 0 {
p = p + "?" + ctx.Req().URL.RawQuery
}
ctx.Debug("Started", ctx.Req().Method, p, "for", ctx.IP())
if action := ctx.Action(); action != nil {
if l, ok := action.(LogInterface); ok {
l.SetLogger(ctx.Logger)
}
}
ctx.Next()
if !ctx.Written() {
if ctx.Result == nil {
ctx.Result = NotFound()
}
ctx.HandleError()
}
statusCode := ctx.Status()
if statusCode >= 200 && statusCode < 400 {
ctx.Info(ctx.Req().Method, statusCode, time.Since(start), p)
} else {
ctx.Error(ctx.Req().Method, statusCode, time.Since(start), p, ctx.Result)
}
}
} | go | func Logging() HandlerFunc {
return func(ctx *Context) {
start := time.Now()
p := ctx.Req().URL.Path
if len(ctx.Req().URL.RawQuery) > 0 {
p = p + "?" + ctx.Req().URL.RawQuery
}
ctx.Debug("Started", ctx.Req().Method, p, "for", ctx.IP())
if action := ctx.Action(); action != nil {
if l, ok := action.(LogInterface); ok {
l.SetLogger(ctx.Logger)
}
}
ctx.Next()
if !ctx.Written() {
if ctx.Result == nil {
ctx.Result = NotFound()
}
ctx.HandleError()
}
statusCode := ctx.Status()
if statusCode >= 200 && statusCode < 400 {
ctx.Info(ctx.Req().Method, statusCode, time.Since(start), p)
} else {
ctx.Error(ctx.Req().Method, statusCode, time.Since(start), p, ctx.Result)
}
}
} | [
"func",
"Logging",
"(",
")",
"HandlerFunc",
"{",
"return",
"func",
"(",
"ctx",
"*",
"Context",
")",
"{",
"start",
":=",
"time",
".",
"Now",
"(",
")",
"\n",
"p",
":=",
"ctx",
".",
"Req",
"(",
")",
".",
"URL",
".",
"Path",
"\n",
"if",
"len",
"(",
"ctx",
".",
"Req",
"(",
")",
".",
"URL",
".",
"RawQuery",
")",
">",
"0",
"{",
"p",
"=",
"p",
"+",
"\"",
"\"",
"+",
"ctx",
".",
"Req",
"(",
")",
".",
"URL",
".",
"RawQuery",
"\n",
"}",
"\n\n",
"ctx",
".",
"Debug",
"(",
"\"",
"\"",
",",
"ctx",
".",
"Req",
"(",
")",
".",
"Method",
",",
"p",
",",
"\"",
"\"",
",",
"ctx",
".",
"IP",
"(",
")",
")",
"\n\n",
"if",
"action",
":=",
"ctx",
".",
"Action",
"(",
")",
";",
"action",
"!=",
"nil",
"{",
"if",
"l",
",",
"ok",
":=",
"action",
".",
"(",
"LogInterface",
")",
";",
"ok",
"{",
"l",
".",
"SetLogger",
"(",
"ctx",
".",
"Logger",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"ctx",
".",
"Next",
"(",
")",
"\n\n",
"if",
"!",
"ctx",
".",
"Written",
"(",
")",
"{",
"if",
"ctx",
".",
"Result",
"==",
"nil",
"{",
"ctx",
".",
"Result",
"=",
"NotFound",
"(",
")",
"\n",
"}",
"\n",
"ctx",
".",
"HandleError",
"(",
")",
"\n",
"}",
"\n\n",
"statusCode",
":=",
"ctx",
".",
"Status",
"(",
")",
"\n\n",
"if",
"statusCode",
">=",
"200",
"&&",
"statusCode",
"<",
"400",
"{",
"ctx",
".",
"Info",
"(",
"ctx",
".",
"Req",
"(",
")",
".",
"Method",
",",
"statusCode",
",",
"time",
".",
"Since",
"(",
"start",
")",
",",
"p",
")",
"\n",
"}",
"else",
"{",
"ctx",
".",
"Error",
"(",
"ctx",
".",
"Req",
"(",
")",
".",
"Method",
",",
"statusCode",
",",
"time",
".",
"Since",
"(",
"start",
")",
",",
"p",
",",
"ctx",
".",
"Result",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}"
]
| // Logging returns handler to log informations | [
"Logging",
"returns",
"handler",
"to",
"log",
"informations"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/logger.go#L115-L148 |
8,807 | lunny/tango | query.go | Values | func (f *Queries) Values() url.Values {
return (*http.Request)(f).URL.Query()
} | go | func (f *Queries) Values() url.Values {
return (*http.Request)(f).URL.Query()
} | [
"func",
"(",
"f",
"*",
"Queries",
")",
"Values",
"(",
")",
"url",
".",
"Values",
"{",
"return",
"(",
"*",
"http",
".",
"Request",
")",
"(",
"f",
")",
".",
"URL",
".",
"Query",
"(",
")",
"\n",
"}"
]
| // Values returns http.Request values | [
"Values",
"returns",
"http",
".",
"Request",
"values"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/query.go#L20-L22 |
8,808 | lunny/tango | query.go | Query | func (ctx *Context) Query(key string, defaults ...string) string {
return (*Queries)(ctx.req).MustString(key, defaults...)
} | go | func (ctx *Context) Query(key string, defaults ...string) string {
return (*Queries)(ctx.req).MustString(key, defaults...)
} | [
"func",
"(",
"ctx",
"*",
"Context",
")",
"Query",
"(",
"key",
"string",
",",
"defaults",
"...",
"string",
")",
"string",
"{",
"return",
"(",
"*",
"Queries",
")",
"(",
"ctx",
".",
"req",
")",
".",
"MustString",
"(",
"key",
",",
"defaults",
"...",
")",
"\n",
"}"
]
| // Query returns request form as string with default | [
"Query",
"returns",
"request",
"form",
"as",
"string",
"with",
"default"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/query.go#L296-L298 |
8,809 | lunny/tango | query.go | QueryStrings | func (ctx *Context) QueryStrings(key string, defaults ...[]string) []string {
return (*Queries)(ctx.req).MustStrings(key, defaults...)
} | go | func (ctx *Context) QueryStrings(key string, defaults ...[]string) []string {
return (*Queries)(ctx.req).MustStrings(key, defaults...)
} | [
"func",
"(",
"ctx",
"*",
"Context",
")",
"QueryStrings",
"(",
"key",
"string",
",",
"defaults",
"...",
"[",
"]",
"string",
")",
"[",
"]",
"string",
"{",
"return",
"(",
"*",
"Queries",
")",
"(",
"ctx",
".",
"req",
")",
".",
"MustStrings",
"(",
"key",
",",
"defaults",
"...",
")",
"\n",
"}"
]
| // QueryStrings returns request form as strings with default | [
"QueryStrings",
"returns",
"request",
"form",
"as",
"strings",
"with",
"default"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/query.go#L301-L303 |
8,810 | lunny/tango | query.go | QueryEscape | func (ctx *Context) QueryEscape(key string, defaults ...string) string {
return (*Queries)(ctx.req).MustEscape(key, defaults...)
} | go | func (ctx *Context) QueryEscape(key string, defaults ...string) string {
return (*Queries)(ctx.req).MustEscape(key, defaults...)
} | [
"func",
"(",
"ctx",
"*",
"Context",
")",
"QueryEscape",
"(",
"key",
"string",
",",
"defaults",
"...",
"string",
")",
"string",
"{",
"return",
"(",
"*",
"Queries",
")",
"(",
"ctx",
".",
"req",
")",
".",
"MustEscape",
"(",
"key",
",",
"defaults",
"...",
")",
"\n",
"}"
]
| // QueryEscape returns request form as escaped string with default | [
"QueryEscape",
"returns",
"request",
"form",
"as",
"escaped",
"string",
"with",
"default"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/query.go#L306-L308 |
8,811 | lunny/tango | query.go | QueryInt | func (ctx *Context) QueryInt(key string, defaults ...int) int {
return (*Queries)(ctx.req).MustInt(key, defaults...)
} | go | func (ctx *Context) QueryInt(key string, defaults ...int) int {
return (*Queries)(ctx.req).MustInt(key, defaults...)
} | [
"func",
"(",
"ctx",
"*",
"Context",
")",
"QueryInt",
"(",
"key",
"string",
",",
"defaults",
"...",
"int",
")",
"int",
"{",
"return",
"(",
"*",
"Queries",
")",
"(",
"ctx",
".",
"req",
")",
".",
"MustInt",
"(",
"key",
",",
"defaults",
"...",
")",
"\n",
"}"
]
| // QueryInt returns request form as int with default | [
"QueryInt",
"returns",
"request",
"form",
"as",
"int",
"with",
"default"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/query.go#L311-L313 |
8,812 | lunny/tango | query.go | QueryInt32 | func (ctx *Context) QueryInt32(key string, defaults ...int32) int32 {
return (*Queries)(ctx.req).MustInt32(key, defaults...)
} | go | func (ctx *Context) QueryInt32(key string, defaults ...int32) int32 {
return (*Queries)(ctx.req).MustInt32(key, defaults...)
} | [
"func",
"(",
"ctx",
"*",
"Context",
")",
"QueryInt32",
"(",
"key",
"string",
",",
"defaults",
"...",
"int32",
")",
"int32",
"{",
"return",
"(",
"*",
"Queries",
")",
"(",
"ctx",
".",
"req",
")",
".",
"MustInt32",
"(",
"key",
",",
"defaults",
"...",
")",
"\n",
"}"
]
| // QueryInt32 returns request form as int32 with default | [
"QueryInt32",
"returns",
"request",
"form",
"as",
"int32",
"with",
"default"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/query.go#L316-L318 |
8,813 | lunny/tango | query.go | QueryInt64 | func (ctx *Context) QueryInt64(key string, defaults ...int64) int64 {
return (*Queries)(ctx.req).MustInt64(key, defaults...)
} | go | func (ctx *Context) QueryInt64(key string, defaults ...int64) int64 {
return (*Queries)(ctx.req).MustInt64(key, defaults...)
} | [
"func",
"(",
"ctx",
"*",
"Context",
")",
"QueryInt64",
"(",
"key",
"string",
",",
"defaults",
"...",
"int64",
")",
"int64",
"{",
"return",
"(",
"*",
"Queries",
")",
"(",
"ctx",
".",
"req",
")",
".",
"MustInt64",
"(",
"key",
",",
"defaults",
"...",
")",
"\n",
"}"
]
| // QueryInt64 returns request form as int64 with default | [
"QueryInt64",
"returns",
"request",
"form",
"as",
"int64",
"with",
"default"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/query.go#L321-L323 |
8,814 | lunny/tango | query.go | QueryUint | func (ctx *Context) QueryUint(key string, defaults ...uint) uint {
return (*Queries)(ctx.req).MustUint(key, defaults...)
} | go | func (ctx *Context) QueryUint(key string, defaults ...uint) uint {
return (*Queries)(ctx.req).MustUint(key, defaults...)
} | [
"func",
"(",
"ctx",
"*",
"Context",
")",
"QueryUint",
"(",
"key",
"string",
",",
"defaults",
"...",
"uint",
")",
"uint",
"{",
"return",
"(",
"*",
"Queries",
")",
"(",
"ctx",
".",
"req",
")",
".",
"MustUint",
"(",
"key",
",",
"defaults",
"...",
")",
"\n",
"}"
]
| // QueryUint returns request form as uint with default | [
"QueryUint",
"returns",
"request",
"form",
"as",
"uint",
"with",
"default"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/query.go#L326-L328 |
8,815 | lunny/tango | query.go | QueryUint32 | func (ctx *Context) QueryUint32(key string, defaults ...uint32) uint32 {
return (*Queries)(ctx.req).MustUint32(key, defaults...)
} | go | func (ctx *Context) QueryUint32(key string, defaults ...uint32) uint32 {
return (*Queries)(ctx.req).MustUint32(key, defaults...)
} | [
"func",
"(",
"ctx",
"*",
"Context",
")",
"QueryUint32",
"(",
"key",
"string",
",",
"defaults",
"...",
"uint32",
")",
"uint32",
"{",
"return",
"(",
"*",
"Queries",
")",
"(",
"ctx",
".",
"req",
")",
".",
"MustUint32",
"(",
"key",
",",
"defaults",
"...",
")",
"\n",
"}"
]
| // QueryUint32 returns request form as uint32 with default | [
"QueryUint32",
"returns",
"request",
"form",
"as",
"uint32",
"with",
"default"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/query.go#L331-L333 |
8,816 | lunny/tango | query.go | QueryUint64 | func (ctx *Context) QueryUint64(key string, defaults ...uint64) uint64 {
return (*Queries)(ctx.req).MustUint64(key, defaults...)
} | go | func (ctx *Context) QueryUint64(key string, defaults ...uint64) uint64 {
return (*Queries)(ctx.req).MustUint64(key, defaults...)
} | [
"func",
"(",
"ctx",
"*",
"Context",
")",
"QueryUint64",
"(",
"key",
"string",
",",
"defaults",
"...",
"uint64",
")",
"uint64",
"{",
"return",
"(",
"*",
"Queries",
")",
"(",
"ctx",
".",
"req",
")",
".",
"MustUint64",
"(",
"key",
",",
"defaults",
"...",
")",
"\n",
"}"
]
| // QueryUint64 returns request form as uint64 with default | [
"QueryUint64",
"returns",
"request",
"form",
"as",
"uint64",
"with",
"default"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/query.go#L336-L338 |
8,817 | lunny/tango | query.go | QueryFloat32 | func (ctx *Context) QueryFloat32(key string, defaults ...float32) float32 {
return (*Queries)(ctx.req).MustFloat32(key, defaults...)
} | go | func (ctx *Context) QueryFloat32(key string, defaults ...float32) float32 {
return (*Queries)(ctx.req).MustFloat32(key, defaults...)
} | [
"func",
"(",
"ctx",
"*",
"Context",
")",
"QueryFloat32",
"(",
"key",
"string",
",",
"defaults",
"...",
"float32",
")",
"float32",
"{",
"return",
"(",
"*",
"Queries",
")",
"(",
"ctx",
".",
"req",
")",
".",
"MustFloat32",
"(",
"key",
",",
"defaults",
"...",
")",
"\n",
"}"
]
| // QueryFloat32 returns request form as float32 with default | [
"QueryFloat32",
"returns",
"request",
"form",
"as",
"float32",
"with",
"default"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/query.go#L341-L343 |
8,818 | lunny/tango | tan.go | Get | func (t *Tango) Get(url string, c interface{}, middlewares ...Handler) {
t.Route([]string{"GET", "HEAD:Get"}, url, c, middlewares...)
} | go | func (t *Tango) Get(url string, c interface{}, middlewares ...Handler) {
t.Route([]string{"GET", "HEAD:Get"}, url, c, middlewares...)
} | [
"func",
"(",
"t",
"*",
"Tango",
")",
"Get",
"(",
"url",
"string",
",",
"c",
"interface",
"{",
"}",
",",
"middlewares",
"...",
"Handler",
")",
"{",
"t",
".",
"Route",
"(",
"[",
"]",
"string",
"{",
"\"",
"\"",
",",
"\"",
"\"",
"}",
",",
"url",
",",
"c",
",",
"middlewares",
"...",
")",
"\n",
"}"
]
| // Get sets a route with GET method | [
"Get",
"sets",
"a",
"route",
"with",
"GET",
"method"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/tan.go#L50-L52 |
8,819 | lunny/tango | tan.go | Any | func (t *Tango) Any(url string, c interface{}, middlewares ...Handler) {
t.Route(SupportMethods, url, c, middlewares...)
t.Route([]string{"HEAD:Get"}, url, c, middlewares...)
} | go | func (t *Tango) Any(url string, c interface{}, middlewares ...Handler) {
t.Route(SupportMethods, url, c, middlewares...)
t.Route([]string{"HEAD:Get"}, url, c, middlewares...)
} | [
"func",
"(",
"t",
"*",
"Tango",
")",
"Any",
"(",
"url",
"string",
",",
"c",
"interface",
"{",
"}",
",",
"middlewares",
"...",
"Handler",
")",
"{",
"t",
".",
"Route",
"(",
"SupportMethods",
",",
"url",
",",
"c",
",",
"middlewares",
"...",
")",
"\n",
"t",
".",
"Route",
"(",
"[",
"]",
"string",
"{",
"\"",
"\"",
"}",
",",
"url",
",",
"c",
",",
"middlewares",
"...",
")",
"\n",
"}"
]
| // Any sets a route every support method is OK. | [
"Any",
"sets",
"a",
"route",
"every",
"support",
"method",
"is",
"OK",
"."
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/tan.go#L90-L93 |
8,820 | lunny/tango | tan.go | Use | func (t *Tango) Use(handlers ...Handler) {
t.handlers = append(t.handlers, handlers...)
} | go | func (t *Tango) Use(handlers ...Handler) {
t.handlers = append(t.handlers, handlers...)
} | [
"func",
"(",
"t",
"*",
"Tango",
")",
"Use",
"(",
"handlers",
"...",
"Handler",
")",
"{",
"t",
".",
"handlers",
"=",
"append",
"(",
"t",
".",
"handlers",
",",
"handlers",
"...",
")",
"\n",
"}"
]
| // Use addes some global handlers | [
"Use",
"addes",
"some",
"global",
"handlers"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/tan.go#L96-L98 |
8,821 | lunny/tango | tan.go | getAddress | func getAddress(args ...interface{}) string {
var host string
var port int
if len(args) == 1 {
switch arg := args[0].(type) {
case string:
addrs := strings.Split(args[0].(string), ":")
if len(addrs) == 1 {
host = addrs[0]
} else if len(addrs) >= 2 {
host = addrs[0]
_port, _ := strconv.ParseInt(addrs[1], 10, 0)
port = int(_port)
}
case int:
port = arg
}
} else if len(args) >= 2 {
if arg, ok := args[0].(string); ok {
host = arg
}
if arg, ok := args[1].(int); ok {
port = arg
}
}
if envHost := os.Getenv("HOST"); len(envHost) != 0 {
host = envHost
} else if len(host) == 0 {
host = "0.0.0.0"
}
if envPort, _ := strconv.ParseInt(os.Getenv("PORT"), 10, 32); envPort != 0 {
port = int(envPort)
} else if port == 0 {
port = 8000
}
addr := host + ":" + strconv.FormatInt(int64(port), 10)
return addr
} | go | func getAddress(args ...interface{}) string {
var host string
var port int
if len(args) == 1 {
switch arg := args[0].(type) {
case string:
addrs := strings.Split(args[0].(string), ":")
if len(addrs) == 1 {
host = addrs[0]
} else if len(addrs) >= 2 {
host = addrs[0]
_port, _ := strconv.ParseInt(addrs[1], 10, 0)
port = int(_port)
}
case int:
port = arg
}
} else if len(args) >= 2 {
if arg, ok := args[0].(string); ok {
host = arg
}
if arg, ok := args[1].(int); ok {
port = arg
}
}
if envHost := os.Getenv("HOST"); len(envHost) != 0 {
host = envHost
} else if len(host) == 0 {
host = "0.0.0.0"
}
if envPort, _ := strconv.ParseInt(os.Getenv("PORT"), 10, 32); envPort != 0 {
port = int(envPort)
} else if port == 0 {
port = 8000
}
addr := host + ":" + strconv.FormatInt(int64(port), 10)
return addr
} | [
"func",
"getAddress",
"(",
"args",
"...",
"interface",
"{",
"}",
")",
"string",
"{",
"var",
"host",
"string",
"\n",
"var",
"port",
"int",
"\n\n",
"if",
"len",
"(",
"args",
")",
"==",
"1",
"{",
"switch",
"arg",
":=",
"args",
"[",
"0",
"]",
".",
"(",
"type",
")",
"{",
"case",
"string",
":",
"addrs",
":=",
"strings",
".",
"Split",
"(",
"args",
"[",
"0",
"]",
".",
"(",
"string",
")",
",",
"\"",
"\"",
")",
"\n",
"if",
"len",
"(",
"addrs",
")",
"==",
"1",
"{",
"host",
"=",
"addrs",
"[",
"0",
"]",
"\n",
"}",
"else",
"if",
"len",
"(",
"addrs",
")",
">=",
"2",
"{",
"host",
"=",
"addrs",
"[",
"0",
"]",
"\n",
"_port",
",",
"_",
":=",
"strconv",
".",
"ParseInt",
"(",
"addrs",
"[",
"1",
"]",
",",
"10",
",",
"0",
")",
"\n",
"port",
"=",
"int",
"(",
"_port",
")",
"\n",
"}",
"\n",
"case",
"int",
":",
"port",
"=",
"arg",
"\n",
"}",
"\n",
"}",
"else",
"if",
"len",
"(",
"args",
")",
">=",
"2",
"{",
"if",
"arg",
",",
"ok",
":=",
"args",
"[",
"0",
"]",
".",
"(",
"string",
")",
";",
"ok",
"{",
"host",
"=",
"arg",
"\n",
"}",
"\n",
"if",
"arg",
",",
"ok",
":=",
"args",
"[",
"1",
"]",
".",
"(",
"int",
")",
";",
"ok",
"{",
"port",
"=",
"arg",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"envHost",
":=",
"os",
".",
"Getenv",
"(",
"\"",
"\"",
")",
";",
"len",
"(",
"envHost",
")",
"!=",
"0",
"{",
"host",
"=",
"envHost",
"\n",
"}",
"else",
"if",
"len",
"(",
"host",
")",
"==",
"0",
"{",
"host",
"=",
"\"",
"\"",
"\n",
"}",
"\n\n",
"if",
"envPort",
",",
"_",
":=",
"strconv",
".",
"ParseInt",
"(",
"os",
".",
"Getenv",
"(",
"\"",
"\"",
")",
",",
"10",
",",
"32",
")",
";",
"envPort",
"!=",
"0",
"{",
"port",
"=",
"int",
"(",
"envPort",
")",
"\n",
"}",
"else",
"if",
"port",
"==",
"0",
"{",
"port",
"=",
"8000",
"\n",
"}",
"\n\n",
"addr",
":=",
"host",
"+",
"\"",
"\"",
"+",
"strconv",
".",
"FormatInt",
"(",
"int64",
"(",
"port",
")",
",",
"10",
")",
"\n\n",
"return",
"addr",
"\n",
"}"
]
| // GetAddress parses address | [
"GetAddress",
"parses",
"address"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/tan.go#L101-L143 |
8,822 | lunny/tango | tan.go | RunTLS | func (t *Tango) RunTLS(certFile, keyFile string, args ...interface{}) {
addr := getAddress(args...)
t.logger.Info("Listening on https://" + addr)
t.Server.Addr = addr
t.Server.Handler = t
err := t.ListenAndServeTLS(certFile, keyFile)
if err != nil {
t.logger.Error(err)
}
} | go | func (t *Tango) RunTLS(certFile, keyFile string, args ...interface{}) {
addr := getAddress(args...)
t.logger.Info("Listening on https://" + addr)
t.Server.Addr = addr
t.Server.Handler = t
err := t.ListenAndServeTLS(certFile, keyFile)
if err != nil {
t.logger.Error(err)
}
} | [
"func",
"(",
"t",
"*",
"Tango",
")",
"RunTLS",
"(",
"certFile",
",",
"keyFile",
"string",
",",
"args",
"...",
"interface",
"{",
"}",
")",
"{",
"addr",
":=",
"getAddress",
"(",
"args",
"...",
")",
"\n\n",
"t",
".",
"logger",
".",
"Info",
"(",
"\"",
"\"",
"+",
"addr",
")",
"\n\n",
"t",
".",
"Server",
".",
"Addr",
"=",
"addr",
"\n",
"t",
".",
"Server",
".",
"Handler",
"=",
"t",
"\n\n",
"err",
":=",
"t",
".",
"ListenAndServeTLS",
"(",
"certFile",
",",
"keyFile",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"t",
".",
"logger",
".",
"Error",
"(",
"err",
")",
"\n",
"}",
"\n",
"}"
]
| // RunTLS runs the https server with special cert and key files | [
"RunTLS",
"runs",
"the",
"https",
"server",
"with",
"special",
"cert",
"and",
"key",
"files"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/tan.go#L160-L172 |
8,823 | lunny/tango | tan.go | WrapBefore | func WrapBefore(handler http.Handler) HandlerFunc {
return func(ctx *Context) {
handler.ServeHTTP(ctx.ResponseWriter, ctx.Req())
ctx.Next()
}
} | go | func WrapBefore(handler http.Handler) HandlerFunc {
return func(ctx *Context) {
handler.ServeHTTP(ctx.ResponseWriter, ctx.Req())
ctx.Next()
}
} | [
"func",
"WrapBefore",
"(",
"handler",
"http",
".",
"Handler",
")",
"HandlerFunc",
"{",
"return",
"func",
"(",
"ctx",
"*",
"Context",
")",
"{",
"handler",
".",
"ServeHTTP",
"(",
"ctx",
".",
"ResponseWriter",
",",
"ctx",
".",
"Req",
"(",
")",
")",
"\n\n",
"ctx",
".",
"Next",
"(",
")",
"\n",
"}",
"\n",
"}"
]
| // WrapBefore wraps a http standard handler to tango's before action executes | [
"WrapBefore",
"wraps",
"a",
"http",
"standard",
"handler",
"to",
"tango",
"s",
"before",
"action",
"executes"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/tan.go#L183-L189 |
8,824 | lunny/tango | tan.go | UseHandler | func (t *Tango) UseHandler(handler http.Handler) {
t.Use(WrapBefore(handler))
} | go | func (t *Tango) UseHandler(handler http.Handler) {
t.Use(WrapBefore(handler))
} | [
"func",
"(",
"t",
"*",
"Tango",
")",
"UseHandler",
"(",
"handler",
"http",
".",
"Handler",
")",
"{",
"t",
".",
"Use",
"(",
"WrapBefore",
"(",
"handler",
")",
")",
"\n",
"}"
]
| // UseHandler adds a standard http handler to tango's | [
"UseHandler",
"adds",
"a",
"standard",
"http",
"handler",
"to",
"tango",
"s"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/tan.go#L201-L203 |
8,825 | lunny/tango | tan.go | NewWithLog | func NewWithLog(logger Logger, handlers ...Handler) *Tango {
tan := &Tango{
Router: newRouter(),
logger: logger,
handlers: make([]Handler, 0),
ErrHandler: Errors(),
}
tan.ctxPool.New = func() interface{} {
return &Context{
tan: tan,
Logger: tan.logger,
}
}
tan.respPool.New = func() interface{} {
return &responseWriter{}
}
tan.Use(handlers...)
return tan
} | go | func NewWithLog(logger Logger, handlers ...Handler) *Tango {
tan := &Tango{
Router: newRouter(),
logger: logger,
handlers: make([]Handler, 0),
ErrHandler: Errors(),
}
tan.ctxPool.New = func() interface{} {
return &Context{
tan: tan,
Logger: tan.logger,
}
}
tan.respPool.New = func() interface{} {
return &responseWriter{}
}
tan.Use(handlers...)
return tan
} | [
"func",
"NewWithLog",
"(",
"logger",
"Logger",
",",
"handlers",
"...",
"Handler",
")",
"*",
"Tango",
"{",
"tan",
":=",
"&",
"Tango",
"{",
"Router",
":",
"newRouter",
"(",
")",
",",
"logger",
":",
"logger",
",",
"handlers",
":",
"make",
"(",
"[",
"]",
"Handler",
",",
"0",
")",
",",
"ErrHandler",
":",
"Errors",
"(",
")",
",",
"}",
"\n\n",
"tan",
".",
"ctxPool",
".",
"New",
"=",
"func",
"(",
")",
"interface",
"{",
"}",
"{",
"return",
"&",
"Context",
"{",
"tan",
":",
"tan",
",",
"Logger",
":",
"tan",
".",
"logger",
",",
"}",
"\n",
"}",
"\n\n",
"tan",
".",
"respPool",
".",
"New",
"=",
"func",
"(",
")",
"interface",
"{",
"}",
"{",
"return",
"&",
"responseWriter",
"{",
"}",
"\n",
"}",
"\n\n",
"tan",
".",
"Use",
"(",
"handlers",
"...",
")",
"\n\n",
"return",
"tan",
"\n",
"}"
]
| // NewWithLog creates tango with the special logger and handlers | [
"NewWithLog",
"creates",
"tango",
"with",
"the",
"special",
"logger",
"and",
"handlers"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/tan.go#L248-L270 |
8,826 | lunny/tango | tan.go | Classic | func Classic(l ...Logger) *Tango {
var logger Logger
if len(l) == 0 {
logger = NewLogger(os.Stdout)
} else {
logger = l[0]
}
return NewWithLog(
logger,
ClassicHandlers...,
)
} | go | func Classic(l ...Logger) *Tango {
var logger Logger
if len(l) == 0 {
logger = NewLogger(os.Stdout)
} else {
logger = l[0]
}
return NewWithLog(
logger,
ClassicHandlers...,
)
} | [
"func",
"Classic",
"(",
"l",
"...",
"Logger",
")",
"*",
"Tango",
"{",
"var",
"logger",
"Logger",
"\n",
"if",
"len",
"(",
"l",
")",
"==",
"0",
"{",
"logger",
"=",
"NewLogger",
"(",
"os",
".",
"Stdout",
")",
"\n",
"}",
"else",
"{",
"logger",
"=",
"l",
"[",
"0",
"]",
"\n",
"}",
"\n\n",
"return",
"NewWithLog",
"(",
"logger",
",",
"ClassicHandlers",
"...",
",",
")",
"\n",
"}"
]
| // Classic returns the tango with default handlers and logger | [
"Classic",
"returns",
"the",
"tango",
"with",
"default",
"handlers",
"and",
"logger"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/tan.go#L278-L290 |
8,827 | lunny/tango | file.go | File | func File(path string) func(ctx *Context) {
return func(ctx *Context) {
ctx.ServeFile(path)
}
} | go | func File(path string) func(ctx *Context) {
return func(ctx *Context) {
ctx.ServeFile(path)
}
} | [
"func",
"File",
"(",
"path",
"string",
")",
"func",
"(",
"ctx",
"*",
"Context",
")",
"{",
"return",
"func",
"(",
"ctx",
"*",
"Context",
")",
"{",
"ctx",
".",
"ServeFile",
"(",
"path",
")",
"\n",
"}",
"\n",
"}"
]
| // File returns a handle to serve a file | [
"File",
"returns",
"a",
"handle",
"to",
"serve",
"a",
"file"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/file.go#L10-L14 |
8,828 | lunny/tango | file.go | Dir | func Dir(dir string) func(ctx *Context) {
return func(ctx *Context) {
params := ctx.Params()
if len(*params) <= 0 {
ctx.Result = NotFound()
ctx.HandleError()
return
}
ctx.ServeFile(filepath.Join(dir, (*params)[0].Value))
}
} | go | func Dir(dir string) func(ctx *Context) {
return func(ctx *Context) {
params := ctx.Params()
if len(*params) <= 0 {
ctx.Result = NotFound()
ctx.HandleError()
return
}
ctx.ServeFile(filepath.Join(dir, (*params)[0].Value))
}
} | [
"func",
"Dir",
"(",
"dir",
"string",
")",
"func",
"(",
"ctx",
"*",
"Context",
")",
"{",
"return",
"func",
"(",
"ctx",
"*",
"Context",
")",
"{",
"params",
":=",
"ctx",
".",
"Params",
"(",
")",
"\n",
"if",
"len",
"(",
"*",
"params",
")",
"<=",
"0",
"{",
"ctx",
".",
"Result",
"=",
"NotFound",
"(",
")",
"\n",
"ctx",
".",
"HandleError",
"(",
")",
"\n",
"return",
"\n",
"}",
"\n",
"ctx",
".",
"ServeFile",
"(",
"filepath",
".",
"Join",
"(",
"dir",
",",
"(",
"*",
"params",
")",
"[",
"0",
"]",
".",
"Value",
")",
")",
"\n",
"}",
"\n",
"}"
]
| // Dir returns a handle to serve a directory | [
"Dir",
"returns",
"a",
"handle",
"to",
"serve",
"a",
"directory"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/file.go#L17-L27 |
8,829 | lunny/tango | form.go | Strings | func (f *Forms) Strings(key string) ([]string, error) {
(*http.Request)(f).ParseMultipartForm(32 << 20)
if v, ok := (*http.Request)(f).Form[key]; ok {
return v, nil
}
return nil, errors.New("not exist")
} | go | func (f *Forms) Strings(key string) ([]string, error) {
(*http.Request)(f).ParseMultipartForm(32 << 20)
if v, ok := (*http.Request)(f).Form[key]; ok {
return v, nil
}
return nil, errors.New("not exist")
} | [
"func",
"(",
"f",
"*",
"Forms",
")",
"Strings",
"(",
"key",
"string",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"(",
"*",
"http",
".",
"Request",
")",
"(",
"f",
")",
".",
"ParseMultipartForm",
"(",
"32",
"<<",
"20",
")",
"\n",
"if",
"v",
",",
"ok",
":=",
"(",
"*",
"http",
".",
"Request",
")",
"(",
"f",
")",
".",
"Form",
"[",
"key",
"]",
";",
"ok",
"{",
"return",
"v",
",",
"nil",
"\n",
"}",
"\n",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}"
]
| // Strings returns request form as strings | [
"Strings",
"returns",
"request",
"form",
"as",
"strings"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/form.go#L31-L37 |
8,830 | lunny/tango | form.go | Form | func (ctx *Context) Form(key string, defaults ...string) string {
return (*Forms)(ctx.req).MustString(key, defaults...)
} | go | func (ctx *Context) Form(key string, defaults ...string) string {
return (*Forms)(ctx.req).MustString(key, defaults...)
} | [
"func",
"(",
"ctx",
"*",
"Context",
")",
"Form",
"(",
"key",
"string",
",",
"defaults",
"...",
"string",
")",
"string",
"{",
"return",
"(",
"*",
"Forms",
")",
"(",
"ctx",
".",
"req",
")",
".",
"MustString",
"(",
"key",
",",
"defaults",
"...",
")",
"\n",
"}"
]
| // Form returns request form as string with default | [
"Form",
"returns",
"request",
"form",
"as",
"string",
"with",
"default"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/form.go#L209-L211 |
8,831 | lunny/tango | form.go | FormStrings | func (ctx *Context) FormStrings(key string, defaults ...[]string) []string {
return (*Forms)(ctx.req).MustStrings(key, defaults...)
} | go | func (ctx *Context) FormStrings(key string, defaults ...[]string) []string {
return (*Forms)(ctx.req).MustStrings(key, defaults...)
} | [
"func",
"(",
"ctx",
"*",
"Context",
")",
"FormStrings",
"(",
"key",
"string",
",",
"defaults",
"...",
"[",
"]",
"string",
")",
"[",
"]",
"string",
"{",
"return",
"(",
"*",
"Forms",
")",
"(",
"ctx",
".",
"req",
")",
".",
"MustStrings",
"(",
"key",
",",
"defaults",
"...",
")",
"\n",
"}"
]
| // FormStrings returns request form as strings with default | [
"FormStrings",
"returns",
"request",
"form",
"as",
"strings",
"with",
"default"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/form.go#L214-L216 |
8,832 | lunny/tango | form.go | FormEscape | func (ctx *Context) FormEscape(key string, defaults ...string) string {
return (*Forms)(ctx.req).MustEscape(key, defaults...)
} | go | func (ctx *Context) FormEscape(key string, defaults ...string) string {
return (*Forms)(ctx.req).MustEscape(key, defaults...)
} | [
"func",
"(",
"ctx",
"*",
"Context",
")",
"FormEscape",
"(",
"key",
"string",
",",
"defaults",
"...",
"string",
")",
"string",
"{",
"return",
"(",
"*",
"Forms",
")",
"(",
"ctx",
".",
"req",
")",
".",
"MustEscape",
"(",
"key",
",",
"defaults",
"...",
")",
"\n",
"}"
]
| // FormEscape returns request form as escaped string with default | [
"FormEscape",
"returns",
"request",
"form",
"as",
"escaped",
"string",
"with",
"default"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/form.go#L219-L221 |
8,833 | lunny/tango | form.go | FormInt | func (ctx *Context) FormInt(key string, defaults ...int) int {
return (*Forms)(ctx.req).MustInt(key, defaults...)
} | go | func (ctx *Context) FormInt(key string, defaults ...int) int {
return (*Forms)(ctx.req).MustInt(key, defaults...)
} | [
"func",
"(",
"ctx",
"*",
"Context",
")",
"FormInt",
"(",
"key",
"string",
",",
"defaults",
"...",
"int",
")",
"int",
"{",
"return",
"(",
"*",
"Forms",
")",
"(",
"ctx",
".",
"req",
")",
".",
"MustInt",
"(",
"key",
",",
"defaults",
"...",
")",
"\n",
"}"
]
| // FormInt returns request form as int with default | [
"FormInt",
"returns",
"request",
"form",
"as",
"int",
"with",
"default"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/form.go#L224-L226 |
8,834 | lunny/tango | form.go | FormInt32 | func (ctx *Context) FormInt32(key string, defaults ...int32) int32 {
return (*Forms)(ctx.req).MustInt32(key, defaults...)
} | go | func (ctx *Context) FormInt32(key string, defaults ...int32) int32 {
return (*Forms)(ctx.req).MustInt32(key, defaults...)
} | [
"func",
"(",
"ctx",
"*",
"Context",
")",
"FormInt32",
"(",
"key",
"string",
",",
"defaults",
"...",
"int32",
")",
"int32",
"{",
"return",
"(",
"*",
"Forms",
")",
"(",
"ctx",
".",
"req",
")",
".",
"MustInt32",
"(",
"key",
",",
"defaults",
"...",
")",
"\n",
"}"
]
| // FormInt32 returns request form as int32 with default | [
"FormInt32",
"returns",
"request",
"form",
"as",
"int32",
"with",
"default"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/form.go#L229-L231 |
8,835 | lunny/tango | form.go | FormInt64 | func (ctx *Context) FormInt64(key string, defaults ...int64) int64 {
return (*Forms)(ctx.req).MustInt64(key, defaults...)
} | go | func (ctx *Context) FormInt64(key string, defaults ...int64) int64 {
return (*Forms)(ctx.req).MustInt64(key, defaults...)
} | [
"func",
"(",
"ctx",
"*",
"Context",
")",
"FormInt64",
"(",
"key",
"string",
",",
"defaults",
"...",
"int64",
")",
"int64",
"{",
"return",
"(",
"*",
"Forms",
")",
"(",
"ctx",
".",
"req",
")",
".",
"MustInt64",
"(",
"key",
",",
"defaults",
"...",
")",
"\n",
"}"
]
| // FormInt64 returns request form as int64 with default | [
"FormInt64",
"returns",
"request",
"form",
"as",
"int64",
"with",
"default"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/form.go#L234-L236 |
8,836 | lunny/tango | form.go | FormUint | func (ctx *Context) FormUint(key string, defaults ...uint) uint {
return (*Forms)(ctx.req).MustUint(key, defaults...)
} | go | func (ctx *Context) FormUint(key string, defaults ...uint) uint {
return (*Forms)(ctx.req).MustUint(key, defaults...)
} | [
"func",
"(",
"ctx",
"*",
"Context",
")",
"FormUint",
"(",
"key",
"string",
",",
"defaults",
"...",
"uint",
")",
"uint",
"{",
"return",
"(",
"*",
"Forms",
")",
"(",
"ctx",
".",
"req",
")",
".",
"MustUint",
"(",
"key",
",",
"defaults",
"...",
")",
"\n",
"}"
]
| // FormUint returns request form as uint with default | [
"FormUint",
"returns",
"request",
"form",
"as",
"uint",
"with",
"default"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/form.go#L239-L241 |
8,837 | lunny/tango | form.go | FormUint32 | func (ctx *Context) FormUint32(key string, defaults ...uint32) uint32 {
return (*Forms)(ctx.req).MustUint32(key, defaults...)
} | go | func (ctx *Context) FormUint32(key string, defaults ...uint32) uint32 {
return (*Forms)(ctx.req).MustUint32(key, defaults...)
} | [
"func",
"(",
"ctx",
"*",
"Context",
")",
"FormUint32",
"(",
"key",
"string",
",",
"defaults",
"...",
"uint32",
")",
"uint32",
"{",
"return",
"(",
"*",
"Forms",
")",
"(",
"ctx",
".",
"req",
")",
".",
"MustUint32",
"(",
"key",
",",
"defaults",
"...",
")",
"\n",
"}"
]
| // FormUint32 returns request form as uint32 with default | [
"FormUint32",
"returns",
"request",
"form",
"as",
"uint32",
"with",
"default"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/form.go#L244-L246 |
8,838 | lunny/tango | form.go | FormUint64 | func (ctx *Context) FormUint64(key string, defaults ...uint64) uint64 {
return (*Forms)(ctx.req).MustUint64(key, defaults...)
} | go | func (ctx *Context) FormUint64(key string, defaults ...uint64) uint64 {
return (*Forms)(ctx.req).MustUint64(key, defaults...)
} | [
"func",
"(",
"ctx",
"*",
"Context",
")",
"FormUint64",
"(",
"key",
"string",
",",
"defaults",
"...",
"uint64",
")",
"uint64",
"{",
"return",
"(",
"*",
"Forms",
")",
"(",
"ctx",
".",
"req",
")",
".",
"MustUint64",
"(",
"key",
",",
"defaults",
"...",
")",
"\n",
"}"
]
| // FormUint64 returns request form as uint64 with default | [
"FormUint64",
"returns",
"request",
"form",
"as",
"uint64",
"with",
"default"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/form.go#L249-L251 |
8,839 | lunny/tango | form.go | FormFloat32 | func (ctx *Context) FormFloat32(key string, defaults ...float32) float32 {
return (*Forms)(ctx.req).MustFloat32(key, defaults...)
} | go | func (ctx *Context) FormFloat32(key string, defaults ...float32) float32 {
return (*Forms)(ctx.req).MustFloat32(key, defaults...)
} | [
"func",
"(",
"ctx",
"*",
"Context",
")",
"FormFloat32",
"(",
"key",
"string",
",",
"defaults",
"...",
"float32",
")",
"float32",
"{",
"return",
"(",
"*",
"Forms",
")",
"(",
"ctx",
".",
"req",
")",
".",
"MustFloat32",
"(",
"key",
",",
"defaults",
"...",
")",
"\n",
"}"
]
| // FormFloat32 returns request form as float32 with default | [
"FormFloat32",
"returns",
"request",
"form",
"as",
"float32",
"with",
"default"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/form.go#L254-L256 |
8,840 | lunny/tango | context.go | SecureCookies | func (ctx *Context) SecureCookies(secret string) Cookies {
return &secureCookies{
(*cookies)(ctx),
secret,
}
} | go | func (ctx *Context) SecureCookies(secret string) Cookies {
return &secureCookies{
(*cookies)(ctx),
secret,
}
} | [
"func",
"(",
"ctx",
"*",
"Context",
")",
"SecureCookies",
"(",
"secret",
"string",
")",
"Cookies",
"{",
"return",
"&",
"secureCookies",
"{",
"(",
"*",
"cookies",
")",
"(",
"ctx",
")",
",",
"secret",
",",
"}",
"\n",
"}"
]
| // SecureCookies generates a secret cookie | [
"SecureCookies",
"generates",
"a",
"secret",
"cookie"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/context.go#L78-L83 |
8,841 | lunny/tango | context.go | IP | func (ctx *Context) IP() string {
proxy := []string{}
if ips := ctx.Req().Header.Get("X-Forwarded-For"); ips != "" {
proxy = strings.Split(ips, ",")
}
if len(proxy) > 0 && proxy[0] != "" {
return proxy[0]
}
ip := strings.Split(ctx.Req().RemoteAddr, ":")
if len(ip) > 0 {
if ip[0] != "[" {
return ip[0]
}
}
return "127.0.0.1"
} | go | func (ctx *Context) IP() string {
proxy := []string{}
if ips := ctx.Req().Header.Get("X-Forwarded-For"); ips != "" {
proxy = strings.Split(ips, ",")
}
if len(proxy) > 0 && proxy[0] != "" {
return proxy[0]
}
ip := strings.Split(ctx.Req().RemoteAddr, ":")
if len(ip) > 0 {
if ip[0] != "[" {
return ip[0]
}
}
return "127.0.0.1"
} | [
"func",
"(",
"ctx",
"*",
"Context",
")",
"IP",
"(",
")",
"string",
"{",
"proxy",
":=",
"[",
"]",
"string",
"{",
"}",
"\n",
"if",
"ips",
":=",
"ctx",
".",
"Req",
"(",
")",
".",
"Header",
".",
"Get",
"(",
"\"",
"\"",
")",
";",
"ips",
"!=",
"\"",
"\"",
"{",
"proxy",
"=",
"strings",
".",
"Split",
"(",
"ips",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"len",
"(",
"proxy",
")",
">",
"0",
"&&",
"proxy",
"[",
"0",
"]",
"!=",
"\"",
"\"",
"{",
"return",
"proxy",
"[",
"0",
"]",
"\n",
"}",
"\n",
"ip",
":=",
"strings",
".",
"Split",
"(",
"ctx",
".",
"Req",
"(",
")",
".",
"RemoteAddr",
",",
"\"",
"\"",
")",
"\n",
"if",
"len",
"(",
"ip",
")",
">",
"0",
"{",
"if",
"ip",
"[",
"0",
"]",
"!=",
"\"",
"\"",
"{",
"return",
"ip",
"[",
"0",
"]",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"\"",
"\"",
"\n",
"}"
]
| // IP returns remote IP | [
"IP",
"returns",
"remote",
"IP"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/context.go#L114-L129 |
8,842 | lunny/tango | context.go | WriteString | func (ctx *Context) WriteString(content string) (int, error) {
return io.WriteString(ctx.ResponseWriter, content)
} | go | func (ctx *Context) WriteString(content string) (int, error) {
return io.WriteString(ctx.ResponseWriter, content)
} | [
"func",
"(",
"ctx",
"*",
"Context",
")",
"WriteString",
"(",
"content",
"string",
")",
"(",
"int",
",",
"error",
")",
"{",
"return",
"io",
".",
"WriteString",
"(",
"ctx",
".",
"ResponseWriter",
",",
"content",
")",
"\n",
"}"
]
| // WriteString writes a string to response write | [
"WriteString",
"writes",
"a",
"string",
"to",
"response",
"write"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/context.go#L162-L164 |
8,843 | lunny/tango | context.go | ServeFile | func (ctx *Context) ServeFile(path string) error {
dir, file := filepath.Split(path)
return ctx.ServeContent(file, http.Dir(dir))
} | go | func (ctx *Context) ServeFile(path string) error {
dir, file := filepath.Split(path)
return ctx.ServeContent(file, http.Dir(dir))
} | [
"func",
"(",
"ctx",
"*",
"Context",
")",
"ServeFile",
"(",
"path",
"string",
")",
"error",
"{",
"dir",
",",
"file",
":=",
"filepath",
".",
"Split",
"(",
"path",
")",
"\n",
"return",
"ctx",
".",
"ServeContent",
"(",
"file",
",",
"http",
".",
"Dir",
"(",
"dir",
")",
")",
"\n",
"}"
]
| // ServeFile serves a file | [
"ServeFile",
"serves",
"a",
"file"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/context.go#L274-L277 |
8,844 | lunny/tango | context.go | ServeContent | func (ctx *Context) ServeContent(path string, fileSystem http.FileSystem) error {
f, err := fileSystem.Open(path)
if err != nil {
msg, code := toHTTPError(err)
http.Error(ctx, msg, code)
return nil
}
defer f.Close()
d, err := f.Stat()
if err != nil {
msg, code := toHTTPError(err)
http.Error(ctx, msg, code)
return nil
}
if d.IsDir() {
http.Error(ctx, http.StatusText(http.StatusForbidden), http.StatusForbidden)
return nil
}
http.ServeContent(ctx, ctx.Req(), d.Name(), d.ModTime(), f)
return nil
} | go | func (ctx *Context) ServeContent(path string, fileSystem http.FileSystem) error {
f, err := fileSystem.Open(path)
if err != nil {
msg, code := toHTTPError(err)
http.Error(ctx, msg, code)
return nil
}
defer f.Close()
d, err := f.Stat()
if err != nil {
msg, code := toHTTPError(err)
http.Error(ctx, msg, code)
return nil
}
if d.IsDir() {
http.Error(ctx, http.StatusText(http.StatusForbidden), http.StatusForbidden)
return nil
}
http.ServeContent(ctx, ctx.Req(), d.Name(), d.ModTime(), f)
return nil
} | [
"func",
"(",
"ctx",
"*",
"Context",
")",
"ServeContent",
"(",
"path",
"string",
",",
"fileSystem",
"http",
".",
"FileSystem",
")",
"error",
"{",
"f",
",",
"err",
":=",
"fileSystem",
".",
"Open",
"(",
"path",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"msg",
",",
"code",
":=",
"toHTTPError",
"(",
"err",
")",
"\n",
"http",
".",
"Error",
"(",
"ctx",
",",
"msg",
",",
"code",
")",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"defer",
"f",
".",
"Close",
"(",
")",
"\n\n",
"d",
",",
"err",
":=",
"f",
".",
"Stat",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"msg",
",",
"code",
":=",
"toHTTPError",
"(",
"err",
")",
"\n",
"http",
".",
"Error",
"(",
"ctx",
",",
"msg",
",",
"code",
")",
"\n",
"return",
"nil",
"\n",
"}",
"\n\n",
"if",
"d",
".",
"IsDir",
"(",
")",
"{",
"http",
".",
"Error",
"(",
"ctx",
",",
"http",
".",
"StatusText",
"(",
"http",
".",
"StatusForbidden",
")",
",",
"http",
".",
"StatusForbidden",
")",
"\n",
"return",
"nil",
"\n",
"}",
"\n\n",
"http",
".",
"ServeContent",
"(",
"ctx",
",",
"ctx",
".",
"Req",
"(",
")",
",",
"d",
".",
"Name",
"(",
")",
",",
"d",
".",
"ModTime",
"(",
")",
",",
"f",
")",
"\n",
"return",
"nil",
"\n",
"}"
]
| // ServeContent serve content | [
"ServeContent",
"serve",
"content"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/context.go#L280-L303 |
8,845 | lunny/tango | context.go | ServeXML | func (ctx *Context) ServeXML(obj interface{}) error {
encoder := xml.NewEncoder(ctx)
ctx.Header().Set("Content-Type", "application/xml; charset=UTF-8")
err := encoder.Encode(obj)
if err != nil {
ctx.Header().Del("Content-Type")
}
return err
} | go | func (ctx *Context) ServeXML(obj interface{}) error {
encoder := xml.NewEncoder(ctx)
ctx.Header().Set("Content-Type", "application/xml; charset=UTF-8")
err := encoder.Encode(obj)
if err != nil {
ctx.Header().Del("Content-Type")
}
return err
} | [
"func",
"(",
"ctx",
"*",
"Context",
")",
"ServeXML",
"(",
"obj",
"interface",
"{",
"}",
")",
"error",
"{",
"encoder",
":=",
"xml",
".",
"NewEncoder",
"(",
"ctx",
")",
"\n",
"ctx",
".",
"Header",
"(",
")",
".",
"Set",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"err",
":=",
"encoder",
".",
"Encode",
"(",
"obj",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"ctx",
".",
"Header",
"(",
")",
".",
"Del",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"err",
"\n",
"}"
]
| // ServeXML serves marshaled XML content from obj | [
"ServeXML",
"serves",
"marshaled",
"XML",
"content",
"from",
"obj"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/context.go#L312-L320 |
8,846 | lunny/tango | context.go | ServeJSON | func (ctx *Context) ServeJSON(obj interface{}) error {
encoder := json.NewEncoder(ctx)
ctx.Header().Set("Content-Type", "application/json; charset=UTF-8")
err := encoder.Encode(obj)
if err != nil {
ctx.Header().Del("Content-Type")
}
return err
} | go | func (ctx *Context) ServeJSON(obj interface{}) error {
encoder := json.NewEncoder(ctx)
ctx.Header().Set("Content-Type", "application/json; charset=UTF-8")
err := encoder.Encode(obj)
if err != nil {
ctx.Header().Del("Content-Type")
}
return err
} | [
"func",
"(",
"ctx",
"*",
"Context",
")",
"ServeJSON",
"(",
"obj",
"interface",
"{",
"}",
")",
"error",
"{",
"encoder",
":=",
"json",
".",
"NewEncoder",
"(",
"ctx",
")",
"\n",
"ctx",
".",
"Header",
"(",
")",
".",
"Set",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"err",
":=",
"encoder",
".",
"Encode",
"(",
"obj",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"ctx",
".",
"Header",
"(",
")",
".",
"Del",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"err",
"\n",
"}"
]
| // ServeJSON serves marshaled JSON content from obj | [
"ServeJSON",
"serves",
"marshaled",
"JSON",
"content",
"from",
"obj"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/context.go#L329-L337 |
8,847 | lunny/tango | context.go | Body | func (ctx *Context) Body() ([]byte, error) {
if ctx.req.Body == nil {
return []byte{}, nil
}
body, err := ioutil.ReadAll(ctx.req.Body)
if err != nil {
return nil, err
}
ctx.req.Body.Close()
ctx.req.Body = ioutil.NopCloser(bytes.NewBuffer(body))
return body, nil
} | go | func (ctx *Context) Body() ([]byte, error) {
if ctx.req.Body == nil {
return []byte{}, nil
}
body, err := ioutil.ReadAll(ctx.req.Body)
if err != nil {
return nil, err
}
ctx.req.Body.Close()
ctx.req.Body = ioutil.NopCloser(bytes.NewBuffer(body))
return body, nil
} | [
"func",
"(",
"ctx",
"*",
"Context",
")",
"Body",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"if",
"ctx",
".",
"req",
".",
"Body",
"==",
"nil",
"{",
"return",
"[",
"]",
"byte",
"{",
"}",
",",
"nil",
"\n",
"}",
"\n\n",
"body",
",",
"err",
":=",
"ioutil",
".",
"ReadAll",
"(",
"ctx",
".",
"req",
".",
"Body",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"ctx",
".",
"req",
".",
"Body",
".",
"Close",
"(",
")",
"\n",
"ctx",
".",
"req",
".",
"Body",
"=",
"ioutil",
".",
"NopCloser",
"(",
"bytes",
".",
"NewBuffer",
"(",
"body",
")",
")",
"\n\n",
"return",
"body",
",",
"nil",
"\n",
"}"
]
| // Body returns body's content | [
"Body",
"returns",
"body",
"s",
"content"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/context.go#L340-L354 |
8,848 | lunny/tango | context.go | DecodeJSON | func (ctx *Context) DecodeJSON(obj interface{}) error {
body, err := ctx.Body()
if err != nil {
return err
}
return json.Unmarshal(body, obj)
} | go | func (ctx *Context) DecodeJSON(obj interface{}) error {
body, err := ctx.Body()
if err != nil {
return err
}
return json.Unmarshal(body, obj)
} | [
"func",
"(",
"ctx",
"*",
"Context",
")",
"DecodeJSON",
"(",
"obj",
"interface",
"{",
"}",
")",
"error",
"{",
"body",
",",
"err",
":=",
"ctx",
".",
"Body",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"return",
"json",
".",
"Unmarshal",
"(",
"body",
",",
"obj",
")",
"\n",
"}"
]
| // DecodeJSON decodes body as JSON format to obj | [
"DecodeJSON",
"decodes",
"body",
"as",
"JSON",
"format",
"to",
"obj"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/context.go#L363-L370 |
8,849 | lunny/tango | context.go | DecodeXML | func (ctx *Context) DecodeXML(obj interface{}) error {
body, err := ctx.Body()
if err != nil {
return err
}
return xml.Unmarshal(body, obj)
} | go | func (ctx *Context) DecodeXML(obj interface{}) error {
body, err := ctx.Body()
if err != nil {
return err
}
return xml.Unmarshal(body, obj)
} | [
"func",
"(",
"ctx",
"*",
"Context",
")",
"DecodeXML",
"(",
"obj",
"interface",
"{",
"}",
")",
"error",
"{",
"body",
",",
"err",
":=",
"ctx",
".",
"Body",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"return",
"xml",
".",
"Unmarshal",
"(",
"body",
",",
"obj",
")",
"\n",
"}"
]
| // DecodeXML decodes body as XML format to obj | [
"DecodeXML",
"decodes",
"body",
"as",
"XML",
"format",
"to",
"obj"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/context.go#L379-L386 |
8,850 | lunny/tango | context.go | Download | func (ctx *Context) Download(fpath string) error {
f, err := os.Open(fpath)
if err != nil {
return err
}
defer f.Close()
fName := filepath.Base(fpath)
ctx.Header().Set("Content-Disposition", fmt.Sprintf("attachment; filename=\"%v\"", fName))
_, err = io.Copy(ctx, f)
return err
} | go | func (ctx *Context) Download(fpath string) error {
f, err := os.Open(fpath)
if err != nil {
return err
}
defer f.Close()
fName := filepath.Base(fpath)
ctx.Header().Set("Content-Disposition", fmt.Sprintf("attachment; filename=\"%v\"", fName))
_, err = io.Copy(ctx, f)
return err
} | [
"func",
"(",
"ctx",
"*",
"Context",
")",
"Download",
"(",
"fpath",
"string",
")",
"error",
"{",
"f",
",",
"err",
":=",
"os",
".",
"Open",
"(",
"fpath",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"defer",
"f",
".",
"Close",
"(",
")",
"\n\n",
"fName",
":=",
"filepath",
".",
"Base",
"(",
"fpath",
")",
"\n",
"ctx",
".",
"Header",
"(",
")",
".",
"Set",
"(",
"\"",
"\"",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\\\"",
"\\\"",
"\"",
",",
"fName",
")",
")",
"\n",
"_",
",",
"err",
"=",
"io",
".",
"Copy",
"(",
"ctx",
",",
"f",
")",
"\n",
"return",
"err",
"\n",
"}"
]
| // Download provides a locale file to http client | [
"Download",
"provides",
"a",
"locale",
"file",
"to",
"http",
"client"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/context.go#L389-L400 |
8,851 | lunny/tango | context.go | SaveToFile | func (ctx *Context) SaveToFile(formName, savePath string) error {
file, _, err := ctx.Req().FormFile(formName)
if err != nil {
return err
}
defer file.Close()
f, err := os.OpenFile(savePath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0666)
if err != nil {
return err
}
defer f.Close()
_, err = io.Copy(f, file)
return err
} | go | func (ctx *Context) SaveToFile(formName, savePath string) error {
file, _, err := ctx.Req().FormFile(formName)
if err != nil {
return err
}
defer file.Close()
f, err := os.OpenFile(savePath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0666)
if err != nil {
return err
}
defer f.Close()
_, err = io.Copy(f, file)
return err
} | [
"func",
"(",
"ctx",
"*",
"Context",
")",
"SaveToFile",
"(",
"formName",
",",
"savePath",
"string",
")",
"error",
"{",
"file",
",",
"_",
",",
"err",
":=",
"ctx",
".",
"Req",
"(",
")",
".",
"FormFile",
"(",
"formName",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"defer",
"file",
".",
"Close",
"(",
")",
"\n\n",
"f",
",",
"err",
":=",
"os",
".",
"OpenFile",
"(",
"savePath",
",",
"os",
".",
"O_WRONLY",
"|",
"os",
".",
"O_CREATE",
"|",
"os",
".",
"O_TRUNC",
",",
"0666",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"defer",
"f",
".",
"Close",
"(",
")",
"\n",
"_",
",",
"err",
"=",
"io",
".",
"Copy",
"(",
"f",
",",
"file",
")",
"\n",
"return",
"err",
"\n",
"}"
]
| // SaveToFile saves the HTTP post file form to local file path | [
"SaveToFile",
"saves",
"the",
"HTTP",
"post",
"file",
"form",
"to",
"local",
"file",
"path"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/context.go#L403-L417 |
8,852 | lunny/tango | context.go | Redirect | func (ctx *Context) Redirect(url string, status ...int) {
s := http.StatusFound
if len(status) > 0 {
s = status[0]
}
http.Redirect(ctx.ResponseWriter, ctx.Req(), url, s)
} | go | func (ctx *Context) Redirect(url string, status ...int) {
s := http.StatusFound
if len(status) > 0 {
s = status[0]
}
http.Redirect(ctx.ResponseWriter, ctx.Req(), url, s)
} | [
"func",
"(",
"ctx",
"*",
"Context",
")",
"Redirect",
"(",
"url",
"string",
",",
"status",
"...",
"int",
")",
"{",
"s",
":=",
"http",
".",
"StatusFound",
"\n",
"if",
"len",
"(",
"status",
")",
">",
"0",
"{",
"s",
"=",
"status",
"[",
"0",
"]",
"\n",
"}",
"\n",
"http",
".",
"Redirect",
"(",
"ctx",
".",
"ResponseWriter",
",",
"ctx",
".",
"Req",
"(",
")",
",",
"url",
",",
"s",
")",
"\n",
"}"
]
| // Redirect redirects the request to another URL | [
"Redirect",
"redirects",
"the",
"request",
"to",
"another",
"URL"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/context.go#L420-L426 |
8,853 | lunny/tango | context.go | Unauthorized | func (ctx *Context) Unauthorized() {
ctx.Abort(http.StatusUnauthorized, http.StatusText(http.StatusUnauthorized))
} | go | func (ctx *Context) Unauthorized() {
ctx.Abort(http.StatusUnauthorized, http.StatusText(http.StatusUnauthorized))
} | [
"func",
"(",
"ctx",
"*",
"Context",
")",
"Unauthorized",
"(",
")",
"{",
"ctx",
".",
"Abort",
"(",
"http",
".",
"StatusUnauthorized",
",",
"http",
".",
"StatusText",
"(",
"http",
".",
"StatusUnauthorized",
")",
")",
"\n",
"}"
]
| // Unauthorized writes a 401 HTTP response | [
"Unauthorized",
"writes",
"a",
"401",
"HTTP",
"response"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/context.go#L434-L436 |
8,854 | lunny/tango | context.go | NotFound | func (ctx *Context) NotFound(message ...string) {
if len(message) == 0 {
ctx.Abort(http.StatusNotFound, http.StatusText(http.StatusNotFound))
return
}
ctx.Abort(http.StatusNotFound, message[0])
} | go | func (ctx *Context) NotFound(message ...string) {
if len(message) == 0 {
ctx.Abort(http.StatusNotFound, http.StatusText(http.StatusNotFound))
return
}
ctx.Abort(http.StatusNotFound, message[0])
} | [
"func",
"(",
"ctx",
"*",
"Context",
")",
"NotFound",
"(",
"message",
"...",
"string",
")",
"{",
"if",
"len",
"(",
"message",
")",
"==",
"0",
"{",
"ctx",
".",
"Abort",
"(",
"http",
".",
"StatusNotFound",
",",
"http",
".",
"StatusText",
"(",
"http",
".",
"StatusNotFound",
")",
")",
"\n",
"return",
"\n",
"}",
"\n",
"ctx",
".",
"Abort",
"(",
"http",
".",
"StatusNotFound",
",",
"message",
"[",
"0",
"]",
")",
"\n",
"}"
]
| // NotFound writes a 404 HTTP response | [
"NotFound",
"writes",
"a",
"404",
"HTTP",
"response"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/context.go#L439-L445 |
8,855 | lunny/tango | context.go | Contexts | func Contexts() HandlerFunc {
return func(ctx *Context) {
if action := ctx.Action(); action != nil {
if a, ok := action.(Contexter); ok {
a.SetContext(ctx)
}
}
ctx.Next()
}
} | go | func Contexts() HandlerFunc {
return func(ctx *Context) {
if action := ctx.Action(); action != nil {
if a, ok := action.(Contexter); ok {
a.SetContext(ctx)
}
}
ctx.Next()
}
} | [
"func",
"Contexts",
"(",
")",
"HandlerFunc",
"{",
"return",
"func",
"(",
"ctx",
"*",
"Context",
")",
"{",
"if",
"action",
":=",
"ctx",
".",
"Action",
"(",
")",
";",
"action",
"!=",
"nil",
"{",
"if",
"a",
",",
"ok",
":=",
"action",
".",
"(",
"Contexter",
")",
";",
"ok",
"{",
"a",
".",
"SetContext",
"(",
"ctx",
")",
"\n",
"}",
"\n",
"}",
"\n",
"ctx",
".",
"Next",
"(",
")",
"\n",
"}",
"\n",
"}"
]
| // Contexts returns a middleware to inject Context to action struct | [
"Contexts",
"returns",
"a",
"middleware",
"to",
"inject",
"Context",
"to",
"action",
"struct"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/context.go#L472-L481 |
8,856 | lunny/tango | error.go | Abort | func Abort(code int, content ...string) AbortError {
if len(content) >= 1 {
return &abortError{code, content[0]}
}
return &abortError{code, http.StatusText(code)}
} | go | func Abort(code int, content ...string) AbortError {
if len(content) >= 1 {
return &abortError{code, content[0]}
}
return &abortError{code, http.StatusText(code)}
} | [
"func",
"Abort",
"(",
"code",
"int",
",",
"content",
"...",
"string",
")",
"AbortError",
"{",
"if",
"len",
"(",
"content",
")",
">=",
"1",
"{",
"return",
"&",
"abortError",
"{",
"code",
",",
"content",
"[",
"0",
"]",
"}",
"\n",
"}",
"\n",
"return",
"&",
"abortError",
"{",
"code",
",",
"http",
".",
"StatusText",
"(",
"code",
")",
"}",
"\n",
"}"
]
| // Abort returns an AbortError | [
"Abort",
"returns",
"an",
"AbortError"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/error.go#L32-L37 |
8,857 | lunny/tango | error.go | Errors | func Errors() HandlerFunc {
return func(ctx *Context) {
switch res := ctx.Result.(type) {
case AbortError:
ctx.WriteHeader(res.Code())
ctx.WriteString(res.Error())
case error:
ctx.WriteHeader(http.StatusInternalServerError)
ctx.WriteString(res.Error())
default:
ctx.WriteHeader(http.StatusInternalServerError)
ctx.WriteString(http.StatusText(http.StatusInternalServerError))
}
}
} | go | func Errors() HandlerFunc {
return func(ctx *Context) {
switch res := ctx.Result.(type) {
case AbortError:
ctx.WriteHeader(res.Code())
ctx.WriteString(res.Error())
case error:
ctx.WriteHeader(http.StatusInternalServerError)
ctx.WriteString(res.Error())
default:
ctx.WriteHeader(http.StatusInternalServerError)
ctx.WriteString(http.StatusText(http.StatusInternalServerError))
}
}
} | [
"func",
"Errors",
"(",
")",
"HandlerFunc",
"{",
"return",
"func",
"(",
"ctx",
"*",
"Context",
")",
"{",
"switch",
"res",
":=",
"ctx",
".",
"Result",
".",
"(",
"type",
")",
"{",
"case",
"AbortError",
":",
"ctx",
".",
"WriteHeader",
"(",
"res",
".",
"Code",
"(",
")",
")",
"\n",
"ctx",
".",
"WriteString",
"(",
"res",
".",
"Error",
"(",
")",
")",
"\n",
"case",
"error",
":",
"ctx",
".",
"WriteHeader",
"(",
"http",
".",
"StatusInternalServerError",
")",
"\n",
"ctx",
".",
"WriteString",
"(",
"res",
".",
"Error",
"(",
")",
")",
"\n",
"default",
":",
"ctx",
".",
"WriteHeader",
"(",
"http",
".",
"StatusInternalServerError",
")",
"\n",
"ctx",
".",
"WriteString",
"(",
"http",
".",
"StatusText",
"(",
"http",
".",
"StatusInternalServerError",
")",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}"
]
| // Errors returns default errorhandler, you can use your self handler | [
"Errors",
"returns",
"default",
"errorhandler",
"you",
"can",
"use",
"your",
"self",
"handler"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/error.go#L65-L79 |
8,858 | lunny/tango | static.go | IsFilterExt | func (s *StaticOptions) IsFilterExt(rPath string) bool {
rext := path.Ext(rPath)
for _, ext := range s.FilterExts {
if rext == ext {
return true
}
}
return false
} | go | func (s *StaticOptions) IsFilterExt(rPath string) bool {
rext := path.Ext(rPath)
for _, ext := range s.FilterExts {
if rext == ext {
return true
}
}
return false
} | [
"func",
"(",
"s",
"*",
"StaticOptions",
")",
"IsFilterExt",
"(",
"rPath",
"string",
")",
"bool",
"{",
"rext",
":=",
"path",
".",
"Ext",
"(",
"rPath",
")",
"\n",
"for",
"_",
",",
"ext",
":=",
"range",
"s",
".",
"FilterExts",
"{",
"if",
"rext",
"==",
"ext",
"{",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
]
| // IsFilterExt decribes if rPath's ext match filter ext | [
"IsFilterExt",
"decribes",
"if",
"rPath",
"s",
"ext",
"match",
"filter",
"ext"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/static.go#L27-L35 |
8,859 | lunny/tango | router.go | NewRoute | func NewRoute(v interface{}, t reflect.Type,
method reflect.Value, tp RouteType, handlers []Handler) *Route {
var pool *pool
if tp == StructRoute || tp == StructPtrRoute {
pool = newPool(PoolSize, t)
}
return &Route{
raw: v,
routeType: tp,
method: method,
pool: pool,
handlers: handlers,
}
} | go | func NewRoute(v interface{}, t reflect.Type,
method reflect.Value, tp RouteType, handlers []Handler) *Route {
var pool *pool
if tp == StructRoute || tp == StructPtrRoute {
pool = newPool(PoolSize, t)
}
return &Route{
raw: v,
routeType: tp,
method: method,
pool: pool,
handlers: handlers,
}
} | [
"func",
"NewRoute",
"(",
"v",
"interface",
"{",
"}",
",",
"t",
"reflect",
".",
"Type",
",",
"method",
"reflect",
".",
"Value",
",",
"tp",
"RouteType",
",",
"handlers",
"[",
"]",
"Handler",
")",
"*",
"Route",
"{",
"var",
"pool",
"*",
"pool",
"\n",
"if",
"tp",
"==",
"StructRoute",
"||",
"tp",
"==",
"StructPtrRoute",
"{",
"pool",
"=",
"newPool",
"(",
"PoolSize",
",",
"t",
")",
"\n",
"}",
"\n",
"return",
"&",
"Route",
"{",
"raw",
":",
"v",
",",
"routeType",
":",
"tp",
",",
"method",
":",
"method",
",",
"pool",
":",
"pool",
",",
"handlers",
":",
"handlers",
",",
"}",
"\n",
"}"
]
| // NewRoute returns a route | [
"NewRoute",
"returns",
"a",
"route"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/router.go#L53-L66 |
8,860 | lunny/tango | router.go | IsStruct | func (r *Route) IsStruct() bool {
return r.routeType == StructRoute || r.routeType == StructPtrRoute
} | go | func (r *Route) IsStruct() bool {
return r.routeType == StructRoute || r.routeType == StructPtrRoute
} | [
"func",
"(",
"r",
"*",
"Route",
")",
"IsStruct",
"(",
")",
"bool",
"{",
"return",
"r",
".",
"routeType",
"==",
"StructRoute",
"||",
"r",
".",
"routeType",
"==",
"StructPtrRoute",
"\n",
"}"
]
| // IsStruct returns if the execute is a struct | [
"IsStruct",
"returns",
"if",
"the",
"execute",
"is",
"a",
"struct"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/router.go#L84-L86 |
8,861 | lunny/tango | router.go | Less | func (e edges) Less(i, j int) bool {
if e[i].tp == snode {
if e[j].tp == snode {
return len(e[i].content) > len(e[j].content)
}
return true
}
if e[j].tp == snode {
return false
}
return i < j
} | go | func (e edges) Less(i, j int) bool {
if e[i].tp == snode {
if e[j].tp == snode {
return len(e[i].content) > len(e[j].content)
}
return true
}
if e[j].tp == snode {
return false
}
return i < j
} | [
"func",
"(",
"e",
"edges",
")",
"Less",
"(",
"i",
",",
"j",
"int",
")",
"bool",
"{",
"if",
"e",
"[",
"i",
"]",
".",
"tp",
"==",
"snode",
"{",
"if",
"e",
"[",
"j",
"]",
".",
"tp",
"==",
"snode",
"{",
"return",
"len",
"(",
"e",
"[",
"i",
"]",
".",
"content",
")",
">",
"len",
"(",
"e",
"[",
"j",
"]",
".",
"content",
")",
"\n",
"}",
"\n",
"return",
"true",
"\n",
"}",
"\n",
"if",
"e",
"[",
"j",
"]",
".",
"tp",
"==",
"snode",
"{",
"return",
"false",
"\n",
"}",
"\n",
"return",
"i",
"<",
"j",
"\n",
"}"
]
| // static route will be put the first, so it will be match first.
// two static route, content longer is first. | [
"static",
"route",
"will",
"be",
"put",
"the",
"first",
"so",
"it",
"will",
"be",
"match",
"first",
".",
"two",
"static",
"route",
"content",
"longer",
"is",
"first",
"."
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/router.go#L142-L153 |
8,862 | lunny/tango | router.go | newRouter | func newRouter() (r *router) {
r = &router{
trees: make(map[string]*node),
}
for _, m := range SupportMethods {
r.trees[m] = &node{
edges: edges{},
}
}
return
} | go | func newRouter() (r *router) {
r = &router{
trees: make(map[string]*node),
}
for _, m := range SupportMethods {
r.trees[m] = &node{
edges: edges{},
}
}
return
} | [
"func",
"newRouter",
"(",
")",
"(",
"r",
"*",
"router",
")",
"{",
"r",
"=",
"&",
"router",
"{",
"trees",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"node",
")",
",",
"}",
"\n",
"for",
"_",
",",
"m",
":=",
"range",
"SupportMethods",
"{",
"r",
".",
"trees",
"[",
"m",
"]",
"=",
"&",
"node",
"{",
"edges",
":",
"edges",
"{",
"}",
",",
"}",
"\n",
"}",
"\n",
"return",
"\n",
"}"
]
| // newRouter return a new router | [
"newRouter",
"return",
"a",
"new",
"router"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/router.go#L170-L180 |
8,863 | lunny/tango | router.go | Match | func (r *router) Match(url, method string) (*Route, Params) {
cn, ok := r.trees[method]
if !ok {
return nil, nil
}
var params = make(Params, 0, strings.Count(url, "/"))
for _, n := range cn.edges {
e, newParams := r.matchNode(n, url, params)
if e != nil {
return e.handle, newParams
}
}
return nil, nil
} | go | func (r *router) Match(url, method string) (*Route, Params) {
cn, ok := r.trees[method]
if !ok {
return nil, nil
}
var params = make(Params, 0, strings.Count(url, "/"))
for _, n := range cn.edges {
e, newParams := r.matchNode(n, url, params)
if e != nil {
return e.handle, newParams
}
}
return nil, nil
} | [
"func",
"(",
"r",
"*",
"router",
")",
"Match",
"(",
"url",
",",
"method",
"string",
")",
"(",
"*",
"Route",
",",
"Params",
")",
"{",
"cn",
",",
"ok",
":=",
"r",
".",
"trees",
"[",
"method",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
",",
"nil",
"\n",
"}",
"\n",
"var",
"params",
"=",
"make",
"(",
"Params",
",",
"0",
",",
"strings",
".",
"Count",
"(",
"url",
",",
"\"",
"\"",
")",
")",
"\n",
"for",
"_",
",",
"n",
":=",
"range",
"cn",
".",
"edges",
"{",
"e",
",",
"newParams",
":=",
"r",
".",
"matchNode",
"(",
"n",
",",
"url",
",",
"params",
")",
"\n",
"if",
"e",
"!=",
"nil",
"{",
"return",
"e",
".",
"handle",
",",
"newParams",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
",",
"nil",
"\n",
"}"
]
| // Match for request url, match router | [
"Match",
"for",
"request",
"url",
"match",
"router"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/router.go#L370-L383 |
8,864 | lunny/tango | router.go | validNodes | func validNodes(nodes []*node) bool {
if len(nodes) == 0 {
return false
}
var lastTp = nodes[0]
for _, node := range nodes[1:] {
if lastTp.tp != snode && node.tp != snode {
return false
}
lastTp = node
}
return true
} | go | func validNodes(nodes []*node) bool {
if len(nodes) == 0 {
return false
}
var lastTp = nodes[0]
for _, node := range nodes[1:] {
if lastTp.tp != snode && node.tp != snode {
return false
}
lastTp = node
}
return true
} | [
"func",
"validNodes",
"(",
"nodes",
"[",
"]",
"*",
"node",
")",
"bool",
"{",
"if",
"len",
"(",
"nodes",
")",
"==",
"0",
"{",
"return",
"false",
"\n",
"}",
"\n",
"var",
"lastTp",
"=",
"nodes",
"[",
"0",
"]",
"\n",
"for",
"_",
",",
"node",
":=",
"range",
"nodes",
"[",
"1",
":",
"]",
"{",
"if",
"lastTp",
".",
"tp",
"!=",
"snode",
"&&",
"node",
".",
"tp",
"!=",
"snode",
"{",
"return",
"false",
"\n",
"}",
"\n",
"lastTp",
"=",
"node",
"\n",
"}",
"\n",
"return",
"true",
"\n",
"}"
]
| // validNodes validates parsed nodes, all non-static route should have static route children. | [
"validNodes",
"validates",
"parsed",
"nodes",
"all",
"non",
"-",
"static",
"route",
"should",
"have",
"static",
"route",
"children",
"."
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/router.go#L406-L418 |
8,865 | lunny/tango | router.go | addnodes | func (r *router) addnodes(method string, nodes []*node) {
cn := r.trees[method]
var p = cn
for i := 0; i < len(nodes); i++ {
p = r.addnode(p, nodes, i)
}
} | go | func (r *router) addnodes(method string, nodes []*node) {
cn := r.trees[method]
var p = cn
for i := 0; i < len(nodes); i++ {
p = r.addnode(p, nodes, i)
}
} | [
"func",
"(",
"r",
"*",
"router",
")",
"addnodes",
"(",
"method",
"string",
",",
"nodes",
"[",
"]",
"*",
"node",
")",
"{",
"cn",
":=",
"r",
".",
"trees",
"[",
"method",
"]",
"\n",
"var",
"p",
"=",
"cn",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"len",
"(",
"nodes",
")",
";",
"i",
"++",
"{",
"p",
"=",
"r",
".",
"addnode",
"(",
"p",
",",
"nodes",
",",
"i",
")",
"\n",
"}",
"\n",
"}"
]
| // addnodes adds nodes to trees | [
"addnodes",
"adds",
"nodes",
"to",
"trees"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/router.go#L421-L427 |
8,866 | lunny/tango | router.go | Route | func (r *router) Route(ms interface{}, url string, c interface{}, handlers ...Handler) {
vc := reflect.ValueOf(c)
if vc.Kind() == reflect.Func {
switch ms.(type) {
case string:
s := strings.Split(ms.(string), ":")
r.addFunc([]string{s[0]}, url, c, handlers)
case []string:
var newSlice []string
for _, m := range ms.([]string) {
s := strings.Split(m, ":")
newSlice = append(newSlice, s[0])
}
r.addFunc(newSlice, url, c, handlers)
default:
panic("unknow methods format")
}
} else if vc.Kind() == reflect.Ptr && vc.Elem().Kind() == reflect.Struct {
if handler, ok := vc.Interface().(http.Handler); ok {
r.Route(ms, url, handler.ServeHTTP, handlers...)
return
}
var methods = make(map[string]string)
switch ms.(type) {
case string:
s := strings.Split(ms.(string), ":")
if len(s) == 1 {
methods[s[0]] = strings.Title(strings.ToLower(s[0]))
} else if len(s) == 2 {
methods[s[0]] = strings.TrimSpace(s[1])
} else {
panic("unknow methods format")
}
case []string:
for _, m := range ms.([]string) {
s := strings.Split(m, ":")
if len(s) == 1 {
methods[s[0]] = strings.Title(strings.ToLower(s[0]))
} else if len(s) == 2 {
methods[s[0]] = strings.TrimSpace(s[1])
} else {
panic("unknow format")
}
}
case map[string]string:
methods = ms.(map[string]string)
default:
panic("unsupported methods")
}
r.addStruct(methods, url, c, handlers)
} else {
panic("not support route type")
}
} | go | func (r *router) Route(ms interface{}, url string, c interface{}, handlers ...Handler) {
vc := reflect.ValueOf(c)
if vc.Kind() == reflect.Func {
switch ms.(type) {
case string:
s := strings.Split(ms.(string), ":")
r.addFunc([]string{s[0]}, url, c, handlers)
case []string:
var newSlice []string
for _, m := range ms.([]string) {
s := strings.Split(m, ":")
newSlice = append(newSlice, s[0])
}
r.addFunc(newSlice, url, c, handlers)
default:
panic("unknow methods format")
}
} else if vc.Kind() == reflect.Ptr && vc.Elem().Kind() == reflect.Struct {
if handler, ok := vc.Interface().(http.Handler); ok {
r.Route(ms, url, handler.ServeHTTP, handlers...)
return
}
var methods = make(map[string]string)
switch ms.(type) {
case string:
s := strings.Split(ms.(string), ":")
if len(s) == 1 {
methods[s[0]] = strings.Title(strings.ToLower(s[0]))
} else if len(s) == 2 {
methods[s[0]] = strings.TrimSpace(s[1])
} else {
panic("unknow methods format")
}
case []string:
for _, m := range ms.([]string) {
s := strings.Split(m, ":")
if len(s) == 1 {
methods[s[0]] = strings.Title(strings.ToLower(s[0]))
} else if len(s) == 2 {
methods[s[0]] = strings.TrimSpace(s[1])
} else {
panic("unknow format")
}
}
case map[string]string:
methods = ms.(map[string]string)
default:
panic("unsupported methods")
}
r.addStruct(methods, url, c, handlers)
} else {
panic("not support route type")
}
} | [
"func",
"(",
"r",
"*",
"router",
")",
"Route",
"(",
"ms",
"interface",
"{",
"}",
",",
"url",
"string",
",",
"c",
"interface",
"{",
"}",
",",
"handlers",
"...",
"Handler",
")",
"{",
"vc",
":=",
"reflect",
".",
"ValueOf",
"(",
"c",
")",
"\n",
"if",
"vc",
".",
"Kind",
"(",
")",
"==",
"reflect",
".",
"Func",
"{",
"switch",
"ms",
".",
"(",
"type",
")",
"{",
"case",
"string",
":",
"s",
":=",
"strings",
".",
"Split",
"(",
"ms",
".",
"(",
"string",
")",
",",
"\"",
"\"",
")",
"\n",
"r",
".",
"addFunc",
"(",
"[",
"]",
"string",
"{",
"s",
"[",
"0",
"]",
"}",
",",
"url",
",",
"c",
",",
"handlers",
")",
"\n",
"case",
"[",
"]",
"string",
":",
"var",
"newSlice",
"[",
"]",
"string",
"\n",
"for",
"_",
",",
"m",
":=",
"range",
"ms",
".",
"(",
"[",
"]",
"string",
")",
"{",
"s",
":=",
"strings",
".",
"Split",
"(",
"m",
",",
"\"",
"\"",
")",
"\n",
"newSlice",
"=",
"append",
"(",
"newSlice",
",",
"s",
"[",
"0",
"]",
")",
"\n",
"}",
"\n",
"r",
".",
"addFunc",
"(",
"newSlice",
",",
"url",
",",
"c",
",",
"handlers",
")",
"\n",
"default",
":",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"else",
"if",
"vc",
".",
"Kind",
"(",
")",
"==",
"reflect",
".",
"Ptr",
"&&",
"vc",
".",
"Elem",
"(",
")",
".",
"Kind",
"(",
")",
"==",
"reflect",
".",
"Struct",
"{",
"if",
"handler",
",",
"ok",
":=",
"vc",
".",
"Interface",
"(",
")",
".",
"(",
"http",
".",
"Handler",
")",
";",
"ok",
"{",
"r",
".",
"Route",
"(",
"ms",
",",
"url",
",",
"handler",
".",
"ServeHTTP",
",",
"handlers",
"...",
")",
"\n",
"return",
"\n",
"}",
"\n",
"var",
"methods",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"string",
")",
"\n",
"switch",
"ms",
".",
"(",
"type",
")",
"{",
"case",
"string",
":",
"s",
":=",
"strings",
".",
"Split",
"(",
"ms",
".",
"(",
"string",
")",
",",
"\"",
"\"",
")",
"\n",
"if",
"len",
"(",
"s",
")",
"==",
"1",
"{",
"methods",
"[",
"s",
"[",
"0",
"]",
"]",
"=",
"strings",
".",
"Title",
"(",
"strings",
".",
"ToLower",
"(",
"s",
"[",
"0",
"]",
")",
")",
"\n",
"}",
"else",
"if",
"len",
"(",
"s",
")",
"==",
"2",
"{",
"methods",
"[",
"s",
"[",
"0",
"]",
"]",
"=",
"strings",
".",
"TrimSpace",
"(",
"s",
"[",
"1",
"]",
")",
"\n",
"}",
"else",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"case",
"[",
"]",
"string",
":",
"for",
"_",
",",
"m",
":=",
"range",
"ms",
".",
"(",
"[",
"]",
"string",
")",
"{",
"s",
":=",
"strings",
".",
"Split",
"(",
"m",
",",
"\"",
"\"",
")",
"\n",
"if",
"len",
"(",
"s",
")",
"==",
"1",
"{",
"methods",
"[",
"s",
"[",
"0",
"]",
"]",
"=",
"strings",
".",
"Title",
"(",
"strings",
".",
"ToLower",
"(",
"s",
"[",
"0",
"]",
")",
")",
"\n",
"}",
"else",
"if",
"len",
"(",
"s",
")",
"==",
"2",
"{",
"methods",
"[",
"s",
"[",
"0",
"]",
"]",
"=",
"strings",
".",
"TrimSpace",
"(",
"s",
"[",
"1",
"]",
")",
"\n",
"}",
"else",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"\n",
"case",
"map",
"[",
"string",
"]",
"string",
":",
"methods",
"=",
"ms",
".",
"(",
"map",
"[",
"string",
"]",
"string",
")",
"\n",
"default",
":",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"r",
".",
"addStruct",
"(",
"methods",
",",
"url",
",",
"c",
",",
"handlers",
")",
"\n",
"}",
"else",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}"
]
| // Route adds route | [
"Route",
"adds",
"route"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/router.go#L438-L492 |
8,867 | lunny/tango | compress.go | Compresses | func Compresses(exts []string) HandlerFunc {
extsmap := make(map[string]bool)
for _, ext := range exts {
extsmap[strings.ToLower(ext)] = true
}
return func(ctx *Context) {
ae := ctx.Req().Header.Get("Accept-Encoding")
if ae == "" {
ctx.Next()
return
}
if len(extsmap) > 0 {
ext := strings.ToLower(path.Ext(ctx.Req().URL.Path))
if _, ok := extsmap[ext]; ok {
compress(ctx, "auto")
return
}
}
if action := ctx.Action(); action != nil {
if c, ok := action.(Compresser); ok {
compress(ctx, c.CompressType())
return
}
}
// if blank, then no compress
ctx.Next()
}
} | go | func Compresses(exts []string) HandlerFunc {
extsmap := make(map[string]bool)
for _, ext := range exts {
extsmap[strings.ToLower(ext)] = true
}
return func(ctx *Context) {
ae := ctx.Req().Header.Get("Accept-Encoding")
if ae == "" {
ctx.Next()
return
}
if len(extsmap) > 0 {
ext := strings.ToLower(path.Ext(ctx.Req().URL.Path))
if _, ok := extsmap[ext]; ok {
compress(ctx, "auto")
return
}
}
if action := ctx.Action(); action != nil {
if c, ok := action.(Compresser); ok {
compress(ctx, c.CompressType())
return
}
}
// if blank, then no compress
ctx.Next()
}
} | [
"func",
"Compresses",
"(",
"exts",
"[",
"]",
"string",
")",
"HandlerFunc",
"{",
"extsmap",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"bool",
")",
"\n",
"for",
"_",
",",
"ext",
":=",
"range",
"exts",
"{",
"extsmap",
"[",
"strings",
".",
"ToLower",
"(",
"ext",
")",
"]",
"=",
"true",
"\n",
"}",
"\n\n",
"return",
"func",
"(",
"ctx",
"*",
"Context",
")",
"{",
"ae",
":=",
"ctx",
".",
"Req",
"(",
")",
".",
"Header",
".",
"Get",
"(",
"\"",
"\"",
")",
"\n",
"if",
"ae",
"==",
"\"",
"\"",
"{",
"ctx",
".",
"Next",
"(",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"extsmap",
")",
">",
"0",
"{",
"ext",
":=",
"strings",
".",
"ToLower",
"(",
"path",
".",
"Ext",
"(",
"ctx",
".",
"Req",
"(",
")",
".",
"URL",
".",
"Path",
")",
")",
"\n",
"if",
"_",
",",
"ok",
":=",
"extsmap",
"[",
"ext",
"]",
";",
"ok",
"{",
"compress",
"(",
"ctx",
",",
"\"",
"\"",
")",
"\n",
"return",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"action",
":=",
"ctx",
".",
"Action",
"(",
")",
";",
"action",
"!=",
"nil",
"{",
"if",
"c",
",",
"ok",
":=",
"action",
".",
"(",
"Compresser",
")",
";",
"ok",
"{",
"compress",
"(",
"ctx",
",",
"c",
".",
"CompressType",
"(",
")",
")",
"\n",
"return",
"\n",
"}",
"\n",
"}",
"\n\n",
"// if blank, then no compress",
"ctx",
".",
"Next",
"(",
")",
"\n",
"}",
"\n",
"}"
]
| // Compresses defines a middleware to compress HTTP response | [
"Compresses",
"defines",
"a",
"middleware",
"to",
"compress",
"HTTP",
"response"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/compress.go#L58-L89 |
8,868 | lunny/tango | recovery.go | Recovery | func Recovery(debug bool) HandlerFunc {
return func(ctx *Context) {
defer func() {
if e := recover(); e != nil {
var buf bytes.Buffer
fmt.Fprintf(&buf, "Handler crashed with error: %v", e)
for i := 1; ; i++ {
_, file, line, ok := runtime.Caller(i)
if !ok {
break
} else {
fmt.Fprintf(&buf, "\n")
}
fmt.Fprintf(&buf, "%v:%v", file, line)
}
var content = buf.String()
ctx.Logger.Error(content)
if !ctx.Written() {
if !debug {
ctx.Result = InternalServerError(http.StatusText(http.StatusInternalServerError))
} else {
ctx.Result = InternalServerError(content)
}
}
}
}()
ctx.Next()
}
} | go | func Recovery(debug bool) HandlerFunc {
return func(ctx *Context) {
defer func() {
if e := recover(); e != nil {
var buf bytes.Buffer
fmt.Fprintf(&buf, "Handler crashed with error: %v", e)
for i := 1; ; i++ {
_, file, line, ok := runtime.Caller(i)
if !ok {
break
} else {
fmt.Fprintf(&buf, "\n")
}
fmt.Fprintf(&buf, "%v:%v", file, line)
}
var content = buf.String()
ctx.Logger.Error(content)
if !ctx.Written() {
if !debug {
ctx.Result = InternalServerError(http.StatusText(http.StatusInternalServerError))
} else {
ctx.Result = InternalServerError(content)
}
}
}
}()
ctx.Next()
}
} | [
"func",
"Recovery",
"(",
"debug",
"bool",
")",
"HandlerFunc",
"{",
"return",
"func",
"(",
"ctx",
"*",
"Context",
")",
"{",
"defer",
"func",
"(",
")",
"{",
"if",
"e",
":=",
"recover",
"(",
")",
";",
"e",
"!=",
"nil",
"{",
"var",
"buf",
"bytes",
".",
"Buffer",
"\n",
"fmt",
".",
"Fprintf",
"(",
"&",
"buf",
",",
"\"",
"\"",
",",
"e",
")",
"\n\n",
"for",
"i",
":=",
"1",
";",
";",
"i",
"++",
"{",
"_",
",",
"file",
",",
"line",
",",
"ok",
":=",
"runtime",
".",
"Caller",
"(",
"i",
")",
"\n",
"if",
"!",
"ok",
"{",
"break",
"\n",
"}",
"else",
"{",
"fmt",
".",
"Fprintf",
"(",
"&",
"buf",
",",
"\"",
"\\n",
"\"",
")",
"\n",
"}",
"\n",
"fmt",
".",
"Fprintf",
"(",
"&",
"buf",
",",
"\"",
"\"",
",",
"file",
",",
"line",
")",
"\n",
"}",
"\n\n",
"var",
"content",
"=",
"buf",
".",
"String",
"(",
")",
"\n",
"ctx",
".",
"Logger",
".",
"Error",
"(",
"content",
")",
"\n\n",
"if",
"!",
"ctx",
".",
"Written",
"(",
")",
"{",
"if",
"!",
"debug",
"{",
"ctx",
".",
"Result",
"=",
"InternalServerError",
"(",
"http",
".",
"StatusText",
"(",
"http",
".",
"StatusInternalServerError",
")",
")",
"\n",
"}",
"else",
"{",
"ctx",
".",
"Result",
"=",
"InternalServerError",
"(",
"content",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"(",
")",
"\n\n",
"ctx",
".",
"Next",
"(",
")",
"\n",
"}",
"\n",
"}"
]
| // Recovery returns a middleware which catch panics and log them | [
"Recovery",
"returns",
"a",
"middleware",
"which",
"catch",
"panics",
"and",
"log",
"them"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/recovery.go#L15-L47 |
8,869 | lunny/tango | param.go | Get | func (p *Params) Get(key string) string {
if len(key) == 0 {
return ""
}
if key[0] != ':' && key[0] != '*' {
key = ":" + key
}
for _, v := range *p {
if v.Name == key {
return v.Value
}
}
return ""
} | go | func (p *Params) Get(key string) string {
if len(key) == 0 {
return ""
}
if key[0] != ':' && key[0] != '*' {
key = ":" + key
}
for _, v := range *p {
if v.Name == key {
return v.Value
}
}
return ""
} | [
"func",
"(",
"p",
"*",
"Params",
")",
"Get",
"(",
"key",
"string",
")",
"string",
"{",
"if",
"len",
"(",
"key",
")",
"==",
"0",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n",
"if",
"key",
"[",
"0",
"]",
"!=",
"':'",
"&&",
"key",
"[",
"0",
"]",
"!=",
"'*'",
"{",
"key",
"=",
"\"",
"\"",
"+",
"key",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"v",
":=",
"range",
"*",
"p",
"{",
"if",
"v",
".",
"Name",
"==",
"key",
"{",
"return",
"v",
".",
"Value",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"\"",
"\"",
"\n",
"}"
]
| // Get returns request form as string | [
"Get",
"returns",
"request",
"form",
"as",
"string"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/param.go#L25-L39 |
8,870 | lunny/tango | param.go | Strings | func (p *Params) Strings(key string) ([]string, error) {
if len(key) == 0 {
return nil, errors.New("not exist")
}
if key[0] != ':' && key[0] != '*' {
key = ":" + key
}
var s = make([]string, 0)
for _, v := range *p {
if v.Name == key {
s = append(s, v.Value)
}
}
if len(s) > 0 {
return s, nil
}
return nil, errors.New("not exist")
} | go | func (p *Params) Strings(key string) ([]string, error) {
if len(key) == 0 {
return nil, errors.New("not exist")
}
if key[0] != ':' && key[0] != '*' {
key = ":" + key
}
var s = make([]string, 0)
for _, v := range *p {
if v.Name == key {
s = append(s, v.Value)
}
}
if len(s) > 0 {
return s, nil
}
return nil, errors.New("not exist")
} | [
"func",
"(",
"p",
"*",
"Params",
")",
"Strings",
"(",
"key",
"string",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"if",
"len",
"(",
"key",
")",
"==",
"0",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"key",
"[",
"0",
"]",
"!=",
"':'",
"&&",
"key",
"[",
"0",
"]",
"!=",
"'*'",
"{",
"key",
"=",
"\"",
"\"",
"+",
"key",
"\n",
"}",
"\n\n",
"var",
"s",
"=",
"make",
"(",
"[",
"]",
"string",
",",
"0",
")",
"\n",
"for",
"_",
",",
"v",
":=",
"range",
"*",
"p",
"{",
"if",
"v",
".",
"Name",
"==",
"key",
"{",
"s",
"=",
"append",
"(",
"s",
",",
"v",
".",
"Value",
")",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"len",
"(",
"s",
")",
">",
"0",
"{",
"return",
"s",
",",
"nil",
"\n",
"}",
"\n",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}"
]
| // Strings returns request form as slice of string | [
"Strings",
"returns",
"request",
"form",
"as",
"slice",
"of",
"string"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/param.go#L59-L77 |
8,871 | lunny/tango | param.go | MustString | func (p *Params) MustString(key string, defaults ...string) string {
if len(key) == 0 {
return ""
}
if key[0] != ':' && key[0] != '*' {
key = ":" + key
}
for _, v := range *p {
if v.Name == key {
return v.Value
}
}
if len(defaults) > 0 {
return defaults[0]
}
return ""
} | go | func (p *Params) MustString(key string, defaults ...string) string {
if len(key) == 0 {
return ""
}
if key[0] != ':' && key[0] != '*' {
key = ":" + key
}
for _, v := range *p {
if v.Name == key {
return v.Value
}
}
if len(defaults) > 0 {
return defaults[0]
}
return ""
} | [
"func",
"(",
"p",
"*",
"Params",
")",
"MustString",
"(",
"key",
"string",
",",
"defaults",
"...",
"string",
")",
"string",
"{",
"if",
"len",
"(",
"key",
")",
"==",
"0",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n",
"if",
"key",
"[",
"0",
"]",
"!=",
"':'",
"&&",
"key",
"[",
"0",
"]",
"!=",
"'*'",
"{",
"key",
"=",
"\"",
"\"",
"+",
"key",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"v",
":=",
"range",
"*",
"p",
"{",
"if",
"v",
".",
"Name",
"==",
"key",
"{",
"return",
"v",
".",
"Value",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"len",
"(",
"defaults",
")",
">",
"0",
"{",
"return",
"defaults",
"[",
"0",
"]",
"\n",
"}",
"\n",
"return",
"\"",
"\"",
"\n",
"}"
]
| // MustString returns request form as slice of string with default | [
"MustString",
"returns",
"request",
"form",
"as",
"slice",
"of",
"string",
"with",
"default"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/param.go#L146-L163 |
8,872 | lunny/tango | param.go | MustStrings | func (p *Params) MustStrings(key string, defaults ...[]string) []string {
if len(key) == 0 {
return []string{}
}
if key[0] != ':' && key[0] != '*' {
key = ":" + key
}
var s = make([]string, 0)
for _, v := range *p {
if v.Name == key {
s = append(s, v.Value)
}
}
if len(s) > 0 {
return s
}
if len(defaults) > 0 {
return defaults[0]
}
return []string{}
} | go | func (p *Params) MustStrings(key string, defaults ...[]string) []string {
if len(key) == 0 {
return []string{}
}
if key[0] != ':' && key[0] != '*' {
key = ":" + key
}
var s = make([]string, 0)
for _, v := range *p {
if v.Name == key {
s = append(s, v.Value)
}
}
if len(s) > 0 {
return s
}
if len(defaults) > 0 {
return defaults[0]
}
return []string{}
} | [
"func",
"(",
"p",
"*",
"Params",
")",
"MustStrings",
"(",
"key",
"string",
",",
"defaults",
"...",
"[",
"]",
"string",
")",
"[",
"]",
"string",
"{",
"if",
"len",
"(",
"key",
")",
"==",
"0",
"{",
"return",
"[",
"]",
"string",
"{",
"}",
"\n",
"}",
"\n",
"if",
"key",
"[",
"0",
"]",
"!=",
"':'",
"&&",
"key",
"[",
"0",
"]",
"!=",
"'*'",
"{",
"key",
"=",
"\"",
"\"",
"+",
"key",
"\n",
"}",
"\n\n",
"var",
"s",
"=",
"make",
"(",
"[",
"]",
"string",
",",
"0",
")",
"\n",
"for",
"_",
",",
"v",
":=",
"range",
"*",
"p",
"{",
"if",
"v",
".",
"Name",
"==",
"key",
"{",
"s",
"=",
"append",
"(",
"s",
",",
"v",
".",
"Value",
")",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"len",
"(",
"s",
")",
">",
"0",
"{",
"return",
"s",
"\n",
"}",
"\n",
"if",
"len",
"(",
"defaults",
")",
">",
"0",
"{",
"return",
"defaults",
"[",
"0",
"]",
"\n",
"}",
"\n",
"return",
"[",
"]",
"string",
"{",
"}",
"\n",
"}"
]
| // MustStrings returns request form as slice of string with default | [
"MustStrings",
"returns",
"request",
"form",
"as",
"slice",
"of",
"string",
"with",
"default"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/param.go#L166-L187 |
8,873 | lunny/tango | param.go | Param | func (ctx *Context) Param(key string, defaults ...string) string {
return ctx.Params().MustString(key, defaults...)
} | go | func (ctx *Context) Param(key string, defaults ...string) string {
return ctx.Params().MustString(key, defaults...)
} | [
"func",
"(",
"ctx",
"*",
"Context",
")",
"Param",
"(",
"key",
"string",
",",
"defaults",
"...",
"string",
")",
"string",
"{",
"return",
"ctx",
".",
"Params",
"(",
")",
".",
"MustString",
"(",
"key",
",",
"defaults",
"...",
")",
"\n",
"}"
]
| // Param returns request form as string with default | [
"Param",
"returns",
"request",
"form",
"as",
"string",
"with",
"default"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/param.go#L293-L295 |
8,874 | lunny/tango | param.go | ParamStrings | func (ctx *Context) ParamStrings(key string, defaults ...[]string) []string {
return ctx.Params().MustStrings(key, defaults...)
} | go | func (ctx *Context) ParamStrings(key string, defaults ...[]string) []string {
return ctx.Params().MustStrings(key, defaults...)
} | [
"func",
"(",
"ctx",
"*",
"Context",
")",
"ParamStrings",
"(",
"key",
"string",
",",
"defaults",
"...",
"[",
"]",
"string",
")",
"[",
"]",
"string",
"{",
"return",
"ctx",
".",
"Params",
"(",
")",
".",
"MustStrings",
"(",
"key",
",",
"defaults",
"...",
")",
"\n",
"}"
]
| // ParamStrings returns request form as slice of string with default | [
"ParamStrings",
"returns",
"request",
"form",
"as",
"slice",
"of",
"string",
"with",
"default"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/param.go#L298-L300 |
8,875 | lunny/tango | param.go | ParamEscape | func (ctx *Context) ParamEscape(key string, defaults ...string) string {
return ctx.Params().MustEscape(key, defaults...)
} | go | func (ctx *Context) ParamEscape(key string, defaults ...string) string {
return ctx.Params().MustEscape(key, defaults...)
} | [
"func",
"(",
"ctx",
"*",
"Context",
")",
"ParamEscape",
"(",
"key",
"string",
",",
"defaults",
"...",
"string",
")",
"string",
"{",
"return",
"ctx",
".",
"Params",
"(",
")",
".",
"MustEscape",
"(",
"key",
",",
"defaults",
"...",
")",
"\n",
"}"
]
| // ParamEscape returns request form as escaped string with default | [
"ParamEscape",
"returns",
"request",
"form",
"as",
"escaped",
"string",
"with",
"default"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/param.go#L303-L305 |
8,876 | lunny/tango | param.go | ParamInt | func (ctx *Context) ParamInt(key string, defaults ...int) int {
return ctx.Params().MustInt(key, defaults...)
} | go | func (ctx *Context) ParamInt(key string, defaults ...int) int {
return ctx.Params().MustInt(key, defaults...)
} | [
"func",
"(",
"ctx",
"*",
"Context",
")",
"ParamInt",
"(",
"key",
"string",
",",
"defaults",
"...",
"int",
")",
"int",
"{",
"return",
"ctx",
".",
"Params",
"(",
")",
".",
"MustInt",
"(",
"key",
",",
"defaults",
"...",
")",
"\n",
"}"
]
| // ParamInt returns request form as int with default | [
"ParamInt",
"returns",
"request",
"form",
"as",
"int",
"with",
"default"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/param.go#L308-L310 |
8,877 | lunny/tango | param.go | ParamInt32 | func (ctx *Context) ParamInt32(key string, defaults ...int32) int32 {
return ctx.Params().MustInt32(key, defaults...)
} | go | func (ctx *Context) ParamInt32(key string, defaults ...int32) int32 {
return ctx.Params().MustInt32(key, defaults...)
} | [
"func",
"(",
"ctx",
"*",
"Context",
")",
"ParamInt32",
"(",
"key",
"string",
",",
"defaults",
"...",
"int32",
")",
"int32",
"{",
"return",
"ctx",
".",
"Params",
"(",
")",
".",
"MustInt32",
"(",
"key",
",",
"defaults",
"...",
")",
"\n",
"}"
]
| // ParamInt32 returns request form as int32 with default | [
"ParamInt32",
"returns",
"request",
"form",
"as",
"int32",
"with",
"default"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/param.go#L313-L315 |
8,878 | lunny/tango | param.go | ParamInt64 | func (ctx *Context) ParamInt64(key string, defaults ...int64) int64 {
return ctx.Params().MustInt64(key, defaults...)
} | go | func (ctx *Context) ParamInt64(key string, defaults ...int64) int64 {
return ctx.Params().MustInt64(key, defaults...)
} | [
"func",
"(",
"ctx",
"*",
"Context",
")",
"ParamInt64",
"(",
"key",
"string",
",",
"defaults",
"...",
"int64",
")",
"int64",
"{",
"return",
"ctx",
".",
"Params",
"(",
")",
".",
"MustInt64",
"(",
"key",
",",
"defaults",
"...",
")",
"\n",
"}"
]
| // ParamInt64 returns request form as int64 with default | [
"ParamInt64",
"returns",
"request",
"form",
"as",
"int64",
"with",
"default"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/param.go#L318-L320 |
8,879 | lunny/tango | param.go | ParamUint | func (ctx *Context) ParamUint(key string, defaults ...uint) uint {
return ctx.Params().MustUint(key, defaults...)
} | go | func (ctx *Context) ParamUint(key string, defaults ...uint) uint {
return ctx.Params().MustUint(key, defaults...)
} | [
"func",
"(",
"ctx",
"*",
"Context",
")",
"ParamUint",
"(",
"key",
"string",
",",
"defaults",
"...",
"uint",
")",
"uint",
"{",
"return",
"ctx",
".",
"Params",
"(",
")",
".",
"MustUint",
"(",
"key",
",",
"defaults",
"...",
")",
"\n",
"}"
]
| // ParamUint returns request form as uint with default | [
"ParamUint",
"returns",
"request",
"form",
"as",
"uint",
"with",
"default"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/param.go#L323-L325 |
8,880 | lunny/tango | param.go | ParamUint32 | func (ctx *Context) ParamUint32(key string, defaults ...uint32) uint32 {
return ctx.Params().MustUint32(key, defaults...)
} | go | func (ctx *Context) ParamUint32(key string, defaults ...uint32) uint32 {
return ctx.Params().MustUint32(key, defaults...)
} | [
"func",
"(",
"ctx",
"*",
"Context",
")",
"ParamUint32",
"(",
"key",
"string",
",",
"defaults",
"...",
"uint32",
")",
"uint32",
"{",
"return",
"ctx",
".",
"Params",
"(",
")",
".",
"MustUint32",
"(",
"key",
",",
"defaults",
"...",
")",
"\n",
"}"
]
| // ParamUint32 returns request form as uint32 with default | [
"ParamUint32",
"returns",
"request",
"form",
"as",
"uint32",
"with",
"default"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/param.go#L328-L330 |
8,881 | lunny/tango | param.go | ParamUint64 | func (ctx *Context) ParamUint64(key string, defaults ...uint64) uint64 {
return ctx.Params().MustUint64(key, defaults...)
} | go | func (ctx *Context) ParamUint64(key string, defaults ...uint64) uint64 {
return ctx.Params().MustUint64(key, defaults...)
} | [
"func",
"(",
"ctx",
"*",
"Context",
")",
"ParamUint64",
"(",
"key",
"string",
",",
"defaults",
"...",
"uint64",
")",
"uint64",
"{",
"return",
"ctx",
".",
"Params",
"(",
")",
".",
"MustUint64",
"(",
"key",
",",
"defaults",
"...",
")",
"\n",
"}"
]
| // ParamUint64 returns request form as uint64 with default | [
"ParamUint64",
"returns",
"request",
"form",
"as",
"uint64",
"with",
"default"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/param.go#L333-L335 |
8,882 | lunny/tango | param.go | ParamFloat32 | func (ctx *Context) ParamFloat32(key string, defaults ...float32) float32 {
return ctx.Params().MustFloat32(key, defaults...)
} | go | func (ctx *Context) ParamFloat32(key string, defaults ...float32) float32 {
return ctx.Params().MustFloat32(key, defaults...)
} | [
"func",
"(",
"ctx",
"*",
"Context",
")",
"ParamFloat32",
"(",
"key",
"string",
",",
"defaults",
"...",
"float32",
")",
"float32",
"{",
"return",
"ctx",
".",
"Params",
"(",
")",
".",
"MustFloat32",
"(",
"key",
",",
"defaults",
"...",
")",
"\n",
"}"
]
| // ParamFloat32 returns request form as float32 with default | [
"ParamFloat32",
"returns",
"request",
"form",
"as",
"float32",
"with",
"default"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/param.go#L338-L340 |
8,883 | lunny/tango | param.go | ParamFloat64 | func (ctx *Context) ParamFloat64(key string, defaults ...float64) float64 {
return ctx.Params().MustFloat64(key, defaults...)
} | go | func (ctx *Context) ParamFloat64(key string, defaults ...float64) float64 {
return ctx.Params().MustFloat64(key, defaults...)
} | [
"func",
"(",
"ctx",
"*",
"Context",
")",
"ParamFloat64",
"(",
"key",
"string",
",",
"defaults",
"...",
"float64",
")",
"float64",
"{",
"return",
"ctx",
".",
"Params",
"(",
")",
".",
"MustFloat64",
"(",
"key",
",",
"defaults",
"...",
")",
"\n",
"}"
]
| // ParamFloat64 returns request form as float64 with default | [
"ParamFloat64",
"returns",
"request",
"form",
"as",
"float64",
"with",
"default"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/param.go#L343-L345 |
8,884 | lunny/tango | param.go | ParamBool | func (ctx *Context) ParamBool(key string, defaults ...bool) bool {
return ctx.Params().MustBool(key, defaults...)
} | go | func (ctx *Context) ParamBool(key string, defaults ...bool) bool {
return ctx.Params().MustBool(key, defaults...)
} | [
"func",
"(",
"ctx",
"*",
"Context",
")",
"ParamBool",
"(",
"key",
"string",
",",
"defaults",
"...",
"bool",
")",
"bool",
"{",
"return",
"ctx",
".",
"Params",
"(",
")",
".",
"MustBool",
"(",
"key",
",",
"defaults",
"...",
")",
"\n",
"}"
]
| // ParamBool returns request form as bool with default | [
"ParamBool",
"returns",
"request",
"form",
"as",
"bool",
"with",
"default"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/param.go#L348-L350 |
8,885 | lunny/tango | param.go | Param | func Param() HandlerFunc {
return func(ctx *Context) {
if action := ctx.Action(); action != nil {
if p, ok := action.(Paramer); ok {
p.SetParams(*ctx.Params())
}
}
ctx.Next()
}
} | go | func Param() HandlerFunc {
return func(ctx *Context) {
if action := ctx.Action(); action != nil {
if p, ok := action.(Paramer); ok {
p.SetParams(*ctx.Params())
}
}
ctx.Next()
}
} | [
"func",
"Param",
"(",
")",
"HandlerFunc",
"{",
"return",
"func",
"(",
"ctx",
"*",
"Context",
")",
"{",
"if",
"action",
":=",
"ctx",
".",
"Action",
"(",
")",
";",
"action",
"!=",
"nil",
"{",
"if",
"p",
",",
"ok",
":=",
"action",
".",
"(",
"Paramer",
")",
";",
"ok",
"{",
"p",
".",
"SetParams",
"(",
"*",
"ctx",
".",
"Params",
"(",
")",
")",
"\n",
"}",
"\n",
"}",
"\n",
"ctx",
".",
"Next",
"(",
")",
"\n",
"}",
"\n",
"}"
]
| // Param returns params handle to operate param | [
"Param",
"returns",
"params",
"handle",
"to",
"operate",
"param"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/param.go#L382-L391 |
8,886 | lunny/tango | group.go | Use | func (g *Group) Use(handlers ...Handler) {
g.handlers = append(g.handlers, handlers...)
} | go | func (g *Group) Use(handlers ...Handler) {
g.handlers = append(g.handlers, handlers...)
} | [
"func",
"(",
"g",
"*",
"Group",
")",
"Use",
"(",
"handlers",
"...",
"Handler",
")",
"{",
"g",
".",
"handlers",
"=",
"append",
"(",
"g",
".",
"handlers",
",",
"handlers",
"...",
")",
"\n",
"}"
]
| // Use set the middlewares to apply to this group's routes | [
"Use",
"set",
"the",
"middlewares",
"to",
"apply",
"to",
"this",
"group",
"s",
"routes"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/group.go#L29-L31 |
8,887 | lunny/tango | group.go | Get | func (g *Group) Get(url string, c interface{}, middlewares ...Handler) {
g.Route([]string{"GET", "HEAD:Get"}, url, c, middlewares...)
} | go | func (g *Group) Get(url string, c interface{}, middlewares ...Handler) {
g.Route([]string{"GET", "HEAD:Get"}, url, c, middlewares...)
} | [
"func",
"(",
"g",
"*",
"Group",
")",
"Get",
"(",
"url",
"string",
",",
"c",
"interface",
"{",
"}",
",",
"middlewares",
"...",
"Handler",
")",
"{",
"g",
".",
"Route",
"(",
"[",
"]",
"string",
"{",
"\"",
"\"",
",",
"\"",
"\"",
"}",
",",
"url",
",",
"c",
",",
"middlewares",
"...",
")",
"\n",
"}"
]
| // Get addes a GET route to this group | [
"Get",
"addes",
"a",
"GET",
"route",
"to",
"this",
"group"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/group.go#L34-L36 |
8,888 | lunny/tango | group.go | Any | func (g *Group) Any(url string, c interface{}, middlewares ...Handler) {
g.Route(SupportMethods, url, c, middlewares...)
g.Route([]string{"HEAD:Get"}, url, c, middlewares...)
} | go | func (g *Group) Any(url string, c interface{}, middlewares ...Handler) {
g.Route(SupportMethods, url, c, middlewares...)
g.Route([]string{"HEAD:Get"}, url, c, middlewares...)
} | [
"func",
"(",
"g",
"*",
"Group",
")",
"Any",
"(",
"url",
"string",
",",
"c",
"interface",
"{",
"}",
",",
"middlewares",
"...",
"Handler",
")",
"{",
"g",
".",
"Route",
"(",
"SupportMethods",
",",
"url",
",",
"c",
",",
"middlewares",
"...",
")",
"\n",
"g",
".",
"Route",
"(",
"[",
"]",
"string",
"{",
"\"",
"\"",
"}",
",",
"url",
",",
"c",
",",
"middlewares",
"...",
")",
"\n",
"}"
]
| // Any addes the default mehtods route to this group | [
"Any",
"addes",
"the",
"default",
"mehtods",
"route",
"to",
"this",
"group"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/group.go#L74-L77 |
8,889 | lunny/tango | group.go | Route | func (g *Group) Route(methods interface{}, url string, c interface{}, middlewares ...Handler) {
g.routers = append(g.routers, groupRouter{methods, url, c, middlewares})
} | go | func (g *Group) Route(methods interface{}, url string, c interface{}, middlewares ...Handler) {
g.routers = append(g.routers, groupRouter{methods, url, c, middlewares})
} | [
"func",
"(",
"g",
"*",
"Group",
")",
"Route",
"(",
"methods",
"interface",
"{",
"}",
",",
"url",
"string",
",",
"c",
"interface",
"{",
"}",
",",
"middlewares",
"...",
"Handler",
")",
"{",
"g",
".",
"routers",
"=",
"append",
"(",
"g",
".",
"routers",
",",
"groupRouter",
"{",
"methods",
",",
"url",
",",
"c",
",",
"middlewares",
"}",
")",
"\n",
"}"
]
| // Route defines a customerize route to this group | [
"Route",
"defines",
"a",
"customerize",
"route",
"to",
"this",
"group"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/group.go#L80-L82 |
8,890 | lunny/tango | group.go | Group | func (g *Group) Group(p string, o interface{}) {
gr := getGroup(o)
for _, gchild := range gr.routers {
g.Route(gchild.methods, joinRoute(p, gchild.url), gchild.c, append(gr.handlers, gchild.handlers...)...)
}
} | go | func (g *Group) Group(p string, o interface{}) {
gr := getGroup(o)
for _, gchild := range gr.routers {
g.Route(gchild.methods, joinRoute(p, gchild.url), gchild.c, append(gr.handlers, gchild.handlers...)...)
}
} | [
"func",
"(",
"g",
"*",
"Group",
")",
"Group",
"(",
"p",
"string",
",",
"o",
"interface",
"{",
"}",
")",
"{",
"gr",
":=",
"getGroup",
"(",
"o",
")",
"\n",
"for",
"_",
",",
"gchild",
":=",
"range",
"gr",
".",
"routers",
"{",
"g",
".",
"Route",
"(",
"gchild",
".",
"methods",
",",
"joinRoute",
"(",
"p",
",",
"gchild",
".",
"url",
")",
",",
"gchild",
".",
"c",
",",
"append",
"(",
"gr",
".",
"handlers",
",",
"gchild",
".",
"handlers",
"...",
")",
"...",
")",
"\n",
"}",
"\n",
"}"
]
| // Group defines group's child group | [
"Group",
"defines",
"group",
"s",
"child",
"group"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/group.go#L85-L90 |
8,891 | lunny/tango | group.go | Group | func (t *Tango) Group(p string, o interface{}) {
t.addGroup(p, getGroup(o))
} | go | func (t *Tango) Group(p string, o interface{}) {
t.addGroup(p, getGroup(o))
} | [
"func",
"(",
"t",
"*",
"Tango",
")",
"Group",
"(",
"p",
"string",
",",
"o",
"interface",
"{",
"}",
")",
"{",
"t",
".",
"addGroup",
"(",
"p",
",",
"getGroup",
"(",
"o",
")",
")",
"\n",
"}"
]
| // Group adds routines groups | [
"Group",
"adds",
"routines",
"groups"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/group.go#L120-L122 |
8,892 | go-gormigrate/gormigrate | gormigrate.go | MigrateTo | func (g *Gormigrate) MigrateTo(migrationID string) error {
if err := g.checkIDExist(migrationID); err != nil {
return err
}
return g.migrate(migrationID)
} | go | func (g *Gormigrate) MigrateTo(migrationID string) error {
if err := g.checkIDExist(migrationID); err != nil {
return err
}
return g.migrate(migrationID)
} | [
"func",
"(",
"g",
"*",
"Gormigrate",
")",
"MigrateTo",
"(",
"migrationID",
"string",
")",
"error",
"{",
"if",
"err",
":=",
"g",
".",
"checkIDExist",
"(",
"migrationID",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"g",
".",
"migrate",
"(",
"migrationID",
")",
"\n",
"}"
]
| // MigrateTo executes all migrations that did not run yet up to the migration that matches `migrationID`. | [
"MigrateTo",
"executes",
"all",
"migrations",
"that",
"did",
"not",
"run",
"yet",
"up",
"to",
"the",
"migration",
"that",
"matches",
"migrationID",
"."
]
| 3185a539c4b4156457c96d6c999290b524fe9f27 | https://github.com/go-gormigrate/gormigrate/blob/3185a539c4b4156457c96d6c999290b524fe9f27/gormigrate.go#L140-L145 |
8,893 | go-gormigrate/gormigrate | gormigrate.go | hasMigrations | func (g *Gormigrate) hasMigrations() bool {
return g.initSchema != nil || len(g.migrations) > 0
} | go | func (g *Gormigrate) hasMigrations() bool {
return g.initSchema != nil || len(g.migrations) > 0
} | [
"func",
"(",
"g",
"*",
"Gormigrate",
")",
"hasMigrations",
"(",
")",
"bool",
"{",
"return",
"g",
".",
"initSchema",
"!=",
"nil",
"||",
"len",
"(",
"g",
".",
"migrations",
")",
">",
"0",
"\n",
"}"
]
| // There are migrations to apply if either there's a defined
// initSchema function or if the list of migrations is not empty. | [
"There",
"are",
"migrations",
"to",
"apply",
"if",
"either",
"there",
"s",
"a",
"defined",
"initSchema",
"function",
"or",
"if",
"the",
"list",
"of",
"migrations",
"is",
"not",
"empty",
"."
]
| 3185a539c4b4156457c96d6c999290b524fe9f27 | https://github.com/go-gormigrate/gormigrate/blob/3185a539c4b4156457c96d6c999290b524fe9f27/gormigrate.go#L193-L195 |
8,894 | go-gormigrate/gormigrate | gormigrate.go | checkReservedID | func (g *Gormigrate) checkReservedID() error {
for _, m := range g.migrations {
if m.ID == initSchemaMigrationID {
return &ReservedIDError{ID: m.ID}
}
}
return nil
} | go | func (g *Gormigrate) checkReservedID() error {
for _, m := range g.migrations {
if m.ID == initSchemaMigrationID {
return &ReservedIDError{ID: m.ID}
}
}
return nil
} | [
"func",
"(",
"g",
"*",
"Gormigrate",
")",
"checkReservedID",
"(",
")",
"error",
"{",
"for",
"_",
",",
"m",
":=",
"range",
"g",
".",
"migrations",
"{",
"if",
"m",
".",
"ID",
"==",
"initSchemaMigrationID",
"{",
"return",
"&",
"ReservedIDError",
"{",
"ID",
":",
"m",
".",
"ID",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
]
| // Check whether any migration is using a reserved ID.
// For now there's only have one reserved ID, but there may be more in the future. | [
"Check",
"whether",
"any",
"migration",
"is",
"using",
"a",
"reserved",
"ID",
".",
"For",
"now",
"there",
"s",
"only",
"have",
"one",
"reserved",
"ID",
"but",
"there",
"may",
"be",
"more",
"in",
"the",
"future",
"."
]
| 3185a539c4b4156457c96d6c999290b524fe9f27 | https://github.com/go-gormigrate/gormigrate/blob/3185a539c4b4156457c96d6c999290b524fe9f27/gormigrate.go#L199-L206 |
8,895 | go-gormigrate/gormigrate | gormigrate.go | RollbackTo | func (g *Gormigrate) RollbackTo(migrationID string) error {
if len(g.migrations) == 0 {
return ErrNoMigrationDefined
}
if err := g.checkIDExist(migrationID); err != nil {
return err
}
g.begin()
defer g.rollback()
for i := len(g.migrations) - 1; i >= 0; i-- {
migration := g.migrations[i]
if migration.ID == migrationID {
break
}
migrationRan, err := g.migrationRan(migration)
if err != nil {
return err
}
if migrationRan {
if err := g.rollbackMigration(migration); err != nil {
return err
}
}
}
return g.commit()
} | go | func (g *Gormigrate) RollbackTo(migrationID string) error {
if len(g.migrations) == 0 {
return ErrNoMigrationDefined
}
if err := g.checkIDExist(migrationID); err != nil {
return err
}
g.begin()
defer g.rollback()
for i := len(g.migrations) - 1; i >= 0; i-- {
migration := g.migrations[i]
if migration.ID == migrationID {
break
}
migrationRan, err := g.migrationRan(migration)
if err != nil {
return err
}
if migrationRan {
if err := g.rollbackMigration(migration); err != nil {
return err
}
}
}
return g.commit()
} | [
"func",
"(",
"g",
"*",
"Gormigrate",
")",
"RollbackTo",
"(",
"migrationID",
"string",
")",
"error",
"{",
"if",
"len",
"(",
"g",
".",
"migrations",
")",
"==",
"0",
"{",
"return",
"ErrNoMigrationDefined",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"g",
".",
"checkIDExist",
"(",
"migrationID",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"g",
".",
"begin",
"(",
")",
"\n",
"defer",
"g",
".",
"rollback",
"(",
")",
"\n\n",
"for",
"i",
":=",
"len",
"(",
"g",
".",
"migrations",
")",
"-",
"1",
";",
"i",
">=",
"0",
";",
"i",
"--",
"{",
"migration",
":=",
"g",
".",
"migrations",
"[",
"i",
"]",
"\n",
"if",
"migration",
".",
"ID",
"==",
"migrationID",
"{",
"break",
"\n",
"}",
"\n",
"migrationRan",
",",
"err",
":=",
"g",
".",
"migrationRan",
"(",
"migration",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"migrationRan",
"{",
"if",
"err",
":=",
"g",
".",
"rollbackMigration",
"(",
"migration",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"g",
".",
"commit",
"(",
")",
"\n",
"}"
]
| // RollbackTo undoes migrations up to the given migration that matches the `migrationID`.
// Migration with the matching `migrationID` is not rolled back. | [
"RollbackTo",
"undoes",
"migrations",
"up",
"to",
"the",
"given",
"migration",
"that",
"matches",
"the",
"migrationID",
".",
"Migration",
"with",
"the",
"matching",
"migrationID",
"is",
"not",
"rolled",
"back",
"."
]
| 3185a539c4b4156457c96d6c999290b524fe9f27 | https://github.com/go-gormigrate/gormigrate/blob/3185a539c4b4156457c96d6c999290b524fe9f27/gormigrate.go#L250-L278 |
8,896 | go-gormigrate/gormigrate | gormigrate.go | canInitializeSchema | func (g *Gormigrate) canInitializeSchema() (bool, error) {
migrationRan, err := g.migrationRan(&Migration{ID: initSchemaMigrationID})
if err != nil {
return false, err
}
if migrationRan {
return false, nil
}
// If the ID doesn't exist, we also want the list of migrations to be empty
var count int
err = g.tx.
Table(g.options.TableName).
Count(&count).
Error
return count == 0, err
} | go | func (g *Gormigrate) canInitializeSchema() (bool, error) {
migrationRan, err := g.migrationRan(&Migration{ID: initSchemaMigrationID})
if err != nil {
return false, err
}
if migrationRan {
return false, nil
}
// If the ID doesn't exist, we also want the list of migrations to be empty
var count int
err = g.tx.
Table(g.options.TableName).
Count(&count).
Error
return count == 0, err
} | [
"func",
"(",
"g",
"*",
"Gormigrate",
")",
"canInitializeSchema",
"(",
")",
"(",
"bool",
",",
"error",
")",
"{",
"migrationRan",
",",
"err",
":=",
"g",
".",
"migrationRan",
"(",
"&",
"Migration",
"{",
"ID",
":",
"initSchemaMigrationID",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"false",
",",
"err",
"\n",
"}",
"\n",
"if",
"migrationRan",
"{",
"return",
"false",
",",
"nil",
"\n",
"}",
"\n\n",
"// If the ID doesn't exist, we also want the list of migrations to be empty",
"var",
"count",
"int",
"\n",
"err",
"=",
"g",
".",
"tx",
".",
"Table",
"(",
"g",
".",
"options",
".",
"TableName",
")",
".",
"Count",
"(",
"&",
"count",
")",
".",
"Error",
"\n",
"return",
"count",
"==",
"0",
",",
"err",
"\n",
"}"
]
| // The schema can be initialised only if it hasn't been initialised yet
// and no other migration has been applied already. | [
"The",
"schema",
"can",
"be",
"initialised",
"only",
"if",
"it",
"hasn",
"t",
"been",
"initialised",
"yet",
"and",
"no",
"other",
"migration",
"has",
"been",
"applied",
"already",
"."
]
| 3185a539c4b4156457c96d6c999290b524fe9f27 | https://github.com/go-gormigrate/gormigrate/blob/3185a539c4b4156457c96d6c999290b524fe9f27/gormigrate.go#L379-L395 |
8,897 | matryer/moq | generate/generated.go | One | func (mock *MyInterfaceMock) One() bool {
if mock.OneFunc == nil {
panic("MyInterfaceMock.OneFunc: method is nil but MyInterface.One was just called")
}
callInfo := struct {
}{}
lockMyInterfaceMockOne.Lock()
mock.calls.One = append(mock.calls.One, callInfo)
lockMyInterfaceMockOne.Unlock()
return mock.OneFunc()
} | go | func (mock *MyInterfaceMock) One() bool {
if mock.OneFunc == nil {
panic("MyInterfaceMock.OneFunc: method is nil but MyInterface.One was just called")
}
callInfo := struct {
}{}
lockMyInterfaceMockOne.Lock()
mock.calls.One = append(mock.calls.One, callInfo)
lockMyInterfaceMockOne.Unlock()
return mock.OneFunc()
} | [
"func",
"(",
"mock",
"*",
"MyInterfaceMock",
")",
"One",
"(",
")",
"bool",
"{",
"if",
"mock",
".",
"OneFunc",
"==",
"nil",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"callInfo",
":=",
"struct",
"{",
"}",
"{",
"}",
"\n",
"lockMyInterfaceMockOne",
".",
"Lock",
"(",
")",
"\n",
"mock",
".",
"calls",
".",
"One",
"=",
"append",
"(",
"mock",
".",
"calls",
".",
"One",
",",
"callInfo",
")",
"\n",
"lockMyInterfaceMockOne",
".",
"Unlock",
"(",
")",
"\n",
"return",
"mock",
".",
"OneFunc",
"(",
")",
"\n",
"}"
]
| // One calls OneFunc. | [
"One",
"calls",
"OneFunc",
"."
]
| 6cfb0558e1bd81d19c9909483c39e199634fed29 | https://github.com/matryer/moq/blob/6cfb0558e1bd81d19c9909483c39e199634fed29/generate/generated.go#L66-L76 |
8,898 | matryer/moq | generate/generated.go | Three | func (mock *MyInterfaceMock) Three() string {
if mock.ThreeFunc == nil {
panic("MyInterfaceMock.ThreeFunc: method is nil but MyInterface.Three was just called")
}
callInfo := struct {
}{}
lockMyInterfaceMockThree.Lock()
mock.calls.Three = append(mock.calls.Three, callInfo)
lockMyInterfaceMockThree.Unlock()
return mock.ThreeFunc()
} | go | func (mock *MyInterfaceMock) Three() string {
if mock.ThreeFunc == nil {
panic("MyInterfaceMock.ThreeFunc: method is nil but MyInterface.Three was just called")
}
callInfo := struct {
}{}
lockMyInterfaceMockThree.Lock()
mock.calls.Three = append(mock.calls.Three, callInfo)
lockMyInterfaceMockThree.Unlock()
return mock.ThreeFunc()
} | [
"func",
"(",
"mock",
"*",
"MyInterfaceMock",
")",
"Three",
"(",
")",
"string",
"{",
"if",
"mock",
".",
"ThreeFunc",
"==",
"nil",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"callInfo",
":=",
"struct",
"{",
"}",
"{",
"}",
"\n",
"lockMyInterfaceMockThree",
".",
"Lock",
"(",
")",
"\n",
"mock",
".",
"calls",
".",
"Three",
"=",
"append",
"(",
"mock",
".",
"calls",
".",
"Three",
",",
"callInfo",
")",
"\n",
"lockMyInterfaceMockThree",
".",
"Unlock",
"(",
")",
"\n",
"return",
"mock",
".",
"ThreeFunc",
"(",
")",
"\n",
"}"
]
| // Three calls ThreeFunc. | [
"Three",
"calls",
"ThreeFunc",
"."
]
| 6cfb0558e1bd81d19c9909483c39e199634fed29 | https://github.com/matryer/moq/blob/6cfb0558e1bd81d19c9909483c39e199634fed29/generate/generated.go#L92-L102 |
8,899 | matryer/moq | generate/generated.go | Two | func (mock *MyInterfaceMock) Two() int {
if mock.TwoFunc == nil {
panic("MyInterfaceMock.TwoFunc: method is nil but MyInterface.Two was just called")
}
callInfo := struct {
}{}
lockMyInterfaceMockTwo.Lock()
mock.calls.Two = append(mock.calls.Two, callInfo)
lockMyInterfaceMockTwo.Unlock()
return mock.TwoFunc()
} | go | func (mock *MyInterfaceMock) Two() int {
if mock.TwoFunc == nil {
panic("MyInterfaceMock.TwoFunc: method is nil but MyInterface.Two was just called")
}
callInfo := struct {
}{}
lockMyInterfaceMockTwo.Lock()
mock.calls.Two = append(mock.calls.Two, callInfo)
lockMyInterfaceMockTwo.Unlock()
return mock.TwoFunc()
} | [
"func",
"(",
"mock",
"*",
"MyInterfaceMock",
")",
"Two",
"(",
")",
"int",
"{",
"if",
"mock",
".",
"TwoFunc",
"==",
"nil",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"callInfo",
":=",
"struct",
"{",
"}",
"{",
"}",
"\n",
"lockMyInterfaceMockTwo",
".",
"Lock",
"(",
")",
"\n",
"mock",
".",
"calls",
".",
"Two",
"=",
"append",
"(",
"mock",
".",
"calls",
".",
"Two",
",",
"callInfo",
")",
"\n",
"lockMyInterfaceMockTwo",
".",
"Unlock",
"(",
")",
"\n",
"return",
"mock",
".",
"TwoFunc",
"(",
")",
"\n",
"}"
]
| // Two calls TwoFunc. | [
"Two",
"calls",
"TwoFunc",
"."
]
| 6cfb0558e1bd81d19c9909483c39e199634fed29 | https://github.com/matryer/moq/blob/6cfb0558e1bd81d19c9909483c39e199634fed29/generate/generated.go#L118-L128 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.