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 list | docstring stringlengths 6 2.61k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 85 252 |
|---|---|---|---|---|---|---|---|---|---|---|---|
145,500 | luismesas/goPi | spi/spi.go | SPI_IOC_MESSAGE | func SPI_IOC_MESSAGE(n uintptr) uintptr {
return ioctl.IOW(SPI_IOC_MAGIC, 0, uintptr(SPI_MESSAGE_SIZE(n)))
} | go | func SPI_IOC_MESSAGE(n uintptr) uintptr {
return ioctl.IOW(SPI_IOC_MAGIC, 0, uintptr(SPI_MESSAGE_SIZE(n)))
} | [
"func",
"SPI_IOC_MESSAGE",
"(",
"n",
"uintptr",
")",
"uintptr",
"{",
"return",
"ioctl",
".",
"IOW",
"(",
"SPI_IOC_MAGIC",
",",
"0",
",",
"uintptr",
"(",
"SPI_MESSAGE_SIZE",
"(",
"n",
")",
")",
")",
"\n",
"}"
] | // Write custom SPI message | [
"Write",
"custom",
"SPI",
"message"
] | abc9b85cfb5fdde8a715ca5d205e044e8b8fe52c | https://github.com/luismesas/goPi/blob/abc9b85cfb5fdde8a715ca5d205e044e8b8fe52c/spi/spi.go#L51-L53 |
145,501 | Clever/kayvee-go | router/router.go | NewFromRoutes | func NewFromRoutes(routes map[string]Rule) (Router, error) {
router := &RuleRouter{}
for name, rule := range routes {
output, err := substituteEnvVars(rule.Output)
if err != nil {
return router, err
}
output = setDefaults(output)
rule.Name = name
rule.Output = output
router.rules = append(router.rul... | go | func NewFromRoutes(routes map[string]Rule) (Router, error) {
router := &RuleRouter{}
for name, rule := range routes {
output, err := substituteEnvVars(rule.Output)
if err != nil {
return router, err
}
output = setDefaults(output)
rule.Name = name
rule.Output = output
router.rules = append(router.rul... | [
"func",
"NewFromRoutes",
"(",
"routes",
"map",
"[",
"string",
"]",
"Rule",
")",
"(",
"Router",
",",
"error",
")",
"{",
"router",
":=",
"&",
"RuleRouter",
"{",
"}",
"\n",
"for",
"name",
",",
"rule",
":=",
"range",
"routes",
"{",
"output",
",",
"err",
... | // NewFromRoutes constructs a RuleRouter using the provided map of route names
// to Rules. | [
"NewFromRoutes",
"constructs",
"a",
"RuleRouter",
"using",
"the",
"provided",
"map",
"of",
"route",
"names",
"to",
"Rules",
"."
] | 1e2557bcbd6982e6303c364505d1c129ede8f2ee | https://github.com/Clever/kayvee-go/blob/1e2557bcbd6982e6303c364505d1c129ede8f2ee/router/router.go#L102-L117 |
145,502 | Clever/kayvee-go | validator/validator.go | ValidateJSONFormat | func ValidateJSONFormat(logLine string) error {
var kayveeData map[string]interface{}
err := json.Unmarshal([]byte(strings.TrimSpace(logLine)), &kayveeData)
if err != nil {
return &InvalidJSONError{jsonError: err}
}
return validateKayveeData(kayveeData)
} | go | func ValidateJSONFormat(logLine string) error {
var kayveeData map[string]interface{}
err := json.Unmarshal([]byte(strings.TrimSpace(logLine)), &kayveeData)
if err != nil {
return &InvalidJSONError{jsonError: err}
}
return validateKayveeData(kayveeData)
} | [
"func",
"ValidateJSONFormat",
"(",
"logLine",
"string",
")",
"error",
"{",
"var",
"kayveeData",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"\n\n",
"err",
":=",
"json",
".",
"Unmarshal",
"(",
"[",
"]",
"byte",
"(",
"strings",
".",
"TrimSpace",
"(",... | // ValidateJSONFormat returns a errors if the given string is not a valid
// JSON-formatted kayvee log line. | [
"ValidateJSONFormat",
"returns",
"a",
"errors",
"if",
"the",
"given",
"string",
"is",
"not",
"a",
"valid",
"JSON",
"-",
"formatted",
"kayvee",
"log",
"line",
"."
] | 1e2557bcbd6982e6303c364505d1c129ede8f2ee | https://github.com/Clever/kayvee-go/blob/1e2557bcbd6982e6303c364505d1c129ede8f2ee/validator/validator.go#L93-L102 |
145,503 | Clever/kayvee-go | logger/mocklogger.go | RuleCounts | func (ml *MockRouteCountLogger) RuleCounts() map[string]int {
out := make(map[string]int)
for k, v := range ml.routeMatches {
out[k] = len(v)
}
return out
} | go | func (ml *MockRouteCountLogger) RuleCounts() map[string]int {
out := make(map[string]int)
for k, v := range ml.routeMatches {
out[k] = len(v)
}
return out
} | [
"func",
"(",
"ml",
"*",
"MockRouteCountLogger",
")",
"RuleCounts",
"(",
")",
"map",
"[",
"string",
"]",
"int",
"{",
"out",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"int",
")",
"\n",
"for",
"k",
",",
"v",
":=",
"range",
"ml",
".",
"routeMatches... | // RuleCounts returns a map of rule names to the number of times that rule has been applied
// in routing logs for MockRouteCountLogger. Only includes routing rules that have at least
// one use. | [
"RuleCounts",
"returns",
"a",
"map",
"of",
"rule",
"names",
"to",
"the",
"number",
"of",
"times",
"that",
"rule",
"has",
"been",
"applied",
"in",
"routing",
"logs",
"for",
"MockRouteCountLogger",
".",
"Only",
"includes",
"routing",
"rules",
"that",
"have",
"... | 1e2557bcbd6982e6303c364505d1c129ede8f2ee | https://github.com/Clever/kayvee-go/blob/1e2557bcbd6982e6303c364505d1c129ede8f2ee/logger/mocklogger.go#L19-L25 |
145,504 | Clever/kayvee-go | logger/mocklogger.go | NewMockCountLoggerWithContext | func NewMockCountLoggerWithContext(source string, contextValues map[string]interface{}) *MockRouteCountLogger {
routeMatches := make(map[string][]router.RuleOutput)
lg := NewWithContext(source, contextValues)
lg.setFormatLogger(&routeCountingFormatLogger{
routeMatches: routeMatches,
})
mocklg := MockRouteCountLo... | go | func NewMockCountLoggerWithContext(source string, contextValues map[string]interface{}) *MockRouteCountLogger {
routeMatches := make(map[string][]router.RuleOutput)
lg := NewWithContext(source, contextValues)
lg.setFormatLogger(&routeCountingFormatLogger{
routeMatches: routeMatches,
})
mocklg := MockRouteCountLo... | [
"func",
"NewMockCountLoggerWithContext",
"(",
"source",
"string",
",",
"contextValues",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"*",
"MockRouteCountLogger",
"{",
"routeMatches",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"[",
"]",
"router",
... | // NewMockCountLoggerWithContext returns a new MockRoutCountLogger with the specified `source` and `contextValues`. | [
"NewMockCountLoggerWithContext",
"returns",
"a",
"new",
"MockRoutCountLogger",
"with",
"the",
"specified",
"source",
"and",
"contextValues",
"."
] | 1e2557bcbd6982e6303c364505d1c129ede8f2ee | https://github.com/Clever/kayvee-go/blob/1e2557bcbd6982e6303c364505d1c129ede8f2ee/logger/mocklogger.go#L39-L50 |
145,505 | Clever/kayvee-go | logger/mocklogger.go | formatAndLog | func (fl *routeCountingFormatLogger) formatAndLog(data map[string]interface{}) {
routeData, ok := data["_kvmeta"]
if !ok {
return
}
routes, ok := routeData.(map[string]interface{})["routes"]
if !ok {
return
}
for _, route := range routes.([]map[string]interface{}) {
rule := route["rule"].(string)
fl.rout... | go | func (fl *routeCountingFormatLogger) formatAndLog(data map[string]interface{}) {
routeData, ok := data["_kvmeta"]
if !ok {
return
}
routes, ok := routeData.(map[string]interface{})["routes"]
if !ok {
return
}
for _, route := range routes.([]map[string]interface{}) {
rule := route["rule"].(string)
fl.rout... | [
"func",
"(",
"fl",
"*",
"routeCountingFormatLogger",
")",
"formatAndLog",
"(",
"data",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"{",
"routeData",
",",
"ok",
":=",
"data",
"[",
"\"",
"\"",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"\n",... | // formatAndLog tracks routing statistics for this mock router.
// Initialization works as with the default format logger, but no formatting or logging is actually performed. | [
"formatAndLog",
"tracks",
"routing",
"statistics",
"for",
"this",
"mock",
"router",
".",
"Initialization",
"works",
"as",
"with",
"the",
"default",
"format",
"logger",
"but",
"no",
"formatting",
"or",
"logging",
"is",
"actually",
"performed",
"."
] | 1e2557bcbd6982e6303c364505d1c129ede8f2ee | https://github.com/Clever/kayvee-go/blob/1e2557bcbd6982e6303c364505d1c129ede8f2ee/logger/mocklogger.go#L66-L79 |
145,506 | Clever/kayvee-go | logger/mocklogger.go | SetRouter | func (ml *MockRouteCountLogger) SetRouter(router router.Router) {
ml.logger.SetRouter(router)
} | go | func (ml *MockRouteCountLogger) SetRouter(router router.Router) {
ml.logger.SetRouter(router)
} | [
"func",
"(",
"ml",
"*",
"MockRouteCountLogger",
")",
"SetRouter",
"(",
"router",
"router",
".",
"Router",
")",
"{",
"ml",
".",
"logger",
".",
"SetRouter",
"(",
"router",
")",
"\n",
"}"
] | // SetRouter implements the method for the KayveeLogger interface. | [
"SetRouter",
"implements",
"the",
"method",
"for",
"the",
"KayveeLogger",
"interface",
"."
] | 1e2557bcbd6982e6303c364505d1c129ede8f2ee | https://github.com/Clever/kayvee-go/blob/1e2557bcbd6982e6303c364505d1c129ede8f2ee/logger/mocklogger.go#L135-L137 |
145,507 | Clever/kayvee-go | logger/mocklogger.go | GaugeInt | func (ml *MockRouteCountLogger) GaugeInt(title string, value int) {
ml.logger.GaugeInt(title, value)
} | go | func (ml *MockRouteCountLogger) GaugeInt(title string, value int) {
ml.logger.GaugeInt(title, value)
} | [
"func",
"(",
"ml",
"*",
"MockRouteCountLogger",
")",
"GaugeInt",
"(",
"title",
"string",
",",
"value",
"int",
")",
"{",
"ml",
".",
"logger",
".",
"GaugeInt",
"(",
"title",
",",
"value",
")",
"\n",
"}"
] | // GaugeInt implements the method for the KayveeLogger interface. | [
"GaugeInt",
"implements",
"the",
"method",
"for",
"the",
"KayveeLogger",
"interface",
"."
] | 1e2557bcbd6982e6303c364505d1c129ede8f2ee | https://github.com/Clever/kayvee-go/blob/1e2557bcbd6982e6303c364505d1c129ede8f2ee/logger/mocklogger.go#L175-L177 |
145,508 | Clever/kayvee-go | logger/mocklogger.go | GaugeFloat | func (ml *MockRouteCountLogger) GaugeFloat(title string, value float64) {
ml.logger.GaugeFloat(title, value)
} | go | func (ml *MockRouteCountLogger) GaugeFloat(title string, value float64) {
ml.logger.GaugeFloat(title, value)
} | [
"func",
"(",
"ml",
"*",
"MockRouteCountLogger",
")",
"GaugeFloat",
"(",
"title",
"string",
",",
"value",
"float64",
")",
"{",
"ml",
".",
"logger",
".",
"GaugeFloat",
"(",
"title",
",",
"value",
")",
"\n",
"}"
] | // GaugeFloat implements the method for the KayveeLogger interface. | [
"GaugeFloat",
"implements",
"the",
"method",
"for",
"the",
"KayveeLogger",
"interface",
"."
] | 1e2557bcbd6982e6303c364505d1c129ede8f2ee | https://github.com/Clever/kayvee-go/blob/1e2557bcbd6982e6303c364505d1c129ede8f2ee/logger/mocklogger.go#L180-L182 |
145,509 | Clever/kayvee-go | logger/mocklogger.go | CounterD | func (ml *MockRouteCountLogger) CounterD(title string, value int, data map[string]interface{}) {
ml.logger.CounterD(title, value, data)
} | go | func (ml *MockRouteCountLogger) CounterD(title string, value int, data map[string]interface{}) {
ml.logger.CounterD(title, value, data)
} | [
"func",
"(",
"ml",
"*",
"MockRouteCountLogger",
")",
"CounterD",
"(",
"title",
"string",
",",
"value",
"int",
",",
"data",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"{",
"ml",
".",
"logger",
".",
"CounterD",
"(",
"title",
",",
"value",
"... | // CounterD implements the method for the KayveeLogger interface. | [
"CounterD",
"implements",
"the",
"method",
"for",
"the",
"KayveeLogger",
"interface",
"."
] | 1e2557bcbd6982e6303c364505d1c129ede8f2ee | https://github.com/Clever/kayvee-go/blob/1e2557bcbd6982e6303c364505d1c129ede8f2ee/logger/mocklogger.go#L215-L217 |
145,510 | Clever/kayvee-go | middleware/middleware.go | HeaderHandler | func HeaderHandler(headers ...string) func(*http.Request) map[string]interface{} {
return func(req *http.Request) map[string]interface{} {
result := map[string]interface{}{}
for _, header := range headers {
if val := req.Header.Get(header); val != "" {
result[header] = val
}
}
return result
}
} | go | func HeaderHandler(headers ...string) func(*http.Request) map[string]interface{} {
return func(req *http.Request) map[string]interface{} {
result := map[string]interface{}{}
for _, header := range headers {
if val := req.Header.Get(header); val != "" {
result[header] = val
}
}
return result
}
} | [
"func",
"HeaderHandler",
"(",
"headers",
"...",
"string",
")",
"func",
"(",
"*",
"http",
".",
"Request",
")",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"return",
"func",
"(",
"req",
"*",
"http",
".",
"Request",
")",
"map",
"[",
"string",... | // HeaderHandler takes in any amount of headers and returns a handler that adds those headers. | [
"HeaderHandler",
"takes",
"in",
"any",
"amount",
"of",
"headers",
"and",
"returns",
"a",
"handler",
"that",
"adds",
"those",
"headers",
"."
] | 1e2557bcbd6982e6303c364505d1c129ede8f2ee | https://github.com/Clever/kayvee-go/blob/1e2557bcbd6982e6303c364505d1c129ede8f2ee/middleware/middleware.go#L119-L129 |
145,511 | Clever/kayvee-go | middleware/rollup.go | EnableRollups | func EnableRollups(ctx context.Context, logger RollupLogger, reportingInterval time.Duration) {
globalRollupRouter = NewRollupRouter(ctx, logger, reportingInterval)
} | go | func EnableRollups(ctx context.Context, logger RollupLogger, reportingInterval time.Duration) {
globalRollupRouter = NewRollupRouter(ctx, logger, reportingInterval)
} | [
"func",
"EnableRollups",
"(",
"ctx",
"context",
".",
"Context",
",",
"logger",
"RollupLogger",
",",
"reportingInterval",
"time",
".",
"Duration",
")",
"{",
"globalRollupRouter",
"=",
"NewRollupRouter",
"(",
"ctx",
",",
"logger",
",",
"reportingInterval",
")",
"\... | // EnableRollups turns on rollups for kv middleware logs. | [
"EnableRollups",
"turns",
"on",
"rollups",
"for",
"kv",
"middleware",
"logs",
"."
] | 1e2557bcbd6982e6303c364505d1c129ede8f2ee | https://github.com/Clever/kayvee-go/blob/1e2557bcbd6982e6303c364505d1c129ede8f2ee/middleware/rollup.go#L22-L24 |
145,512 | Clever/kayvee-go | middleware/rollup.go | NewRollupRouter | func NewRollupRouter(ctx context.Context, logger RollupLogger, reportingDelay time.Duration) *RollupRouter {
l := &RollupRouter{
logger: logger,
reportingDelay: reportingDelay,
rollups: map[string]*logRollup{},
ctx: ctx,
ctxDone: false,
}
go func() {
select {
case <-ctx... | go | func NewRollupRouter(ctx context.Context, logger RollupLogger, reportingDelay time.Duration) *RollupRouter {
l := &RollupRouter{
logger: logger,
reportingDelay: reportingDelay,
rollups: map[string]*logRollup{},
ctx: ctx,
ctxDone: false,
}
go func() {
select {
case <-ctx... | [
"func",
"NewRollupRouter",
"(",
"ctx",
"context",
".",
"Context",
",",
"logger",
"RollupLogger",
",",
"reportingDelay",
"time",
".",
"Duration",
")",
"*",
"RollupRouter",
"{",
"l",
":=",
"&",
"RollupRouter",
"{",
"logger",
":",
"logger",
",",
"reportingDelay",... | // NewRollupRouter creates a new log rollup output.
// Rollups will stop when the context is canceled. | [
"NewRollupRouter",
"creates",
"a",
"new",
"log",
"rollup",
"output",
".",
"Rollups",
"will",
"stop",
"when",
"the",
"context",
"is",
"canceled",
"."
] | 1e2557bcbd6982e6303c364505d1c129ede8f2ee | https://github.com/Clever/kayvee-go/blob/1e2557bcbd6982e6303c364505d1c129ede8f2ee/middleware/rollup.go#L40-L58 |
145,513 | Clever/kayvee-go | middleware/rollup.go | ShouldRollup | func (r *RollupRouter) ShouldRollup(logmsg map[string]interface{}) bool {
if _, ok := logmsg["op"].(string); !ok {
return false
}
if _, ok := logmsg["method"].(string); !ok {
return false
}
statusCode, ok := logmsg["status-code"].(int)
if !ok {
return false
} else if statusCode != 200 {
return false
}... | go | func (r *RollupRouter) ShouldRollup(logmsg map[string]interface{}) bool {
if _, ok := logmsg["op"].(string); !ok {
return false
}
if _, ok := logmsg["method"].(string); !ok {
return false
}
statusCode, ok := logmsg["status-code"].(int)
if !ok {
return false
} else if statusCode != 200 {
return false
}... | [
"func",
"(",
"r",
"*",
"RollupRouter",
")",
"ShouldRollup",
"(",
"logmsg",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"bool",
"{",
"if",
"_",
",",
"ok",
":=",
"logmsg",
"[",
"\"",
"\"",
"]",
".",
"(",
"string",
")",
";",
"!",
"ok",
... | // ShouldRollup returns true when a log msg meets the criteria for rollup.
// In the future allow more configurability, for now default to 200's and < 500ms. | [
"ShouldRollup",
"returns",
"true",
"when",
"a",
"log",
"msg",
"meets",
"the",
"criteria",
"for",
"rollup",
".",
"In",
"the",
"future",
"allow",
"more",
"configurability",
"for",
"now",
"default",
"to",
"200",
"s",
"and",
"<",
"500ms",
"."
] | 1e2557bcbd6982e6303c364505d1c129ede8f2ee | https://github.com/Clever/kayvee-go/blob/1e2557bcbd6982e6303c364505d1c129ede8f2ee/middleware/rollup.go#L62-L86 |
145,514 | Clever/kayvee-go | middleware/rollup.go | Process | func (r *RollupRouter) Process(logmsg map[string]interface{}) {
if r.ctxDone {
return
}
statusCode, ok := logmsg["status-code"].(int)
if !ok {
return
}
op, ok := logmsg["op"].(string)
if !ok {
return
}
httpMethod, ok := logmsg["method"].(string)
if !ok {
return
}
canary, ok := logmsg["canary"].(boo... | go | func (r *RollupRouter) Process(logmsg map[string]interface{}) {
if r.ctxDone {
return
}
statusCode, ok := logmsg["status-code"].(int)
if !ok {
return
}
op, ok := logmsg["op"].(string)
if !ok {
return
}
httpMethod, ok := logmsg["method"].(string)
if !ok {
return
}
canary, ok := logmsg["canary"].(boo... | [
"func",
"(",
"r",
"*",
"RollupRouter",
")",
"Process",
"(",
"logmsg",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"{",
"if",
"r",
".",
"ctxDone",
"{",
"return",
"\n",
"}",
"\n\n",
"statusCode",
",",
"ok",
":=",
"logmsg",
"[",
"\"",
"\"",... | // Process rolls up a log message. | [
"Process",
"rolls",
"up",
"a",
"log",
"message",
"."
] | 1e2557bcbd6982e6303c364505d1c129ede8f2ee | https://github.com/Clever/kayvee-go/blob/1e2557bcbd6982e6303c364505d1c129ede8f2ee/middleware/rollup.go#L89-L111 |
145,515 | Clever/kayvee-go | router/match.go | Matches | func (r *Rule) Matches(msg map[string]interface{}) bool {
for field, values := range r.Matchers {
if !fieldMatches(field, values, msg) {
return false
}
}
return true
} | go | func (r *Rule) Matches(msg map[string]interface{}) bool {
for field, values := range r.Matchers {
if !fieldMatches(field, values, msg) {
return false
}
}
return true
} | [
"func",
"(",
"r",
"*",
"Rule",
")",
"Matches",
"(",
"msg",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"bool",
"{",
"for",
"field",
",",
"values",
":=",
"range",
"r",
".",
"Matchers",
"{",
"if",
"!",
"fieldMatches",
"(",
"field",
",",
... | // Matches returns true if the `msg` matches the matchers specified in this
// routing rule. | [
"Matches",
"returns",
"true",
"if",
"the",
"msg",
"matches",
"the",
"matchers",
"specified",
"in",
"this",
"routing",
"rule",
"."
] | 1e2557bcbd6982e6303c364505d1c129ede8f2ee | https://github.com/Clever/kayvee-go/blob/1e2557bcbd6982e6303c364505d1c129ede8f2ee/router/match.go#L9-L16 |
145,516 | Clever/kayvee-go | router/match.go | OutputFor | func (r *Rule) OutputFor(msg map[string]interface{}) map[string]interface{} {
lookup := func(field string) (interface{}, bool) {
return lookupField(field, msg)
}
subbed := substituteFields(r.Output, lookup)
subbed["rule"] = r.Name
return subbed
} | go | func (r *Rule) OutputFor(msg map[string]interface{}) map[string]interface{} {
lookup := func(field string) (interface{}, bool) {
return lookupField(field, msg)
}
subbed := substituteFields(r.Output, lookup)
subbed["rule"] = r.Name
return subbed
} | [
"func",
"(",
"r",
"*",
"Rule",
")",
"OutputFor",
"(",
"msg",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"lookup",
":=",
"func",
"(",
"field",
"string",
")",
"(",
"interface",
"{",
... | // OutputFor returns the output map for this routing rule with substitutions
// applied in accordance with the current environment and the contents of the
// message. | [
"OutputFor",
"returns",
"the",
"output",
"map",
"for",
"this",
"routing",
"rule",
"with",
"substitutions",
"applied",
"in",
"accordance",
"with",
"the",
"current",
"environment",
"and",
"the",
"contents",
"of",
"the",
"message",
"."
] | 1e2557bcbd6982e6303c364505d1c129ede8f2ee | https://github.com/Clever/kayvee-go/blob/1e2557bcbd6982e6303c364505d1c129ede8f2ee/router/match.go#L21-L28 |
145,517 | Clever/kayvee-go | router/match.go | lookupField | func lookupField(field string, obj map[string]interface{}) (interface{}, bool) {
if strings.Index(field, ".") == -1 {
val, ok := obj[field]
return val, ok
}
return lookupFieldPath(strings.Split(field, "."), obj)
} | go | func lookupField(field string, obj map[string]interface{}) (interface{}, bool) {
if strings.Index(field, ".") == -1 {
val, ok := obj[field]
return val, ok
}
return lookupFieldPath(strings.Split(field, "."), obj)
} | [
"func",
"lookupField",
"(",
"field",
"string",
",",
"obj",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"(",
"interface",
"{",
"}",
",",
"bool",
")",
"{",
"if",
"strings",
".",
"Index",
"(",
"field",
",",
"\"",
"\"",
")",
"==",
"-",
"1"... | // lookupField does an extended lookup on `obj`, interpreting dots in field as
// corresponding to subobjects. It returns the value and true if the lookup
// succeeded or `"", false` if the key is missing or corresponds to a
// non-string value. | [
"lookupField",
"does",
"an",
"extended",
"lookup",
"on",
"obj",
"interpreting",
"dots",
"in",
"field",
"as",
"corresponding",
"to",
"subobjects",
".",
"It",
"returns",
"the",
"value",
"and",
"true",
"if",
"the",
"lookup",
"succeeded",
"or",
"false",
"if",
"t... | 1e2557bcbd6982e6303c364505d1c129ede8f2ee | https://github.com/Clever/kayvee-go/blob/1e2557bcbd6982e6303c364505d1c129ede8f2ee/router/match.go#L34-L40 |
145,518 | Clever/kayvee-go | router/match.go | lookupFieldPath | func lookupFieldPath(fieldPath []string, obj map[string]interface{}) (interface{}, bool) {
part := fieldPath[0]
if len(fieldPath) == 1 {
val, ok := obj[part]
return val, ok
}
if subObj, ok := obj[part].(map[string]interface{}); ok {
return lookupFieldPath(fieldPath[1:], subObj)
}
return "", false
} | go | func lookupFieldPath(fieldPath []string, obj map[string]interface{}) (interface{}, bool) {
part := fieldPath[0]
if len(fieldPath) == 1 {
val, ok := obj[part]
return val, ok
}
if subObj, ok := obj[part].(map[string]interface{}); ok {
return lookupFieldPath(fieldPath[1:], subObj)
}
return "", false
} | [
"func",
"lookupFieldPath",
"(",
"fieldPath",
"[",
"]",
"string",
",",
"obj",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"(",
"interface",
"{",
"}",
",",
"bool",
")",
"{",
"part",
":=",
"fieldPath",
"[",
"0",
"]",
"\n",
"if",
"len",
"(",... | // lookupFieldPath does an extended lookup on `obj`, with each entry in `fieldPath`
// corresponding to subobjects. It returns the value and true if the lookup
// succeeded or `"", false` if a key was missing along the path or if the final
// key corresponds to a non-string value. | [
"lookupFieldPath",
"does",
"an",
"extended",
"lookup",
"on",
"obj",
"with",
"each",
"entry",
"in",
"fieldPath",
"corresponding",
"to",
"subobjects",
".",
"It",
"returns",
"the",
"value",
"and",
"true",
"if",
"the",
"lookup",
"succeeded",
"or",
"false",
"if",
... | 1e2557bcbd6982e6303c364505d1c129ede8f2ee | https://github.com/Clever/kayvee-go/blob/1e2557bcbd6982e6303c364505d1c129ede8f2ee/router/match.go#L46-L56 |
145,519 | Clever/kayvee-go | kayvee.go | Format | func Format(data map[string]interface{}) string {
if deployEnv != "" {
data["deploy_env"] = deployEnv
}
if workflowID != "" {
data["wf_id"] = workflowID
}
if podID != "" {
data["pod-id"] = podID
}
if podRegion != "" {
data["pod-region"] = podRegion
}
if podAccount != "" {
data["pod-account"] = podAcc... | go | func Format(data map[string]interface{}) string {
if deployEnv != "" {
data["deploy_env"] = deployEnv
}
if workflowID != "" {
data["wf_id"] = workflowID
}
if podID != "" {
data["pod-id"] = podID
}
if podRegion != "" {
data["pod-region"] = podRegion
}
if podAccount != "" {
data["pod-account"] = podAcc... | [
"func",
"Format",
"(",
"data",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"string",
"{",
"if",
"deployEnv",
"!=",
"\"",
"\"",
"{",
"data",
"[",
"\"",
"\"",
"]",
"=",
"deployEnv",
"\n",
"}",
"\n",
"if",
"workflowID",
"!=",
"\"",
"\"",
... | // Format converts a map to a string of space-delimited key=val pairs | [
"Format",
"converts",
"a",
"map",
"to",
"a",
"string",
"of",
"space",
"-",
"delimited",
"key",
"=",
"val",
"pairs"
] | 1e2557bcbd6982e6303c364505d1c129ede8f2ee | https://github.com/Clever/kayvee-go/blob/1e2557bcbd6982e6303c364505d1c129ede8f2ee/kayvee.go#L56-L74 |
145,520 | Clever/kayvee-go | kayvee.go | FormatLog | func FormatLog(source string, level LogLevel, title string, data map[string]interface{}) string {
if data == nil {
data = make(map[string]interface{})
}
data["source"] = source
data["level"] = level
data["title"] = title
return Format(data)
} | go | func FormatLog(source string, level LogLevel, title string, data map[string]interface{}) string {
if data == nil {
data = make(map[string]interface{})
}
data["source"] = source
data["level"] = level
data["title"] = title
return Format(data)
} | [
"func",
"FormatLog",
"(",
"source",
"string",
",",
"level",
"LogLevel",
",",
"title",
"string",
",",
"data",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"string",
"{",
"if",
"data",
"==",
"nil",
"{",
"data",
"=",
"make",
"(",
"map",
"[",
... | // FormatLog is similar to Format, but takes additional reserved params to promote logging best-practices | [
"FormatLog",
"is",
"similar",
"to",
"Format",
"but",
"takes",
"additional",
"reserved",
"params",
"to",
"promote",
"logging",
"best",
"-",
"practices"
] | 1e2557bcbd6982e6303c364505d1c129ede8f2ee | https://github.com/Clever/kayvee-go/blob/1e2557bcbd6982e6303c364505d1c129ede8f2ee/kayvee.go#L77-L85 |
145,521 | Clever/kayvee-go | logger/logger.go | SetGlobalRouting | func SetGlobalRouting(filename string) error {
var err error
globalRouter, err = router.NewFromConfig(filename)
return err
} | go | func SetGlobalRouting(filename string) error {
var err error
globalRouter, err = router.NewFromConfig(filename)
return err
} | [
"func",
"SetGlobalRouting",
"(",
"filename",
"string",
")",
"error",
"{",
"var",
"err",
"error",
"\n",
"globalRouter",
",",
"err",
"=",
"router",
".",
"NewFromConfig",
"(",
"filename",
")",
"\n",
"return",
"err",
"\n",
"}"
] | // SetGlobalRouting installs a new log router onto the KayveeLogger with the
// configuration specified in `filename`. For convenience, the KayveeLogger is expected
// to return itself as the first return value. | [
"SetGlobalRouting",
"installs",
"a",
"new",
"log",
"router",
"onto",
"the",
"KayveeLogger",
"with",
"the",
"configuration",
"specified",
"in",
"filename",
".",
"For",
"convenience",
"the",
"KayveeLogger",
"is",
"expected",
"to",
"return",
"itself",
"as",
"the",
... | 1e2557bcbd6982e6303c364505d1c129ede8f2ee | https://github.com/Clever/kayvee-go/blob/1e2557bcbd6982e6303c364505d1c129ede8f2ee/logger/logger.go#L96-L100 |
145,522 | Clever/kayvee-go | logger/logger.go | SetGlobalRoutingFromBytes | func SetGlobalRoutingFromBytes(fileBytes []byte) error {
var err error
globalRouter, err = router.NewFromConfigBytes(fileBytes)
return err
} | go | func SetGlobalRoutingFromBytes(fileBytes []byte) error {
var err error
globalRouter, err = router.NewFromConfigBytes(fileBytes)
return err
} | [
"func",
"SetGlobalRoutingFromBytes",
"(",
"fileBytes",
"[",
"]",
"byte",
")",
"error",
"{",
"var",
"err",
"error",
"\n",
"globalRouter",
",",
"err",
"=",
"router",
".",
"NewFromConfigBytes",
"(",
"fileBytes",
")",
"\n",
"return",
"err",
"\n",
"}"
] | // SetGlobalRoutingFromBytes installs a new log router onto the KayveeLogger with the
// configuration specified in . For convenience, the KayveeLogger is expected
// to return itself as the first return value. | [
"SetGlobalRoutingFromBytes",
"installs",
"a",
"new",
"log",
"router",
"onto",
"the",
"KayveeLogger",
"with",
"the",
"configuration",
"specified",
"in",
".",
"For",
"convenience",
"the",
"KayveeLogger",
"is",
"expected",
"to",
"return",
"itself",
"as",
"the",
"firs... | 1e2557bcbd6982e6303c364505d1c129ede8f2ee | https://github.com/Clever/kayvee-go/blob/1e2557bcbd6982e6303c364505d1c129ede8f2ee/logger/logger.go#L105-L109 |
145,523 | Clever/kayvee-go | logger/logger.go | SetConfig | func (l *Logger) SetConfig(source string, logLvl LogLevel, formatter Formatter, output io.Writer) {
l.globalsL.Lock()
defer l.globalsL.Unlock()
if l.globals == nil {
l.globals = make(map[string]interface{})
}
l.globals["source"] = source
l.logLvl = logLvl
l.fLogger.setFormatter(formatter)
l.fLogger.setOutput... | go | func (l *Logger) SetConfig(source string, logLvl LogLevel, formatter Formatter, output io.Writer) {
l.globalsL.Lock()
defer l.globalsL.Unlock()
if l.globals == nil {
l.globals = make(map[string]interface{})
}
l.globals["source"] = source
l.logLvl = logLvl
l.fLogger.setFormatter(formatter)
l.fLogger.setOutput... | [
"func",
"(",
"l",
"*",
"Logger",
")",
"SetConfig",
"(",
"source",
"string",
",",
"logLvl",
"LogLevel",
",",
"formatter",
"Formatter",
",",
"output",
"io",
".",
"Writer",
")",
"{",
"l",
".",
"globalsL",
".",
"Lock",
"(",
")",
"\n",
"defer",
"l",
".",
... | // SetConfig implements the method for the KayveeLogger interface. | [
"SetConfig",
"implements",
"the",
"method",
"for",
"the",
"KayveeLogger",
"interface",
"."
] | 1e2557bcbd6982e6303c364505d1c129ede8f2ee | https://github.com/Clever/kayvee-go/blob/1e2557bcbd6982e6303c364505d1c129ede8f2ee/logger/logger.go#L112-L123 |
145,524 | Clever/kayvee-go | logger/logger.go | GaugeInt | func (l *Logger) GaugeInt(title string, value int) {
l.GaugeIntD(title, value, M{})
} | go | func (l *Logger) GaugeInt(title string, value int) {
l.GaugeIntD(title, value, M{})
} | [
"func",
"(",
"l",
"*",
"Logger",
")",
"GaugeInt",
"(",
"title",
"string",
",",
"value",
"int",
")",
"{",
"l",
".",
"GaugeIntD",
"(",
"title",
",",
"value",
",",
"M",
"{",
"}",
")",
"\n",
"}"
] | // GaugeInt implements the method for the KayveeLogger interface.
// Logs with type = gauge, and value = value | [
"GaugeInt",
"implements",
"the",
"method",
"for",
"the",
"KayveeLogger",
"interface",
".",
"Logs",
"with",
"type",
"=",
"gauge",
"and",
"value",
"=",
"value"
] | 1e2557bcbd6982e6303c364505d1c129ede8f2ee | https://github.com/Clever/kayvee-go/blob/1e2557bcbd6982e6303c364505d1c129ede8f2ee/logger/logger.go#L202-L204 |
145,525 | Clever/kayvee-go | logger/logger.go | GaugeFloat | func (l *Logger) GaugeFloat(title string, value float64) {
l.GaugeFloatD(title, value, M{})
} | go | func (l *Logger) GaugeFloat(title string, value float64) {
l.GaugeFloatD(title, value, M{})
} | [
"func",
"(",
"l",
"*",
"Logger",
")",
"GaugeFloat",
"(",
"title",
"string",
",",
"value",
"float64",
")",
"{",
"l",
".",
"GaugeFloatD",
"(",
"title",
",",
"value",
",",
"M",
"{",
"}",
")",
"\n",
"}"
] | // GaugeFloat implements the method for the KayveeLogger interface.
// Logs with type = gauge, and value = value | [
"GaugeFloat",
"implements",
"the",
"method",
"for",
"the",
"KayveeLogger",
"interface",
".",
"Logs",
"with",
"type",
"=",
"gauge",
"and",
"value",
"=",
"value"
] | 1e2557bcbd6982e6303c364505d1c129ede8f2ee | https://github.com/Clever/kayvee-go/blob/1e2557bcbd6982e6303c364505d1c129ede8f2ee/logger/logger.go#L208-L210 |
145,526 | Clever/kayvee-go | logger/logger.go | CounterD | func (l *Logger) CounterD(title string, value int, data map[string]interface{}) {
data["title"] = title
data["value"] = value
data["type"] = "counter"
l.logWithLevel(Info, data)
} | go | func (l *Logger) CounterD(title string, value int, data map[string]interface{}) {
data["title"] = title
data["value"] = value
data["type"] = "counter"
l.logWithLevel(Info, data)
} | [
"func",
"(",
"l",
"*",
"Logger",
")",
"CounterD",
"(",
"title",
"string",
",",
"value",
"int",
",",
"data",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"{",
"data",
"[",
"\"",
"\"",
"]",
"=",
"title",
"\n",
"data",
"[",
"\"",
"\"",
"... | // CounterD implements the method for the KayveeLogger interface.
// Logs with type = gauge, and value = value | [
"CounterD",
"implements",
"the",
"method",
"for",
"the",
"KayveeLogger",
"interface",
".",
"Logs",
"with",
"type",
"=",
"gauge",
"and",
"value",
"=",
"value"
] | 1e2557bcbd6982e6303c364505d1c129ede8f2ee | https://github.com/Clever/kayvee-go/blob/1e2557bcbd6982e6303c364505d1c129ede8f2ee/logger/logger.go#L250-L255 |
145,527 | Clever/kayvee-go | logger/logger.go | GaugeIntD | func (l *Logger) GaugeIntD(title string, value int, data map[string]interface{}) {
l.gauge(title, value, data)
} | go | func (l *Logger) GaugeIntD(title string, value int, data map[string]interface{}) {
l.gauge(title, value, data)
} | [
"func",
"(",
"l",
"*",
"Logger",
")",
"GaugeIntD",
"(",
"title",
"string",
",",
"value",
"int",
",",
"data",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"{",
"l",
".",
"gauge",
"(",
"title",
",",
"value",
",",
"data",
")",
"\n",
"}"
] | // GaugeIntD implements the method for the KayveeLogger interface.
// Logs with type = gauge, and value = value | [
"GaugeIntD",
"implements",
"the",
"method",
"for",
"the",
"KayveeLogger",
"interface",
".",
"Logs",
"with",
"type",
"=",
"gauge",
"and",
"value",
"=",
"value"
] | 1e2557bcbd6982e6303c364505d1c129ede8f2ee | https://github.com/Clever/kayvee-go/blob/1e2557bcbd6982e6303c364505d1c129ede8f2ee/logger/logger.go#L259-L261 |
145,528 | Clever/kayvee-go | logger/logger.go | logWithLevel | func (l *Logger) logWithLevel(logLvl LogLevel, data map[string]interface{}) {
if logLvl < l.logLvl {
// No log output
return
}
data["level"] = logLvl.String()
l.globalsL.RLock()
defer l.globalsL.RUnlock()
for key, value := range l.globals {
if _, ok := data[key]; ok {
// Values in the data map override t... | go | func (l *Logger) logWithLevel(logLvl LogLevel, data map[string]interface{}) {
if logLvl < l.logLvl {
// No log output
return
}
data["level"] = logLvl.String()
l.globalsL.RLock()
defer l.globalsL.RUnlock()
for key, value := range l.globals {
if _, ok := data[key]; ok {
// Values in the data map override t... | [
"func",
"(",
"l",
"*",
"Logger",
")",
"logWithLevel",
"(",
"logLvl",
"LogLevel",
",",
"data",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"{",
"if",
"logLvl",
"<",
"l",
".",
"logLvl",
"{",
"// No log output",
"return",
"\n",
"}",
"\n",
"da... | // Actual logging. Handles whether to output based on log level and
// unifies the passed in data with the stored globals | [
"Actual",
"logging",
".",
"Handles",
"whether",
"to",
"output",
"based",
"on",
"log",
"level",
"and",
"unifies",
"the",
"passed",
"in",
"data",
"with",
"the",
"stored",
"globals"
] | 1e2557bcbd6982e6303c364505d1c129ede8f2ee | https://github.com/Clever/kayvee-go/blob/1e2557bcbd6982e6303c364505d1c129ede8f2ee/logger/logger.go#L278-L300 |
145,529 | Clever/kayvee-go | logger/context.go | NewContext | func NewContext(ctx context.Context, logger KayveeLogger) context.Context {
return context.WithValue(ctx, loggerKey, logger)
} | go | func NewContext(ctx context.Context, logger KayveeLogger) context.Context {
return context.WithValue(ctx, loggerKey, logger)
} | [
"func",
"NewContext",
"(",
"ctx",
"context",
".",
"Context",
",",
"logger",
"KayveeLogger",
")",
"context",
".",
"Context",
"{",
"return",
"context",
".",
"WithValue",
"(",
"ctx",
",",
"loggerKey",
",",
"logger",
")",
"\n",
"}"
] | // NewContext creates a new context object containing a logger value. | [
"NewContext",
"creates",
"a",
"new",
"context",
"object",
"containing",
"a",
"logger",
"value",
"."
] | 1e2557bcbd6982e6303c364505d1c129ede8f2ee | https://github.com/Clever/kayvee-go/blob/1e2557bcbd6982e6303c364505d1c129ede8f2ee/logger/context.go#L10-L12 |
145,530 | Clever/kayvee-go | router/parse.go | UnmarshalYAML | func (m *RuleMatchers) UnmarshalYAML(unmarshal func(interface{}) error) error {
// Use a map[string]interface{} for validation purposes. If we used a
// map[string][]string, the YAML unmarshaler would coerce non-string values
// into string values, breaking our ability to validate configs. i.e., it
// would change ... | go | func (m *RuleMatchers) UnmarshalYAML(unmarshal func(interface{}) error) error {
// Use a map[string]interface{} for validation purposes. If we used a
// map[string][]string, the YAML unmarshaler would coerce non-string values
// into string values, breaking our ability to validate configs. i.e., it
// would change ... | [
"func",
"(",
"m",
"*",
"RuleMatchers",
")",
"UnmarshalYAML",
"(",
"unmarshal",
"func",
"(",
"interface",
"{",
"}",
")",
"error",
")",
"error",
"{",
"// Use a map[string]interface{} for validation purposes. If we used a",
"// map[string][]string, the YAML unmarshaler would coe... | // UnmarshalYAML unmarshals the `matchers` section of a log-routing
// configuration and validates it. | [
"UnmarshalYAML",
"unmarshals",
"the",
"matchers",
"section",
"of",
"a",
"log",
"-",
"routing",
"configuration",
"and",
"validates",
"it",
"."
] | 1e2557bcbd6982e6303c364505d1c129ede8f2ee | https://github.com/Clever/kayvee-go/blob/1e2557bcbd6982e6303c364505d1c129ede8f2ee/router/parse.go#L51-L95 |
145,531 | bradrydzewski/go.auth | oauth2_google.go | NewGoogleProvider | func NewGoogleProvider(client, secret, redirect string) *GoogleProvider {
goog := GoogleProvider{}
goog.AuthorizationURL = "https://accounts.google.com/o/oauth2/auth"
goog.AccessTokenURL = "https://accounts.google.com/o/oauth2/token"
goog.RedirectURL = redirect
goog.ClientId = client
goog.ClientSec... | go | func NewGoogleProvider(client, secret, redirect string) *GoogleProvider {
goog := GoogleProvider{}
goog.AuthorizationURL = "https://accounts.google.com/o/oauth2/auth"
goog.AccessTokenURL = "https://accounts.google.com/o/oauth2/token"
goog.RedirectURL = redirect
goog.ClientId = client
goog.ClientSec... | [
"func",
"NewGoogleProvider",
"(",
"client",
",",
"secret",
",",
"redirect",
"string",
")",
"*",
"GoogleProvider",
"{",
"goog",
":=",
"GoogleProvider",
"{",
"}",
"\n",
"goog",
".",
"AuthorizationURL",
"=",
"\"",
"\"",
"\n",
"goog",
".",
"AccessTokenURL",
"=",... | // NewGoogleProvider allocates and returns a new GoogleProvider. | [
"NewGoogleProvider",
"allocates",
"and",
"returns",
"a",
"new",
"GoogleProvider",
"."
] | d0051b5cc53874ee5e0b2223e57c0e35d18029a8 | https://github.com/bradrydzewski/go.auth/blob/d0051b5cc53874ee5e0b2223e57c0e35d18029a8/oauth2_google.go#L32-L40 |
145,532 | bradrydzewski/go.auth | oauth2_google.go | Redirect | func (self *GoogleProvider) Redirect(w http.ResponseWriter, r *http.Request) {
const scope = "https://www.googleapis.com/auth/userinfo.profile+https://www.googleapis.com/auth/userinfo.email"
self.OAuth2Mixin.AuthorizeRedirect(w, r, scope)
} | go | func (self *GoogleProvider) Redirect(w http.ResponseWriter, r *http.Request) {
const scope = "https://www.googleapis.com/auth/userinfo.profile+https://www.googleapis.com/auth/userinfo.email"
self.OAuth2Mixin.AuthorizeRedirect(w, r, scope)
} | [
"func",
"(",
"self",
"*",
"GoogleProvider",
")",
"Redirect",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"const",
"scope",
"=",
"\"",
"\"",
"\n",
"self",
".",
"OAuth2Mixin",
".",
"AuthorizeRedirect",
"(",
"... | // Redirect will do an http.Redirect, sending the user to the Google login
// screen. | [
"Redirect",
"will",
"do",
"an",
"http",
".",
"Redirect",
"sending",
"the",
"user",
"to",
"the",
"Google",
"login",
"screen",
"."
] | d0051b5cc53874ee5e0b2223e57c0e35d18029a8 | https://github.com/bradrydzewski/go.auth/blob/d0051b5cc53874ee5e0b2223e57c0e35d18029a8/oauth2_google.go#L44-L47 |
145,533 | bradrydzewski/go.auth | oauth2_google.go | GetAuthenticatedUser | func (self *GoogleProvider) GetAuthenticatedUser(w http.ResponseWriter, r *http.Request) (User, Token, error) {
// Get the OAuth2 Access Token
token, err := self.GetAccessToken(r)
if err != nil {
return nil, nil, err
}
user := GoogleUser{}
err = self.OAuth2Mixin.GetAuthenticatedUser("https://www.googleapis.com... | go | func (self *GoogleProvider) GetAuthenticatedUser(w http.ResponseWriter, r *http.Request) (User, Token, error) {
// Get the OAuth2 Access Token
token, err := self.GetAccessToken(r)
if err != nil {
return nil, nil, err
}
user := GoogleUser{}
err = self.OAuth2Mixin.GetAuthenticatedUser("https://www.googleapis.com... | [
"func",
"(",
"self",
"*",
"GoogleProvider",
")",
"GetAuthenticatedUser",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"(",
"User",
",",
"Token",
",",
"error",
")",
"{",
"// Get the OAuth2 Access Token",
"token",
",",
... | // GetAuthenticatedUser will retrieve the Authentication User from the
// http.Request object. | [
"GetAuthenticatedUser",
"will",
"retrieve",
"the",
"Authentication",
"User",
"from",
"the",
"http",
".",
"Request",
"object",
"."
] | d0051b5cc53874ee5e0b2223e57c0e35d18029a8 | https://github.com/bradrydzewski/go.auth/blob/d0051b5cc53874ee5e0b2223e57c0e35d18029a8/oauth2_google.go#L51-L61 |
145,534 | bradrydzewski/go.auth | oauth2/client.go | AuthorizeRedirect | func (c *Client) AuthorizeRedirect(scope, state string) string {
// add required parameters
params := make(url.Values)
params.Add("response_type", ResponseTypeCode)
//params.Set("redirect_uri", c.RedirectURL)
params.Set("client_id", c.ClientId)
// add optional redirect param
// NOTE: this is optional for some p... | go | func (c *Client) AuthorizeRedirect(scope, state string) string {
// add required parameters
params := make(url.Values)
params.Add("response_type", ResponseTypeCode)
//params.Set("redirect_uri", c.RedirectURL)
params.Set("client_id", c.ClientId)
// add optional redirect param
// NOTE: this is optional for some p... | [
"func",
"(",
"c",
"*",
"Client",
")",
"AuthorizeRedirect",
"(",
"scope",
",",
"state",
"string",
")",
"string",
"{",
"// add required parameters",
"params",
":=",
"make",
"(",
"url",
".",
"Values",
")",
"\n",
"params",
".",
"Add",
"(",
"\"",
"\"",
",",
... | // AuthorizeRedirect constructs the Authorization Endpoint, where the user
// can authorize the client to access protected resources. | [
"AuthorizeRedirect",
"constructs",
"the",
"Authorization",
"Endpoint",
"where",
"the",
"user",
"can",
"authorize",
"the",
"client",
"to",
"access",
"protected",
"resources",
"."
] | d0051b5cc53874ee5e0b2223e57c0e35d18029a8 | https://github.com/bradrydzewski/go.auth/blob/d0051b5cc53874ee5e0b2223e57c0e35d18029a8/oauth2/client.go#L41-L80 |
145,535 | bradrydzewski/go.auth | oauth2/client.go | RefreshToken | func (c *Client) RefreshToken(refreshToken string) (*Token, error) {
params := make(url.Values)
params.Set("grant_type", GrantTypeRefreshToken)
params.Set("refresh_token", refreshToken)
params.Set("scope", "")
return c.grantToken(params)
} | go | func (c *Client) RefreshToken(refreshToken string) (*Token, error) {
params := make(url.Values)
params.Set("grant_type", GrantTypeRefreshToken)
params.Set("refresh_token", refreshToken)
params.Set("scope", "")
return c.grantToken(params)
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"RefreshToken",
"(",
"refreshToken",
"string",
")",
"(",
"*",
"Token",
",",
"error",
")",
"{",
"params",
":=",
"make",
"(",
"url",
".",
"Values",
")",
"\n",
"params",
".",
"Set",
"(",
"\"",
"\"",
",",
"GrantTyp... | // RefreshToken requests a new access token by authenticating with
// the authorization server and presenting the refresh token. | [
"RefreshToken",
"requests",
"a",
"new",
"access",
"token",
"by",
"authenticating",
"with",
"the",
"authorization",
"server",
"and",
"presenting",
"the",
"refresh",
"token",
"."
] | d0051b5cc53874ee5e0b2223e57c0e35d18029a8 | https://github.com/bradrydzewski/go.auth/blob/d0051b5cc53874ee5e0b2223e57c0e35d18029a8/oauth2/client.go#L125-L131 |
145,536 | bradrydzewski/go.auth | oauth2/client.go | grantToken | func (c *Client) grantToken(params url.Values) (*Token, error) {
// Create the access token url params
if params == nil {
params = make(url.Values)
}
// Add the client id, client secret and code to the query params
params.Set("client_id", c.ClientId)
params.Set("client_secret", c.ClientSecret)
params.Set("red... | go | func (c *Client) grantToken(params url.Values) (*Token, error) {
// Create the access token url params
if params == nil {
params = make(url.Values)
}
// Add the client id, client secret and code to the query params
params.Set("client_id", c.ClientId)
params.Set("client_secret", c.ClientSecret)
params.Set("red... | [
"func",
"(",
"c",
"*",
"Client",
")",
"grantToken",
"(",
"params",
"url",
".",
"Values",
")",
"(",
"*",
"Token",
",",
"error",
")",
"{",
"// Create the access token url params",
"if",
"params",
"==",
"nil",
"{",
"params",
"=",
"make",
"(",
"url",
".",
... | // helper function to retrieve a token from the server | [
"helper",
"function",
"to",
"retrieve",
"a",
"token",
"from",
"the",
"server"
] | d0051b5cc53874ee5e0b2223e57c0e35d18029a8 | https://github.com/bradrydzewski/go.auth/blob/d0051b5cc53874ee5e0b2223e57c0e35d18029a8/oauth2/client.go#L183-L249 |
145,537 | bradrydzewski/go.auth | oauth1/consumer.go | AuthorizeRedirect | func (c *Consumer) AuthorizeRedirect(t *RequestToken) (string, error) {
redirect, err := url.Parse(c.AuthorizationURL)
if err != nil {
return "", err
}
params := make(url.Values)
params.Add("oauth_token", t.token)
redirect.RawQuery = params.Encode()
u := redirect.String()
if strings.HasPrefix(u, "https://bi... | go | func (c *Consumer) AuthorizeRedirect(t *RequestToken) (string, error) {
redirect, err := url.Parse(c.AuthorizationURL)
if err != nil {
return "", err
}
params := make(url.Values)
params.Add("oauth_token", t.token)
redirect.RawQuery = params.Encode()
u := redirect.String()
if strings.HasPrefix(u, "https://bi... | [
"func",
"(",
"c",
"*",
"Consumer",
")",
"AuthorizeRedirect",
"(",
"t",
"*",
"RequestToken",
")",
"(",
"string",
",",
"error",
")",
"{",
"redirect",
",",
"err",
":=",
"url",
".",
"Parse",
"(",
"c",
".",
"AuthorizationURL",
")",
"\n",
"if",
"err",
"!="... | // AuthorizeRedirect constructs the request URL that should be used
// to redirect the User to verify User identify and consent. | [
"AuthorizeRedirect",
"constructs",
"the",
"request",
"URL",
"that",
"should",
"be",
"used",
"to",
"redirect",
"the",
"User",
"to",
"verify",
"User",
"identify",
"and",
"consent",
"."
] | d0051b5cc53874ee5e0b2223e57c0e35d18029a8 | https://github.com/bradrydzewski/go.auth/blob/d0051b5cc53874ee5e0b2223e57c0e35d18029a8/oauth1/consumer.go#L92-L108 |
145,538 | bradrydzewski/go.auth | oauth1/consumer.go | Sign | func (c *Consumer) Sign(req *http.Request, token Token) error {
return c.SignParams(req, token, nil)
} | go | func (c *Consumer) Sign(req *http.Request, token Token) error {
return c.SignParams(req, token, nil)
} | [
"func",
"(",
"c",
"*",
"Consumer",
")",
"Sign",
"(",
"req",
"*",
"http",
".",
"Request",
",",
"token",
"Token",
")",
"error",
"{",
"return",
"c",
".",
"SignParams",
"(",
"req",
",",
"token",
",",
"nil",
")",
"\n",
"}"
] | // Sign will sign an http.Request using the provided token. | [
"Sign",
"will",
"sign",
"an",
"http",
".",
"Request",
"using",
"the",
"provided",
"token",
"."
] | d0051b5cc53874ee5e0b2223e57c0e35d18029a8 | https://github.com/bradrydzewski/go.auth/blob/d0051b5cc53874ee5e0b2223e57c0e35d18029a8/oauth1/consumer.go#L144-L146 |
145,539 | bradrydzewski/go.auth | oauth1/consumer.go | SignParams | func (c *Consumer) SignParams(req *http.Request, token Token, params map[string]string) error {
// ensure the parameter map is not nil
if params == nil {
params = map[string]string{}
}
// ensure default parameters are set
//params["oauth_token"] = token.Token()
params["oauth_consumer_key"] = c.... | go | func (c *Consumer) SignParams(req *http.Request, token Token, params map[string]string) error {
// ensure the parameter map is not nil
if params == nil {
params = map[string]string{}
}
// ensure default parameters are set
//params["oauth_token"] = token.Token()
params["oauth_consumer_key"] = c.... | [
"func",
"(",
"c",
"*",
"Consumer",
")",
"SignParams",
"(",
"req",
"*",
"http",
".",
"Request",
",",
"token",
"Token",
",",
"params",
"map",
"[",
"string",
"]",
"string",
")",
"error",
"{",
"// ensure the parameter map is not nil",
"if",
"params",
"==",
"ni... | // Sign will sign an http.Request using the provided token, and additional
// parameters. | [
"Sign",
"will",
"sign",
"an",
"http",
".",
"Request",
"using",
"the",
"provided",
"token",
"and",
"additional",
"parameters",
"."
] | d0051b5cc53874ee5e0b2223e57c0e35d18029a8 | https://github.com/bradrydzewski/go.auth/blob/d0051b5cc53874ee5e0b2223e57c0e35d18029a8/oauth1/consumer.go#L150-L213 |
145,540 | bradrydzewski/go.auth | oauth1/consumer.go | sign | func sign(message, key string) string {
hashfun := hmac.New(sha1.New, []byte(key))
hashfun.Write([]byte(message))
rawsignature := hashfun.Sum(nil)
base64signature := make([]byte, base64.StdEncoding.EncodedLen(len(rawsignature)))
base64.StdEncoding.Encode(base64signature, rawsignature)
return string(base64signatu... | go | func sign(message, key string) string {
hashfun := hmac.New(sha1.New, []byte(key))
hashfun.Write([]byte(message))
rawsignature := hashfun.Sum(nil)
base64signature := make([]byte, base64.StdEncoding.EncodedLen(len(rawsignature)))
base64.StdEncoding.Encode(base64signature, rawsignature)
return string(base64signatu... | [
"func",
"sign",
"(",
"message",
",",
"key",
"string",
")",
"string",
"{",
"hashfun",
":=",
"hmac",
".",
"New",
"(",
"sha1",
".",
"New",
",",
"[",
"]",
"byte",
"(",
"key",
")",
")",
"\n",
"hashfun",
".",
"Write",
"(",
"[",
"]",
"byte",
"(",
"mes... | // Generates an HMAC Signature for an OAuth1.0a request. | [
"Generates",
"an",
"HMAC",
"Signature",
"for",
"an",
"OAuth1",
".",
"0a",
"request",
"."
] | d0051b5cc53874ee5e0b2223e57c0e35d18029a8 | https://github.com/bradrydzewski/go.auth/blob/d0051b5cc53874ee5e0b2223e57c0e35d18029a8/oauth1/consumer.go#L234-L242 |
145,541 | bradrydzewski/go.auth | oauth1/consumer.go | headers | func headers(consumerKey string) map[string]string {
return map[string]string{
"oauth_consumer_key" : consumerKey,
"oauth_nonce" : nonce(),
"oauth_signature_method" : "HMAC-SHA1",
"oauth_timestamp" : timestamp(),
"oauth_version" : "1.0",
}
} | go | func headers(consumerKey string) map[string]string {
return map[string]string{
"oauth_consumer_key" : consumerKey,
"oauth_nonce" : nonce(),
"oauth_signature_method" : "HMAC-SHA1",
"oauth_timestamp" : timestamp(),
"oauth_version" : "1.0",
}
} | [
"func",
"headers",
"(",
"consumerKey",
"string",
")",
"map",
"[",
"string",
"]",
"string",
"{",
"return",
"map",
"[",
"string",
"]",
"string",
"{",
"\"",
"\"",
":",
"consumerKey",
",",
"\"",
"\"",
":",
"nonce",
"(",
")",
",",
"\"",
"\"",
":",
"\"",... | // Gets the default set of OAuth1.0a headers. | [
"Gets",
"the",
"default",
"set",
"of",
"OAuth1",
".",
"0a",
"headers",
"."
] | d0051b5cc53874ee5e0b2223e57c0e35d18029a8 | https://github.com/bradrydzewski/go.auth/blob/d0051b5cc53874ee5e0b2223e57c0e35d18029a8/oauth1/consumer.go#L245-L253 |
145,542 | bradrydzewski/go.auth | oauth2.go | AuthorizeRedirect | func (self *OAuth2Mixin) AuthorizeRedirect(w http.ResponseWriter, r *http.Request, scope string) {
state := strconv.FormatInt(stateGenerator.Int63(), 10)
url := self.Client.AuthorizeRedirect(scope, state)
http.Redirect(w, r, url, http.StatusSeeOther)
} | go | func (self *OAuth2Mixin) AuthorizeRedirect(w http.ResponseWriter, r *http.Request, scope string) {
state := strconv.FormatInt(stateGenerator.Int63(), 10)
url := self.Client.AuthorizeRedirect(scope, state)
http.Redirect(w, r, url, http.StatusSeeOther)
} | [
"func",
"(",
"self",
"*",
"OAuth2Mixin",
")",
"AuthorizeRedirect",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
",",
"scope",
"string",
")",
"{",
"state",
":=",
"strconv",
".",
"FormatInt",
"(",
"stateGenerator",
".",
"... | // Redirects the User to the Login Screen | [
"Redirects",
"the",
"User",
"to",
"the",
"Login",
"Screen"
] | d0051b5cc53874ee5e0b2223e57c0e35d18029a8 | https://github.com/bradrydzewski/go.auth/blob/d0051b5cc53874ee5e0b2223e57c0e35d18029a8/oauth2.go#L32-L36 |
145,543 | bradrydzewski/go.auth | oauth2.go | GetAccessToken | func (self *OAuth2Mixin) GetAccessToken(r *http.Request) (*oauth2.Token, error) {
code := r.URL.Query().Get("code")
if len(code) == 0 {
return nil, errors.New("No Access Code in the Request URL")
}
accessToken, err := self.Client.GrantToken(code)
if err != nil {
return nil, err
}
return accessToken, err
} | go | func (self *OAuth2Mixin) GetAccessToken(r *http.Request) (*oauth2.Token, error) {
code := r.URL.Query().Get("code")
if len(code) == 0 {
return nil, errors.New("No Access Code in the Request URL")
}
accessToken, err := self.Client.GrantToken(code)
if err != nil {
return nil, err
}
return accessToken, err
} | [
"func",
"(",
"self",
"*",
"OAuth2Mixin",
")",
"GetAccessToken",
"(",
"r",
"*",
"http",
".",
"Request",
")",
"(",
"*",
"oauth2",
".",
"Token",
",",
"error",
")",
"{",
"code",
":=",
"r",
".",
"URL",
".",
"Query",
"(",
")",
".",
"Get",
"(",
"\"",
... | // Exchanges the verifier for an OAuth2 Access Token. | [
"Exchanges",
"the",
"verifier",
"for",
"an",
"OAuth2",
"Access",
"Token",
"."
] | d0051b5cc53874ee5e0b2223e57c0e35d18029a8 | https://github.com/bradrydzewski/go.auth/blob/d0051b5cc53874ee5e0b2223e57c0e35d18029a8/oauth2.go#L39-L52 |
145,544 | bradrydzewski/go.auth | oauth2.go | GetAuthenticatedUser | func (self *OAuth2Mixin) GetAuthenticatedUser(endpoint string, accessToken string, resp interface{}) error {
//create the user url
endpointUrl, _ := url.Parse(endpoint)
endpointUrl.RawQuery = "access_token="+accessToken
//create the http request for the user Url
req := http.Request{
URL: endpointUrl,
... | go | func (self *OAuth2Mixin) GetAuthenticatedUser(endpoint string, accessToken string, resp interface{}) error {
//create the user url
endpointUrl, _ := url.Parse(endpoint)
endpointUrl.RawQuery = "access_token="+accessToken
//create the http request for the user Url
req := http.Request{
URL: endpointUrl,
... | [
"func",
"(",
"self",
"*",
"OAuth2Mixin",
")",
"GetAuthenticatedUser",
"(",
"endpoint",
"string",
",",
"accessToken",
"string",
",",
"resp",
"interface",
"{",
"}",
")",
"error",
"{",
"//create the user url",
"endpointUrl",
",",
"_",
":=",
"url",
".",
"Parse",
... | // Gets the Authenticated User | [
"Gets",
"the",
"Authenticated",
"User"
] | d0051b5cc53874ee5e0b2223e57c0e35d18029a8 | https://github.com/bradrydzewski/go.auth/blob/d0051b5cc53874ee5e0b2223e57c0e35d18029a8/oauth2.go#L55-L85 |
145,545 | bradrydzewski/go.auth | twitter.go | NewTwitterProvider | func NewTwitterProvider(key, secret, callback string) *TwitterProvider {
twitter := TwitterProvider{}
twitter.AuthorizationURL = "https://api.twitter.com/oauth/authorize"
twitter.RequestTokenURL = "https://api.twitter.com/oauth/request_token"
twitter.AccessTokenURL = "https://api.twitter.com/oauth/access_token"
... | go | func NewTwitterProvider(key, secret, callback string) *TwitterProvider {
twitter := TwitterProvider{}
twitter.AuthorizationURL = "https://api.twitter.com/oauth/authorize"
twitter.RequestTokenURL = "https://api.twitter.com/oauth/request_token"
twitter.AccessTokenURL = "https://api.twitter.com/oauth/access_token"
... | [
"func",
"NewTwitterProvider",
"(",
"key",
",",
"secret",
",",
"callback",
"string",
")",
"*",
"TwitterProvider",
"{",
"twitter",
":=",
"TwitterProvider",
"{",
"}",
"\n",
"twitter",
".",
"AuthorizationURL",
"=",
"\"",
"\"",
"\n",
"twitter",
".",
"RequestTokenUR... | // NewTwitterProvider allocates and returns a new BitbucketProvider. | [
"NewTwitterProvider",
"allocates",
"and",
"returns",
"a",
"new",
"BitbucketProvider",
"."
] | d0051b5cc53874ee5e0b2223e57c0e35d18029a8 | https://github.com/bradrydzewski/go.auth/blob/d0051b5cc53874ee5e0b2223e57c0e35d18029a8/twitter.go#L27-L37 |
145,546 | bradrydzewski/go.auth | twitter.go | GetAuthenticatedUser | func (self *TwitterProvider) GetAuthenticatedUser(w http.ResponseWriter, r *http.Request) (User, Token, error) {
// upgrade the oauth_token to an access token
token, err := self.OAuth1Mixin.AuthorizeToken(w, r)
if err != nil {
return nil, nil, err
}
// get the Bitbucket User details
user := TwitterUser{}
if ... | go | func (self *TwitterProvider) GetAuthenticatedUser(w http.ResponseWriter, r *http.Request) (User, Token, error) {
// upgrade the oauth_token to an access token
token, err := self.OAuth1Mixin.AuthorizeToken(w, r)
if err != nil {
return nil, nil, err
}
// get the Bitbucket User details
user := TwitterUser{}
if ... | [
"func",
"(",
"self",
"*",
"TwitterProvider",
")",
"GetAuthenticatedUser",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"(",
"User",
",",
"Token",
",",
"error",
")",
"{",
"// upgrade the oauth_token to an access token",
"... | // GetAuthenticatedUser will upgrade the oauth_token to an access token, and
// invoke the appropriate Twitter REST API call to get the User's information. | [
"GetAuthenticatedUser",
"will",
"upgrade",
"the",
"oauth_token",
"to",
"an",
"access",
"token",
"and",
"invoke",
"the",
"appropriate",
"Twitter",
"REST",
"API",
"call",
"to",
"get",
"the",
"User",
"s",
"information",
"."
] | d0051b5cc53874ee5e0b2223e57c0e35d18029a8 | https://github.com/bradrydzewski/go.auth/blob/d0051b5cc53874ee5e0b2223e57c0e35d18029a8/twitter.go#L41-L55 |
145,547 | bradrydzewski/go.auth | cookie.go | SetUserCookie | func SetUserCookie(w http.ResponseWriter, r *http.Request, user User) {
cookie := &http.Cookie{
Name: Config.CookieName,
Path: "/",
Domain: r.URL.Host,
HttpOnly: Config.CookieHttpOnly,
Secure: Config.CookieSecure,
}
// if not a session cookie set the MaxAge
if Config.CookieMaxAge > 0 {
coo... | go | func SetUserCookie(w http.ResponseWriter, r *http.Request, user User) {
cookie := &http.Cookie{
Name: Config.CookieName,
Path: "/",
Domain: r.URL.Host,
HttpOnly: Config.CookieHttpOnly,
Secure: Config.CookieSecure,
}
// if not a session cookie set the MaxAge
if Config.CookieMaxAge > 0 {
coo... | [
"func",
"SetUserCookie",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
",",
"user",
"User",
")",
"{",
"cookie",
":=",
"&",
"http",
".",
"Cookie",
"{",
"Name",
":",
"Config",
".",
"CookieName",
",",
"Path",
":",
"\"",... | // SetUserCookie creates a secure cookie for the given username, indicating the
// user is authenticated. | [
"SetUserCookie",
"creates",
"a",
"secure",
"cookie",
"for",
"the",
"given",
"username",
"indicating",
"the",
"user",
"is",
"authenticated",
"."
] | d0051b5cc53874ee5e0b2223e57c0e35d18029a8 | https://github.com/bradrydzewski/go.auth/blob/d0051b5cc53874ee5e0b2223e57c0e35d18029a8/cookie.go#L20-L36 |
145,548 | bradrydzewski/go.auth | cookie.go | SetUserCookieOpts | func SetUserCookieOpts(w http.ResponseWriter, cookie *http.Cookie, user User) {
// default cookie expiration
exp := time.Now().Add(Config.CookieExp)
// generate cookie valid for 24 hours for user
// the strings are quoted to ensure they aren't tampered with
// TODO explore storing string as a URL Parameter Strin... | go | func SetUserCookieOpts(w http.ResponseWriter, cookie *http.Cookie, user User) {
// default cookie expiration
exp := time.Now().Add(Config.CookieExp)
// generate cookie valid for 24 hours for user
// the strings are quoted to ensure they aren't tampered with
// TODO explore storing string as a URL Parameter Strin... | [
"func",
"SetUserCookieOpts",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"cookie",
"*",
"http",
".",
"Cookie",
",",
"user",
"User",
")",
"{",
"// default cookie expiration",
"exp",
":=",
"time",
".",
"Now",
"(",
")",
".",
"Add",
"(",
"Config",
".",
"Co... | // SetUserCookieOpts creates a secure cookie for the given User and with the
// specified cookie options. | [
"SetUserCookieOpts",
"creates",
"a",
"secure",
"cookie",
"for",
"the",
"given",
"User",
"and",
"with",
"the",
"specified",
"cookie",
"options",
"."
] | d0051b5cc53874ee5e0b2223e57c0e35d18029a8 | https://github.com/bradrydzewski/go.auth/blob/d0051b5cc53874ee5e0b2223e57c0e35d18029a8/cookie.go#L40-L58 |
145,549 | bradrydzewski/go.auth | cookie.go | DeleteUserCookie | func DeleteUserCookie(w http.ResponseWriter, r *http.Request) {
DeleteUserCookieName(w, r, Config.CookieName)
} | go | func DeleteUserCookie(w http.ResponseWriter, r *http.Request) {
DeleteUserCookieName(w, r, Config.CookieName)
} | [
"func",
"DeleteUserCookie",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"DeleteUserCookieName",
"(",
"w",
",",
"r",
",",
"Config",
".",
"CookieName",
")",
"\n",
"}"
] | // DeleteUserCookie removes a secure cookie that was created for the user's
// login session. This effectively logs a user out of the system. | [
"DeleteUserCookie",
"removes",
"a",
"secure",
"cookie",
"that",
"was",
"created",
"for",
"the",
"user",
"s",
"login",
"session",
".",
"This",
"effectively",
"logs",
"a",
"user",
"out",
"of",
"the",
"system",
"."
] | d0051b5cc53874ee5e0b2223e57c0e35d18029a8 | https://github.com/bradrydzewski/go.auth/blob/d0051b5cc53874ee5e0b2223e57c0e35d18029a8/cookie.go#L62-L64 |
145,550 | bradrydzewski/go.auth | cookie.go | GetUserCookie | func GetUserCookie(r *http.Request) (User, error) {
return GetUserCookieName(r, Config.CookieName)
} | go | func GetUserCookie(r *http.Request) (User, error) {
return GetUserCookieName(r, Config.CookieName)
} | [
"func",
"GetUserCookie",
"(",
"r",
"*",
"http",
".",
"Request",
")",
"(",
"User",
",",
"error",
")",
"{",
"return",
"GetUserCookieName",
"(",
"r",
",",
"Config",
".",
"CookieName",
")",
"\n",
"}"
] | // GetUserCookie will get the User data from the http session. If the session is
// inactive, or if the session has expired, then an error will be returned. | [
"GetUserCookie",
"will",
"get",
"the",
"User",
"data",
"from",
"the",
"http",
"session",
".",
"If",
"the",
"session",
"is",
"inactive",
"or",
"if",
"the",
"session",
"has",
"expired",
"then",
"an",
"error",
"will",
"be",
"returned",
"."
] | d0051b5cc53874ee5e0b2223e57c0e35d18029a8 | https://github.com/bradrydzewski/go.auth/blob/d0051b5cc53874ee5e0b2223e57c0e35d18029a8/cookie.go#L81-L83 |
145,551 | bradrydzewski/go.auth | cookie.go | GetUserCookieName | func GetUserCookieName(r *http.Request, name string) (User, error) {
//look for the authcookie
cookie, err := r.Cookie(name)
//if doesn't exist (or is malformed) redirect
//back to the login url
if err != nil {
return nil, err
}
// get the login string from authcookie
login, expires, err := authcookie.Parse... | go | func GetUserCookieName(r *http.Request, name string) (User, error) {
//look for the authcookie
cookie, err := r.Cookie(name)
//if doesn't exist (or is malformed) redirect
//back to the login url
if err != nil {
return nil, err
}
// get the login string from authcookie
login, expires, err := authcookie.Parse... | [
"func",
"GetUserCookieName",
"(",
"r",
"*",
"http",
".",
"Request",
",",
"name",
"string",
")",
"(",
"User",
",",
"error",
")",
"{",
"//look for the authcookie",
"cookie",
",",
"err",
":=",
"r",
".",
"Cookie",
"(",
"name",
")",
"\n\n",
"//if doesn't exist ... | // GetUserCookieName will get the User data from the http session for the
// specified secure cookie. If the session is inactive, or if the session has
// expired, then an error will be returned. | [
"GetUserCookieName",
"will",
"get",
"the",
"User",
"data",
"from",
"the",
"http",
"session",
"for",
"the",
"specified",
"secure",
"cookie",
".",
"If",
"the",
"session",
"is",
"inactive",
"or",
"if",
"the",
"session",
"has",
"expired",
"then",
"an",
"error",
... | d0051b5cc53874ee5e0b2223e57c0e35d18029a8 | https://github.com/bradrydzewski/go.auth/blob/d0051b5cc53874ee5e0b2223e57c0e35d18029a8/cookie.go#L88-L125 |
145,552 | bradrydzewski/go.auth | examples/openid/openid_demo.go | Private | func Private(w http.ResponseWriter, r *http.Request) {
user := r.URL.User.Username()
fmt.Fprintf(w, fmt.Sprintf(privatepage, user, user))
} | go | func Private(w http.ResponseWriter, r *http.Request) {
user := r.URL.User.Username()
fmt.Fprintf(w, fmt.Sprintf(privatepage, user, user))
} | [
"func",
"Private",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"user",
":=",
"r",
".",
"URL",
".",
"User",
".",
"Username",
"(",
")",
"\n",
"fmt",
".",
"Fprintf",
"(",
"w",
",",
"fmt",
".",
"Sprintf",... | // private webpage, authentication required | [
"private",
"webpage",
"authentication",
"required"
] | d0051b5cc53874ee5e0b2223e57c0e35d18029a8 | https://github.com/bradrydzewski/go.auth/blob/d0051b5cc53874ee5e0b2223e57c0e35d18029a8/examples/openid/openid_demo.go#L34-L37 |
145,553 | bradrydzewski/go.auth | examples/openid/openid_demo.go | Public | func Public(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, homepage)
} | go | func Public(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, homepage)
} | [
"func",
"Public",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"fmt",
".",
"Fprintf",
"(",
"w",
",",
"homepage",
")",
"\n",
"}"
] | // public webpage, no authentication required | [
"public",
"webpage",
"no",
"authentication",
"required"
] | d0051b5cc53874ee5e0b2223e57c0e35d18029a8 | https://github.com/bradrydzewski/go.auth/blob/d0051b5cc53874ee5e0b2223e57c0e35d18029a8/examples/openid/openid_demo.go#L40-L42 |
145,554 | bradrydzewski/go.auth | oauth1.go | Redirect | func (self *OAuth1Mixin) Redirect(w http.ResponseWriter, r *http.Request) {
if err := self.AuthorizeRedirect(w, r, self.Consumer.AuthorizationURL); err != nil {
println("Error redirecting to authorization endpoint: " + err.Error())
}
} | go | func (self *OAuth1Mixin) Redirect(w http.ResponseWriter, r *http.Request) {
if err := self.AuthorizeRedirect(w, r, self.Consumer.AuthorizationURL); err != nil {
println("Error redirecting to authorization endpoint: " + err.Error())
}
} | [
"func",
"(",
"self",
"*",
"OAuth1Mixin",
")",
"Redirect",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"if",
"err",
":=",
"self",
".",
"AuthorizeRedirect",
"(",
"w",
",",
"r",
",",
"self",
".",
"Consumer",... | // Redirect will do an http.Redirect, sending the user to the Provider's
// login screen. | [
"Redirect",
"will",
"do",
"an",
"http",
".",
"Redirect",
"sending",
"the",
"user",
"to",
"the",
"Provider",
"s",
"login",
"screen",
"."
] | d0051b5cc53874ee5e0b2223e57c0e35d18029a8 | https://github.com/bradrydzewski/go.auth/blob/d0051b5cc53874ee5e0b2223e57c0e35d18029a8/oauth1.go#L19-L23 |
145,555 | bradrydzewski/go.auth | oauth1.go | RedirectRequired | func (self *OAuth1Mixin) RedirectRequired(r *http.Request) bool {
return r.URL.Query().Get("oauth_verifier") == ""
} | go | func (self *OAuth1Mixin) RedirectRequired(r *http.Request) bool {
return r.URL.Query().Get("oauth_verifier") == ""
} | [
"func",
"(",
"self",
"*",
"OAuth1Mixin",
")",
"RedirectRequired",
"(",
"r",
"*",
"http",
".",
"Request",
")",
"bool",
"{",
"return",
"r",
".",
"URL",
".",
"Query",
"(",
")",
".",
"Get",
"(",
"\"",
"\"",
")",
"==",
"\"",
"\"",
"\n",
"}"
] | // RedirectRequired returns a boolean value indicating if the request should
// be redirected to the Provider's login screen, in order to provide an OAuth
// Verifier Token. | [
"RedirectRequired",
"returns",
"a",
"boolean",
"value",
"indicating",
"if",
"the",
"request",
"should",
"be",
"redirected",
"to",
"the",
"Provider",
"s",
"login",
"screen",
"in",
"order",
"to",
"provide",
"an",
"OAuth",
"Verifier",
"Token",
"."
] | d0051b5cc53874ee5e0b2223e57c0e35d18029a8 | https://github.com/bradrydzewski/go.auth/blob/d0051b5cc53874ee5e0b2223e57c0e35d18029a8/oauth1.go#L28-L30 |
145,556 | bradrydzewski/go.auth | examples/multiple/multiple_demo.go | MultiLogin | func MultiLogin(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, loginPage)
} | go | func MultiLogin(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, loginPage)
} | [
"func",
"MultiLogin",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"fmt",
".",
"Fprintf",
"(",
"w",
",",
"loginPage",
")",
"\n",
"}"
] | // page to choose auth provider | [
"page",
"to",
"choose",
"auth",
"provider"
] | d0051b5cc53874ee5e0b2223e57c0e35d18029a8 | https://github.com/bradrydzewski/go.auth/blob/d0051b5cc53874ee5e0b2223e57c0e35d18029a8/examples/multiple/multiple_demo.go#L58-L60 |
145,557 | bradrydzewski/go.auth | oauth1/token.go | NewAccessToken | func NewAccessToken(token, secret string, params map[string]string) *AccessToken {
return &AccessToken {
token : token,
secret : secret,
params : params,
}
} | go | func NewAccessToken(token, secret string, params map[string]string) *AccessToken {
return &AccessToken {
token : token,
secret : secret,
params : params,
}
} | [
"func",
"NewAccessToken",
"(",
"token",
",",
"secret",
"string",
",",
"params",
"map",
"[",
"string",
"]",
"string",
")",
"*",
"AccessToken",
"{",
"return",
"&",
"AccessToken",
"{",
"token",
":",
"token",
",",
"secret",
":",
"secret",
",",
"params",
":",... | // NewAccessToken returns a new instance of AccessToken with the specified
// token, secret and additional parameters. | [
"NewAccessToken",
"returns",
"a",
"new",
"instance",
"of",
"AccessToken",
"with",
"the",
"specified",
"token",
"secret",
"and",
"additional",
"parameters",
"."
] | d0051b5cc53874ee5e0b2223e57c0e35d18029a8 | https://github.com/bradrydzewski/go.auth/blob/d0051b5cc53874ee5e0b2223e57c0e35d18029a8/oauth1/token.go#L28-L34 |
145,558 | bradrydzewski/go.auth | oauth1/token.go | ParseAccessToken | func ParseAccessToken(reader io.ReadCloser) (*AccessToken, error) {
body, err := ioutil.ReadAll(reader)
reader.Close()
if err != nil {
return nil, err
}
return ParseAccessTokenStr(string(body))
} | go | func ParseAccessToken(reader io.ReadCloser) (*AccessToken, error) {
body, err := ioutil.ReadAll(reader)
reader.Close()
if err != nil {
return nil, err
}
return ParseAccessTokenStr(string(body))
} | [
"func",
"ParseAccessToken",
"(",
"reader",
"io",
".",
"ReadCloser",
")",
"(",
"*",
"AccessToken",
",",
"error",
")",
"{",
"body",
",",
"err",
":=",
"ioutil",
".",
"ReadAll",
"(",
"reader",
")",
"\n",
"reader",
".",
"Close",
"(",
")",
"\n",
"if",
"err... | // ParseAccessToken parses the URL-encoded query string from the Reader
// and returns an AccessToken. | [
"ParseAccessToken",
"parses",
"the",
"URL",
"-",
"encoded",
"query",
"string",
"from",
"the",
"Reader",
"and",
"returns",
"an",
"AccessToken",
"."
] | d0051b5cc53874ee5e0b2223e57c0e35d18029a8 | https://github.com/bradrydzewski/go.auth/blob/d0051b5cc53874ee5e0b2223e57c0e35d18029a8/oauth1/token.go#L38-L46 |
145,559 | bradrydzewski/go.auth | oauth1/token.go | ParseAccessTokenStr | func ParseAccessTokenStr(str string) (*AccessToken, error) {
token := AccessToken{}
token.params = map[string]string{}
//parse the request token from the body
parts, err := url.ParseQuery(str)
if err != nil {
return nil, err
}
//loop through parts to create Token
for key, val := range parts {
switch key {... | go | func ParseAccessTokenStr(str string) (*AccessToken, error) {
token := AccessToken{}
token.params = map[string]string{}
//parse the request token from the body
parts, err := url.ParseQuery(str)
if err != nil {
return nil, err
}
//loop through parts to create Token
for key, val := range parts {
switch key {... | [
"func",
"ParseAccessTokenStr",
"(",
"str",
"string",
")",
"(",
"*",
"AccessToken",
",",
"error",
")",
"{",
"token",
":=",
"AccessToken",
"{",
"}",
"\n",
"token",
".",
"params",
"=",
"map",
"[",
"string",
"]",
"string",
"{",
"}",
"\n\n",
"//parse the requ... | // ParseAccessTokenStr parses the URL-encoded query string and returns
// an AccessToken. | [
"ParseAccessTokenStr",
"parses",
"the",
"URL",
"-",
"encoded",
"query",
"string",
"and",
"returns",
"an",
"AccessToken",
"."
] | d0051b5cc53874ee5e0b2223e57c0e35d18029a8 | https://github.com/bradrydzewski/go.auth/blob/d0051b5cc53874ee5e0b2223e57c0e35d18029a8/oauth1/token.go#L50-L76 |
145,560 | bradrydzewski/go.auth | oauth1/token.go | ParseRequestToken | func ParseRequestToken(reader io.ReadCloser) (*RequestToken, error) {
body, err := ioutil.ReadAll(reader)
reader.Close()
if err != nil {
return nil, err
}
return ParseRequestTokenStr(string(body))
} | go | func ParseRequestToken(reader io.ReadCloser) (*RequestToken, error) {
body, err := ioutil.ReadAll(reader)
reader.Close()
if err != nil {
return nil, err
}
return ParseRequestTokenStr(string(body))
} | [
"func",
"ParseRequestToken",
"(",
"reader",
"io",
".",
"ReadCloser",
")",
"(",
"*",
"RequestToken",
",",
"error",
")",
"{",
"body",
",",
"err",
":=",
"ioutil",
".",
"ReadAll",
"(",
"reader",
")",
"\n",
"reader",
".",
"Close",
"(",
")",
"\n",
"if",
"e... | // ParseRequestToken parses the URL-encoded query string from the Reader
// and returns a RequestToken. | [
"ParseRequestToken",
"parses",
"the",
"URL",
"-",
"encoded",
"query",
"string",
"from",
"the",
"Reader",
"and",
"returns",
"a",
"RequestToken",
"."
] | d0051b5cc53874ee5e0b2223e57c0e35d18029a8 | https://github.com/bradrydzewski/go.auth/blob/d0051b5cc53874ee5e0b2223e57c0e35d18029a8/oauth1/token.go#L112-L120 |
145,561 | bradrydzewski/go.auth | oauth1/token.go | ParseRequestTokenStr | func ParseRequestTokenStr(str string) (*RequestToken, error) {
//parse the request token from the body
parts, err := url.ParseQuery(str)
if err != nil {
return nil, err
}
token := RequestToken{}
token.token = parts.Get("oauth_token")
token.secret = parts.Get("oauth_token_secret")
token.callbackConfirmed = p... | go | func ParseRequestTokenStr(str string) (*RequestToken, error) {
//parse the request token from the body
parts, err := url.ParseQuery(str)
if err != nil {
return nil, err
}
token := RequestToken{}
token.token = parts.Get("oauth_token")
token.secret = parts.Get("oauth_token_secret")
token.callbackConfirmed = p... | [
"func",
"ParseRequestTokenStr",
"(",
"str",
"string",
")",
"(",
"*",
"RequestToken",
",",
"error",
")",
"{",
"//parse the request token from the body",
"parts",
",",
"err",
":=",
"url",
".",
"ParseQuery",
"(",
"str",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",... | // ParseRequestTokenStr parses the URL-encoded query string and returns
// a RequestToken. | [
"ParseRequestTokenStr",
"parses",
"the",
"URL",
"-",
"encoded",
"query",
"string",
"and",
"returns",
"a",
"RequestToken",
"."
] | d0051b5cc53874ee5e0b2223e57c0e35d18029a8 | https://github.com/bradrydzewski/go.auth/blob/d0051b5cc53874ee5e0b2223e57c0e35d18029a8/oauth1/token.go#L124-L143 |
145,562 | bradrydzewski/go.auth | openid.go | Redirect | func (self *OpenIdProvider) Redirect(w http.ResponseWriter, r *http.Request) {
// create the url params
var params = make(url.Values)
// construct the Redirect URL with default OpenId params
for key, val := range openIdParams {
params.Add(key, val)
}
// append the real and return_to parameters
// they will ... | go | func (self *OpenIdProvider) Redirect(w http.ResponseWriter, r *http.Request) {
// create the url params
var params = make(url.Values)
// construct the Redirect URL with default OpenId params
for key, val := range openIdParams {
params.Add(key, val)
}
// append the real and return_to parameters
// they will ... | [
"func",
"(",
"self",
"*",
"OpenIdProvider",
")",
"Redirect",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"// create the url params",
"var",
"params",
"=",
"make",
"(",
"url",
".",
"Values",
")",
"\n\n",
"// c... | // Redirect will send the user to the OpenId Authentication URL | [
"Redirect",
"will",
"send",
"the",
"user",
"to",
"the",
"OpenId",
"Authentication",
"URL"
] | d0051b5cc53874ee5e0b2223e57c0e35d18029a8 | https://github.com/bradrydzewski/go.auth/blob/d0051b5cc53874ee5e0b2223e57c0e35d18029a8/openid.go#L49-L71 |
145,563 | bradrydzewski/go.auth | openid.go | GetAuthenticatedUser | func (self *OpenIdProvider) GetAuthenticatedUser(w http.ResponseWriter, r *http.Request) (User, Token, error) {
// Parse the url parameters
params := r.URL.Query()
// Check to see if the user successfully authenticated
if params.Get("openid.mode") == "cancel" {
return nil, nil, ErrAuthDeclined
}
// Get the u... | go | func (self *OpenIdProvider) GetAuthenticatedUser(w http.ResponseWriter, r *http.Request) (User, Token, error) {
// Parse the url parameters
params := r.URL.Query()
// Check to see if the user successfully authenticated
if params.Get("openid.mode") == "cancel" {
return nil, nil, ErrAuthDeclined
}
// Get the u... | [
"func",
"(",
"self",
"*",
"OpenIdProvider",
")",
"GetAuthenticatedUser",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"(",
"User",
",",
"Token",
",",
"error",
")",
"{",
"// Parse the url parameters",
"params",
":=",
... | // GetAuthenticatedUser will retrieve the User information from the URL
// query parameters, per the OpenID specification. If the authentication failed,
// the function will return an error. | [
"GetAuthenticatedUser",
"will",
"retrieve",
"the",
"User",
"information",
"from",
"the",
"URL",
"query",
"parameters",
"per",
"the",
"OpenID",
"specification",
".",
"If",
"the",
"authentication",
"failed",
"the",
"function",
"will",
"return",
"an",
"error",
"."
] | d0051b5cc53874ee5e0b2223e57c0e35d18029a8 | https://github.com/bradrydzewski/go.auth/blob/d0051b5cc53874ee5e0b2223e57c0e35d18029a8/openid.go#L76-L96 |
145,564 | bradrydzewski/go.auth | examples/github/github_demo.go | Private2 | func Private2(w http.ResponseWriter, r *http.Request, user auth.User) {
page := fmt.Sprintf(privatepage2, user.Picture(), user.Id(), user.Name())
fmt.Fprintf(w, page)
} | go | func Private2(w http.ResponseWriter, r *http.Request, user auth.User) {
page := fmt.Sprintf(privatepage2, user.Picture(), user.Id(), user.Name())
fmt.Fprintf(w, page)
} | [
"func",
"Private2",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
",",
"user",
"auth",
".",
"User",
")",
"{",
"page",
":=",
"fmt",
".",
"Sprintf",
"(",
"privatepage2",
",",
"user",
".",
"Picture",
"(",
")",
",",
"u... | // private webpage, authentication required, with User struct passed directly
// into the function | [
"private",
"webpage",
"authentication",
"required",
"with",
"User",
"struct",
"passed",
"directly",
"into",
"the",
"function"
] | d0051b5cc53874ee5e0b2223e57c0e35d18029a8 | https://github.com/bradrydzewski/go.auth/blob/d0051b5cc53874ee5e0b2223e57c0e35d18029a8/examples/github/github_demo.go#L56-L59 |
145,565 | bradrydzewski/go.auth | bitbucket.go | NewBitbucketProvider | func NewBitbucketProvider(key, secret, callback string) *BitbucketProvider {
bb := BitbucketProvider{}
//bb.AuthorizationURL = "https://bitbucket.org/!api/1.0/oauth/authenticate"
//bb.RequestTokenURL = "https://bitbucket.org/api/1.0/oauth/request_token/"
//bb.AccessTokenURL = "https://bitbucket.org/api/1.0/oauth/ac... | go | func NewBitbucketProvider(key, secret, callback string) *BitbucketProvider {
bb := BitbucketProvider{}
//bb.AuthorizationURL = "https://bitbucket.org/!api/1.0/oauth/authenticate"
//bb.RequestTokenURL = "https://bitbucket.org/api/1.0/oauth/request_token/"
//bb.AccessTokenURL = "https://bitbucket.org/api/1.0/oauth/ac... | [
"func",
"NewBitbucketProvider",
"(",
"key",
",",
"secret",
",",
"callback",
"string",
")",
"*",
"BitbucketProvider",
"{",
"bb",
":=",
"BitbucketProvider",
"{",
"}",
"\n",
"//bb.AuthorizationURL = \"https://bitbucket.org/!api/1.0/oauth/authenticate\"",
"//bb.RequestTokenURL = ... | // NewBitbucketProvider allocates and returns a new BitbucketProvider. | [
"NewBitbucketProvider",
"allocates",
"and",
"returns",
"a",
"new",
"BitbucketProvider",
"."
] | d0051b5cc53874ee5e0b2223e57c0e35d18029a8 | https://github.com/bradrydzewski/go.auth/blob/d0051b5cc53874ee5e0b2223e57c0e35d18029a8/bitbucket.go#L30-L43 |
145,566 | bradrydzewski/go.auth | bitbucket.go | GetAuthenticatedUser | func (self *BitbucketProvider) GetAuthenticatedUser(w http.ResponseWriter, r *http.Request) (User, Token, error) {
// upgrade the oauth_token to an access token
token, err := self.OAuth1Mixin.AuthorizeToken(w, r)
if err != nil {
return nil, nil, err
}
// bitbuckets user object comes wrapped in a composite obje... | go | func (self *BitbucketProvider) GetAuthenticatedUser(w http.ResponseWriter, r *http.Request) (User, Token, error) {
// upgrade the oauth_token to an access token
token, err := self.OAuth1Mixin.AuthorizeToken(w, r)
if err != nil {
return nil, nil, err
}
// bitbuckets user object comes wrapped in a composite obje... | [
"func",
"(",
"self",
"*",
"BitbucketProvider",
")",
"GetAuthenticatedUser",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"(",
"User",
",",
"Token",
",",
"error",
")",
"{",
"// upgrade the oauth_token to an access token",
... | // GetAuthenticatedUser will upgrade the oauth_token to an access token, and
// invoke the appropriate Bitbucket REST API call to get the User's information. | [
"GetAuthenticatedUser",
"will",
"upgrade",
"the",
"oauth_token",
"to",
"an",
"access",
"token",
"and",
"invoke",
"the",
"appropriate",
"Bitbucket",
"REST",
"API",
"call",
"to",
"get",
"the",
"User",
"s",
"information",
"."
] | d0051b5cc53874ee5e0b2223e57c0e35d18029a8 | https://github.com/bradrydzewski/go.auth/blob/d0051b5cc53874ee5e0b2223e57c0e35d18029a8/bitbucket.go#L47-L71 |
145,567 | bradrydzewski/go.auth | auth.go | Google | func Google(client, secret, redirect string) *AuthHandler {
return New(NewGoogleProvider(client, secret, redirect))
} | go | func Google(client, secret, redirect string) *AuthHandler {
return New(NewGoogleProvider(client, secret, redirect))
} | [
"func",
"Google",
"(",
"client",
",",
"secret",
",",
"redirect",
"string",
")",
"*",
"AuthHandler",
"{",
"return",
"New",
"(",
"NewGoogleProvider",
"(",
"client",
",",
"secret",
",",
"redirect",
")",
")",
"\n",
"}"
] | // Google allocates and returns a new AuthHandler, using the GoogleProvider. | [
"Google",
"allocates",
"and",
"returns",
"a",
"new",
"AuthHandler",
"using",
"the",
"GoogleProvider",
"."
] | d0051b5cc53874ee5e0b2223e57c0e35d18029a8 | https://github.com/bradrydzewski/go.auth/blob/d0051b5cc53874ee5e0b2223e57c0e35d18029a8/auth.go#L31-L33 |
145,568 | bradrydzewski/go.auth | auth.go | Github | func Github(client, secret, scope string) *AuthHandler {
return New(NewGithubProvider(client, secret, scope))
} | go | func Github(client, secret, scope string) *AuthHandler {
return New(NewGithubProvider(client, secret, scope))
} | [
"func",
"Github",
"(",
"client",
",",
"secret",
",",
"scope",
"string",
")",
"*",
"AuthHandler",
"{",
"return",
"New",
"(",
"NewGithubProvider",
"(",
"client",
",",
"secret",
",",
"scope",
")",
")",
"\n",
"}"
] | // Github allocates and returns a new AuthHandler, using the GithubProvider. | [
"Github",
"allocates",
"and",
"returns",
"a",
"new",
"AuthHandler",
"using",
"the",
"GithubProvider",
"."
] | d0051b5cc53874ee5e0b2223e57c0e35d18029a8 | https://github.com/bradrydzewski/go.auth/blob/d0051b5cc53874ee5e0b2223e57c0e35d18029a8/auth.go#L36-L38 |
145,569 | bradrydzewski/go.auth | auth.go | Bitbucket | func Bitbucket(key, secret, callback string) *AuthHandler {
return New(NewBitbucketProvider(key, secret, callback))
} | go | func Bitbucket(key, secret, callback string) *AuthHandler {
return New(NewBitbucketProvider(key, secret, callback))
} | [
"func",
"Bitbucket",
"(",
"key",
",",
"secret",
",",
"callback",
"string",
")",
"*",
"AuthHandler",
"{",
"return",
"New",
"(",
"NewBitbucketProvider",
"(",
"key",
",",
"secret",
",",
"callback",
")",
")",
"\n",
"}"
] | // Bitbucket allocates and returns a new AuthHandler, using the BitbucketProvider. | [
"Bitbucket",
"allocates",
"and",
"returns",
"a",
"new",
"AuthHandler",
"using",
"the",
"BitbucketProvider",
"."
] | d0051b5cc53874ee5e0b2223e57c0e35d18029a8 | https://github.com/bradrydzewski/go.auth/blob/d0051b5cc53874ee5e0b2223e57c0e35d18029a8/auth.go#L46-L48 |
145,570 | bradrydzewski/go.auth | auth.go | Twitter | func Twitter(key, secret, callback string) *AuthHandler {
return New(NewTwitterProvider(key, secret, callback))
} | go | func Twitter(key, secret, callback string) *AuthHandler {
return New(NewTwitterProvider(key, secret, callback))
} | [
"func",
"Twitter",
"(",
"key",
",",
"secret",
",",
"callback",
"string",
")",
"*",
"AuthHandler",
"{",
"return",
"New",
"(",
"NewTwitterProvider",
"(",
"key",
",",
"secret",
",",
"callback",
")",
")",
"\n",
"}"
] | // Twitter allocates and returns a new AuthHandler, using the TwitterProvider. | [
"Twitter",
"allocates",
"and",
"returns",
"a",
"new",
"AuthHandler",
"using",
"the",
"TwitterProvider",
"."
] | d0051b5cc53874ee5e0b2223e57c0e35d18029a8 | https://github.com/bradrydzewski/go.auth/blob/d0051b5cc53874ee5e0b2223e57c0e35d18029a8/auth.go#L51-L53 |
145,571 | bradrydzewski/go.auth | auth.go | ServeHTTP | func (self *AuthHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
// Redirect the user, if required
if self.provider.RedirectRequired(r) == true {
self.provider.Redirect(w, r)
return
}
// Get the authenticated user Id
u, t, err := self.provider.GetAuthenticatedUser(w, r)
if err != nil {
// If t... | go | func (self *AuthHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
// Redirect the user, if required
if self.provider.RedirectRequired(r) == true {
self.provider.Redirect(w, r)
return
}
// Get the authenticated user Id
u, t, err := self.provider.GetAuthenticatedUser(w, r)
if err != nil {
// If t... | [
"func",
"(",
"self",
"*",
"AuthHandler",
")",
"ServeHTTP",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"// Redirect the user, if required",
"if",
"self",
".",
"provider",
".",
"RedirectRequired",
"(",
"r",
")",
... | // ServeHTTP handles the authentication request and manages the
// authentication flow. | [
"ServeHTTP",
"handles",
"the",
"authentication",
"request",
"and",
"manages",
"the",
"authentication",
"flow",
"."
] | d0051b5cc53874ee5e0b2223e57c0e35d18029a8 | https://github.com/bradrydzewski/go.auth/blob/d0051b5cc53874ee5e0b2223e57c0e35d18029a8/auth.go#L57-L83 |
145,572 | bradrydzewski/go.auth | auth.go | SecureFunc | func SecureFunc(handler http.HandlerFunc) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
user, err := GetUserCookie(r)
//if no active user session then authorize user
if err != nil || user.Id() == "" {
http.Redirect(w, r, Config.LoginRedirect, http.StatusSeeOther)
return
}
/... | go | func SecureFunc(handler http.HandlerFunc) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
user, err := GetUserCookie(r)
//if no active user session then authorize user
if err != nil || user.Id() == "" {
http.Redirect(w, r, Config.LoginRedirect, http.StatusSeeOther)
return
}
/... | [
"func",
"SecureFunc",
"(",
"handler",
"http",
".",
"HandlerFunc",
")",
"http",
".",
"HandlerFunc",
"{",
"return",
"func",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"user",
",",
"err",
":=",
"GetUserCookie",... | // SecureFunc will attempt to verify a user session exists prior to executing
// the http.HandlerFunc. If no valid sessions exists, the user will be
// redirected to the Config.LoginRedirect Url. | [
"SecureFunc",
"will",
"attempt",
"to",
"verify",
"a",
"user",
"session",
"exists",
"prior",
"to",
"executing",
"the",
"http",
".",
"HandlerFunc",
".",
"If",
"no",
"valid",
"sessions",
"exists",
"the",
"user",
"will",
"be",
"redirected",
"to",
"the",
"Config"... | d0051b5cc53874ee5e0b2223e57c0e35d18029a8 | https://github.com/bradrydzewski/go.auth/blob/d0051b5cc53874ee5e0b2223e57c0e35d18029a8/auth.go#L183-L197 |
145,573 | bradrydzewski/go.auth | auth.go | SecureUser | func SecureUser(handler SecureHandlerFunc) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
user, err := GetUserCookie(r)
//if no active user session then authorize user
if err != nil || user.Id() == "" {
http.Redirect(w, r, Config.LoginRedirect, http.StatusSeeOther)
return
}
... | go | func SecureUser(handler SecureHandlerFunc) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
user, err := GetUserCookie(r)
//if no active user session then authorize user
if err != nil || user.Id() == "" {
http.Redirect(w, r, Config.LoginRedirect, http.StatusSeeOther)
return
}
... | [
"func",
"SecureUser",
"(",
"handler",
"SecureHandlerFunc",
")",
"http",
".",
"HandlerFunc",
"{",
"return",
"func",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"user",
",",
"err",
":=",
"GetUserCookie",
"(",
"... | // SecureUser will attempt to verify a user session exists prior to
// executing the auth.SecureHandlerFunc function. If no valid sessions exists,
// the user will be redirected to a login URL. | [
"SecureUser",
"will",
"attempt",
"to",
"verify",
"a",
"user",
"session",
"exists",
"prior",
"to",
"executing",
"the",
"auth",
".",
"SecureHandlerFunc",
"function",
".",
"If",
"no",
"valid",
"sessions",
"exists",
"the",
"user",
"will",
"be",
"redirected",
"to",... | d0051b5cc53874ee5e0b2223e57c0e35d18029a8 | https://github.com/bradrydzewski/go.auth/blob/d0051b5cc53874ee5e0b2223e57c0e35d18029a8/auth.go#L206-L219 |
145,574 | bradrydzewski/go.auth | auth.go | SecureGuest | func SecureGuest(handler SecureHandlerFunc) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
user, err := GetUserCookie(r)
//if no active user session then authorize user
if err != nil || user.Id() == "" {
handler(w, r, nil)
return
}
//else, invoke the handler and provide the ... | go | func SecureGuest(handler SecureHandlerFunc) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
user, err := GetUserCookie(r)
//if no active user session then authorize user
if err != nil || user.Id() == "" {
handler(w, r, nil)
return
}
//else, invoke the handler and provide the ... | [
"func",
"SecureGuest",
"(",
"handler",
"SecureHandlerFunc",
")",
"http",
".",
"HandlerFunc",
"{",
"return",
"func",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"user",
",",
"err",
":=",
"GetUserCookie",
"(",
... | // SecureGuest will attempt to retireve authenticated User details from
// the current session when invoking the auth.SecureHandlerFunc function. If no
// User details are found the handler will allow the user to proceed as a guest,
// which means the User details will be nil.
//
// This function is intended for pages... | [
"SecureGuest",
"will",
"attempt",
"to",
"retireve",
"authenticated",
"User",
"details",
"from",
"the",
"current",
"session",
"when",
"invoking",
"the",
"auth",
".",
"SecureHandlerFunc",
"function",
".",
"If",
"no",
"User",
"details",
"are",
"found",
"the",
"hand... | d0051b5cc53874ee5e0b2223e57c0e35d18029a8 | https://github.com/bradrydzewski/go.auth/blob/d0051b5cc53874ee5e0b2223e57c0e35d18029a8/auth.go#L228-L241 |
145,575 | bradrydzewski/go.auth | oauth2_github.go | NewGithubProvider | func NewGithubProvider(clientId, clientSecret, scope string) *GithubProvider {
github := GithubProvider{}
github.AuthorizationURL = "https://github.com/login/oauth/authorize"
github.AccessTokenURL = "https://github.com/login/oauth/access_token"
github.ClientId = clientId
github.ClientSecret = clientS... | go | func NewGithubProvider(clientId, clientSecret, scope string) *GithubProvider {
github := GithubProvider{}
github.AuthorizationURL = "https://github.com/login/oauth/authorize"
github.AccessTokenURL = "https://github.com/login/oauth/access_token"
github.ClientId = clientId
github.ClientSecret = clientS... | [
"func",
"NewGithubProvider",
"(",
"clientId",
",",
"clientSecret",
",",
"scope",
"string",
")",
"*",
"GithubProvider",
"{",
"github",
":=",
"GithubProvider",
"{",
"}",
"\n",
"github",
".",
"AuthorizationURL",
"=",
"\"",
"\"",
"\n",
"github",
".",
"AccessTokenU... | // NewGithubProvider allocates and returns a new GithubProvider. | [
"NewGithubProvider",
"allocates",
"and",
"returns",
"a",
"new",
"GithubProvider",
"."
] | d0051b5cc53874ee5e0b2223e57c0e35d18029a8 | https://github.com/bradrydzewski/go.auth/blob/d0051b5cc53874ee5e0b2223e57c0e35d18029a8/oauth2_github.go#L59-L72 |
145,576 | bradrydzewski/go.auth | oauth2_github.go | Redirect | func (self *GithubProvider) Redirect(w http.ResponseWriter, r *http.Request) {
self.OAuth2Mixin.AuthorizeRedirect(w, r, self.Scope)
} | go | func (self *GithubProvider) Redirect(w http.ResponseWriter, r *http.Request) {
self.OAuth2Mixin.AuthorizeRedirect(w, r, self.Scope)
} | [
"func",
"(",
"self",
"*",
"GithubProvider",
")",
"Redirect",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"self",
".",
"OAuth2Mixin",
".",
"AuthorizeRedirect",
"(",
"w",
",",
"r",
",",
"self",
".",
"Scope",
... | // Redirect will do an http.Redirect, sending the user to the Github login
// screen. | [
"Redirect",
"will",
"do",
"an",
"http",
".",
"Redirect",
"sending",
"the",
"user",
"to",
"the",
"Github",
"login",
"screen",
"."
] | d0051b5cc53874ee5e0b2223e57c0e35d18029a8 | https://github.com/bradrydzewski/go.auth/blob/d0051b5cc53874ee5e0b2223e57c0e35d18029a8/oauth2_github.go#L76-L78 |
145,577 | go-humble/router | router.go | newRoute | func newRoute(path string, handler Handler) *route {
route := &route{
handler: handler,
}
strs := strings.Split(path, "/")
strs = removeEmptyStrings(strs)
pattern := `^`
for _, str := range strs {
if str[0] == '{' && str[len(str)-1] == '}' {
pattern += `/`
pattern += `([^/]*)`
route.paramNames = appe... | go | func newRoute(path string, handler Handler) *route {
route := &route{
handler: handler,
}
strs := strings.Split(path, "/")
strs = removeEmptyStrings(strs)
pattern := `^`
for _, str := range strs {
if str[0] == '{' && str[len(str)-1] == '}' {
pattern += `/`
pattern += `([^/]*)`
route.paramNames = appe... | [
"func",
"newRoute",
"(",
"path",
"string",
",",
"handler",
"Handler",
")",
"*",
"route",
"{",
"route",
":=",
"&",
"route",
"{",
"handler",
":",
"handler",
",",
"}",
"\n",
"strs",
":=",
"strings",
".",
"Split",
"(",
"path",
",",
"\"",
"\"",
")",
"\n... | // newRoute returns a route with the given arguments. paramNames and regex
// are calculated from the path | [
"newRoute",
"returns",
"a",
"route",
"with",
"the",
"given",
"arguments",
".",
"paramNames",
"and",
"regex",
"are",
"calculated",
"from",
"the",
"path"
] | 79b5b8fa588a29a5e5dfccf0f3aa795feb6768a0 | https://github.com/go-humble/router/blob/79b5b8fa588a29a5e5dfccf0f3aa795feb6768a0/router.go#L118-L138 |
145,578 | go-humble/router | router.go | Start | func (r *Router) Start() {
if browserSupportsPushState && !r.ForceHashURL {
r.pathChanged(getPath(), true)
r.watchHistory()
} else {
r.setInitialHash()
r.watchHash()
}
if r.ShouldInterceptLinks {
r.InterceptLinks()
}
} | go | func (r *Router) Start() {
if browserSupportsPushState && !r.ForceHashURL {
r.pathChanged(getPath(), true)
r.watchHistory()
} else {
r.setInitialHash()
r.watchHash()
}
if r.ShouldInterceptLinks {
r.InterceptLinks()
}
} | [
"func",
"(",
"r",
"*",
"Router",
")",
"Start",
"(",
")",
"{",
"if",
"browserSupportsPushState",
"&&",
"!",
"r",
".",
"ForceHashURL",
"{",
"r",
".",
"pathChanged",
"(",
"getPath",
"(",
")",
",",
"true",
")",
"\n",
"r",
".",
"watchHistory",
"(",
")",
... | // Start causes the router to listen for changes to window.location and
// trigger the appropriate handler whenever there is a change. | [
"Start",
"causes",
"the",
"router",
"to",
"listen",
"for",
"changes",
"to",
"window",
".",
"location",
"and",
"trigger",
"the",
"appropriate",
"handler",
"whenever",
"there",
"is",
"a",
"change",
"."
] | 79b5b8fa588a29a5e5dfccf0f3aa795feb6768a0 | https://github.com/go-humble/router/blob/79b5b8fa588a29a5e5dfccf0f3aa795feb6768a0/router.go#L142-L153 |
145,579 | go-humble/router | router.go | Stop | func (r *Router) Stop() {
if browserSupportsPushState && !r.ForceHashURL {
js.Global.Set("onpopstate", nil)
} else {
js.Global.Set("onhashchange", nil)
}
} | go | func (r *Router) Stop() {
if browserSupportsPushState && !r.ForceHashURL {
js.Global.Set("onpopstate", nil)
} else {
js.Global.Set("onhashchange", nil)
}
} | [
"func",
"(",
"r",
"*",
"Router",
")",
"Stop",
"(",
")",
"{",
"if",
"browserSupportsPushState",
"&&",
"!",
"r",
".",
"ForceHashURL",
"{",
"js",
".",
"Global",
".",
"Set",
"(",
"\"",
"\"",
",",
"nil",
")",
"\n",
"}",
"else",
"{",
"js",
".",
"Global... | // Stop causes the router to stop listening for changes, and therefore
// the router will not trigger any more router.Handler functions. | [
"Stop",
"causes",
"the",
"router",
"to",
"stop",
"listening",
"for",
"changes",
"and",
"therefore",
"the",
"router",
"will",
"not",
"trigger",
"any",
"more",
"router",
".",
"Handler",
"functions",
"."
] | 79b5b8fa588a29a5e5dfccf0f3aa795feb6768a0 | https://github.com/go-humble/router/blob/79b5b8fa588a29a5e5dfccf0f3aa795feb6768a0/router.go#L157-L163 |
145,580 | go-humble/router | router.go | Navigate | func (r *Router) Navigate(path string) {
if browserSupportsPushState && !r.ForceHashURL {
pushState(path)
r.pathChanged(path, false)
} else {
setHash(path)
}
if r.ShouldInterceptLinks {
r.InterceptLinks()
}
} | go | func (r *Router) Navigate(path string) {
if browserSupportsPushState && !r.ForceHashURL {
pushState(path)
r.pathChanged(path, false)
} else {
setHash(path)
}
if r.ShouldInterceptLinks {
r.InterceptLinks()
}
} | [
"func",
"(",
"r",
"*",
"Router",
")",
"Navigate",
"(",
"path",
"string",
")",
"{",
"if",
"browserSupportsPushState",
"&&",
"!",
"r",
".",
"ForceHashURL",
"{",
"pushState",
"(",
"path",
")",
"\n",
"r",
".",
"pathChanged",
"(",
"path",
",",
"false",
")",... | // Navigate will trigger the handler associated with the given path
// and update window.location accordingly. If the browser supports
// history.pushState, that will be used. Otherwise, Navigate will
// set the hash component of window.location to the given path. | [
"Navigate",
"will",
"trigger",
"the",
"handler",
"associated",
"with",
"the",
"given",
"path",
"and",
"update",
"window",
".",
"location",
"accordingly",
".",
"If",
"the",
"browser",
"supports",
"history",
".",
"pushState",
"that",
"will",
"be",
"used",
".",
... | 79b5b8fa588a29a5e5dfccf0f3aa795feb6768a0 | https://github.com/go-humble/router/blob/79b5b8fa588a29a5e5dfccf0f3aa795feb6768a0/router.go#L169-L179 |
145,581 | go-humble/router | router.go | CanNavigate | func (r *Router) CanNavigate(path string) bool {
if bestRoute, _, _ := r.findBestRoute(path); bestRoute != nil {
return true
}
return false
} | go | func (r *Router) CanNavigate(path string) bool {
if bestRoute, _, _ := r.findBestRoute(path); bestRoute != nil {
return true
}
return false
} | [
"func",
"(",
"r",
"*",
"Router",
")",
"CanNavigate",
"(",
"path",
"string",
")",
"bool",
"{",
"if",
"bestRoute",
",",
"_",
",",
"_",
":=",
"r",
".",
"findBestRoute",
"(",
"path",
")",
";",
"bestRoute",
"!=",
"nil",
"{",
"return",
"true",
"\n",
"}",... | // CanNavigate returns true if the specified path can be navigated by the
// router, and false otherwise | [
"CanNavigate",
"returns",
"true",
"if",
"the",
"specified",
"path",
"can",
"be",
"navigated",
"by",
"the",
"router",
"and",
"false",
"otherwise"
] | 79b5b8fa588a29a5e5dfccf0f3aa795feb6768a0 | https://github.com/go-humble/router/blob/79b5b8fa588a29a5e5dfccf0f3aa795feb6768a0/router.go#L183-L188 |
145,582 | go-humble/router | router.go | interceptLink | func (r *Router) interceptLink(event dom.Event) {
path := event.CurrentTarget().GetAttribute("href")
// Only intercept the click event if we have a route which matches
// Otherwise, just do the default.
if bestRoute, _, _ := r.findBestRoute(path); bestRoute != nil {
event.PreventDefault()
go r.Navigate(path)
}... | go | func (r *Router) interceptLink(event dom.Event) {
path := event.CurrentTarget().GetAttribute("href")
// Only intercept the click event if we have a route which matches
// Otherwise, just do the default.
if bestRoute, _, _ := r.findBestRoute(path); bestRoute != nil {
event.PreventDefault()
go r.Navigate(path)
}... | [
"func",
"(",
"r",
"*",
"Router",
")",
"interceptLink",
"(",
"event",
"dom",
".",
"Event",
")",
"{",
"path",
":=",
"event",
".",
"CurrentTarget",
"(",
")",
".",
"GetAttribute",
"(",
"\"",
"\"",
")",
"\n",
"// Only intercept the click event if we have a route wh... | // interceptLink is intended to be used as a callback function. It stops
// the default behavior of event and instead calls r.Navigate, passing through
// the link's href property. | [
"interceptLink",
"is",
"intended",
"to",
"be",
"used",
"as",
"a",
"callback",
"function",
".",
"It",
"stops",
"the",
"default",
"behavior",
"of",
"event",
"and",
"instead",
"calls",
"r",
".",
"Navigate",
"passing",
"through",
"the",
"link",
"s",
"href",
"p... | 79b5b8fa588a29a5e5dfccf0f3aa795feb6768a0 | https://github.com/go-humble/router/blob/79b5b8fa588a29a5e5dfccf0f3aa795feb6768a0/router.go#L241-L249 |
145,583 | go-humble/router | router.go | pathChanged | func (r *Router) pathChanged(path string, initial bool) {
bestRoute, tokens, params := r.findBestRoute(path)
// If no routes match, we throw console error and no handlers are called
if bestRoute == nil {
if r.Verbose {
log.Println("Could not find route to match: " + path)
}
return
}
// Create the context ... | go | func (r *Router) pathChanged(path string, initial bool) {
bestRoute, tokens, params := r.findBestRoute(path)
// If no routes match, we throw console error and no handlers are called
if bestRoute == nil {
if r.Verbose {
log.Println("Could not find route to match: " + path)
}
return
}
// Create the context ... | [
"func",
"(",
"r",
"*",
"Router",
")",
"pathChanged",
"(",
"path",
"string",
",",
"initial",
"bool",
")",
"{",
"bestRoute",
",",
"tokens",
",",
"params",
":=",
"r",
".",
"findBestRoute",
"(",
"path",
")",
"\n",
"// If no routes match, we throw console error and... | // pathChanged should be called whenever the path changes and will trigger
// the appropriate handler. initial should be true iff this is the first
// time the javascript is loaded on the page. | [
"pathChanged",
"should",
"be",
"called",
"whenever",
"the",
"path",
"changes",
"and",
"will",
"trigger",
"the",
"appropriate",
"handler",
".",
"initial",
"should",
"be",
"true",
"iff",
"this",
"is",
"the",
"first",
"time",
"the",
"javascript",
"is",
"loaded",
... | 79b5b8fa588a29a5e5dfccf0f3aa795feb6768a0 | https://github.com/go-humble/router/blob/79b5b8fa588a29a5e5dfccf0f3aa795feb6768a0/router.go#L263-L283 |
145,584 | go-humble/router | router.go | parseQueryPart | func (r Router) parseQueryPart(queryPart string) (params map[string][]string) {
var err error
params, err = url.ParseQuery(queryPart)
if err != nil && r.Verbose {
// the URL spec allows things other than name/value pairs in the query
// part of the URL, so we optionally log a message
log.Printf("Error parsing ... | go | func (r Router) parseQueryPart(queryPart string) (params map[string][]string) {
var err error
params, err = url.ParseQuery(queryPart)
if err != nil && r.Verbose {
// the URL spec allows things other than name/value pairs in the query
// part of the URL, so we optionally log a message
log.Printf("Error parsing ... | [
"func",
"(",
"r",
"Router",
")",
"parseQueryPart",
"(",
"queryPart",
"string",
")",
"(",
"params",
"map",
"[",
"string",
"]",
"[",
"]",
"string",
")",
"{",
"var",
"err",
"error",
"\n",
"params",
",",
"err",
"=",
"url",
".",
"ParseQuery",
"(",
"queryP... | // parseQueryPart extracts query params from the query part of the URL | [
"parseQueryPart",
"extracts",
"query",
"params",
"from",
"the",
"query",
"part",
"of",
"the",
"URL"
] | 79b5b8fa588a29a5e5dfccf0f3aa795feb6768a0 | https://github.com/go-humble/router/blob/79b5b8fa588a29a5e5dfccf0f3aa795feb6768a0/router.go#L312-L321 |
145,585 | go-humble/router | router.go | removeEmptyStrings | func removeEmptyStrings(strings []string) []string {
result := []string{}
for _, s := range strings {
if s != "" {
result = append(result, s)
}
}
return result
} | go | func removeEmptyStrings(strings []string) []string {
result := []string{}
for _, s := range strings {
if s != "" {
result = append(result, s)
}
}
return result
} | [
"func",
"removeEmptyStrings",
"(",
"strings",
"[",
"]",
"string",
")",
"[",
"]",
"string",
"{",
"result",
":=",
"[",
"]",
"string",
"{",
"}",
"\n",
"for",
"_",
",",
"s",
":=",
"range",
"strings",
"{",
"if",
"s",
"!=",
"\"",
"\"",
"{",
"result",
"... | // removeEmptyStrings removes any empty strings from strings | [
"removeEmptyStrings",
"removes",
"any",
"empty",
"strings",
"from",
"strings"
] | 79b5b8fa588a29a5e5dfccf0f3aa795feb6768a0 | https://github.com/go-humble/router/blob/79b5b8fa588a29a5e5dfccf0f3aa795feb6768a0/router.go#L324-L332 |
145,586 | go-humble/router | router.go | watchHash | func (r *Router) watchHash() {
js.Global.Set("onhashchange", func() {
go func() {
path := getPathFromHash(getHash())
r.pathChanged(path, false)
}()
})
} | go | func (r *Router) watchHash() {
js.Global.Set("onhashchange", func() {
go func() {
path := getPathFromHash(getHash())
r.pathChanged(path, false)
}()
})
} | [
"func",
"(",
"r",
"*",
"Router",
")",
"watchHash",
"(",
")",
"{",
"js",
".",
"Global",
".",
"Set",
"(",
"\"",
"\"",
",",
"func",
"(",
")",
"{",
"go",
"func",
"(",
")",
"{",
"path",
":=",
"getPathFromHash",
"(",
"getHash",
"(",
")",
")",
"\n",
... | // watchHash listens to the onhashchange event and calls r.pathChanged when
// it changes | [
"watchHash",
"listens",
"to",
"the",
"onhashchange",
"event",
"and",
"calls",
"r",
".",
"pathChanged",
"when",
"it",
"changes"
] | 79b5b8fa588a29a5e5dfccf0f3aa795feb6768a0 | https://github.com/go-humble/router/blob/79b5b8fa588a29a5e5dfccf0f3aa795feb6768a0/router.go#L336-L343 |
145,587 | go-humble/router | router.go | watchHistory | func (r *Router) watchHistory() {
js.Global.Set("onpopstate", func() {
go func() {
r.pathChanged(getPath(), false)
if r.ShouldInterceptLinks {
r.InterceptLinks()
}
}()
})
} | go | func (r *Router) watchHistory() {
js.Global.Set("onpopstate", func() {
go func() {
r.pathChanged(getPath(), false)
if r.ShouldInterceptLinks {
r.InterceptLinks()
}
}()
})
} | [
"func",
"(",
"r",
"*",
"Router",
")",
"watchHistory",
"(",
")",
"{",
"js",
".",
"Global",
".",
"Set",
"(",
"\"",
"\"",
",",
"func",
"(",
")",
"{",
"go",
"func",
"(",
")",
"{",
"r",
".",
"pathChanged",
"(",
"getPath",
"(",
")",
",",
"false",
"... | // watchHistory listens to the onpopstate event and calls r.pathChanged when
// it changes | [
"watchHistory",
"listens",
"to",
"the",
"onpopstate",
"event",
"and",
"calls",
"r",
".",
"pathChanged",
"when",
"it",
"changes"
] | 79b5b8fa588a29a5e5dfccf0f3aa795feb6768a0 | https://github.com/go-humble/router/blob/79b5b8fa588a29a5e5dfccf0f3aa795feb6768a0/router.go#L347-L356 |
145,588 | GaryBoone/GoStats | stats/regression.go | Update | func (r *Regression) Update(x, y float64) {
r.n++
r.sx += x
r.sy += y
r.sxx += x * x
r.sxy += x * y
r.syy += y * y
} | go | func (r *Regression) Update(x, y float64) {
r.n++
r.sx += x
r.sy += y
r.sxx += x * x
r.sxy += x * y
r.syy += y * y
} | [
"func",
"(",
"r",
"*",
"Regression",
")",
"Update",
"(",
"x",
",",
"y",
"float64",
")",
"{",
"r",
".",
"n",
"++",
"\n",
"r",
".",
"sx",
"+=",
"x",
"\n",
"r",
".",
"sy",
"+=",
"y",
"\n",
"r",
".",
"sxx",
"+=",
"x",
"*",
"x",
"\n",
"r",
"... | //
//
// Incremental Functions
//
//
// Update the stats with a new point. | [
"Incremental",
"Functions",
"Update",
"the",
"stats",
"with",
"a",
"new",
"point",
"."
] | 1993eafbef57be29ee8f5eb9d26a22f20ff3c207 | https://github.com/GaryBoone/GoStats/blob/1993eafbef57be29ee8f5eb9d26a22f20ff3c207/stats/regression.go#L52-L59 |
145,589 | GaryBoone/GoStats | stats/regression.go | UpdateArray | func (r *Regression) UpdateArray(xData, yData []float64) {
if len(xData) != len(yData) {
panic("array lengths differ in UpdateArray()")
}
for i := 0; i < len(xData); i++ {
r.Update(xData[i], yData[i])
}
} | go | func (r *Regression) UpdateArray(xData, yData []float64) {
if len(xData) != len(yData) {
panic("array lengths differ in UpdateArray()")
}
for i := 0; i < len(xData); i++ {
r.Update(xData[i], yData[i])
}
} | [
"func",
"(",
"r",
"*",
"Regression",
")",
"UpdateArray",
"(",
"xData",
",",
"yData",
"[",
"]",
"float64",
")",
"{",
"if",
"len",
"(",
"xData",
")",
"!=",
"len",
"(",
"yData",
")",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"for",
"i",... | // Update the stats with arrays of x and y values. | [
"Update",
"the",
"stats",
"with",
"arrays",
"of",
"x",
"and",
"y",
"values",
"."
] | 1993eafbef57be29ee8f5eb9d26a22f20ff3c207 | https://github.com/GaryBoone/GoStats/blob/1993eafbef57be29ee8f5eb9d26a22f20ff3c207/stats/regression.go#L62-L69 |
145,590 | GaryBoone/GoStats | stats/stats.go | Update | func (d *Stats) Update(x float64) {
if d.n == 0.0 || x < d.min {
d.min = x
}
if d.n == 0.0 || x > d.max {
d.max = x
}
d.sum += x
nMinus1 := d.n
d.n += 1.0
delta := x - d.mean
delta_n := delta / d.n
delta_n2 := delta_n * delta_n
term1 := delta * delta_n * nMinus1
d.mean += delta_n
d.m4 += term1*delta_n2... | go | func (d *Stats) Update(x float64) {
if d.n == 0.0 || x < d.min {
d.min = x
}
if d.n == 0.0 || x > d.max {
d.max = x
}
d.sum += x
nMinus1 := d.n
d.n += 1.0
delta := x - d.mean
delta_n := delta / d.n
delta_n2 := delta_n * delta_n
term1 := delta * delta_n * nMinus1
d.mean += delta_n
d.m4 += term1*delta_n2... | [
"func",
"(",
"d",
"*",
"Stats",
")",
"Update",
"(",
"x",
"float64",
")",
"{",
"if",
"d",
".",
"n",
"==",
"0.0",
"||",
"x",
"<",
"d",
".",
"min",
"{",
"d",
".",
"min",
"=",
"x",
"\n",
"}",
"\n",
"if",
"d",
".",
"n",
"==",
"0.0",
"||",
"x... | //
//
// Incremental Functions
//
//
// Update the stats with the given value. | [
"Incremental",
"Functions",
"Update",
"the",
"stats",
"with",
"the",
"given",
"value",
"."
] | 1993eafbef57be29ee8f5eb9d26a22f20ff3c207 | https://github.com/GaryBoone/GoStats/blob/1993eafbef57be29ee8f5eb9d26a22f20ff3c207/stats/stats.go#L81-L99 |
145,591 | GaryBoone/GoStats | stats/stats.go | UpdateArray | func (d *Stats) UpdateArray(data []float64) {
for _, v := range data {
d.Update(v)
}
} | go | func (d *Stats) UpdateArray(data []float64) {
for _, v := range data {
d.Update(v)
}
} | [
"func",
"(",
"d",
"*",
"Stats",
")",
"UpdateArray",
"(",
"data",
"[",
"]",
"float64",
")",
"{",
"for",
"_",
",",
"v",
":=",
"range",
"data",
"{",
"d",
".",
"Update",
"(",
"v",
")",
"\n",
"}",
"\n",
"}"
] | // Update the stats with the given array of values. | [
"Update",
"the",
"stats",
"with",
"the",
"given",
"array",
"of",
"values",
"."
] | 1993eafbef57be29ee8f5eb9d26a22f20ff3c207 | https://github.com/GaryBoone/GoStats/blob/1993eafbef57be29ee8f5eb9d26a22f20ff3c207/stats/stats.go#L102-L106 |
145,592 | GaryBoone/GoStats | stats/stats.go | StatsPopulationKurtosis | func StatsPopulationKurtosis(data []float64) (kurtosis float64) {
mean := StatsMean(data)
n := float64(len(data))
sum4 := 0.0
for _, v := range data {
delta := v - mean
sum4 += delta * delta * delta * delta
}
variance := StatsPopulationVariance(data)
kurtosis = sum4/(variance*variance)/n - 3.0
return
} | go | func StatsPopulationKurtosis(data []float64) (kurtosis float64) {
mean := StatsMean(data)
n := float64(len(data))
sum4 := 0.0
for _, v := range data {
delta := v - mean
sum4 += delta * delta * delta * delta
}
variance := StatsPopulationVariance(data)
kurtosis = sum4/(variance*variance)/n - 3.0
return
} | [
"func",
"StatsPopulationKurtosis",
"(",
"data",
"[",
"]",
"float64",
")",
"(",
"kurtosis",
"float64",
")",
"{",
"mean",
":=",
"StatsMean",
"(",
"data",
")",
"\n",
"n",
":=",
"float64",
"(",
"len",
"(",
"data",
")",
")",
"\n\n",
"sum4",
":=",
"0.0",
"... | // The kurtosis functions return _excess_ kurtosis | [
"The",
"kurtosis",
"functions",
"return",
"_excess_",
"kurtosis"
] | 1993eafbef57be29ee8f5eb9d26a22f20ff3c207 | https://github.com/GaryBoone/GoStats/blob/1993eafbef57be29ee8f5eb9d26a22f20ff3c207/stats/stats.go#L262-L275 |
145,593 | drone/signal | signal.go | WithContextFunc | func WithContextFunc(ctx context.Context, f func()) context.Context {
ctx, cancel := context.WithCancel(ctx)
go func() {
c := make(chan os.Signal)
signal.Notify(c, syscall.SIGINT, syscall.SIGTERM)
defer signal.Stop(c)
select {
case <-ctx.Done():
case <-c:
f()
cancel()
}
}()
return ctx
} | go | func WithContextFunc(ctx context.Context, f func()) context.Context {
ctx, cancel := context.WithCancel(ctx)
go func() {
c := make(chan os.Signal)
signal.Notify(c, syscall.SIGINT, syscall.SIGTERM)
defer signal.Stop(c)
select {
case <-ctx.Done():
case <-c:
f()
cancel()
}
}()
return ctx
} | [
"func",
"WithContextFunc",
"(",
"ctx",
"context",
".",
"Context",
",",
"f",
"func",
"(",
")",
")",
"context",
".",
"Context",
"{",
"ctx",
",",
"cancel",
":=",
"context",
".",
"WithCancel",
"(",
"ctx",
")",
"\n",
"go",
"func",
"(",
")",
"{",
"c",
":... | // WithContextFunc returns a copy of parent context that is cancelled when
// an os interrupt signal is received. The callback function f is invoked
// before cancellation. | [
"WithContextFunc",
"returns",
"a",
"copy",
"of",
"parent",
"context",
"that",
"is",
"cancelled",
"when",
"an",
"os",
"interrupt",
"signal",
"is",
"received",
".",
"The",
"callback",
"function",
"f",
"is",
"invoked",
"before",
"cancellation",
"."
] | 8e64eaa3eaf106e8702d6622c43fd78de52ec9d2 | https://github.com/drone/signal/blob/8e64eaa3eaf106e8702d6622c43fd78de52ec9d2/signal.go#L22-L38 |
145,594 | codeskyblue/kexec | kexec.go | Wait | func (k *KCommand) Wait() error {
if k.Process == nil {
return errors.New("exec: not started")
}
k.once.Do(func() {
if k.errCs == nil {
k.errCs = make([]chan error, 0)
}
go func() {
k.err = k.Cmd.Wait()
k.mu.Lock()
k.finished = true
for _, errC := range k.errCs {
errC <- k.err... | go | func (k *KCommand) Wait() error {
if k.Process == nil {
return errors.New("exec: not started")
}
k.once.Do(func() {
if k.errCs == nil {
k.errCs = make([]chan error, 0)
}
go func() {
k.err = k.Cmd.Wait()
k.mu.Lock()
k.finished = true
for _, errC := range k.errCs {
errC <- k.err... | [
"func",
"(",
"k",
"*",
"KCommand",
")",
"Wait",
"(",
")",
"error",
"{",
"if",
"k",
".",
"Process",
"==",
"nil",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"k",
".",
"once",
".",
"Do",
"(",
"func",
"(",
")",
... | // This Wait wraps exec.Wait, but support multi call | [
"This",
"Wait",
"wraps",
"exec",
".",
"Wait",
"but",
"support",
"multi",
"call"
] | 5a4bed90d99a42c283dafbc64d94a6a8f372f949 | https://github.com/codeskyblue/kexec/blob/5a4bed90d99a42c283dafbc64d94a6a8f372f949/kexec.go#L27-L54 |
145,595 | codeskyblue/kexec | kexec_windows.go | SetUser | func (k *KCommand) SetUser(name string) (err error) {
log.Printf("Can not set user(%s) on windows", name)
return nil
} | go | func (k *KCommand) SetUser(name string) (err error) {
log.Printf("Can not set user(%s) on windows", name)
return nil
} | [
"func",
"(",
"k",
"*",
"KCommand",
")",
"SetUser",
"(",
"name",
"string",
")",
"(",
"err",
"error",
")",
"{",
"log",
".",
"Printf",
"(",
"\"",
"\"",
",",
"name",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | // SetUser not support on windws | [
"SetUser",
"not",
"support",
"on",
"windws"
] | 5a4bed90d99a42c283dafbc64d94a6a8f372f949 | https://github.com/codeskyblue/kexec/blob/5a4bed90d99a42c283dafbc64d94a6a8f372f949/kexec_windows.go#L37-L40 |
145,596 | wayneashleyberry/terminal-dimensions | terminaldimensions.go | Width | func Width() (uint, error) {
output, err := size()
if err != nil {
return 0, err
}
_, width, err := parse(output)
return width, err
} | go | func Width() (uint, error) {
output, err := size()
if err != nil {
return 0, err
}
_, width, err := parse(output)
return width, err
} | [
"func",
"Width",
"(",
")",
"(",
"uint",
",",
"error",
")",
"{",
"output",
",",
"err",
":=",
"size",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"err",
"\n",
"}",
"\n",
"_",
",",
"width",
",",
"err",
":=",
"parse",
"(",
... | // Width return the width of the terminal. | [
"Width",
"return",
"the",
"width",
"of",
"the",
"terminal",
"."
] | 29d939246793fbd8100dcf74700637adcb839bc5 | https://github.com/wayneashleyberry/terminal-dimensions/blob/29d939246793fbd8100dcf74700637adcb839bc5/terminaldimensions.go#L33-L40 |
145,597 | wayneashleyberry/terminal-dimensions | terminaldimensions.go | Height | func Height() (uint, error) {
output, err := size()
if err != nil {
return 0, err
}
height, _, err := parse(output)
return height, err
} | go | func Height() (uint, error) {
output, err := size()
if err != nil {
return 0, err
}
height, _, err := parse(output)
return height, err
} | [
"func",
"Height",
"(",
")",
"(",
"uint",
",",
"error",
")",
"{",
"output",
",",
"err",
":=",
"size",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"err",
"\n",
"}",
"\n",
"height",
",",
"_",
",",
"err",
":=",
"parse",
"("... | // Height returns the height of the terminal. | [
"Height",
"returns",
"the",
"height",
"of",
"the",
"terminal",
"."
] | 29d939246793fbd8100dcf74700637adcb839bc5 | https://github.com/wayneashleyberry/terminal-dimensions/blob/29d939246793fbd8100dcf74700637adcb839bc5/terminaldimensions.go#L43-L50 |
145,598 | keybase/go-updater | process/process.go | FindProcesses | func FindProcesses(matcher Matcher, wait time.Duration, delay time.Duration, log Log) ([]ps.Process, error) {
breakFn := func(procs []ps.Process) bool {
return len(procs) > 0
}
return findProcesses(matcher, breakFn, wait, delay, log)
} | go | func FindProcesses(matcher Matcher, wait time.Duration, delay time.Duration, log Log) ([]ps.Process, error) {
breakFn := func(procs []ps.Process) bool {
return len(procs) > 0
}
return findProcesses(matcher, breakFn, wait, delay, log)
} | [
"func",
"FindProcesses",
"(",
"matcher",
"Matcher",
",",
"wait",
"time",
".",
"Duration",
",",
"delay",
"time",
".",
"Duration",
",",
"log",
"Log",
")",
"(",
"[",
"]",
"ps",
".",
"Process",
",",
"error",
")",
"{",
"breakFn",
":=",
"func",
"(",
"procs... | // FindProcesses returns processes containing string matching process path | [
"FindProcesses",
"returns",
"processes",
"containing",
"string",
"matching",
"process",
"path"
] | 56ad0c90cf4c65f9f0ab421f09cef15e3b224512 | https://github.com/keybase/go-updater/blob/56ad0c90cf4c65f9f0ab421f09cef15e3b224512/process/process.go#L28-L33 |
145,599 | keybase/go-updater | process/process.go | findProcessWithPID | func findProcessWithPID(pid int) (ps.Process, error) {
matchPID := func(p ps.Process) bool { return p.Pid() == pid }
procs, err := findProcessesWithFn(ps.Processes, matchPID, 1)
if err != nil {
return nil, err
}
if len(procs) == 0 {
return nil, nil
}
return procs[0], nil
} | go | func findProcessWithPID(pid int) (ps.Process, error) {
matchPID := func(p ps.Process) bool { return p.Pid() == pid }
procs, err := findProcessesWithFn(ps.Processes, matchPID, 1)
if err != nil {
return nil, err
}
if len(procs) == 0 {
return nil, nil
}
return procs[0], nil
} | [
"func",
"findProcessWithPID",
"(",
"pid",
"int",
")",
"(",
"ps",
".",
"Process",
",",
"error",
")",
"{",
"matchPID",
":=",
"func",
"(",
"p",
"ps",
".",
"Process",
")",
"bool",
"{",
"return",
"p",
".",
"Pid",
"(",
")",
"==",
"pid",
"}",
"\n",
"pro... | // findProcessWithPID returns a process for a pid.
// Consider using os.FindProcess instead if suitable since this may be
// inefficient. | [
"findProcessWithPID",
"returns",
"a",
"process",
"for",
"a",
"pid",
".",
"Consider",
"using",
"os",
".",
"FindProcess",
"instead",
"if",
"suitable",
"since",
"this",
"may",
"be",
"inefficient",
"."
] | 56ad0c90cf4c65f9f0ab421f09cef15e3b224512 | https://github.com/keybase/go-updater/blob/56ad0c90cf4c65f9f0ab421f09cef15e3b224512/process/process.go#L65-L75 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.