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
124,800
influxdata/influxdb
models/points.go
StringValue
func (p *point) StringValue() string { return unescapeStringField(string(p.it.valueBuf[1 : len(p.it.valueBuf)-1])) }
go
func (p *point) StringValue() string { return unescapeStringField(string(p.it.valueBuf[1 : len(p.it.valueBuf)-1])) }
[ "func", "(", "p", "*", "point", ")", "StringValue", "(", ")", "string", "{", "return", "unescapeStringField", "(", "string", "(", "p", ".", "it", ".", "valueBuf", "[", "1", ":", "len", "(", "p", ".", "it", ".", "valueBuf", ")", "-", "1", "]", ")"...
// StringValue returns the string value of the current field.
[ "StringValue", "returns", "the", "string", "value", "of", "the", "current", "field", "." ]
16d0bbb0cd468fd51f412021a76ae5c4b450dea8
https://github.com/influxdata/influxdb/blob/16d0bbb0cd468fd51f412021a76ae5c4b450dea8/models/points.go#L2394-L2396
124,801
influxdata/influxdb
models/points.go
IntegerValue
func (p *point) IntegerValue() (int64, error) { n, err := parseIntBytes(p.it.valueBuf, 10, 64) if err != nil { return 0, fmt.Errorf("unable to parse integer value %q: %v", p.it.valueBuf, err) } return n, nil }
go
func (p *point) IntegerValue() (int64, error) { n, err := parseIntBytes(p.it.valueBuf, 10, 64) if err != nil { return 0, fmt.Errorf("unable to parse integer value %q: %v", p.it.valueBuf, err) } return n, nil }
[ "func", "(", "p", "*", "point", ")", "IntegerValue", "(", ")", "(", "int64", ",", "error", ")", "{", "n", ",", "err", ":=", "parseIntBytes", "(", "p", ".", "it", ".", "valueBuf", ",", "10", ",", "64", ")", "\n", "if", "err", "!=", "nil", "{", ...
// IntegerValue returns the integer value of the current field.
[ "IntegerValue", "returns", "the", "integer", "value", "of", "the", "current", "field", "." ]
16d0bbb0cd468fd51f412021a76ae5c4b450dea8
https://github.com/influxdata/influxdb/blob/16d0bbb0cd468fd51f412021a76ae5c4b450dea8/models/points.go#L2399-L2405
124,802
influxdata/influxdb
models/points.go
UnsignedValue
func (p *point) UnsignedValue() (uint64, error) { n, err := parseUintBytes(p.it.valueBuf, 10, 64) if err != nil { return 0, fmt.Errorf("unable to parse unsigned value %q: %v", p.it.valueBuf, err) } return n, nil }
go
func (p *point) UnsignedValue() (uint64, error) { n, err := parseUintBytes(p.it.valueBuf, 10, 64) if err != nil { return 0, fmt.Errorf("unable to parse unsigned value %q: %v", p.it.valueBuf, err) } return n, nil }
[ "func", "(", "p", "*", "point", ")", "UnsignedValue", "(", ")", "(", "uint64", ",", "error", ")", "{", "n", ",", "err", ":=", "parseUintBytes", "(", "p", ".", "it", ".", "valueBuf", ",", "10", ",", "64", ")", "\n", "if", "err", "!=", "nil", "{"...
// UnsignedValue returns the unsigned value of the current field.
[ "UnsignedValue", "returns", "the", "unsigned", "value", "of", "the", "current", "field", "." ]
16d0bbb0cd468fd51f412021a76ae5c4b450dea8
https://github.com/influxdata/influxdb/blob/16d0bbb0cd468fd51f412021a76ae5c4b450dea8/models/points.go#L2408-L2414
124,803
influxdata/influxdb
models/points.go
BooleanValue
func (p *point) BooleanValue() (bool, error) { b, err := parseBoolBytes(p.it.valueBuf) if err != nil { return false, fmt.Errorf("unable to parse bool value %q: %v", p.it.valueBuf, err) } return b, nil }
go
func (p *point) BooleanValue() (bool, error) { b, err := parseBoolBytes(p.it.valueBuf) if err != nil { return false, fmt.Errorf("unable to parse bool value %q: %v", p.it.valueBuf, err) } return b, nil }
[ "func", "(", "p", "*", "point", ")", "BooleanValue", "(", ")", "(", "bool", ",", "error", ")", "{", "b", ",", "err", ":=", "parseBoolBytes", "(", "p", ".", "it", ".", "valueBuf", ")", "\n", "if", "err", "!=", "nil", "{", "return", "false", ",", ...
// BooleanValue returns the boolean value of the current field.
[ "BooleanValue", "returns", "the", "boolean", "value", "of", "the", "current", "field", "." ]
16d0bbb0cd468fd51f412021a76ae5c4b450dea8
https://github.com/influxdata/influxdb/blob/16d0bbb0cd468fd51f412021a76ae5c4b450dea8/models/points.go#L2417-L2423
124,804
influxdata/influxdb
models/points.go
FloatValue
func (p *point) FloatValue() (float64, error) { f, err := parseFloatBytes(p.it.valueBuf, 64) if err != nil { return 0, fmt.Errorf("unable to parse floating point value %q: %v", p.it.valueBuf, err) } return f, nil }
go
func (p *point) FloatValue() (float64, error) { f, err := parseFloatBytes(p.it.valueBuf, 64) if err != nil { return 0, fmt.Errorf("unable to parse floating point value %q: %v", p.it.valueBuf, err) } return f, nil }
[ "func", "(", "p", "*", "point", ")", "FloatValue", "(", ")", "(", "float64", ",", "error", ")", "{", "f", ",", "err", ":=", "parseFloatBytes", "(", "p", ".", "it", ".", "valueBuf", ",", "64", ")", "\n", "if", "err", "!=", "nil", "{", "return", ...
// FloatValue returns the float value of the current field.
[ "FloatValue", "returns", "the", "float", "value", "of", "the", "current", "field", "." ]
16d0bbb0cd468fd51f412021a76ae5c4b450dea8
https://github.com/influxdata/influxdb/blob/16d0bbb0cd468fd51f412021a76ae5c4b450dea8/models/points.go#L2426-L2432
124,805
influxdata/influxdb
models/points.go
Reset
func (p *point) Reset() { p.it.fieldType = Empty p.it.key = nil p.it.valueBuf = nil p.it.start = 0 p.it.end = 0 }
go
func (p *point) Reset() { p.it.fieldType = Empty p.it.key = nil p.it.valueBuf = nil p.it.start = 0 p.it.end = 0 }
[ "func", "(", "p", "*", "point", ")", "Reset", "(", ")", "{", "p", ".", "it", ".", "fieldType", "=", "Empty", "\n", "p", ".", "it", ".", "key", "=", "nil", "\n", "p", ".", "it", ".", "valueBuf", "=", "nil", "\n", "p", ".", "it", ".", "start"...
// Reset resets the iterator to its initial state.
[ "Reset", "resets", "the", "iterator", "to", "its", "initial", "state", "." ]
16d0bbb0cd468fd51f412021a76ae5c4b450dea8
https://github.com/influxdata/influxdb/blob/16d0bbb0cd468fd51f412021a76ae5c4b450dea8/models/points.go#L2435-L2441
124,806
influxdata/influxdb
models/points.go
ValidToken
func ValidToken(a []byte) bool { if !utf8.Valid(a) { return false } for _, r := range string(a) { if !unicode.IsPrint(r) || r == unicode.ReplacementChar { return false } } return true }
go
func ValidToken(a []byte) bool { if !utf8.Valid(a) { return false } for _, r := range string(a) { if !unicode.IsPrint(r) || r == unicode.ReplacementChar { return false } } return true }
[ "func", "ValidToken", "(", "a", "[", "]", "byte", ")", "bool", "{", "if", "!", "utf8", ".", "Valid", "(", "a", ")", "{", "return", "false", "\n", "}", "\n\n", "for", "_", ",", "r", ":=", "range", "string", "(", "a", ")", "{", "if", "!", "unic...
// ValidToken returns true if the provided token is a valid unicode string, and // only contains printable, non-replacement characters.
[ "ValidToken", "returns", "true", "if", "the", "provided", "token", "is", "a", "valid", "unicode", "string", "and", "only", "contains", "printable", "non", "-", "replacement", "characters", "." ]
16d0bbb0cd468fd51f412021a76ae5c4b450dea8
https://github.com/influxdata/influxdb/blob/16d0bbb0cd468fd51f412021a76ae5c4b450dea8/models/points.go#L2534-L2545
124,807
influxdata/influxdb
models/points.go
ValidTagTokens
func ValidTagTokens(tags Tags) bool { for _, tag := range tags { // Validate all external tag keys. if !bytes.Equal(tag.Key, MeasurementTagKeyBytes) && !bytes.Equal(tag.Key, FieldKeyTagKeyBytes) && !ValidToken(tag.Key) { return false } // Validate all tag values (this will also validate the field key, whic...
go
func ValidTagTokens(tags Tags) bool { for _, tag := range tags { // Validate all external tag keys. if !bytes.Equal(tag.Key, MeasurementTagKeyBytes) && !bytes.Equal(tag.Key, FieldKeyTagKeyBytes) && !ValidToken(tag.Key) { return false } // Validate all tag values (this will also validate the field key, whic...
[ "func", "ValidTagTokens", "(", "tags", "Tags", ")", "bool", "{", "for", "_", ",", "tag", ":=", "range", "tags", "{", "// Validate all external tag keys.", "if", "!", "bytes", ".", "Equal", "(", "tag", ".", "Key", ",", "MeasurementTagKeyBytes", ")", "&&", "...
// ValidTagTokens returns true if all the provided tag key and values are // valid. // // ValidTagTokens does not validate the special tag keys used to represent the // measurement name and field key, but it does validate the associated values.
[ "ValidTagTokens", "returns", "true", "if", "all", "the", "provided", "tag", "key", "and", "values", "are", "valid", ".", "ValidTagTokens", "does", "not", "validate", "the", "special", "tag", "keys", "used", "to", "represent", "the", "measurement", "name", "and...
16d0bbb0cd468fd51f412021a76ae5c4b450dea8
https://github.com/influxdata/influxdb/blob/16d0bbb0cd468fd51f412021a76ae5c4b450dea8/models/points.go#L2552-L2565
124,808
influxdata/influxdb
cmd/influx_inspect/buildtsi/buildtsi.go
NewCommand
func NewCommand() *Command { return &Command{ Stderr: os.Stderr, Stdout: os.Stdout, Logger: zap.NewNop(), batchSize: defaultBatchSize, concurrency: runtime.GOMAXPROCS(0), } }
go
func NewCommand() *Command { return &Command{ Stderr: os.Stderr, Stdout: os.Stdout, Logger: zap.NewNop(), batchSize: defaultBatchSize, concurrency: runtime.GOMAXPROCS(0), } }
[ "func", "NewCommand", "(", ")", "*", "Command", "{", "return", "&", "Command", "{", "Stderr", ":", "os", ".", "Stderr", ",", "Stdout", ":", "os", ".", "Stdout", ",", "Logger", ":", "zap", ".", "NewNop", "(", ")", ",", "batchSize", ":", "defaultBatchS...
// NewCommand returns a new instance of Command.
[ "NewCommand", "returns", "a", "new", "instance", "of", "Command", "." ]
16d0bbb0cd468fd51f412021a76ae5c4b450dea8
https://github.com/influxdata/influxdb/blob/16d0bbb0cd468fd51f412021a76ae5c4b450dea8/cmd/influx_inspect/buildtsi/buildtsi.go#L48-L56
124,809
influxdata/influxdb
chronograf/filestore/environ.go
environ
func environ() map[string]string { if env == nil { env = make(map[string]string) envVars := os.Environ() for _, envVar := range envVars { kv := strings.SplitN(envVar, "=", 2) if len(kv) != 2 { continue } env[kv[0]] = kv[1] } } return env }
go
func environ() map[string]string { if env == nil { env = make(map[string]string) envVars := os.Environ() for _, envVar := range envVars { kv := strings.SplitN(envVar, "=", 2) if len(kv) != 2 { continue } env[kv[0]] = kv[1] } } return env }
[ "func", "environ", "(", ")", "map", "[", "string", "]", "string", "{", "if", "env", "==", "nil", "{", "env", "=", "make", "(", "map", "[", "string", "]", "string", ")", "\n", "envVars", ":=", "os", ".", "Environ", "(", ")", "\n", "for", "_", ",...
// environ returns a map of all environment variables in the running process
[ "environ", "returns", "a", "map", "of", "all", "environment", "variables", "in", "the", "running", "process" ]
16d0bbb0cd468fd51f412021a76ae5c4b450dea8
https://github.com/influxdata/influxdb/blob/16d0bbb0cd468fd51f412021a76ae5c4b450dea8/chronograf/filestore/environ.go#L11-L24
124,810
influxdata/influxdb
tsdb/cursors/arrayvalues.gen.go
Contains
func (a *TimestampArray) Contains(min, max int64) bool { rmin, rmax := a.FindRange(min, max) if rmin == -1 && rmax == -1 { return false } // a.Timestamps[rmin] ≥ min // a.Timestamps[rmax] ≥ max if a.Timestamps[rmin] == min { return true } if rmax < a.Len() && a.Timestamps[rmax] == max { return true } ...
go
func (a *TimestampArray) Contains(min, max int64) bool { rmin, rmax := a.FindRange(min, max) if rmin == -1 && rmax == -1 { return false } // a.Timestamps[rmin] ≥ min // a.Timestamps[rmax] ≥ max if a.Timestamps[rmin] == min { return true } if rmax < a.Len() && a.Timestamps[rmax] == max { return true } ...
[ "func", "(", "a", "*", "TimestampArray", ")", "Contains", "(", "min", ",", "max", "int64", ")", "bool", "{", "rmin", ",", "rmax", ":=", "a", ".", "FindRange", "(", "min", ",", "max", ")", "\n", "if", "rmin", "==", "-", "1", "&&", "rmax", "==", ...
// Contains returns true if values exist between min and max inclusive. The // values must be sorted before calling Contains or the results are undefined.
[ "Contains", "returns", "true", "if", "values", "exist", "between", "min", "and", "max", "inclusive", ".", "The", "values", "must", "be", "sorted", "before", "calling", "Contains", "or", "the", "results", "are", "undefined", "." ]
16d0bbb0cd468fd51f412021a76ae5c4b450dea8
https://github.com/influxdata/influxdb/blob/16d0bbb0cd468fd51f412021a76ae5c4b450dea8/tsdb/cursors/arrayvalues.gen.go#L1113-L1131
124,811
influxdata/influxdb
mock/source_service.go
NewSourceService
func NewSourceService() *SourceService { return &SourceService{ DefaultSourceFn: func(context.Context) (*platform.Source, error) { return nil, nil }, FindSourceByIDFn: func(context.Context, platform.ID) (*platform.Source, error) { return nil, nil }, CreateSourceFn: func(context.Context, *platform.Source) erro...
go
func NewSourceService() *SourceService { return &SourceService{ DefaultSourceFn: func(context.Context) (*platform.Source, error) { return nil, nil }, FindSourceByIDFn: func(context.Context, platform.ID) (*platform.Source, error) { return nil, nil }, CreateSourceFn: func(context.Context, *platform.Source) erro...
[ "func", "NewSourceService", "(", ")", "*", "SourceService", "{", "return", "&", "SourceService", "{", "DefaultSourceFn", ":", "func", "(", "context", ".", "Context", ")", "(", "*", "platform", ".", "Source", ",", "error", ")", "{", "return", "nil", ",", ...
// NewSourceService returns a mock of SourceService where its methods will return zero values.
[ "NewSourceService", "returns", "a", "mock", "of", "SourceService", "where", "its", "methods", "will", "return", "zero", "values", "." ]
16d0bbb0cd468fd51f412021a76ae5c4b450dea8
https://github.com/influxdata/influxdb/blob/16d0bbb0cd468fd51f412021a76ae5c4b450dea8/mock/source_service.go#L22-L33
124,812
influxdata/influxdb
mock/source_service.go
FindSourceByID
func (s *SourceService) FindSourceByID(ctx context.Context, id platform.ID) (*platform.Source, error) { return s.FindSourceByIDFn(ctx, id) }
go
func (s *SourceService) FindSourceByID(ctx context.Context, id platform.ID) (*platform.Source, error) { return s.FindSourceByIDFn(ctx, id) }
[ "func", "(", "s", "*", "SourceService", ")", "FindSourceByID", "(", "ctx", "context", ".", "Context", ",", "id", "platform", ".", "ID", ")", "(", "*", "platform", ".", "Source", ",", "error", ")", "{", "return", "s", ".", "FindSourceByIDFn", "(", "ctx"...
// FindSourceByID retrieves a source by its ID.
[ "FindSourceByID", "retrieves", "a", "source", "by", "its", "ID", "." ]
16d0bbb0cd468fd51f412021a76ae5c4b450dea8
https://github.com/influxdata/influxdb/blob/16d0bbb0cd468fd51f412021a76ae5c4b450dea8/mock/source_service.go#L41-L43
124,813
influxdata/influxdb
mock/source_service.go
FindSources
func (s *SourceService) FindSources(ctx context.Context, opts platform.FindOptions) ([]*platform.Source, int, error) { return s.FindSourcesFn(ctx, opts) }
go
func (s *SourceService) FindSources(ctx context.Context, opts platform.FindOptions) ([]*platform.Source, int, error) { return s.FindSourcesFn(ctx, opts) }
[ "func", "(", "s", "*", "SourceService", ")", "FindSources", "(", "ctx", "context", ".", "Context", ",", "opts", "platform", ".", "FindOptions", ")", "(", "[", "]", "*", "platform", ".", "Source", ",", "int", ",", "error", ")", "{", "return", "s", "."...
// FindSources returns a list of all sources.
[ "FindSources", "returns", "a", "list", "of", "all", "sources", "." ]
16d0bbb0cd468fd51f412021a76ae5c4b450dea8
https://github.com/influxdata/influxdb/blob/16d0bbb0cd468fd51f412021a76ae5c4b450dea8/mock/source_service.go#L46-L48
124,814
influxdata/influxdb
mock/source_service.go
CreateSource
func (s *SourceService) CreateSource(ctx context.Context, source *platform.Source) error { return s.CreateSourceFn(ctx, source) }
go
func (s *SourceService) CreateSource(ctx context.Context, source *platform.Source) error { return s.CreateSourceFn(ctx, source) }
[ "func", "(", "s", "*", "SourceService", ")", "CreateSource", "(", "ctx", "context", ".", "Context", ",", "source", "*", "platform", ".", "Source", ")", "error", "{", "return", "s", ".", "CreateSourceFn", "(", "ctx", ",", "source", ")", "\n", "}" ]
// CreateSource sets the sources ID and stores it.
[ "CreateSource", "sets", "the", "sources", "ID", "and", "stores", "it", "." ]
16d0bbb0cd468fd51f412021a76ae5c4b450dea8
https://github.com/influxdata/influxdb/blob/16d0bbb0cd468fd51f412021a76ae5c4b450dea8/mock/source_service.go#L51-L53
124,815
influxdata/influxdb
mock/source_service.go
DeleteSource
func (s *SourceService) DeleteSource(ctx context.Context, id platform.ID) error { return s.DeleteSourceFn(ctx, id) }
go
func (s *SourceService) DeleteSource(ctx context.Context, id platform.ID) error { return s.DeleteSourceFn(ctx, id) }
[ "func", "(", "s", "*", "SourceService", ")", "DeleteSource", "(", "ctx", "context", ".", "Context", ",", "id", "platform", ".", "ID", ")", "error", "{", "return", "s", ".", "DeleteSourceFn", "(", "ctx", ",", "id", ")", "\n", "}" ]
// DeleteSource removes the source.
[ "DeleteSource", "removes", "the", "source", "." ]
16d0bbb0cd468fd51f412021a76ae5c4b450dea8
https://github.com/influxdata/influxdb/blob/16d0bbb0cd468fd51f412021a76ae5c4b450dea8/mock/source_service.go#L56-L58
124,816
influxdata/influxdb
mock/source_service.go
UpdateSource
func (s *SourceService) UpdateSource(ctx context.Context, id platform.ID, upd platform.SourceUpdate) (*platform.Source, error) { return s.UpdateSourceFn(ctx, id, upd) }
go
func (s *SourceService) UpdateSource(ctx context.Context, id platform.ID, upd platform.SourceUpdate) (*platform.Source, error) { return s.UpdateSourceFn(ctx, id, upd) }
[ "func", "(", "s", "*", "SourceService", ")", "UpdateSource", "(", "ctx", "context", ".", "Context", ",", "id", "platform", ".", "ID", ",", "upd", "platform", ".", "SourceUpdate", ")", "(", "*", "platform", ".", "Source", ",", "error", ")", "{", "return...
// UpdateSource updates the source.
[ "UpdateSource", "updates", "the", "source", "." ]
16d0bbb0cd468fd51f412021a76ae5c4b450dea8
https://github.com/influxdata/influxdb/blob/16d0bbb0cd468fd51f412021a76ae5c4b450dea8/mock/source_service.go#L61-L63
124,817
mholt/caddy
caddy/caddymain/run.go
confLoader
func confLoader(serverType string) (caddy.Input, error) { if conf == "" { return nil, nil } if conf == "stdin" { return caddy.CaddyfileFromPipe(os.Stdin, serverType) } var contents []byte if strings.Contains(conf, "*") { // Let caddyfile.doImport logic handle the globbed path contents = []byte("import "...
go
func confLoader(serverType string) (caddy.Input, error) { if conf == "" { return nil, nil } if conf == "stdin" { return caddy.CaddyfileFromPipe(os.Stdin, serverType) } var contents []byte if strings.Contains(conf, "*") { // Let caddyfile.doImport logic handle the globbed path contents = []byte("import "...
[ "func", "confLoader", "(", "serverType", "string", ")", "(", "caddy", ".", "Input", ",", "error", ")", "{", "if", "conf", "==", "\"", "\"", "{", "return", "nil", ",", "nil", "\n", "}", "\n\n", "if", "conf", "==", "\"", "\"", "{", "return", "caddy",...
// confLoader loads the Caddyfile using the -conf flag.
[ "confLoader", "loads", "the", "Caddyfile", "using", "the", "-", "conf", "flag", "." ]
a2ed91bc45c8b3faa1577ed4c18334d38a581ca7
https://github.com/mholt/caddy/blob/a2ed91bc45c8b3faa1577ed4c18334d38a581ca7/caddy/caddymain/run.go#L236-L262
124,818
mholt/caddy
caddy/caddymain/run.go
defaultLoader
func defaultLoader(serverType string) (caddy.Input, error) { contents, err := ioutil.ReadFile(caddy.DefaultConfigFile) if err != nil { if os.IsNotExist(err) { return nil, nil } return nil, err } return caddy.CaddyfileInput{ Contents: contents, Filepath: caddy.DefaultConfigFile, ServerType...
go
func defaultLoader(serverType string) (caddy.Input, error) { contents, err := ioutil.ReadFile(caddy.DefaultConfigFile) if err != nil { if os.IsNotExist(err) { return nil, nil } return nil, err } return caddy.CaddyfileInput{ Contents: contents, Filepath: caddy.DefaultConfigFile, ServerType...
[ "func", "defaultLoader", "(", "serverType", "string", ")", "(", "caddy", ".", "Input", ",", "error", ")", "{", "contents", ",", "err", ":=", "ioutil", ".", "ReadFile", "(", "caddy", ".", "DefaultConfigFile", ")", "\n", "if", "err", "!=", "nil", "{", "i...
// defaultLoader loads the Caddyfile from the current working directory.
[ "defaultLoader", "loads", "the", "Caddyfile", "from", "the", "current", "working", "directory", "." ]
a2ed91bc45c8b3faa1577ed4c18334d38a581ca7
https://github.com/mholt/caddy/blob/a2ed91bc45c8b3faa1577ed4c18334d38a581ca7/caddy/caddymain/run.go#L265-L278
124,819
mholt/caddy
caddy/caddymain/run.go
initTelemetry
func initTelemetry() error { uuidFilename := filepath.Join(caddy.AssetsPath(), "uuid") if customUUIDFile := os.Getenv("CADDY_UUID_FILE"); customUUIDFile != "" { uuidFilename = customUUIDFile } newUUID := func() uuid.UUID { id := uuid.New() err := os.MkdirAll(caddy.AssetsPath(), 0700) if err != nil { log...
go
func initTelemetry() error { uuidFilename := filepath.Join(caddy.AssetsPath(), "uuid") if customUUIDFile := os.Getenv("CADDY_UUID_FILE"); customUUIDFile != "" { uuidFilename = customUUIDFile } newUUID := func() uuid.UUID { id := uuid.New() err := os.MkdirAll(caddy.AssetsPath(), 0700) if err != nil { log...
[ "func", "initTelemetry", "(", ")", "error", "{", "uuidFilename", ":=", "filepath", ".", "Join", "(", "caddy", ".", "AssetsPath", "(", ")", ",", "\"", "\"", ")", "\n", "if", "customUUIDFile", ":=", "os", ".", "Getenv", "(", "\"", "\"", ")", ";", "cust...
// initTelemetry initializes the telemetry engine.
[ "initTelemetry", "initializes", "the", "telemetry", "engine", "." ]
a2ed91bc45c8b3faa1577ed4c18334d38a581ca7
https://github.com/mholt/caddy/blob/a2ed91bc45c8b3faa1577ed4c18334d38a581ca7/caddy/caddymain/run.go#L413-L482
124,820
mholt/caddy
caddy/caddymain/run.go
splitTrim
func splitTrim(s string, sep string) []string { splitItems := strings.Split(s, sep) trimItems := make([]string, 0, len(splitItems)) for _, item := range splitItems { if item = strings.TrimSpace(item); item != "" { trimItems = append(trimItems, item) } } return trimItems }
go
func splitTrim(s string, sep string) []string { splitItems := strings.Split(s, sep) trimItems := make([]string, 0, len(splitItems)) for _, item := range splitItems { if item = strings.TrimSpace(item); item != "" { trimItems = append(trimItems, item) } } return trimItems }
[ "func", "splitTrim", "(", "s", "string", ",", "sep", "string", ")", "[", "]", "string", "{", "splitItems", ":=", "strings", ".", "Split", "(", "s", ",", "sep", ")", "\n", "trimItems", ":=", "make", "(", "[", "]", "string", ",", "0", ",", "len", "...
// Split string s into all substrings separated by sep and returns a slice of // the substrings between those separators. // // If s does not contain sep and sep is not empty, Split returns a // slice of length 1 whose only element is s. // // If sep is empty, Split splits after each UTF-8 sequence. If both s // and se...
[ "Split", "string", "s", "into", "all", "substrings", "separated", "by", "sep", "and", "returns", "a", "slice", "of", "the", "substrings", "between", "those", "separators", ".", "If", "s", "does", "not", "contain", "sep", "and", "sep", "is", "not", "empty",...
a2ed91bc45c8b3faa1577ed4c18334d38a581ca7
https://github.com/mholt/caddy/blob/a2ed91bc45c8b3faa1577ed4c18334d38a581ca7/caddy/caddymain/run.go#L494-L503
124,821
mholt/caddy
caddy/caddymain/run.go
LoadEnvFromFile
func LoadEnvFromFile(envFile string) error { if envFile == "" { return nil } file, err := os.Open(envFile) if err != nil { return err } defer file.Close() envMap, err := ParseEnvFile(file) if err != nil { return err } for k, v := range envMap { if err := os.Setenv(k, v); err != nil { return err ...
go
func LoadEnvFromFile(envFile string) error { if envFile == "" { return nil } file, err := os.Open(envFile) if err != nil { return err } defer file.Close() envMap, err := ParseEnvFile(file) if err != nil { return err } for k, v := range envMap { if err := os.Setenv(k, v); err != nil { return err ...
[ "func", "LoadEnvFromFile", "(", "envFile", "string", ")", "error", "{", "if", "envFile", "==", "\"", "\"", "{", "return", "nil", "\n", "}", "\n\n", "file", ",", "err", ":=", "os", ".", "Open", "(", "envFile", ")", "\n", "if", "err", "!=", "nil", "{...
// LoadEnvFromFile loads additional envs if file provided and exists // Envs in file should be in KEY=VALUE format
[ "LoadEnvFromFile", "loads", "additional", "envs", "if", "file", "provided", "and", "exists", "Envs", "in", "file", "should", "be", "in", "KEY", "=", "VALUE", "format" ]
a2ed91bc45c8b3faa1577ed4c18334d38a581ca7
https://github.com/mholt/caddy/blob/a2ed91bc45c8b3faa1577ed4c18334d38a581ca7/caddy/caddymain/run.go#L507-L530
124,822
mholt/caddy
caddy/caddymain/run.go
ParseEnvFile
func ParseEnvFile(envInput io.Reader) (map[string]string, error) { envMap := make(map[string]string) scanner := bufio.NewScanner(envInput) var line string lineNumber := 0 for scanner.Scan() { line = strings.TrimSpace(scanner.Text()) lineNumber++ // skip lines starting with comment if strings.HasPrefix(l...
go
func ParseEnvFile(envInput io.Reader) (map[string]string, error) { envMap := make(map[string]string) scanner := bufio.NewScanner(envInput) var line string lineNumber := 0 for scanner.Scan() { line = strings.TrimSpace(scanner.Text()) lineNumber++ // skip lines starting with comment if strings.HasPrefix(l...
[ "func", "ParseEnvFile", "(", "envInput", "io", ".", "Reader", ")", "(", "map", "[", "string", "]", "string", ",", "error", ")", "{", "envMap", ":=", "make", "(", "map", "[", "string", "]", "string", ")", "\n\n", "scanner", ":=", "bufio", ".", "NewSca...
// ParseEnvFile implements parse logic for environment files
[ "ParseEnvFile", "implements", "parse", "logic", "for", "environment", "files" ]
a2ed91bc45c8b3faa1577ed4c18334d38a581ca7
https://github.com/mholt/caddy/blob/a2ed91bc45c8b3faa1577ed4c18334d38a581ca7/caddy/caddymain/run.go#L533-L577
124,823
mholt/caddy
commands.go
SplitCommandAndArgs
func SplitCommandAndArgs(command string) (cmd string, args []string, err error) { var parts []string if runtimeGoos == "windows" { parts = parseWindowsCommand(command) // parse it Windows-style } else { parts, err = parseUnixCommand(command) // parse it Unix-style if err != nil { err = errors.New("error pa...
go
func SplitCommandAndArgs(command string) (cmd string, args []string, err error) { var parts []string if runtimeGoos == "windows" { parts = parseWindowsCommand(command) // parse it Windows-style } else { parts, err = parseUnixCommand(command) // parse it Unix-style if err != nil { err = errors.New("error pa...
[ "func", "SplitCommandAndArgs", "(", "command", "string", ")", "(", "cmd", "string", ",", "args", "[", "]", "string", ",", "err", "error", ")", "{", "var", "parts", "[", "]", "string", "\n\n", "if", "runtimeGoos", "==", "\"", "\"", "{", "parts", "=", ...
// SplitCommandAndArgs takes a command string and parses it shell-style into the // command and its separate arguments.
[ "SplitCommandAndArgs", "takes", "a", "command", "string", "and", "parses", "it", "shell", "-", "style", "into", "the", "command", "and", "its", "separate", "arguments", "." ]
a2ed91bc45c8b3faa1577ed4c18334d38a581ca7
https://github.com/mholt/caddy/blob/a2ed91bc45c8b3faa1577ed4c18334d38a581ca7/commands.go#L29-L53
124,824
mholt/caddy
caddyfile/json.go
ToJSON
func ToJSON(caddyfile []byte) ([]byte, error) { var j EncodedCaddyfile serverBlocks, err := Parse(filename, bytes.NewReader(caddyfile), nil) if err != nil { return nil, err } for _, sb := range serverBlocks { block := EncodedServerBlock{ Keys: sb.Keys, Body: [][]interface{}{}, } // Extract directi...
go
func ToJSON(caddyfile []byte) ([]byte, error) { var j EncodedCaddyfile serverBlocks, err := Parse(filename, bytes.NewReader(caddyfile), nil) if err != nil { return nil, err } for _, sb := range serverBlocks { block := EncodedServerBlock{ Keys: sb.Keys, Body: [][]interface{}{}, } // Extract directi...
[ "func", "ToJSON", "(", "caddyfile", "[", "]", "byte", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "var", "j", "EncodedCaddyfile", "\n\n", "serverBlocks", ",", "err", ":=", "Parse", "(", "filename", ",", "bytes", ".", "NewReader", "(", "caddyfil...
// ToJSON converts caddyfile to its JSON representation.
[ "ToJSON", "converts", "caddyfile", "to", "its", "JSON", "representation", "." ]
a2ed91bc45c8b3faa1577ed4c18334d38a581ca7
https://github.com/mholt/caddy/blob/a2ed91bc45c8b3faa1577ed4c18334d38a581ca7/caddyfile/json.go#L29-L68
124,825
mholt/caddy
caddyfile/json.go
constructBlock
func constructBlock(d *Dispenser) [][]interface{} { block := [][]interface{}{} for d.Next() { if d.Val() == "}" { break } block = append(block, constructLine(d)) } return block }
go
func constructBlock(d *Dispenser) [][]interface{} { block := [][]interface{}{} for d.Next() { if d.Val() == "}" { break } block = append(block, constructLine(d)) } return block }
[ "func", "constructBlock", "(", "d", "*", "Dispenser", ")", "[", "]", "[", "]", "interface", "{", "}", "{", "block", ":=", "[", "]", "[", "]", "interface", "{", "}", "{", "}", "\n\n", "for", "d", ".", "Next", "(", ")", "{", "if", "d", ".", "Va...
// constructBlock recursively processes tokens into a // JSON-encodable structure. To be used in a directive's // block. Goes to end of block.
[ "constructBlock", "recursively", "processes", "tokens", "into", "a", "JSON", "-", "encodable", "structure", ".", "To", "be", "used", "in", "a", "directive", "s", "block", ".", "Goes", "to", "end", "of", "block", "." ]
a2ed91bc45c8b3faa1577ed4c18334d38a581ca7
https://github.com/mholt/caddy/blob/a2ed91bc45c8b3faa1577ed4c18334d38a581ca7/caddyfile/json.go#L93-L104
124,826
mholt/caddy
caddyfile/json.go
FromJSON
func FromJSON(jsonBytes []byte) ([]byte, error) { var j EncodedCaddyfile var result string err := json.Unmarshal(jsonBytes, &j) if err != nil { return nil, err } for sbPos, sb := range j { if sbPos > 0 { result += "\n\n" } for i, key := range sb.Keys { if i > 0 { result += ", " } //resul...
go
func FromJSON(jsonBytes []byte) ([]byte, error) { var j EncodedCaddyfile var result string err := json.Unmarshal(jsonBytes, &j) if err != nil { return nil, err } for sbPos, sb := range j { if sbPos > 0 { result += "\n\n" } for i, key := range sb.Keys { if i > 0 { result += ", " } //resul...
[ "func", "FromJSON", "(", "jsonBytes", "[", "]", "byte", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "var", "j", "EncodedCaddyfile", "\n", "var", "result", "string", "\n\n", "err", ":=", "json", ".", "Unmarshal", "(", "jsonBytes", ",", "&", "j...
// FromJSON converts JSON-encoded jsonBytes to Caddyfile text
[ "FromJSON", "converts", "JSON", "-", "encoded", "jsonBytes", "to", "Caddyfile", "text" ]
a2ed91bc45c8b3faa1577ed4c18334d38a581ca7
https://github.com/mholt/caddy/blob/a2ed91bc45c8b3faa1577ed4c18334d38a581ca7/caddyfile/json.go#L107-L131
124,827
mholt/caddy
caddyfile/json.go
jsonToText
func jsonToText(scope interface{}, depth int) string { var result string switch val := scope.(type) { case string: if strings.ContainsAny(val, "\" \n\t\r") { result += `"` + strings.Replace(val, "\"", "\\\"", -1) + `"` } else { result += val } case int: result += strconv.Itoa(val) case float64: re...
go
func jsonToText(scope interface{}, depth int) string { var result string switch val := scope.(type) { case string: if strings.ContainsAny(val, "\" \n\t\r") { result += `"` + strings.Replace(val, "\"", "\\\"", -1) + `"` } else { result += val } case int: result += strconv.Itoa(val) case float64: re...
[ "func", "jsonToText", "(", "scope", "interface", "{", "}", ",", "depth", "int", ")", "string", "{", "var", "result", "string", "\n\n", "switch", "val", ":=", "scope", ".", "(", "type", ")", "{", "case", "string", ":", "if", "strings", ".", "ContainsAny...
// jsonToText recursively transforms a scope of JSON into plain // Caddyfile text.
[ "jsonToText", "recursively", "transforms", "a", "scope", "of", "JSON", "into", "plain", "Caddyfile", "text", "." ]
a2ed91bc45c8b3faa1577ed4c18334d38a581ca7
https://github.com/mholt/caddy/blob/a2ed91bc45c8b3faa1577ed4c18334d38a581ca7/caddyfile/json.go#L135-L175
124,828
mholt/caddy
caddyhttp/httpserver/middleware.go
Select
func (c ConfigSelector) Select(r *http.Request) (config HandlerConfig) { for i := range c { if !c[i].Match(r) { continue } if config == nil || len(c[i].BasePath()) > len(config.BasePath()) { config = c[i] } } return config }
go
func (c ConfigSelector) Select(r *http.Request) (config HandlerConfig) { for i := range c { if !c[i].Match(r) { continue } if config == nil || len(c[i].BasePath()) > len(config.BasePath()) { config = c[i] } } return config }
[ "func", "(", "c", "ConfigSelector", ")", "Select", "(", "r", "*", "http", ".", "Request", ")", "(", "config", "HandlerConfig", ")", "{", "for", "i", ":=", "range", "c", "{", "if", "!", "c", "[", "i", "]", ".", "Match", "(", "r", ")", "{", "cont...
// Select selects a Config. // This chooses the config with the longest length.
[ "Select", "selects", "a", "Config", ".", "This", "chooses", "the", "config", "with", "the", "longest", "length", "." ]
a2ed91bc45c8b3faa1577ed4c18334d38a581ca7
https://github.com/mholt/caddy/blob/a2ed91bc45c8b3faa1577ed4c18334d38a581ca7/caddyhttp/httpserver/middleware.go#L97-L107
124,829
mholt/caddy
caddyhttp/httpserver/middleware.go
SetLastModifiedHeader
func SetLastModifiedHeader(w http.ResponseWriter, modTime time.Time) { if modTime.IsZero() || modTime.Equal(time.Unix(0, 0)) { // the time does not appear to be valid. Don't put it in the response return } // RFC 2616 - Section 14.29 - Last-Modified: // An origin server MUST NOT send a Last-Modified date which...
go
func SetLastModifiedHeader(w http.ResponseWriter, modTime time.Time) { if modTime.IsZero() || modTime.Equal(time.Unix(0, 0)) { // the time does not appear to be valid. Don't put it in the response return } // RFC 2616 - Section 14.29 - Last-Modified: // An origin server MUST NOT send a Last-Modified date which...
[ "func", "SetLastModifiedHeader", "(", "w", "http", ".", "ResponseWriter", ",", "modTime", "time", ".", "Time", ")", "{", "if", "modTime", ".", "IsZero", "(", ")", "||", "modTime", ".", "Equal", "(", "time", ".", "Unix", "(", "0", ",", "0", ")", ")", ...
// SetLastModifiedHeader checks if the provided modTime is valid and if it is sets it // as a Last-Modified header to the ResponseWriter. If the modTime is in the future // the current time is used instead.
[ "SetLastModifiedHeader", "checks", "if", "the", "provided", "modTime", "is", "valid", "and", "if", "it", "is", "sets", "it", "as", "a", "Last", "-", "Modified", "header", "to", "the", "ResponseWriter", ".", "If", "the", "modTime", "is", "in", "the", "futur...
a2ed91bc45c8b3faa1577ed4c18334d38a581ca7
https://github.com/mholt/caddy/blob/a2ed91bc45c8b3faa1577ed4c18334d38a581ca7/caddyhttp/httpserver/middleware.go#L140-L157
124,830
mholt/caddy
caddyhttp/httpserver/middleware.go
Match
func (m requestMatchers) Match(r *http.Request) bool { for _, matcher := range m { if !matcher.Match(r) { return false } } return true }
go
func (m requestMatchers) Match(r *http.Request) bool { for _, matcher := range m { if !matcher.Match(r) { return false } } return true }
[ "func", "(", "m", "requestMatchers", ")", "Match", "(", "r", "*", "http", ".", "Request", ")", "bool", "{", "for", "_", ",", "matcher", ":=", "range", "m", "{", "if", "!", "matcher", ".", "Match", "(", "r", ")", "{", "return", "false", "\n", "}",...
// Match satisfies RequestMatcher interface.
[ "Match", "satisfies", "RequestMatcher", "interface", "." ]
a2ed91bc45c8b3faa1577ed4c18334d38a581ca7
https://github.com/mholt/caddy/blob/a2ed91bc45c8b3faa1577ed4c18334d38a581ca7/caddyhttp/httpserver/middleware.go#L186-L193
124,831
mholt/caddy
caddyhttp/httpserver/middleware.go
SameNext
func SameNext(next1, next2 Handler) bool { return fmt.Sprintf("%v", next1) == fmt.Sprintf("%v", next2) }
go
func SameNext(next1, next2 Handler) bool { return fmt.Sprintf("%v", next1) == fmt.Sprintf("%v", next2) }
[ "func", "SameNext", "(", "next1", ",", "next2", "Handler", ")", "bool", "{", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "next1", ")", "==", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "next2", ")", "\n", "}" ]
// SameNext does a pointer comparison between next1 and next2. // // Used primarily for testing but needs to be exported so // plugins can use this as a convenience.
[ "SameNext", "does", "a", "pointer", "comparison", "between", "next1", "and", "next2", ".", "Used", "primarily", "for", "testing", "but", "needs", "to", "be", "exported", "so", "plugins", "can", "use", "this", "as", "a", "convenience", "." ]
a2ed91bc45c8b3faa1577ed4c18334d38a581ca7
https://github.com/mholt/caddy/blob/a2ed91bc45c8b3faa1577ed4c18334d38a581ca7/caddyhttp/httpserver/middleware.go#L211-L213
124,832
mholt/caddy
caddyhttp/httpserver/server.go
makeTLSConfig
func makeTLSConfig(group []*SiteConfig) (*tls.Config, error) { var tlsConfigs []*caddytls.Config for i := range group { if HTTP2 && len(group[i].TLS.ALPN) == 0 { // if no application-level protocol was configured up to now, // default to HTTP/2, then HTTP/1.1 if necessary group[i].TLS.ALPN = defaultALPN ...
go
func makeTLSConfig(group []*SiteConfig) (*tls.Config, error) { var tlsConfigs []*caddytls.Config for i := range group { if HTTP2 && len(group[i].TLS.ALPN) == 0 { // if no application-level protocol was configured up to now, // default to HTTP/2, then HTTP/1.1 if necessary group[i].TLS.ALPN = defaultALPN ...
[ "func", "makeTLSConfig", "(", "group", "[", "]", "*", "SiteConfig", ")", "(", "*", "tls", ".", "Config", ",", "error", ")", "{", "var", "tlsConfigs", "[", "]", "*", "caddytls", ".", "Config", "\n", "for", "i", ":=", "range", "group", "{", "if", "HT...
// makeTLSConfig extracts TLS settings from each site config to // build a tls.Config usable in Caddy HTTP servers. The returned // config will be nil if TLS is disabled for these sites.
[ "makeTLSConfig", "extracts", "TLS", "settings", "from", "each", "site", "config", "to", "build", "a", "tls", ".", "Config", "usable", "in", "Caddy", "HTTP", "servers", ".", "The", "returned", "config", "will", "be", "nil", "if", "TLS", "is", "disabled", "f...
a2ed91bc45c8b3faa1577ed4c18334d38a581ca7
https://github.com/mholt/caddy/blob/a2ed91bc45c8b3faa1577ed4c18334d38a581ca7/caddyhttp/httpserver/server.go#L59-L70
124,833
mholt/caddy
caddyhttp/httpserver/server.go
makeHTTPServerWithHeaderLimit
func makeHTTPServerWithHeaderLimit(s *http.Server, group []*SiteConfig) *http.Server { var min int64 for _, cfg := range group { limit := cfg.Limits.MaxRequestHeaderSize if limit == 0 { continue } // not set yet if min == 0 { min = limit } // find a better one if limit < min { min = limit ...
go
func makeHTTPServerWithHeaderLimit(s *http.Server, group []*SiteConfig) *http.Server { var min int64 for _, cfg := range group { limit := cfg.Limits.MaxRequestHeaderSize if limit == 0 { continue } // not set yet if min == 0 { min = limit } // find a better one if limit < min { min = limit ...
[ "func", "makeHTTPServerWithHeaderLimit", "(", "s", "*", "http", ".", "Server", ",", "group", "[", "]", "*", "SiteConfig", ")", "*", "http", ".", "Server", "{", "var", "min", "int64", "\n", "for", "_", ",", "cfg", ":=", "range", "group", "{", "limit", ...
// makeHTTPServerWithHeaderLimit apply minimum header limit within a group to given http.Server
[ "makeHTTPServerWithHeaderLimit", "apply", "minimum", "header", "limit", "within", "a", "group", "to", "given", "http", ".", "Server" ]
a2ed91bc45c8b3faa1577ed4c18334d38a581ca7
https://github.com/mholt/caddy/blob/a2ed91bc45c8b3faa1577ed4c18334d38a581ca7/caddyhttp/httpserver/server.go#L155-L178
124,834
mholt/caddy
caddyhttp/httpserver/server.go
WrapListener
func (s *Server) WrapListener(ln net.Listener) net.Listener { if ln == nil { return nil } cln := ln.(caddy.Listener) for _, site := range s.sites { for _, m := range site.listenerMiddleware { cln = m(cln) } } return cln }
go
func (s *Server) WrapListener(ln net.Listener) net.Listener { if ln == nil { return nil } cln := ln.(caddy.Listener) for _, site := range s.sites { for _, m := range site.listenerMiddleware { cln = m(cln) } } return cln }
[ "func", "(", "s", "*", "Server", ")", "WrapListener", "(", "ln", "net", ".", "Listener", ")", "net", ".", "Listener", "{", "if", "ln", "==", "nil", "{", "return", "nil", "\n", "}", "\n", "cln", ":=", "ln", ".", "(", "caddy", ".", "Listener", ")",...
// WrapListener wraps ln in the listener middlewares configured // for this server.
[ "WrapListener", "wraps", "ln", "in", "the", "listener", "middlewares", "configured", "for", "this", "server", "." ]
a2ed91bc45c8b3faa1577ed4c18334d38a581ca7
https://github.com/mholt/caddy/blob/a2ed91bc45c8b3faa1577ed4c18334d38a581ca7/caddyhttp/httpserver/server.go#L285-L296
124,835
mholt/caddy
caddyhttp/httpserver/server.go
ListenPacket
func (s *Server) ListenPacket() (net.PacketConn, error) { if QUIC { udpAddr, err := net.ResolveUDPAddr("udp", s.Server.Addr) if err != nil { return nil, err } return net.ListenUDP("udp", udpAddr) } return nil, nil }
go
func (s *Server) ListenPacket() (net.PacketConn, error) { if QUIC { udpAddr, err := net.ResolveUDPAddr("udp", s.Server.Addr) if err != nil { return nil, err } return net.ListenUDP("udp", udpAddr) } return nil, nil }
[ "func", "(", "s", "*", "Server", ")", "ListenPacket", "(", ")", "(", "net", ".", "PacketConn", ",", "error", ")", "{", "if", "QUIC", "{", "udpAddr", ",", "err", ":=", "net", ".", "ResolveUDPAddr", "(", "\"", "\"", ",", "s", ".", "Server", ".", "A...
// ListenPacket creates udp connection for QUIC if it is enabled,
[ "ListenPacket", "creates", "udp", "connection", "for", "QUIC", "if", "it", "is", "enabled" ]
a2ed91bc45c8b3faa1577ed4c18334d38a581ca7
https://github.com/mholt/caddy/blob/a2ed91bc45c8b3faa1577ed4c18334d38a581ca7/caddyhttp/httpserver/server.go#L299-L308
124,836
mholt/caddy
caddyhttp/httpserver/server.go
DefaultErrorFunc
func DefaultErrorFunc(w http.ResponseWriter, r *http.Request, status int) { WriteTextResponse(w, status, fmt.Sprintf("%d %s\n", status, http.StatusText(status))) }
go
func DefaultErrorFunc(w http.ResponseWriter, r *http.Request, status int) { WriteTextResponse(w, status, fmt.Sprintf("%d %s\n", status, http.StatusText(status))) }
[ "func", "DefaultErrorFunc", "(", "w", "http", ".", "ResponseWriter", ",", "r", "*", "http", ".", "Request", ",", "status", "int", ")", "{", "WriteTextResponse", "(", "w", ",", "status", ",", "fmt", ".", "Sprintf", "(", "\"", "\\n", "\"", ",", "status",...
// DefaultErrorFunc responds to an HTTP request with a simple description // of the specified HTTP status code.
[ "DefaultErrorFunc", "responds", "to", "an", "HTTP", "request", "with", "a", "simple", "description", "of", "the", "specified", "HTTP", "status", "code", "." ]
a2ed91bc45c8b3faa1577ed4c18334d38a581ca7
https://github.com/mholt/caddy/blob/a2ed91bc45c8b3faa1577ed4c18334d38a581ca7/caddyhttp/httpserver/server.go#L582-L584
124,837
mholt/caddy
caddyhttp/httpserver/server.go
WriteSiteNotFound
func WriteSiteNotFound(w http.ResponseWriter, r *http.Request) { status := http.StatusNotFound if r.ProtoMajor >= 2 { // TODO: use http.StatusMisdirectedRequest when it gets defined status = httpStatusMisdirectedRequest } WriteTextResponse(w, status, fmt.Sprintf("%d Site %s is not served on this interface\n", s...
go
func WriteSiteNotFound(w http.ResponseWriter, r *http.Request) { status := http.StatusNotFound if r.ProtoMajor >= 2 { // TODO: use http.StatusMisdirectedRequest when it gets defined status = httpStatusMisdirectedRequest } WriteTextResponse(w, status, fmt.Sprintf("%d Site %s is not served on this interface\n", s...
[ "func", "WriteSiteNotFound", "(", "w", "http", ".", "ResponseWriter", ",", "r", "*", "http", ".", "Request", ")", "{", "status", ":=", "http", ".", "StatusNotFound", "\n", "if", "r", ".", "ProtoMajor", ">=", "2", "{", "// TODO: use http.StatusMisdirectedReques...
// WriteSiteNotFound writes appropriate error code to w, signaling that // requested host is not served by Caddy on a given port.
[ "WriteSiteNotFound", "writes", "appropriate", "error", "code", "to", "w", "signaling", "that", "requested", "host", "is", "not", "served", "by", "Caddy", "on", "a", "given", "port", "." ]
a2ed91bc45c8b3faa1577ed4c18334d38a581ca7
https://github.com/mholt/caddy/blob/a2ed91bc45c8b3faa1577ed4c18334d38a581ca7/caddyhttp/httpserver/server.go#L590-L597
124,838
mholt/caddy
caddyhttp/httpserver/server.go
SafePath
func SafePath(siteRoot, reqPath string) string { reqPath = filepath.ToSlash(reqPath) reqPath = strings.Replace(reqPath, "\x00", "", -1) // NOTE: Go 1.9 checks for null bytes in the syscall package if siteRoot == "" { siteRoot = "." } return filepath.Join(siteRoot, filepath.FromSlash(path.Clean("/"+reqPath))) }
go
func SafePath(siteRoot, reqPath string) string { reqPath = filepath.ToSlash(reqPath) reqPath = strings.Replace(reqPath, "\x00", "", -1) // NOTE: Go 1.9 checks for null bytes in the syscall package if siteRoot == "" { siteRoot = "." } return filepath.Join(siteRoot, filepath.FromSlash(path.Clean("/"+reqPath))) }
[ "func", "SafePath", "(", "siteRoot", ",", "reqPath", "string", ")", "string", "{", "reqPath", "=", "filepath", ".", "ToSlash", "(", "reqPath", ")", "\n", "reqPath", "=", "strings", ".", "Replace", "(", "reqPath", ",", "\"", "\\x00", "\"", ",", "\"", "\...
// SafePath joins siteRoot and reqPath and converts it to a path that can // be used to access a path on the local disk. It ensures the path does // not traverse outside of the site root. // // If opening a file, use http.Dir instead.
[ "SafePath", "joins", "siteRoot", "and", "reqPath", "and", "converts", "it", "to", "a", "path", "that", "can", "be", "used", "to", "access", "a", "path", "on", "the", "local", "disk", ".", "It", "ensures", "the", "path", "does", "not", "traverse", "outsid...
a2ed91bc45c8b3faa1577ed4c18334d38a581ca7
https://github.com/mholt/caddy/blob/a2ed91bc45c8b3faa1577ed4c18334d38a581ca7/caddyhttp/httpserver/server.go#L615-L622
124,839
mholt/caddy
caddyhttp/proxy/reverseproxy.go
UseOwnCACertificates
func (rp *ReverseProxy) UseOwnCACertificates(CaCertPool *x509.CertPool) { if transport, ok := rp.Transport.(*http.Transport); ok { if transport.TLSClientConfig == nil { transport.TLSClientConfig = &tls.Config{} } transport.TLSClientConfig.RootCAs = CaCertPool // No http2.ConfigureTransport() here. // For ...
go
func (rp *ReverseProxy) UseOwnCACertificates(CaCertPool *x509.CertPool) { if transport, ok := rp.Transport.(*http.Transport); ok { if transport.TLSClientConfig == nil { transport.TLSClientConfig = &tls.Config{} } transport.TLSClientConfig.RootCAs = CaCertPool // No http2.ConfigureTransport() here. // For ...
[ "func", "(", "rp", "*", "ReverseProxy", ")", "UseOwnCACertificates", "(", "CaCertPool", "*", "x509", ".", "CertPool", ")", "{", "if", "transport", ",", "ok", ":=", "rp", ".", "Transport", ".", "(", "*", "http", ".", "Transport", ")", ";", "ok", "{", ...
// UseOwnCertificate is used to facilitate HTTPS proxying // with locally provided certificate.
[ "UseOwnCertificate", "is", "used", "to", "facilitate", "HTTPS", "proxying", "with", "locally", "provided", "certificate", "." ]
a2ed91bc45c8b3faa1577ed4c18334d38a581ca7
https://github.com/mholt/caddy/blob/a2ed91bc45c8b3faa1577ed4c18334d38a581ca7/caddyhttp/proxy/reverseproxy.go#L323-L338
124,840
mholt/caddy
caddyhttp/proxy/reverseproxy.go
getTransportDial
func getTransportDial(t *http.Transport) func(network, addr string) (net.Conn, error) { if t.Dial != nil { return t.Dial } return defaultDialer.Dial }
go
func getTransportDial(t *http.Transport) func(network, addr string) (net.Conn, error) { if t.Dial != nil { return t.Dial } return defaultDialer.Dial }
[ "func", "getTransportDial", "(", "t", "*", "http", ".", "Transport", ")", "func", "(", "network", ",", "addr", "string", ")", "(", "net", ".", "Conn", ",", "error", ")", "{", "if", "t", ".", "Dial", "!=", "nil", "{", "return", "t", ".", "Dial", "...
// getTransportDial always returns a plain Dialer // and defaults to the existing t.Dial.
[ "getTransportDial", "always", "returns", "a", "plain", "Dialer", "and", "defaults", "to", "the", "existing", "t", ".", "Dial", "." ]
a2ed91bc45c8b3faa1577ed4c18334d38a581ca7
https://github.com/mholt/caddy/blob/a2ed91bc45c8b3faa1577ed4c18334d38a581ca7/caddyhttp/proxy/reverseproxy.go#L644-L649
124,841
mholt/caddy
caddyhttp/proxy/reverseproxy.go
getTransportDialTLS
func getTransportDialTLS(t *http.Transport) func(network, addr string) (net.Conn, error) { if t.DialTLS != nil { return t.DialTLS } // newConnHijackerTransport will modify t.Dial after calling this method // => Create a backup reference. plainDial := getTransportDial(t) // The following DialTLS implementation...
go
func getTransportDialTLS(t *http.Transport) func(network, addr string) (net.Conn, error) { if t.DialTLS != nil { return t.DialTLS } // newConnHijackerTransport will modify t.Dial after calling this method // => Create a backup reference. plainDial := getTransportDial(t) // The following DialTLS implementation...
[ "func", "getTransportDialTLS", "(", "t", "*", "http", ".", "Transport", ")", "func", "(", "network", ",", "addr", "string", ")", "(", "net", ".", "Conn", ",", "error", ")", "{", "if", "t", ".", "DialTLS", "!=", "nil", "{", "return", "t", ".", "Dial...
// getTransportDial always returns a TLS Dialer // and defaults to the existing t.DialTLS.
[ "getTransportDial", "always", "returns", "a", "TLS", "Dialer", "and", "defaults", "to", "the", "existing", "t", ".", "DialTLS", "." ]
a2ed91bc45c8b3faa1577ed4c18334d38a581ca7
https://github.com/mholt/caddy/blob/a2ed91bc45c8b3faa1577ed4c18334d38a581ca7/caddyhttp/proxy/reverseproxy.go#L653-L711
124,842
mholt/caddy
caddyhttp/push/setup.go
setup
func setup(c *caddy.Controller) error { rules, err := parsePushRules(c) if err != nil { return err } cfg := httpserver.GetConfig(c) cfg.AddMiddleware(func(next httpserver.Handler) httpserver.Handler { return Middleware{Next: next, Rules: rules, Root: http.Dir(cfg.Root), indexPages: cfg.IndexPages} }) retu...
go
func setup(c *caddy.Controller) error { rules, err := parsePushRules(c) if err != nil { return err } cfg := httpserver.GetConfig(c) cfg.AddMiddleware(func(next httpserver.Handler) httpserver.Handler { return Middleware{Next: next, Rules: rules, Root: http.Dir(cfg.Root), indexPages: cfg.IndexPages} }) retu...
[ "func", "setup", "(", "c", "*", "caddy", ".", "Controller", ")", "error", "{", "rules", ",", "err", ":=", "parsePushRules", "(", "c", ")", "\n\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "cfg", ":=", "httpserver", ".", "G...
// setup configures a new Push middleware
[ "setup", "configures", "a", "new", "Push", "middleware" ]
a2ed91bc45c8b3faa1577ed4c18334d38a581ca7
https://github.com/mholt/caddy/blob/a2ed91bc45c8b3faa1577ed4c18334d38a581ca7/caddyhttp/push/setup.go#L44-L57
124,843
mholt/caddy
caddyhttp/websocket/setup.go
setup
func setup(c *caddy.Controller) error { websocks, err := webSocketParse(c) if err != nil { return err } GatewayInterface = caddy.AppName + "-CGI/1.1" ServerSoftware = caddy.AppName + "/" + caddy.AppVersion httpserver.GetConfig(c).AddMiddleware(func(next httpserver.Handler) httpserver.Handler { return WebSoc...
go
func setup(c *caddy.Controller) error { websocks, err := webSocketParse(c) if err != nil { return err } GatewayInterface = caddy.AppName + "-CGI/1.1" ServerSoftware = caddy.AppName + "/" + caddy.AppVersion httpserver.GetConfig(c).AddMiddleware(func(next httpserver.Handler) httpserver.Handler { return WebSoc...
[ "func", "setup", "(", "c", "*", "caddy", ".", "Controller", ")", "error", "{", "websocks", ",", "err", ":=", "webSocketParse", "(", "c", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "GatewayInterface", "=", "caddy", "...
// setup configures a new WebSocket middleware instance.
[ "setup", "configures", "a", "new", "WebSocket", "middleware", "instance", "." ]
a2ed91bc45c8b3faa1577ed4c18334d38a581ca7
https://github.com/mholt/caddy/blob/a2ed91bc45c8b3faa1577ed4c18334d38a581ca7/caddyhttp/websocket/setup.go#L30-L44
124,844
mholt/caddy
caddyhttp/markdown/summary/summary.go
Markdown
func Markdown(input []byte, wordcount int) []byte { words := bytes.Fields(blackfriday.Markdown(input, renderer{}, 0)) if wordcount > len(words) { wordcount = len(words) } return bytes.Join(words[0:wordcount], []byte{' '}) }
go
func Markdown(input []byte, wordcount int) []byte { words := bytes.Fields(blackfriday.Markdown(input, renderer{}, 0)) if wordcount > len(words) { wordcount = len(words) } return bytes.Join(words[0:wordcount], []byte{' '}) }
[ "func", "Markdown", "(", "input", "[", "]", "byte", ",", "wordcount", "int", ")", "[", "]", "byte", "{", "words", ":=", "bytes", ".", "Fields", "(", "blackfriday", ".", "Markdown", "(", "input", ",", "renderer", "{", "}", ",", "0", ")", ")", "\n", ...
// Markdown formats input using a plain-text renderer, and // then returns up to the first `wordcount` words as a summary.
[ "Markdown", "formats", "input", "using", "a", "plain", "-", "text", "renderer", "and", "then", "returns", "up", "to", "the", "first", "wordcount", "words", "as", "a", "summary", "." ]
a2ed91bc45c8b3faa1577ed4c18334d38a581ca7
https://github.com/mholt/caddy/blob/a2ed91bc45c8b3faa1577ed4c18334d38a581ca7/caddyhttp/markdown/summary/summary.go#L25-L31
124,845
mholt/caddy
caddyhttp/browse/setup.go
setup
func setup(c *caddy.Controller) error { configs, err := browseParse(c) if err != nil { return err } b := Browse{ Configs: configs, IgnoreIndexes: false, } httpserver.GetConfig(c).AddMiddleware(func(next httpserver.Handler) httpserver.Handler { b.Next = next return b }) return nil }
go
func setup(c *caddy.Controller) error { configs, err := browseParse(c) if err != nil { return err } b := Browse{ Configs: configs, IgnoreIndexes: false, } httpserver.GetConfig(c).AddMiddleware(func(next httpserver.Handler) httpserver.Handler { b.Next = next return b }) return nil }
[ "func", "setup", "(", "c", "*", "caddy", ".", "Controller", ")", "error", "{", "configs", ",", "err", ":=", "browseParse", "(", "c", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "b", ":=", "Browse", "{", "Configs", ...
// setup configures a new Browse middleware instance.
[ "setup", "configures", "a", "new", "Browse", "middleware", "instance", "." ]
a2ed91bc45c8b3faa1577ed4c18334d38a581ca7
https://github.com/mholt/caddy/blob/a2ed91bc45c8b3faa1577ed4c18334d38a581ca7/caddyhttp/browse/setup.go#L36-L53
124,846
mholt/caddy
telemetry/collection.go
Init
func Init(instanceID uuid.UUID, disabledMetricsKeys []string) { if enabled { panic("already initialized") } if str := instanceID.String(); str == "" || str == "00000000-0000-0000-0000-000000000000" { panic("empty UUID") } instanceUUID = instanceID disabledMetricsMu.Lock() for _, key := range disabledMetric...
go
func Init(instanceID uuid.UUID, disabledMetricsKeys []string) { if enabled { panic("already initialized") } if str := instanceID.String(); str == "" || str == "00000000-0000-0000-0000-000000000000" { panic("empty UUID") } instanceUUID = instanceID disabledMetricsMu.Lock() for _, key := range disabledMetric...
[ "func", "Init", "(", "instanceID", "uuid", ".", "UUID", ",", "disabledMetricsKeys", "[", "]", "string", ")", "{", "if", "enabled", "{", "panic", "(", "\"", "\"", ")", "\n", "}", "\n", "if", "str", ":=", "instanceID", ".", "String", "(", ")", ";", "...
// Init initializes this package so that it may // be used. Do not call this function more than // once. Init panics if it is called more than // once or if the UUID value is empty. Once this // function is called, the rest of the package // may safely be used. If this function is not // called, the collector functions...
[ "Init", "initializes", "this", "package", "so", "that", "it", "may", "be", "used", ".", "Do", "not", "call", "this", "function", "more", "than", "once", ".", "Init", "panics", "if", "it", "is", "called", "more", "than", "once", "or", "if", "the", "UUID...
a2ed91bc45c8b3faa1577ed4c18334d38a581ca7
https://github.com/mholt/caddy/blob/a2ed91bc45c8b3faa1577ed4c18334d38a581ca7/telemetry/collection.go#L38-L53
124,847
mholt/caddy
telemetry/collection.go
Set
func Set(key string, val interface{}) { if !enabled || isDisabled(key) { return } bufferMu.Lock() if _, ok := buffer[key]; !ok { if bufferItemCount >= maxBufferItems { bufferMu.Unlock() return } bufferItemCount++ } buffer[key] = val bufferMu.Unlock() }
go
func Set(key string, val interface{}) { if !enabled || isDisabled(key) { return } bufferMu.Lock() if _, ok := buffer[key]; !ok { if bufferItemCount >= maxBufferItems { bufferMu.Unlock() return } bufferItemCount++ } buffer[key] = val bufferMu.Unlock() }
[ "func", "Set", "(", "key", "string", ",", "val", "interface", "{", "}", ")", "{", "if", "!", "enabled", "||", "isDisabled", "(", "key", ")", "{", "return", "\n", "}", "\n", "bufferMu", ".", "Lock", "(", ")", "\n", "if", "_", ",", "ok", ":=", "b...
// Set puts a value in the buffer to be included // in the next emission. It overwrites any // previous value. // // This function is safe for multiple goroutines, // and it is recommended to call this using the // go keyword after the call to SendHello so it // doesn't block crucial code.
[ "Set", "puts", "a", "value", "in", "the", "buffer", "to", "be", "included", "in", "the", "next", "emission", ".", "It", "overwrites", "any", "previous", "value", ".", "This", "function", "is", "safe", "for", "multiple", "goroutines", "and", "it", "is", "...
a2ed91bc45c8b3faa1577ed4c18334d38a581ca7
https://github.com/mholt/caddy/blob/a2ed91bc45c8b3faa1577ed4c18334d38a581ca7/telemetry/collection.go#L118-L132
124,848
mholt/caddy
telemetry/collection.go
SetNested
func SetNested(key, subkey string, val interface{}) { if !enabled || isDisabled(key) { return } bufferMu.Lock() if topLevel, ok1 := buffer[key]; ok1 { topLevelMap, ok2 := topLevel.(map[string]interface{}) if !ok2 { bufferMu.Unlock() log.Printf("[PANIC] Telemetry: key %s is already used for non-nested-ma...
go
func SetNested(key, subkey string, val interface{}) { if !enabled || isDisabled(key) { return } bufferMu.Lock() if topLevel, ok1 := buffer[key]; ok1 { topLevelMap, ok2 := topLevel.(map[string]interface{}) if !ok2 { bufferMu.Unlock() log.Printf("[PANIC] Telemetry: key %s is already used for non-nested-ma...
[ "func", "SetNested", "(", "key", ",", "subkey", "string", ",", "val", "interface", "{", "}", ")", "{", "if", "!", "enabled", "||", "isDisabled", "(", "key", ")", "{", "return", "\n", "}", "\n", "bufferMu", ".", "Lock", "(", ")", "\n", "if", "topLev...
// SetNested puts a value in the buffer to be included // in the next emission, nested under the top-level key // as subkey. It overwrites any previous value. // // This function is safe for multiple goroutines, // and it is recommended to call this using the // go keyword after the call to SendHello so it // doesn't b...
[ "SetNested", "puts", "a", "value", "in", "the", "buffer", "to", "be", "included", "in", "the", "next", "emission", "nested", "under", "the", "top", "-", "level", "key", "as", "subkey", ".", "It", "overwrites", "any", "previous", "value", ".", "This", "fu...
a2ed91bc45c8b3faa1577ed4c18334d38a581ca7
https://github.com/mholt/caddy/blob/a2ed91bc45c8b3faa1577ed4c18334d38a581ca7/telemetry/collection.go#L142-L173
124,849
mholt/caddy
telemetry/collection.go
Append
func Append(key string, value interface{}) { if !enabled || isDisabled(key) { return } bufferMu.Lock() if bufferItemCount >= maxBufferItems { bufferMu.Unlock() return } // TODO: Test this... bufVal, inBuffer := buffer[key] sliceVal, sliceOk := bufVal.([]interface{}) if inBuffer && !sliceOk { bufferMu.U...
go
func Append(key string, value interface{}) { if !enabled || isDisabled(key) { return } bufferMu.Lock() if bufferItemCount >= maxBufferItems { bufferMu.Unlock() return } // TODO: Test this... bufVal, inBuffer := buffer[key] sliceVal, sliceOk := bufVal.([]interface{}) if inBuffer && !sliceOk { bufferMu.U...
[ "func", "Append", "(", "key", "string", ",", "value", "interface", "{", "}", ")", "{", "if", "!", "enabled", "||", "isDisabled", "(", "key", ")", "{", "return", "\n", "}", "\n", "bufferMu", ".", "Lock", "(", ")", "\n", "if", "bufferItemCount", ">=", ...
// Append appends value to a list named key. // If key is new, a new list will be created. // If key maps to a type that is not a list, // a panic is logged, and this is a no-op.
[ "Append", "appends", "value", "to", "a", "list", "named", "key", ".", "If", "key", "is", "new", "a", "new", "list", "will", "be", "created", ".", "If", "key", "maps", "to", "a", "type", "that", "is", "not", "a", "list", "a", "panic", "is", "logged"...
a2ed91bc45c8b3faa1577ed4c18334d38a581ca7
https://github.com/mholt/caddy/blob/a2ed91bc45c8b3faa1577ed4c18334d38a581ca7/telemetry/collection.go#L179-L203
124,850
mholt/caddy
telemetry/collection.go
AppendUnique
func AppendUnique(key string, value interface{}) { if !enabled || isDisabled(key) { return } bufferMu.Lock() bufVal, inBuffer := buffer[key] setVal, setOk := bufVal.(countingSet) if inBuffer && !setOk { bufferMu.Unlock() log.Printf("[PANIC] Telemetry: key %s already used for non-counting-set value", key) ...
go
func AppendUnique(key string, value interface{}) { if !enabled || isDisabled(key) { return } bufferMu.Lock() bufVal, inBuffer := buffer[key] setVal, setOk := bufVal.(countingSet) if inBuffer && !setOk { bufferMu.Unlock() log.Printf("[PANIC] Telemetry: key %s already used for non-counting-set value", key) ...
[ "func", "AppendUnique", "(", "key", "string", ",", "value", "interface", "{", "}", ")", "{", "if", "!", "enabled", "||", "isDisabled", "(", "key", ")", "{", "return", "\n", "}", "\n", "bufferMu", ".", "Lock", "(", ")", "\n", "bufVal", ",", "inBuffer"...
// AppendUnique adds value to a set named key. // Set items are unordered. Values in the set // are unique, but how many times they are // appended is counted. The value must be // hashable. // // If key is new, a new set will be created for // values with that key. If key maps to a type // that is not a counting set, ...
[ "AppendUnique", "adds", "value", "to", "a", "set", "named", "key", ".", "Set", "items", "are", "unordered", ".", "Values", "in", "the", "set", "are", "unique", "but", "how", "many", "times", "they", "are", "appended", "is", "counted", ".", "The", "value"...
a2ed91bc45c8b3faa1577ed4c18334d38a581ca7
https://github.com/mholt/caddy/blob/a2ed91bc45c8b3faa1577ed4c18334d38a581ca7/telemetry/collection.go#L215-L240
124,851
mholt/caddy
telemetry/collection.go
FastHash
func FastHash(input []byte) string { h := fnv.New32a() if _, err := h.Write(input); err != nil { log.Println("[ERROR] failed to write bytes: ", err) } return fmt.Sprintf("%x", h.Sum32()) }
go
func FastHash(input []byte) string { h := fnv.New32a() if _, err := h.Write(input); err != nil { log.Println("[ERROR] failed to write bytes: ", err) } return fmt.Sprintf("%x", h.Sum32()) }
[ "func", "FastHash", "(", "input", "[", "]", "byte", ")", "string", "{", "h", ":=", "fnv", ".", "New32a", "(", ")", "\n", "if", "_", ",", "err", ":=", "h", ".", "Write", "(", "input", ")", ";", "err", "!=", "nil", "{", "log", ".", "Println", "...
// FastHash hashes input using a 32-bit hashing algorithm // that is fast, and returns the hash as a hex-encoded string. // Do not use this for cryptographic purposes.
[ "FastHash", "hashes", "input", "using", "a", "32", "-", "bit", "hashing", "algorithm", "that", "is", "fast", "and", "returns", "the", "hash", "as", "a", "hex", "-", "encoded", "string", ".", "Do", "not", "use", "this", "for", "cryptographic", "purposes", ...
a2ed91bc45c8b3faa1577ed4c18334d38a581ca7
https://github.com/mholt/caddy/blob/a2ed91bc45c8b3faa1577ed4c18334d38a581ca7/telemetry/collection.go#L284-L291
124,852
mholt/caddy
telemetry/collection.go
isDisabled
func isDisabled(key string) bool { // for keys that are augmented with data, such as // "tls_client_hello_ua:<hash>", just // check the prefix "tls_client_hello_ua" checkKey := key if idx := strings.Index(key, ":"); idx > -1 { checkKey = key[:idx] } disabledMetricsMu.RLock() _, ok := disabledMetrics[checkKey...
go
func isDisabled(key string) bool { // for keys that are augmented with data, such as // "tls_client_hello_ua:<hash>", just // check the prefix "tls_client_hello_ua" checkKey := key if idx := strings.Index(key, ":"); idx > -1 { checkKey = key[:idx] } disabledMetricsMu.RLock() _, ok := disabledMetrics[checkKey...
[ "func", "isDisabled", "(", "key", "string", ")", "bool", "{", "// for keys that are augmented with data, such as", "// \"tls_client_hello_ua:<hash>\", just", "// check the prefix \"tls_client_hello_ua\"", "checkKey", ":=", "key", "\n", "if", "idx", ":=", "strings", ".", "Inde...
// isDisabled returns whether key is // a disabled metric key. ALL collection // functions should call this and not // save the value if this returns true.
[ "isDisabled", "returns", "whether", "key", "is", "a", "disabled", "metric", "key", ".", "ALL", "collection", "functions", "should", "call", "this", "and", "not", "save", "the", "value", "if", "this", "returns", "true", "." ]
a2ed91bc45c8b3faa1577ed4c18334d38a581ca7
https://github.com/mholt/caddy/blob/a2ed91bc45c8b3faa1577ed4c18334d38a581ca7/telemetry/collection.go#L297-L310
124,853
mholt/caddy
caddyhttp/markdown/metadata/metadata_none.go
Init
func (n *NoneParser) Init(b *bytes.Buffer) bool { m := make(map[string]interface{}) n.metadata = NewMetadata(m) n.markdown = bytes.NewBuffer(b.Bytes()) return true }
go
func (n *NoneParser) Init(b *bytes.Buffer) bool { m := make(map[string]interface{}) n.metadata = NewMetadata(m) n.markdown = bytes.NewBuffer(b.Bytes()) return true }
[ "func", "(", "n", "*", "NoneParser", ")", "Init", "(", "b", "*", "bytes", ".", "Buffer", ")", "bool", "{", "m", ":=", "make", "(", "map", "[", "string", "]", "interface", "{", "}", ")", "\n", "n", ".", "metadata", "=", "NewMetadata", "(", "m", ...
// Init preparses and parses the metadata and markdown file
[ "Init", "preparses", "and", "parses", "the", "metadata", "and", "markdown", "file" ]
a2ed91bc45c8b3faa1577ed4c18334d38a581ca7
https://github.com/mholt/caddy/blob/a2ed91bc45c8b3faa1577ed4c18334d38a581ca7/caddyhttp/markdown/metadata/metadata_none.go#L33-L39
124,854
mholt/caddy
caddyfile/parse.go
Parse
func Parse(filename string, input io.Reader, validDirectives []string) ([]ServerBlock, error) { p := parser{Dispenser: NewDispenser(filename, input), validDirectives: validDirectives} return p.parseAll() }
go
func Parse(filename string, input io.Reader, validDirectives []string) ([]ServerBlock, error) { p := parser{Dispenser: NewDispenser(filename, input), validDirectives: validDirectives} return p.parseAll() }
[ "func", "Parse", "(", "filename", "string", ",", "input", "io", ".", "Reader", ",", "validDirectives", "[", "]", "string", ")", "(", "[", "]", "ServerBlock", ",", "error", ")", "{", "p", ":=", "parser", "{", "Dispenser", ":", "NewDispenser", "(", "file...
// Parse parses the input just enough to group tokens, in // order, by server block. No further parsing is performed. // Server blocks are returned in the order in which they appear. // Directives that do not appear in validDirectives will cause // an error. If you do not want to check for valid directives, // pass in ...
[ "Parse", "parses", "the", "input", "just", "enough", "to", "group", "tokens", "in", "order", "by", "server", "block", ".", "No", "further", "parsing", "is", "performed", ".", "Server", "blocks", "are", "returned", "in", "the", "order", "in", "which", "they...
a2ed91bc45c8b3faa1577ed4c18334d38a581ca7
https://github.com/mholt/caddy/blob/a2ed91bc45c8b3faa1577ed4c18334d38a581ca7/caddyfile/parse.go#L33-L36
124,855
mholt/caddy
caddyfile/parse.go
allTokens
func allTokens(input io.Reader) ([]Token, error) { l := new(lexer) err := l.load(input) if err != nil { return nil, err } var tokens []Token for l.next() { tokens = append(tokens, l.token) } return tokens, nil }
go
func allTokens(input io.Reader) ([]Token, error) { l := new(lexer) err := l.load(input) if err != nil { return nil, err } var tokens []Token for l.next() { tokens = append(tokens, l.token) } return tokens, nil }
[ "func", "allTokens", "(", "input", "io", ".", "Reader", ")", "(", "[", "]", "Token", ",", "error", ")", "{", "l", ":=", "new", "(", "lexer", ")", "\n", "err", ":=", "l", ".", "load", "(", "input", ")", "\n", "if", "err", "!=", "nil", "{", "re...
// allTokens lexes the entire input, but does not parse it. // It returns all the tokens from the input, unstructured // and in order.
[ "allTokens", "lexes", "the", "entire", "input", "but", "does", "not", "parse", "it", ".", "It", "returns", "all", "the", "tokens", "from", "the", "input", "unstructured", "and", "in", "order", "." ]
a2ed91bc45c8b3faa1577ed4c18334d38a581ca7
https://github.com/mholt/caddy/blob/a2ed91bc45c8b3faa1577ed4c18334d38a581ca7/caddyfile/parse.go#L41-L52
124,856
mholt/caddy
caddyfile/parse.go
directives
func (p *parser) directives() error { for p.Next() { // end of server block if p.Val() == "}" { break } // special case: import directive replaces tokens during parse-time if p.Val() == "import" { err := p.doImport() if err != nil { return err } p.cursor-- // cursor is advanced when we co...
go
func (p *parser) directives() error { for p.Next() { // end of server block if p.Val() == "}" { break } // special case: import directive replaces tokens during parse-time if p.Val() == "import" { err := p.doImport() if err != nil { return err } p.cursor-- // cursor is advanced when we co...
[ "func", "(", "p", "*", "parser", ")", "directives", "(", ")", "error", "{", "for", "p", ".", "Next", "(", ")", "{", "// end of server block", "if", "p", ".", "Val", "(", ")", "==", "\"", "\"", "{", "break", "\n", "}", "\n\n", "// special case: import...
// directives parses through all the lines for directives // and it expects the next token to be the first // directive. It goes until EOF or closing curly brace // which ends the server block.
[ "directives", "parses", "through", "all", "the", "lines", "for", "directives", "and", "it", "expects", "the", "next", "token", "to", "be", "the", "first", "directive", ".", "It", "goes", "until", "EOF", "or", "closing", "curly", "brace", "which", "ends", "...
a2ed91bc45c8b3faa1577ed4c18334d38a581ca7
https://github.com/mholt/caddy/blob/a2ed91bc45c8b3faa1577ed4c18334d38a581ca7/caddyfile/parse.go#L202-L225
124,857
mholt/caddy
caddyfile/parse.go
doSingleImport
func (p *parser) doSingleImport(importFile string) ([]Token, error) { file, err := os.Open(importFile) if err != nil { return nil, p.Errf("Could not import %s: %v", importFile, err) } defer file.Close() if info, err := file.Stat(); err != nil { return nil, p.Errf("Could not import %s: %v", importFile, err) }...
go
func (p *parser) doSingleImport(importFile string) ([]Token, error) { file, err := os.Open(importFile) if err != nil { return nil, p.Errf("Could not import %s: %v", importFile, err) } defer file.Close() if info, err := file.Stat(); err != nil { return nil, p.Errf("Could not import %s: %v", importFile, err) }...
[ "func", "(", "p", "*", "parser", ")", "doSingleImport", "(", "importFile", "string", ")", "(", "[", "]", "Token", ",", "error", ")", "{", "file", ",", "err", ":=", "os", ".", "Open", "(", "importFile", ")", "\n", "if", "err", "!=", "nil", "{", "r...
// doSingleImport lexes the individual file at importFile and returns // its tokens or an error, if any.
[ "doSingleImport", "lexes", "the", "individual", "file", "at", "importFile", "and", "returns", "its", "tokens", "or", "an", "error", "if", "any", "." ]
a2ed91bc45c8b3faa1577ed4c18334d38a581ca7
https://github.com/mholt/caddy/blob/a2ed91bc45c8b3faa1577ed4c18334d38a581ca7/caddyfile/parse.go#L308-L337
124,858
mholt/caddy
caddyfile/parse.go
validDirective
func (p *parser) validDirective(dir string) bool { if p.validDirectives == nil { return true } for _, d := range p.validDirectives { if d == dir { return true } } return false }
go
func (p *parser) validDirective(dir string) bool { if p.validDirectives == nil { return true } for _, d := range p.validDirectives { if d == dir { return true } } return false }
[ "func", "(", "p", "*", "parser", ")", "validDirective", "(", "dir", "string", ")", "bool", "{", "if", "p", ".", "validDirectives", "==", "nil", "{", "return", "true", "\n", "}", "\n", "for", "_", ",", "d", ":=", "range", "p", ".", "validDirectives", ...
// validDirective returns true if dir is in p.validDirectives.
[ "validDirective", "returns", "true", "if", "dir", "is", "in", "p", ".", "validDirectives", "." ]
a2ed91bc45c8b3faa1577ed4c18334d38a581ca7
https://github.com/mholt/caddy/blob/a2ed91bc45c8b3faa1577ed4c18334d38a581ca7/caddyfile/parse.go#L408-L418
124,859
mholt/caddy
caddyfile/parse.go
snippetTokens
func (p *parser) snippetTokens() ([]Token, error) { // TODO: disallow imports in snippets for simplicity at import time // snippet must have curlies. err := p.openCurlyBrace() if err != nil { return nil, err } count := 1 tokens := []Token{} for p.Next() { if p.Val() == "}" { count-- if count == 0 { ...
go
func (p *parser) snippetTokens() ([]Token, error) { // TODO: disallow imports in snippets for simplicity at import time // snippet must have curlies. err := p.openCurlyBrace() if err != nil { return nil, err } count := 1 tokens := []Token{} for p.Next() { if p.Val() == "}" { count-- if count == 0 { ...
[ "func", "(", "p", "*", "parser", ")", "snippetTokens", "(", ")", "(", "[", "]", "Token", ",", "error", ")", "{", "// TODO: disallow imports in snippets for simplicity at import time", "// snippet must have curlies.", "err", ":=", "p", ".", "openCurlyBrace", "(", ")"...
// read and store everything in a block for later replay.
[ "read", "and", "store", "everything", "in", "a", "block", "for", "later", "replay", "." ]
a2ed91bc45c8b3faa1577ed4c18334d38a581ca7
https://github.com/mholt/caddy/blob/a2ed91bc45c8b3faa1577ed4c18334d38a581ca7/caddyfile/parse.go#L467-L493
124,860
mholt/caddy
rlimit_posix.go
checkFdlimit
func checkFdlimit() { const min = 8192 // Warn if ulimit is too low for production sites rlimit := &syscall.Rlimit{} err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, rlimit) if err == nil && rlimit.Cur < min { fmt.Printf("WARNING: File descriptor limit %d is too low for production servers. "+ "At least %d is ...
go
func checkFdlimit() { const min = 8192 // Warn if ulimit is too low for production sites rlimit := &syscall.Rlimit{} err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, rlimit) if err == nil && rlimit.Cur < min { fmt.Printf("WARNING: File descriptor limit %d is too low for production servers. "+ "At least %d is ...
[ "func", "checkFdlimit", "(", ")", "{", "const", "min", "=", "8192", "\n\n", "// Warn if ulimit is too low for production sites", "rlimit", ":=", "&", "syscall", ".", "Rlimit", "{", "}", "\n", "err", ":=", "syscall", ".", "Getrlimit", "(", "syscall", ".", "RLIM...
// checkFdlimit issues a warning if the OS limit for // max file descriptors is below a recommended minimum.
[ "checkFdlimit", "issues", "a", "warning", "if", "the", "OS", "limit", "for", "max", "file", "descriptors", "is", "below", "a", "recommended", "minimum", "." ]
a2ed91bc45c8b3faa1577ed4c18334d38a581ca7
https://github.com/mholt/caddy/blob/a2ed91bc45c8b3faa1577ed4c18334d38a581ca7/rlimit_posix.go#L26-L37
124,861
mholt/caddy
caddyhttp/httpserver/replacer.go
unescapeBraces
func unescapeBraces(s string) string { s = strings.Replace(s, "\\{", "{", -1) s = strings.Replace(s, "\\}", "}", -1) return s }
go
func unescapeBraces(s string) string { s = strings.Replace(s, "\\{", "{", -1) s = strings.Replace(s, "\\}", "}", -1) return s }
[ "func", "unescapeBraces", "(", "s", "string", ")", "string", "{", "s", "=", "strings", ".", "Replace", "(", "s", ",", "\"", "\\\\", "\"", ",", "\"", "\"", ",", "-", "1", ")", "\n", "s", "=", "strings", ".", "Replace", "(", "s", ",", "\"", "\\\\...
// unescapeBraces finds escaped braces in s and returns // a string with those braces unescaped.
[ "unescapeBraces", "finds", "escaped", "braces", "in", "s", "and", "returns", "a", "string", "with", "those", "braces", "unescaped", "." ]
a2ed91bc45c8b3faa1577ed4c18334d38a581ca7
https://github.com/mholt/caddy/blob/a2ed91bc45c8b3faa1577ed4c18334d38a581ca7/caddyhttp/httpserver/replacer.go#L150-L154
124,862
mholt/caddy
caddyhttp/httpserver/replacer.go
round
func round(d, r time.Duration) time.Duration { if r <= 0 { return d } neg := d < 0 if neg { d = -d } if m := d % r; m+m < r { d = d - m } else { d = d + r - m } if neg { return -d } return d }
go
func round(d, r time.Duration) time.Duration { if r <= 0 { return d } neg := d < 0 if neg { d = -d } if m := d % r; m+m < r { d = d - m } else { d = d + r - m } if neg { return -d } return d }
[ "func", "round", "(", "d", ",", "r", "time", ".", "Duration", ")", "time", ".", "Duration", "{", "if", "r", "<=", "0", "{", "return", "d", "\n", "}", "\n", "neg", ":=", "d", "<", "0", "\n", "if", "neg", "{", "d", "=", "-", "d", "\n", "}", ...
// round rounds d to the nearest r
[ "round", "rounds", "d", "to", "the", "nearest", "r" ]
a2ed91bc45c8b3faa1577ed4c18334d38a581ca7
https://github.com/mholt/caddy/blob/a2ed91bc45c8b3faa1577ed4c18334d38a581ca7/caddyhttp/httpserver/replacer.go#L231-L248
124,863
mholt/caddy
caddyhttp/httpserver/replacer.go
getPeerCert
func (r *replacer) getPeerCert() *x509.Certificate { if r.request.TLS != nil && len(r.request.TLS.PeerCertificates) > 0 { return r.request.TLS.PeerCertificates[0] } return nil }
go
func (r *replacer) getPeerCert() *x509.Certificate { if r.request.TLS != nil && len(r.request.TLS.PeerCertificates) > 0 { return r.request.TLS.PeerCertificates[0] } return nil }
[ "func", "(", "r", "*", "replacer", ")", "getPeerCert", "(", ")", "*", "x509", ".", "Certificate", "{", "if", "r", ".", "request", ".", "TLS", "!=", "nil", "&&", "len", "(", "r", ".", "request", ".", "TLS", ".", "PeerCertificates", ")", ">", "0", ...
// getPeerCert returns peer certificate
[ "getPeerCert", "returns", "peer", "certificate" ]
a2ed91bc45c8b3faa1577ed4c18334d38a581ca7
https://github.com/mholt/caddy/blob/a2ed91bc45c8b3faa1577ed4c18334d38a581ca7/caddyhttp/httpserver/replacer.go#L251-L257
124,864
mholt/caddy
caddyhttp/httpserver/replacer.go
Set
func (r *replacer) Set(key, value string) { r.customReplacements["{"+key+"}"] = value }
go
func (r *replacer) Set(key, value string) { r.customReplacements["{"+key+"}"] = value }
[ "func", "(", "r", "*", "replacer", ")", "Set", "(", "key", ",", "value", "string", ")", "{", "r", ".", "customReplacements", "[", "\"", "\"", "+", "key", "+", "\"", "\"", "]", "=", "value", "\n", "}" ]
// Set sets key to value in the r.customReplacements map.
[ "Set", "sets", "key", "to", "value", "in", "the", "r", ".", "customReplacements", "map", "." ]
a2ed91bc45c8b3faa1577ed4c18334d38a581ca7
https://github.com/mholt/caddy/blob/a2ed91bc45c8b3faa1577ed4c18334d38a581ca7/caddyhttp/httpserver/replacer.go#L548-L550
124,865
mholt/caddy
caddyhttp/rewrite/setup.go
setup
func setup(c *caddy.Controller) error { rewrites, err := rewriteParse(c) if err != nil { return err } cfg := httpserver.GetConfig(c) cfg.AddMiddleware(func(next httpserver.Handler) httpserver.Handler { return Rewrite{ Next: next, FileSys: http.Dir(cfg.Root), Rules: rewrites, } }) return ni...
go
func setup(c *caddy.Controller) error { rewrites, err := rewriteParse(c) if err != nil { return err } cfg := httpserver.GetConfig(c) cfg.AddMiddleware(func(next httpserver.Handler) httpserver.Handler { return Rewrite{ Next: next, FileSys: http.Dir(cfg.Root), Rules: rewrites, } }) return ni...
[ "func", "setup", "(", "c", "*", "caddy", ".", "Controller", ")", "error", "{", "rewrites", ",", "err", ":=", "rewriteParse", "(", "c", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "cfg", ":=", "httpserver", ".", "Ge...
// setup configures a new Rewrite middleware instance.
[ "setup", "configures", "a", "new", "Rewrite", "middleware", "instance", "." ]
a2ed91bc45c8b3faa1577ed4c18334d38a581ca7
https://github.com/mholt/caddy/blob/a2ed91bc45c8b3faa1577ed4c18334d38a581ca7/caddyhttp/rewrite/setup.go#L33-L50
124,866
mholt/caddy
telemetry/telemetry.go
logEmit
func logEmit(final bool) { err := emit(final) if err != nil { log.Printf("[ERROR] Sending telemetry: %v", err) } }
go
func logEmit(final bool) { err := emit(final) if err != nil { log.Printf("[ERROR] Sending telemetry: %v", err) } }
[ "func", "logEmit", "(", "final", "bool", ")", "{", "err", ":=", "emit", "(", "final", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Printf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "}" ]
// logEmit calls emit and then logs the error, if any. // See docs for emit.
[ "logEmit", "calls", "emit", "and", "then", "logs", "the", "error", "if", "any", ".", "See", "docs", "for", "emit", "." ]
a2ed91bc45c8b3faa1577ed4c18334d38a581ca7
https://github.com/mholt/caddy/blob/a2ed91bc45c8b3faa1577ed4c18334d38a581ca7/telemetry/telemetry.go#L54-L59
124,867
mholt/caddy
telemetry/telemetry.go
setEmitTimeMetrics
func setEmitTimeMetrics() { Set("goroutines", runtime.NumGoroutine()) var mem runtime.MemStats runtime.ReadMemStats(&mem) SetNested("memory", "heap_alloc", mem.HeapAlloc) SetNested("memory", "sys", mem.Sys) }
go
func setEmitTimeMetrics() { Set("goroutines", runtime.NumGoroutine()) var mem runtime.MemStats runtime.ReadMemStats(&mem) SetNested("memory", "heap_alloc", mem.HeapAlloc) SetNested("memory", "sys", mem.Sys) }
[ "func", "setEmitTimeMetrics", "(", ")", "{", "Set", "(", "\"", "\"", ",", "runtime", ".", "NumGoroutine", "(", ")", ")", "\n\n", "var", "mem", "runtime", ".", "MemStats", "\n", "runtime", ".", "ReadMemStats", "(", "&", "mem", ")", "\n", "SetNested", "(...
// setEmitTimeMetrics sets some metrics that should // be recorded just before emitting.
[ "setEmitTimeMetrics", "sets", "some", "metrics", "that", "should", "be", "recorded", "just", "before", "emitting", "." ]
a2ed91bc45c8b3faa1577ed4c18334d38a581ca7
https://github.com/mholt/caddy/blob/a2ed91bc45c8b3faa1577ed4c18334d38a581ca7/telemetry/telemetry.go#L237-L244
124,868
mholt/caddy
telemetry/telemetry.go
makePayloadAndResetBuffer
func makePayloadAndResetBuffer() ([]byte, error) { bufCopy := resetBuffer() // encode payload in preparation for transmission payload := Payload{ InstanceID: instanceUUID.String(), Timestamp: time.Now().UTC(), Data: bufCopy, } return json.Marshal(payload) }
go
func makePayloadAndResetBuffer() ([]byte, error) { bufCopy := resetBuffer() // encode payload in preparation for transmission payload := Payload{ InstanceID: instanceUUID.String(), Timestamp: time.Now().UTC(), Data: bufCopy, } return json.Marshal(payload) }
[ "func", "makePayloadAndResetBuffer", "(", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "bufCopy", ":=", "resetBuffer", "(", ")", "\n\n", "// encode payload in preparation for transmission", "payload", ":=", "Payload", "{", "InstanceID", ":", "instanceUUID", ...
// makePayloadAndResetBuffer prepares a payload // by emptying the collection buffer. It returns // the bytes of the payload to send to the server. // Since the buffer is reset by this, if the // resulting byte slice is lost, the payload is // gone with it.
[ "makePayloadAndResetBuffer", "prepares", "a", "payload", "by", "emptying", "the", "collection", "buffer", ".", "It", "returns", "the", "bytes", "of", "the", "payload", "to", "send", "to", "the", "server", ".", "Since", "the", "buffer", "is", "reset", "by", "...
a2ed91bc45c8b3faa1577ed4c18334d38a581ca7
https://github.com/mholt/caddy/blob/a2ed91bc45c8b3faa1577ed4c18334d38a581ca7/telemetry/telemetry.go#L252-L262
124,869
mholt/caddy
telemetry/telemetry.go
resetBuffer
func resetBuffer() map[string]interface{} { bufferMu.Lock() bufCopy := buffer buffer = make(map[string]interface{}) bufferItemCount = 0 bufferMu.Unlock() return bufCopy }
go
func resetBuffer() map[string]interface{} { bufferMu.Lock() bufCopy := buffer buffer = make(map[string]interface{}) bufferItemCount = 0 bufferMu.Unlock() return bufCopy }
[ "func", "resetBuffer", "(", ")", "map", "[", "string", "]", "interface", "{", "}", "{", "bufferMu", ".", "Lock", "(", ")", "\n", "bufCopy", ":=", "buffer", "\n", "buffer", "=", "make", "(", "map", "[", "string", "]", "interface", "{", "}", ")", "\n...
// resetBuffer makes a local pointer to the buffer, // then resets the buffer by assigning to be a newly- // made value to clear it out, then sets the buffer // item count to 0. It returns the copied pointer to // the original map so the old buffer value can be // used locally.
[ "resetBuffer", "makes", "a", "local", "pointer", "to", "the", "buffer", "then", "resets", "the", "buffer", "by", "assigning", "to", "be", "a", "newly", "-", "made", "value", "to", "clear", "it", "out", "then", "sets", "the", "buffer", "item", "count", "t...
a2ed91bc45c8b3faa1577ed4c18334d38a581ca7
https://github.com/mholt/caddy/blob/a2ed91bc45c8b3faa1577ed4c18334d38a581ca7/telemetry/telemetry.go#L270-L277
124,870
mholt/caddy
telemetry/telemetry.go
Int
func (p Payload) Int(key string) int { val, _ := p.Data[key] switch p.Data[key].(type) { case int: return val.(int) case float64: // after JSON-decoding, int becomes float64... return int(val.(float64)) } return 0 }
go
func (p Payload) Int(key string) int { val, _ := p.Data[key] switch p.Data[key].(type) { case int: return val.(int) case float64: // after JSON-decoding, int becomes float64... return int(val.(float64)) } return 0 }
[ "func", "(", "p", "Payload", ")", "Int", "(", "key", "string", ")", "int", "{", "val", ",", "_", ":=", "p", ".", "Data", "[", "key", "]", "\n", "switch", "p", ".", "Data", "[", "key", "]", ".", "(", "type", ")", "{", "case", "int", ":", "re...
// Int returns the value of the data keyed by key // if it is an integer; otherwise it returns 0.
[ "Int", "returns", "the", "value", "of", "the", "data", "keyed", "by", "key", "if", "it", "is", "an", "integer", ";", "otherwise", "it", "returns", "0", "." ]
a2ed91bc45c8b3faa1577ed4c18334d38a581ca7
https://github.com/mholt/caddy/blob/a2ed91bc45c8b3faa1577ed4c18334d38a581ca7/telemetry/telemetry.go#L326-L335
124,871
mholt/caddy
telemetry/telemetry.go
MarshalJSON
func (s countingSet) MarshalJSON() ([]byte, error) { type Item struct { Value interface{} `json:"value"` Count int `json:"count"` } var list []Item for k, v := range s { list = append(list, Item{Value: k, Count: v}) } return json.Marshal(list) }
go
func (s countingSet) MarshalJSON() ([]byte, error) { type Item struct { Value interface{} `json:"value"` Count int `json:"count"` } var list []Item for k, v := range s { list = append(list, Item{Value: k, Count: v}) } return json.Marshal(list) }
[ "func", "(", "s", "countingSet", ")", "MarshalJSON", "(", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "type", "Item", "struct", "{", "Value", "interface", "{", "}", "`json:\"value\"`", "\n", "Count", "int", "`json:\"count\"`", "\n", "}", "\n", ...
// MarshalJSON implements the json.Marshaler interface. // It converts the set to an array so that the values // are JSON object values instead of keys, since keys // are difficult to query in databases.
[ "MarshalJSON", "implements", "the", "json", ".", "Marshaler", "interface", ".", "It", "converts", "the", "set", "to", "an", "array", "so", "that", "the", "values", "are", "JSON", "object", "values", "instead", "of", "keys", "since", "keys", "are", "difficult...
a2ed91bc45c8b3faa1577ed4c18334d38a581ca7
https://github.com/mholt/caddy/blob/a2ed91bc45c8b3faa1577ed4c18334d38a581ca7/telemetry/telemetry.go#L347-L359
124,872
mholt/caddy
caddyhttp/proxy/policy.go
Select
func (r *RoundRobin) Select(pool HostPool, request *http.Request) *UpstreamHost { poolLen := uint32(len(pool)) r.mutex.Lock() defer r.mutex.Unlock() // Return next available host for i := uint32(0); i < poolLen; i++ { r.robin++ host := pool[r.robin%poolLen] if host.Available() { return host } } return...
go
func (r *RoundRobin) Select(pool HostPool, request *http.Request) *UpstreamHost { poolLen := uint32(len(pool)) r.mutex.Lock() defer r.mutex.Unlock() // Return next available host for i := uint32(0); i < poolLen; i++ { r.robin++ host := pool[r.robin%poolLen] if host.Available() { return host } } return...
[ "func", "(", "r", "*", "RoundRobin", ")", "Select", "(", "pool", "HostPool", ",", "request", "*", "http", ".", "Request", ")", "*", "UpstreamHost", "{", "poolLen", ":=", "uint32", "(", "len", "(", "pool", ")", ")", "\n", "r", ".", "mutex", ".", "Lo...
// Select selects an up host from the pool using a round-robin ordering scheme.
[ "Select", "selects", "an", "up", "host", "from", "the", "pool", "using", "a", "round", "-", "robin", "ordering", "scheme", "." ]
a2ed91bc45c8b3faa1577ed4c18334d38a581ca7
https://github.com/mholt/caddy/blob/a2ed91bc45c8b3faa1577ed4c18334d38a581ca7/caddyhttp/proxy/policy.go#L111-L124
124,873
mholt/caddy
caddyhttp/proxy/policy.go
hostByHashing
func hostByHashing(pool HostPool, s string) *UpstreamHost { poolLen := uint32(len(pool)) index := hash(s) % poolLen for i := uint32(0); i < poolLen; i++ { index += i host := pool[index%poolLen] if host.Available() { return host } } return nil }
go
func hostByHashing(pool HostPool, s string) *UpstreamHost { poolLen := uint32(len(pool)) index := hash(s) % poolLen for i := uint32(0); i < poolLen; i++ { index += i host := pool[index%poolLen] if host.Available() { return host } } return nil }
[ "func", "hostByHashing", "(", "pool", "HostPool", ",", "s", "string", ")", "*", "UpstreamHost", "{", "poolLen", ":=", "uint32", "(", "len", "(", "pool", ")", ")", "\n", "index", ":=", "hash", "(", "s", ")", "%", "poolLen", "\n", "for", "i", ":=", "...
// hostByHashing returns an available host from pool based on a hashable string
[ "hostByHashing", "returns", "an", "available", "host", "from", "pool", "based", "on", "a", "hashable", "string" ]
a2ed91bc45c8b3faa1577ed4c18334d38a581ca7
https://github.com/mholt/caddy/blob/a2ed91bc45c8b3faa1577ed4c18334d38a581ca7/caddyhttp/proxy/policy.go#L127-L138
124,874
mholt/caddy
caddyhttp/proxy/policy.go
hash
func hash(s string) uint32 { h := fnv.New32a() if _, err := h.Write([]byte(s)); err != nil { log.Println("[ERROR] failed to write bytes: ", err) } return h.Sum32() }
go
func hash(s string) uint32 { h := fnv.New32a() if _, err := h.Write([]byte(s)); err != nil { log.Println("[ERROR] failed to write bytes: ", err) } return h.Sum32() }
[ "func", "hash", "(", "s", "string", ")", "uint32", "{", "h", ":=", "fnv", ".", "New32a", "(", ")", "\n", "if", "_", ",", "err", ":=", "h", ".", "Write", "(", "[", "]", "byte", "(", "s", ")", ")", ";", "err", "!=", "nil", "{", "log", ".", ...
// hash calculates a hash based on string s
[ "hash", "calculates", "a", "hash", "based", "on", "string", "s" ]
a2ed91bc45c8b3faa1577ed4c18334d38a581ca7
https://github.com/mholt/caddy/blob/a2ed91bc45c8b3faa1577ed4c18334d38a581ca7/caddyhttp/proxy/policy.go#L141-L147
124,875
mholt/caddy
caddyhttp/proxy/policy.go
Select
func (r *IPHash) Select(pool HostPool, request *http.Request) *UpstreamHost { clientIP, _, err := net.SplitHostPort(request.RemoteAddr) if err != nil { clientIP = request.RemoteAddr } return hostByHashing(pool, clientIP) }
go
func (r *IPHash) Select(pool HostPool, request *http.Request) *UpstreamHost { clientIP, _, err := net.SplitHostPort(request.RemoteAddr) if err != nil { clientIP = request.RemoteAddr } return hostByHashing(pool, clientIP) }
[ "func", "(", "r", "*", "IPHash", ")", "Select", "(", "pool", "HostPool", ",", "request", "*", "http", ".", "Request", ")", "*", "UpstreamHost", "{", "clientIP", ",", "_", ",", "err", ":=", "net", ".", "SplitHostPort", "(", "request", ".", "RemoteAddr",...
// Select selects an up host from the pool based on hashing the request IP
[ "Select", "selects", "an", "up", "host", "from", "the", "pool", "based", "on", "hashing", "the", "request", "IP" ]
a2ed91bc45c8b3faa1577ed4c18334d38a581ca7
https://github.com/mholt/caddy/blob/a2ed91bc45c8b3faa1577ed4c18334d38a581ca7/caddyhttp/proxy/policy.go#L153-L159
124,876
mholt/caddy
caddyhttp/proxy/policy.go
Select
func (r *URIHash) Select(pool HostPool, request *http.Request) *UpstreamHost { return hostByHashing(pool, request.RequestURI) }
go
func (r *URIHash) Select(pool HostPool, request *http.Request) *UpstreamHost { return hostByHashing(pool, request.RequestURI) }
[ "func", "(", "r", "*", "URIHash", ")", "Select", "(", "pool", "HostPool", ",", "request", "*", "http", ".", "Request", ")", "*", "UpstreamHost", "{", "return", "hostByHashing", "(", "pool", ",", "request", ".", "RequestURI", ")", "\n", "}" ]
// Select selects the host based on hashing the URI
[ "Select", "selects", "the", "host", "based", "on", "hashing", "the", "URI" ]
a2ed91bc45c8b3faa1577ed4c18334d38a581ca7
https://github.com/mholt/caddy/blob/a2ed91bc45c8b3faa1577ed4c18334d38a581ca7/caddyhttp/proxy/policy.go#L165-L167
124,877
mholt/caddy
caddyhttp/proxy/policy.go
Select
func (r *First) Select(pool HostPool, request *http.Request) *UpstreamHost { for _, host := range pool { if host.Available() { return host } } return nil }
go
func (r *First) Select(pool HostPool, request *http.Request) *UpstreamHost { for _, host := range pool { if host.Available() { return host } } return nil }
[ "func", "(", "r", "*", "First", ")", "Select", "(", "pool", "HostPool", ",", "request", "*", "http", ".", "Request", ")", "*", "UpstreamHost", "{", "for", "_", ",", "host", ":=", "range", "pool", "{", "if", "host", ".", "Available", "(", ")", "{", ...
// Select selects the first available host from the pool
[ "Select", "selects", "the", "first", "available", "host", "from", "the", "pool" ]
a2ed91bc45c8b3faa1577ed4c18334d38a581ca7
https://github.com/mholt/caddy/blob/a2ed91bc45c8b3faa1577ed4c18334d38a581ca7/caddyhttp/proxy/policy.go#L173-L180
124,878
mholt/caddy
caddyhttp/proxy/policy.go
Select
func (r *Header) Select(pool HostPool, request *http.Request) *UpstreamHost { if r.Name == "" { return nil } val := request.Header.Get(r.Name) if val == "" { // fallback to RoundRobin policy in case no Header in request return roundRobinPolicier.Select(pool, request) } return hostByHashing(pool, val) }
go
func (r *Header) Select(pool HostPool, request *http.Request) *UpstreamHost { if r.Name == "" { return nil } val := request.Header.Get(r.Name) if val == "" { // fallback to RoundRobin policy in case no Header in request return roundRobinPolicier.Select(pool, request) } return hostByHashing(pool, val) }
[ "func", "(", "r", "*", "Header", ")", "Select", "(", "pool", "HostPool", ",", "request", "*", "http", ".", "Request", ")", "*", "UpstreamHost", "{", "if", "r", ".", "Name", "==", "\"", "\"", "{", "return", "nil", "\n", "}", "\n", "val", ":=", "re...
// Select selects the host based on hashing the header value
[ "Select", "selects", "the", "host", "based", "on", "hashing", "the", "header", "value" ]
a2ed91bc45c8b3faa1577ed4c18334d38a581ca7
https://github.com/mholt/caddy/blob/a2ed91bc45c8b3faa1577ed4c18334d38a581ca7/caddyhttp/proxy/policy.go#L192-L202
124,879
mholt/caddy
caddyhttp/markdown/metadata/metadata_toml.go
Init
func (t *TOMLParser) Init(b *bytes.Buffer) bool { meta, data := splitBuffer(b, "+++") if meta == nil || data == nil { return false } t.markdown = data m := make(map[string]interface{}) if err := toml.Unmarshal(meta.Bytes(), &m); err != nil { return false } t.metadata = NewMetadata(m) return true }
go
func (t *TOMLParser) Init(b *bytes.Buffer) bool { meta, data := splitBuffer(b, "+++") if meta == nil || data == nil { return false } t.markdown = data m := make(map[string]interface{}) if err := toml.Unmarshal(meta.Bytes(), &m); err != nil { return false } t.metadata = NewMetadata(m) return true }
[ "func", "(", "t", "*", "TOMLParser", ")", "Init", "(", "b", "*", "bytes", ".", "Buffer", ")", "bool", "{", "meta", ",", "data", ":=", "splitBuffer", "(", "b", ",", "\"", "\"", ")", "\n", "if", "meta", "==", "nil", "||", "data", "==", "nil", "{"...
// Init prepares and parses the metadata and markdown file itself
[ "Init", "prepares", "and", "parses", "the", "metadata", "and", "markdown", "file", "itself" ]
a2ed91bc45c8b3faa1577ed4c18334d38a581ca7
https://github.com/mholt/caddy/blob/a2ed91bc45c8b3faa1577ed4c18334d38a581ca7/caddyhttp/markdown/metadata/metadata_toml.go#L35-L49
124,880
mholt/caddy
plugins.go
ListPlugins
func ListPlugins() map[string][]string { p := make(map[string][]string) // server type plugins for name := range serverTypes { p["server_types"] = append(p["server_types"], name) } // caddyfile loaders in registration order for _, loader := range caddyfileLoaders { p["caddyfile_loaders"] = append(p["caddyfi...
go
func ListPlugins() map[string][]string { p := make(map[string][]string) // server type plugins for name := range serverTypes { p["server_types"] = append(p["server_types"], name) } // caddyfile loaders in registration order for _, loader := range caddyfileLoaders { p["caddyfile_loaders"] = append(p["caddyfi...
[ "func", "ListPlugins", "(", ")", "map", "[", "string", "]", "[", "]", "string", "{", "p", ":=", "make", "(", "map", "[", "string", "]", "[", "]", "string", ")", "\n\n", "// server type plugins", "for", "name", ":=", "range", "serverTypes", "{", "p", ...
// ListPlugins makes a list of the registered plugins, // keyed by plugin type.
[ "ListPlugins", "makes", "a", "list", "of", "the", "registered", "plugins", "keyed", "by", "plugin", "type", "." ]
a2ed91bc45c8b3faa1577ed4c18334d38a581ca7
https://github.com/mholt/caddy/blob/a2ed91bc45c8b3faa1577ed4c18334d38a581ca7/plugins.go#L93-L134
124,881
mholt/caddy
plugins.go
ValidDirectives
func ValidDirectives(serverType string) []string { stype, err := getServerType(serverType) if err != nil { return nil } return stype.Directives() }
go
func ValidDirectives(serverType string) []string { stype, err := getServerType(serverType) if err != nil { return nil } return stype.Directives() }
[ "func", "ValidDirectives", "(", "serverType", "string", ")", "[", "]", "string", "{", "stype", ",", "err", ":=", "getServerType", "(", "serverType", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", "\n", "}", "\n", "return", "stype", ".", "Di...
// ValidDirectives returns the list of all directives that are // recognized for the server type serverType. However, not all // directives may be installed. This makes it possible to give // more helpful error messages, like "did you mean ..." or // "maybe you need to plug in ...".
[ "ValidDirectives", "returns", "the", "list", "of", "all", "directives", "that", "are", "recognized", "for", "the", "server", "type", "serverType", ".", "However", "not", "all", "directives", "may", "be", "installed", ".", "This", "makes", "it", "possible", "to...
a2ed91bc45c8b3faa1577ed4c18334d38a581ca7
https://github.com/mholt/caddy/blob/a2ed91bc45c8b3faa1577ed4c18334d38a581ca7/plugins.go#L141-L147
124,882
mholt/caddy
plugins.go
LocalAddr
func (s ServerListener) LocalAddr() net.Addr { if s.packet == nil { return nil } return s.packet.LocalAddr() }
go
func (s ServerListener) LocalAddr() net.Addr { if s.packet == nil { return nil } return s.packet.LocalAddr() }
[ "func", "(", "s", "ServerListener", ")", "LocalAddr", "(", ")", "net", ".", "Addr", "{", "if", "s", ".", "packet", "==", "nil", "{", "return", "nil", "\n", "}", "\n", "return", "s", ".", "packet", ".", "LocalAddr", "(", ")", "\n", "}" ]
// LocalAddr returns the local network address of the packetconn. It returns // nil when it is not set.
[ "LocalAddr", "returns", "the", "local", "network", "address", "of", "the", "packetconn", ".", "It", "returns", "nil", "when", "it", "is", "not", "set", "." ]
a2ed91bc45c8b3faa1577ed4c18334d38a581ca7
https://github.com/mholt/caddy/blob/a2ed91bc45c8b3faa1577ed4c18334d38a581ca7/plugins.go#L158-L163
124,883
mholt/caddy
plugins.go
Addr
func (s ServerListener) Addr() net.Addr { if s.listener == nil { return nil } return s.listener.Addr() }
go
func (s ServerListener) Addr() net.Addr { if s.listener == nil { return nil } return s.listener.Addr() }
[ "func", "(", "s", "ServerListener", ")", "Addr", "(", ")", "net", ".", "Addr", "{", "if", "s", ".", "listener", "==", "nil", "{", "return", "nil", "\n", "}", "\n", "return", "s", ".", "listener", ".", "Addr", "(", ")", "\n", "}" ]
// Addr returns the listener's network address. It returns nil when it is // not set.
[ "Addr", "returns", "the", "listener", "s", "network", "address", ".", "It", "returns", "nil", "when", "it", "is", "not", "set", "." ]
a2ed91bc45c8b3faa1577ed4c18334d38a581ca7
https://github.com/mholt/caddy/blob/a2ed91bc45c8b3faa1577ed4c18334d38a581ca7/plugins.go#L167-L172
124,884
mholt/caddy
plugins.go
RegisterServerType
func RegisterServerType(typeName string, srv ServerType) { if _, ok := serverTypes[typeName]; ok { panic("server type already registered") } serverTypes[typeName] = srv }
go
func RegisterServerType(typeName string, srv ServerType) { if _, ok := serverTypes[typeName]; ok { panic("server type already registered") } serverTypes[typeName] = srv }
[ "func", "RegisterServerType", "(", "typeName", "string", ",", "srv", "ServerType", ")", "{", "if", "_", ",", "ok", ":=", "serverTypes", "[", "typeName", "]", ";", "ok", "{", "panic", "(", "\"", "\"", ")", "\n", "}", "\n", "serverTypes", "[", "typeName"...
// RegisterServerType registers a server type srv by its // name, typeName.
[ "RegisterServerType", "registers", "a", "server", "type", "srv", "by", "its", "name", "typeName", "." ]
a2ed91bc45c8b3faa1577ed4c18334d38a581ca7
https://github.com/mholt/caddy/blob/a2ed91bc45c8b3faa1577ed4c18334d38a581ca7/plugins.go#L203-L208
124,885
mholt/caddy
plugins.go
RegisterEventHook
func RegisterEventHook(name string, hook EventHook) { if name == "" { panic("event hook must have a name") } _, dup := eventHooks.LoadOrStore(name, hook) if dup { panic("hook named " + name + " already registered") } }
go
func RegisterEventHook(name string, hook EventHook) { if name == "" { panic("event hook must have a name") } _, dup := eventHooks.LoadOrStore(name, hook) if dup { panic("hook named " + name + " already registered") } }
[ "func", "RegisterEventHook", "(", "name", "string", ",", "hook", "EventHook", ")", "{", "if", "name", "==", "\"", "\"", "{", "panic", "(", "\"", "\"", ")", "\n", "}", "\n", "_", ",", "dup", ":=", "eventHooks", ".", "LoadOrStore", "(", "name", ",", ...
// RegisterEventHook plugs in hook. All the hooks should register themselves // and they must have a name.
[ "RegisterEventHook", "plugs", "in", "hook", ".", "All", "the", "hooks", "should", "register", "themselves", "and", "they", "must", "have", "a", "name", "." ]
a2ed91bc45c8b3faa1577ed4c18334d38a581ca7
https://github.com/mholt/caddy/blob/a2ed91bc45c8b3faa1577ed4c18334d38a581ca7/plugins.go#L284-L292
124,886
mholt/caddy
plugins.go
EmitEvent
func EmitEvent(event EventName, info interface{}) { eventHooks.Range(func(k, v interface{}) bool { err := v.(EventHook)(event, info) if err != nil { log.Printf("error on '%s' hook: %v", k.(string), err) } return true }) }
go
func EmitEvent(event EventName, info interface{}) { eventHooks.Range(func(k, v interface{}) bool { err := v.(EventHook)(event, info) if err != nil { log.Printf("error on '%s' hook: %v", k.(string), err) } return true }) }
[ "func", "EmitEvent", "(", "event", "EventName", ",", "info", "interface", "{", "}", ")", "{", "eventHooks", ".", "Range", "(", "func", "(", "k", ",", "v", "interface", "{", "}", ")", "bool", "{", "err", ":=", "v", ".", "(", "EventHook", ")", "(", ...
// EmitEvent executes the different hooks passing the EventType as an // argument. This is a blocking function. Hook developers should // use 'go' keyword if they don't want to block Caddy.
[ "EmitEvent", "executes", "the", "different", "hooks", "passing", "the", "EventType", "as", "an", "argument", ".", "This", "is", "a", "blocking", "function", ".", "Hook", "developers", "should", "use", "go", "keyword", "if", "they", "don", "t", "want", "to", ...
a2ed91bc45c8b3faa1577ed4c18334d38a581ca7
https://github.com/mholt/caddy/blob/a2ed91bc45c8b3faa1577ed4c18334d38a581ca7/plugins.go#L297-L305
124,887
mholt/caddy
plugins.go
purgeEventHooks
func purgeEventHooks() { eventHooks.Range(func(k, _ interface{}) bool { eventHooks.Delete(k) return true }) }
go
func purgeEventHooks() { eventHooks.Range(func(k, _ interface{}) bool { eventHooks.Delete(k) return true }) }
[ "func", "purgeEventHooks", "(", ")", "{", "eventHooks", ".", "Range", "(", "func", "(", "k", ",", "_", "interface", "{", "}", ")", "bool", "{", "eventHooks", ".", "Delete", "(", "k", ")", "\n", "return", "true", "\n", "}", ")", "\n", "}" ]
// purgeEventHooks purges all event hooks from the map
[ "purgeEventHooks", "purges", "all", "event", "hooks", "from", "the", "map" ]
a2ed91bc45c8b3faa1577ed4c18334d38a581ca7
https://github.com/mholt/caddy/blob/a2ed91bc45c8b3faa1577ed4c18334d38a581ca7/plugins.go#L318-L323
124,888
mholt/caddy
plugins.go
RegisterParsingCallback
func RegisterParsingCallback(serverType, afterDir string, callback ParsingCallback) { if _, ok := parsingCallbacks[serverType]; !ok { parsingCallbacks[serverType] = make(map[string][]ParsingCallback) } parsingCallbacks[serverType][afterDir] = append(parsingCallbacks[serverType][afterDir], callback) }
go
func RegisterParsingCallback(serverType, afterDir string, callback ParsingCallback) { if _, ok := parsingCallbacks[serverType]; !ok { parsingCallbacks[serverType] = make(map[string][]ParsingCallback) } parsingCallbacks[serverType][afterDir] = append(parsingCallbacks[serverType][afterDir], callback) }
[ "func", "RegisterParsingCallback", "(", "serverType", ",", "afterDir", "string", ",", "callback", "ParsingCallback", ")", "{", "if", "_", ",", "ok", ":=", "parsingCallbacks", "[", "serverType", "]", ";", "!", "ok", "{", "parsingCallbacks", "[", "serverType", "...
// RegisterParsingCallback registers callback to be called after // executing the directive afterDir for server type serverType.
[ "RegisterParsingCallback", "registers", "callback", "to", "be", "called", "after", "executing", "the", "directive", "afterDir", "for", "server", "type", "serverType", "." ]
a2ed91bc45c8b3faa1577ed4c18334d38a581ca7
https://github.com/mholt/caddy/blob/a2ed91bc45c8b3faa1577ed4c18334d38a581ca7/plugins.go#L344-L349
124,889
mholt/caddy
plugins.go
DirectiveAction
func DirectiveAction(serverType, dir string) (SetupFunc, error) { if stypePlugins, ok := plugins[serverType]; ok { if plugin, ok := stypePlugins[dir]; ok { return plugin.Action, nil } } if genericPlugins, ok := plugins[""]; ok { if plugin, ok := genericPlugins[dir]; ok { return plugin.Action, nil } } ...
go
func DirectiveAction(serverType, dir string) (SetupFunc, error) { if stypePlugins, ok := plugins[serverType]; ok { if plugin, ok := stypePlugins[dir]; ok { return plugin.Action, nil } } if genericPlugins, ok := plugins[""]; ok { if plugin, ok := genericPlugins[dir]; ok { return plugin.Action, nil } } ...
[ "func", "DirectiveAction", "(", "serverType", ",", "dir", "string", ")", "(", "SetupFunc", ",", "error", ")", "{", "if", "stypePlugins", ",", "ok", ":=", "plugins", "[", "serverType", "]", ";", "ok", "{", "if", "plugin", ",", "ok", ":=", "stypePlugins", ...
// DirectiveAction gets the action for directive dir of // server type serverType.
[ "DirectiveAction", "gets", "the", "action", "for", "directive", "dir", "of", "server", "type", "serverType", "." ]
a2ed91bc45c8b3faa1577ed4c18334d38a581ca7
https://github.com/mholt/caddy/blob/a2ed91bc45c8b3faa1577ed4c18334d38a581ca7/plugins.go#L358-L371
124,890
mholt/caddy
plugins.go
RegisterCaddyfileLoader
func RegisterCaddyfileLoader(name string, loader Loader) { caddyfileLoaders = append(caddyfileLoaders, caddyfileLoader{name: name, loader: loader}) }
go
func RegisterCaddyfileLoader(name string, loader Loader) { caddyfileLoaders = append(caddyfileLoaders, caddyfileLoader{name: name, loader: loader}) }
[ "func", "RegisterCaddyfileLoader", "(", "name", "string", ",", "loader", "Loader", ")", "{", "caddyfileLoaders", "=", "append", "(", "caddyfileLoaders", ",", "caddyfileLoader", "{", "name", ":", "name", ",", "loader", ":", "loader", "}", ")", "\n", "}" ]
// RegisterCaddyfileLoader registers loader named name.
[ "RegisterCaddyfileLoader", "registers", "loader", "named", "name", "." ]
a2ed91bc45c8b3faa1577ed4c18334d38a581ca7
https://github.com/mholt/caddy/blob/a2ed91bc45c8b3faa1577ed4c18334d38a581ca7/plugins.go#L404-L406
124,891
mholt/caddy
plugins.go
SetDefaultCaddyfileLoader
func SetDefaultCaddyfileLoader(name string, loader Loader) { defaultCaddyfileLoader = caddyfileLoader{name: name, loader: loader} }
go
func SetDefaultCaddyfileLoader(name string, loader Loader) { defaultCaddyfileLoader = caddyfileLoader{name: name, loader: loader} }
[ "func", "SetDefaultCaddyfileLoader", "(", "name", "string", ",", "loader", "Loader", ")", "{", "defaultCaddyfileLoader", "=", "caddyfileLoader", "{", "name", ":", "name", ",", "loader", ":", "loader", "}", "\n", "}" ]
// SetDefaultCaddyfileLoader registers loader by name // as the default Caddyfile loader if no others produce // a Caddyfile. If another Caddyfile loader has already // been set as the default, this replaces it. // // Do not call RegisterCaddyfileLoader on the same // loader; that would be redundant.
[ "SetDefaultCaddyfileLoader", "registers", "loader", "by", "name", "as", "the", "default", "Caddyfile", "loader", "if", "no", "others", "produce", "a", "Caddyfile", ".", "If", "another", "Caddyfile", "loader", "has", "already", "been", "set", "as", "the", "defaul...
a2ed91bc45c8b3faa1577ed4c18334d38a581ca7
https://github.com/mholt/caddy/blob/a2ed91bc45c8b3faa1577ed4c18334d38a581ca7/plugins.go#L415-L417
124,892
mholt/caddy
plugins.go
loadCaddyfileInput
func loadCaddyfileInput(serverType string) (Input, error) { var loadedBy string var caddyfileToUse Input for _, l := range caddyfileLoaders { cdyfile, err := l.loader.Load(serverType) if err != nil { return nil, fmt.Errorf("loading Caddyfile via %s: %v", l.name, err) } if cdyfile != nil { if caddyfileT...
go
func loadCaddyfileInput(serverType string) (Input, error) { var loadedBy string var caddyfileToUse Input for _, l := range caddyfileLoaders { cdyfile, err := l.loader.Load(serverType) if err != nil { return nil, fmt.Errorf("loading Caddyfile via %s: %v", l.name, err) } if cdyfile != nil { if caddyfileT...
[ "func", "loadCaddyfileInput", "(", "serverType", "string", ")", "(", "Input", ",", "error", ")", "{", "var", "loadedBy", "string", "\n", "var", "caddyfileToUse", "Input", "\n", "for", "_", ",", "l", ":=", "range", "caddyfileLoaders", "{", "cdyfile", ",", "...
// loadCaddyfileInput iterates the registered Caddyfile loaders // and, if needed, calls the default loader, to load a Caddyfile. // It is an error if any of the loaders return an error or if // more than one loader returns a Caddyfile.
[ "loadCaddyfileInput", "iterates", "the", "registered", "Caddyfile", "loaders", "and", "if", "needed", "calls", "the", "default", "loader", "to", "load", "a", "Caddyfile", ".", "It", "is", "an", "error", "if", "any", "of", "the", "loaders", "return", "an", "e...
a2ed91bc45c8b3faa1577ed4c18334d38a581ca7
https://github.com/mholt/caddy/blob/a2ed91bc45c8b3faa1577ed4c18334d38a581ca7/plugins.go#L423-L451
124,893
mholt/caddy
caddyhttp/basicauth/setup.go
setup
func setup(c *caddy.Controller) error { cfg := httpserver.GetConfig(c) root := cfg.Root rules, err := basicAuthParse(c) if err != nil { return err } basic := BasicAuth{Rules: rules} cfg.AddMiddleware(func(next httpserver.Handler) httpserver.Handler { basic.Next = next basic.SiteRoot = root return basi...
go
func setup(c *caddy.Controller) error { cfg := httpserver.GetConfig(c) root := cfg.Root rules, err := basicAuthParse(c) if err != nil { return err } basic := BasicAuth{Rules: rules} cfg.AddMiddleware(func(next httpserver.Handler) httpserver.Handler { basic.Next = next basic.SiteRoot = root return basi...
[ "func", "setup", "(", "c", "*", "caddy", ".", "Controller", ")", "error", "{", "cfg", ":=", "httpserver", ".", "GetConfig", "(", "c", ")", "\n", "root", ":=", "cfg", ".", "Root", "\n\n", "rules", ",", "err", ":=", "basicAuthParse", "(", "c", ")", "...
// setup configures a new BasicAuth middleware instance.
[ "setup", "configures", "a", "new", "BasicAuth", "middleware", "instance", "." ]
a2ed91bc45c8b3faa1577ed4c18334d38a581ca7
https://github.com/mholt/caddy/blob/a2ed91bc45c8b3faa1577ed4c18334d38a581ca7/caddyhttp/basicauth/setup.go#L32-L50
124,894
mholt/caddy
caddyhttp/mime/setup.go
setup
func setup(c *caddy.Controller) error { configs, err := mimeParse(c) if err != nil { return err } httpserver.GetConfig(c).AddMiddleware(func(next httpserver.Handler) httpserver.Handler { return Mime{Next: next, Configs: configs} }) return nil }
go
func setup(c *caddy.Controller) error { configs, err := mimeParse(c) if err != nil { return err } httpserver.GetConfig(c).AddMiddleware(func(next httpserver.Handler) httpserver.Handler { return Mime{Next: next, Configs: configs} }) return nil }
[ "func", "setup", "(", "c", "*", "caddy", ".", "Controller", ")", "error", "{", "configs", ",", "err", ":=", "mimeParse", "(", "c", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "httpserver", ".", "GetConfig", "(", "c...
// setup configures a new mime middleware instance.
[ "setup", "configures", "a", "new", "mime", "middleware", "instance", "." ]
a2ed91bc45c8b3faa1577ed4c18334d38a581ca7
https://github.com/mholt/caddy/blob/a2ed91bc45c8b3faa1577ed4c18334d38a581ca7/caddyhttp/mime/setup.go#L33-L44
124,895
mholt/caddy
caddyhttp/mime/setup.go
validateExt
func validateExt(configs Config, ext string) error { if !strings.HasPrefix(ext, ".") { return fmt.Errorf(`mime: invalid extension "%v" (must start with dot)`, ext) } if _, ok := configs[ext]; ok { return fmt.Errorf(`mime: duplicate extension "%v" found`, ext) } return nil }
go
func validateExt(configs Config, ext string) error { if !strings.HasPrefix(ext, ".") { return fmt.Errorf(`mime: invalid extension "%v" (must start with dot)`, ext) } if _, ok := configs[ext]; ok { return fmt.Errorf(`mime: duplicate extension "%v" found`, ext) } return nil }
[ "func", "validateExt", "(", "configs", "Config", ",", "ext", "string", ")", "error", "{", "if", "!", "strings", ".", "HasPrefix", "(", "ext", ",", "\"", "\"", ")", "{", "return", "fmt", ".", "Errorf", "(", "`mime: invalid extension \"%v\" (must start with dot)...
// validateExt checks for valid file name extension.
[ "validateExt", "checks", "for", "valid", "file", "name", "extension", "." ]
a2ed91bc45c8b3faa1577ed4c18334d38a581ca7
https://github.com/mholt/caddy/blob/a2ed91bc45c8b3faa1577ed4c18334d38a581ca7/caddyhttp/mime/setup.go#L80-L88
124,896
mholt/caddy
caddytls/handshake.go
GetConfigForClient
func (cg configGroup) GetConfigForClient(clientHello *tls.ClientHelloInfo) (*tls.Config, error) { config := cg.getConfig(clientHello) if config != nil { return config.tlsConfig, nil } return nil, nil }
go
func (cg configGroup) GetConfigForClient(clientHello *tls.ClientHelloInfo) (*tls.Config, error) { config := cg.getConfig(clientHello) if config != nil { return config.tlsConfig, nil } return nil, nil }
[ "func", "(", "cg", "configGroup", ")", "GetConfigForClient", "(", "clientHello", "*", "tls", ".", "ClientHelloInfo", ")", "(", "*", "tls", ".", "Config", ",", "error", ")", "{", "config", ":=", "cg", ".", "getConfig", "(", "clientHello", ")", "\n", "if",...
// GetConfigForClient gets a TLS configuration satisfying clientHello. // In getting the configuration, it abides the rules and settings // defined in the Config that matches clientHello.ServerName. If no // tls.Config is set on the matching Config, a nil value is returned. // // This method is safe for use as a tls.Co...
[ "GetConfigForClient", "gets", "a", "TLS", "configuration", "satisfying", "clientHello", ".", "In", "getting", "the", "configuration", "it", "abides", "the", "rules", "and", "settings", "defined", "in", "the", "Config", "that", "matches", "clientHello", ".", "Serve...
a2ed91bc45c8b3faa1577ed4c18334d38a581ca7
https://github.com/mholt/caddy/blob/a2ed91bc45c8b3faa1577ed4c18334d38a581ca7/caddytls/handshake.go#L105-L111
124,897
mholt/caddy
caddytls/handshake.go
Key
func (info ClientHelloInfo) Key() string { extensions, compressionMethods := "?", "?" if !info.ExtensionsUnknown { extensions = fmt.Sprintf("%x", info.Extensions) } if !info.CompressionMethodsUnknown { compressionMethods = fmt.Sprintf("%x", info.CompressionMethods) } return telemetry.FastHash([]byte(fmt.Sprin...
go
func (info ClientHelloInfo) Key() string { extensions, compressionMethods := "?", "?" if !info.ExtensionsUnknown { extensions = fmt.Sprintf("%x", info.Extensions) } if !info.CompressionMethodsUnknown { compressionMethods = fmt.Sprintf("%x", info.CompressionMethods) } return telemetry.FastHash([]byte(fmt.Sprin...
[ "func", "(", "info", "ClientHelloInfo", ")", "Key", "(", ")", "string", "{", "extensions", ",", "compressionMethods", ":=", "\"", "\"", ",", "\"", "\"", "\n", "if", "!", "info", ".", "ExtensionsUnknown", "{", "extensions", "=", "fmt", ".", "Sprintf", "("...
// Key returns a standardized string form of the data in info, // useful for identifying duplicates.
[ "Key", "returns", "a", "standardized", "string", "form", "of", "the", "data", "in", "info", "useful", "for", "identifying", "duplicates", "." ]
a2ed91bc45c8b3faa1577ed4c18334d38a581ca7
https://github.com/mholt/caddy/blob/a2ed91bc45c8b3faa1577ed4c18334d38a581ca7/caddytls/handshake.go#L136-L147
124,898
mholt/caddy
caddyhttp/markdown/template.go
SetTemplate
func SetTemplate(t *template.Template, name, filename string) error { // Read template buf, err := ioutil.ReadFile(filename) if err != nil { return err } // Update if exists if tt := t.Lookup(name); tt != nil { _, err = tt.Parse(string(buf)) return err } // Allocate new name if not _, err = t.New(name...
go
func SetTemplate(t *template.Template, name, filename string) error { // Read template buf, err := ioutil.ReadFile(filename) if err != nil { return err } // Update if exists if tt := t.Lookup(name); tt != nil { _, err = tt.Parse(string(buf)) return err } // Allocate new name if not _, err = t.New(name...
[ "func", "SetTemplate", "(", "t", "*", "template", ".", "Template", ",", "name", ",", "filename", "string", ")", "error", "{", "// Read template", "buf", ",", "err", ":=", "ioutil", ".", "ReadFile", "(", "filename", ")", "\n", "if", "err", "!=", "nil", ...
// SetTemplate reads in the template with the filename provided. If the file does not exist or is not parsable, it will return an error.
[ "SetTemplate", "reads", "in", "the", "template", "with", "the", "filename", "provided", ".", "If", "the", "file", "does", "not", "exist", "or", "is", "not", "parsable", "it", "will", "return", "an", "error", "." ]
a2ed91bc45c8b3faa1577ed4c18334d38a581ca7
https://github.com/mholt/caddy/blob/a2ed91bc45c8b3faa1577ed4c18334d38a581ca7/caddyhttp/markdown/template.go#L118-L135
124,899
mholt/caddy
caddyhttp/gzip/requestfilter.go
DefaultExtFilter
func DefaultExtFilter() ExtFilter { m := ExtFilter{Exts: make(Set)} for _, extension := range defaultExtensions { m.Exts.Add(extension) } return m }
go
func DefaultExtFilter() ExtFilter { m := ExtFilter{Exts: make(Set)} for _, extension := range defaultExtensions { m.Exts.Add(extension) } return m }
[ "func", "DefaultExtFilter", "(", ")", "ExtFilter", "{", "m", ":=", "ExtFilter", "{", "Exts", ":", "make", "(", "Set", ")", "}", "\n", "for", "_", ",", "extension", ":=", "range", "defaultExtensions", "{", "m", ".", "Exts", ".", "Add", "(", "extension",...
// DefaultExtFilter creates an ExtFilter with default extensions.
[ "DefaultExtFilter", "creates", "an", "ExtFilter", "with", "default", "extensions", "." ]
a2ed91bc45c8b3faa1577ed4c18334d38a581ca7
https://github.com/mholt/caddy/blob/a2ed91bc45c8b3faa1577ed4c18334d38a581ca7/caddyhttp/gzip/requestfilter.go#L36-L42