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
|
|---|---|---|---|---|---|---|---|---|---|---|---|
19,600
|
gramework/gramework
|
router.go
|
HTTP
|
func (r *Router) HTTP() *Router {
if r.root != nil {
return r.root.HTTP()
}
r.mu.Lock()
if r.httprouter == nil {
r.httprouter = &Router{
router: newRouter(),
app: r.app,
root: r,
}
}
r.mu.Unlock()
return r.httprouter
}
|
go
|
func (r *Router) HTTP() *Router {
if r.root != nil {
return r.root.HTTP()
}
r.mu.Lock()
if r.httprouter == nil {
r.httprouter = &Router{
router: newRouter(),
app: r.app,
root: r,
}
}
r.mu.Unlock()
return r.httprouter
}
|
[
"func",
"(",
"r",
"*",
"Router",
")",
"HTTP",
"(",
")",
"*",
"Router",
"{",
"if",
"r",
".",
"root",
"!=",
"nil",
"{",
"return",
"r",
".",
"root",
".",
"HTTP",
"(",
")",
"\n",
"}",
"\n",
"r",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"if",
"r",
".",
"httprouter",
"==",
"nil",
"{",
"r",
".",
"httprouter",
"=",
"&",
"Router",
"{",
"router",
":",
"newRouter",
"(",
")",
",",
"app",
":",
"r",
".",
"app",
",",
"root",
":",
"r",
",",
"}",
"\n",
"}",
"\n",
"r",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n\n",
"return",
"r",
".",
"httprouter",
"\n",
"}"
] |
// HTTP router returns a router instance that work only on HTTP requests
|
[
"HTTP",
"router",
"returns",
"a",
"router",
"instance",
"that",
"work",
"only",
"on",
"HTTP",
"requests"
] |
31c8d0b9955432cea19730996643bd857481d6a8
|
https://github.com/gramework/gramework/blob/31c8d0b9955432cea19730996643bd857481d6a8/router.go#L259-L274
|
19,601
|
gramework/gramework
|
router.go
|
HTTPS
|
func (r *Router) HTTPS() *Router {
if r.root != nil {
return r.root.HTTPS()
}
r.mu.Lock()
if r.httpsrouter == nil {
r.httpsrouter = &Router{
router: newRouter(),
app: r.app,
root: r,
}
}
r.mu.Unlock()
return r.httpsrouter
}
|
go
|
func (r *Router) HTTPS() *Router {
if r.root != nil {
return r.root.HTTPS()
}
r.mu.Lock()
if r.httpsrouter == nil {
r.httpsrouter = &Router{
router: newRouter(),
app: r.app,
root: r,
}
}
r.mu.Unlock()
return r.httpsrouter
}
|
[
"func",
"(",
"r",
"*",
"Router",
")",
"HTTPS",
"(",
")",
"*",
"Router",
"{",
"if",
"r",
".",
"root",
"!=",
"nil",
"{",
"return",
"r",
".",
"root",
".",
"HTTPS",
"(",
")",
"\n",
"}",
"\n",
"r",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"if",
"r",
".",
"httpsrouter",
"==",
"nil",
"{",
"r",
".",
"httpsrouter",
"=",
"&",
"Router",
"{",
"router",
":",
"newRouter",
"(",
")",
",",
"app",
":",
"r",
".",
"app",
",",
"root",
":",
"r",
",",
"}",
"\n",
"}",
"\n",
"r",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n\n",
"return",
"r",
".",
"httpsrouter",
"\n",
"}"
] |
// HTTPS router returns a router instance that work only on HTTPS requests
|
[
"HTTPS",
"router",
"returns",
"a",
"router",
"instance",
"that",
"work",
"only",
"on",
"HTTPS",
"requests"
] |
31c8d0b9955432cea19730996643bd857481d6a8
|
https://github.com/gramework/gramework/blob/31c8d0b9955432cea19730996643bd857481d6a8/router.go#L277-L292
|
19,602
|
gramework/gramework
|
internal/gfmt/si.go
|
Si
|
func Si(n uint64) string {
suff := siRaw
x := float64(n)
for ; x >= 1024; x = x / 1024 {
suff++
}
return fmt.Sprintf("%.2f%s", x, suff.String())
}
|
go
|
func Si(n uint64) string {
suff := siRaw
x := float64(n)
for ; x >= 1024; x = x / 1024 {
suff++
}
return fmt.Sprintf("%.2f%s", x, suff.String())
}
|
[
"func",
"Si",
"(",
"n",
"uint64",
")",
"string",
"{",
"suff",
":=",
"siRaw",
"\n",
"x",
":=",
"float64",
"(",
"n",
")",
"\n",
"for",
";",
"x",
">=",
"1024",
";",
"x",
"=",
"x",
"/",
"1024",
"{",
"suff",
"++",
"\n",
"}",
"\n\n",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"x",
",",
"suff",
".",
"String",
"(",
")",
")",
"\n",
"}"
] |
// Si formats a number in a short si format
|
[
"Si",
"formats",
"a",
"number",
"in",
"a",
"short",
"si",
"format"
] |
31c8d0b9955432cea19730996643bd857481d6a8
|
https://github.com/gramework/gramework/blob/31c8d0b9955432cea19730996643bd857481d6a8/internal/gfmt/si.go#L6-L14
|
19,603
|
gramework/gramework
|
app_healthcheck.go
|
HealthHandler
|
func (app *App) HealthHandler(ctx *Context) {
var m runtime.MemStats
runtime.ReadMemStats(&m)
e := ctx.JSON(m)
_ = e
}
|
go
|
func (app *App) HealthHandler(ctx *Context) {
var m runtime.MemStats
runtime.ReadMemStats(&m)
e := ctx.JSON(m)
_ = e
}
|
[
"func",
"(",
"app",
"*",
"App",
")",
"HealthHandler",
"(",
"ctx",
"*",
"Context",
")",
"{",
"var",
"m",
"runtime",
".",
"MemStats",
"\n",
"runtime",
".",
"ReadMemStats",
"(",
"&",
"m",
")",
"\n\n",
"e",
":=",
"ctx",
".",
"JSON",
"(",
"m",
")",
"\n",
"_",
"=",
"e",
"\n",
"}"
] |
// HealthHandler serves info about memory usage
|
[
"HealthHandler",
"serves",
"info",
"about",
"memory",
"usage"
] |
31c8d0b9955432cea19730996643bd857481d6a8
|
https://github.com/gramework/gramework/blob/31c8d0b9955432cea19730996643bd857481d6a8/app_healthcheck.go#L18-L24
|
19,604
|
gramework/gramework
|
infrastructure/infrastructure_AddServiceServer.go
|
AddServiceServer
|
func (i *Infrastructure) AddServiceServer(serviceName string, addr Address) error {
i.Lock.RLock()
if _, ok := i.Services[serviceName]; !ok {
i.Lock.RUnlock()
return ErrServiceNotExists
}
i.Lock.RUnlock()
i.Lock.Lock()
if i.Services[serviceName].Addresses == nil {
i.Services[serviceName].Addresses = make([]Address, 0)
}
i.UpdateTimestamp = time.Now().UnixNano()
i.Services[serviceName].Addresses = append(i.Services[serviceName].Addresses, addr)
i.Lock.Unlock()
return nil
}
|
go
|
func (i *Infrastructure) AddServiceServer(serviceName string, addr Address) error {
i.Lock.RLock()
if _, ok := i.Services[serviceName]; !ok {
i.Lock.RUnlock()
return ErrServiceNotExists
}
i.Lock.RUnlock()
i.Lock.Lock()
if i.Services[serviceName].Addresses == nil {
i.Services[serviceName].Addresses = make([]Address, 0)
}
i.UpdateTimestamp = time.Now().UnixNano()
i.Services[serviceName].Addresses = append(i.Services[serviceName].Addresses, addr)
i.Lock.Unlock()
return nil
}
|
[
"func",
"(",
"i",
"*",
"Infrastructure",
")",
"AddServiceServer",
"(",
"serviceName",
"string",
",",
"addr",
"Address",
")",
"error",
"{",
"i",
".",
"Lock",
".",
"RLock",
"(",
")",
"\n",
"if",
"_",
",",
"ok",
":=",
"i",
".",
"Services",
"[",
"serviceName",
"]",
";",
"!",
"ok",
"{",
"i",
".",
"Lock",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"ErrServiceNotExists",
"\n",
"}",
"\n",
"i",
".",
"Lock",
".",
"RUnlock",
"(",
")",
"\n",
"i",
".",
"Lock",
".",
"Lock",
"(",
")",
"\n",
"if",
"i",
".",
"Services",
"[",
"serviceName",
"]",
".",
"Addresses",
"==",
"nil",
"{",
"i",
".",
"Services",
"[",
"serviceName",
"]",
".",
"Addresses",
"=",
"make",
"(",
"[",
"]",
"Address",
",",
"0",
")",
"\n",
"}",
"\n",
"i",
".",
"UpdateTimestamp",
"=",
"time",
".",
"Now",
"(",
")",
".",
"UnixNano",
"(",
")",
"\n",
"i",
".",
"Services",
"[",
"serviceName",
"]",
".",
"Addresses",
"=",
"append",
"(",
"i",
".",
"Services",
"[",
"serviceName",
"]",
".",
"Addresses",
",",
"addr",
")",
"\n",
"i",
".",
"Lock",
".",
"Unlock",
"(",
")",
"\n",
"return",
"nil",
"\n",
"}"
] |
// AddServiceServer registers server to a service in the infrastructure
|
[
"AddServiceServer",
"registers",
"server",
"to",
"a",
"service",
"in",
"the",
"infrastructure"
] |
31c8d0b9955432cea19730996643bd857481d6a8
|
https://github.com/gramework/gramework/blob/31c8d0b9955432cea19730996643bd857481d6a8/infrastructure/infrastructure_AddServiceServer.go#L13-L28
|
19,605
|
gramework/gramework
|
metrics/metrics.go
|
Register
|
func Register(app *gramework.App, serviceName ...string) error {
var m Middleware
name := os.Args[0]
if len(serviceName) > 0 {
name = serviceName[0]
}
hostname, err := os.Hostname()
if err != nil {
return err
}
m.httpReqCounter = prometheus.NewCounterVec(
prometheus.CounterOpts{
Name: "gramework_http_requests_total",
Help: "Total count of HTTP requests processed, partitioned by code, method, path and type (HTTP/HTTPS)",
ConstLabels: prometheus.Labels{
"service": name,
"node": hostname,
},
},
[]string{"code", "method", "path", "type"},
)
if err = prometheus.Register(m.httpReqCounter); err != nil {
return err
}
m.reqDuration = prometheus.NewHistogramVec(
prometheus.HistogramOpts{
Name: "gramework_http_requests_duration_seconds",
Help: "Request processing duration, partitioned by code, method, path and type (HTTP/HTTPS)",
ConstLabels: prometheus.Labels{
"service": name,
"node": hostname,
},
},
[]string{"code", "method", "path", "type"},
)
if err = prometheus.Register(m.reqDuration); err != nil {
return err
}
app.GET(string(metricsPath), gramework.NewGrameHandler(promhttp.Handler()))
if err = app.UsePre(m.startReq); err != nil {
return err
}
return app.UseAfterRequest(m.endReq)
}
|
go
|
func Register(app *gramework.App, serviceName ...string) error {
var m Middleware
name := os.Args[0]
if len(serviceName) > 0 {
name = serviceName[0]
}
hostname, err := os.Hostname()
if err != nil {
return err
}
m.httpReqCounter = prometheus.NewCounterVec(
prometheus.CounterOpts{
Name: "gramework_http_requests_total",
Help: "Total count of HTTP requests processed, partitioned by code, method, path and type (HTTP/HTTPS)",
ConstLabels: prometheus.Labels{
"service": name,
"node": hostname,
},
},
[]string{"code", "method", "path", "type"},
)
if err = prometheus.Register(m.httpReqCounter); err != nil {
return err
}
m.reqDuration = prometheus.NewHistogramVec(
prometheus.HistogramOpts{
Name: "gramework_http_requests_duration_seconds",
Help: "Request processing duration, partitioned by code, method, path and type (HTTP/HTTPS)",
ConstLabels: prometheus.Labels{
"service": name,
"node": hostname,
},
},
[]string{"code", "method", "path", "type"},
)
if err = prometheus.Register(m.reqDuration); err != nil {
return err
}
app.GET(string(metricsPath), gramework.NewGrameHandler(promhttp.Handler()))
if err = app.UsePre(m.startReq); err != nil {
return err
}
return app.UseAfterRequest(m.endReq)
}
|
[
"func",
"Register",
"(",
"app",
"*",
"gramework",
".",
"App",
",",
"serviceName",
"...",
"string",
")",
"error",
"{",
"var",
"m",
"Middleware",
"\n",
"name",
":=",
"os",
".",
"Args",
"[",
"0",
"]",
"\n",
"if",
"len",
"(",
"serviceName",
")",
">",
"0",
"{",
"name",
"=",
"serviceName",
"[",
"0",
"]",
"\n",
"}",
"\n\n",
"hostname",
",",
"err",
":=",
"os",
".",
"Hostname",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"m",
".",
"httpReqCounter",
"=",
"prometheus",
".",
"NewCounterVec",
"(",
"prometheus",
".",
"CounterOpts",
"{",
"Name",
":",
"\"",
"\"",
",",
"Help",
":",
"\"",
"\"",
",",
"ConstLabels",
":",
"prometheus",
".",
"Labels",
"{",
"\"",
"\"",
":",
"name",
",",
"\"",
"\"",
":",
"hostname",
",",
"}",
",",
"}",
",",
"[",
"]",
"string",
"{",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
"}",
",",
")",
"\n",
"if",
"err",
"=",
"prometheus",
".",
"Register",
"(",
"m",
".",
"httpReqCounter",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"m",
".",
"reqDuration",
"=",
"prometheus",
".",
"NewHistogramVec",
"(",
"prometheus",
".",
"HistogramOpts",
"{",
"Name",
":",
"\"",
"\"",
",",
"Help",
":",
"\"",
"\"",
",",
"ConstLabels",
":",
"prometheus",
".",
"Labels",
"{",
"\"",
"\"",
":",
"name",
",",
"\"",
"\"",
":",
"hostname",
",",
"}",
",",
"}",
",",
"[",
"]",
"string",
"{",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
"}",
",",
")",
"\n\n",
"if",
"err",
"=",
"prometheus",
".",
"Register",
"(",
"m",
".",
"reqDuration",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"app",
".",
"GET",
"(",
"string",
"(",
"metricsPath",
")",
",",
"gramework",
".",
"NewGrameHandler",
"(",
"promhttp",
".",
"Handler",
"(",
")",
")",
")",
"\n\n",
"if",
"err",
"=",
"app",
".",
"UsePre",
"(",
"m",
".",
"startReq",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"return",
"app",
".",
"UseAfterRequest",
"(",
"m",
".",
"endReq",
")",
"\n",
"}"
] |
// Register the middlewares
|
[
"Register",
"the",
"middlewares"
] |
31c8d0b9955432cea19730996643bd857481d6a8
|
https://github.com/gramework/gramework/blob/31c8d0b9955432cea19730996643bd857481d6a8/metrics/metrics.go#L33-L83
|
19,606
|
gramework/gramework
|
app.go
|
SetCookieExpire
|
func (app *App) SetCookieExpire(d time.Duration) {
if d != 0 {
app.cookieExpire = d
}
}
|
go
|
func (app *App) SetCookieExpire(d time.Duration) {
if d != 0 {
app.cookieExpire = d
}
}
|
[
"func",
"(",
"app",
"*",
"App",
")",
"SetCookieExpire",
"(",
"d",
"time",
".",
"Duration",
")",
"{",
"if",
"d",
"!=",
"0",
"{",
"app",
".",
"cookieExpire",
"=",
"d",
"\n",
"}",
"\n",
"}"
] |
// SetCookieExpire allows you set cookie expire time
|
[
"SetCookieExpire",
"allows",
"you",
"set",
"cookie",
"expire",
"time"
] |
31c8d0b9955432cea19730996643bd857481d6a8
|
https://github.com/gramework/gramework/blob/31c8d0b9955432cea19730996643bd857481d6a8/app.go#L31-L35
|
19,607
|
gramework/gramework
|
app.go
|
SetSanitizerPolicy
|
func (app *App) SetSanitizerPolicy(newPolicy *bluemonday.Policy) {
if newPolicy != nil {
app.sanitizerPolicy = newPolicy
}
}
|
go
|
func (app *App) SetSanitizerPolicy(newPolicy *bluemonday.Policy) {
if newPolicy != nil {
app.sanitizerPolicy = newPolicy
}
}
|
[
"func",
"(",
"app",
"*",
"App",
")",
"SetSanitizerPolicy",
"(",
"newPolicy",
"*",
"bluemonday",
".",
"Policy",
")",
"{",
"if",
"newPolicy",
"!=",
"nil",
"{",
"app",
".",
"sanitizerPolicy",
"=",
"newPolicy",
"\n",
"}",
"\n",
"}"
] |
// SetSanitizerPolicy updates app's sanitizer policy to a new one, if newPolicy is not nil
|
[
"SetSanitizerPolicy",
"updates",
"app",
"s",
"sanitizer",
"policy",
"to",
"a",
"new",
"one",
"if",
"newPolicy",
"is",
"not",
"nil"
] |
31c8d0b9955432cea19730996643bd857481d6a8
|
https://github.com/gramework/gramework/blob/31c8d0b9955432cea19730996643bd857481d6a8/app.go#L49-L53
|
19,608
|
gramework/gramework
|
app_shutdown.go
|
Shutdown
|
func (app *App) Shutdown() (err error) {
app.runningServersMu.Lock()
// this is not a hot path, we can freely use defer here
defer app.runningServersMu.Unlock()
newRunningList := []runningServerInfo{}
for _, info := range app.runningServers {
app.internalLog.WithField("bind", info.bind).Warn("shutting down server")
err = info.srv.Shutdown()
if err != nil {
app.internalLog.WithError(err).Error("could not shutdown server")
newRunningList = append(newRunningList, info)
continue
}
}
app.runningServers = newRunningList
if err == nil {
app.internalLog.Warn("application servers shutted down successfully")
return
}
app.internalLog.WithError(err).WithField("stillRunning", len(app.runningServers)).Warn("could not stop servers")
return
}
|
go
|
func (app *App) Shutdown() (err error) {
app.runningServersMu.Lock()
// this is not a hot path, we can freely use defer here
defer app.runningServersMu.Unlock()
newRunningList := []runningServerInfo{}
for _, info := range app.runningServers {
app.internalLog.WithField("bind", info.bind).Warn("shutting down server")
err = info.srv.Shutdown()
if err != nil {
app.internalLog.WithError(err).Error("could not shutdown server")
newRunningList = append(newRunningList, info)
continue
}
}
app.runningServers = newRunningList
if err == nil {
app.internalLog.Warn("application servers shutted down successfully")
return
}
app.internalLog.WithError(err).WithField("stillRunning", len(app.runningServers)).Warn("could not stop servers")
return
}
|
[
"func",
"(",
"app",
"*",
"App",
")",
"Shutdown",
"(",
")",
"(",
"err",
"error",
")",
"{",
"app",
".",
"runningServersMu",
".",
"Lock",
"(",
")",
"\n",
"// this is not a hot path, we can freely use defer here",
"defer",
"app",
".",
"runningServersMu",
".",
"Unlock",
"(",
")",
"\n\n",
"newRunningList",
":=",
"[",
"]",
"runningServerInfo",
"{",
"}",
"\n",
"for",
"_",
",",
"info",
":=",
"range",
"app",
".",
"runningServers",
"{",
"app",
".",
"internalLog",
".",
"WithField",
"(",
"\"",
"\"",
",",
"info",
".",
"bind",
")",
".",
"Warn",
"(",
"\"",
"\"",
")",
"\n",
"err",
"=",
"info",
".",
"srv",
".",
"Shutdown",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"app",
".",
"internalLog",
".",
"WithError",
"(",
"err",
")",
".",
"Error",
"(",
"\"",
"\"",
")",
"\n",
"newRunningList",
"=",
"append",
"(",
"newRunningList",
",",
"info",
")",
"\n",
"continue",
"\n",
"}",
"\n",
"}",
"\n\n",
"app",
".",
"runningServers",
"=",
"newRunningList",
"\n\n",
"if",
"err",
"==",
"nil",
"{",
"app",
".",
"internalLog",
".",
"Warn",
"(",
"\"",
"\"",
")",
"\n",
"return",
"\n",
"}",
"\n",
"app",
".",
"internalLog",
".",
"WithError",
"(",
"err",
")",
".",
"WithField",
"(",
"\"",
"\"",
",",
"len",
"(",
"app",
".",
"runningServers",
")",
")",
".",
"Warn",
"(",
"\"",
"\"",
")",
"\n",
"return",
"\n",
"}"
] |
// Shutdown gracefully shuts down application servers
|
[
"Shutdown",
"gracefully",
"shuts",
"down",
"application",
"servers"
] |
31c8d0b9955432cea19730996643bd857481d6a8
|
https://github.com/gramework/gramework/blob/31c8d0b9955432cea19730996643bd857481d6a8/app_shutdown.go#L4-L28
|
19,609
|
gramework/gramework
|
behind/akamai/akamai.go
|
New
|
func New(opts ...Option) *Unwrapper {
a := &Unwrapper{
ipHeader: DefaultAkamaiIPHeader,
}
for _, opt := range opts {
opt(a)
}
return a
}
|
go
|
func New(opts ...Option) *Unwrapper {
a := &Unwrapper{
ipHeader: DefaultAkamaiIPHeader,
}
for _, opt := range opts {
opt(a)
}
return a
}
|
[
"func",
"New",
"(",
"opts",
"...",
"Option",
")",
"*",
"Unwrapper",
"{",
"a",
":=",
"&",
"Unwrapper",
"{",
"ipHeader",
":",
"DefaultAkamaiIPHeader",
",",
"}",
"\n\n",
"for",
"_",
",",
"opt",
":=",
"range",
"opts",
"{",
"opt",
"(",
"a",
")",
"\n",
"}",
"\n\n",
"return",
"a",
"\n",
"}"
] |
// New creates an unwrapper, optimized for Akamai network
|
[
"New",
"creates",
"an",
"unwrapper",
"optimized",
"for",
"Akamai",
"network"
] |
31c8d0b9955432cea19730996643bd857481d6a8
|
https://github.com/gramework/gramework/blob/31c8d0b9955432cea19730996643bd857481d6a8/behind/akamai/akamai.go#L62-L72
|
19,610
|
gramework/gramework
|
tolower_go112.go
|
toLower
|
func toLower(s string) string {
isASCII, hasUpper := true, false
for i := 0; i < len(s); i++ {
c := s[i]
if c >= utf8.RuneSelf {
isASCII = false
break
}
hasUpper = hasUpper || (c >= 'A' && c <= 'Z')
}
if isASCII { // optimize for ASCII-only strings.
if !hasUpper {
return s
}
var b strings.Builder
b.Grow(len(s))
for i := 0; i < len(s); i++ {
c := s[i]
if c >= 'A' && c <= 'Z' {
c += 'a' - 'A'
}
b.WriteByte(c)
}
return b.String()
}
return stringsMap(unicode.ToLower, s)
}
|
go
|
func toLower(s string) string {
isASCII, hasUpper := true, false
for i := 0; i < len(s); i++ {
c := s[i]
if c >= utf8.RuneSelf {
isASCII = false
break
}
hasUpper = hasUpper || (c >= 'A' && c <= 'Z')
}
if isASCII { // optimize for ASCII-only strings.
if !hasUpper {
return s
}
var b strings.Builder
b.Grow(len(s))
for i := 0; i < len(s); i++ {
c := s[i]
if c >= 'A' && c <= 'Z' {
c += 'a' - 'A'
}
b.WriteByte(c)
}
return b.String()
}
return stringsMap(unicode.ToLower, s)
}
|
[
"func",
"toLower",
"(",
"s",
"string",
")",
"string",
"{",
"isASCII",
",",
"hasUpper",
":=",
"true",
",",
"false",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"len",
"(",
"s",
")",
";",
"i",
"++",
"{",
"c",
":=",
"s",
"[",
"i",
"]",
"\n",
"if",
"c",
">=",
"utf8",
".",
"RuneSelf",
"{",
"isASCII",
"=",
"false",
"\n",
"break",
"\n",
"}",
"\n",
"hasUpper",
"=",
"hasUpper",
"||",
"(",
"c",
">=",
"'A'",
"&&",
"c",
"<=",
"'Z'",
")",
"\n",
"}",
"\n\n",
"if",
"isASCII",
"{",
"// optimize for ASCII-only strings.",
"if",
"!",
"hasUpper",
"{",
"return",
"s",
"\n",
"}",
"\n",
"var",
"b",
"strings",
".",
"Builder",
"\n",
"b",
".",
"Grow",
"(",
"len",
"(",
"s",
")",
")",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"len",
"(",
"s",
")",
";",
"i",
"++",
"{",
"c",
":=",
"s",
"[",
"i",
"]",
"\n",
"if",
"c",
">=",
"'A'",
"&&",
"c",
"<=",
"'Z'",
"{",
"c",
"+=",
"'a'",
"-",
"'A'",
"\n",
"}",
"\n",
"b",
".",
"WriteByte",
"(",
"c",
")",
"\n",
"}",
"\n",
"return",
"b",
".",
"String",
"(",
")",
"\n",
"}",
"\n",
"return",
"stringsMap",
"(",
"unicode",
".",
"ToLower",
",",
"s",
")",
"\n",
"}"
] |
// toLower returns a copy of the string s with all Unicode letters mapped to their lower case.
|
[
"toLower",
"returns",
"a",
"copy",
"of",
"the",
"string",
"s",
"with",
"all",
"Unicode",
"letters",
"mapped",
"to",
"their",
"lower",
"case",
"."
] |
31c8d0b9955432cea19730996643bd857481d6a8
|
https://github.com/gramework/gramework/blob/31c8d0b9955432cea19730996643bd857481d6a8/tolower_go112.go#L16-L43
|
19,611
|
gramework/gramework
|
tolower_go112.go
|
stringsMap
|
func stringsMap(mapping func(rune) rune, s string) string {
// In the worst case, the string can grow when mapped, making
// things unpleasant. But it's so rare we barge in assuming it's
// fine. It could also shrink but that falls out naturally.
// The output buffer b is initialized on demand, the first
// time a character differs.
var b strings.Builder
for i, c := range s {
r := mapping(c)
if r == c {
continue
}
b.Grow(len(s) + utf8.UTFMax)
b.WriteString(s[:i])
if r >= 0 {
b.WriteRune(r)
}
if c == utf8.RuneError {
// RuneError is the result of either decoding
// an invalid sequence or '\uFFFD'. Determine
// the correct number of bytes we need to advance.
_, w := utf8.DecodeRuneInString(s[i:])
i += w
} else {
i += utf8.RuneLen(c)
}
s = s[i:]
break
}
// Fast path for unchanged input
if b.Cap() == 0 { // didn't call b.Grow above
return s
}
for _, c := range s {
r := mapping(c)
if r >= 0 {
// common case
// Due to inlining, it is more performant to determine if WriteByte should be
// invoked rather than always call WriteRune
if r < utf8.RuneSelf {
b.WriteByte(byte(r))
} else {
// r is not a ASCII rune.
b.WriteRune(r)
}
}
}
return b.String()
}
|
go
|
func stringsMap(mapping func(rune) rune, s string) string {
// In the worst case, the string can grow when mapped, making
// things unpleasant. But it's so rare we barge in assuming it's
// fine. It could also shrink but that falls out naturally.
// The output buffer b is initialized on demand, the first
// time a character differs.
var b strings.Builder
for i, c := range s {
r := mapping(c)
if r == c {
continue
}
b.Grow(len(s) + utf8.UTFMax)
b.WriteString(s[:i])
if r >= 0 {
b.WriteRune(r)
}
if c == utf8.RuneError {
// RuneError is the result of either decoding
// an invalid sequence or '\uFFFD'. Determine
// the correct number of bytes we need to advance.
_, w := utf8.DecodeRuneInString(s[i:])
i += w
} else {
i += utf8.RuneLen(c)
}
s = s[i:]
break
}
// Fast path for unchanged input
if b.Cap() == 0 { // didn't call b.Grow above
return s
}
for _, c := range s {
r := mapping(c)
if r >= 0 {
// common case
// Due to inlining, it is more performant to determine if WriteByte should be
// invoked rather than always call WriteRune
if r < utf8.RuneSelf {
b.WriteByte(byte(r))
} else {
// r is not a ASCII rune.
b.WriteRune(r)
}
}
}
return b.String()
}
|
[
"func",
"stringsMap",
"(",
"mapping",
"func",
"(",
"rune",
")",
"rune",
",",
"s",
"string",
")",
"string",
"{",
"// In the worst case, the string can grow when mapped, making",
"// things unpleasant. But it's so rare we barge in assuming it's",
"// fine. It could also shrink but that falls out naturally.",
"// The output buffer b is initialized on demand, the first",
"// time a character differs.",
"var",
"b",
"strings",
".",
"Builder",
"\n\n",
"for",
"i",
",",
"c",
":=",
"range",
"s",
"{",
"r",
":=",
"mapping",
"(",
"c",
")",
"\n",
"if",
"r",
"==",
"c",
"{",
"continue",
"\n",
"}",
"\n\n",
"b",
".",
"Grow",
"(",
"len",
"(",
"s",
")",
"+",
"utf8",
".",
"UTFMax",
")",
"\n",
"b",
".",
"WriteString",
"(",
"s",
"[",
":",
"i",
"]",
")",
"\n",
"if",
"r",
">=",
"0",
"{",
"b",
".",
"WriteRune",
"(",
"r",
")",
"\n",
"}",
"\n\n",
"if",
"c",
"==",
"utf8",
".",
"RuneError",
"{",
"// RuneError is the result of either decoding",
"// an invalid sequence or '\\uFFFD'. Determine",
"// the correct number of bytes we need to advance.",
"_",
",",
"w",
":=",
"utf8",
".",
"DecodeRuneInString",
"(",
"s",
"[",
"i",
":",
"]",
")",
"\n",
"i",
"+=",
"w",
"\n",
"}",
"else",
"{",
"i",
"+=",
"utf8",
".",
"RuneLen",
"(",
"c",
")",
"\n",
"}",
"\n\n",
"s",
"=",
"s",
"[",
"i",
":",
"]",
"\n",
"break",
"\n",
"}",
"\n\n",
"// Fast path for unchanged input",
"if",
"b",
".",
"Cap",
"(",
")",
"==",
"0",
"{",
"// didn't call b.Grow above",
"return",
"s",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"c",
":=",
"range",
"s",
"{",
"r",
":=",
"mapping",
"(",
"c",
")",
"\n\n",
"if",
"r",
">=",
"0",
"{",
"// common case",
"// Due to inlining, it is more performant to determine if WriteByte should be",
"// invoked rather than always call WriteRune",
"if",
"r",
"<",
"utf8",
".",
"RuneSelf",
"{",
"b",
".",
"WriteByte",
"(",
"byte",
"(",
"r",
")",
")",
"\n",
"}",
"else",
"{",
"// r is not a ASCII rune.",
"b",
".",
"WriteRune",
"(",
"r",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"b",
".",
"String",
"(",
")",
"\n",
"}"
] |
// Map returns a copy of the string s with all its characters modified
// according to the mapping function. If mapping returns a negative value, the character is
// dropped from the string with no replacement.
|
[
"Map",
"returns",
"a",
"copy",
"of",
"the",
"string",
"s",
"with",
"all",
"its",
"characters",
"modified",
"according",
"to",
"the",
"mapping",
"function",
".",
"If",
"mapping",
"returns",
"a",
"negative",
"value",
"the",
"character",
"is",
"dropped",
"from",
"the",
"string",
"with",
"no",
"replacement",
"."
] |
31c8d0b9955432cea19730996643bd857481d6a8
|
https://github.com/gramework/gramework/blob/31c8d0b9955432cea19730996643bd857481d6a8/tolower_go112.go#L48-L105
|
19,612
|
gramework/gramework
|
infrastructure/infrastructure_RegisterService.go
|
RegisterService
|
func (i *Infrastructure) RegisterService(name string, s Service) error {
i.Lock.RLock()
if _, ok := i.Services[name]; ok {
i.Lock.RUnlock()
return ErrServiceExists
}
i.Lock.RUnlock()
i.Lock.Lock()
if s.Name == "" {
s.Name = name
}
i.Services[name] = &s
i.Lock.Unlock()
return nil
}
|
go
|
func (i *Infrastructure) RegisterService(name string, s Service) error {
i.Lock.RLock()
if _, ok := i.Services[name]; ok {
i.Lock.RUnlock()
return ErrServiceExists
}
i.Lock.RUnlock()
i.Lock.Lock()
if s.Name == "" {
s.Name = name
}
i.Services[name] = &s
i.Lock.Unlock()
return nil
}
|
[
"func",
"(",
"i",
"*",
"Infrastructure",
")",
"RegisterService",
"(",
"name",
"string",
",",
"s",
"Service",
")",
"error",
"{",
"i",
".",
"Lock",
".",
"RLock",
"(",
")",
"\n",
"if",
"_",
",",
"ok",
":=",
"i",
".",
"Services",
"[",
"name",
"]",
";",
"ok",
"{",
"i",
".",
"Lock",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"ErrServiceExists",
"\n",
"}",
"\n",
"i",
".",
"Lock",
".",
"RUnlock",
"(",
")",
"\n",
"i",
".",
"Lock",
".",
"Lock",
"(",
")",
"\n",
"if",
"s",
".",
"Name",
"==",
"\"",
"\"",
"{",
"s",
".",
"Name",
"=",
"name",
"\n",
"}",
"\n",
"i",
".",
"Services",
"[",
"name",
"]",
"=",
"&",
"s",
"\n",
"i",
".",
"Lock",
".",
"Unlock",
"(",
")",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// RegisterService in the infrastructure
|
[
"RegisterService",
"in",
"the",
"infrastructure"
] |
31c8d0b9955432cea19730996643bd857481d6a8
|
https://github.com/gramework/gramework/blob/31c8d0b9955432cea19730996643bd857481d6a8/infrastructure/infrastructure_RegisterService.go#L13-L28
|
19,613
|
gramework/gramework
|
infrastructure/infrastructure_RegisterService.go
|
MergeService
|
func (i *Infrastructure) MergeService(name string, s Service) {
i.Lock.Lock()
if _, ok := i.Services[name]; ok {
i.Services[name].Addresses = append(i.Services[name].Addresses, s.Addresses...)
i.Lock.Unlock()
return
}
i.Services[name] = &s
i.Lock.Unlock()
}
|
go
|
func (i *Infrastructure) MergeService(name string, s Service) {
i.Lock.Lock()
if _, ok := i.Services[name]; ok {
i.Services[name].Addresses = append(i.Services[name].Addresses, s.Addresses...)
i.Lock.Unlock()
return
}
i.Services[name] = &s
i.Lock.Unlock()
}
|
[
"func",
"(",
"i",
"*",
"Infrastructure",
")",
"MergeService",
"(",
"name",
"string",
",",
"s",
"Service",
")",
"{",
"i",
".",
"Lock",
".",
"Lock",
"(",
")",
"\n",
"if",
"_",
",",
"ok",
":=",
"i",
".",
"Services",
"[",
"name",
"]",
";",
"ok",
"{",
"i",
".",
"Services",
"[",
"name",
"]",
".",
"Addresses",
"=",
"append",
"(",
"i",
".",
"Services",
"[",
"name",
"]",
".",
"Addresses",
",",
"s",
".",
"Addresses",
"...",
")",
"\n",
"i",
".",
"Lock",
".",
"Unlock",
"(",
")",
"\n",
"return",
"\n",
"}",
"\n",
"i",
".",
"Services",
"[",
"name",
"]",
"=",
"&",
"s",
"\n",
"i",
".",
"Lock",
".",
"Unlock",
"(",
")",
"\n",
"}"
] |
// MergeService in the infrastructure
|
[
"MergeService",
"in",
"the",
"infrastructure"
] |
31c8d0b9955432cea19730996643bd857481d6a8
|
https://github.com/gramework/gramework/blob/31c8d0b9955432cea19730996643bd857481d6a8/infrastructure/infrastructure_RegisterService.go#L53-L62
|
19,614
|
gramework/gramework
|
log.go
|
SetEnv
|
func SetEnv(e Environment) {
if e != DEV && e != STAGE && e != PROD {
internalLog.Warn("could not set unknown environment value, ignoring")
return
}
if e != GetEnv() {
internalLog.
WithField("prevEnv", GetEnv()).
WithField("newEnv", e).
Warn("Setting a new environment")
}
if e == PROD {
Logger.Level = log.InfoLevel
enableDebug = false
} else {
enableDebug = true
Logger.Level = log.DebugLevel
}
atomic.StoreInt32(currentEnvironment, int32(e))
}
|
go
|
func SetEnv(e Environment) {
if e != DEV && e != STAGE && e != PROD {
internalLog.Warn("could not set unknown environment value, ignoring")
return
}
if e != GetEnv() {
internalLog.
WithField("prevEnv", GetEnv()).
WithField("newEnv", e).
Warn("Setting a new environment")
}
if e == PROD {
Logger.Level = log.InfoLevel
enableDebug = false
} else {
enableDebug = true
Logger.Level = log.DebugLevel
}
atomic.StoreInt32(currentEnvironment, int32(e))
}
|
[
"func",
"SetEnv",
"(",
"e",
"Environment",
")",
"{",
"if",
"e",
"!=",
"DEV",
"&&",
"e",
"!=",
"STAGE",
"&&",
"e",
"!=",
"PROD",
"{",
"internalLog",
".",
"Warn",
"(",
"\"",
"\"",
")",
"\n",
"return",
"\n",
"}",
"\n",
"if",
"e",
"!=",
"GetEnv",
"(",
")",
"{",
"internalLog",
".",
"WithField",
"(",
"\"",
"\"",
",",
"GetEnv",
"(",
")",
")",
".",
"WithField",
"(",
"\"",
"\"",
",",
"e",
")",
".",
"Warn",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"e",
"==",
"PROD",
"{",
"Logger",
".",
"Level",
"=",
"log",
".",
"InfoLevel",
"\n",
"enableDebug",
"=",
"false",
"\n",
"}",
"else",
"{",
"enableDebug",
"=",
"true",
"\n",
"Logger",
".",
"Level",
"=",
"log",
".",
"DebugLevel",
"\n",
"}",
"\n",
"atomic",
".",
"StoreInt32",
"(",
"currentEnvironment",
",",
"int32",
"(",
"e",
")",
")",
"\n",
"}"
] |
// SetEnv sets gramework's environment
|
[
"SetEnv",
"sets",
"gramework",
"s",
"environment"
] |
31c8d0b9955432cea19730996643bd857481d6a8
|
https://github.com/gramework/gramework/blob/31c8d0b9955432cea19730996643bd857481d6a8/log.go#L81-L100
|
19,615
|
gramework/gramework
|
app_listenAndServeAutoTLS.go
|
ListenAndServeAutoTLS
|
func (app *App) ListenAndServeAutoTLS(addr string, cachePath ...string) error {
if len(app.TLSEmails) == 0 {
return ErrTLSNoEmails
}
addr, err := normalizeTLSAddr(addr)
if err != nil {
app.internalLog.Errorf("Bad address %q: %s", addr, err)
}
ln, err := net.Listen("tcp", addr)
if err != nil {
app.internalLog.Errorf("Can't serve %q: %s", addr, err)
return err
}
letscache := getCachePath()
if len(cachePath) > 0 {
letscache = cachePath[0]
}
s := rand.NewSource(time.Now().Unix())
r := rand.New(s)
m := autocert.Manager{
Prompt: autocert.AcceptTOS,
Email: app.TLSEmails[r.Intn(len(app.TLSEmails))],
}
if letscache != "" {
m.Cache = autocert.DirCache(letscache)
}
tlsConfig := getDefaultTLSConfig()
tlsConfig.GetCertificate = func(hello *tls.ClientHelloInfo) (cert *tls.Certificate, err error) {
if len(hello.ServerName) == 0 || hello.ServerName == localhost {
hello.ServerName = localhost
cert, err = selfSignedCertificate(hello)
} else {
cert, err = m.GetCertificate(hello)
}
if err != nil {
app.internalLog.Errorf("Can't get cert for %q: %s", hello.ServerName, err)
}
return cert, err
}
tlsLn := tls.NewListener(ln, tlsConfig)
l := app.internalLog.WithField("bind", addr)
l.Info("Starting HTTPS")
srv := app.copyServer()
app.runningServersMu.Lock()
app.runningServers = append(app.runningServers, runningServerInfo{
bind: addr,
srv: srv,
})
app.runningServersMu.Unlock()
if err = srv.Serve(tlsLn); err != nil {
app.internalLog.Errorf("Can't serve: %s", err)
}
return err
}
|
go
|
func (app *App) ListenAndServeAutoTLS(addr string, cachePath ...string) error {
if len(app.TLSEmails) == 0 {
return ErrTLSNoEmails
}
addr, err := normalizeTLSAddr(addr)
if err != nil {
app.internalLog.Errorf("Bad address %q: %s", addr, err)
}
ln, err := net.Listen("tcp", addr)
if err != nil {
app.internalLog.Errorf("Can't serve %q: %s", addr, err)
return err
}
letscache := getCachePath()
if len(cachePath) > 0 {
letscache = cachePath[0]
}
s := rand.NewSource(time.Now().Unix())
r := rand.New(s)
m := autocert.Manager{
Prompt: autocert.AcceptTOS,
Email: app.TLSEmails[r.Intn(len(app.TLSEmails))],
}
if letscache != "" {
m.Cache = autocert.DirCache(letscache)
}
tlsConfig := getDefaultTLSConfig()
tlsConfig.GetCertificate = func(hello *tls.ClientHelloInfo) (cert *tls.Certificate, err error) {
if len(hello.ServerName) == 0 || hello.ServerName == localhost {
hello.ServerName = localhost
cert, err = selfSignedCertificate(hello)
} else {
cert, err = m.GetCertificate(hello)
}
if err != nil {
app.internalLog.Errorf("Can't get cert for %q: %s", hello.ServerName, err)
}
return cert, err
}
tlsLn := tls.NewListener(ln, tlsConfig)
l := app.internalLog.WithField("bind", addr)
l.Info("Starting HTTPS")
srv := app.copyServer()
app.runningServersMu.Lock()
app.runningServers = append(app.runningServers, runningServerInfo{
bind: addr,
srv: srv,
})
app.runningServersMu.Unlock()
if err = srv.Serve(tlsLn); err != nil {
app.internalLog.Errorf("Can't serve: %s", err)
}
return err
}
|
[
"func",
"(",
"app",
"*",
"App",
")",
"ListenAndServeAutoTLS",
"(",
"addr",
"string",
",",
"cachePath",
"...",
"string",
")",
"error",
"{",
"if",
"len",
"(",
"app",
".",
"TLSEmails",
")",
"==",
"0",
"{",
"return",
"ErrTLSNoEmails",
"\n",
"}",
"\n\n",
"addr",
",",
"err",
":=",
"normalizeTLSAddr",
"(",
"addr",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"app",
".",
"internalLog",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"addr",
",",
"err",
")",
"\n",
"}",
"\n\n",
"ln",
",",
"err",
":=",
"net",
".",
"Listen",
"(",
"\"",
"\"",
",",
"addr",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"app",
".",
"internalLog",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"addr",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"letscache",
":=",
"getCachePath",
"(",
")",
"\n",
"if",
"len",
"(",
"cachePath",
")",
">",
"0",
"{",
"letscache",
"=",
"cachePath",
"[",
"0",
"]",
"\n",
"}",
"\n\n",
"s",
":=",
"rand",
".",
"NewSource",
"(",
"time",
".",
"Now",
"(",
")",
".",
"Unix",
"(",
")",
")",
"\n",
"r",
":=",
"rand",
".",
"New",
"(",
"s",
")",
"\n",
"m",
":=",
"autocert",
".",
"Manager",
"{",
"Prompt",
":",
"autocert",
".",
"AcceptTOS",
",",
"Email",
":",
"app",
".",
"TLSEmails",
"[",
"r",
".",
"Intn",
"(",
"len",
"(",
"app",
".",
"TLSEmails",
")",
")",
"]",
",",
"}",
"\n\n",
"if",
"letscache",
"!=",
"\"",
"\"",
"{",
"m",
".",
"Cache",
"=",
"autocert",
".",
"DirCache",
"(",
"letscache",
")",
"\n",
"}",
"\n\n",
"tlsConfig",
":=",
"getDefaultTLSConfig",
"(",
")",
"\n",
"tlsConfig",
".",
"GetCertificate",
"=",
"func",
"(",
"hello",
"*",
"tls",
".",
"ClientHelloInfo",
")",
"(",
"cert",
"*",
"tls",
".",
"Certificate",
",",
"err",
"error",
")",
"{",
"if",
"len",
"(",
"hello",
".",
"ServerName",
")",
"==",
"0",
"||",
"hello",
".",
"ServerName",
"==",
"localhost",
"{",
"hello",
".",
"ServerName",
"=",
"localhost",
"\n",
"cert",
",",
"err",
"=",
"selfSignedCertificate",
"(",
"hello",
")",
"\n",
"}",
"else",
"{",
"cert",
",",
"err",
"=",
"m",
".",
"GetCertificate",
"(",
"hello",
")",
"\n",
"}",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"app",
".",
"internalLog",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"hello",
".",
"ServerName",
",",
"err",
")",
"\n",
"}",
"\n\n",
"return",
"cert",
",",
"err",
"\n",
"}",
"\n\n",
"tlsLn",
":=",
"tls",
".",
"NewListener",
"(",
"ln",
",",
"tlsConfig",
")",
"\n\n",
"l",
":=",
"app",
".",
"internalLog",
".",
"WithField",
"(",
"\"",
"\"",
",",
"addr",
")",
"\n",
"l",
".",
"Info",
"(",
"\"",
"\"",
")",
"\n\n",
"srv",
":=",
"app",
".",
"copyServer",
"(",
")",
"\n",
"app",
".",
"runningServersMu",
".",
"Lock",
"(",
")",
"\n",
"app",
".",
"runningServers",
"=",
"append",
"(",
"app",
".",
"runningServers",
",",
"runningServerInfo",
"{",
"bind",
":",
"addr",
",",
"srv",
":",
"srv",
",",
"}",
")",
"\n",
"app",
".",
"runningServersMu",
".",
"Unlock",
"(",
")",
"\n",
"if",
"err",
"=",
"srv",
".",
"Serve",
"(",
"tlsLn",
")",
";",
"err",
"!=",
"nil",
"{",
"app",
".",
"internalLog",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"return",
"err",
"\n",
"}"
] |
// ListenAndServeAutoTLS serves TLS requests
|
[
"ListenAndServeAutoTLS",
"serves",
"TLS",
"requests"
] |
31c8d0b9955432cea19730996643bd857481d6a8
|
https://github.com/gramework/gramework/blob/31c8d0b9955432cea19730996643bd857481d6a8/app_listenAndServeAutoTLS.go#L41-L106
|
19,616
|
gramework/gramework
|
x/sqlgen/create_table.go
|
Column
|
func (tb *CreateTableBuilder) Column(name string) *ColumnBuilder {
return &ColumnBuilder{
tableBuilder: tb,
name: name,
}
}
|
go
|
func (tb *CreateTableBuilder) Column(name string) *ColumnBuilder {
return &ColumnBuilder{
tableBuilder: tb,
name: name,
}
}
|
[
"func",
"(",
"tb",
"*",
"CreateTableBuilder",
")",
"Column",
"(",
"name",
"string",
")",
"*",
"ColumnBuilder",
"{",
"return",
"&",
"ColumnBuilder",
"{",
"tableBuilder",
":",
"tb",
",",
"name",
":",
"name",
",",
"}",
"\n",
"}"
] |
// Column initialize a column builder
// that requires you to choose a type
// before you can Build the statement
|
[
"Column",
"initialize",
"a",
"column",
"builder",
"that",
"requires",
"you",
"to",
"choose",
"a",
"type",
"before",
"you",
"can",
"Build",
"the",
"statement"
] |
31c8d0b9955432cea19730996643bd857481d6a8
|
https://github.com/gramework/gramework/blob/31c8d0b9955432cea19730996643bd857481d6a8/x/sqlgen/create_table.go#L11-L16
|
19,617
|
gramework/gramework
|
x/sqlgen/create_table.go
|
appendColumn
|
func (tb *CreateTableBuilder) appendColumn(c *tableColumn) *CreateTableBuilder {
tb.columns = append(tb.columns, *c)
return tb
}
|
go
|
func (tb *CreateTableBuilder) appendColumn(c *tableColumn) *CreateTableBuilder {
tb.columns = append(tb.columns, *c)
return tb
}
|
[
"func",
"(",
"tb",
"*",
"CreateTableBuilder",
")",
"appendColumn",
"(",
"c",
"*",
"tableColumn",
")",
"*",
"CreateTableBuilder",
"{",
"tb",
".",
"columns",
"=",
"append",
"(",
"tb",
".",
"columns",
",",
"*",
"c",
")",
"\n",
"return",
"tb",
"\n",
"}"
] |
// appendColumn to the table column list
|
[
"appendColumn",
"to",
"the",
"table",
"column",
"list"
] |
31c8d0b9955432cea19730996643bd857481d6a8
|
https://github.com/gramework/gramework/blob/31c8d0b9955432cea19730996643bd857481d6a8/x/sqlgen/create_table.go#L19-L22
|
19,618
|
gramework/gramework
|
x/client/new.go
|
New
|
func New(config Config) *Instance {
client := &Instance{
conf: &config,
clients: make(map[string]*fasthttp.HostClient),
clientsMu: new(sync.RWMutex),
balancer: newRangeBalancer(),
}
return client
}
|
go
|
func New(config Config) *Instance {
client := &Instance{
conf: &config,
clients: make(map[string]*fasthttp.HostClient),
clientsMu: new(sync.RWMutex),
balancer: newRangeBalancer(),
}
return client
}
|
[
"func",
"New",
"(",
"config",
"Config",
")",
"*",
"Instance",
"{",
"client",
":=",
"&",
"Instance",
"{",
"conf",
":",
"&",
"config",
",",
"clients",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"fasthttp",
".",
"HostClient",
")",
",",
"clientsMu",
":",
"new",
"(",
"sync",
".",
"RWMutex",
")",
",",
"balancer",
":",
"newRangeBalancer",
"(",
")",
",",
"}",
"\n\n",
"return",
"client",
"\n",
"}"
] |
// New API client instance
|
[
"New",
"API",
"client",
"instance"
] |
31c8d0b9955432cea19730996643bd857481d6a8
|
https://github.com/gramework/gramework/blob/31c8d0b9955432cea19730996643bd857481d6a8/x/client/new.go#L20-L29
|
19,619
|
gramework/gramework
|
grypto/providers/scrypt/scrypt_provider.go
|
Equals
|
func (p *scryptParams) Equals(p1 *scryptParams) bool {
return p.keyLen == p1.keyLen &&
p.n == p1.n &&
p.r == p1.r &&
p.p == p1.p &&
p.saltLen == p1.saltLen
}
|
go
|
func (p *scryptParams) Equals(p1 *scryptParams) bool {
return p.keyLen == p1.keyLen &&
p.n == p1.n &&
p.r == p1.r &&
p.p == p1.p &&
p.saltLen == p1.saltLen
}
|
[
"func",
"(",
"p",
"*",
"scryptParams",
")",
"Equals",
"(",
"p1",
"*",
"scryptParams",
")",
"bool",
"{",
"return",
"p",
".",
"keyLen",
"==",
"p1",
".",
"keyLen",
"&&",
"p",
".",
"n",
"==",
"p1",
".",
"n",
"&&",
"p",
".",
"r",
"==",
"p1",
".",
"r",
"&&",
"p",
".",
"p",
"==",
"p1",
".",
"p",
"&&",
"p",
".",
"saltLen",
"==",
"p1",
".",
"saltLen",
"\n",
"}"
] |
// Equals returns true if params p equals to params p1
|
[
"Equals",
"returns",
"true",
"if",
"params",
"p",
"equals",
"to",
"params",
"p1"
] |
31c8d0b9955432cea19730996643bd857481d6a8
|
https://github.com/gramework/gramework/blob/31c8d0b9955432cea19730996643bd857481d6a8/grypto/providers/scrypt/scrypt_provider.go#L50-L56
|
19,620
|
gramework/gramework
|
grypto/providers/scrypt/scrypt_provider.go
|
String
|
func (p *scryptParams) String() string {
return fmt.Sprintf(paramsFmt, p.keyLen, p.n, p.r, p.p, p.saltLen)
}
|
go
|
func (p *scryptParams) String() string {
return fmt.Sprintf(paramsFmt, p.keyLen, p.n, p.r, p.p, p.saltLen)
}
|
[
"func",
"(",
"p",
"*",
"scryptParams",
")",
"String",
"(",
")",
"string",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"paramsFmt",
",",
"p",
".",
"keyLen",
",",
"p",
".",
"n",
",",
"p",
".",
"r",
",",
"p",
".",
"p",
",",
"p",
".",
"saltLen",
")",
"\n",
"}"
] |
// String returns params p as a MCF
|
[
"String",
"returns",
"params",
"p",
"as",
"a",
"MCF"
] |
31c8d0b9955432cea19730996643bd857481d6a8
|
https://github.com/gramework/gramework/blob/31c8d0b9955432cea19730996643bd857481d6a8/grypto/providers/scrypt/scrypt_provider.go#L59-L61
|
19,621
|
gramework/gramework
|
grypto/providers/scrypt/scrypt_provider.go
|
New
|
func New() *Provider {
return &Provider{
params: &scryptParams{
keyLen: DefaultKeyLen,
n: DefaultN,
r: DefaultR,
p: DefaultP,
saltLen: DefaultSaltLen,
},
}
}
|
go
|
func New() *Provider {
return &Provider{
params: &scryptParams{
keyLen: DefaultKeyLen,
n: DefaultN,
r: DefaultR,
p: DefaultP,
saltLen: DefaultSaltLen,
},
}
}
|
[
"func",
"New",
"(",
")",
"*",
"Provider",
"{",
"return",
"&",
"Provider",
"{",
"params",
":",
"&",
"scryptParams",
"{",
"keyLen",
":",
"DefaultKeyLen",
",",
"n",
":",
"DefaultN",
",",
"r",
":",
"DefaultR",
",",
"p",
":",
"DefaultP",
",",
"saltLen",
":",
"DefaultSaltLen",
",",
"}",
",",
"}",
"\n",
"}"
] |
// New returns new scrypt provider
|
[
"New",
"returns",
"new",
"scrypt",
"provider"
] |
31c8d0b9955432cea19730996643bd857481d6a8
|
https://github.com/gramework/gramework/blob/31c8d0b9955432cea19730996643bd857481d6a8/grypto/providers/scrypt/scrypt_provider.go#L64-L74
|
19,622
|
gramework/gramework
|
grypto/providers/scrypt/scrypt_provider.go
|
HashString
|
func (p *Provider) HashString(plaintext string) []byte {
return p.Hash([]byte(plaintext))
}
|
go
|
func (p *Provider) HashString(plaintext string) []byte {
return p.Hash([]byte(plaintext))
}
|
[
"func",
"(",
"p",
"*",
"Provider",
")",
"HashString",
"(",
"plaintext",
"string",
")",
"[",
"]",
"byte",
"{",
"return",
"p",
".",
"Hash",
"(",
"[",
"]",
"byte",
"(",
"plaintext",
")",
")",
"\n",
"}"
] |
// HashString returns scrypt hash of plaintext
|
[
"HashString",
"returns",
"scrypt",
"hash",
"of",
"plaintext"
] |
31c8d0b9955432cea19730996643bd857481d6a8
|
https://github.com/gramework/gramework/blob/31c8d0b9955432cea19730996643bd857481d6a8/grypto/providers/scrypt/scrypt_provider.go#L107-L109
|
19,623
|
gramework/gramework
|
context_writers.go
|
Encode
|
func (ctx *Context) Encode(v interface{}) (string, error) {
accept := ctx.Request.Header.Peek(acceptHeader)
accepted := acceptParser.Parse(BytesToString(accept))
sentType, err := accepted.Negotiate(ctypes...)
if err != nil {
return emptyString, err
}
switch sentType {
case jsonCT:
err = ctx.JSON(v)
case xmlCT:
err = ctx.XML(v)
case csvCT:
err = ctx.CSV(v)
}
return sentType, err
}
|
go
|
func (ctx *Context) Encode(v interface{}) (string, error) {
accept := ctx.Request.Header.Peek(acceptHeader)
accepted := acceptParser.Parse(BytesToString(accept))
sentType, err := accepted.Negotiate(ctypes...)
if err != nil {
return emptyString, err
}
switch sentType {
case jsonCT:
err = ctx.JSON(v)
case xmlCT:
err = ctx.XML(v)
case csvCT:
err = ctx.CSV(v)
}
return sentType, err
}
|
[
"func",
"(",
"ctx",
"*",
"Context",
")",
"Encode",
"(",
"v",
"interface",
"{",
"}",
")",
"(",
"string",
",",
"error",
")",
"{",
"accept",
":=",
"ctx",
".",
"Request",
".",
"Header",
".",
"Peek",
"(",
"acceptHeader",
")",
"\n",
"accepted",
":=",
"acceptParser",
".",
"Parse",
"(",
"BytesToString",
"(",
"accept",
")",
")",
"\n\n",
"sentType",
",",
"err",
":=",
"accepted",
".",
"Negotiate",
"(",
"ctypes",
"...",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"emptyString",
",",
"err",
"\n",
"}",
"\n\n",
"switch",
"sentType",
"{",
"case",
"jsonCT",
":",
"err",
"=",
"ctx",
".",
"JSON",
"(",
"v",
")",
"\n",
"case",
"xmlCT",
":",
"err",
"=",
"ctx",
".",
"XML",
"(",
"v",
")",
"\n",
"case",
"csvCT",
":",
"err",
"=",
"ctx",
".",
"CSV",
"(",
"v",
")",
"\n",
"}",
"\n\n",
"return",
"sentType",
",",
"err",
"\n",
"}"
] |
// Encode automatically determines accepted formats
// and choose preferred one
|
[
"Encode",
"automatically",
"determines",
"accepted",
"formats",
"and",
"choose",
"preferred",
"one"
] |
31c8d0b9955432cea19730996643bd857481d6a8
|
https://github.com/gramework/gramework/blob/31c8d0b9955432cea19730996643bd857481d6a8/context_writers.go#L17-L36
|
19,624
|
gramework/gramework
|
context_writers.go
|
HTML
|
func (ctx *Context) HTML(src ...string) *Context {
ctx.SetContentType(htmlCT)
if len(src) > 0 {
_, e := ctx.WriteString(src[0])
_ = e
}
return ctx
}
|
go
|
func (ctx *Context) HTML(src ...string) *Context {
ctx.SetContentType(htmlCT)
if len(src) > 0 {
_, e := ctx.WriteString(src[0])
_ = e
}
return ctx
}
|
[
"func",
"(",
"ctx",
"*",
"Context",
")",
"HTML",
"(",
"src",
"...",
"string",
")",
"*",
"Context",
"{",
"ctx",
".",
"SetContentType",
"(",
"htmlCT",
")",
"\n",
"if",
"len",
"(",
"src",
")",
">",
"0",
"{",
"_",
",",
"e",
":=",
"ctx",
".",
"WriteString",
"(",
"src",
"[",
"0",
"]",
")",
"\n",
"_",
"=",
"e",
"\n",
"}",
"\n",
"return",
"ctx",
"\n",
"}"
] |
// HTML sets HTML content type
|
[
"HTML",
"sets",
"HTML",
"content",
"type"
] |
31c8d0b9955432cea19730996643bd857481d6a8
|
https://github.com/gramework/gramework/blob/31c8d0b9955432cea19730996643bd857481d6a8/context_writers.go#L73-L80
|
19,625
|
gramework/gramework
|
context_writers.go
|
CORS
|
func (ctx *Context) CORS(domains ...string) *Context {
var origins []string
if len(domains) > 0 {
origins = domains
} else if headerOrigin := ctx.Request.Header.Peek(hOrigin); len(headerOrigin) > 0 {
origins = append(origins, string(headerOrigin))
} else {
origins = append(origins, string(ctx.Request.URI().Host()))
}
ctx.Response.Header.Set(corsAccessControlAllowOrigin, strings.Join(origins, " "))
ctx.Response.Header.Set(corsAccessControlAllowMethods, methods)
ctx.Response.Header.Set(corsAccessControlAllowHeaders, corsCType)
ctx.Response.Header.Set(corsAccessControlAllowCredentials, trueStr)
return ctx
}
|
go
|
func (ctx *Context) CORS(domains ...string) *Context {
var origins []string
if len(domains) > 0 {
origins = domains
} else if headerOrigin := ctx.Request.Header.Peek(hOrigin); len(headerOrigin) > 0 {
origins = append(origins, string(headerOrigin))
} else {
origins = append(origins, string(ctx.Request.URI().Host()))
}
ctx.Response.Header.Set(corsAccessControlAllowOrigin, strings.Join(origins, " "))
ctx.Response.Header.Set(corsAccessControlAllowMethods, methods)
ctx.Response.Header.Set(corsAccessControlAllowHeaders, corsCType)
ctx.Response.Header.Set(corsAccessControlAllowCredentials, trueStr)
return ctx
}
|
[
"func",
"(",
"ctx",
"*",
"Context",
")",
"CORS",
"(",
"domains",
"...",
"string",
")",
"*",
"Context",
"{",
"var",
"origins",
"[",
"]",
"string",
"\n",
"if",
"len",
"(",
"domains",
")",
">",
"0",
"{",
"origins",
"=",
"domains",
"\n",
"}",
"else",
"if",
"headerOrigin",
":=",
"ctx",
".",
"Request",
".",
"Header",
".",
"Peek",
"(",
"hOrigin",
")",
";",
"len",
"(",
"headerOrigin",
")",
">",
"0",
"{",
"origins",
"=",
"append",
"(",
"origins",
",",
"string",
"(",
"headerOrigin",
")",
")",
"\n",
"}",
"else",
"{",
"origins",
"=",
"append",
"(",
"origins",
",",
"string",
"(",
"ctx",
".",
"Request",
".",
"URI",
"(",
")",
".",
"Host",
"(",
")",
")",
")",
"\n",
"}",
"\n\n",
"ctx",
".",
"Response",
".",
"Header",
".",
"Set",
"(",
"corsAccessControlAllowOrigin",
",",
"strings",
".",
"Join",
"(",
"origins",
",",
"\"",
"\"",
")",
")",
"\n",
"ctx",
".",
"Response",
".",
"Header",
".",
"Set",
"(",
"corsAccessControlAllowMethods",
",",
"methods",
")",
"\n",
"ctx",
".",
"Response",
".",
"Header",
".",
"Set",
"(",
"corsAccessControlAllowHeaders",
",",
"corsCType",
")",
"\n",
"ctx",
".",
"Response",
".",
"Header",
".",
"Set",
"(",
"corsAccessControlAllowCredentials",
",",
"trueStr",
")",
"\n\n",
"return",
"ctx",
"\n",
"}"
] |
// CORS enables CORS in the current context
|
[
"CORS",
"enables",
"CORS",
"in",
"the",
"current",
"context"
] |
31c8d0b9955432cea19730996643bd857481d6a8
|
https://github.com/gramework/gramework/blob/31c8d0b9955432cea19730996643bd857481d6a8/context_writers.go#L83-L99
|
19,626
|
gramework/gramework
|
context_writers.go
|
JSON
|
func (ctx *Context) JSON(v interface{}) error {
ctx.SetContentType(jsonCT)
b, err := ctx.ToJSON(v)
if err != nil {
return err
}
_, err = ctx.Write(b)
return err
}
|
go
|
func (ctx *Context) JSON(v interface{}) error {
ctx.SetContentType(jsonCT)
b, err := ctx.ToJSON(v)
if err != nil {
return err
}
_, err = ctx.Write(b)
return err
}
|
[
"func",
"(",
"ctx",
"*",
"Context",
")",
"JSON",
"(",
"v",
"interface",
"{",
"}",
")",
"error",
"{",
"ctx",
".",
"SetContentType",
"(",
"jsonCT",
")",
"\n",
"b",
",",
"err",
":=",
"ctx",
".",
"ToJSON",
"(",
"v",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"_",
",",
"err",
"=",
"ctx",
".",
"Write",
"(",
"b",
")",
"\n",
"return",
"err",
"\n",
"}"
] |
// JSON serializes and writes a json-formatted response to user
|
[
"JSON",
"serializes",
"and",
"writes",
"a",
"json",
"-",
"formatted",
"response",
"to",
"user"
] |
31c8d0b9955432cea19730996643bd857481d6a8
|
https://github.com/gramework/gramework/blob/31c8d0b9955432cea19730996643bd857481d6a8/context_writers.go#L102-L111
|
19,627
|
gramework/gramework
|
context_writers.go
|
Err500
|
func (ctx *Context) Err500(message ...interface{}) *Context {
ctx.SetStatusCode(fasthttp.StatusInternalServerError)
for k := range message {
switch v := message[k].(type) {
case string:
_, err := ctx.WriteString(v)
if err != nil {
ctx.Logger.WithError(err).Error("Err500 serving error")
}
case error:
_, e := ctx.Writef(fmtS, v)
_ = e // it's already 500
default:
_, e := ctx.Writef(fmtV, v)
_ = e
}
}
return ctx
}
|
go
|
func (ctx *Context) Err500(message ...interface{}) *Context {
ctx.SetStatusCode(fasthttp.StatusInternalServerError)
for k := range message {
switch v := message[k].(type) {
case string:
_, err := ctx.WriteString(v)
if err != nil {
ctx.Logger.WithError(err).Error("Err500 serving error")
}
case error:
_, e := ctx.Writef(fmtS, v)
_ = e // it's already 500
default:
_, e := ctx.Writef(fmtV, v)
_ = e
}
}
return ctx
}
|
[
"func",
"(",
"ctx",
"*",
"Context",
")",
"Err500",
"(",
"message",
"...",
"interface",
"{",
"}",
")",
"*",
"Context",
"{",
"ctx",
".",
"SetStatusCode",
"(",
"fasthttp",
".",
"StatusInternalServerError",
")",
"\n",
"for",
"k",
":=",
"range",
"message",
"{",
"switch",
"v",
":=",
"message",
"[",
"k",
"]",
".",
"(",
"type",
")",
"{",
"case",
"string",
":",
"_",
",",
"err",
":=",
"ctx",
".",
"WriteString",
"(",
"v",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"ctx",
".",
"Logger",
".",
"WithError",
"(",
"err",
")",
".",
"Error",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"case",
"error",
":",
"_",
",",
"e",
":=",
"ctx",
".",
"Writef",
"(",
"fmtS",
",",
"v",
")",
"\n",
"_",
"=",
"e",
"// it's already 500",
"\n",
"default",
":",
"_",
",",
"e",
":=",
"ctx",
".",
"Writef",
"(",
"fmtV",
",",
"v",
")",
"\n",
"_",
"=",
"e",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"ctx",
"\n",
"}"
] |
// Err500 sets Internal Server Error status
|
[
"Err500",
"sets",
"Internal",
"Server",
"Error",
"status"
] |
31c8d0b9955432cea19730996643bd857481d6a8
|
https://github.com/gramework/gramework/blob/31c8d0b9955432cea19730996643bd857481d6a8/context_writers.go#L124-L142
|
19,628
|
gramework/gramework
|
context_writers.go
|
JSONError
|
func (ctx *Context) JSONError(v interface{}) error {
ctx.Err500()
return ctx.JSON(v)
}
|
go
|
func (ctx *Context) JSONError(v interface{}) error {
ctx.Err500()
return ctx.JSON(v)
}
|
[
"func",
"(",
"ctx",
"*",
"Context",
")",
"JSONError",
"(",
"v",
"interface",
"{",
"}",
")",
"error",
"{",
"ctx",
".",
"Err500",
"(",
")",
"\n",
"return",
"ctx",
".",
"JSON",
"(",
"v",
")",
"\n",
"}"
] |
// JSONError sets Internal Server Error status,
// serializes and writes a json-formatted response to user
|
[
"JSONError",
"sets",
"Internal",
"Server",
"Error",
"status",
"serializes",
"and",
"writes",
"a",
"json",
"-",
"formatted",
"response",
"to",
"user"
] |
31c8d0b9955432cea19730996643bd857481d6a8
|
https://github.com/gramework/gramework/blob/31c8d0b9955432cea19730996643bd857481d6a8/context_writers.go#L146-L149
|
19,629
|
gramework/gramework
|
grypto/pass.go
|
PasswordValid
|
func PasswordValid(hash, password []byte) bool {
p := matchProvider(hash)
if p == nil {
return false
}
return p.Valid(hash, password)
}
|
go
|
func PasswordValid(hash, password []byte) bool {
p := matchProvider(hash)
if p == nil {
return false
}
return p.Valid(hash, password)
}
|
[
"func",
"PasswordValid",
"(",
"hash",
",",
"password",
"[",
"]",
"byte",
")",
"bool",
"{",
"p",
":=",
"matchProvider",
"(",
"hash",
")",
"\n",
"if",
"p",
"==",
"nil",
"{",
"return",
"false",
"\n",
"}",
"\n",
"return",
"p",
".",
"Valid",
"(",
"hash",
",",
"password",
")",
"\n",
"}"
] |
// PasswordValid checks if provided hash
|
[
"PasswordValid",
"checks",
"if",
"provided",
"hash"
] |
31c8d0b9955432cea19730996643bd857481d6a8
|
https://github.com/gramework/gramework/blob/31c8d0b9955432cea19730996643bd857481d6a8/grypto/pass.go#L60-L66
|
19,630
|
gramework/gramework
|
opts.go
|
OptAppName
|
func OptAppName(n string) func(*App) {
return func(app *App) {
assertAppNotNill(app)
app.name = n
}
}
|
go
|
func OptAppName(n string) func(*App) {
return func(app *App) {
assertAppNotNill(app)
app.name = n
}
}
|
[
"func",
"OptAppName",
"(",
"n",
"string",
")",
"func",
"(",
"*",
"App",
")",
"{",
"return",
"func",
"(",
"app",
"*",
"App",
")",
"{",
"assertAppNotNill",
"(",
"app",
")",
"\n",
"app",
".",
"name",
"=",
"n",
"\n",
"}",
"\n",
"}"
] |
// OptAppName sets app.name and app.serverBase.Name
|
[
"OptAppName",
"sets",
"app",
".",
"name",
"and",
"app",
".",
"serverBase",
".",
"Name"
] |
31c8d0b9955432cea19730996643bd857481d6a8
|
https://github.com/gramework/gramework/blob/31c8d0b9955432cea19730996643bd857481d6a8/opts.go#L21-L26
|
19,631
|
gramework/gramework
|
opts.go
|
OptUseCustomLogger
|
func OptUseCustomLogger(logger *log.Logger) func(*App) {
return func(app *App) {
assertAppNotNill(app)
app.Logger = logger
}
}
|
go
|
func OptUseCustomLogger(logger *log.Logger) func(*App) {
return func(app *App) {
assertAppNotNill(app)
app.Logger = logger
}
}
|
[
"func",
"OptUseCustomLogger",
"(",
"logger",
"*",
"log",
".",
"Logger",
")",
"func",
"(",
"*",
"App",
")",
"{",
"return",
"func",
"(",
"app",
"*",
"App",
")",
"{",
"assertAppNotNill",
"(",
"app",
")",
"\n",
"app",
".",
"Logger",
"=",
"logger",
"\n",
"}",
"\n",
"}"
] |
// OptUseCustomLogger allows use custom preconfigured Apex logger.
// For exmaple with custom Handler.
|
[
"OptUseCustomLogger",
"allows",
"use",
"custom",
"preconfigured",
"Apex",
"logger",
".",
"For",
"exmaple",
"with",
"custom",
"Handler",
"."
] |
31c8d0b9955432cea19730996643bd857481d6a8
|
https://github.com/gramework/gramework/blob/31c8d0b9955432cea19730996643bd857481d6a8/opts.go#L30-L35
|
19,632
|
gramework/gramework
|
opts.go
|
OptUseServer
|
func OptUseServer(s *fasthttp.Server) func(*App) {
return func(app *App) {
assertAppNotNill(app)
if s == nil {
panic(errors.New("cannot set nil as app server instance"))
}
app.serverBase = s
app.serverBase.Handler = app.handler()
}
}
|
go
|
func OptUseServer(s *fasthttp.Server) func(*App) {
return func(app *App) {
assertAppNotNill(app)
if s == nil {
panic(errors.New("cannot set nil as app server instance"))
}
app.serverBase = s
app.serverBase.Handler = app.handler()
}
}
|
[
"func",
"OptUseServer",
"(",
"s",
"*",
"fasthttp",
".",
"Server",
")",
"func",
"(",
"*",
"App",
")",
"{",
"return",
"func",
"(",
"app",
"*",
"App",
")",
"{",
"assertAppNotNill",
"(",
"app",
")",
"\n",
"if",
"s",
"==",
"nil",
"{",
"panic",
"(",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
")",
"\n",
"}",
"\n",
"app",
".",
"serverBase",
"=",
"s",
"\n",
"app",
".",
"serverBase",
".",
"Handler",
"=",
"app",
".",
"handler",
"(",
")",
"\n",
"}",
"\n",
"}"
] |
// OptUseServer sets fasthttp.Server instance to use
|
[
"OptUseServer",
"sets",
"fasthttp",
".",
"Server",
"instance",
"to",
"use"
] |
31c8d0b9955432cea19730996643bd857481d6a8
|
https://github.com/gramework/gramework/blob/31c8d0b9955432cea19730996643bd857481d6a8/opts.go#L38-L47
|
19,633
|
gramework/gramework
|
opts.go
|
OptMaxRequestBodySize
|
func OptMaxRequestBodySize(size int) func(*App) {
return func(app *App) {
assertAppNotNill(app)
if app.serverBase == nil {
app.serverBase = newDefaultServerBaseFor(app)
}
app.serverBase.MaxRequestBodySize = size
}
}
|
go
|
func OptMaxRequestBodySize(size int) func(*App) {
return func(app *App) {
assertAppNotNill(app)
if app.serverBase == nil {
app.serverBase = newDefaultServerBaseFor(app)
}
app.serverBase.MaxRequestBodySize = size
}
}
|
[
"func",
"OptMaxRequestBodySize",
"(",
"size",
"int",
")",
"func",
"(",
"*",
"App",
")",
"{",
"return",
"func",
"(",
"app",
"*",
"App",
")",
"{",
"assertAppNotNill",
"(",
"app",
")",
"\n",
"if",
"app",
".",
"serverBase",
"==",
"nil",
"{",
"app",
".",
"serverBase",
"=",
"newDefaultServerBaseFor",
"(",
"app",
")",
"\n",
"}",
"\n",
"app",
".",
"serverBase",
".",
"MaxRequestBodySize",
"=",
"size",
"\n",
"}",
"\n",
"}"
] |
// OptMaxRequestBodySize sets new MaxRequestBodySize in the server used at the execution time.
// All OptUseServer will overwrite this setting 'case OptUseServer replaces the whole server instance
// with a new one.
|
[
"OptMaxRequestBodySize",
"sets",
"new",
"MaxRequestBodySize",
"in",
"the",
"server",
"used",
"at",
"the",
"execution",
"time",
".",
"All",
"OptUseServer",
"will",
"overwrite",
"this",
"setting",
"case",
"OptUseServer",
"replaces",
"the",
"whole",
"server",
"instance",
"with",
"a",
"new",
"one",
"."
] |
31c8d0b9955432cea19730996643bd857481d6a8
|
https://github.com/gramework/gramework/blob/31c8d0b9955432cea19730996643bd857481d6a8/opts.go#L52-L60
|
19,634
|
gramework/gramework
|
opts.go
|
OptKeepHijackedConns
|
func OptKeepHijackedConns(keep bool) func(*App) {
return func(app *App) {
assertAppNotNill(app)
if app.serverBase == nil {
app.serverBase = newDefaultServerBaseFor(app)
}
app.serverBase.KeepHijackedConns = keep
}
}
|
go
|
func OptKeepHijackedConns(keep bool) func(*App) {
return func(app *App) {
assertAppNotNill(app)
if app.serverBase == nil {
app.serverBase = newDefaultServerBaseFor(app)
}
app.serverBase.KeepHijackedConns = keep
}
}
|
[
"func",
"OptKeepHijackedConns",
"(",
"keep",
"bool",
")",
"func",
"(",
"*",
"App",
")",
"{",
"return",
"func",
"(",
"app",
"*",
"App",
")",
"{",
"assertAppNotNill",
"(",
"app",
")",
"\n",
"if",
"app",
".",
"serverBase",
"==",
"nil",
"{",
"app",
".",
"serverBase",
"=",
"newDefaultServerBaseFor",
"(",
"app",
")",
"\n",
"}",
"\n",
"app",
".",
"serverBase",
".",
"KeepHijackedConns",
"=",
"keep",
"\n",
"}",
"\n",
"}"
] |
// OptKeepHijackedConns sets new KeepHijackedConns in the server used at the execution time.
// All OptUseServer will overwrite this setting 'case OptUseServer replaces the whole server instance
// with a new one.
|
[
"OptKeepHijackedConns",
"sets",
"new",
"KeepHijackedConns",
"in",
"the",
"server",
"used",
"at",
"the",
"execution",
"time",
".",
"All",
"OptUseServer",
"will",
"overwrite",
"this",
"setting",
"case",
"OptUseServer",
"replaces",
"the",
"whole",
"server",
"instance",
"with",
"a",
"new",
"one",
"."
] |
31c8d0b9955432cea19730996643bd857481d6a8
|
https://github.com/gramework/gramework/blob/31c8d0b9955432cea19730996643bd857481d6a8/opts.go#L65-L73
|
19,635
|
gramework/gramework
|
x/sqlgen/columnBuilder.go
|
Integer
|
func (cb *ColumnBuilder) Integer() *CreateTableBuilder {
return cb.tableBuilder.appendColumn(&tableColumn{
name: cb.name,
sqlType: "INTEGER",
})
}
|
go
|
func (cb *ColumnBuilder) Integer() *CreateTableBuilder {
return cb.tableBuilder.appendColumn(&tableColumn{
name: cb.name,
sqlType: "INTEGER",
})
}
|
[
"func",
"(",
"cb",
"*",
"ColumnBuilder",
")",
"Integer",
"(",
")",
"*",
"CreateTableBuilder",
"{",
"return",
"cb",
".",
"tableBuilder",
".",
"appendColumn",
"(",
"&",
"tableColumn",
"{",
"name",
":",
"cb",
".",
"name",
",",
"sqlType",
":",
"\"",
"\"",
",",
"}",
")",
"\n",
"}"
] |
// Integer sets INTEGER type to the column
|
[
"Integer",
"sets",
"INTEGER",
"type",
"to",
"the",
"column"
] |
31c8d0b9955432cea19730996643bd857481d6a8
|
https://github.com/gramework/gramework/blob/31c8d0b9955432cea19730996643bd857481d6a8/x/sqlgen/columnBuilder.go#L17-L22
|
19,636
|
gramework/gramework
|
fasthttprouter_router.go
|
newRouter
|
func newRouter() *router {
r := &router{
RedirectTrailingSlash: true,
RedirectFixedPath: true,
HandleMethodNotAllowed: true,
HandleOPTIONS: true,
cache: &cache{
v: map[string]*msc{
// init default methods
MethodGET: &msc{
v: make(map[string]*cacheRecord),
},
MethodDELETE: &msc{
v: make(map[string]*cacheRecord),
},
MethodHEAD: &msc{
v: make(map[string]*cacheRecord),
},
MethodOPTIONS: &msc{
v: make(map[string]*cacheRecord),
},
MethodPATCH: &msc{
v: make(map[string]*cacheRecord),
},
MethodPOST: &msc{
v: make(map[string]*cacheRecord),
},
MethodPUT: &msc{
v: make(map[string]*cacheRecord),
},
},
},
}
r.StaticHandlers = map[methodIndex]map[string]staticHandler{
methodToIdx(GET): make(map[string]staticHandler),
methodToIdx(DELETE): make(map[string]staticHandler),
methodToIdx(HEAD): make(map[string]staticHandler),
methodToIdx(OPTIONS): make(map[string]staticHandler),
methodToIdx(PATCH): make(map[string]staticHandler),
methodToIdx(POST): make(map[string]staticHandler),
methodToIdx(PUT): make(map[string]staticHandler),
}
go r.cache.maintain()
return r
}
|
go
|
func newRouter() *router {
r := &router{
RedirectTrailingSlash: true,
RedirectFixedPath: true,
HandleMethodNotAllowed: true,
HandleOPTIONS: true,
cache: &cache{
v: map[string]*msc{
// init default methods
MethodGET: &msc{
v: make(map[string]*cacheRecord),
},
MethodDELETE: &msc{
v: make(map[string]*cacheRecord),
},
MethodHEAD: &msc{
v: make(map[string]*cacheRecord),
},
MethodOPTIONS: &msc{
v: make(map[string]*cacheRecord),
},
MethodPATCH: &msc{
v: make(map[string]*cacheRecord),
},
MethodPOST: &msc{
v: make(map[string]*cacheRecord),
},
MethodPUT: &msc{
v: make(map[string]*cacheRecord),
},
},
},
}
r.StaticHandlers = map[methodIndex]map[string]staticHandler{
methodToIdx(GET): make(map[string]staticHandler),
methodToIdx(DELETE): make(map[string]staticHandler),
methodToIdx(HEAD): make(map[string]staticHandler),
methodToIdx(OPTIONS): make(map[string]staticHandler),
methodToIdx(PATCH): make(map[string]staticHandler),
methodToIdx(POST): make(map[string]staticHandler),
methodToIdx(PUT): make(map[string]staticHandler),
}
go r.cache.maintain()
return r
}
|
[
"func",
"newRouter",
"(",
")",
"*",
"router",
"{",
"r",
":=",
"&",
"router",
"{",
"RedirectTrailingSlash",
":",
"true",
",",
"RedirectFixedPath",
":",
"true",
",",
"HandleMethodNotAllowed",
":",
"true",
",",
"HandleOPTIONS",
":",
"true",
",",
"cache",
":",
"&",
"cache",
"{",
"v",
":",
"map",
"[",
"string",
"]",
"*",
"msc",
"{",
"// init default methods",
"MethodGET",
":",
"&",
"msc",
"{",
"v",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"cacheRecord",
")",
",",
"}",
",",
"MethodDELETE",
":",
"&",
"msc",
"{",
"v",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"cacheRecord",
")",
",",
"}",
",",
"MethodHEAD",
":",
"&",
"msc",
"{",
"v",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"cacheRecord",
")",
",",
"}",
",",
"MethodOPTIONS",
":",
"&",
"msc",
"{",
"v",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"cacheRecord",
")",
",",
"}",
",",
"MethodPATCH",
":",
"&",
"msc",
"{",
"v",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"cacheRecord",
")",
",",
"}",
",",
"MethodPOST",
":",
"&",
"msc",
"{",
"v",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"cacheRecord",
")",
",",
"}",
",",
"MethodPUT",
":",
"&",
"msc",
"{",
"v",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"cacheRecord",
")",
",",
"}",
",",
"}",
",",
"}",
",",
"}",
"\n",
"r",
".",
"StaticHandlers",
"=",
"map",
"[",
"methodIndex",
"]",
"map",
"[",
"string",
"]",
"staticHandler",
"{",
"methodToIdx",
"(",
"GET",
")",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"staticHandler",
")",
",",
"methodToIdx",
"(",
"DELETE",
")",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"staticHandler",
")",
",",
"methodToIdx",
"(",
"HEAD",
")",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"staticHandler",
")",
",",
"methodToIdx",
"(",
"OPTIONS",
")",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"staticHandler",
")",
",",
"methodToIdx",
"(",
"PATCH",
")",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"staticHandler",
")",
",",
"methodToIdx",
"(",
"POST",
")",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"staticHandler",
")",
",",
"methodToIdx",
"(",
"PUT",
")",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"staticHandler",
")",
",",
"}",
"\n",
"go",
"r",
".",
"cache",
".",
"maintain",
"(",
")",
"\n",
"return",
"r",
"\n",
"}"
] |
// newRouter returns a new initialized Router.
// Path auto-correction, including trailing slashes, is enabled by default.
|
[
"newRouter",
"returns",
"a",
"new",
"initialized",
"Router",
".",
"Path",
"auto",
"-",
"correction",
"including",
"trailing",
"slashes",
"is",
"enabled",
"by",
"default",
"."
] |
31c8d0b9955432cea19730996643bd857481d6a8
|
https://github.com/gramework/gramework/blob/31c8d0b9955432cea19730996643bd857481d6a8/fasthttprouter_router.go#L122-L166
|
19,637
|
gramework/gramework
|
fasthttprouter_router.go
|
Recv
|
func (r *router) Recv(ctx *Context, tracer *log.Entry) {
if rcv := recover(); rcv != nil {
if r.PanicHandler != nil {
r.PanicHandler(ctx, rcv)
} else {
DefaultPanicHandler(ctx, rcv)
}
if tracer != nil {
tracer.WithFields(log.Fields{
"reason": rcv,
"code": ctx.Response.StatusCode(),
}).Error("request caused panic")
}
}
}
|
go
|
func (r *router) Recv(ctx *Context, tracer *log.Entry) {
if rcv := recover(); rcv != nil {
if r.PanicHandler != nil {
r.PanicHandler(ctx, rcv)
} else {
DefaultPanicHandler(ctx, rcv)
}
if tracer != nil {
tracer.WithFields(log.Fields{
"reason": rcv,
"code": ctx.Response.StatusCode(),
}).Error("request caused panic")
}
}
}
|
[
"func",
"(",
"r",
"*",
"router",
")",
"Recv",
"(",
"ctx",
"*",
"Context",
",",
"tracer",
"*",
"log",
".",
"Entry",
")",
"{",
"if",
"rcv",
":=",
"recover",
"(",
")",
";",
"rcv",
"!=",
"nil",
"{",
"if",
"r",
".",
"PanicHandler",
"!=",
"nil",
"{",
"r",
".",
"PanicHandler",
"(",
"ctx",
",",
"rcv",
")",
"\n",
"}",
"else",
"{",
"DefaultPanicHandler",
"(",
"ctx",
",",
"rcv",
")",
"\n",
"}",
"\n",
"if",
"tracer",
"!=",
"nil",
"{",
"tracer",
".",
"WithFields",
"(",
"log",
".",
"Fields",
"{",
"\"",
"\"",
":",
"rcv",
",",
"\"",
"\"",
":",
"ctx",
".",
"Response",
".",
"StatusCode",
"(",
")",
",",
"}",
")",
".",
"Error",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] |
// Recv used to recover after panic. Called if PanicHandler was set
|
[
"Recv",
"used",
"to",
"recover",
"after",
"panic",
".",
"Called",
"if",
"PanicHandler",
"was",
"set"
] |
31c8d0b9955432cea19730996643bd857481d6a8
|
https://github.com/gramework/gramework/blob/31c8d0b9955432cea19730996643bd857481d6a8/fasthttprouter_router.go#L280-L294
|
19,638
|
gramework/gramework
|
context.go
|
ContentType
|
func (ctx *Context) ContentType() string {
return string(ctx.Request.Header.Peek(contentType))
}
|
go
|
func (ctx *Context) ContentType() string {
return string(ctx.Request.Header.Peek(contentType))
}
|
[
"func",
"(",
"ctx",
"*",
"Context",
")",
"ContentType",
"(",
")",
"string",
"{",
"return",
"string",
"(",
"ctx",
".",
"Request",
".",
"Header",
".",
"Peek",
"(",
"contentType",
")",
")",
"\n",
"}"
] |
// ContentType returns Content-Type header for current request
|
[
"ContentType",
"returns",
"Content",
"-",
"Type",
"header",
"for",
"current",
"request"
] |
31c8d0b9955432cea19730996643bd857481d6a8
|
https://github.com/gramework/gramework/blob/31c8d0b9955432cea19730996643bd857481d6a8/context.go#L75-L77
|
19,639
|
gramework/gramework
|
context.go
|
RouteArg
|
func (ctx *Context) RouteArg(argName string) string {
v, err := ctx.RouteArgErr(argName)
if err != nil {
return emptyString
}
return v
}
|
go
|
func (ctx *Context) RouteArg(argName string) string {
v, err := ctx.RouteArgErr(argName)
if err != nil {
return emptyString
}
return v
}
|
[
"func",
"(",
"ctx",
"*",
"Context",
")",
"RouteArg",
"(",
"argName",
"string",
")",
"string",
"{",
"v",
",",
"err",
":=",
"ctx",
".",
"RouteArgErr",
"(",
"argName",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"emptyString",
"\n",
"}",
"\n",
"return",
"v",
"\n",
"}"
] |
// RouteArg returns an argument value as a string or empty string
|
[
"RouteArg",
"returns",
"an",
"argument",
"value",
"as",
"a",
"string",
"or",
"empty",
"string"
] |
31c8d0b9955432cea19730996643bd857481d6a8
|
https://github.com/gramework/gramework/blob/31c8d0b9955432cea19730996643bd857481d6a8/context.go#L92-L98
|
19,640
|
gramework/gramework
|
context.go
|
ToXML
|
func (ctx *Context) ToXML(v interface{}) ([]byte, error) {
b := bytes.NewBuffer(nil)
err := xml.NewEncoder(b).Encode(v)
return b.Bytes(), err
}
|
go
|
func (ctx *Context) ToXML(v interface{}) ([]byte, error) {
b := bytes.NewBuffer(nil)
err := xml.NewEncoder(b).Encode(v)
return b.Bytes(), err
}
|
[
"func",
"(",
"ctx",
"*",
"Context",
")",
"ToXML",
"(",
"v",
"interface",
"{",
"}",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"b",
":=",
"bytes",
".",
"NewBuffer",
"(",
"nil",
")",
"\n",
"err",
":=",
"xml",
".",
"NewEncoder",
"(",
"b",
")",
".",
"Encode",
"(",
"v",
")",
"\n",
"return",
"b",
".",
"Bytes",
"(",
")",
",",
"err",
"\n",
"}"
] |
// ToXML encodes xml-encoded value to client
|
[
"ToXML",
"encodes",
"xml",
"-",
"encoded",
"value",
"to",
"client"
] |
31c8d0b9955432cea19730996643bd857481d6a8
|
https://github.com/gramework/gramework/blob/31c8d0b9955432cea19730996643bd857481d6a8/context.go#L106-L110
|
19,641
|
gramework/gramework
|
context.go
|
RouteArgErr
|
func (ctx *Context) RouteArgErr(argName string) (string, error) {
i := ctx.UserValue(argName)
if i == nil {
return emptyString, ErrArgNotFound
}
switch value := i.(type) {
case string:
return value, nil
default:
return fmt.Sprintf(fmtV, i), nil
}
}
|
go
|
func (ctx *Context) RouteArgErr(argName string) (string, error) {
i := ctx.UserValue(argName)
if i == nil {
return emptyString, ErrArgNotFound
}
switch value := i.(type) {
case string:
return value, nil
default:
return fmt.Sprintf(fmtV, i), nil
}
}
|
[
"func",
"(",
"ctx",
"*",
"Context",
")",
"RouteArgErr",
"(",
"argName",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"i",
":=",
"ctx",
".",
"UserValue",
"(",
"argName",
")",
"\n",
"if",
"i",
"==",
"nil",
"{",
"return",
"emptyString",
",",
"ErrArgNotFound",
"\n",
"}",
"\n",
"switch",
"value",
":=",
"i",
".",
"(",
"type",
")",
"{",
"case",
"string",
":",
"return",
"value",
",",
"nil",
"\n",
"default",
":",
"return",
"fmt",
".",
"Sprintf",
"(",
"fmtV",
",",
"i",
")",
",",
"nil",
"\n",
"}",
"\n",
"}"
] |
// RouteArgErr returns an argument value as a string or empty string
// and ErrArgNotFound if argument was not found
|
[
"RouteArgErr",
"returns",
"an",
"argument",
"value",
"as",
"a",
"string",
"or",
"empty",
"string",
"and",
"ErrArgNotFound",
"if",
"argument",
"was",
"not",
"found"
] |
31c8d0b9955432cea19730996643bd857481d6a8
|
https://github.com/gramework/gramework/blob/31c8d0b9955432cea19730996643bd857481d6a8/context.go#L150-L161
|
19,642
|
gramework/gramework
|
context.go
|
ToTLS
|
func (ctx *Context) ToTLS() {
u := ctx.URI()
u.SetScheme(https)
ctx.Redirect(u.String(), redirectCode)
}
|
go
|
func (ctx *Context) ToTLS() {
u := ctx.URI()
u.SetScheme(https)
ctx.Redirect(u.String(), redirectCode)
}
|
[
"func",
"(",
"ctx",
"*",
"Context",
")",
"ToTLS",
"(",
")",
"{",
"u",
":=",
"ctx",
".",
"URI",
"(",
")",
"\n",
"u",
".",
"SetScheme",
"(",
"https",
")",
"\n",
"ctx",
".",
"Redirect",
"(",
"u",
".",
"String",
"(",
")",
",",
"redirectCode",
")",
"\n",
"}"
] |
// ToTLS redirects user to HTTPS scheme
|
[
"ToTLS",
"redirects",
"user",
"to",
"HTTPS",
"scheme"
] |
31c8d0b9955432cea19730996643bd857481d6a8
|
https://github.com/gramework/gramework/blob/31c8d0b9955432cea19730996643bd857481d6a8/context.go#L164-L168
|
19,643
|
gramework/gramework
|
context.go
|
ToJSON
|
func (ctx *Context) ToJSON(v interface{}) ([]byte, error) {
b := bytes.NewBuffer(nil)
enc := ffjson.NewEncoder(b)
err := enc.Encode(v)
return b.Bytes(), err
}
|
go
|
func (ctx *Context) ToJSON(v interface{}) ([]byte, error) {
b := bytes.NewBuffer(nil)
enc := ffjson.NewEncoder(b)
err := enc.Encode(v)
return b.Bytes(), err
}
|
[
"func",
"(",
"ctx",
"*",
"Context",
")",
"ToJSON",
"(",
"v",
"interface",
"{",
"}",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"b",
":=",
"bytes",
".",
"NewBuffer",
"(",
"nil",
")",
"\n",
"enc",
":=",
"ffjson",
".",
"NewEncoder",
"(",
"b",
")",
"\n",
"err",
":=",
"enc",
".",
"Encode",
"(",
"v",
")",
"\n",
"return",
"b",
".",
"Bytes",
"(",
")",
",",
"err",
"\n",
"}"
] |
// ToJSON serializes v and returns the result
|
[
"ToJSON",
"serializes",
"v",
"and",
"returns",
"the",
"result"
] |
31c8d0b9955432cea19730996643bd857481d6a8
|
https://github.com/gramework/gramework/blob/31c8d0b9955432cea19730996643bd857481d6a8/context.go#L176-L181
|
19,644
|
gramework/gramework
|
context.go
|
UnJSON
|
func (ctx *Context) UnJSON(v interface{}) error {
return ffjson.NewDecoder().Decode(ctx.Request.Body(), &v)
}
|
go
|
func (ctx *Context) UnJSON(v interface{}) error {
return ffjson.NewDecoder().Decode(ctx.Request.Body(), &v)
}
|
[
"func",
"(",
"ctx",
"*",
"Context",
")",
"UnJSON",
"(",
"v",
"interface",
"{",
"}",
")",
"error",
"{",
"return",
"ffjson",
".",
"NewDecoder",
"(",
")",
".",
"Decode",
"(",
"ctx",
".",
"Request",
".",
"Body",
"(",
")",
",",
"&",
"v",
")",
"\n",
"}"
] |
// UnJSON deserializes JSON request body to given variable pointer
|
[
"UnJSON",
"deserializes",
"JSON",
"request",
"body",
"to",
"given",
"variable",
"pointer"
] |
31c8d0b9955432cea19730996643bd857481d6a8
|
https://github.com/gramework/gramework/blob/31c8d0b9955432cea19730996643bd857481d6a8/context.go#L190-L192
|
19,645
|
gramework/gramework
|
app_cache.go
|
NewCacheOptions
|
func NewCacheOptions() *CacheOptions {
return &CacheOptions{
TTL: 30 * time.Second,
Cacheable: func(ctx *Context) bool {
if len(ctx.Request.Header.Peek("Authentication")) > 0 {
return false
}
if len(ctx.Cookies.Storage) > 0 {
return false
}
return true
},
CacheKey: func(ctx *Context) []byte {
return ctx.Path()
},
}
}
|
go
|
func NewCacheOptions() *CacheOptions {
return &CacheOptions{
TTL: 30 * time.Second,
Cacheable: func(ctx *Context) bool {
if len(ctx.Request.Header.Peek("Authentication")) > 0 {
return false
}
if len(ctx.Cookies.Storage) > 0 {
return false
}
return true
},
CacheKey: func(ctx *Context) []byte {
return ctx.Path()
},
}
}
|
[
"func",
"NewCacheOptions",
"(",
")",
"*",
"CacheOptions",
"{",
"return",
"&",
"CacheOptions",
"{",
"TTL",
":",
"30",
"*",
"time",
".",
"Second",
",",
"Cacheable",
":",
"func",
"(",
"ctx",
"*",
"Context",
")",
"bool",
"{",
"if",
"len",
"(",
"ctx",
".",
"Request",
".",
"Header",
".",
"Peek",
"(",
"\"",
"\"",
")",
")",
">",
"0",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"ctx",
".",
"Cookies",
".",
"Storage",
")",
">",
"0",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"return",
"true",
"\n",
"}",
",",
"CacheKey",
":",
"func",
"(",
"ctx",
"*",
"Context",
")",
"[",
"]",
"byte",
"{",
"return",
"ctx",
".",
"Path",
"(",
")",
"\n",
"}",
",",
"}",
"\n",
"}"
] |
// NewCacheOptions returns a cache options with default settings.
|
[
"NewCacheOptions",
"returns",
"a",
"cache",
"options",
"with",
"default",
"settings",
"."
] |
31c8d0b9955432cea19730996643bd857481d6a8
|
https://github.com/gramework/gramework/blob/31c8d0b9955432cea19730996643bd857481d6a8/app_cache.go#L29-L47
|
19,646
|
gramework/gramework
|
x/client/wsHandler.go
|
WSHandler
|
func (client *Instance) WSHandler() func(*gramework.Context) error {
up := websocket.FastHTTPUpgrader{}
return func(ctx *gramework.Context) error {
if websocket.FastHTTPIsWebSocketUpgrade(ctx.RequestCtx) {
return up.Upgrade(ctx.RequestCtx, func(conn *websocket.Conn) {
for {
v := <-client.watch(ctx)
err := conn.WriteMessage(websocket.TextMessage, v)
if err != nil {
break
}
}
})
}
return client.handleHTTP(ctx)
}
}
|
go
|
func (client *Instance) WSHandler() func(*gramework.Context) error {
up := websocket.FastHTTPUpgrader{}
return func(ctx *gramework.Context) error {
if websocket.FastHTTPIsWebSocketUpgrade(ctx.RequestCtx) {
return up.Upgrade(ctx.RequestCtx, func(conn *websocket.Conn) {
for {
v := <-client.watch(ctx)
err := conn.WriteMessage(websocket.TextMessage, v)
if err != nil {
break
}
}
})
}
return client.handleHTTP(ctx)
}
}
|
[
"func",
"(",
"client",
"*",
"Instance",
")",
"WSHandler",
"(",
")",
"func",
"(",
"*",
"gramework",
".",
"Context",
")",
"error",
"{",
"up",
":=",
"websocket",
".",
"FastHTTPUpgrader",
"{",
"}",
"\n",
"return",
"func",
"(",
"ctx",
"*",
"gramework",
".",
"Context",
")",
"error",
"{",
"if",
"websocket",
".",
"FastHTTPIsWebSocketUpgrade",
"(",
"ctx",
".",
"RequestCtx",
")",
"{",
"return",
"up",
".",
"Upgrade",
"(",
"ctx",
".",
"RequestCtx",
",",
"func",
"(",
"conn",
"*",
"websocket",
".",
"Conn",
")",
"{",
"for",
"{",
"v",
":=",
"<-",
"client",
".",
"watch",
"(",
"ctx",
")",
"\n",
"err",
":=",
"conn",
".",
"WriteMessage",
"(",
"websocket",
".",
"TextMessage",
",",
"v",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"break",
"\n",
"}",
"\n",
"}",
"\n",
"}",
")",
"\n",
"}",
"\n\n",
"return",
"client",
".",
"handleHTTP",
"(",
"ctx",
")",
"\n",
"}",
"\n",
"}"
] |
// WSHandler returns gramework handler
|
[
"WSHandler",
"returns",
"gramework",
"handler"
] |
31c8d0b9955432cea19730996643bd857481d6a8
|
https://github.com/gramework/gramework/blob/31c8d0b9955432cea19730996643bd857481d6a8/x/client/wsHandler.go#L21-L38
|
19,647
|
gramework/gramework
|
fasthttprouter_tree.go
|
FindCaseInsensitivePath
|
func (n *node) FindCaseInsensitivePath(path string, fixTrailingSlash bool) ([]byte, bool) {
return n.findCaseInsensitivePathRec(
path,
toLower(path),
make([]byte, zero, len(path)+one), // preallocate enough memory for new path
[4]byte{}, // empty rune buffer
fixTrailingSlash,
)
}
|
go
|
func (n *node) FindCaseInsensitivePath(path string, fixTrailingSlash bool) ([]byte, bool) {
return n.findCaseInsensitivePathRec(
path,
toLower(path),
make([]byte, zero, len(path)+one), // preallocate enough memory for new path
[4]byte{}, // empty rune buffer
fixTrailingSlash,
)
}
|
[
"func",
"(",
"n",
"*",
"node",
")",
"FindCaseInsensitivePath",
"(",
"path",
"string",
",",
"fixTrailingSlash",
"bool",
")",
"(",
"[",
"]",
"byte",
",",
"bool",
")",
"{",
"return",
"n",
".",
"findCaseInsensitivePathRec",
"(",
"path",
",",
"toLower",
"(",
"path",
")",
",",
"make",
"(",
"[",
"]",
"byte",
",",
"zero",
",",
"len",
"(",
"path",
")",
"+",
"one",
")",
",",
"// preallocate enough memory for new path",
"[",
"4",
"]",
"byte",
"{",
"}",
",",
"// empty rune buffer",
"fixTrailingSlash",
",",
")",
"\n",
"}"
] |
// FindCaseInsensitivePath makes a case-insensitive lookup of the given path
// and tries to find a handler.
// It can optionally also fix trailing slashes.
// It returns the case-corrected path and a bool indicating whether the lookup
// was successful.
|
[
"FindCaseInsensitivePath",
"makes",
"a",
"case",
"-",
"insensitive",
"lookup",
"of",
"the",
"given",
"path",
"and",
"tries",
"to",
"find",
"a",
"handler",
".",
"It",
"can",
"optionally",
"also",
"fix",
"trailing",
"slashes",
".",
"It",
"returns",
"the",
"case",
"-",
"corrected",
"path",
"and",
"a",
"bool",
"indicating",
"whether",
"the",
"lookup",
"was",
"successful",
"."
] |
31c8d0b9955432cea19730996643bd857481d6a8
|
https://github.com/gramework/gramework/blob/31c8d0b9955432cea19730996643bd857481d6a8/fasthttprouter_tree.go#L519-L527
|
19,648
|
gramework/gramework
|
x/sqlgen/create.go
|
Table
|
func (cb *CreateBuilder) Table(name string) *CreateTableBuilder {
return &CreateTableBuilder{
name: name,
columns: make([]tableColumn, 0),
}
}
|
go
|
func (cb *CreateBuilder) Table(name string) *CreateTableBuilder {
return &CreateTableBuilder{
name: name,
columns: make([]tableColumn, 0),
}
}
|
[
"func",
"(",
"cb",
"*",
"CreateBuilder",
")",
"Table",
"(",
"name",
"string",
")",
"*",
"CreateTableBuilder",
"{",
"return",
"&",
"CreateTableBuilder",
"{",
"name",
":",
"name",
",",
"columns",
":",
"make",
"(",
"[",
"]",
"tableColumn",
",",
"0",
")",
",",
"}",
"\n",
"}"
] |
// Table says that we are CREATE-ing
// a TABLE with given name
|
[
"Table",
"says",
"that",
"we",
"are",
"CREATE",
"-",
"ing",
"a",
"TABLE",
"with",
"given",
"name"
] |
31c8d0b9955432cea19730996643bd857481d6a8
|
https://github.com/gramework/gramework/blob/31c8d0b9955432cea19730996643bd857481d6a8/x/sqlgen/create.go#L26-L31
|
19,649
|
gramework/gramework
|
router_domain.go
|
Domain
|
func (app *App) Domain(domain string) *Router {
app.domainListLock.Lock()
if app.domains[domain] == nil {
app.domains[domain] = &Router{
router: newRouter(),
app: app,
}
}
app.domainListLock.Unlock()
return app.domains[domain]
}
|
go
|
func (app *App) Domain(domain string) *Router {
app.domainListLock.Lock()
if app.domains[domain] == nil {
app.domains[domain] = &Router{
router: newRouter(),
app: app,
}
}
app.domainListLock.Unlock()
return app.domains[domain]
}
|
[
"func",
"(",
"app",
"*",
"App",
")",
"Domain",
"(",
"domain",
"string",
")",
"*",
"Router",
"{",
"app",
".",
"domainListLock",
".",
"Lock",
"(",
")",
"\n",
"if",
"app",
".",
"domains",
"[",
"domain",
"]",
"==",
"nil",
"{",
"app",
".",
"domains",
"[",
"domain",
"]",
"=",
"&",
"Router",
"{",
"router",
":",
"newRouter",
"(",
")",
",",
"app",
":",
"app",
",",
"}",
"\n",
"}",
"\n",
"app",
".",
"domainListLock",
".",
"Unlock",
"(",
")",
"\n",
"return",
"app",
".",
"domains",
"[",
"domain",
"]",
"\n",
"}"
] |
// Domain returns a domain router
|
[
"Domain",
"returns",
"a",
"domain",
"router"
] |
31c8d0b9955432cea19730996643bd857481d6a8
|
https://github.com/gramework/gramework/blob/31c8d0b9955432cea19730996643bd857481d6a8/router_domain.go#L14-L24
|
19,650
|
gramework/gramework
|
app_router.go
|
ServeDir
|
func (app *App) ServeDir(path string) func(*Context) {
return app.ServeDirCustom(path, 0, true, false, []string{"index.html", "index.htm"})
}
|
go
|
func (app *App) ServeDir(path string) func(*Context) {
return app.ServeDirCustom(path, 0, true, false, []string{"index.html", "index.htm"})
}
|
[
"func",
"(",
"app",
"*",
"App",
")",
"ServeDir",
"(",
"path",
"string",
")",
"func",
"(",
"*",
"Context",
")",
"{",
"return",
"app",
".",
"ServeDirCustom",
"(",
"path",
",",
"0",
",",
"true",
",",
"false",
",",
"[",
"]",
"string",
"{",
"\"",
"\"",
",",
"\"",
"\"",
"}",
")",
"\n",
"}"
] |
// ServeDir from a given path
|
[
"ServeDir",
"from",
"a",
"given",
"path"
] |
31c8d0b9955432cea19730996643bd857481d6a8
|
https://github.com/gramework/gramework/blob/31c8d0b9955432cea19730996643bd857481d6a8/app_router.go#L20-L22
|
19,651
|
gramework/gramework
|
app_router.go
|
ServeDirCustom
|
func (app *App) ServeDirCustom(path string, stripSlashes int, compress bool, generateIndexPages bool, indexNames []string) func(*Context) {
if indexNames == nil {
indexNames = []string{}
}
fs := &fasthttp.FS{
Root: path,
IndexNames: indexNames,
GenerateIndexPages: generateIndexPages,
Compress: compress,
CacheDuration: 5 * time.Minute,
CompressedFileSuffix: ".gz",
}
if stripSlashes > 0 {
fs.PathRewrite = fasthttp.NewPathSlashesStripper(stripSlashes)
}
h := fs.NewRequestHandler()
return func(ctx *Context) {
h(ctx.RequestCtx)
}
}
|
go
|
func (app *App) ServeDirCustom(path string, stripSlashes int, compress bool, generateIndexPages bool, indexNames []string) func(*Context) {
if indexNames == nil {
indexNames = []string{}
}
fs := &fasthttp.FS{
Root: path,
IndexNames: indexNames,
GenerateIndexPages: generateIndexPages,
Compress: compress,
CacheDuration: 5 * time.Minute,
CompressedFileSuffix: ".gz",
}
if stripSlashes > 0 {
fs.PathRewrite = fasthttp.NewPathSlashesStripper(stripSlashes)
}
h := fs.NewRequestHandler()
return func(ctx *Context) {
h(ctx.RequestCtx)
}
}
|
[
"func",
"(",
"app",
"*",
"App",
")",
"ServeDirCustom",
"(",
"path",
"string",
",",
"stripSlashes",
"int",
",",
"compress",
"bool",
",",
"generateIndexPages",
"bool",
",",
"indexNames",
"[",
"]",
"string",
")",
"func",
"(",
"*",
"Context",
")",
"{",
"if",
"indexNames",
"==",
"nil",
"{",
"indexNames",
"=",
"[",
"]",
"string",
"{",
"}",
"\n",
"}",
"\n",
"fs",
":=",
"&",
"fasthttp",
".",
"FS",
"{",
"Root",
":",
"path",
",",
"IndexNames",
":",
"indexNames",
",",
"GenerateIndexPages",
":",
"generateIndexPages",
",",
"Compress",
":",
"compress",
",",
"CacheDuration",
":",
"5",
"*",
"time",
".",
"Minute",
",",
"CompressedFileSuffix",
":",
"\"",
"\"",
",",
"}",
"\n\n",
"if",
"stripSlashes",
">",
"0",
"{",
"fs",
".",
"PathRewrite",
"=",
"fasthttp",
".",
"NewPathSlashesStripper",
"(",
"stripSlashes",
")",
"\n",
"}",
"\n\n",
"h",
":=",
"fs",
".",
"NewRequestHandler",
"(",
")",
"\n",
"return",
"func",
"(",
"ctx",
"*",
"Context",
")",
"{",
"h",
"(",
"ctx",
".",
"RequestCtx",
")",
"\n",
"}",
"\n",
"}"
] |
// ServeDirCustom gives you ability to serve a dir with custom settings
|
[
"ServeDirCustom",
"gives",
"you",
"ability",
"to",
"serve",
"a",
"dir",
"with",
"custom",
"settings"
] |
31c8d0b9955432cea19730996643bd857481d6a8
|
https://github.com/gramework/gramework/blob/31c8d0b9955432cea19730996643bd857481d6a8/app_router.go#L25-L46
|
19,652
|
gramework/gramework
|
app_router.go
|
ServeDirNoCache
|
func (app *App) ServeDirNoCache(path string) func(*Context) {
return app.ServeDirNoCacheCustom(path, 0, true, false, nil)
}
|
go
|
func (app *App) ServeDirNoCache(path string) func(*Context) {
return app.ServeDirNoCacheCustom(path, 0, true, false, nil)
}
|
[
"func",
"(",
"app",
"*",
"App",
")",
"ServeDirNoCache",
"(",
"path",
"string",
")",
"func",
"(",
"*",
"Context",
")",
"{",
"return",
"app",
".",
"ServeDirNoCacheCustom",
"(",
"path",
",",
"0",
",",
"true",
",",
"false",
",",
"nil",
")",
"\n",
"}"
] |
// ServeDirNoCache gives you ability to serve a dir without caching
|
[
"ServeDirNoCache",
"gives",
"you",
"ability",
"to",
"serve",
"a",
"dir",
"without",
"caching"
] |
31c8d0b9955432cea19730996643bd857481d6a8
|
https://github.com/gramework/gramework/blob/31c8d0b9955432cea19730996643bd857481d6a8/app_router.go#L49-L51
|
19,653
|
gramework/gramework
|
app_router.go
|
ServeDirNoCacheCustom
|
func (app *App) ServeDirNoCacheCustom(path string, stripSlashes int, compress bool, generateIndexPages bool, indexNames []string) func(*Context) {
if indexNames == nil {
indexNames = []string{}
}
fs := &fasthttp.FS{
Root: path,
IndexNames: indexNames,
GenerateIndexPages: generateIndexPages,
Compress: compress,
CacheDuration: time.Millisecond,
CompressedFileSuffix: ".gz",
}
if stripSlashes > 0 {
fs.PathRewrite = fasthttp.NewPathSlashesStripper(stripSlashes)
}
h := fs.NewRequestHandler()
pragmaH := "Pragma"
pragmaV := "no-cache"
expiresH := "Expires"
expiresV := "0"
ccH := "Cache-Control"
ccV := "no-cache, no-store, must-revalidate"
return func(ctx *Context) {
ctx.Response.Header.Add(pragmaH, pragmaV)
ctx.Response.Header.Add(expiresH, expiresV)
ctx.Response.Header.Add(ccH, ccV)
h(ctx.RequestCtx)
}
}
|
go
|
func (app *App) ServeDirNoCacheCustom(path string, stripSlashes int, compress bool, generateIndexPages bool, indexNames []string) func(*Context) {
if indexNames == nil {
indexNames = []string{}
}
fs := &fasthttp.FS{
Root: path,
IndexNames: indexNames,
GenerateIndexPages: generateIndexPages,
Compress: compress,
CacheDuration: time.Millisecond,
CompressedFileSuffix: ".gz",
}
if stripSlashes > 0 {
fs.PathRewrite = fasthttp.NewPathSlashesStripper(stripSlashes)
}
h := fs.NewRequestHandler()
pragmaH := "Pragma"
pragmaV := "no-cache"
expiresH := "Expires"
expiresV := "0"
ccH := "Cache-Control"
ccV := "no-cache, no-store, must-revalidate"
return func(ctx *Context) {
ctx.Response.Header.Add(pragmaH, pragmaV)
ctx.Response.Header.Add(expiresH, expiresV)
ctx.Response.Header.Add(ccH, ccV)
h(ctx.RequestCtx)
}
}
|
[
"func",
"(",
"app",
"*",
"App",
")",
"ServeDirNoCacheCustom",
"(",
"path",
"string",
",",
"stripSlashes",
"int",
",",
"compress",
"bool",
",",
"generateIndexPages",
"bool",
",",
"indexNames",
"[",
"]",
"string",
")",
"func",
"(",
"*",
"Context",
")",
"{",
"if",
"indexNames",
"==",
"nil",
"{",
"indexNames",
"=",
"[",
"]",
"string",
"{",
"}",
"\n",
"}",
"\n",
"fs",
":=",
"&",
"fasthttp",
".",
"FS",
"{",
"Root",
":",
"path",
",",
"IndexNames",
":",
"indexNames",
",",
"GenerateIndexPages",
":",
"generateIndexPages",
",",
"Compress",
":",
"compress",
",",
"CacheDuration",
":",
"time",
".",
"Millisecond",
",",
"CompressedFileSuffix",
":",
"\"",
"\"",
",",
"}",
"\n\n",
"if",
"stripSlashes",
">",
"0",
"{",
"fs",
".",
"PathRewrite",
"=",
"fasthttp",
".",
"NewPathSlashesStripper",
"(",
"stripSlashes",
")",
"\n",
"}",
"\n\n",
"h",
":=",
"fs",
".",
"NewRequestHandler",
"(",
")",
"\n",
"pragmaH",
":=",
"\"",
"\"",
"\n",
"pragmaV",
":=",
"\"",
"\"",
"\n",
"expiresH",
":=",
"\"",
"\"",
"\n",
"expiresV",
":=",
"\"",
"\"",
"\n",
"ccH",
":=",
"\"",
"\"",
"\n",
"ccV",
":=",
"\"",
"\"",
"\n",
"return",
"func",
"(",
"ctx",
"*",
"Context",
")",
"{",
"ctx",
".",
"Response",
".",
"Header",
".",
"Add",
"(",
"pragmaH",
",",
"pragmaV",
")",
"\n",
"ctx",
".",
"Response",
".",
"Header",
".",
"Add",
"(",
"expiresH",
",",
"expiresV",
")",
"\n",
"ctx",
".",
"Response",
".",
"Header",
".",
"Add",
"(",
"ccH",
",",
"ccV",
")",
"\n",
"h",
"(",
"ctx",
".",
"RequestCtx",
")",
"\n",
"}",
"\n",
"}"
] |
// ServeDirNoCacheCustom gives you ability to serve a dir with custom settings without caching
|
[
"ServeDirNoCacheCustom",
"gives",
"you",
"ability",
"to",
"serve",
"a",
"dir",
"with",
"custom",
"settings",
"without",
"caching"
] |
31c8d0b9955432cea19730996643bd857481d6a8
|
https://github.com/gramework/gramework/blob/31c8d0b9955432cea19730996643bd857481d6a8/app_router.go#L54-L84
|
19,654
|
gramework/gramework
|
regFlags.go
|
AddFlag
|
func (app *App) AddFlag(f Flag) {
if app.flagsQueue == nil {
app.flagsQueue = make([]Flag, 0)
}
app.flagsQueue = append(app.flagsQueue, f)
}
|
go
|
func (app *App) AddFlag(f Flag) {
if app.flagsQueue == nil {
app.flagsQueue = make([]Flag, 0)
}
app.flagsQueue = append(app.flagsQueue, f)
}
|
[
"func",
"(",
"app",
"*",
"App",
")",
"AddFlag",
"(",
"f",
"Flag",
")",
"{",
"if",
"app",
".",
"flagsQueue",
"==",
"nil",
"{",
"app",
".",
"flagsQueue",
"=",
"make",
"(",
"[",
"]",
"Flag",
",",
"0",
")",
"\n",
"}",
"\n",
"app",
".",
"flagsQueue",
"=",
"append",
"(",
"app",
".",
"flagsQueue",
",",
"f",
")",
"\n",
"}"
] |
// AddFlag adds a Flag to flag queue that will be
// parsed if flags wasn't parsed yet
|
[
"AddFlag",
"adds",
"a",
"Flag",
"to",
"flag",
"queue",
"that",
"will",
"be",
"parsed",
"if",
"flags",
"wasn",
"t",
"parsed",
"yet"
] |
31c8d0b9955432cea19730996643bd857481d6a8
|
https://github.com/gramework/gramework/blob/31c8d0b9955432cea19730996643bd857481d6a8/regFlags.go#L29-L34
|
19,655
|
gramework/gramework
|
regFlags.go
|
RegFlags
|
func (app *App) RegFlags() {
if app.Flags.values == nil {
app.Flags.values = make(map[string]Flag)
}
app.flagsRegistered = true
for _, v := range app.flagsQueue {
app.Flags.values[v.Name] = Flag{
Name: v.Name,
Description: v.Description,
Default: v.Default,
Value: flag.String(v.Name, v.Default, v.Description),
}
}
}
|
go
|
func (app *App) RegFlags() {
if app.Flags.values == nil {
app.Flags.values = make(map[string]Flag)
}
app.flagsRegistered = true
for _, v := range app.flagsQueue {
app.Flags.values[v.Name] = Flag{
Name: v.Name,
Description: v.Description,
Default: v.Default,
Value: flag.String(v.Name, v.Default, v.Description),
}
}
}
|
[
"func",
"(",
"app",
"*",
"App",
")",
"RegFlags",
"(",
")",
"{",
"if",
"app",
".",
"Flags",
".",
"values",
"==",
"nil",
"{",
"app",
".",
"Flags",
".",
"values",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"Flag",
")",
"\n",
"}",
"\n",
"app",
".",
"flagsRegistered",
"=",
"true",
"\n",
"for",
"_",
",",
"v",
":=",
"range",
"app",
".",
"flagsQueue",
"{",
"app",
".",
"Flags",
".",
"values",
"[",
"v",
".",
"Name",
"]",
"=",
"Flag",
"{",
"Name",
":",
"v",
".",
"Name",
",",
"Description",
":",
"v",
".",
"Description",
",",
"Default",
":",
"v",
".",
"Default",
",",
"Value",
":",
"flag",
".",
"String",
"(",
"v",
".",
"Name",
",",
"v",
".",
"Default",
",",
"v",
".",
"Description",
")",
",",
"}",
"\n",
"}",
"\n",
"}"
] |
// RegFlags registers current flag queue in flag parser
|
[
"RegFlags",
"registers",
"current",
"flag",
"queue",
"in",
"flag",
"parser"
] |
31c8d0b9955432cea19730996643bd857481d6a8
|
https://github.com/gramework/gramework/blob/31c8d0b9955432cea19730996643bd857481d6a8/regFlags.go#L37-L50
|
19,656
|
gramework/gramework
|
regFlags.go
|
GetStringFlag
|
func (app *App) GetStringFlag(name string) (string, bool) {
if !flag.Parsed() && !flagsDisabled {
flag.Parse()
}
if app.Flags.values != nil {
if bindFlag, ok := app.Flags.values[name]; ok {
return *bindFlag.Value, ok
}
}
return "", false
}
|
go
|
func (app *App) GetStringFlag(name string) (string, bool) {
if !flag.Parsed() && !flagsDisabled {
flag.Parse()
}
if app.Flags.values != nil {
if bindFlag, ok := app.Flags.values[name]; ok {
return *bindFlag.Value, ok
}
}
return "", false
}
|
[
"func",
"(",
"app",
"*",
"App",
")",
"GetStringFlag",
"(",
"name",
"string",
")",
"(",
"string",
",",
"bool",
")",
"{",
"if",
"!",
"flag",
".",
"Parsed",
"(",
")",
"&&",
"!",
"flagsDisabled",
"{",
"flag",
".",
"Parse",
"(",
")",
"\n",
"}",
"\n",
"if",
"app",
".",
"Flags",
".",
"values",
"!=",
"nil",
"{",
"if",
"bindFlag",
",",
"ok",
":=",
"app",
".",
"Flags",
".",
"values",
"[",
"name",
"]",
";",
"ok",
"{",
"return",
"*",
"bindFlag",
".",
"Value",
",",
"ok",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"\"",
"\"",
",",
"false",
"\n",
"}"
] |
// GetStringFlag return command line app flag value by name and false if not exists
|
[
"GetStringFlag",
"return",
"command",
"line",
"app",
"flag",
"value",
"by",
"name",
"and",
"false",
"if",
"not",
"exists"
] |
31c8d0b9955432cea19730996643bd857481d6a8
|
https://github.com/gramework/gramework/blob/31c8d0b9955432cea19730996643bd857481d6a8/regFlags.go#L53-L64
|
19,657
|
gramework/gramework
|
middleware.go
|
Use
|
func (app *App) Use(middleware interface{}) error {
if middleware == nil {
return ErrEmptyMiddleware
}
processor, err := app.middlewareProcessor(middleware)
app.middlewaresMu.Lock()
if err == nil {
app.middlewares = append(app.middlewares, processor)
}
app.middlewaresMu.Unlock()
return err
}
|
go
|
func (app *App) Use(middleware interface{}) error {
if middleware == nil {
return ErrEmptyMiddleware
}
processor, err := app.middlewareProcessor(middleware)
app.middlewaresMu.Lock()
if err == nil {
app.middlewares = append(app.middlewares, processor)
}
app.middlewaresMu.Unlock()
return err
}
|
[
"func",
"(",
"app",
"*",
"App",
")",
"Use",
"(",
"middleware",
"interface",
"{",
"}",
")",
"error",
"{",
"if",
"middleware",
"==",
"nil",
"{",
"return",
"ErrEmptyMiddleware",
"\n",
"}",
"\n",
"processor",
",",
"err",
":=",
"app",
".",
"middlewareProcessor",
"(",
"middleware",
")",
"\n",
"app",
".",
"middlewaresMu",
".",
"Lock",
"(",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"app",
".",
"middlewares",
"=",
"append",
"(",
"app",
".",
"middlewares",
",",
"processor",
")",
"\n",
"}",
"\n",
"app",
".",
"middlewaresMu",
".",
"Unlock",
"(",
")",
"\n\n",
"return",
"err",
"\n",
"}"
] |
// Use the middleware before request processing
|
[
"Use",
"the",
"middleware",
"before",
"request",
"processing"
] |
31c8d0b9955432cea19730996643bd857481d6a8
|
https://github.com/gramework/gramework/blob/31c8d0b9955432cea19730996643bd857481d6a8/middleware.go#L35-L47
|
19,658
|
gramework/gramework
|
middleware.go
|
UsePre
|
func (app *App) UsePre(middleware interface{}) error {
if middleware == nil {
return ErrEmptyMiddleware
}
processor, err := app.middlewareProcessor(middleware)
app.preMiddlewaresMu.Lock()
if err == nil {
app.preMiddlewares = append(app.preMiddlewares, processor)
}
app.preMiddlewaresMu.Unlock()
return err
}
|
go
|
func (app *App) UsePre(middleware interface{}) error {
if middleware == nil {
return ErrEmptyMiddleware
}
processor, err := app.middlewareProcessor(middleware)
app.preMiddlewaresMu.Lock()
if err == nil {
app.preMiddlewares = append(app.preMiddlewares, processor)
}
app.preMiddlewaresMu.Unlock()
return err
}
|
[
"func",
"(",
"app",
"*",
"App",
")",
"UsePre",
"(",
"middleware",
"interface",
"{",
"}",
")",
"error",
"{",
"if",
"middleware",
"==",
"nil",
"{",
"return",
"ErrEmptyMiddleware",
"\n",
"}",
"\n",
"processor",
",",
"err",
":=",
"app",
".",
"middlewareProcessor",
"(",
"middleware",
")",
"\n",
"app",
".",
"preMiddlewaresMu",
".",
"Lock",
"(",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"app",
".",
"preMiddlewares",
"=",
"append",
"(",
"app",
".",
"preMiddlewares",
",",
"processor",
")",
"\n",
"}",
"\n",
"app",
".",
"preMiddlewaresMu",
".",
"Unlock",
"(",
")",
"\n\n",
"return",
"err",
"\n",
"}"
] |
// UsePre registers middleware before any other middleware. Use only for metrics or access control!
|
[
"UsePre",
"registers",
"middleware",
"before",
"any",
"other",
"middleware",
".",
"Use",
"only",
"for",
"metrics",
"or",
"access",
"control!"
] |
31c8d0b9955432cea19730996643bd857481d6a8
|
https://github.com/gramework/gramework/blob/31c8d0b9955432cea19730996643bd857481d6a8/middleware.go#L50-L62
|
19,659
|
gramework/gramework
|
middleware.go
|
UseAfterRequest
|
func (app *App) UseAfterRequest(middleware interface{}) error {
if middleware == nil {
return ErrEmptyMiddleware
}
processor, err := app.middlewareProcessor(middleware)
app.middlewaresAfterRequestMu.Lock()
if err == nil {
app.middlewaresAfterRequest = append(app.middlewaresAfterRequest, processor)
}
app.middlewaresAfterRequestMu.Unlock()
return nil
}
|
go
|
func (app *App) UseAfterRequest(middleware interface{}) error {
if middleware == nil {
return ErrEmptyMiddleware
}
processor, err := app.middlewareProcessor(middleware)
app.middlewaresAfterRequestMu.Lock()
if err == nil {
app.middlewaresAfterRequest = append(app.middlewaresAfterRequest, processor)
}
app.middlewaresAfterRequestMu.Unlock()
return nil
}
|
[
"func",
"(",
"app",
"*",
"App",
")",
"UseAfterRequest",
"(",
"middleware",
"interface",
"{",
"}",
")",
"error",
"{",
"if",
"middleware",
"==",
"nil",
"{",
"return",
"ErrEmptyMiddleware",
"\n",
"}",
"\n\n",
"processor",
",",
"err",
":=",
"app",
".",
"middlewareProcessor",
"(",
"middleware",
")",
"\n",
"app",
".",
"middlewaresAfterRequestMu",
".",
"Lock",
"(",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"app",
".",
"middlewaresAfterRequest",
"=",
"append",
"(",
"app",
".",
"middlewaresAfterRequest",
",",
"processor",
")",
"\n",
"}",
"\n",
"app",
".",
"middlewaresAfterRequestMu",
".",
"Unlock",
"(",
")",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// UseAfterRequest the middleware after request processing
|
[
"UseAfterRequest",
"the",
"middleware",
"after",
"request",
"processing"
] |
31c8d0b9955432cea19730996643bd857481d6a8
|
https://github.com/gramework/gramework/blob/31c8d0b9955432cea19730996643bd857481d6a8/middleware.go#L65-L78
|
19,660
|
gramework/gramework
|
context_logHeaders.go
|
LogHeaders
|
func (ctx *Context) LogHeaders() {
ctx.Request.Header.VisitAll(func(k, v []byte) {
ctx.Logger.Debugf("%s = [%s]\n", k, v)
})
}
|
go
|
func (ctx *Context) LogHeaders() {
ctx.Request.Header.VisitAll(func(k, v []byte) {
ctx.Logger.Debugf("%s = [%s]\n", k, v)
})
}
|
[
"func",
"(",
"ctx",
"*",
"Context",
")",
"LogHeaders",
"(",
")",
"{",
"ctx",
".",
"Request",
".",
"Header",
".",
"VisitAll",
"(",
"func",
"(",
"k",
",",
"v",
"[",
"]",
"byte",
")",
"{",
"ctx",
".",
"Logger",
".",
"Debugf",
"(",
"\"",
"\\n",
"\"",
",",
"k",
",",
"v",
")",
"\n",
"}",
")",
"\n",
"}"
] |
// LogHeaders logs all request headers for debug
|
[
"LogHeaders",
"logs",
"all",
"request",
"headers",
"for",
"debug"
] |
31c8d0b9955432cea19730996643bd857481d6a8
|
https://github.com/gramework/gramework/blob/31c8d0b9955432cea19730996643bd857481d6a8/context_logHeaders.go#L14-L18
|
19,661
|
gramework/gramework
|
context_proxy.go
|
Proxy
|
func (ctx *Context) Proxy(url string) (err error) {
proxyReq := fasthttp.AcquireRequest()
ctx.Request.CopyTo(proxyReq)
proxyReq.SetRequestURI(url)
err = fasthttp.Do(proxyReq, &ctx.Response)
fasthttp.ReleaseRequest(proxyReq)
return
}
|
go
|
func (ctx *Context) Proxy(url string) (err error) {
proxyReq := fasthttp.AcquireRequest()
ctx.Request.CopyTo(proxyReq)
proxyReq.SetRequestURI(url)
err = fasthttp.Do(proxyReq, &ctx.Response)
fasthttp.ReleaseRequest(proxyReq)
return
}
|
[
"func",
"(",
"ctx",
"*",
"Context",
")",
"Proxy",
"(",
"url",
"string",
")",
"(",
"err",
"error",
")",
"{",
"proxyReq",
":=",
"fasthttp",
".",
"AcquireRequest",
"(",
")",
"\n",
"ctx",
".",
"Request",
".",
"CopyTo",
"(",
"proxyReq",
")",
"\n",
"proxyReq",
".",
"SetRequestURI",
"(",
"url",
")",
"\n\n",
"err",
"=",
"fasthttp",
".",
"Do",
"(",
"proxyReq",
",",
"&",
"ctx",
".",
"Response",
")",
"\n\n",
"fasthttp",
".",
"ReleaseRequest",
"(",
"proxyReq",
")",
"\n",
"return",
"\n",
"}"
] |
// Proxy request to given url
|
[
"Proxy",
"request",
"to",
"given",
"url"
] |
31c8d0b9955432cea19730996643bd857481d6a8
|
https://github.com/gramework/gramework/blob/31c8d0b9955432cea19730996643bd857481d6a8/context_proxy.go#L18-L27
|
19,662
|
gramework/gramework
|
healthchecks/hc.go
|
Register
|
func Register(r interface{}, collectors ...func() (statKey string, stats interface{})) error {
return doReg(r, collectors, true, true)
}
|
go
|
func Register(r interface{}, collectors ...func() (statKey string, stats interface{})) error {
return doReg(r, collectors, true, true)
}
|
[
"func",
"Register",
"(",
"r",
"interface",
"{",
"}",
",",
"collectors",
"...",
"func",
"(",
")",
"(",
"statKey",
"string",
",",
"stats",
"interface",
"{",
"}",
")",
")",
"error",
"{",
"return",
"doReg",
"(",
"r",
",",
"collectors",
",",
"true",
",",
"true",
")",
"\n",
"}"
] |
// Register both ping and healthcheck endpoints
|
[
"Register",
"both",
"ping",
"and",
"healthcheck",
"endpoints"
] |
31c8d0b9955432cea19730996643bd857481d6a8
|
https://github.com/gramework/gramework/blob/31c8d0b9955432cea19730996643bd857481d6a8/healthchecks/hc.go#L4-L6
|
19,663
|
gramework/gramework
|
healthchecks/hc.go
|
RegisterHealthcheck
|
func RegisterHealthcheck(r interface{}, collectors ...func() (statKey string, stats interface{})) error {
return doReg(r, collectors, false, true)
}
|
go
|
func RegisterHealthcheck(r interface{}, collectors ...func() (statKey string, stats interface{})) error {
return doReg(r, collectors, false, true)
}
|
[
"func",
"RegisterHealthcheck",
"(",
"r",
"interface",
"{",
"}",
",",
"collectors",
"...",
"func",
"(",
")",
"(",
"statKey",
"string",
",",
"stats",
"interface",
"{",
"}",
")",
")",
"error",
"{",
"return",
"doReg",
"(",
"r",
",",
"collectors",
",",
"false",
",",
"true",
")",
"\n",
"}"
] |
// RegisterHealthcheck registers healthcheck endpoint
|
[
"RegisterHealthcheck",
"registers",
"healthcheck",
"endpoint"
] |
31c8d0b9955432cea19730996643bd857481d6a8
|
https://github.com/gramework/gramework/blob/31c8d0b9955432cea19730996643bd857481d6a8/healthchecks/hc.go#L14-L16
|
19,664
|
gramework/gramework
|
infrastructure/infrastructure_New.go
|
New
|
func New() *Infrastructure {
return &Infrastructure{
Lock: new(sync.RWMutex),
Services: make(map[string]*Service),
UpdateTimestamp: time.Now().UnixNano(),
}
}
|
go
|
func New() *Infrastructure {
return &Infrastructure{
Lock: new(sync.RWMutex),
Services: make(map[string]*Service),
UpdateTimestamp: time.Now().UnixNano(),
}
}
|
[
"func",
"New",
"(",
")",
"*",
"Infrastructure",
"{",
"return",
"&",
"Infrastructure",
"{",
"Lock",
":",
"new",
"(",
"sync",
".",
"RWMutex",
")",
",",
"Services",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"Service",
")",
",",
"UpdateTimestamp",
":",
"time",
".",
"Now",
"(",
")",
".",
"UnixNano",
"(",
")",
",",
"}",
"\n",
"}"
] |
// New initializes an empty infrastructure
|
[
"New",
"initializes",
"an",
"empty",
"infrastructure"
] |
31c8d0b9955432cea19730996643bd857481d6a8
|
https://github.com/gramework/gramework/blob/31c8d0b9955432cea19730996643bd857481d6a8/infrastructure/infrastructure_New.go#L9-L15
|
19,665
|
gramework/gramework
|
behind/akamai/internal/portWhitelist/portWhitelist.go
|
IsPortInRange
|
func IsPortInRange(port string) bool {
if strings.Contains(port, ",") {
ports := strings.Split(port, ",")
for _, p := range ports {
if strings.Contains(p, "-") && IsPortInRange(p) {
return true
}
for _, allowedPort := range allowedPorts {
if p == allowedPort {
return true
}
}
}
return false
}
if strings.Contains(port, "-") {
portRange := strings.Split(port, "-")
if len(portRange) != 2 {
return false
}
min, err := strconv.Atoi(portRange[0])
if err != nil {
return false
}
max, err := strconv.Atoi(portRange[1])
if err != nil {
return false
}
for _, p := range allowedPortsInts {
if min <= p && max >= p {
return true
}
}
return false
}
for _, p := range allowedPorts {
if port == p {
return true
}
}
return false
}
|
go
|
func IsPortInRange(port string) bool {
if strings.Contains(port, ",") {
ports := strings.Split(port, ",")
for _, p := range ports {
if strings.Contains(p, "-") && IsPortInRange(p) {
return true
}
for _, allowedPort := range allowedPorts {
if p == allowedPort {
return true
}
}
}
return false
}
if strings.Contains(port, "-") {
portRange := strings.Split(port, "-")
if len(portRange) != 2 {
return false
}
min, err := strconv.Atoi(portRange[0])
if err != nil {
return false
}
max, err := strconv.Atoi(portRange[1])
if err != nil {
return false
}
for _, p := range allowedPortsInts {
if min <= p && max >= p {
return true
}
}
return false
}
for _, p := range allowedPorts {
if port == p {
return true
}
}
return false
}
|
[
"func",
"IsPortInRange",
"(",
"port",
"string",
")",
"bool",
"{",
"if",
"strings",
".",
"Contains",
"(",
"port",
",",
"\"",
"\"",
")",
"{",
"ports",
":=",
"strings",
".",
"Split",
"(",
"port",
",",
"\"",
"\"",
")",
"\n",
"for",
"_",
",",
"p",
":=",
"range",
"ports",
"{",
"if",
"strings",
".",
"Contains",
"(",
"p",
",",
"\"",
"\"",
")",
"&&",
"IsPortInRange",
"(",
"p",
")",
"{",
"return",
"true",
"\n",
"}",
"\n",
"for",
"_",
",",
"allowedPort",
":=",
"range",
"allowedPorts",
"{",
"if",
"p",
"==",
"allowedPort",
"{",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"false",
"\n",
"}",
"\n\n",
"if",
"strings",
".",
"Contains",
"(",
"port",
",",
"\"",
"\"",
")",
"{",
"portRange",
":=",
"strings",
".",
"Split",
"(",
"port",
",",
"\"",
"\"",
")",
"\n",
"if",
"len",
"(",
"portRange",
")",
"!=",
"2",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"min",
",",
"err",
":=",
"strconv",
".",
"Atoi",
"(",
"portRange",
"[",
"0",
"]",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"max",
",",
"err",
":=",
"strconv",
".",
"Atoi",
"(",
"portRange",
"[",
"1",
"]",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"false",
"\n",
"}",
"\n",
"for",
"_",
",",
"p",
":=",
"range",
"allowedPortsInts",
"{",
"if",
"min",
"<=",
"p",
"&&",
"max",
">=",
"p",
"{",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"p",
":=",
"range",
"allowedPorts",
"{",
"if",
"port",
"==",
"p",
"{",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"false",
"\n",
"}"
] |
// IsPortInRange checks if port is in whitelist.
|
[
"IsPortInRange",
"checks",
"if",
"port",
"is",
"in",
"whitelist",
"."
] |
31c8d0b9955432cea19730996643bd857481d6a8
|
https://github.com/gramework/gramework/blob/31c8d0b9955432cea19730996643bd857481d6a8/behind/akamai/internal/portWhitelist/portWhitelist.go#L31-L78
|
19,666
|
gramework/gramework
|
x/sqlgen/insert.go
|
Insert
|
func Insert(table string) *InsertBuilder {
return &InsertBuilder{
tableName: table,
query: fmt.Sprintln(`INSERT INTO`, table),
lock: new(sync.Mutex),
}
}
|
go
|
func Insert(table string) *InsertBuilder {
return &InsertBuilder{
tableName: table,
query: fmt.Sprintln(`INSERT INTO`, table),
lock: new(sync.Mutex),
}
}
|
[
"func",
"Insert",
"(",
"table",
"string",
")",
"*",
"InsertBuilder",
"{",
"return",
"&",
"InsertBuilder",
"{",
"tableName",
":",
"table",
",",
"query",
":",
"fmt",
".",
"Sprintln",
"(",
"`INSERT INTO`",
",",
"table",
")",
",",
"lock",
":",
"new",
"(",
"sync",
".",
"Mutex",
")",
",",
"}",
"\n",
"}"
] |
// Insert statement builder generates
// an insert statement using `?` placeholders
// for values
|
[
"Insert",
"statement",
"builder",
"generates",
"an",
"insert",
"statement",
"using",
"?",
"placeholders",
"for",
"values"
] |
31c8d0b9955432cea19730996643bd857481d6a8
|
https://github.com/gramework/gramework/blob/31c8d0b9955432cea19730996643bd857481d6a8/x/sqlgen/insert.go#L12-L18
|
19,667
|
gramework/gramework
|
x/sqlgen/insert.go
|
PreparedInsert
|
func PreparedInsert(table string) *InsertBuilder {
i := Insert(table)
i.prepared = true
return i
}
|
go
|
func PreparedInsert(table string) *InsertBuilder {
i := Insert(table)
i.prepared = true
return i
}
|
[
"func",
"PreparedInsert",
"(",
"table",
"string",
")",
"*",
"InsertBuilder",
"{",
"i",
":=",
"Insert",
"(",
"table",
")",
"\n",
"i",
".",
"prepared",
"=",
"true",
"\n",
"return",
"i",
"\n",
"}"
] |
// PreparedInsert statement builder generates
// the insert SQL statement with values built
// in the statement without using placeholders
|
[
"PreparedInsert",
"statement",
"builder",
"generates",
"the",
"insert",
"SQL",
"statement",
"with",
"values",
"built",
"in",
"the",
"statement",
"without",
"using",
"placeholders"
] |
31c8d0b9955432cea19730996643bd857481d6a8
|
https://github.com/gramework/gramework/blob/31c8d0b9955432cea19730996643bd857481d6a8/x/sqlgen/insert.go#L23-L27
|
19,668
|
gramework/gramework
|
x/sqlgen/insert.go
|
Columns
|
func (b *InsertBuilder) Columns(columns ...string) *InsertBuilder {
b.lock.Lock()
b.columns = columns
b.query = fmt.Sprintf(`%s(`, b.query)
for i, column := range columns {
b.query = fmt.Sprintf(`%s%s`, b.query, column)
if i < len(columns)-1 {
b.query = fmt.Sprintf(`%s,`, b.query)
}
}
b.query = fmt.Sprintf(`%s)`, b.query)
b.lock.Unlock()
return b
}
|
go
|
func (b *InsertBuilder) Columns(columns ...string) *InsertBuilder {
b.lock.Lock()
b.columns = columns
b.query = fmt.Sprintf(`%s(`, b.query)
for i, column := range columns {
b.query = fmt.Sprintf(`%s%s`, b.query, column)
if i < len(columns)-1 {
b.query = fmt.Sprintf(`%s,`, b.query)
}
}
b.query = fmt.Sprintf(`%s)`, b.query)
b.lock.Unlock()
return b
}
|
[
"func",
"(",
"b",
"*",
"InsertBuilder",
")",
"Columns",
"(",
"columns",
"...",
"string",
")",
"*",
"InsertBuilder",
"{",
"b",
".",
"lock",
".",
"Lock",
"(",
")",
"\n",
"b",
".",
"columns",
"=",
"columns",
"\n",
"b",
".",
"query",
"=",
"fmt",
".",
"Sprintf",
"(",
"`%s(`",
",",
"b",
".",
"query",
")",
"\n",
"for",
"i",
",",
"column",
":=",
"range",
"columns",
"{",
"b",
".",
"query",
"=",
"fmt",
".",
"Sprintf",
"(",
"`%s%s`",
",",
"b",
".",
"query",
",",
"column",
")",
"\n",
"if",
"i",
"<",
"len",
"(",
"columns",
")",
"-",
"1",
"{",
"b",
".",
"query",
"=",
"fmt",
".",
"Sprintf",
"(",
"`%s,`",
",",
"b",
".",
"query",
")",
"\n",
"}",
"\n",
"}",
"\n",
"b",
".",
"query",
"=",
"fmt",
".",
"Sprintf",
"(",
"`%s)`",
",",
"b",
".",
"query",
")",
"\n",
"b",
".",
"lock",
".",
"Unlock",
"(",
")",
"\n",
"return",
"b",
"\n",
"}"
] |
// Columns defines column list
|
[
"Columns",
"defines",
"column",
"list"
] |
31c8d0b9955432cea19730996643bd857481d6a8
|
https://github.com/gramework/gramework/blob/31c8d0b9955432cea19730996643bd857481d6a8/x/sqlgen/insert.go#L30-L43
|
19,669
|
gramework/gramework
|
x/sqlgen/insert.go
|
Values
|
func (b *InsertBuilder) Values(columnValues ...interface{}) *InsertBuilder {
b.lock.Lock()
sqlValue := "("
if b.prepared {
for k, columnValue := range columnValues {
switch v := columnValue.(type) {
case string:
sqlValue = fmt.Sprintf("%s'%s'", sqlValue, strings.Replace(v, "'", "''", -1))
default:
sqlValue = fmt.Sprintf("%s%v", sqlValue, v)
}
if k < len(columnValues)-1 {
sqlValue = fmt.Sprintf("%s, ", sqlValue)
}
}
} else {
for k := range columnValues {
sqlValue = fmt.Sprintf("%s?", sqlValue)
if k < len(columnValues)-1 {
sqlValue = fmt.Sprintf("%s, ", sqlValue)
}
}
}
b.sqlValues = append(b.sqlValues, fmt.Sprintf(`%s)`, sqlValue))
b.lock.Unlock()
return b
}
|
go
|
func (b *InsertBuilder) Values(columnValues ...interface{}) *InsertBuilder {
b.lock.Lock()
sqlValue := "("
if b.prepared {
for k, columnValue := range columnValues {
switch v := columnValue.(type) {
case string:
sqlValue = fmt.Sprintf("%s'%s'", sqlValue, strings.Replace(v, "'", "''", -1))
default:
sqlValue = fmt.Sprintf("%s%v", sqlValue, v)
}
if k < len(columnValues)-1 {
sqlValue = fmt.Sprintf("%s, ", sqlValue)
}
}
} else {
for k := range columnValues {
sqlValue = fmt.Sprintf("%s?", sqlValue)
if k < len(columnValues)-1 {
sqlValue = fmt.Sprintf("%s, ", sqlValue)
}
}
}
b.sqlValues = append(b.sqlValues, fmt.Sprintf(`%s)`, sqlValue))
b.lock.Unlock()
return b
}
|
[
"func",
"(",
"b",
"*",
"InsertBuilder",
")",
"Values",
"(",
"columnValues",
"...",
"interface",
"{",
"}",
")",
"*",
"InsertBuilder",
"{",
"b",
".",
"lock",
".",
"Lock",
"(",
")",
"\n",
"sqlValue",
":=",
"\"",
"\"",
"\n",
"if",
"b",
".",
"prepared",
"{",
"for",
"k",
",",
"columnValue",
":=",
"range",
"columnValues",
"{",
"switch",
"v",
":=",
"columnValue",
".",
"(",
"type",
")",
"{",
"case",
"string",
":",
"sqlValue",
"=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"sqlValue",
",",
"strings",
".",
"Replace",
"(",
"v",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"-",
"1",
")",
")",
"\n",
"default",
":",
"sqlValue",
"=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"sqlValue",
",",
"v",
")",
"\n",
"}",
"\n",
"if",
"k",
"<",
"len",
"(",
"columnValues",
")",
"-",
"1",
"{",
"sqlValue",
"=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"sqlValue",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"else",
"{",
"for",
"k",
":=",
"range",
"columnValues",
"{",
"sqlValue",
"=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"sqlValue",
")",
"\n",
"if",
"k",
"<",
"len",
"(",
"columnValues",
")",
"-",
"1",
"{",
"sqlValue",
"=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"sqlValue",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"b",
".",
"sqlValues",
"=",
"append",
"(",
"b",
".",
"sqlValues",
",",
"fmt",
".",
"Sprintf",
"(",
"`%s)`",
",",
"sqlValue",
")",
")",
"\n\n",
"b",
".",
"lock",
".",
"Unlock",
"(",
")",
"\n\n",
"return",
"b",
"\n",
"}"
] |
// Values appends column values to the query
|
[
"Values",
"appends",
"column",
"values",
"to",
"the",
"query"
] |
31c8d0b9955432cea19730996643bd857481d6a8
|
https://github.com/gramework/gramework/blob/31c8d0b9955432cea19730996643bd857481d6a8/x/sqlgen/insert.go#L46-L74
|
19,670
|
gramework/gramework
|
x/sqlgen/insert.go
|
Build
|
func (b *InsertBuilder) Build() string {
b.lock.Lock()
defer b.lock.Unlock()
return fmt.Sprintf("%s\n VALUES %s;", b.query, strings.Join(b.sqlValues, ", \n "))
}
|
go
|
func (b *InsertBuilder) Build() string {
b.lock.Lock()
defer b.lock.Unlock()
return fmt.Sprintf("%s\n VALUES %s;", b.query, strings.Join(b.sqlValues, ", \n "))
}
|
[
"func",
"(",
"b",
"*",
"InsertBuilder",
")",
"Build",
"(",
")",
"string",
"{",
"b",
".",
"lock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"b",
".",
"lock",
".",
"Unlock",
"(",
")",
"\n",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\\n",
"\"",
",",
"b",
".",
"query",
",",
"strings",
".",
"Join",
"(",
"b",
".",
"sqlValues",
",",
"\"",
"\\n",
"\"",
")",
")",
"\n",
"}"
] |
// Build the query
|
[
"Build",
"the",
"query"
] |
31c8d0b9955432cea19730996643bd857481d6a8
|
https://github.com/gramework/gramework/blob/31c8d0b9955432cea19730996643bd857481d6a8/x/sqlgen/insert.go#L77-L81
|
19,671
|
gramework/gramework
|
graphiql/graphiql.go
|
Handler
|
func Handler(ctx *gramework.Context) {
if _, err := ctx.HTML().WriteString(tpl); err != nil {
ctx.Logger.WithError(err).WithField("package", "mw/graphiql").Error("could not send template")
}
}
|
go
|
func Handler(ctx *gramework.Context) {
if _, err := ctx.HTML().WriteString(tpl); err != nil {
ctx.Logger.WithError(err).WithField("package", "mw/graphiql").Error("could not send template")
}
}
|
[
"func",
"Handler",
"(",
"ctx",
"*",
"gramework",
".",
"Context",
")",
"{",
"if",
"_",
",",
"err",
":=",
"ctx",
".",
"HTML",
"(",
")",
".",
"WriteString",
"(",
"tpl",
")",
";",
"err",
"!=",
"nil",
"{",
"ctx",
".",
"Logger",
".",
"WithError",
"(",
"err",
")",
".",
"WithField",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
".",
"Error",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}"
] |
// Handler serves standalone graphiql HTML.
|
[
"Handler",
"serves",
"standalone",
"graphiql",
"HTML",
"."
] |
31c8d0b9955432cea19730996643bd857481d6a8
|
https://github.com/gramework/gramework/blob/31c8d0b9955432cea19730996643bd857481d6a8/graphiql/graphiql.go#L12-L16
|
19,672
|
gramework/gramework
|
cookie.go
|
GetCookieDomain
|
func (ctx *Context) GetCookieDomain() (domain string, wasConfigured bool) {
return ctx.App.cookieDomain, len(ctx.App.cookieDomain) > 0
}
|
go
|
func (ctx *Context) GetCookieDomain() (domain string, wasConfigured bool) {
return ctx.App.cookieDomain, len(ctx.App.cookieDomain) > 0
}
|
[
"func",
"(",
"ctx",
"*",
"Context",
")",
"GetCookieDomain",
"(",
")",
"(",
"domain",
"string",
",",
"wasConfigured",
"bool",
")",
"{",
"return",
"ctx",
".",
"App",
".",
"cookieDomain",
",",
"len",
"(",
"ctx",
".",
"App",
".",
"cookieDomain",
")",
">",
"0",
"\n",
"}"
] |
// GetCookieDomain returns previously configured cookie domain and if cookie domain
// was configured at all
|
[
"GetCookieDomain",
"returns",
"previously",
"configured",
"cookie",
"domain",
"and",
"if",
"cookie",
"domain",
"was",
"configured",
"at",
"all"
] |
31c8d0b9955432cea19730996643bd857481d6a8
|
https://github.com/gramework/gramework/blob/31c8d0b9955432cea19730996643bd857481d6a8/cookie.go#L23-L25
|
19,673
|
gramework/gramework
|
cookie.go
|
Set
|
func (c *Cookies) Set(key, value string) {
c.Mu.Lock()
if c.Storage == nil {
c.Storage = make(map[string]string, zero)
}
c.Storage[key] = value
c.Mu.Unlock()
}
|
go
|
func (c *Cookies) Set(key, value string) {
c.Mu.Lock()
if c.Storage == nil {
c.Storage = make(map[string]string, zero)
}
c.Storage[key] = value
c.Mu.Unlock()
}
|
[
"func",
"(",
"c",
"*",
"Cookies",
")",
"Set",
"(",
"key",
",",
"value",
"string",
")",
"{",
"c",
".",
"Mu",
".",
"Lock",
"(",
")",
"\n",
"if",
"c",
".",
"Storage",
"==",
"nil",
"{",
"c",
".",
"Storage",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"string",
",",
"zero",
")",
"\n",
"}",
"\n",
"c",
".",
"Storage",
"[",
"key",
"]",
"=",
"value",
"\n",
"c",
".",
"Mu",
".",
"Unlock",
"(",
")",
"\n",
"}"
] |
// Set a cookie with given key to the value
|
[
"Set",
"a",
"cookie",
"with",
"given",
"key",
"to",
"the",
"value"
] |
31c8d0b9955432cea19730996643bd857481d6a8
|
https://github.com/gramework/gramework/blob/31c8d0b9955432cea19730996643bd857481d6a8/cookie.go#L56-L63
|
19,674
|
gramework/gramework
|
cookie.go
|
Get
|
func (c *Cookies) Get(key string) (string, bool) {
c.Mu.Lock()
if c.Storage == nil {
c.Storage = make(map[string]string, zero)
c.Mu.Unlock()
return emptyString, false
}
if v, ok := c.Storage[key]; ok {
c.Mu.Unlock()
return v, ok
}
c.Mu.Unlock()
return emptyString, false
}
|
go
|
func (c *Cookies) Get(key string) (string, bool) {
c.Mu.Lock()
if c.Storage == nil {
c.Storage = make(map[string]string, zero)
c.Mu.Unlock()
return emptyString, false
}
if v, ok := c.Storage[key]; ok {
c.Mu.Unlock()
return v, ok
}
c.Mu.Unlock()
return emptyString, false
}
|
[
"func",
"(",
"c",
"*",
"Cookies",
")",
"Get",
"(",
"key",
"string",
")",
"(",
"string",
",",
"bool",
")",
"{",
"c",
".",
"Mu",
".",
"Lock",
"(",
")",
"\n",
"if",
"c",
".",
"Storage",
"==",
"nil",
"{",
"c",
".",
"Storage",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"string",
",",
"zero",
")",
"\n",
"c",
".",
"Mu",
".",
"Unlock",
"(",
")",
"\n",
"return",
"emptyString",
",",
"false",
"\n",
"}",
"\n",
"if",
"v",
",",
"ok",
":=",
"c",
".",
"Storage",
"[",
"key",
"]",
";",
"ok",
"{",
"c",
".",
"Mu",
".",
"Unlock",
"(",
")",
"\n",
"return",
"v",
",",
"ok",
"\n",
"}",
"\n",
"c",
".",
"Mu",
".",
"Unlock",
"(",
")",
"\n",
"return",
"emptyString",
",",
"false",
"\n",
"}"
] |
// Get a cookie by given key
|
[
"Get",
"a",
"cookie",
"by",
"given",
"key"
] |
31c8d0b9955432cea19730996643bd857481d6a8
|
https://github.com/gramework/gramework/blob/31c8d0b9955432cea19730996643bd857481d6a8/cookie.go#L66-L79
|
19,675
|
gramework/gramework
|
cookie.go
|
Exists
|
func (c *Cookies) Exists(key string) bool {
c.Mu.Lock()
if c.Storage == nil {
c.Storage = make(map[string]string, zero)
c.Mu.Unlock()
return false
}
if _, ok := c.Storage[key]; ok {
c.Mu.Unlock()
return ok
}
c.Mu.Unlock()
return false
}
|
go
|
func (c *Cookies) Exists(key string) bool {
c.Mu.Lock()
if c.Storage == nil {
c.Storage = make(map[string]string, zero)
c.Mu.Unlock()
return false
}
if _, ok := c.Storage[key]; ok {
c.Mu.Unlock()
return ok
}
c.Mu.Unlock()
return false
}
|
[
"func",
"(",
"c",
"*",
"Cookies",
")",
"Exists",
"(",
"key",
"string",
")",
"bool",
"{",
"c",
".",
"Mu",
".",
"Lock",
"(",
")",
"\n",
"if",
"c",
".",
"Storage",
"==",
"nil",
"{",
"c",
".",
"Storage",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"string",
",",
"zero",
")",
"\n",
"c",
".",
"Mu",
".",
"Unlock",
"(",
")",
"\n",
"return",
"false",
"\n",
"}",
"\n",
"if",
"_",
",",
"ok",
":=",
"c",
".",
"Storage",
"[",
"key",
"]",
";",
"ok",
"{",
"c",
".",
"Mu",
".",
"Unlock",
"(",
")",
"\n",
"return",
"ok",
"\n",
"}",
"\n",
"c",
".",
"Mu",
".",
"Unlock",
"(",
")",
"\n",
"return",
"false",
"\n",
"}"
] |
// Exists reports if the given key exists for current request
|
[
"Exists",
"reports",
"if",
"the",
"given",
"key",
"exists",
"for",
"current",
"request"
] |
31c8d0b9955432cea19730996643bd857481d6a8
|
https://github.com/gramework/gramework/blob/31c8d0b9955432cea19730996643bd857481d6a8/cookie.go#L82-L95
|
19,676
|
gramework/gramework
|
subroute.go
|
HTTP
|
func (r *SubRouter) HTTP() *SubRouter {
switch parent := r.parent.(type) {
case *SubRouter:
return parent.HTTP()
case *Router:
return &SubRouter{
parent: parent,
prefix: r.prefix,
}
default:
Errorf("[HIGH SEVERITY BUG]: unreachable case found! Expected *SubRouter or *Router, got %T! Returning nil!", parent)
Errorf("Please report the bug on https://github.com/gramework/gramework ASAP!")
return nil
}
}
|
go
|
func (r *SubRouter) HTTP() *SubRouter {
switch parent := r.parent.(type) {
case *SubRouter:
return parent.HTTP()
case *Router:
return &SubRouter{
parent: parent,
prefix: r.prefix,
}
default:
Errorf("[HIGH SEVERITY BUG]: unreachable case found! Expected *SubRouter or *Router, got %T! Returning nil!", parent)
Errorf("Please report the bug on https://github.com/gramework/gramework ASAP!")
return nil
}
}
|
[
"func",
"(",
"r",
"*",
"SubRouter",
")",
"HTTP",
"(",
")",
"*",
"SubRouter",
"{",
"switch",
"parent",
":=",
"r",
".",
"parent",
".",
"(",
"type",
")",
"{",
"case",
"*",
"SubRouter",
":",
"return",
"parent",
".",
"HTTP",
"(",
")",
"\n",
"case",
"*",
"Router",
":",
"return",
"&",
"SubRouter",
"{",
"parent",
":",
"parent",
",",
"prefix",
":",
"r",
".",
"prefix",
",",
"}",
"\n",
"default",
":",
"Errorf",
"(",
"\"",
"\"",
",",
"parent",
")",
"\n",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] |
// HTTP returns SubRouter for http requests with given r.prefix
|
[
"HTTP",
"returns",
"SubRouter",
"for",
"http",
"requests",
"with",
"given",
"r",
".",
"prefix"
] |
31c8d0b9955432cea19730996643bd857481d6a8
|
https://github.com/gramework/gramework/blob/31c8d0b9955432cea19730996643bd857481d6a8/subroute.go#L148-L162
|
19,677
|
gramework/gramework
|
subroute.go
|
HTTPS
|
func (r *SubRouter) HTTPS() *SubRouter {
switch parent := r.parent.(type) {
case *SubRouter:
return parent.HTTPS()
case *Router:
return &SubRouter{
parent: parent,
prefix: r.prefix,
}
default:
Errorf("[HIGH SEVERITY BUG]: unreachable case found! Expected *SubRouter or *Router, got %T! Returning nil!", parent)
Errorf("Please report the bug on https://github.com/gramework/gramework ASAP!")
return nil
}
}
|
go
|
func (r *SubRouter) HTTPS() *SubRouter {
switch parent := r.parent.(type) {
case *SubRouter:
return parent.HTTPS()
case *Router:
return &SubRouter{
parent: parent,
prefix: r.prefix,
}
default:
Errorf("[HIGH SEVERITY BUG]: unreachable case found! Expected *SubRouter or *Router, got %T! Returning nil!", parent)
Errorf("Please report the bug on https://github.com/gramework/gramework ASAP!")
return nil
}
}
|
[
"func",
"(",
"r",
"*",
"SubRouter",
")",
"HTTPS",
"(",
")",
"*",
"SubRouter",
"{",
"switch",
"parent",
":=",
"r",
".",
"parent",
".",
"(",
"type",
")",
"{",
"case",
"*",
"SubRouter",
":",
"return",
"parent",
".",
"HTTPS",
"(",
")",
"\n",
"case",
"*",
"Router",
":",
"return",
"&",
"SubRouter",
"{",
"parent",
":",
"parent",
",",
"prefix",
":",
"r",
".",
"prefix",
",",
"}",
"\n",
"default",
":",
"Errorf",
"(",
"\"",
"\"",
",",
"parent",
")",
"\n",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] |
// HTTPS returns SubRouter for https requests with given r.prefix
|
[
"HTTPS",
"returns",
"SubRouter",
"for",
"https",
"requests",
"with",
"given",
"r",
".",
"prefix"
] |
31c8d0b9955432cea19730996643bd857481d6a8
|
https://github.com/gramework/gramework/blob/31c8d0b9955432cea19730996643bd857481d6a8/subroute.go#L165-L179
|
19,678
|
gramework/gramework
|
context_gql.go
|
DecodeGQL
|
func (ctx *Context) DecodeGQL() (*GQLRequest, error) {
r := &GQLRequest{}
if string(ctx.Method()) == GET {
query := ctx.GETParam("query")
if len(query) == 0 {
return nil, ErrInvalidGQLRequest
}
r.Query = query[0]
if operationName := ctx.GETParam("operationName"); len(operationName) != 0 {
r.OperationName = operationName[0]
}
if variables := ctx.GETParam("variables"); len(variables) != 0 {
if _, err := ctx.UnJSONBytes([]byte(variables[0]), &r.Variables); err != nil {
return nil, ErrInvalidGQLRequest
}
}
return r, nil
}
ctSplitParams := strings.Split(ctx.ContentType(), delimiterCTParams)
switch ctSplitParams[0] {
case jsonCTshort:
if err := ctx.UnJSON(&r); err != nil {
return nil, err
}
case gqlCT:
r.Query = string(ctx.PostBody())
}
return r, nil
}
|
go
|
func (ctx *Context) DecodeGQL() (*GQLRequest, error) {
r := &GQLRequest{}
if string(ctx.Method()) == GET {
query := ctx.GETParam("query")
if len(query) == 0 {
return nil, ErrInvalidGQLRequest
}
r.Query = query[0]
if operationName := ctx.GETParam("operationName"); len(operationName) != 0 {
r.OperationName = operationName[0]
}
if variables := ctx.GETParam("variables"); len(variables) != 0 {
if _, err := ctx.UnJSONBytes([]byte(variables[0]), &r.Variables); err != nil {
return nil, ErrInvalidGQLRequest
}
}
return r, nil
}
ctSplitParams := strings.Split(ctx.ContentType(), delimiterCTParams)
switch ctSplitParams[0] {
case jsonCTshort:
if err := ctx.UnJSON(&r); err != nil {
return nil, err
}
case gqlCT:
r.Query = string(ctx.PostBody())
}
return r, nil
}
|
[
"func",
"(",
"ctx",
"*",
"Context",
")",
"DecodeGQL",
"(",
")",
"(",
"*",
"GQLRequest",
",",
"error",
")",
"{",
"r",
":=",
"&",
"GQLRequest",
"{",
"}",
"\n\n",
"if",
"string",
"(",
"ctx",
".",
"Method",
"(",
")",
")",
"==",
"GET",
"{",
"query",
":=",
"ctx",
".",
"GETParam",
"(",
"\"",
"\"",
")",
"\n",
"if",
"len",
"(",
"query",
")",
"==",
"0",
"{",
"return",
"nil",
",",
"ErrInvalidGQLRequest",
"\n",
"}",
"\n",
"r",
".",
"Query",
"=",
"query",
"[",
"0",
"]",
"\n\n",
"if",
"operationName",
":=",
"ctx",
".",
"GETParam",
"(",
"\"",
"\"",
")",
";",
"len",
"(",
"operationName",
")",
"!=",
"0",
"{",
"r",
".",
"OperationName",
"=",
"operationName",
"[",
"0",
"]",
"\n",
"}",
"\n\n",
"if",
"variables",
":=",
"ctx",
".",
"GETParam",
"(",
"\"",
"\"",
")",
";",
"len",
"(",
"variables",
")",
"!=",
"0",
"{",
"if",
"_",
",",
"err",
":=",
"ctx",
".",
"UnJSONBytes",
"(",
"[",
"]",
"byte",
"(",
"variables",
"[",
"0",
"]",
")",
",",
"&",
"r",
".",
"Variables",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"ErrInvalidGQLRequest",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"r",
",",
"nil",
"\n",
"}",
"\n\n",
"ctSplitParams",
":=",
"strings",
".",
"Split",
"(",
"ctx",
".",
"ContentType",
"(",
")",
",",
"delimiterCTParams",
")",
"\n\n",
"switch",
"ctSplitParams",
"[",
"0",
"]",
"{",
"case",
"jsonCTshort",
":",
"if",
"err",
":=",
"ctx",
".",
"UnJSON",
"(",
"&",
"r",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"case",
"gqlCT",
":",
"r",
".",
"Query",
"=",
"string",
"(",
"ctx",
".",
"PostBody",
"(",
")",
")",
"\n",
"}",
"\n\n",
"return",
"r",
",",
"nil",
"\n",
"}"
] |
// DecodeGQL parses GraphQL request and returns data from it
|
[
"DecodeGQL",
"parses",
"GraphQL",
"request",
"and",
"returns",
"data",
"from",
"it"
] |
31c8d0b9955432cea19730996643bd857481d6a8
|
https://github.com/gramework/gramework/blob/31c8d0b9955432cea19730996643bd857481d6a8/context_gql.go#L8-L43
|
19,679
|
gramework/gramework
|
firewall.go
|
NewRequest
|
func (fw *firewall) NewRequest(ctx *Context) (shouldBeBlocked bool, remoteAddr string) {
if ctx == nil || ctx.RemoteAddr().String() == "0.0.0.0" {
return false, ""
}
// Get the remote addresse of the request
remoteAddr = ctx.RemoteIP().String()
// Check if this remote address is blocked
if fw.isBlocked(remoteAddr) {
return true, remoteAddr
}
// Register the new request in a new goroutine
go fw.addRequest(remoteAddr)
return false, remoteAddr
}
|
go
|
func (fw *firewall) NewRequest(ctx *Context) (shouldBeBlocked bool, remoteAddr string) {
if ctx == nil || ctx.RemoteAddr().String() == "0.0.0.0" {
return false, ""
}
// Get the remote addresse of the request
remoteAddr = ctx.RemoteIP().String()
// Check if this remote address is blocked
if fw.isBlocked(remoteAddr) {
return true, remoteAddr
}
// Register the new request in a new goroutine
go fw.addRequest(remoteAddr)
return false, remoteAddr
}
|
[
"func",
"(",
"fw",
"*",
"firewall",
")",
"NewRequest",
"(",
"ctx",
"*",
"Context",
")",
"(",
"shouldBeBlocked",
"bool",
",",
"remoteAddr",
"string",
")",
"{",
"if",
"ctx",
"==",
"nil",
"||",
"ctx",
".",
"RemoteAddr",
"(",
")",
".",
"String",
"(",
")",
"==",
"\"",
"\"",
"{",
"return",
"false",
",",
"\"",
"\"",
"\n",
"}",
"\n",
"// Get the remote addresse of the request",
"remoteAddr",
"=",
"ctx",
".",
"RemoteIP",
"(",
")",
".",
"String",
"(",
")",
"\n\n",
"// Check if this remote address is blocked",
"if",
"fw",
".",
"isBlocked",
"(",
"remoteAddr",
")",
"{",
"return",
"true",
",",
"remoteAddr",
"\n",
"}",
"\n\n",
"// Register the new request in a new goroutine",
"go",
"fw",
".",
"addRequest",
"(",
"remoteAddr",
")",
"\n\n",
"return",
"false",
",",
"remoteAddr",
"\n",
"}"
] |
// NewRequest tells the firewall, that a new request happened.
// True is returned, if this request should be blocked,
// because the IP is on the block list.
// The remote address is always returned for logging purpose.
|
[
"NewRequest",
"tells",
"the",
"firewall",
"that",
"a",
"new",
"request",
"happened",
".",
"True",
"is",
"returned",
"if",
"this",
"request",
"should",
"be",
"blocked",
"because",
"the",
"IP",
"is",
"on",
"the",
"block",
"list",
".",
"The",
"remote",
"address",
"is",
"always",
"returned",
"for",
"logging",
"purpose",
"."
] |
31c8d0b9955432cea19730996643bd857481d6a8
|
https://github.com/gramework/gramework/blob/31c8d0b9955432cea19730996643bd857481d6a8/firewall.go#L27-L43
|
19,680
|
gramework/gramework
|
firewall.go
|
isBlocked
|
func (fw *firewall) isBlocked(remoteAddr string) bool {
fw.blockListMutex.Lock()
// Check if the remote address exists in the blocked map
_, exists := fw.blockList[remoteAddr]
fw.blockListMutex.Unlock()
return exists
}
|
go
|
func (fw *firewall) isBlocked(remoteAddr string) bool {
fw.blockListMutex.Lock()
// Check if the remote address exists in the blocked map
_, exists := fw.blockList[remoteAddr]
fw.blockListMutex.Unlock()
return exists
}
|
[
"func",
"(",
"fw",
"*",
"firewall",
")",
"isBlocked",
"(",
"remoteAddr",
"string",
")",
"bool",
"{",
"fw",
".",
"blockListMutex",
".",
"Lock",
"(",
")",
"\n\n",
"// Check if the remote address exists in the blocked map",
"_",
",",
"exists",
":=",
"fw",
".",
"blockList",
"[",
"remoteAddr",
"]",
"\n\n",
"fw",
".",
"blockListMutex",
".",
"Unlock",
"(",
")",
"\n",
"return",
"exists",
"\n",
"}"
] |
// isBlocked checks if the remote address is blocked
|
[
"isBlocked",
"checks",
"if",
"the",
"remote",
"address",
"is",
"blocked"
] |
31c8d0b9955432cea19730996643bd857481d6a8
|
https://github.com/gramework/gramework/blob/31c8d0b9955432cea19730996643bd857481d6a8/firewall.go#L46-L54
|
19,681
|
gramework/gramework
|
mw/xhostname/xhostname.go
|
Setup
|
func Setup(app *gramework.App) {
err := app.UseAfterRequest(serveXHost)
if err != nil {
app.Logger.WithError(err).WithField("package", "mw/xhostname").Error("could not register middleware")
}
}
|
go
|
func Setup(app *gramework.App) {
err := app.UseAfterRequest(serveXHost)
if err != nil {
app.Logger.WithError(err).WithField("package", "mw/xhostname").Error("could not register middleware")
}
}
|
[
"func",
"Setup",
"(",
"app",
"*",
"gramework",
".",
"App",
")",
"{",
"err",
":=",
"app",
".",
"UseAfterRequest",
"(",
"serveXHost",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"app",
".",
"Logger",
".",
"WithError",
"(",
"err",
")",
".",
"WithField",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
".",
"Error",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}"
] |
// Setup registers middleware in the provided app
|
[
"Setup",
"registers",
"middleware",
"in",
"the",
"provided",
"app"
] |
31c8d0b9955432cea19730996643bd857481d6a8
|
https://github.com/gramework/gramework/blob/31c8d0b9955432cea19730996643bd857481d6a8/mw/xhostname/xhostname.go#L41-L46
|
19,682
|
gramework/gramework
|
grypto/internal/mcf/mcf.go
|
Encode
|
func Encode(providerName []byte, params string, salt []byte, key []byte) (res []byte) {
salt64 := encodeBase64(salt)
key64 := encodeBase64(key)
// final res len = len(providerName) + len(params) + len(salt) + len(key) + 4, because we need 4 dividers
res = append(res, Divider)
res = append(res, providerName...)
res = append(res, Divider)
res = append(res, params...)
res = append(res, Divider)
res = append(res, salt64...)
res = append(res, Divider)
res = append(res, key64...)
return res
}
|
go
|
func Encode(providerName []byte, params string, salt []byte, key []byte) (res []byte) {
salt64 := encodeBase64(salt)
key64 := encodeBase64(key)
// final res len = len(providerName) + len(params) + len(salt) + len(key) + 4, because we need 4 dividers
res = append(res, Divider)
res = append(res, providerName...)
res = append(res, Divider)
res = append(res, params...)
res = append(res, Divider)
res = append(res, salt64...)
res = append(res, Divider)
res = append(res, key64...)
return res
}
|
[
"func",
"Encode",
"(",
"providerName",
"[",
"]",
"byte",
",",
"params",
"string",
",",
"salt",
"[",
"]",
"byte",
",",
"key",
"[",
"]",
"byte",
")",
"(",
"res",
"[",
"]",
"byte",
")",
"{",
"salt64",
":=",
"encodeBase64",
"(",
"salt",
")",
"\n",
"key64",
":=",
"encodeBase64",
"(",
"key",
")",
"\n",
"// final res len = len(providerName) + len(params) + len(salt) + len(key) + 4, because we need 4 dividers",
"res",
"=",
"append",
"(",
"res",
",",
"Divider",
")",
"\n",
"res",
"=",
"append",
"(",
"res",
",",
"providerName",
"...",
")",
"\n",
"res",
"=",
"append",
"(",
"res",
",",
"Divider",
")",
"\n",
"res",
"=",
"append",
"(",
"res",
",",
"params",
"...",
")",
"\n",
"res",
"=",
"append",
"(",
"res",
",",
"Divider",
")",
"\n",
"res",
"=",
"append",
"(",
"res",
",",
"salt64",
"...",
")",
"\n",
"res",
"=",
"append",
"(",
"res",
",",
"Divider",
")",
"\n",
"res",
"=",
"append",
"(",
"res",
",",
"key64",
"...",
")",
"\n",
"return",
"res",
"\n",
"}"
] |
// Encode encodes given providerName, params, salt and key into Modular Crypt Format.
|
[
"Encode",
"encodes",
"given",
"providerName",
"params",
"salt",
"and",
"key",
"into",
"Modular",
"Crypt",
"Format",
"."
] |
31c8d0b9955432cea19730996643bd857481d6a8
|
https://github.com/gramework/gramework/blob/31c8d0b9955432cea19730996643bd857481d6a8/grypto/internal/mcf/mcf.go#L19-L32
|
19,683
|
gramework/gramework
|
grypto/internal/mcf/mcf.go
|
encodeBase64
|
func encodeBase64(in []byte) (out []byte) {
enc := base64.StdEncoding
out = make([]byte, enc.EncodedLen(len(in)))
enc.Encode(out, in)
return out
}
|
go
|
func encodeBase64(in []byte) (out []byte) {
enc := base64.StdEncoding
out = make([]byte, enc.EncodedLen(len(in)))
enc.Encode(out, in)
return out
}
|
[
"func",
"encodeBase64",
"(",
"in",
"[",
"]",
"byte",
")",
"(",
"out",
"[",
"]",
"byte",
")",
"{",
"enc",
":=",
"base64",
".",
"StdEncoding",
"\n",
"out",
"=",
"make",
"(",
"[",
"]",
"byte",
",",
"enc",
".",
"EncodedLen",
"(",
"len",
"(",
"in",
")",
")",
")",
"\n",
"enc",
".",
"Encode",
"(",
"out",
",",
"in",
")",
"\n",
"return",
"out",
"\n",
"}"
] |
// encodeBase64 encodes the input bytes into standard base64.
|
[
"encodeBase64",
"encodes",
"the",
"input",
"bytes",
"into",
"standard",
"base64",
"."
] |
31c8d0b9955432cea19730996643bd857481d6a8
|
https://github.com/gramework/gramework/blob/31c8d0b9955432cea19730996643bd857481d6a8/grypto/internal/mcf/mcf.go#L35-L40
|
19,684
|
gramework/gramework
|
grypto/internal/mcf/mcf.go
|
Decode
|
func Decode(mcf []byte, expectedPWType []byte) (providerName []byte, params string, salt []byte, key []byte, err error) {
if len(mcf) <= 1 || mcf[0] != Divider {
err = ErrorInvalidDecodeInput
return
}
parts := bytes.Split(mcf[1:], splitDivider)
if len(parts) != 4 {
err = ErrorInvalidDecodeInput
return
}
if subtle.ConstantTimeCompare(parts[0], expectedPWType) == 0 {
err = ErrorInvalidDecodeInput
return
}
params = string(parts[1])
saltDecoded, err := decodeBase64(parts[2])
if err != nil {
err = ErrorInvalidDecodeInput
return
}
salt = saltDecoded
keyDecoded, err := decodeBase64(parts[3])
if err != nil {
err = ErrorInvalidDecodeInput
return
}
key = keyDecoded
return
}
|
go
|
func Decode(mcf []byte, expectedPWType []byte) (providerName []byte, params string, salt []byte, key []byte, err error) {
if len(mcf) <= 1 || mcf[0] != Divider {
err = ErrorInvalidDecodeInput
return
}
parts := bytes.Split(mcf[1:], splitDivider)
if len(parts) != 4 {
err = ErrorInvalidDecodeInput
return
}
if subtle.ConstantTimeCompare(parts[0], expectedPWType) == 0 {
err = ErrorInvalidDecodeInput
return
}
params = string(parts[1])
saltDecoded, err := decodeBase64(parts[2])
if err != nil {
err = ErrorInvalidDecodeInput
return
}
salt = saltDecoded
keyDecoded, err := decodeBase64(parts[3])
if err != nil {
err = ErrorInvalidDecodeInput
return
}
key = keyDecoded
return
}
|
[
"func",
"Decode",
"(",
"mcf",
"[",
"]",
"byte",
",",
"expectedPWType",
"[",
"]",
"byte",
")",
"(",
"providerName",
"[",
"]",
"byte",
",",
"params",
"string",
",",
"salt",
"[",
"]",
"byte",
",",
"key",
"[",
"]",
"byte",
",",
"err",
"error",
")",
"{",
"if",
"len",
"(",
"mcf",
")",
"<=",
"1",
"||",
"mcf",
"[",
"0",
"]",
"!=",
"Divider",
"{",
"err",
"=",
"ErrorInvalidDecodeInput",
"\n",
"return",
"\n",
"}",
"\n\n",
"parts",
":=",
"bytes",
".",
"Split",
"(",
"mcf",
"[",
"1",
":",
"]",
",",
"splitDivider",
")",
"\n\n",
"if",
"len",
"(",
"parts",
")",
"!=",
"4",
"{",
"err",
"=",
"ErrorInvalidDecodeInput",
"\n",
"return",
"\n",
"}",
"\n\n",
"if",
"subtle",
".",
"ConstantTimeCompare",
"(",
"parts",
"[",
"0",
"]",
",",
"expectedPWType",
")",
"==",
"0",
"{",
"err",
"=",
"ErrorInvalidDecodeInput",
"\n",
"return",
"\n",
"}",
"\n\n",
"params",
"=",
"string",
"(",
"parts",
"[",
"1",
"]",
")",
"\n\n",
"saltDecoded",
",",
"err",
":=",
"decodeBase64",
"(",
"parts",
"[",
"2",
"]",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"err",
"=",
"ErrorInvalidDecodeInput",
"\n",
"return",
"\n",
"}",
"\n\n",
"salt",
"=",
"saltDecoded",
"\n\n",
"keyDecoded",
",",
"err",
":=",
"decodeBase64",
"(",
"parts",
"[",
"3",
"]",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"err",
"=",
"ErrorInvalidDecodeInput",
"\n",
"return",
"\n",
"}",
"\n",
"key",
"=",
"keyDecoded",
"\n",
"return",
"\n",
"}"
] |
// Decode given MCF if it contains information about expected pw type
|
[
"Decode",
"given",
"MCF",
"if",
"it",
"contains",
"information",
"about",
"expected",
"pw",
"type"
] |
31c8d0b9955432cea19730996643bd857481d6a8
|
https://github.com/gramework/gramework/blob/31c8d0b9955432cea19730996643bd857481d6a8/grypto/internal/mcf/mcf.go#L50-L85
|
19,685
|
gramework/gramework
|
x/client/get.go
|
GET
|
func (client *Instance) GET() (statusCode int, body []byte, err error) {
api, err := client.nextServer()
if err != nil {
return 0, nil, err
}
return api.HostClient.Get(nil, api.Addr)
}
|
go
|
func (client *Instance) GET() (statusCode int, body []byte, err error) {
api, err := client.nextServer()
if err != nil {
return 0, nil, err
}
return api.HostClient.Get(nil, api.Addr)
}
|
[
"func",
"(",
"client",
"*",
"Instance",
")",
"GET",
"(",
")",
"(",
"statusCode",
"int",
",",
"body",
"[",
"]",
"byte",
",",
"err",
"error",
")",
"{",
"api",
",",
"err",
":=",
"client",
".",
"nextServer",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"api",
".",
"HostClient",
".",
"Get",
"(",
"nil",
",",
"api",
".",
"Addr",
")",
"\n",
"}"
] |
// GET sends a request with GET method
|
[
"GET",
"sends",
"a",
"request",
"with",
"GET",
"method"
] |
31c8d0b9955432cea19730996643bd857481d6a8
|
https://github.com/gramework/gramework/blob/31c8d0b9955432cea19730996643bd857481d6a8/x/client/get.go#L19-L26
|
19,686
|
gramework/gramework
|
x/client/get.go
|
GetJSON
|
func (client *Instance) GetJSON(v interface{}) (statusCode int, err error) {
statusCode, body, err := client.GET()
if err != nil {
return 0, err
}
return statusCode, json.NewDecoder(bytes.NewReader(body)).Decode(&v)
}
|
go
|
func (client *Instance) GetJSON(v interface{}) (statusCode int, err error) {
statusCode, body, err := client.GET()
if err != nil {
return 0, err
}
return statusCode, json.NewDecoder(bytes.NewReader(body)).Decode(&v)
}
|
[
"func",
"(",
"client",
"*",
"Instance",
")",
"GetJSON",
"(",
"v",
"interface",
"{",
"}",
")",
"(",
"statusCode",
"int",
",",
"err",
"error",
")",
"{",
"statusCode",
",",
"body",
",",
"err",
":=",
"client",
".",
"GET",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"statusCode",
",",
"json",
".",
"NewDecoder",
"(",
"bytes",
".",
"NewReader",
"(",
"body",
")",
")",
".",
"Decode",
"(",
"&",
"v",
")",
"\n",
"}"
] |
// GetJSON sends a GET request and deserializes response in a provided variable
|
[
"GetJSON",
"sends",
"a",
"GET",
"request",
"and",
"deserializes",
"response",
"in",
"a",
"provided",
"variable"
] |
31c8d0b9955432cea19730996643bd857481d6a8
|
https://github.com/gramework/gramework/blob/31c8d0b9955432cea19730996643bd857481d6a8/x/client/get.go#L29-L36
|
19,687
|
natefinch/pie
|
pie.go
|
NewProvider
|
func NewProvider() Server {
return Server{
server: rpc.NewServer(),
rwc: rwCloser{os.Stdin, os.Stdout},
}
}
|
go
|
func NewProvider() Server {
return Server{
server: rpc.NewServer(),
rwc: rwCloser{os.Stdin, os.Stdout},
}
}
|
[
"func",
"NewProvider",
"(",
")",
"Server",
"{",
"return",
"Server",
"{",
"server",
":",
"rpc",
".",
"NewServer",
"(",
")",
",",
"rwc",
":",
"rwCloser",
"{",
"os",
".",
"Stdin",
",",
"os",
".",
"Stdout",
"}",
",",
"}",
"\n",
"}"
] |
// NewProvider returns a Server that will serve RPC over this
// application's Stdin and Stdout. This method is intended to be run by the
// plugin application.
|
[
"NewProvider",
"returns",
"a",
"Server",
"that",
"will",
"serve",
"RPC",
"over",
"this",
"application",
"s",
"Stdin",
"and",
"Stdout",
".",
"This",
"method",
"is",
"intended",
"to",
"be",
"run",
"by",
"the",
"plugin",
"application",
"."
] |
9a0d7201400759b777f38c0c2d7b0be4e3e8b5c9
|
https://github.com/natefinch/pie/blob/9a0d7201400759b777f38c0c2d7b0be4e3e8b5c9/pie.go#L18-L23
|
19,688
|
natefinch/pie
|
pie.go
|
Close
|
func (s Server) Close() error {
if s.codec != nil {
return s.codec.Close()
}
return s.rwc.Close()
}
|
go
|
func (s Server) Close() error {
if s.codec != nil {
return s.codec.Close()
}
return s.rwc.Close()
}
|
[
"func",
"(",
"s",
"Server",
")",
"Close",
"(",
")",
"error",
"{",
"if",
"s",
".",
"codec",
"!=",
"nil",
"{",
"return",
"s",
".",
"codec",
".",
"Close",
"(",
")",
"\n",
"}",
"\n",
"return",
"s",
".",
"rwc",
".",
"Close",
"(",
")",
"\n",
"}"
] |
// Close closes the connection with the client. If the client is a plugin
// process, the process will be stopped. Further communication using this
// Server will fail.
|
[
"Close",
"closes",
"the",
"connection",
"with",
"the",
"client",
".",
"If",
"the",
"client",
"is",
"a",
"plugin",
"process",
"the",
"process",
"will",
"be",
"stopped",
".",
"Further",
"communication",
"using",
"this",
"Server",
"will",
"fail",
"."
] |
9a0d7201400759b777f38c0c2d7b0be4e3e8b5c9
|
https://github.com/natefinch/pie/blob/9a0d7201400759b777f38c0c2d7b0be4e3e8b5c9/pie.go#L36-L41
|
19,689
|
natefinch/pie
|
pie.go
|
ServeCodec
|
func (s Server) ServeCodec(f func(io.ReadWriteCloser) rpc.ServerCodec) {
s.server.ServeCodec(f(s.rwc))
}
|
go
|
func (s Server) ServeCodec(f func(io.ReadWriteCloser) rpc.ServerCodec) {
s.server.ServeCodec(f(s.rwc))
}
|
[
"func",
"(",
"s",
"Server",
")",
"ServeCodec",
"(",
"f",
"func",
"(",
"io",
".",
"ReadWriteCloser",
")",
"rpc",
".",
"ServerCodec",
")",
"{",
"s",
".",
"server",
".",
"ServeCodec",
"(",
"f",
"(",
"s",
".",
"rwc",
")",
")",
"\n",
"}"
] |
// ServeCodec starts the Server's RPC server, serving via the encoding returned
// by f. This call will block until the client hangs up.
|
[
"ServeCodec",
"starts",
"the",
"Server",
"s",
"RPC",
"server",
"serving",
"via",
"the",
"encoding",
"returned",
"by",
"f",
".",
"This",
"call",
"will",
"block",
"until",
"the",
"client",
"hangs",
"up",
"."
] |
9a0d7201400759b777f38c0c2d7b0be4e3e8b5c9
|
https://github.com/natefinch/pie/blob/9a0d7201400759b777f38c0c2d7b0be4e3e8b5c9/pie.go#L51-L53
|
19,690
|
natefinch/pie
|
pie.go
|
StartProvider
|
func StartProvider(output io.Writer, path string, args ...string) (*rpc.Client, error) {
pipe, err := start(makeCommand(output, path, args))
if err != nil {
return nil, err
}
return rpc.NewClient(pipe), nil
}
|
go
|
func StartProvider(output io.Writer, path string, args ...string) (*rpc.Client, error) {
pipe, err := start(makeCommand(output, path, args))
if err != nil {
return nil, err
}
return rpc.NewClient(pipe), nil
}
|
[
"func",
"StartProvider",
"(",
"output",
"io",
".",
"Writer",
",",
"path",
"string",
",",
"args",
"...",
"string",
")",
"(",
"*",
"rpc",
".",
"Client",
",",
"error",
")",
"{",
"pipe",
",",
"err",
":=",
"start",
"(",
"makeCommand",
"(",
"output",
",",
"path",
",",
"args",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"rpc",
".",
"NewClient",
"(",
"pipe",
")",
",",
"nil",
"\n",
"}"
] |
// StartProvider start a provider-style plugin application at the given path and
// args, and returns an RPC client that communicates with the plugin using gob
// encoding over the plugin's Stdin and Stdout. The writer passed to output
// will receive output from the plugin's stderr. Closing the RPC client
// returned from this function will shut down the plugin application.
|
[
"StartProvider",
"start",
"a",
"provider",
"-",
"style",
"plugin",
"application",
"at",
"the",
"given",
"path",
"and",
"args",
"and",
"returns",
"an",
"RPC",
"client",
"that",
"communicates",
"with",
"the",
"plugin",
"using",
"gob",
"encoding",
"over",
"the",
"plugin",
"s",
"Stdin",
"and",
"Stdout",
".",
"The",
"writer",
"passed",
"to",
"output",
"will",
"receive",
"output",
"from",
"the",
"plugin",
"s",
"stderr",
".",
"Closing",
"the",
"RPC",
"client",
"returned",
"from",
"this",
"function",
"will",
"shut",
"down",
"the",
"plugin",
"application",
"."
] |
9a0d7201400759b777f38c0c2d7b0be4e3e8b5c9
|
https://github.com/natefinch/pie/blob/9a0d7201400759b777f38c0c2d7b0be4e3e8b5c9/pie.go#L82-L88
|
19,691
|
natefinch/pie
|
pie.go
|
StartProviderCodec
|
func StartProviderCodec(
f func(io.ReadWriteCloser) rpc.ClientCodec,
output io.Writer,
path string,
args ...string,
) (*rpc.Client, error) {
pipe, err := start(makeCommand(output, path, args))
if err != nil {
return nil, err
}
return rpc.NewClientWithCodec(f(pipe)), nil
}
|
go
|
func StartProviderCodec(
f func(io.ReadWriteCloser) rpc.ClientCodec,
output io.Writer,
path string,
args ...string,
) (*rpc.Client, error) {
pipe, err := start(makeCommand(output, path, args))
if err != nil {
return nil, err
}
return rpc.NewClientWithCodec(f(pipe)), nil
}
|
[
"func",
"StartProviderCodec",
"(",
"f",
"func",
"(",
"io",
".",
"ReadWriteCloser",
")",
"rpc",
".",
"ClientCodec",
",",
"output",
"io",
".",
"Writer",
",",
"path",
"string",
",",
"args",
"...",
"string",
",",
")",
"(",
"*",
"rpc",
".",
"Client",
",",
"error",
")",
"{",
"pipe",
",",
"err",
":=",
"start",
"(",
"makeCommand",
"(",
"output",
",",
"path",
",",
"args",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"rpc",
".",
"NewClientWithCodec",
"(",
"f",
"(",
"pipe",
")",
")",
",",
"nil",
"\n",
"}"
] |
// StartProviderCodec starts a provider-style plugin application at the given
// path and args, and returns an RPC client that communicates with the plugin
// using the ClientCodec returned by f over the plugin's Stdin and Stdout. The
// writer passed to output will receive output from the plugin's stderr.
// Closing the RPC client returned from this function will shut down the plugin
// application.
|
[
"StartProviderCodec",
"starts",
"a",
"provider",
"-",
"style",
"plugin",
"application",
"at",
"the",
"given",
"path",
"and",
"args",
"and",
"returns",
"an",
"RPC",
"client",
"that",
"communicates",
"with",
"the",
"plugin",
"using",
"the",
"ClientCodec",
"returned",
"by",
"f",
"over",
"the",
"plugin",
"s",
"Stdin",
"and",
"Stdout",
".",
"The",
"writer",
"passed",
"to",
"output",
"will",
"receive",
"output",
"from",
"the",
"plugin",
"s",
"stderr",
".",
"Closing",
"the",
"RPC",
"client",
"returned",
"from",
"this",
"function",
"will",
"shut",
"down",
"the",
"plugin",
"application",
"."
] |
9a0d7201400759b777f38c0c2d7b0be4e3e8b5c9
|
https://github.com/natefinch/pie/blob/9a0d7201400759b777f38c0c2d7b0be4e3e8b5c9/pie.go#L96-L107
|
19,692
|
natefinch/pie
|
pie.go
|
StartConsumer
|
func StartConsumer(output io.Writer, path string, args ...string) (Server, error) {
pipe, err := start(makeCommand(output, path, args))
if err != nil {
return Server{}, err
}
return Server{
server: rpc.NewServer(),
rwc: pipe,
}, nil
}
|
go
|
func StartConsumer(output io.Writer, path string, args ...string) (Server, error) {
pipe, err := start(makeCommand(output, path, args))
if err != nil {
return Server{}, err
}
return Server{
server: rpc.NewServer(),
rwc: pipe,
}, nil
}
|
[
"func",
"StartConsumer",
"(",
"output",
"io",
".",
"Writer",
",",
"path",
"string",
",",
"args",
"...",
"string",
")",
"(",
"Server",
",",
"error",
")",
"{",
"pipe",
",",
"err",
":=",
"start",
"(",
"makeCommand",
"(",
"output",
",",
"path",
",",
"args",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"Server",
"{",
"}",
",",
"err",
"\n",
"}",
"\n",
"return",
"Server",
"{",
"server",
":",
"rpc",
".",
"NewServer",
"(",
")",
",",
"rwc",
":",
"pipe",
",",
"}",
",",
"nil",
"\n",
"}"
] |
// StartConsumer starts a consumer-style plugin application with the given path
// and args, writing its stderr to output. The plugin consumes an API this
// application provides. The function returns the Server for this host
// application, which should be used to register APIs for the plugin to consume.
|
[
"StartConsumer",
"starts",
"a",
"consumer",
"-",
"style",
"plugin",
"application",
"with",
"the",
"given",
"path",
"and",
"args",
"writing",
"its",
"stderr",
"to",
"output",
".",
"The",
"plugin",
"consumes",
"an",
"API",
"this",
"application",
"provides",
".",
"The",
"function",
"returns",
"the",
"Server",
"for",
"this",
"host",
"application",
"which",
"should",
"be",
"used",
"to",
"register",
"APIs",
"for",
"the",
"plugin",
"to",
"consume",
"."
] |
9a0d7201400759b777f38c0c2d7b0be4e3e8b5c9
|
https://github.com/natefinch/pie/blob/9a0d7201400759b777f38c0c2d7b0be4e3e8b5c9/pie.go#L113-L122
|
19,693
|
natefinch/pie
|
pie.go
|
NewConsumer
|
func NewConsumer() *rpc.Client {
return rpc.NewClient(rwCloser{os.Stdin, os.Stdout})
}
|
go
|
func NewConsumer() *rpc.Client {
return rpc.NewClient(rwCloser{os.Stdin, os.Stdout})
}
|
[
"func",
"NewConsumer",
"(",
")",
"*",
"rpc",
".",
"Client",
"{",
"return",
"rpc",
".",
"NewClient",
"(",
"rwCloser",
"{",
"os",
".",
"Stdin",
",",
"os",
".",
"Stdout",
"}",
")",
"\n",
"}"
] |
// NewConsumer returns an rpc.Client that will consume an API from the host
// process over this application's Stdin and Stdout using gob encoding.
|
[
"NewConsumer",
"returns",
"an",
"rpc",
".",
"Client",
"that",
"will",
"consume",
"an",
"API",
"from",
"the",
"host",
"process",
"over",
"this",
"application",
"s",
"Stdin",
"and",
"Stdout",
"using",
"gob",
"encoding",
"."
] |
9a0d7201400759b777f38c0c2d7b0be4e3e8b5c9
|
https://github.com/natefinch/pie/blob/9a0d7201400759b777f38c0c2d7b0be4e3e8b5c9/pie.go#L126-L128
|
19,694
|
natefinch/pie
|
pie.go
|
NewConsumerCodec
|
func NewConsumerCodec(f func(io.ReadWriteCloser) rpc.ClientCodec) *rpc.Client {
return rpc.NewClientWithCodec(f(rwCloser{os.Stdin, os.Stdout}))
}
|
go
|
func NewConsumerCodec(f func(io.ReadWriteCloser) rpc.ClientCodec) *rpc.Client {
return rpc.NewClientWithCodec(f(rwCloser{os.Stdin, os.Stdout}))
}
|
[
"func",
"NewConsumerCodec",
"(",
"f",
"func",
"(",
"io",
".",
"ReadWriteCloser",
")",
"rpc",
".",
"ClientCodec",
")",
"*",
"rpc",
".",
"Client",
"{",
"return",
"rpc",
".",
"NewClientWithCodec",
"(",
"f",
"(",
"rwCloser",
"{",
"os",
".",
"Stdin",
",",
"os",
".",
"Stdout",
"}",
")",
")",
"\n",
"}"
] |
// NewConsumerCodec returns an rpc.Client that will consume an API from the host
// process over this application's Stdin and Stdout using the ClientCodec
// returned by f.
|
[
"NewConsumerCodec",
"returns",
"an",
"rpc",
".",
"Client",
"that",
"will",
"consume",
"an",
"API",
"from",
"the",
"host",
"process",
"over",
"this",
"application",
"s",
"Stdin",
"and",
"Stdout",
"using",
"the",
"ClientCodec",
"returned",
"by",
"f",
"."
] |
9a0d7201400759b777f38c0c2d7b0be4e3e8b5c9
|
https://github.com/natefinch/pie/blob/9a0d7201400759b777f38c0c2d7b0be4e3e8b5c9/pie.go#L133-L135
|
19,695
|
natefinch/pie
|
pie.go
|
start
|
func start(cmd commander) (_ ioPipe, err error) {
in, err := cmd.StdinPipe()
if err != nil {
return ioPipe{}, err
}
defer func() {
if err != nil {
in.Close()
}
}()
out, err := cmd.StdoutPipe()
if err != nil {
return ioPipe{}, err
}
defer func() {
if err != nil {
out.Close()
}
}()
proc, err := cmd.Start()
if err != nil {
return ioPipe{}, err
}
return ioPipe{out, in, proc}, nil
}
|
go
|
func start(cmd commander) (_ ioPipe, err error) {
in, err := cmd.StdinPipe()
if err != nil {
return ioPipe{}, err
}
defer func() {
if err != nil {
in.Close()
}
}()
out, err := cmd.StdoutPipe()
if err != nil {
return ioPipe{}, err
}
defer func() {
if err != nil {
out.Close()
}
}()
proc, err := cmd.Start()
if err != nil {
return ioPipe{}, err
}
return ioPipe{out, in, proc}, nil
}
|
[
"func",
"start",
"(",
"cmd",
"commander",
")",
"(",
"_",
"ioPipe",
",",
"err",
"error",
")",
"{",
"in",
",",
"err",
":=",
"cmd",
".",
"StdinPipe",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"ioPipe",
"{",
"}",
",",
"err",
"\n",
"}",
"\n",
"defer",
"func",
"(",
")",
"{",
"if",
"err",
"!=",
"nil",
"{",
"in",
".",
"Close",
"(",
")",
"\n",
"}",
"\n",
"}",
"(",
")",
"\n",
"out",
",",
"err",
":=",
"cmd",
".",
"StdoutPipe",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"ioPipe",
"{",
"}",
",",
"err",
"\n",
"}",
"\n",
"defer",
"func",
"(",
")",
"{",
"if",
"err",
"!=",
"nil",
"{",
"out",
".",
"Close",
"(",
")",
"\n",
"}",
"\n",
"}",
"(",
")",
"\n\n",
"proc",
",",
"err",
":=",
"cmd",
".",
"Start",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"ioPipe",
"{",
"}",
",",
"err",
"\n",
"}",
"\n",
"return",
"ioPipe",
"{",
"out",
",",
"in",
",",
"proc",
"}",
",",
"nil",
"\n",
"}"
] |
// start runs the plugin and returns an ioPipe that can be used to control the
// plugin.
|
[
"start",
"runs",
"the",
"plugin",
"and",
"returns",
"an",
"ioPipe",
"that",
"can",
"be",
"used",
"to",
"control",
"the",
"plugin",
"."
] |
9a0d7201400759b777f38c0c2d7b0be4e3e8b5c9
|
https://github.com/natefinch/pie/blob/9a0d7201400759b777f38c0c2d7b0be4e3e8b5c9/pie.go#L139-L164
|
19,696
|
natefinch/pie
|
pie.go
|
Close
|
func (iop ioPipe) Close() error {
err := iop.ReadCloser.Close()
if writeErr := iop.WriteCloser.Close(); writeErr != nil {
err = writeErr
}
if procErr := iop.closeProc(); procErr != nil {
err = procErr
}
return err
}
|
go
|
func (iop ioPipe) Close() error {
err := iop.ReadCloser.Close()
if writeErr := iop.WriteCloser.Close(); writeErr != nil {
err = writeErr
}
if procErr := iop.closeProc(); procErr != nil {
err = procErr
}
return err
}
|
[
"func",
"(",
"iop",
"ioPipe",
")",
"Close",
"(",
")",
"error",
"{",
"err",
":=",
"iop",
".",
"ReadCloser",
".",
"Close",
"(",
")",
"\n",
"if",
"writeErr",
":=",
"iop",
".",
"WriteCloser",
".",
"Close",
"(",
")",
";",
"writeErr",
"!=",
"nil",
"{",
"err",
"=",
"writeErr",
"\n",
"}",
"\n",
"if",
"procErr",
":=",
"iop",
".",
"closeProc",
"(",
")",
";",
"procErr",
"!=",
"nil",
"{",
"err",
"=",
"procErr",
"\n",
"}",
"\n",
"return",
"err",
"\n",
"}"
] |
// Close closes the pipe's WriteCloser, ReadClosers, and process.
|
[
"Close",
"closes",
"the",
"pipe",
"s",
"WriteCloser",
"ReadClosers",
"and",
"process",
"."
] |
9a0d7201400759b777f38c0c2d7b0be4e3e8b5c9
|
https://github.com/natefinch/pie/blob/9a0d7201400759b777f38c0c2d7b0be4e3e8b5c9/pie.go#L212-L221
|
19,697
|
natefinch/pie
|
pie.go
|
closeProc
|
func (iop ioPipe) closeProc() error {
result := make(chan error, 1)
go func() { _, err := iop.proc.Wait(); result <- err }()
if err := iop.proc.Signal(os.Interrupt); err != nil {
return err
}
select {
case err := <-result:
return err
case <-time.After(procTimeout):
if err := iop.proc.Kill(); err != nil {
return fmt.Errorf("error killing process after timeout: %s", err)
}
return errProcStopTimeout
}
}
|
go
|
func (iop ioPipe) closeProc() error {
result := make(chan error, 1)
go func() { _, err := iop.proc.Wait(); result <- err }()
if err := iop.proc.Signal(os.Interrupt); err != nil {
return err
}
select {
case err := <-result:
return err
case <-time.After(procTimeout):
if err := iop.proc.Kill(); err != nil {
return fmt.Errorf("error killing process after timeout: %s", err)
}
return errProcStopTimeout
}
}
|
[
"func",
"(",
"iop",
"ioPipe",
")",
"closeProc",
"(",
")",
"error",
"{",
"result",
":=",
"make",
"(",
"chan",
"error",
",",
"1",
")",
"\n",
"go",
"func",
"(",
")",
"{",
"_",
",",
"err",
":=",
"iop",
".",
"proc",
".",
"Wait",
"(",
")",
";",
"result",
"<-",
"err",
"}",
"(",
")",
"\n",
"if",
"err",
":=",
"iop",
".",
"proc",
".",
"Signal",
"(",
"os",
".",
"Interrupt",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"select",
"{",
"case",
"err",
":=",
"<-",
"result",
":",
"return",
"err",
"\n",
"case",
"<-",
"time",
".",
"After",
"(",
"procTimeout",
")",
":",
"if",
"err",
":=",
"iop",
".",
"proc",
".",
"Kill",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"return",
"errProcStopTimeout",
"\n",
"}",
"\n",
"}"
] |
// closeProc sends an interrupt signal to the pipe's process, and if it doesn't
// respond in one second, kills the process.
|
[
"closeProc",
"sends",
"an",
"interrupt",
"signal",
"to",
"the",
"pipe",
"s",
"process",
"and",
"if",
"it",
"doesn",
"t",
"respond",
"in",
"one",
"second",
"kills",
"the",
"process",
"."
] |
9a0d7201400759b777f38c0c2d7b0be4e3e8b5c9
|
https://github.com/natefinch/pie/blob/9a0d7201400759b777f38c0c2d7b0be4e3e8b5c9/pie.go#L229-L244
|
19,698
|
natefinch/pie
|
pie.go
|
Close
|
func (rw rwCloser) Close() error {
err := rw.ReadCloser.Close()
if err := rw.WriteCloser.Close(); err != nil {
return err
}
return err
}
|
go
|
func (rw rwCloser) Close() error {
err := rw.ReadCloser.Close()
if err := rw.WriteCloser.Close(); err != nil {
return err
}
return err
}
|
[
"func",
"(",
"rw",
"rwCloser",
")",
"Close",
"(",
")",
"error",
"{",
"err",
":=",
"rw",
".",
"ReadCloser",
".",
"Close",
"(",
")",
"\n",
"if",
"err",
":=",
"rw",
".",
"WriteCloser",
".",
"Close",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"err",
"\n",
"}"
] |
// Close closes both the ReadCloser and the WriteCloser, returning the last
// error from either.
|
[
"Close",
"closes",
"both",
"the",
"ReadCloser",
"and",
"the",
"WriteCloser",
"returning",
"the",
"last",
"error",
"from",
"either",
"."
] |
9a0d7201400759b777f38c0c2d7b0be4e3e8b5c9
|
https://github.com/natefinch/pie/blob/9a0d7201400759b777f38c0c2d7b0be4e3e8b5c9/pie.go#L254-L260
|
19,699
|
awalterschulze/goderive
|
derive/fields.go
|
Name
|
func (f *Field) Name(recv string, unsafePkg Import) string {
if !f.Private() || !f.external {
return recv + "." + f.name
}
return `*(*` + f.typeStr() + `)(` + unsafePkg() + `.Pointer(` + recv + `.FieldByName("` + f.name + `").UnsafeAddr()))`
}
|
go
|
func (f *Field) Name(recv string, unsafePkg Import) string {
if !f.Private() || !f.external {
return recv + "." + f.name
}
return `*(*` + f.typeStr() + `)(` + unsafePkg() + `.Pointer(` + recv + `.FieldByName("` + f.name + `").UnsafeAddr()))`
}
|
[
"func",
"(",
"f",
"*",
"Field",
")",
"Name",
"(",
"recv",
"string",
",",
"unsafePkg",
"Import",
")",
"string",
"{",
"if",
"!",
"f",
".",
"Private",
"(",
")",
"||",
"!",
"f",
".",
"external",
"{",
"return",
"recv",
"+",
"\"",
"\"",
"+",
"f",
".",
"name",
"\n",
"}",
"\n",
"return",
"`*(*`",
"+",
"f",
".",
"typeStr",
"(",
")",
"+",
"`)(`",
"+",
"unsafePkg",
"(",
")",
"+",
"`.Pointer(`",
"+",
"recv",
"+",
"`.FieldByName(\"`",
"+",
"f",
".",
"name",
"+",
"`\").UnsafeAddr()))`",
"\n",
"}"
] |
// Name returns the field name, given the receiver and the unsafe import, if needed.
|
[
"Name",
"returns",
"the",
"field",
"name",
"given",
"the",
"receiver",
"and",
"the",
"unsafe",
"import",
"if",
"needed",
"."
] |
71608c676057f3512b43cbd61d645b0dc6bcfc20
|
https://github.com/awalterschulze/goderive/blob/71608c676057f3512b43cbd61d645b0dc6bcfc20/derive/fields.go#L37-L42
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.