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
partition
stringclasses
1 value
go-ini/ini
key.go
StringsWithShadows
func (k *Key) StringsWithShadows(delim string) []string { vals := k.ValueWithShadows() results := make([]string, 0, len(vals)*2) for i := range vals { if len(vals) == 0 { continue } results = append(results, strings.Split(vals[i], delim)...) } for i := range results { results[i] = k.transformValue(strings.TrimSpace(results[i])) } return results }
go
func (k *Key) StringsWithShadows(delim string) []string { vals := k.ValueWithShadows() results := make([]string, 0, len(vals)*2) for i := range vals { if len(vals) == 0 { continue } results = append(results, strings.Split(vals[i], delim)...) } for i := range results { results[i] = k.transformValue(strings.TrimSpace(results[i])) } return results }
[ "func", "(", "k", "*", "Key", ")", "StringsWithShadows", "(", "delim", "string", ")", "[", "]", "string", "{", "vals", ":=", "k", ".", "ValueWithShadows", "(", ")", "\n", "results", ":=", "make", "(", "[", "]", "string", ",", "0", ",", "len", "(", ...
// StringsWithShadows returns list of string divided by given delimiter. // Shadows will also be appended if any.
[ "StringsWithShadows", "returns", "list", "of", "string", "divided", "by", "given", "delimiter", ".", "Shadows", "will", "also", "be", "appended", "if", "any", "." ]
3be5ad479f69d4e08d7fe25edf79bf3346bd658e
https://github.com/go-ini/ini/blob/3be5ad479f69d4e08d7fe25edf79bf3346bd658e/key.go#L510-L525
train
go-ini/ini
key.go
Float64s
func (k *Key) Float64s(delim string) []float64 { vals, _ := k.parseFloat64s(k.Strings(delim), true, false) return vals }
go
func (k *Key) Float64s(delim string) []float64 { vals, _ := k.parseFloat64s(k.Strings(delim), true, false) return vals }
[ "func", "(", "k", "*", "Key", ")", "Float64s", "(", "delim", "string", ")", "[", "]", "float64", "{", "vals", ",", "_", ":=", "k", ".", "parseFloat64s", "(", "k", ".", "Strings", "(", "delim", ")", ",", "true", ",", "false", ")", "\n", "return", ...
// Float64s returns list of float64 divided by given delimiter. Any invalid input will be treated as zero value.
[ "Float64s", "returns", "list", "of", "float64", "divided", "by", "given", "delimiter", ".", "Any", "invalid", "input", "will", "be", "treated", "as", "zero", "value", "." ]
3be5ad479f69d4e08d7fe25edf79bf3346bd658e
https://github.com/go-ini/ini/blob/3be5ad479f69d4e08d7fe25edf79bf3346bd658e/key.go#L528-L531
train
go-ini/ini
key.go
Ints
func (k *Key) Ints(delim string) []int { vals, _ := k.parseInts(k.Strings(delim), true, false) return vals }
go
func (k *Key) Ints(delim string) []int { vals, _ := k.parseInts(k.Strings(delim), true, false) return vals }
[ "func", "(", "k", "*", "Key", ")", "Ints", "(", "delim", "string", ")", "[", "]", "int", "{", "vals", ",", "_", ":=", "k", ".", "parseInts", "(", "k", ".", "Strings", "(", "delim", ")", ",", "true", ",", "false", ")", "\n", "return", "vals", ...
// Ints returns list of int divided by given delimiter. Any invalid input will be treated as zero value.
[ "Ints", "returns", "list", "of", "int", "divided", "by", "given", "delimiter", ".", "Any", "invalid", "input", "will", "be", "treated", "as", "zero", "value", "." ]
3be5ad479f69d4e08d7fe25edf79bf3346bd658e
https://github.com/go-ini/ini/blob/3be5ad479f69d4e08d7fe25edf79bf3346bd658e/key.go#L534-L537
train
go-ini/ini
key.go
Int64s
func (k *Key) Int64s(delim string) []int64 { vals, _ := k.parseInt64s(k.Strings(delim), true, false) return vals }
go
func (k *Key) Int64s(delim string) []int64 { vals, _ := k.parseInt64s(k.Strings(delim), true, false) return vals }
[ "func", "(", "k", "*", "Key", ")", "Int64s", "(", "delim", "string", ")", "[", "]", "int64", "{", "vals", ",", "_", ":=", "k", ".", "parseInt64s", "(", "k", ".", "Strings", "(", "delim", ")", ",", "true", ",", "false", ")", "\n", "return", "val...
// Int64s returns list of int64 divided by given delimiter. Any invalid input will be treated as zero value.
[ "Int64s", "returns", "list", "of", "int64", "divided", "by", "given", "delimiter", ".", "Any", "invalid", "input", "will", "be", "treated", "as", "zero", "value", "." ]
3be5ad479f69d4e08d7fe25edf79bf3346bd658e
https://github.com/go-ini/ini/blob/3be5ad479f69d4e08d7fe25edf79bf3346bd658e/key.go#L540-L543
train
go-ini/ini
key.go
Uints
func (k *Key) Uints(delim string) []uint { vals, _ := k.parseUints(k.Strings(delim), true, false) return vals }
go
func (k *Key) Uints(delim string) []uint { vals, _ := k.parseUints(k.Strings(delim), true, false) return vals }
[ "func", "(", "k", "*", "Key", ")", "Uints", "(", "delim", "string", ")", "[", "]", "uint", "{", "vals", ",", "_", ":=", "k", ".", "parseUints", "(", "k", ".", "Strings", "(", "delim", ")", ",", "true", ",", "false", ")", "\n", "return", "vals",...
// Uints returns list of uint divided by given delimiter. Any invalid input will be treated as zero value.
[ "Uints", "returns", "list", "of", "uint", "divided", "by", "given", "delimiter", ".", "Any", "invalid", "input", "will", "be", "treated", "as", "zero", "value", "." ]
3be5ad479f69d4e08d7fe25edf79bf3346bd658e
https://github.com/go-ini/ini/blob/3be5ad479f69d4e08d7fe25edf79bf3346bd658e/key.go#L546-L549
train
go-ini/ini
key.go
Uint64s
func (k *Key) Uint64s(delim string) []uint64 { vals, _ := k.parseUint64s(k.Strings(delim), true, false) return vals }
go
func (k *Key) Uint64s(delim string) []uint64 { vals, _ := k.parseUint64s(k.Strings(delim), true, false) return vals }
[ "func", "(", "k", "*", "Key", ")", "Uint64s", "(", "delim", "string", ")", "[", "]", "uint64", "{", "vals", ",", "_", ":=", "k", ".", "parseUint64s", "(", "k", ".", "Strings", "(", "delim", ")", ",", "true", ",", "false", ")", "\n", "return", "...
// Uint64s returns list of uint64 divided by given delimiter. Any invalid input will be treated as zero value.
[ "Uint64s", "returns", "list", "of", "uint64", "divided", "by", "given", "delimiter", ".", "Any", "invalid", "input", "will", "be", "treated", "as", "zero", "value", "." ]
3be5ad479f69d4e08d7fe25edf79bf3346bd658e
https://github.com/go-ini/ini/blob/3be5ad479f69d4e08d7fe25edf79bf3346bd658e/key.go#L552-L555
train
go-ini/ini
key.go
ValidFloat64s
func (k *Key) ValidFloat64s(delim string) []float64 { vals, _ := k.parseFloat64s(k.Strings(delim), false, false) return vals }
go
func (k *Key) ValidFloat64s(delim string) []float64 { vals, _ := k.parseFloat64s(k.Strings(delim), false, false) return vals }
[ "func", "(", "k", "*", "Key", ")", "ValidFloat64s", "(", "delim", "string", ")", "[", "]", "float64", "{", "vals", ",", "_", ":=", "k", ".", "parseFloat64s", "(", "k", ".", "Strings", "(", "delim", ")", ",", "false", ",", "false", ")", "\n", "ret...
// ValidFloat64s returns list of float64 divided by given delimiter. If some value is not float, then // it will not be included to result list.
[ "ValidFloat64s", "returns", "list", "of", "float64", "divided", "by", "given", "delimiter", ".", "If", "some", "value", "is", "not", "float", "then", "it", "will", "not", "be", "included", "to", "result", "list", "." ]
3be5ad479f69d4e08d7fe25edf79bf3346bd658e
https://github.com/go-ini/ini/blob/3be5ad479f69d4e08d7fe25edf79bf3346bd658e/key.go#L572-L575
train
go-ini/ini
key.go
ValidInts
func (k *Key) ValidInts(delim string) []int { vals, _ := k.parseInts(k.Strings(delim), false, false) return vals }
go
func (k *Key) ValidInts(delim string) []int { vals, _ := k.parseInts(k.Strings(delim), false, false) return vals }
[ "func", "(", "k", "*", "Key", ")", "ValidInts", "(", "delim", "string", ")", "[", "]", "int", "{", "vals", ",", "_", ":=", "k", ".", "parseInts", "(", "k", ".", "Strings", "(", "delim", ")", ",", "false", ",", "false", ")", "\n", "return", "val...
// ValidInts returns list of int divided by given delimiter. If some value is not integer, then it will // not be included to result list.
[ "ValidInts", "returns", "list", "of", "int", "divided", "by", "given", "delimiter", ".", "If", "some", "value", "is", "not", "integer", "then", "it", "will", "not", "be", "included", "to", "result", "list", "." ]
3be5ad479f69d4e08d7fe25edf79bf3346bd658e
https://github.com/go-ini/ini/blob/3be5ad479f69d4e08d7fe25edf79bf3346bd658e/key.go#L579-L582
train
go-ini/ini
key.go
ValidInt64s
func (k *Key) ValidInt64s(delim string) []int64 { vals, _ := k.parseInt64s(k.Strings(delim), false, false) return vals }
go
func (k *Key) ValidInt64s(delim string) []int64 { vals, _ := k.parseInt64s(k.Strings(delim), false, false) return vals }
[ "func", "(", "k", "*", "Key", ")", "ValidInt64s", "(", "delim", "string", ")", "[", "]", "int64", "{", "vals", ",", "_", ":=", "k", ".", "parseInt64s", "(", "k", ".", "Strings", "(", "delim", ")", ",", "false", ",", "false", ")", "\n", "return", ...
// ValidInt64s returns list of int64 divided by given delimiter. If some value is not 64-bit integer, // then it will not be included to result list.
[ "ValidInt64s", "returns", "list", "of", "int64", "divided", "by", "given", "delimiter", ".", "If", "some", "value", "is", "not", "64", "-", "bit", "integer", "then", "it", "will", "not", "be", "included", "to", "result", "list", "." ]
3be5ad479f69d4e08d7fe25edf79bf3346bd658e
https://github.com/go-ini/ini/blob/3be5ad479f69d4e08d7fe25edf79bf3346bd658e/key.go#L586-L589
train
go-ini/ini
key.go
ValidUints
func (k *Key) ValidUints(delim string) []uint { vals, _ := k.parseUints(k.Strings(delim), false, false) return vals }
go
func (k *Key) ValidUints(delim string) []uint { vals, _ := k.parseUints(k.Strings(delim), false, false) return vals }
[ "func", "(", "k", "*", "Key", ")", "ValidUints", "(", "delim", "string", ")", "[", "]", "uint", "{", "vals", ",", "_", ":=", "k", ".", "parseUints", "(", "k", ".", "Strings", "(", "delim", ")", ",", "false", ",", "false", ")", "\n", "return", "...
// ValidUints returns list of uint divided by given delimiter. If some value is not unsigned integer, // then it will not be included to result list.
[ "ValidUints", "returns", "list", "of", "uint", "divided", "by", "given", "delimiter", ".", "If", "some", "value", "is", "not", "unsigned", "integer", "then", "it", "will", "not", "be", "included", "to", "result", "list", "." ]
3be5ad479f69d4e08d7fe25edf79bf3346bd658e
https://github.com/go-ini/ini/blob/3be5ad479f69d4e08d7fe25edf79bf3346bd658e/key.go#L593-L596
train
go-ini/ini
key.go
ValidUint64s
func (k *Key) ValidUint64s(delim string) []uint64 { vals, _ := k.parseUint64s(k.Strings(delim), false, false) return vals }
go
func (k *Key) ValidUint64s(delim string) []uint64 { vals, _ := k.parseUint64s(k.Strings(delim), false, false) return vals }
[ "func", "(", "k", "*", "Key", ")", "ValidUint64s", "(", "delim", "string", ")", "[", "]", "uint64", "{", "vals", ",", "_", ":=", "k", ".", "parseUint64s", "(", "k", ".", "Strings", "(", "delim", ")", ",", "false", ",", "false", ")", "\n", "return...
// ValidUint64s returns list of uint64 divided by given delimiter. If some value is not 64-bit unsigned // integer, then it will not be included to result list.
[ "ValidUint64s", "returns", "list", "of", "uint64", "divided", "by", "given", "delimiter", ".", "If", "some", "value", "is", "not", "64", "-", "bit", "unsigned", "integer", "then", "it", "will", "not", "be", "included", "to", "result", "list", "." ]
3be5ad479f69d4e08d7fe25edf79bf3346bd658e
https://github.com/go-ini/ini/blob/3be5ad479f69d4e08d7fe25edf79bf3346bd658e/key.go#L600-L603
train
go-ini/ini
key.go
ValidTimesFormat
func (k *Key) ValidTimesFormat(format, delim string) []time.Time { vals, _ := k.parseTimesFormat(format, k.Strings(delim), false, false) return vals }
go
func (k *Key) ValidTimesFormat(format, delim string) []time.Time { vals, _ := k.parseTimesFormat(format, k.Strings(delim), false, false) return vals }
[ "func", "(", "k", "*", "Key", ")", "ValidTimesFormat", "(", "format", ",", "delim", "string", ")", "[", "]", "time", ".", "Time", "{", "vals", ",", "_", ":=", "k", ".", "parseTimesFormat", "(", "format", ",", "k", ".", "Strings", "(", "delim", ")",...
// ValidTimesFormat parses with given format and returns list of time.Time divided by given delimiter.
[ "ValidTimesFormat", "parses", "with", "given", "format", "and", "returns", "list", "of", "time", ".", "Time", "divided", "by", "given", "delimiter", "." ]
3be5ad479f69d4e08d7fe25edf79bf3346bd658e
https://github.com/go-ini/ini/blob/3be5ad479f69d4e08d7fe25edf79bf3346bd658e/key.go#L606-L609
train
go-ini/ini
key.go
ValidTimes
func (k *Key) ValidTimes(delim string) []time.Time { return k.ValidTimesFormat(time.RFC3339, delim) }
go
func (k *Key) ValidTimes(delim string) []time.Time { return k.ValidTimesFormat(time.RFC3339, delim) }
[ "func", "(", "k", "*", "Key", ")", "ValidTimes", "(", "delim", "string", ")", "[", "]", "time", ".", "Time", "{", "return", "k", ".", "ValidTimesFormat", "(", "time", ".", "RFC3339", ",", "delim", ")", "\n", "}" ]
// ValidTimes parses with RFC3339 format and returns list of time.Time divided by given delimiter.
[ "ValidTimes", "parses", "with", "RFC3339", "format", "and", "returns", "list", "of", "time", ".", "Time", "divided", "by", "given", "delimiter", "." ]
3be5ad479f69d4e08d7fe25edf79bf3346bd658e
https://github.com/go-ini/ini/blob/3be5ad479f69d4e08d7fe25edf79bf3346bd658e/key.go#L612-L614
train
go-ini/ini
key.go
StrictFloat64s
func (k *Key) StrictFloat64s(delim string) ([]float64, error) { return k.parseFloat64s(k.Strings(delim), false, true) }
go
func (k *Key) StrictFloat64s(delim string) ([]float64, error) { return k.parseFloat64s(k.Strings(delim), false, true) }
[ "func", "(", "k", "*", "Key", ")", "StrictFloat64s", "(", "delim", "string", ")", "(", "[", "]", "float64", ",", "error", ")", "{", "return", "k", ".", "parseFloat64s", "(", "k", ".", "Strings", "(", "delim", ")", ",", "false", ",", "true", ")", ...
// StrictFloat64s returns list of float64 divided by given delimiter or error on first invalid input.
[ "StrictFloat64s", "returns", "list", "of", "float64", "divided", "by", "given", "delimiter", "or", "error", "on", "first", "invalid", "input", "." ]
3be5ad479f69d4e08d7fe25edf79bf3346bd658e
https://github.com/go-ini/ini/blob/3be5ad479f69d4e08d7fe25edf79bf3346bd658e/key.go#L617-L619
train
go-ini/ini
key.go
StrictInts
func (k *Key) StrictInts(delim string) ([]int, error) { return k.parseInts(k.Strings(delim), false, true) }
go
func (k *Key) StrictInts(delim string) ([]int, error) { return k.parseInts(k.Strings(delim), false, true) }
[ "func", "(", "k", "*", "Key", ")", "StrictInts", "(", "delim", "string", ")", "(", "[", "]", "int", ",", "error", ")", "{", "return", "k", ".", "parseInts", "(", "k", ".", "Strings", "(", "delim", ")", ",", "false", ",", "true", ")", "\n", "}" ...
// StrictInts returns list of int divided by given delimiter or error on first invalid input.
[ "StrictInts", "returns", "list", "of", "int", "divided", "by", "given", "delimiter", "or", "error", "on", "first", "invalid", "input", "." ]
3be5ad479f69d4e08d7fe25edf79bf3346bd658e
https://github.com/go-ini/ini/blob/3be5ad479f69d4e08d7fe25edf79bf3346bd658e/key.go#L622-L624
train
go-ini/ini
key.go
StrictInt64s
func (k *Key) StrictInt64s(delim string) ([]int64, error) { return k.parseInt64s(k.Strings(delim), false, true) }
go
func (k *Key) StrictInt64s(delim string) ([]int64, error) { return k.parseInt64s(k.Strings(delim), false, true) }
[ "func", "(", "k", "*", "Key", ")", "StrictInt64s", "(", "delim", "string", ")", "(", "[", "]", "int64", ",", "error", ")", "{", "return", "k", ".", "parseInt64s", "(", "k", ".", "Strings", "(", "delim", ")", ",", "false", ",", "true", ")", "\n", ...
// StrictInt64s returns list of int64 divided by given delimiter or error on first invalid input.
[ "StrictInt64s", "returns", "list", "of", "int64", "divided", "by", "given", "delimiter", "or", "error", "on", "first", "invalid", "input", "." ]
3be5ad479f69d4e08d7fe25edf79bf3346bd658e
https://github.com/go-ini/ini/blob/3be5ad479f69d4e08d7fe25edf79bf3346bd658e/key.go#L627-L629
train
go-ini/ini
key.go
StrictUints
func (k *Key) StrictUints(delim string) ([]uint, error) { return k.parseUints(k.Strings(delim), false, true) }
go
func (k *Key) StrictUints(delim string) ([]uint, error) { return k.parseUints(k.Strings(delim), false, true) }
[ "func", "(", "k", "*", "Key", ")", "StrictUints", "(", "delim", "string", ")", "(", "[", "]", "uint", ",", "error", ")", "{", "return", "k", ".", "parseUints", "(", "k", ".", "Strings", "(", "delim", ")", ",", "false", ",", "true", ")", "\n", "...
// StrictUints returns list of uint divided by given delimiter or error on first invalid input.
[ "StrictUints", "returns", "list", "of", "uint", "divided", "by", "given", "delimiter", "or", "error", "on", "first", "invalid", "input", "." ]
3be5ad479f69d4e08d7fe25edf79bf3346bd658e
https://github.com/go-ini/ini/blob/3be5ad479f69d4e08d7fe25edf79bf3346bd658e/key.go#L632-L634
train
go-ini/ini
key.go
StrictUint64s
func (k *Key) StrictUint64s(delim string) ([]uint64, error) { return k.parseUint64s(k.Strings(delim), false, true) }
go
func (k *Key) StrictUint64s(delim string) ([]uint64, error) { return k.parseUint64s(k.Strings(delim), false, true) }
[ "func", "(", "k", "*", "Key", ")", "StrictUint64s", "(", "delim", "string", ")", "(", "[", "]", "uint64", ",", "error", ")", "{", "return", "k", ".", "parseUint64s", "(", "k", ".", "Strings", "(", "delim", ")", ",", "false", ",", "true", ")", "\n...
// StrictUint64s returns list of uint64 divided by given delimiter or error on first invalid input.
[ "StrictUint64s", "returns", "list", "of", "uint64", "divided", "by", "given", "delimiter", "or", "error", "on", "first", "invalid", "input", "." ]
3be5ad479f69d4e08d7fe25edf79bf3346bd658e
https://github.com/go-ini/ini/blob/3be5ad479f69d4e08d7fe25edf79bf3346bd658e/key.go#L637-L639
train
go-ini/ini
key.go
StrictTimesFormat
func (k *Key) StrictTimesFormat(format, delim string) ([]time.Time, error) { return k.parseTimesFormat(format, k.Strings(delim), false, true) }
go
func (k *Key) StrictTimesFormat(format, delim string) ([]time.Time, error) { return k.parseTimesFormat(format, k.Strings(delim), false, true) }
[ "func", "(", "k", "*", "Key", ")", "StrictTimesFormat", "(", "format", ",", "delim", "string", ")", "(", "[", "]", "time", ".", "Time", ",", "error", ")", "{", "return", "k", ".", "parseTimesFormat", "(", "format", ",", "k", ".", "Strings", "(", "d...
// StrictTimesFormat parses with given format and returns list of time.Time divided by given delimiter // or error on first invalid input.
[ "StrictTimesFormat", "parses", "with", "given", "format", "and", "returns", "list", "of", "time", ".", "Time", "divided", "by", "given", "delimiter", "or", "error", "on", "first", "invalid", "input", "." ]
3be5ad479f69d4e08d7fe25edf79bf3346bd658e
https://github.com/go-ini/ini/blob/3be5ad479f69d4e08d7fe25edf79bf3346bd658e/key.go#L643-L645
train
go-ini/ini
key.go
StrictTimes
func (k *Key) StrictTimes(delim string) ([]time.Time, error) { return k.StrictTimesFormat(time.RFC3339, delim) }
go
func (k *Key) StrictTimes(delim string) ([]time.Time, error) { return k.StrictTimesFormat(time.RFC3339, delim) }
[ "func", "(", "k", "*", "Key", ")", "StrictTimes", "(", "delim", "string", ")", "(", "[", "]", "time", ".", "Time", ",", "error", ")", "{", "return", "k", ".", "StrictTimesFormat", "(", "time", ".", "RFC3339", ",", "delim", ")", "\n", "}" ]
// StrictTimes parses with RFC3339 format and returns list of time.Time divided by given delimiter // or error on first invalid input.
[ "StrictTimes", "parses", "with", "RFC3339", "format", "and", "returns", "list", "of", "time", ".", "Time", "divided", "by", "given", "delimiter", "or", "error", "on", "first", "invalid", "input", "." ]
3be5ad479f69d4e08d7fe25edf79bf3346bd658e
https://github.com/go-ini/ini/blob/3be5ad479f69d4e08d7fe25edf79bf3346bd658e/key.go#L649-L651
train
go-ini/ini
key.go
parseFloat64s
func (k *Key) parseFloat64s(strs []string, addInvalid, returnOnInvalid bool) ([]float64, error) { vals := make([]float64, 0, len(strs)) for _, str := range strs { val, err := strconv.ParseFloat(str, 64) if err != nil && returnOnInvalid { return nil, err } if err == nil || addInvalid { vals = append(vals, val) } } return vals, nil }
go
func (k *Key) parseFloat64s(strs []string, addInvalid, returnOnInvalid bool) ([]float64, error) { vals := make([]float64, 0, len(strs)) for _, str := range strs { val, err := strconv.ParseFloat(str, 64) if err != nil && returnOnInvalid { return nil, err } if err == nil || addInvalid { vals = append(vals, val) } } return vals, nil }
[ "func", "(", "k", "*", "Key", ")", "parseFloat64s", "(", "strs", "[", "]", "string", ",", "addInvalid", ",", "returnOnInvalid", "bool", ")", "(", "[", "]", "float64", ",", "error", ")", "{", "vals", ":=", "make", "(", "[", "]", "float64", ",", "0",...
// parseFloat64s transforms strings to float64s.
[ "parseFloat64s", "transforms", "strings", "to", "float64s", "." ]
3be5ad479f69d4e08d7fe25edf79bf3346bd658e
https://github.com/go-ini/ini/blob/3be5ad479f69d4e08d7fe25edf79bf3346bd658e/key.go#L654-L666
train
go-ini/ini
key.go
parseInts
func (k *Key) parseInts(strs []string, addInvalid, returnOnInvalid bool) ([]int, error) { vals := make([]int, 0, len(strs)) for _, str := range strs { valInt64, err := strconv.ParseInt(str, 0, 64) val := int(valInt64) if err != nil && returnOnInvalid { return nil, err } if err == nil || addInvalid { vals = append(vals, val) } } return vals, nil }
go
func (k *Key) parseInts(strs []string, addInvalid, returnOnInvalid bool) ([]int, error) { vals := make([]int, 0, len(strs)) for _, str := range strs { valInt64, err := strconv.ParseInt(str, 0, 64) val := int(valInt64) if err != nil && returnOnInvalid { return nil, err } if err == nil || addInvalid { vals = append(vals, val) } } return vals, nil }
[ "func", "(", "k", "*", "Key", ")", "parseInts", "(", "strs", "[", "]", "string", ",", "addInvalid", ",", "returnOnInvalid", "bool", ")", "(", "[", "]", "int", ",", "error", ")", "{", "vals", ":=", "make", "(", "[", "]", "int", ",", "0", ",", "l...
// parseInts transforms strings to ints.
[ "parseInts", "transforms", "strings", "to", "ints", "." ]
3be5ad479f69d4e08d7fe25edf79bf3346bd658e
https://github.com/go-ini/ini/blob/3be5ad479f69d4e08d7fe25edf79bf3346bd658e/key.go#L669-L682
train
go-ini/ini
key.go
parseInt64s
func (k *Key) parseInt64s(strs []string, addInvalid, returnOnInvalid bool) ([]int64, error) { vals := make([]int64, 0, len(strs)) for _, str := range strs { val, err := strconv.ParseInt(str, 0, 64) if err != nil && returnOnInvalid { return nil, err } if err == nil || addInvalid { vals = append(vals, val) } } return vals, nil }
go
func (k *Key) parseInt64s(strs []string, addInvalid, returnOnInvalid bool) ([]int64, error) { vals := make([]int64, 0, len(strs)) for _, str := range strs { val, err := strconv.ParseInt(str, 0, 64) if err != nil && returnOnInvalid { return nil, err } if err == nil || addInvalid { vals = append(vals, val) } } return vals, nil }
[ "func", "(", "k", "*", "Key", ")", "parseInt64s", "(", "strs", "[", "]", "string", ",", "addInvalid", ",", "returnOnInvalid", "bool", ")", "(", "[", "]", "int64", ",", "error", ")", "{", "vals", ":=", "make", "(", "[", "]", "int64", ",", "0", ","...
// parseInt64s transforms strings to int64s.
[ "parseInt64s", "transforms", "strings", "to", "int64s", "." ]
3be5ad479f69d4e08d7fe25edf79bf3346bd658e
https://github.com/go-ini/ini/blob/3be5ad479f69d4e08d7fe25edf79bf3346bd658e/key.go#L685-L697
train
go-ini/ini
key.go
parseUints
func (k *Key) parseUints(strs []string, addInvalid, returnOnInvalid bool) ([]uint, error) { vals := make([]uint, 0, len(strs)) for _, str := range strs { val, err := strconv.ParseUint(str, 0, 0) if err != nil && returnOnInvalid { return nil, err } if err == nil || addInvalid { vals = append(vals, uint(val)) } } return vals, nil }
go
func (k *Key) parseUints(strs []string, addInvalid, returnOnInvalid bool) ([]uint, error) { vals := make([]uint, 0, len(strs)) for _, str := range strs { val, err := strconv.ParseUint(str, 0, 0) if err != nil && returnOnInvalid { return nil, err } if err == nil || addInvalid { vals = append(vals, uint(val)) } } return vals, nil }
[ "func", "(", "k", "*", "Key", ")", "parseUints", "(", "strs", "[", "]", "string", ",", "addInvalid", ",", "returnOnInvalid", "bool", ")", "(", "[", "]", "uint", ",", "error", ")", "{", "vals", ":=", "make", "(", "[", "]", "uint", ",", "0", ",", ...
// parseUints transforms strings to uints.
[ "parseUints", "transforms", "strings", "to", "uints", "." ]
3be5ad479f69d4e08d7fe25edf79bf3346bd658e
https://github.com/go-ini/ini/blob/3be5ad479f69d4e08d7fe25edf79bf3346bd658e/key.go#L700-L712
train
go-ini/ini
key.go
parseTimesFormat
func (k *Key) parseTimesFormat(format string, strs []string, addInvalid, returnOnInvalid bool) ([]time.Time, error) { vals := make([]time.Time, 0, len(strs)) for _, str := range strs { val, err := time.Parse(format, str) if err != nil && returnOnInvalid { return nil, err } if err == nil || addInvalid { vals = append(vals, val) } } return vals, nil }
go
func (k *Key) parseTimesFormat(format string, strs []string, addInvalid, returnOnInvalid bool) ([]time.Time, error) { vals := make([]time.Time, 0, len(strs)) for _, str := range strs { val, err := time.Parse(format, str) if err != nil && returnOnInvalid { return nil, err } if err == nil || addInvalid { vals = append(vals, val) } } return vals, nil }
[ "func", "(", "k", "*", "Key", ")", "parseTimesFormat", "(", "format", "string", ",", "strs", "[", "]", "string", ",", "addInvalid", ",", "returnOnInvalid", "bool", ")", "(", "[", "]", "time", ".", "Time", ",", "error", ")", "{", "vals", ":=", "make",...
// parseTimesFormat transforms strings to times in given format.
[ "parseTimesFormat", "transforms", "strings", "to", "times", "in", "given", "format", "." ]
3be5ad479f69d4e08d7fe25edf79bf3346bd658e
https://github.com/go-ini/ini/blob/3be5ad479f69d4e08d7fe25edf79bf3346bd658e/key.go#L730-L742
train
go-ini/ini
key.go
SetValue
func (k *Key) SetValue(v string) { if k.s.f.BlockMode { k.s.f.lock.Lock() defer k.s.f.lock.Unlock() } k.value = v k.s.keysHash[k.name] = v }
go
func (k *Key) SetValue(v string) { if k.s.f.BlockMode { k.s.f.lock.Lock() defer k.s.f.lock.Unlock() } k.value = v k.s.keysHash[k.name] = v }
[ "func", "(", "k", "*", "Key", ")", "SetValue", "(", "v", "string", ")", "{", "if", "k", ".", "s", ".", "f", ".", "BlockMode", "{", "k", ".", "s", ".", "f", ".", "lock", ".", "Lock", "(", ")", "\n", "defer", "k", ".", "s", ".", "f", ".", ...
// SetValue changes key value.
[ "SetValue", "changes", "key", "value", "." ]
3be5ad479f69d4e08d7fe25edf79bf3346bd658e
https://github.com/go-ini/ini/blob/3be5ad479f69d4e08d7fe25edf79bf3346bd658e/key.go#L745-L753
train
go-ini/ini
parser.go
hasSurroundedQuote
func hasSurroundedQuote(in string, quote byte) bool { return len(in) >= 2 && in[0] == quote && in[len(in)-1] == quote && strings.IndexByte(in[1:], quote) == len(in)-2 }
go
func hasSurroundedQuote(in string, quote byte) bool { return len(in) >= 2 && in[0] == quote && in[len(in)-1] == quote && strings.IndexByte(in[1:], quote) == len(in)-2 }
[ "func", "hasSurroundedQuote", "(", "in", "string", ",", "quote", "byte", ")", "bool", "{", "return", "len", "(", "in", ")", ">=", "2", "&&", "in", "[", "0", "]", "==", "quote", "&&", "in", "[", "len", "(", "in", ")", "-", "1", "]", "==", "quote...
// hasSurroundedQuote check if and only if the first and last characters // are quotes \" or \'. // It returns false if any other parts also contain same kind of quotes.
[ "hasSurroundedQuote", "check", "if", "and", "only", "if", "the", "first", "and", "last", "characters", "are", "quotes", "\\", "or", "\\", ".", "It", "returns", "false", "if", "any", "other", "parts", "also", "contain", "same", "kind", "of", "quotes", "." ]
3be5ad479f69d4e08d7fe25edf79bf3346bd658e
https://github.com/go-ini/ini/blob/3be5ad479f69d4e08d7fe25edf79bf3346bd658e/parser.go#L198-L201
train
go-ini/ini
struct.go
setWithProperType
func setWithProperType(t reflect.Type, key *Key, field reflect.Value, delim string, allowShadow, isStrict bool) error { switch t.Kind() { case reflect.String: if len(key.String()) == 0 { return nil } field.SetString(key.String()) case reflect.Bool: boolVal, err := key.Bool() if err != nil { return wrapStrictError(err, isStrict) } field.SetBool(boolVal) case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: durationVal, err := key.Duration() // Skip zero value if err == nil && int64(durationVal) > 0 { field.Set(reflect.ValueOf(durationVal)) return nil } intVal, err := key.Int64() if err != nil { return wrapStrictError(err, isStrict) } field.SetInt(intVal) // byte is an alias for uint8, so supporting uint8 breaks support for byte case reflect.Uint, reflect.Uint16, reflect.Uint32, reflect.Uint64: durationVal, err := key.Duration() // Skip zero value if err == nil && uint64(durationVal) > 0 { field.Set(reflect.ValueOf(durationVal)) return nil } uintVal, err := key.Uint64() if err != nil { return wrapStrictError(err, isStrict) } field.SetUint(uintVal) case reflect.Float32, reflect.Float64: floatVal, err := key.Float64() if err != nil { return wrapStrictError(err, isStrict) } field.SetFloat(floatVal) case reflectTime: timeVal, err := key.Time() if err != nil { return wrapStrictError(err, isStrict) } field.Set(reflect.ValueOf(timeVal)) case reflect.Slice: return setSliceWithProperType(key, field, delim, allowShadow, isStrict) default: return fmt.Errorf("unsupported type '%s'", t) } return nil }
go
func setWithProperType(t reflect.Type, key *Key, field reflect.Value, delim string, allowShadow, isStrict bool) error { switch t.Kind() { case reflect.String: if len(key.String()) == 0 { return nil } field.SetString(key.String()) case reflect.Bool: boolVal, err := key.Bool() if err != nil { return wrapStrictError(err, isStrict) } field.SetBool(boolVal) case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: durationVal, err := key.Duration() // Skip zero value if err == nil && int64(durationVal) > 0 { field.Set(reflect.ValueOf(durationVal)) return nil } intVal, err := key.Int64() if err != nil { return wrapStrictError(err, isStrict) } field.SetInt(intVal) // byte is an alias for uint8, so supporting uint8 breaks support for byte case reflect.Uint, reflect.Uint16, reflect.Uint32, reflect.Uint64: durationVal, err := key.Duration() // Skip zero value if err == nil && uint64(durationVal) > 0 { field.Set(reflect.ValueOf(durationVal)) return nil } uintVal, err := key.Uint64() if err != nil { return wrapStrictError(err, isStrict) } field.SetUint(uintVal) case reflect.Float32, reflect.Float64: floatVal, err := key.Float64() if err != nil { return wrapStrictError(err, isStrict) } field.SetFloat(floatVal) case reflectTime: timeVal, err := key.Time() if err != nil { return wrapStrictError(err, isStrict) } field.Set(reflect.ValueOf(timeVal)) case reflect.Slice: return setSliceWithProperType(key, field, delim, allowShadow, isStrict) default: return fmt.Errorf("unsupported type '%s'", t) } return nil }
[ "func", "setWithProperType", "(", "t", "reflect", ".", "Type", ",", "key", "*", "Key", ",", "field", "reflect", ".", "Value", ",", "delim", "string", ",", "allowShadow", ",", "isStrict", "bool", ")", "error", "{", "switch", "t", ".", "Kind", "(", ")", ...
// setWithProperType sets proper value to field based on its type, // but it does not return error for failing parsing, // because we want to use default value that is already assigned to strcut.
[ "setWithProperType", "sets", "proper", "value", "to", "field", "based", "on", "its", "type", "but", "it", "does", "not", "return", "error", "for", "failing", "parsing", "because", "we", "want", "to", "use", "default", "value", "that", "is", "already", "assig...
3be5ad479f69d4e08d7fe25edf79bf3346bd658e
https://github.com/go-ini/ini/blob/3be5ad479f69d4e08d7fe25edf79bf3346bd658e/struct.go#L153-L212
train
go-ini/ini
struct.go
MapTo
func (s *Section) MapTo(v interface{}) error { typ := reflect.TypeOf(v) val := reflect.ValueOf(v) if typ.Kind() == reflect.Ptr { typ = typ.Elem() val = val.Elem() } else { return errors.New("cannot map to non-pointer struct") } return s.mapTo(val, false) }
go
func (s *Section) MapTo(v interface{}) error { typ := reflect.TypeOf(v) val := reflect.ValueOf(v) if typ.Kind() == reflect.Ptr { typ = typ.Elem() val = val.Elem() } else { return errors.New("cannot map to non-pointer struct") } return s.mapTo(val, false) }
[ "func", "(", "s", "*", "Section", ")", "MapTo", "(", "v", "interface", "{", "}", ")", "error", "{", "typ", ":=", "reflect", ".", "TypeOf", "(", "v", ")", "\n", "val", ":=", "reflect", ".", "ValueOf", "(", "v", ")", "\n", "if", "typ", ".", "Kind...
// MapTo maps section to given struct.
[ "MapTo", "maps", "section", "to", "given", "struct", "." ]
3be5ad479f69d4e08d7fe25edf79bf3346bd658e
https://github.com/go-ini/ini/blob/3be5ad479f69d4e08d7fe25edf79bf3346bd658e/struct.go#L273-L284
train
go-ini/ini
struct.go
StrictMapTo
func (s *Section) StrictMapTo(v interface{}) error { typ := reflect.TypeOf(v) val := reflect.ValueOf(v) if typ.Kind() == reflect.Ptr { typ = typ.Elem() val = val.Elem() } else { return errors.New("cannot map to non-pointer struct") } return s.mapTo(val, true) }
go
func (s *Section) StrictMapTo(v interface{}) error { typ := reflect.TypeOf(v) val := reflect.ValueOf(v) if typ.Kind() == reflect.Ptr { typ = typ.Elem() val = val.Elem() } else { return errors.New("cannot map to non-pointer struct") } return s.mapTo(val, true) }
[ "func", "(", "s", "*", "Section", ")", "StrictMapTo", "(", "v", "interface", "{", "}", ")", "error", "{", "typ", ":=", "reflect", ".", "TypeOf", "(", "v", ")", "\n", "val", ":=", "reflect", ".", "ValueOf", "(", "v", ")", "\n", "if", "typ", ".", ...
// StrictMapTo maps section to given struct in strict mode, // which returns all possible error including value parsing error.
[ "StrictMapTo", "maps", "section", "to", "given", "struct", "in", "strict", "mode", "which", "returns", "all", "possible", "error", "including", "value", "parsing", "error", "." ]
3be5ad479f69d4e08d7fe25edf79bf3346bd658e
https://github.com/go-ini/ini/blob/3be5ad479f69d4e08d7fe25edf79bf3346bd658e/struct.go#L288-L299
train
go-ini/ini
struct.go
MapToWithMapper
func MapToWithMapper(v interface{}, mapper NameMapper, source interface{}, others ...interface{}) error { cfg, err := Load(source, others...) if err != nil { return err } cfg.NameMapper = mapper return cfg.MapTo(v) }
go
func MapToWithMapper(v interface{}, mapper NameMapper, source interface{}, others ...interface{}) error { cfg, err := Load(source, others...) if err != nil { return err } cfg.NameMapper = mapper return cfg.MapTo(v) }
[ "func", "MapToWithMapper", "(", "v", "interface", "{", "}", ",", "mapper", "NameMapper", ",", "source", "interface", "{", "}", ",", "others", "...", "interface", "{", "}", ")", "error", "{", "cfg", ",", "err", ":=", "Load", "(", "source", ",", "others"...
// MapToWithMapper maps data sources to given struct with name mapper.
[ "MapToWithMapper", "maps", "data", "sources", "to", "given", "struct", "with", "name", "mapper", "." ]
3be5ad479f69d4e08d7fe25edf79bf3346bd658e
https://github.com/go-ini/ini/blob/3be5ad479f69d4e08d7fe25edf79bf3346bd658e/struct.go#L313-L320
train
go-ini/ini
struct.go
StrictMapToWithMapper
func StrictMapToWithMapper(v interface{}, mapper NameMapper, source interface{}, others ...interface{}) error { cfg, err := Load(source, others...) if err != nil { return err } cfg.NameMapper = mapper return cfg.StrictMapTo(v) }
go
func StrictMapToWithMapper(v interface{}, mapper NameMapper, source interface{}, others ...interface{}) error { cfg, err := Load(source, others...) if err != nil { return err } cfg.NameMapper = mapper return cfg.StrictMapTo(v) }
[ "func", "StrictMapToWithMapper", "(", "v", "interface", "{", "}", ",", "mapper", "NameMapper", ",", "source", "interface", "{", "}", ",", "others", "...", "interface", "{", "}", ")", "error", "{", "cfg", ",", "err", ":=", "Load", "(", "source", ",", "o...
// StrictMapToWithMapper maps data sources to given struct with name mapper in strict mode, // which returns all possible error including value parsing error.
[ "StrictMapToWithMapper", "maps", "data", "sources", "to", "given", "struct", "with", "name", "mapper", "in", "strict", "mode", "which", "returns", "all", "possible", "error", "including", "value", "parsing", "error", "." ]
3be5ad479f69d4e08d7fe25edf79bf3346bd658e
https://github.com/go-ini/ini/blob/3be5ad479f69d4e08d7fe25edf79bf3346bd658e/struct.go#L324-L331
train
go-ini/ini
struct.go
MapTo
func MapTo(v, source interface{}, others ...interface{}) error { return MapToWithMapper(v, nil, source, others...) }
go
func MapTo(v, source interface{}, others ...interface{}) error { return MapToWithMapper(v, nil, source, others...) }
[ "func", "MapTo", "(", "v", ",", "source", "interface", "{", "}", ",", "others", "...", "interface", "{", "}", ")", "error", "{", "return", "MapToWithMapper", "(", "v", ",", "nil", ",", "source", ",", "others", "...", ")", "\n", "}" ]
// MapTo maps data sources to given struct.
[ "MapTo", "maps", "data", "sources", "to", "given", "struct", "." ]
3be5ad479f69d4e08d7fe25edf79bf3346bd658e
https://github.com/go-ini/ini/blob/3be5ad479f69d4e08d7fe25edf79bf3346bd658e/struct.go#L334-L336
train
go-ini/ini
struct.go
StrictMapTo
func StrictMapTo(v, source interface{}, others ...interface{}) error { return StrictMapToWithMapper(v, nil, source, others...) }
go
func StrictMapTo(v, source interface{}, others ...interface{}) error { return StrictMapToWithMapper(v, nil, source, others...) }
[ "func", "StrictMapTo", "(", "v", ",", "source", "interface", "{", "}", ",", "others", "...", "interface", "{", "}", ")", "error", "{", "return", "StrictMapToWithMapper", "(", "v", ",", "nil", ",", "source", ",", "others", "...", ")", "\n", "}" ]
// StrictMapTo maps data sources to given struct in strict mode, // which returns all possible error including value parsing error.
[ "StrictMapTo", "maps", "data", "sources", "to", "given", "struct", "in", "strict", "mode", "which", "returns", "all", "possible", "error", "including", "value", "parsing", "error", "." ]
3be5ad479f69d4e08d7fe25edf79bf3346bd658e
https://github.com/go-ini/ini/blob/3be5ad479f69d4e08d7fe25edf79bf3346bd658e/struct.go#L340-L342
train
go-ini/ini
struct.go
reflectSliceWithProperType
func reflectSliceWithProperType(key *Key, field reflect.Value, delim string) error { slice := field.Slice(0, field.Len()) if field.Len() == 0 { return nil } var buf bytes.Buffer sliceOf := field.Type().Elem().Kind() for i := 0; i < field.Len(); i++ { switch sliceOf { case reflect.String: buf.WriteString(slice.Index(i).String()) case reflect.Int, reflect.Int64: buf.WriteString(fmt.Sprint(slice.Index(i).Int())) case reflect.Uint, reflect.Uint64: buf.WriteString(fmt.Sprint(slice.Index(i).Uint())) case reflect.Float64: buf.WriteString(fmt.Sprint(slice.Index(i).Float())) case reflectTime: buf.WriteString(slice.Index(i).Interface().(time.Time).Format(time.RFC3339)) default: return fmt.Errorf("unsupported type '[]%s'", sliceOf) } buf.WriteString(delim) } key.SetValue(buf.String()[:buf.Len()-1]) return nil }
go
func reflectSliceWithProperType(key *Key, field reflect.Value, delim string) error { slice := field.Slice(0, field.Len()) if field.Len() == 0 { return nil } var buf bytes.Buffer sliceOf := field.Type().Elem().Kind() for i := 0; i < field.Len(); i++ { switch sliceOf { case reflect.String: buf.WriteString(slice.Index(i).String()) case reflect.Int, reflect.Int64: buf.WriteString(fmt.Sprint(slice.Index(i).Int())) case reflect.Uint, reflect.Uint64: buf.WriteString(fmt.Sprint(slice.Index(i).Uint())) case reflect.Float64: buf.WriteString(fmt.Sprint(slice.Index(i).Float())) case reflectTime: buf.WriteString(slice.Index(i).Interface().(time.Time).Format(time.RFC3339)) default: return fmt.Errorf("unsupported type '[]%s'", sliceOf) } buf.WriteString(delim) } key.SetValue(buf.String()[:buf.Len()-1]) return nil }
[ "func", "reflectSliceWithProperType", "(", "key", "*", "Key", ",", "field", "reflect", ".", "Value", ",", "delim", "string", ")", "error", "{", "slice", ":=", "field", ".", "Slice", "(", "0", ",", "field", ".", "Len", "(", ")", ")", "\n", "if", "fiel...
// reflectSliceWithProperType does the opposite thing as setSliceWithProperType.
[ "reflectSliceWithProperType", "does", "the", "opposite", "thing", "as", "setSliceWithProperType", "." ]
3be5ad479f69d4e08d7fe25edf79bf3346bd658e
https://github.com/go-ini/ini/blob/3be5ad479f69d4e08d7fe25edf79bf3346bd658e/struct.go#L345-L372
train
go-ini/ini
struct.go
reflectWithProperType
func reflectWithProperType(t reflect.Type, key *Key, field reflect.Value, delim string) error { switch t.Kind() { case reflect.String: key.SetValue(field.String()) case reflect.Bool: key.SetValue(fmt.Sprint(field.Bool())) case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: key.SetValue(fmt.Sprint(field.Int())) case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64: key.SetValue(fmt.Sprint(field.Uint())) case reflect.Float32, reflect.Float64: key.SetValue(fmt.Sprint(field.Float())) case reflectTime: key.SetValue(fmt.Sprint(field.Interface().(time.Time).Format(time.RFC3339))) case reflect.Slice: return reflectSliceWithProperType(key, field, delim) default: return fmt.Errorf("unsupported type '%s'", t) } return nil }
go
func reflectWithProperType(t reflect.Type, key *Key, field reflect.Value, delim string) error { switch t.Kind() { case reflect.String: key.SetValue(field.String()) case reflect.Bool: key.SetValue(fmt.Sprint(field.Bool())) case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: key.SetValue(fmt.Sprint(field.Int())) case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64: key.SetValue(fmt.Sprint(field.Uint())) case reflect.Float32, reflect.Float64: key.SetValue(fmt.Sprint(field.Float())) case reflectTime: key.SetValue(fmt.Sprint(field.Interface().(time.Time).Format(time.RFC3339))) case reflect.Slice: return reflectSliceWithProperType(key, field, delim) default: return fmt.Errorf("unsupported type '%s'", t) } return nil }
[ "func", "reflectWithProperType", "(", "t", "reflect", ".", "Type", ",", "key", "*", "Key", ",", "field", "reflect", ".", "Value", ",", "delim", "string", ")", "error", "{", "switch", "t", ".", "Kind", "(", ")", "{", "case", "reflect", ".", "String", ...
// reflectWithProperType does the opposite thing as setWithProperType.
[ "reflectWithProperType", "does", "the", "opposite", "thing", "as", "setWithProperType", "." ]
3be5ad479f69d4e08d7fe25edf79bf3346bd658e
https://github.com/go-ini/ini/blob/3be5ad479f69d4e08d7fe25edf79bf3346bd658e/struct.go#L375-L395
train
go-ini/ini
struct.go
ReflectFrom
func (s *Section) ReflectFrom(v interface{}) error { typ := reflect.TypeOf(v) val := reflect.ValueOf(v) if typ.Kind() == reflect.Ptr { typ = typ.Elem() val = val.Elem() } else { return errors.New("cannot reflect from non-pointer struct") } return s.reflectFrom(val) }
go
func (s *Section) ReflectFrom(v interface{}) error { typ := reflect.TypeOf(v) val := reflect.ValueOf(v) if typ.Kind() == reflect.Ptr { typ = typ.Elem() val = val.Elem() } else { return errors.New("cannot reflect from non-pointer struct") } return s.reflectFrom(val) }
[ "func", "(", "s", "*", "Section", ")", "ReflectFrom", "(", "v", "interface", "{", "}", ")", "error", "{", "typ", ":=", "reflect", ".", "TypeOf", "(", "v", ")", "\n", "val", ":=", "reflect", ".", "ValueOf", "(", "v", ")", "\n", "if", "typ", ".", ...
// ReflectFrom reflects secion from given struct.
[ "ReflectFrom", "reflects", "secion", "from", "given", "struct", "." ]
3be5ad479f69d4e08d7fe25edf79bf3346bd658e
https://github.com/go-ini/ini/blob/3be5ad479f69d4e08d7fe25edf79bf3346bd658e/struct.go#L485-L496
train
go-ini/ini
struct.go
ReflectFromWithMapper
func ReflectFromWithMapper(cfg *File, v interface{}, mapper NameMapper) error { cfg.NameMapper = mapper return cfg.ReflectFrom(v) }
go
func ReflectFromWithMapper(cfg *File, v interface{}, mapper NameMapper) error { cfg.NameMapper = mapper return cfg.ReflectFrom(v) }
[ "func", "ReflectFromWithMapper", "(", "cfg", "*", "File", ",", "v", "interface", "{", "}", ",", "mapper", "NameMapper", ")", "error", "{", "cfg", ".", "NameMapper", "=", "mapper", "\n", "return", "cfg", ".", "ReflectFrom", "(", "v", ")", "\n", "}" ]
// ReflectFromWithMapper reflects data sources from given struct with name mapper.
[ "ReflectFromWithMapper", "reflects", "data", "sources", "from", "given", "struct", "with", "name", "mapper", "." ]
3be5ad479f69d4e08d7fe25edf79bf3346bd658e
https://github.com/go-ini/ini/blob/3be5ad479f69d4e08d7fe25edf79bf3346bd658e/struct.go#L504-L507
train
go-ini/ini
section.go
SetBody
func (s *Section) SetBody(body string) { if !s.isRawSection { return } s.rawBody = body }
go
func (s *Section) SetBody(body string) { if !s.isRawSection { return } s.rawBody = body }
[ "func", "(", "s", "*", "Section", ")", "SetBody", "(", "body", "string", ")", "{", "if", "!", "s", ".", "isRawSection", "{", "return", "\n", "}", "\n", "s", ".", "rawBody", "=", "body", "\n", "}" ]
// SetBody updates body content only if section is raw.
[ "SetBody", "updates", "body", "content", "only", "if", "section", "is", "raw", "." ]
3be5ad479f69d4e08d7fe25edf79bf3346bd658e
https://github.com/go-ini/ini/blob/3be5ad479f69d4e08d7fe25edf79bf3346bd658e/section.go#L58-L63
train
go-ini/ini
section.go
NewKey
func (s *Section) NewKey(name, val string) (*Key, error) { if len(name) == 0 { return nil, errors.New("error creating new key: empty key name") } else if s.f.options.Insensitive { name = strings.ToLower(name) } if s.f.BlockMode { s.f.lock.Lock() defer s.f.lock.Unlock() } if inSlice(name, s.keyList) { if s.f.options.AllowShadows { if err := s.keys[name].addShadow(val); err != nil { return nil, err } } else { s.keys[name].value = val s.keysHash[name] = val } return s.keys[name], nil } s.keyList = append(s.keyList, name) s.keys[name] = newKey(s, name, val) s.keysHash[name] = val return s.keys[name], nil }
go
func (s *Section) NewKey(name, val string) (*Key, error) { if len(name) == 0 { return nil, errors.New("error creating new key: empty key name") } else if s.f.options.Insensitive { name = strings.ToLower(name) } if s.f.BlockMode { s.f.lock.Lock() defer s.f.lock.Unlock() } if inSlice(name, s.keyList) { if s.f.options.AllowShadows { if err := s.keys[name].addShadow(val); err != nil { return nil, err } } else { s.keys[name].value = val s.keysHash[name] = val } return s.keys[name], nil } s.keyList = append(s.keyList, name) s.keys[name] = newKey(s, name, val) s.keysHash[name] = val return s.keys[name], nil }
[ "func", "(", "s", "*", "Section", ")", "NewKey", "(", "name", ",", "val", "string", ")", "(", "*", "Key", ",", "error", ")", "{", "if", "len", "(", "name", ")", "==", "0", "{", "return", "nil", ",", "errors", ".", "New", "(", "\"", "\"", ")",...
// NewKey creates a new key to given section.
[ "NewKey", "creates", "a", "new", "key", "to", "given", "section", "." ]
3be5ad479f69d4e08d7fe25edf79bf3346bd658e
https://github.com/go-ini/ini/blob/3be5ad479f69d4e08d7fe25edf79bf3346bd658e/section.go#L66-L94
train
go-ini/ini
section.go
NewBooleanKey
func (s *Section) NewBooleanKey(name string) (*Key, error) { key, err := s.NewKey(name, "true") if err != nil { return nil, err } key.isBooleanType = true return key, nil }
go
func (s *Section) NewBooleanKey(name string) (*Key, error) { key, err := s.NewKey(name, "true") if err != nil { return nil, err } key.isBooleanType = true return key, nil }
[ "func", "(", "s", "*", "Section", ")", "NewBooleanKey", "(", "name", "string", ")", "(", "*", "Key", ",", "error", ")", "{", "key", ",", "err", ":=", "s", ".", "NewKey", "(", "name", ",", "\"", "\"", ")", "\n", "if", "err", "!=", "nil", "{", ...
// NewBooleanKey creates a new boolean type key to given section.
[ "NewBooleanKey", "creates", "a", "new", "boolean", "type", "key", "to", "given", "section", "." ]
3be5ad479f69d4e08d7fe25edf79bf3346bd658e
https://github.com/go-ini/ini/blob/3be5ad479f69d4e08d7fe25edf79bf3346bd658e/section.go#L97-L105
train
go-ini/ini
section.go
GetKey
func (s *Section) GetKey(name string) (*Key, error) { if s.f.BlockMode { s.f.lock.RLock() } if s.f.options.Insensitive { name = strings.ToLower(name) } key := s.keys[name] if s.f.BlockMode { s.f.lock.RUnlock() } if key == nil { // Check if it is a child-section. sname := s.name for { if i := strings.LastIndex(sname, "."); i > -1 { sname = sname[:i] sec, err := s.f.GetSection(sname) if err != nil { continue } return sec.GetKey(name) } break } return nil, fmt.Errorf("error when getting key of section '%s': key '%s' not exists", s.name, name) } return key, nil }
go
func (s *Section) GetKey(name string) (*Key, error) { if s.f.BlockMode { s.f.lock.RLock() } if s.f.options.Insensitive { name = strings.ToLower(name) } key := s.keys[name] if s.f.BlockMode { s.f.lock.RUnlock() } if key == nil { // Check if it is a child-section. sname := s.name for { if i := strings.LastIndex(sname, "."); i > -1 { sname = sname[:i] sec, err := s.f.GetSection(sname) if err != nil { continue } return sec.GetKey(name) } break } return nil, fmt.Errorf("error when getting key of section '%s': key '%s' not exists", s.name, name) } return key, nil }
[ "func", "(", "s", "*", "Section", ")", "GetKey", "(", "name", "string", ")", "(", "*", "Key", ",", "error", ")", "{", "if", "s", ".", "f", ".", "BlockMode", "{", "s", ".", "f", ".", "lock", ".", "RLock", "(", ")", "\n", "}", "\n", "if", "s"...
// GetKey returns key in section by given name.
[ "GetKey", "returns", "key", "in", "section", "by", "given", "name", "." ]
3be5ad479f69d4e08d7fe25edf79bf3346bd658e
https://github.com/go-ini/ini/blob/3be5ad479f69d4e08d7fe25edf79bf3346bd658e/section.go#L108-L137
train
go-ini/ini
section.go
HasKey
func (s *Section) HasKey(name string) bool { key, _ := s.GetKey(name) return key != nil }
go
func (s *Section) HasKey(name string) bool { key, _ := s.GetKey(name) return key != nil }
[ "func", "(", "s", "*", "Section", ")", "HasKey", "(", "name", "string", ")", "bool", "{", "key", ",", "_", ":=", "s", ".", "GetKey", "(", "name", ")", "\n", "return", "key", "!=", "nil", "\n", "}" ]
// HasKey returns true if section contains a key with given name.
[ "HasKey", "returns", "true", "if", "section", "contains", "a", "key", "with", "given", "name", "." ]
3be5ad479f69d4e08d7fe25edf79bf3346bd658e
https://github.com/go-ini/ini/blob/3be5ad479f69d4e08d7fe25edf79bf3346bd658e/section.go#L140-L143
train
go-ini/ini
section.go
HasValue
func (s *Section) HasValue(value string) bool { if s.f.BlockMode { s.f.lock.RLock() defer s.f.lock.RUnlock() } for _, k := range s.keys { if value == k.value { return true } } return false }
go
func (s *Section) HasValue(value string) bool { if s.f.BlockMode { s.f.lock.RLock() defer s.f.lock.RUnlock() } for _, k := range s.keys { if value == k.value { return true } } return false }
[ "func", "(", "s", "*", "Section", ")", "HasValue", "(", "value", "string", ")", "bool", "{", "if", "s", ".", "f", ".", "BlockMode", "{", "s", ".", "f", ".", "lock", ".", "RLock", "(", ")", "\n", "defer", "s", ".", "f", ".", "lock", ".", "RUnl...
// HasValue returns true if section contains given raw value.
[ "HasValue", "returns", "true", "if", "section", "contains", "given", "raw", "value", "." ]
3be5ad479f69d4e08d7fe25edf79bf3346bd658e
https://github.com/go-ini/ini/blob/3be5ad479f69d4e08d7fe25edf79bf3346bd658e/section.go#L151-L163
train
go-ini/ini
section.go
Key
func (s *Section) Key(name string) *Key { key, err := s.GetKey(name) if err != nil { // It's OK here because the only possible error is empty key name, // but if it's empty, this piece of code won't be executed. key, _ = s.NewKey(name, "") return key } return key }
go
func (s *Section) Key(name string) *Key { key, err := s.GetKey(name) if err != nil { // It's OK here because the only possible error is empty key name, // but if it's empty, this piece of code won't be executed. key, _ = s.NewKey(name, "") return key } return key }
[ "func", "(", "s", "*", "Section", ")", "Key", "(", "name", "string", ")", "*", "Key", "{", "key", ",", "err", ":=", "s", ".", "GetKey", "(", "name", ")", "\n", "if", "err", "!=", "nil", "{", "// It's OK here because the only possible error is empty key nam...
// Key assumes named Key exists in section and returns a zero-value when not.
[ "Key", "assumes", "named", "Key", "exists", "in", "section", "and", "returns", "a", "zero", "-", "value", "when", "not", "." ]
3be5ad479f69d4e08d7fe25edf79bf3346bd658e
https://github.com/go-ini/ini/blob/3be5ad479f69d4e08d7fe25edf79bf3346bd658e/section.go#L166-L175
train
go-ini/ini
section.go
Keys
func (s *Section) Keys() []*Key { keys := make([]*Key, len(s.keyList)) for i := range s.keyList { keys[i] = s.Key(s.keyList[i]) } return keys }
go
func (s *Section) Keys() []*Key { keys := make([]*Key, len(s.keyList)) for i := range s.keyList { keys[i] = s.Key(s.keyList[i]) } return keys }
[ "func", "(", "s", "*", "Section", ")", "Keys", "(", ")", "[", "]", "*", "Key", "{", "keys", ":=", "make", "(", "[", "]", "*", "Key", ",", "len", "(", "s", ".", "keyList", ")", ")", "\n", "for", "i", ":=", "range", "s", ".", "keyList", "{", ...
// Keys returns list of keys of section.
[ "Keys", "returns", "list", "of", "keys", "of", "section", "." ]
3be5ad479f69d4e08d7fe25edf79bf3346bd658e
https://github.com/go-ini/ini/blob/3be5ad479f69d4e08d7fe25edf79bf3346bd658e/section.go#L178-L184
train
go-ini/ini
section.go
ParentKeys
func (s *Section) ParentKeys() []*Key { var parentKeys []*Key sname := s.name for { if i := strings.LastIndex(sname, "."); i > -1 { sname = sname[:i] sec, err := s.f.GetSection(sname) if err != nil { continue } parentKeys = append(parentKeys, sec.Keys()...) } else { break } } return parentKeys }
go
func (s *Section) ParentKeys() []*Key { var parentKeys []*Key sname := s.name for { if i := strings.LastIndex(sname, "."); i > -1 { sname = sname[:i] sec, err := s.f.GetSection(sname) if err != nil { continue } parentKeys = append(parentKeys, sec.Keys()...) } else { break } } return parentKeys }
[ "func", "(", "s", "*", "Section", ")", "ParentKeys", "(", ")", "[", "]", "*", "Key", "{", "var", "parentKeys", "[", "]", "*", "Key", "\n", "sname", ":=", "s", ".", "name", "\n", "for", "{", "if", "i", ":=", "strings", ".", "LastIndex", "(", "sn...
// ParentKeys returns list of keys of parent section.
[ "ParentKeys", "returns", "list", "of", "keys", "of", "parent", "section", "." ]
3be5ad479f69d4e08d7fe25edf79bf3346bd658e
https://github.com/go-ini/ini/blob/3be5ad479f69d4e08d7fe25edf79bf3346bd658e/section.go#L187-L204
train
go-ini/ini
section.go
KeyStrings
func (s *Section) KeyStrings() []string { list := make([]string, len(s.keyList)) copy(list, s.keyList) return list }
go
func (s *Section) KeyStrings() []string { list := make([]string, len(s.keyList)) copy(list, s.keyList) return list }
[ "func", "(", "s", "*", "Section", ")", "KeyStrings", "(", ")", "[", "]", "string", "{", "list", ":=", "make", "(", "[", "]", "string", ",", "len", "(", "s", ".", "keyList", ")", ")", "\n", "copy", "(", "list", ",", "s", ".", "keyList", ")", "...
// KeyStrings returns list of key names of section.
[ "KeyStrings", "returns", "list", "of", "key", "names", "of", "section", "." ]
3be5ad479f69d4e08d7fe25edf79bf3346bd658e
https://github.com/go-ini/ini/blob/3be5ad479f69d4e08d7fe25edf79bf3346bd658e/section.go#L207-L211
train
go-ini/ini
section.go
KeysHash
func (s *Section) KeysHash() map[string]string { if s.f.BlockMode { s.f.lock.RLock() defer s.f.lock.RUnlock() } hash := map[string]string{} for key, value := range s.keysHash { hash[key] = value } return hash }
go
func (s *Section) KeysHash() map[string]string { if s.f.BlockMode { s.f.lock.RLock() defer s.f.lock.RUnlock() } hash := map[string]string{} for key, value := range s.keysHash { hash[key] = value } return hash }
[ "func", "(", "s", "*", "Section", ")", "KeysHash", "(", ")", "map", "[", "string", "]", "string", "{", "if", "s", ".", "f", ".", "BlockMode", "{", "s", ".", "f", ".", "lock", ".", "RLock", "(", ")", "\n", "defer", "s", ".", "f", ".", "lock", ...
// KeysHash returns keys hash consisting of names and values.
[ "KeysHash", "returns", "keys", "hash", "consisting", "of", "names", "and", "values", "." ]
3be5ad479f69d4e08d7fe25edf79bf3346bd658e
https://github.com/go-ini/ini/blob/3be5ad479f69d4e08d7fe25edf79bf3346bd658e/section.go#L214-L225
train
go-ini/ini
section.go
DeleteKey
func (s *Section) DeleteKey(name string) { if s.f.BlockMode { s.f.lock.Lock() defer s.f.lock.Unlock() } for i, k := range s.keyList { if k == name { s.keyList = append(s.keyList[:i], s.keyList[i+1:]...) delete(s.keys, name) delete(s.keysHash, name) return } } }
go
func (s *Section) DeleteKey(name string) { if s.f.BlockMode { s.f.lock.Lock() defer s.f.lock.Unlock() } for i, k := range s.keyList { if k == name { s.keyList = append(s.keyList[:i], s.keyList[i+1:]...) delete(s.keys, name) delete(s.keysHash, name) return } } }
[ "func", "(", "s", "*", "Section", ")", "DeleteKey", "(", "name", "string", ")", "{", "if", "s", ".", "f", ".", "BlockMode", "{", "s", ".", "f", ".", "lock", ".", "Lock", "(", ")", "\n", "defer", "s", ".", "f", ".", "lock", ".", "Unlock", "(",...
// DeleteKey deletes a key from section.
[ "DeleteKey", "deletes", "a", "key", "from", "section", "." ]
3be5ad479f69d4e08d7fe25edf79bf3346bd658e
https://github.com/go-ini/ini/blob/3be5ad479f69d4e08d7fe25edf79bf3346bd658e/section.go#L228-L242
train
emicklei/go-restful
curly.go
selectRoutes
func (c CurlyRouter) selectRoutes(ws *WebService, requestTokens []string) sortableCurlyRoutes { candidates := make(sortableCurlyRoutes, 0, 8) for _, each := range ws.routes { matches, paramCount, staticCount := c.matchesRouteByPathTokens(each.pathParts, requestTokens) if matches { candidates.add(curlyRoute{each, paramCount, staticCount}) // TODO make sure Routes() return pointers? } } sort.Sort(candidates) return candidates }
go
func (c CurlyRouter) selectRoutes(ws *WebService, requestTokens []string) sortableCurlyRoutes { candidates := make(sortableCurlyRoutes, 0, 8) for _, each := range ws.routes { matches, paramCount, staticCount := c.matchesRouteByPathTokens(each.pathParts, requestTokens) if matches { candidates.add(curlyRoute{each, paramCount, staticCount}) // TODO make sure Routes() return pointers? } } sort.Sort(candidates) return candidates }
[ "func", "(", "c", "CurlyRouter", ")", "selectRoutes", "(", "ws", "*", "WebService", ",", "requestTokens", "[", "]", "string", ")", "sortableCurlyRoutes", "{", "candidates", ":=", "make", "(", "sortableCurlyRoutes", ",", "0", ",", "8", ")", "\n", "for", "_"...
// selectRoutes return a collection of Route from a WebService that matches the path tokens from the request.
[ "selectRoutes", "return", "a", "collection", "of", "Route", "from", "a", "WebService", "that", "matches", "the", "path", "tokens", "from", "the", "request", "." ]
d2b8501d30f1b2c552dafdb21e3434bbafdaa124
https://github.com/emicklei/go-restful/blob/d2b8501d30f1b2c552dafdb21e3434bbafdaa124/curly.go#L47-L57
train
emicklei/go-restful
curly.go
matchesRouteByPathTokens
func (c CurlyRouter) matchesRouteByPathTokens(routeTokens, requestTokens []string) (matches bool, paramCount int, staticCount int) { if len(routeTokens) < len(requestTokens) { // proceed in matching only if last routeToken is wildcard count := len(routeTokens) if count == 0 || !strings.HasSuffix(routeTokens[count-1], "*}") { return false, 0, 0 } // proceed } for i, routeToken := range routeTokens { if i == len(requestTokens) { // reached end of request path return false, 0, 0 } requestToken := requestTokens[i] if strings.HasPrefix(routeToken, "{") { paramCount++ if colon := strings.Index(routeToken, ":"); colon != -1 { // match by regex matchesToken, matchesRemainder := c.regularMatchesPathToken(routeToken, colon, requestToken) if !matchesToken { return false, 0, 0 } if matchesRemainder { break } } } else { // no { prefix if requestToken != routeToken { return false, 0, 0 } staticCount++ } } return true, paramCount, staticCount }
go
func (c CurlyRouter) matchesRouteByPathTokens(routeTokens, requestTokens []string) (matches bool, paramCount int, staticCount int) { if len(routeTokens) < len(requestTokens) { // proceed in matching only if last routeToken is wildcard count := len(routeTokens) if count == 0 || !strings.HasSuffix(routeTokens[count-1], "*}") { return false, 0, 0 } // proceed } for i, routeToken := range routeTokens { if i == len(requestTokens) { // reached end of request path return false, 0, 0 } requestToken := requestTokens[i] if strings.HasPrefix(routeToken, "{") { paramCount++ if colon := strings.Index(routeToken, ":"); colon != -1 { // match by regex matchesToken, matchesRemainder := c.regularMatchesPathToken(routeToken, colon, requestToken) if !matchesToken { return false, 0, 0 } if matchesRemainder { break } } } else { // no { prefix if requestToken != routeToken { return false, 0, 0 } staticCount++ } } return true, paramCount, staticCount }
[ "func", "(", "c", "CurlyRouter", ")", "matchesRouteByPathTokens", "(", "routeTokens", ",", "requestTokens", "[", "]", "string", ")", "(", "matches", "bool", ",", "paramCount", "int", ",", "staticCount", "int", ")", "{", "if", "len", "(", "routeTokens", ")", ...
// matchesRouteByPathTokens computes whether it matches, howmany parameters do match and what the number of static path elements are.
[ "matchesRouteByPathTokens", "computes", "whether", "it", "matches", "howmany", "parameters", "do", "match", "and", "what", "the", "number", "of", "static", "path", "elements", "are", "." ]
d2b8501d30f1b2c552dafdb21e3434bbafdaa124
https://github.com/emicklei/go-restful/blob/d2b8501d30f1b2c552dafdb21e3434bbafdaa124/curly.go#L60-L95
train
emicklei/go-restful
curly.go
detectRoute
func (c CurlyRouter) detectRoute(candidateRoutes sortableCurlyRoutes, httpRequest *http.Request) (*Route, error) { // tracing is done inside detectRoute return jsr311Router.detectRoute(candidateRoutes.routes(), httpRequest) }
go
func (c CurlyRouter) detectRoute(candidateRoutes sortableCurlyRoutes, httpRequest *http.Request) (*Route, error) { // tracing is done inside detectRoute return jsr311Router.detectRoute(candidateRoutes.routes(), httpRequest) }
[ "func", "(", "c", "CurlyRouter", ")", "detectRoute", "(", "candidateRoutes", "sortableCurlyRoutes", ",", "httpRequest", "*", "http", ".", "Request", ")", "(", "*", "Route", ",", "error", ")", "{", "// tracing is done inside detectRoute", "return", "jsr311Router", ...
// detectRoute selectes from a list of Route the first match by inspecting both the Accept and Content-Type // headers of the Request. See also RouterJSR311 in jsr311.go
[ "detectRoute", "selectes", "from", "a", "list", "of", "Route", "the", "first", "match", "by", "inspecting", "both", "the", "Accept", "and", "Content", "-", "Type", "headers", "of", "the", "Request", ".", "See", "also", "RouterJSR311", "in", "jsr311", ".", ...
d2b8501d30f1b2c552dafdb21e3434bbafdaa124
https://github.com/emicklei/go-restful/blob/d2b8501d30f1b2c552dafdb21e3434bbafdaa124/curly.go#L115-L118
train
emicklei/go-restful
curly.go
detectWebService
func (c CurlyRouter) detectWebService(requestTokens []string, webServices []*WebService) *WebService { var best *WebService score := -1 for _, each := range webServices { matches, eachScore := c.computeWebserviceScore(requestTokens, each.pathExpr.tokens) if matches && (eachScore > score) { best = each score = eachScore } } return best }
go
func (c CurlyRouter) detectWebService(requestTokens []string, webServices []*WebService) *WebService { var best *WebService score := -1 for _, each := range webServices { matches, eachScore := c.computeWebserviceScore(requestTokens, each.pathExpr.tokens) if matches && (eachScore > score) { best = each score = eachScore } } return best }
[ "func", "(", "c", "CurlyRouter", ")", "detectWebService", "(", "requestTokens", "[", "]", "string", ",", "webServices", "[", "]", "*", "WebService", ")", "*", "WebService", "{", "var", "best", "*", "WebService", "\n", "score", ":=", "-", "1", "\n", "for"...
// detectWebService returns the best matching webService given the list of path tokens. // see also computeWebserviceScore
[ "detectWebService", "returns", "the", "best", "matching", "webService", "given", "the", "list", "of", "path", "tokens", ".", "see", "also", "computeWebserviceScore" ]
d2b8501d30f1b2c552dafdb21e3434bbafdaa124
https://github.com/emicklei/go-restful/blob/d2b8501d30f1b2c552dafdb21e3434bbafdaa124/curly.go#L122-L133
train
emicklei/go-restful
curly.go
computeWebserviceScore
func (c CurlyRouter) computeWebserviceScore(requestTokens []string, tokens []string) (bool, int) { if len(tokens) > len(requestTokens) { return false, 0 } score := 0 for i := 0; i < len(tokens); i++ { each := requestTokens[i] other := tokens[i] if len(each) == 0 && len(other) == 0 { score++ continue } if len(other) > 0 && strings.HasPrefix(other, "{") { // no empty match if len(each) == 0 { return false, score } score += 1 } else { // not a parameter if each != other { return false, score } score += (len(tokens) - i) * 10 //fuzzy } } return true, score }
go
func (c CurlyRouter) computeWebserviceScore(requestTokens []string, tokens []string) (bool, int) { if len(tokens) > len(requestTokens) { return false, 0 } score := 0 for i := 0; i < len(tokens); i++ { each := requestTokens[i] other := tokens[i] if len(each) == 0 && len(other) == 0 { score++ continue } if len(other) > 0 && strings.HasPrefix(other, "{") { // no empty match if len(each) == 0 { return false, score } score += 1 } else { // not a parameter if each != other { return false, score } score += (len(tokens) - i) * 10 //fuzzy } } return true, score }
[ "func", "(", "c", "CurlyRouter", ")", "computeWebserviceScore", "(", "requestTokens", "[", "]", "string", ",", "tokens", "[", "]", "string", ")", "(", "bool", ",", "int", ")", "{", "if", "len", "(", "tokens", ")", ">", "len", "(", "requestTokens", ")",...
// computeWebserviceScore returns whether tokens match and // the weighted score of the longest matching consecutive tokens from the beginning.
[ "computeWebserviceScore", "returns", "whether", "tokens", "match", "and", "the", "weighted", "score", "of", "the", "longest", "matching", "consecutive", "tokens", "from", "the", "beginning", "." ]
d2b8501d30f1b2c552dafdb21e3434bbafdaa124
https://github.com/emicklei/go-restful/blob/d2b8501d30f1b2c552dafdb21e3434bbafdaa124/curly.go#L137-L164
train
emicklei/go-restful
examples/restful-full-logging-filter.go
main
func main() { restful.Add(newUserService()) log.Print("start listening on localhost:8080") log.Fatal(http.ListenAndServe(":8080", nil)) }
go
func main() { restful.Add(newUserService()) log.Print("start listening on localhost:8080") log.Fatal(http.ListenAndServe(":8080", nil)) }
[ "func", "main", "(", ")", "{", "restful", ".", "Add", "(", "newUserService", "(", ")", ")", "\n", "log", ".", "Print", "(", "\"", "\"", ")", "\n", "log", ".", "Fatal", "(", "http", ".", "ListenAndServe", "(", "\"", "\"", ",", "nil", ")", ")", "...
// // This example shows how to log both the request body and response body
[ "This", "example", "shows", "how", "to", "log", "both", "the", "request", "body", "and", "response", "body" ]
d2b8501d30f1b2c552dafdb21e3434bbafdaa124
https://github.com/emicklei/go-restful/blob/d2b8501d30f1b2c552dafdb21e3434bbafdaa124/examples/restful-full-logging-filter.go#L20-L24
train
emicklei/go-restful
route_builder.go
Method
func (b *RouteBuilder) Method(method string) *RouteBuilder { b.httpMethod = method return b }
go
func (b *RouteBuilder) Method(method string) *RouteBuilder { b.httpMethod = method return b }
[ "func", "(", "b", "*", "RouteBuilder", ")", "Method", "(", "method", "string", ")", "*", "RouteBuilder", "{", "b", ".", "httpMethod", "=", "method", "\n", "return", "b", "\n", "}" ]
// Method specifies what HTTP method to match. Required.
[ "Method", "specifies", "what", "HTTP", "method", "to", "match", ".", "Required", "." ]
d2b8501d30f1b2c552dafdb21e3434bbafdaa124
https://github.com/emicklei/go-restful/blob/d2b8501d30f1b2c552dafdb21e3434bbafdaa124/route_builder.go#L67-L70
train
emicklei/go-restful
route_builder.go
Produces
func (b *RouteBuilder) Produces(mimeTypes ...string) *RouteBuilder { b.produces = mimeTypes return b }
go
func (b *RouteBuilder) Produces(mimeTypes ...string) *RouteBuilder { b.produces = mimeTypes return b }
[ "func", "(", "b", "*", "RouteBuilder", ")", "Produces", "(", "mimeTypes", "...", "string", ")", "*", "RouteBuilder", "{", "b", ".", "produces", "=", "mimeTypes", "\n", "return", "b", "\n", "}" ]
// Produces specifies what MIME types can be produced ; the matched one will appear in the Content-Type Http header.
[ "Produces", "specifies", "what", "MIME", "types", "can", "be", "produced", ";", "the", "matched", "one", "will", "appear", "in", "the", "Content", "-", "Type", "Http", "header", "." ]
d2b8501d30f1b2c552dafdb21e3434bbafdaa124
https://github.com/emicklei/go-restful/blob/d2b8501d30f1b2c552dafdb21e3434bbafdaa124/route_builder.go#L73-L76
train
emicklei/go-restful
route_builder.go
Consumes
func (b *RouteBuilder) Consumes(mimeTypes ...string) *RouteBuilder { b.consumes = mimeTypes return b }
go
func (b *RouteBuilder) Consumes(mimeTypes ...string) *RouteBuilder { b.consumes = mimeTypes return b }
[ "func", "(", "b", "*", "RouteBuilder", ")", "Consumes", "(", "mimeTypes", "...", "string", ")", "*", "RouteBuilder", "{", "b", ".", "consumes", "=", "mimeTypes", "\n", "return", "b", "\n", "}" ]
// Consumes specifies what MIME types can be consumes ; the Accept Http header must matched any of these
[ "Consumes", "specifies", "what", "MIME", "types", "can", "be", "consumes", ";", "the", "Accept", "Http", "header", "must", "matched", "any", "of", "these" ]
d2b8501d30f1b2c552dafdb21e3434bbafdaa124
https://github.com/emicklei/go-restful/blob/d2b8501d30f1b2c552dafdb21e3434bbafdaa124/route_builder.go#L79-L82
train
emicklei/go-restful
route_builder.go
Doc
func (b *RouteBuilder) Doc(documentation string) *RouteBuilder { b.doc = documentation return b }
go
func (b *RouteBuilder) Doc(documentation string) *RouteBuilder { b.doc = documentation return b }
[ "func", "(", "b", "*", "RouteBuilder", ")", "Doc", "(", "documentation", "string", ")", "*", "RouteBuilder", "{", "b", ".", "doc", "=", "documentation", "\n", "return", "b", "\n", "}" ]
// Doc tells what this route is all about. Optional.
[ "Doc", "tells", "what", "this", "route", "is", "all", "about", ".", "Optional", "." ]
d2b8501d30f1b2c552dafdb21e3434bbafdaa124
https://github.com/emicklei/go-restful/blob/d2b8501d30f1b2c552dafdb21e3434bbafdaa124/route_builder.go#L91-L94
train
emicklei/go-restful
route_builder.go
Notes
func (b *RouteBuilder) Notes(notes string) *RouteBuilder { b.notes = notes return b }
go
func (b *RouteBuilder) Notes(notes string) *RouteBuilder { b.notes = notes return b }
[ "func", "(", "b", "*", "RouteBuilder", ")", "Notes", "(", "notes", "string", ")", "*", "RouteBuilder", "{", "b", ".", "notes", "=", "notes", "\n", "return", "b", "\n", "}" ]
// Notes is a verbose explanation of the operation behavior. Optional.
[ "Notes", "is", "a", "verbose", "explanation", "of", "the", "operation", "behavior", ".", "Optional", "." ]
d2b8501d30f1b2c552dafdb21e3434bbafdaa124
https://github.com/emicklei/go-restful/blob/d2b8501d30f1b2c552dafdb21e3434bbafdaa124/route_builder.go#L97-L100
train
emicklei/go-restful
route_builder.go
Reads
func (b *RouteBuilder) Reads(sample interface{}, optionalDescription ...string) *RouteBuilder { fn := b.typeNameHandleFunc if fn == nil { fn = reflectTypeName } typeAsName := fn(sample) description := "" if len(optionalDescription) > 0 { description = optionalDescription[0] } b.readSample = sample bodyParameter := &Parameter{&ParameterData{Name: "body", Description: description}} bodyParameter.beBody() bodyParameter.Required(true) bodyParameter.DataType(typeAsName) b.Param(bodyParameter) return b }
go
func (b *RouteBuilder) Reads(sample interface{}, optionalDescription ...string) *RouteBuilder { fn := b.typeNameHandleFunc if fn == nil { fn = reflectTypeName } typeAsName := fn(sample) description := "" if len(optionalDescription) > 0 { description = optionalDescription[0] } b.readSample = sample bodyParameter := &Parameter{&ParameterData{Name: "body", Description: description}} bodyParameter.beBody() bodyParameter.Required(true) bodyParameter.DataType(typeAsName) b.Param(bodyParameter) return b }
[ "func", "(", "b", "*", "RouteBuilder", ")", "Reads", "(", "sample", "interface", "{", "}", ",", "optionalDescription", "...", "string", ")", "*", "RouteBuilder", "{", "fn", ":=", "b", ".", "typeNameHandleFunc", "\n", "if", "fn", "==", "nil", "{", "fn", ...
// Reads tells what resource type will be read from the request payload. Optional. // A parameter of type "body" is added ,required is set to true and the dataType is set to the qualified name of the sample's type.
[ "Reads", "tells", "what", "resource", "type", "will", "be", "read", "from", "the", "request", "payload", ".", "Optional", ".", "A", "parameter", "of", "type", "body", "is", "added", "required", "is", "set", "to", "true", "and", "the", "dataType", "is", "...
d2b8501d30f1b2c552dafdb21e3434bbafdaa124
https://github.com/emicklei/go-restful/blob/d2b8501d30f1b2c552dafdb21e3434bbafdaa124/route_builder.go#L104-L121
train
emicklei/go-restful
route_builder.go
ReturnsError
func (b *RouteBuilder) ReturnsError(code int, message string, model interface{}) *RouteBuilder { log.Print("ReturnsError is deprecated, use Returns instead.") return b.Returns(code, message, model) }
go
func (b *RouteBuilder) ReturnsError(code int, message string, model interface{}) *RouteBuilder { log.Print("ReturnsError is deprecated, use Returns instead.") return b.Returns(code, message, model) }
[ "func", "(", "b", "*", "RouteBuilder", ")", "ReturnsError", "(", "code", "int", ",", "message", "string", ",", "model", "interface", "{", "}", ")", "*", "RouteBuilder", "{", "log", ".", "Print", "(", "\"", "\"", ")", "\n", "return", "b", ".", "Return...
// ReturnsError is deprecated, use Returns instead.
[ "ReturnsError", "is", "deprecated", "use", "Returns", "instead", "." ]
d2b8501d30f1b2c552dafdb21e3434bbafdaa124
https://github.com/emicklei/go-restful/blob/d2b8501d30f1b2c552dafdb21e3434bbafdaa124/route_builder.go#L157-L160
train
emicklei/go-restful
route_builder.go
DefaultReturns
func (b *RouteBuilder) DefaultReturns(message string, model interface{}) *RouteBuilder { b.defaultResponse = &ResponseError{ Message: message, Model: model, } return b }
go
func (b *RouteBuilder) DefaultReturns(message string, model interface{}) *RouteBuilder { b.defaultResponse = &ResponseError{ Message: message, Model: model, } return b }
[ "func", "(", "b", "*", "RouteBuilder", ")", "DefaultReturns", "(", "message", "string", ",", "model", "interface", "{", "}", ")", "*", "RouteBuilder", "{", "b", ".", "defaultResponse", "=", "&", "ResponseError", "{", "Message", ":", "message", ",", "Model"...
// DefaultReturns is a special Returns call that sets the default of the response.
[ "DefaultReturns", "is", "a", "special", "Returns", "call", "that", "sets", "the", "default", "of", "the", "response", "." ]
d2b8501d30f1b2c552dafdb21e3434bbafdaa124
https://github.com/emicklei/go-restful/blob/d2b8501d30f1b2c552dafdb21e3434bbafdaa124/route_builder.go#L180-L186
train
emicklei/go-restful
route_builder.go
Metadata
func (b *RouteBuilder) Metadata(key string, value interface{}) *RouteBuilder { if b.metadata == nil { b.metadata = map[string]interface{}{} } b.metadata[key] = value return b }
go
func (b *RouteBuilder) Metadata(key string, value interface{}) *RouteBuilder { if b.metadata == nil { b.metadata = map[string]interface{}{} } b.metadata[key] = value return b }
[ "func", "(", "b", "*", "RouteBuilder", ")", "Metadata", "(", "key", "string", ",", "value", "interface", "{", "}", ")", "*", "RouteBuilder", "{", "if", "b", ".", "metadata", "==", "nil", "{", "b", ".", "metadata", "=", "map", "[", "string", "]", "i...
// Metadata adds or updates a key=value pair to the metadata map.
[ "Metadata", "adds", "or", "updates", "a", "key", "=", "value", "pair", "to", "the", "metadata", "map", "." ]
d2b8501d30f1b2c552dafdb21e3434bbafdaa124
https://github.com/emicklei/go-restful/blob/d2b8501d30f1b2c552dafdb21e3434bbafdaa124/route_builder.go#L189-L195
train
emicklei/go-restful
route_builder.go
Filter
func (b *RouteBuilder) Filter(filter FilterFunction) *RouteBuilder { b.filters = append(b.filters, filter) return b }
go
func (b *RouteBuilder) Filter(filter FilterFunction) *RouteBuilder { b.filters = append(b.filters, filter) return b }
[ "func", "(", "b", "*", "RouteBuilder", ")", "Filter", "(", "filter", "FilterFunction", ")", "*", "RouteBuilder", "{", "b", ".", "filters", "=", "append", "(", "b", ".", "filters", ",", "filter", ")", "\n", "return", "b", "\n", "}" ]
// Filter appends a FilterFunction to the end of filters for this Route to build.
[ "Filter", "appends", "a", "FilterFunction", "to", "the", "end", "of", "filters", "for", "this", "Route", "to", "build", "." ]
d2b8501d30f1b2c552dafdb21e3434bbafdaa124
https://github.com/emicklei/go-restful/blob/d2b8501d30f1b2c552dafdb21e3434bbafdaa124/route_builder.go#L217-L220
train
emicklei/go-restful
route_builder.go
ContentEncodingEnabled
func (b *RouteBuilder) ContentEncodingEnabled(enabled bool) *RouteBuilder { b.contentEncodingEnabled = &enabled return b }
go
func (b *RouteBuilder) ContentEncodingEnabled(enabled bool) *RouteBuilder { b.contentEncodingEnabled = &enabled return b }
[ "func", "(", "b", "*", "RouteBuilder", ")", "ContentEncodingEnabled", "(", "enabled", "bool", ")", "*", "RouteBuilder", "{", "b", ".", "contentEncodingEnabled", "=", "&", "enabled", "\n", "return", "b", "\n", "}" ]
// ContentEncodingEnabled allows you to override the Containers value for auto-compressing this route response.
[ "ContentEncodingEnabled", "allows", "you", "to", "override", "the", "Containers", "value", "for", "auto", "-", "compressing", "this", "route", "response", "." ]
d2b8501d30f1b2c552dafdb21e3434bbafdaa124
https://github.com/emicklei/go-restful/blob/d2b8501d30f1b2c552dafdb21e3434bbafdaa124/route_builder.go#L238-L241
train
emicklei/go-restful
route_builder.go
copyDefaults
func (b *RouteBuilder) copyDefaults(rootProduces, rootConsumes []string) { if len(b.produces) == 0 { b.produces = rootProduces } if len(b.consumes) == 0 { b.consumes = rootConsumes } }
go
func (b *RouteBuilder) copyDefaults(rootProduces, rootConsumes []string) { if len(b.produces) == 0 { b.produces = rootProduces } if len(b.consumes) == 0 { b.consumes = rootConsumes } }
[ "func", "(", "b", "*", "RouteBuilder", ")", "copyDefaults", "(", "rootProduces", ",", "rootConsumes", "[", "]", "string", ")", "{", "if", "len", "(", "b", ".", "produces", ")", "==", "0", "{", "b", ".", "produces", "=", "rootProduces", "\n", "}", "\n...
// If no specific Route path then set to rootPath // If no specific Produces then set to rootProduces // If no specific Consumes then set to rootConsumes
[ "If", "no", "specific", "Route", "path", "then", "set", "to", "rootPath", "If", "no", "specific", "Produces", "then", "set", "to", "rootProduces", "If", "no", "specific", "Consumes", "then", "set", "to", "rootConsumes" ]
d2b8501d30f1b2c552dafdb21e3434bbafdaa124
https://github.com/emicklei/go-restful/blob/d2b8501d30f1b2c552dafdb21e3434bbafdaa124/route_builder.go#L246-L253
train
emicklei/go-restful
route_builder.go
typeNameHandler
func (b *RouteBuilder) typeNameHandler(handler TypeNameHandleFunction) *RouteBuilder { b.typeNameHandleFunc = handler return b }
go
func (b *RouteBuilder) typeNameHandler(handler TypeNameHandleFunction) *RouteBuilder { b.typeNameHandleFunc = handler return b }
[ "func", "(", "b", "*", "RouteBuilder", ")", "typeNameHandler", "(", "handler", "TypeNameHandleFunction", ")", "*", "RouteBuilder", "{", "b", ".", "typeNameHandleFunc", "=", "handler", "\n", "return", "b", "\n", "}" ]
// typeNameHandler sets the function that will convert types to strings in the parameter // and model definitions.
[ "typeNameHandler", "sets", "the", "function", "that", "will", "convert", "types", "to", "strings", "in", "the", "parameter", "and", "model", "definitions", "." ]
d2b8501d30f1b2c552dafdb21e3434bbafdaa124
https://github.com/emicklei/go-restful/blob/d2b8501d30f1b2c552dafdb21e3434bbafdaa124/route_builder.go#L257-L260
train
emicklei/go-restful
route_builder.go
Build
func (b *RouteBuilder) Build() Route { pathExpr, err := newPathExpression(b.currentPath) if err != nil { log.Printf("Invalid path:%s because:%v", b.currentPath, err) os.Exit(1) } if b.function == nil { log.Printf("No function specified for route:" + b.currentPath) os.Exit(1) } operationName := b.operation if len(operationName) == 0 && b.function != nil { // extract from definition operationName = nameOfFunction(b.function) } route := Route{ Method: b.httpMethod, Path: concatPath(b.rootPath, b.currentPath), Produces: b.produces, Consumes: b.consumes, Function: b.function, Filters: b.filters, If: b.conditions, relativePath: b.currentPath, pathExpr: pathExpr, Doc: b.doc, Notes: b.notes, Operation: operationName, ParameterDocs: b.parameters, ResponseErrors: b.errorMap, DefaultResponse: b.defaultResponse, ReadSample: b.readSample, WriteSample: b.writeSample, Metadata: b.metadata, Deprecated: b.deprecated, contentEncodingEnabled: b.contentEncodingEnabled, } route.postBuild() return route }
go
func (b *RouteBuilder) Build() Route { pathExpr, err := newPathExpression(b.currentPath) if err != nil { log.Printf("Invalid path:%s because:%v", b.currentPath, err) os.Exit(1) } if b.function == nil { log.Printf("No function specified for route:" + b.currentPath) os.Exit(1) } operationName := b.operation if len(operationName) == 0 && b.function != nil { // extract from definition operationName = nameOfFunction(b.function) } route := Route{ Method: b.httpMethod, Path: concatPath(b.rootPath, b.currentPath), Produces: b.produces, Consumes: b.consumes, Function: b.function, Filters: b.filters, If: b.conditions, relativePath: b.currentPath, pathExpr: pathExpr, Doc: b.doc, Notes: b.notes, Operation: operationName, ParameterDocs: b.parameters, ResponseErrors: b.errorMap, DefaultResponse: b.defaultResponse, ReadSample: b.readSample, WriteSample: b.writeSample, Metadata: b.metadata, Deprecated: b.deprecated, contentEncodingEnabled: b.contentEncodingEnabled, } route.postBuild() return route }
[ "func", "(", "b", "*", "RouteBuilder", ")", "Build", "(", ")", "Route", "{", "pathExpr", ",", "err", ":=", "newPathExpression", "(", "b", ".", "currentPath", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Printf", "(", "\"", "\"", ",", "b",...
// Build creates a new Route using the specification details collected by the RouteBuilder
[ "Build", "creates", "a", "new", "Route", "using", "the", "specification", "details", "collected", "by", "the", "RouteBuilder" ]
d2b8501d30f1b2c552dafdb21e3434bbafdaa124
https://github.com/emicklei/go-restful/blob/d2b8501d30f1b2c552dafdb21e3434bbafdaa124/route_builder.go#L263-L302
train
emicklei/go-restful
route_builder.go
nameOfFunction
func nameOfFunction(f interface{}) string { fun := runtime.FuncForPC(reflect.ValueOf(f).Pointer()) tokenized := strings.Split(fun.Name(), ".") last := tokenized[len(tokenized)-1] last = strings.TrimSuffix(last, ")·fm") // < Go 1.5 last = strings.TrimSuffix(last, ")-fm") // Go 1.5 last = strings.TrimSuffix(last, "·fm") // < Go 1.5 last = strings.TrimSuffix(last, "-fm") // Go 1.5 if last == "func1" { // this could mean conflicts in API docs val := atomic.AddInt32(&anonymousFuncCount, 1) last = "func" + fmt.Sprintf("%d", val) atomic.StoreInt32(&anonymousFuncCount, val) } return last }
go
func nameOfFunction(f interface{}) string { fun := runtime.FuncForPC(reflect.ValueOf(f).Pointer()) tokenized := strings.Split(fun.Name(), ".") last := tokenized[len(tokenized)-1] last = strings.TrimSuffix(last, ")·fm") // < Go 1.5 last = strings.TrimSuffix(last, ")-fm") // Go 1.5 last = strings.TrimSuffix(last, "·fm") // < Go 1.5 last = strings.TrimSuffix(last, "-fm") // Go 1.5 if last == "func1" { // this could mean conflicts in API docs val := atomic.AddInt32(&anonymousFuncCount, 1) last = "func" + fmt.Sprintf("%d", val) atomic.StoreInt32(&anonymousFuncCount, val) } return last }
[ "func", "nameOfFunction", "(", "f", "interface", "{", "}", ")", "string", "{", "fun", ":=", "runtime", ".", "FuncForPC", "(", "reflect", ".", "ValueOf", "(", "f", ")", ".", "Pointer", "(", ")", ")", "\n", "tokenized", ":=", "strings", ".", "Split", "...
// nameOfFunction returns the short name of the function f for documentation. // It uses a runtime feature for debugging ; its value may change for later Go versions.
[ "nameOfFunction", "returns", "the", "short", "name", "of", "the", "function", "f", "for", "documentation", ".", "It", "uses", "a", "runtime", "feature", "for", "debugging", ";", "its", "value", "may", "change", "for", "later", "Go", "versions", "." ]
d2b8501d30f1b2c552dafdb21e3434bbafdaa124
https://github.com/emicklei/go-restful/blob/d2b8501d30f1b2c552dafdb21e3434bbafdaa124/route_builder.go#L312-L326
train
emicklei/go-restful
path_expression.go
newPathExpression
func newPathExpression(path string) (*pathExpression, error) { expression, literalCount, varNames, varCount, tokens := templateToRegularExpression(path) compiled, err := regexp.Compile(expression) if err != nil { return nil, err } return &pathExpression{literalCount, varNames, varCount, compiled, expression, tokens}, nil }
go
func newPathExpression(path string) (*pathExpression, error) { expression, literalCount, varNames, varCount, tokens := templateToRegularExpression(path) compiled, err := regexp.Compile(expression) if err != nil { return nil, err } return &pathExpression{literalCount, varNames, varCount, compiled, expression, tokens}, nil }
[ "func", "newPathExpression", "(", "path", "string", ")", "(", "*", "pathExpression", ",", "error", ")", "{", "expression", ",", "literalCount", ",", "varNames", ",", "varCount", ",", "tokens", ":=", "templateToRegularExpression", "(", "path", ")", "\n", "compi...
// NewPathExpression creates a PathExpression from the input URL path. // Returns an error if the path is invalid.
[ "NewPathExpression", "creates", "a", "PathExpression", "from", "the", "input", "URL", "path", ".", "Returns", "an", "error", "if", "the", "path", "is", "invalid", "." ]
d2b8501d30f1b2c552dafdb21e3434bbafdaa124
https://github.com/emicklei/go-restful/blob/d2b8501d30f1b2c552dafdb21e3434bbafdaa124/path_expression.go#L27-L34
train
emicklei/go-restful
request.go
QueryParameters
func (r *Request) QueryParameters(name string) []string { return r.Request.URL.Query()[name] }
go
func (r *Request) QueryParameters(name string) []string { return r.Request.URL.Query()[name] }
[ "func", "(", "r", "*", "Request", ")", "QueryParameters", "(", "name", "string", ")", "[", "]", "string", "{", "return", "r", ".", "Request", ".", "URL", ".", "Query", "(", ")", "[", "name", "]", "\n", "}" ]
// QueryParameters returns the all the query parameters values by name
[ "QueryParameters", "returns", "the", "all", "the", "query", "parameters", "values", "by", "name" ]
d2b8501d30f1b2c552dafdb21e3434bbafdaa124
https://github.com/emicklei/go-restful/blob/d2b8501d30f1b2c552dafdb21e3434bbafdaa124/request.go#L55-L57
train
emicklei/go-restful
request.go
HeaderParameter
func (r *Request) HeaderParameter(name string) string { return r.Request.Header.Get(name) }
go
func (r *Request) HeaderParameter(name string) string { return r.Request.Header.Get(name) }
[ "func", "(", "r", "*", "Request", ")", "HeaderParameter", "(", "name", "string", ")", "string", "{", "return", "r", ".", "Request", ".", "Header", ".", "Get", "(", "name", ")", "\n", "}" ]
// HeaderParameter returns the HTTP Header value of a Header name or empty if missing
[ "HeaderParameter", "returns", "the", "HTTP", "Header", "value", "of", "a", "Header", "name", "or", "empty", "if", "missing" ]
d2b8501d30f1b2c552dafdb21e3434bbafdaa124
https://github.com/emicklei/go-restful/blob/d2b8501d30f1b2c552dafdb21e3434bbafdaa124/request.go#L69-L71
train
emicklei/go-restful
request.go
ReadEntity
func (r *Request) ReadEntity(entityPointer interface{}) (err error) { contentType := r.Request.Header.Get(HEADER_ContentType) contentEncoding := r.Request.Header.Get(HEADER_ContentEncoding) // check if the request body needs decompression if ENCODING_GZIP == contentEncoding { gzipReader := currentCompressorProvider.AcquireGzipReader() defer currentCompressorProvider.ReleaseGzipReader(gzipReader) gzipReader.Reset(r.Request.Body) r.Request.Body = gzipReader } else if ENCODING_DEFLATE == contentEncoding { zlibReader, err := zlib.NewReader(r.Request.Body) if err != nil { return err } r.Request.Body = zlibReader } // lookup the EntityReader, use defaultRequestContentType if needed and provided entityReader, ok := entityAccessRegistry.accessorAt(contentType) if !ok { if len(defaultRequestContentType) != 0 { entityReader, ok = entityAccessRegistry.accessorAt(defaultRequestContentType) } if !ok { return NewError(http.StatusBadRequest, "Unable to unmarshal content of type:"+contentType) } } return entityReader.Read(r, entityPointer) }
go
func (r *Request) ReadEntity(entityPointer interface{}) (err error) { contentType := r.Request.Header.Get(HEADER_ContentType) contentEncoding := r.Request.Header.Get(HEADER_ContentEncoding) // check if the request body needs decompression if ENCODING_GZIP == contentEncoding { gzipReader := currentCompressorProvider.AcquireGzipReader() defer currentCompressorProvider.ReleaseGzipReader(gzipReader) gzipReader.Reset(r.Request.Body) r.Request.Body = gzipReader } else if ENCODING_DEFLATE == contentEncoding { zlibReader, err := zlib.NewReader(r.Request.Body) if err != nil { return err } r.Request.Body = zlibReader } // lookup the EntityReader, use defaultRequestContentType if needed and provided entityReader, ok := entityAccessRegistry.accessorAt(contentType) if !ok { if len(defaultRequestContentType) != 0 { entityReader, ok = entityAccessRegistry.accessorAt(defaultRequestContentType) } if !ok { return NewError(http.StatusBadRequest, "Unable to unmarshal content of type:"+contentType) } } return entityReader.Read(r, entityPointer) }
[ "func", "(", "r", "*", "Request", ")", "ReadEntity", "(", "entityPointer", "interface", "{", "}", ")", "(", "err", "error", ")", "{", "contentType", ":=", "r", ".", "Request", ".", "Header", ".", "Get", "(", "HEADER_ContentType", ")", "\n", "contentEncod...
// ReadEntity checks the Accept header and reads the content into the entityPointer.
[ "ReadEntity", "checks", "the", "Accept", "header", "and", "reads", "the", "content", "into", "the", "entityPointer", "." ]
d2b8501d30f1b2c552dafdb21e3434bbafdaa124
https://github.com/emicklei/go-restful/blob/d2b8501d30f1b2c552dafdb21e3434bbafdaa124/request.go#L74-L103
train
emicklei/go-restful
request.go
SetAttribute
func (r *Request) SetAttribute(name string, value interface{}) { r.attributes[name] = value }
go
func (r *Request) SetAttribute(name string, value interface{}) { r.attributes[name] = value }
[ "func", "(", "r", "*", "Request", ")", "SetAttribute", "(", "name", "string", ",", "value", "interface", "{", "}", ")", "{", "r", ".", "attributes", "[", "name", "]", "=", "value", "\n", "}" ]
// SetAttribute adds or replaces the attribute with the given value.
[ "SetAttribute", "adds", "or", "replaces", "the", "attribute", "with", "the", "given", "value", "." ]
d2b8501d30f1b2c552dafdb21e3434bbafdaa124
https://github.com/emicklei/go-restful/blob/d2b8501d30f1b2c552dafdb21e3434bbafdaa124/request.go#L106-L108
train
emicklei/go-restful
filter.go
ProcessFilter
func (f *FilterChain) ProcessFilter(request *Request, response *Response) { if f.Index < len(f.Filters) { f.Index++ f.Filters[f.Index-1](request, response, f) } else { f.Target(request, response) } }
go
func (f *FilterChain) ProcessFilter(request *Request, response *Response) { if f.Index < len(f.Filters) { f.Index++ f.Filters[f.Index-1](request, response, f) } else { f.Target(request, response) } }
[ "func", "(", "f", "*", "FilterChain", ")", "ProcessFilter", "(", "request", "*", "Request", ",", "response", "*", "Response", ")", "{", "if", "f", ".", "Index", "<", "len", "(", "f", ".", "Filters", ")", "{", "f", ".", "Index", "++", "\n", "f", "...
// ProcessFilter passes the request,response pair through the next of Filters. // Each filter can decide to proceed to the next Filter or handle the Response itself.
[ "ProcessFilter", "passes", "the", "request", "response", "pair", "through", "the", "next", "of", "Filters", ".", "Each", "filter", "can", "decide", "to", "proceed", "to", "the", "next", "Filter", "or", "handle", "the", "Response", "itself", "." ]
d2b8501d30f1b2c552dafdb21e3434bbafdaa124
https://github.com/emicklei/go-restful/blob/d2b8501d30f1b2c552dafdb21e3434bbafdaa124/filter.go#L16-L23
train
emicklei/go-restful
route.go
wrapRequestResponse
func (r *Route) wrapRequestResponse(httpWriter http.ResponseWriter, httpRequest *http.Request, pathParams map[string]string) (*Request, *Response) { wrappedRequest := NewRequest(httpRequest) wrappedRequest.pathParameters = pathParams wrappedRequest.selectedRoutePath = r.Path wrappedResponse := NewResponse(httpWriter) wrappedResponse.requestAccept = httpRequest.Header.Get(HEADER_Accept) wrappedResponse.routeProduces = r.Produces return wrappedRequest, wrappedResponse }
go
func (r *Route) wrapRequestResponse(httpWriter http.ResponseWriter, httpRequest *http.Request, pathParams map[string]string) (*Request, *Response) { wrappedRequest := NewRequest(httpRequest) wrappedRequest.pathParameters = pathParams wrappedRequest.selectedRoutePath = r.Path wrappedResponse := NewResponse(httpWriter) wrappedResponse.requestAccept = httpRequest.Header.Get(HEADER_Accept) wrappedResponse.routeProduces = r.Produces return wrappedRequest, wrappedResponse }
[ "func", "(", "r", "*", "Route", ")", "wrapRequestResponse", "(", "httpWriter", "http", ".", "ResponseWriter", ",", "httpRequest", "*", "http", ".", "Request", ",", "pathParams", "map", "[", "string", "]", "string", ")", "(", "*", "Request", ",", "*", "Re...
// Create Request and Response from their http versions
[ "Create", "Request", "and", "Response", "from", "their", "http", "versions" ]
d2b8501d30f1b2c552dafdb21e3434bbafdaa124
https://github.com/emicklei/go-restful/blob/d2b8501d30f1b2c552dafdb21e3434bbafdaa124/route.go#L60-L68
train
emicklei/go-restful
route.go
dispatchWithFilters
func (r *Route) dispatchWithFilters(wrappedRequest *Request, wrappedResponse *Response) { if len(r.Filters) > 0 { chain := FilterChain{Filters: r.Filters, Target: r.Function} chain.ProcessFilter(wrappedRequest, wrappedResponse) } else { // unfiltered r.Function(wrappedRequest, wrappedResponse) } }
go
func (r *Route) dispatchWithFilters(wrappedRequest *Request, wrappedResponse *Response) { if len(r.Filters) > 0 { chain := FilterChain{Filters: r.Filters, Target: r.Function} chain.ProcessFilter(wrappedRequest, wrappedResponse) } else { // unfiltered r.Function(wrappedRequest, wrappedResponse) } }
[ "func", "(", "r", "*", "Route", ")", "dispatchWithFilters", "(", "wrappedRequest", "*", "Request", ",", "wrappedResponse", "*", "Response", ")", "{", "if", "len", "(", "r", ".", "Filters", ")", ">", "0", "{", "chain", ":=", "FilterChain", "{", "Filters",...
// dispatchWithFilters call the function after passing through its own filters
[ "dispatchWithFilters", "call", "the", "function", "after", "passing", "through", "its", "own", "filters" ]
d2b8501d30f1b2c552dafdb21e3434bbafdaa124
https://github.com/emicklei/go-restful/blob/d2b8501d30f1b2c552dafdb21e3434bbafdaa124/route.go#L71-L79
train
emicklei/go-restful
route.go
matchesAccept
func (r Route) matchesAccept(mimeTypesWithQuality string) bool { remaining := mimeTypesWithQuality for { var mimeType string if end := strings.Index(remaining, ","); end == -1 { mimeType, remaining = remaining, "" } else { mimeType, remaining = remaining[:end], remaining[end+1:] } if quality := strings.Index(mimeType, ";"); quality != -1 { mimeType = mimeType[:quality] } mimeType = strings.TrimFunc(mimeType, stringTrimSpaceCutset) if mimeType == "*/*" { return true } for _, producibleType := range r.Produces { if producibleType == "*/*" || producibleType == mimeType { return true } } if len(remaining) == 0 { return false } } }
go
func (r Route) matchesAccept(mimeTypesWithQuality string) bool { remaining := mimeTypesWithQuality for { var mimeType string if end := strings.Index(remaining, ","); end == -1 { mimeType, remaining = remaining, "" } else { mimeType, remaining = remaining[:end], remaining[end+1:] } if quality := strings.Index(mimeType, ";"); quality != -1 { mimeType = mimeType[:quality] } mimeType = strings.TrimFunc(mimeType, stringTrimSpaceCutset) if mimeType == "*/*" { return true } for _, producibleType := range r.Produces { if producibleType == "*/*" || producibleType == mimeType { return true } } if len(remaining) == 0 { return false } } }
[ "func", "(", "r", "Route", ")", "matchesAccept", "(", "mimeTypesWithQuality", "string", ")", "bool", "{", "remaining", ":=", "mimeTypesWithQuality", "\n", "for", "{", "var", "mimeType", "string", "\n", "if", "end", ":=", "strings", ".", "Index", "(", "remain...
// Return whether the mimeType matches to what this Route can produce.
[ "Return", "whether", "the", "mimeType", "matches", "to", "what", "this", "Route", "can", "produce", "." ]
d2b8501d30f1b2c552dafdb21e3434bbafdaa124
https://github.com/emicklei/go-restful/blob/d2b8501d30f1b2c552dafdb21e3434bbafdaa124/route.go#L86-L111
train
emicklei/go-restful
route.go
tokenizePath
func tokenizePath(path string) []string { if "/" == path { return nil } return strings.Split(strings.Trim(path, "/"), "/") }
go
func tokenizePath(path string) []string { if "/" == path { return nil } return strings.Split(strings.Trim(path, "/"), "/") }
[ "func", "tokenizePath", "(", "path", "string", ")", "[", "]", "string", "{", "if", "\"", "\"", "==", "path", "{", "return", "nil", "\n", "}", "\n", "return", "strings", ".", "Split", "(", "strings", ".", "Trim", "(", "path", ",", "\"", "\"", ")", ...
// Tokenize an URL path using the slash separator ; the result does not have empty tokens
[ "Tokenize", "an", "URL", "path", "using", "the", "slash", "separator", ";", "the", "result", "does", "not", "have", "empty", "tokens" ]
d2b8501d30f1b2c552dafdb21e3434bbafdaa124
https://github.com/emicklei/go-restful/blob/d2b8501d30f1b2c552dafdb21e3434bbafdaa124/route.go#L155-L160
train
emicklei/go-restful
examples/msgpack/msgpack_entity.go
Read
func (e entityMsgPackAccess) Read(req *restful.Request, v interface{}) error { return msgpack.NewDecoder(req.Request.Body).Decode(v) }
go
func (e entityMsgPackAccess) Read(req *restful.Request, v interface{}) error { return msgpack.NewDecoder(req.Request.Body).Decode(v) }
[ "func", "(", "e", "entityMsgPackAccess", ")", "Read", "(", "req", "*", "restful", ".", "Request", ",", "v", "interface", "{", "}", ")", "error", "{", "return", "msgpack", ".", "NewDecoder", "(", "req", ".", "Request", ".", "Body", ")", ".", "Decode", ...
// Read unmarshalls the value from byte slice and using msgpack to unmarshal
[ "Read", "unmarshalls", "the", "value", "from", "byte", "slice", "and", "using", "msgpack", "to", "unmarshal" ]
d2b8501d30f1b2c552dafdb21e3434bbafdaa124
https://github.com/emicklei/go-restful/blob/d2b8501d30f1b2c552dafdb21e3434bbafdaa124/examples/msgpack/msgpack_entity.go#L21-L23
train
emicklei/go-restful
examples/msgpack/msgpack_entity.go
Write
func (e entityMsgPackAccess) Write(resp *restful.Response, status int, v interface{}) error { if v == nil { resp.WriteHeader(status) // do not write a nil representation return nil } resp.WriteHeader(status) return msgpack.NewEncoder(resp).Encode(v) }
go
func (e entityMsgPackAccess) Write(resp *restful.Response, status int, v interface{}) error { if v == nil { resp.WriteHeader(status) // do not write a nil representation return nil } resp.WriteHeader(status) return msgpack.NewEncoder(resp).Encode(v) }
[ "func", "(", "e", "entityMsgPackAccess", ")", "Write", "(", "resp", "*", "restful", ".", "Response", ",", "status", "int", ",", "v", "interface", "{", "}", ")", "error", "{", "if", "v", "==", "nil", "{", "resp", ".", "WriteHeader", "(", "status", ")"...
// Write marshals the value to byte slice and set the Content-Type Header.
[ "Write", "marshals", "the", "value", "to", "byte", "slice", "and", "set", "the", "Content", "-", "Type", "Header", "." ]
d2b8501d30f1b2c552dafdb21e3434bbafdaa124
https://github.com/emicklei/go-restful/blob/d2b8501d30f1b2c552dafdb21e3434bbafdaa124/examples/msgpack/msgpack_entity.go#L26-L34
train
emicklei/go-restful
jsr311.go
ExtractParameters
func (r RouterJSR311) ExtractParameters(route *Route, webService *WebService, urlPath string) map[string]string { webServiceExpr := webService.pathExpr webServiceMatches := webServiceExpr.Matcher.FindStringSubmatch(urlPath) pathParameters := r.extractParams(webServiceExpr, webServiceMatches) routeExpr := route.pathExpr routeMatches := routeExpr.Matcher.FindStringSubmatch(webServiceMatches[len(webServiceMatches)-1]) routeParams := r.extractParams(routeExpr, routeMatches) for key, value := range routeParams { pathParameters[key] = value } return pathParameters }
go
func (r RouterJSR311) ExtractParameters(route *Route, webService *WebService, urlPath string) map[string]string { webServiceExpr := webService.pathExpr webServiceMatches := webServiceExpr.Matcher.FindStringSubmatch(urlPath) pathParameters := r.extractParams(webServiceExpr, webServiceMatches) routeExpr := route.pathExpr routeMatches := routeExpr.Matcher.FindStringSubmatch(webServiceMatches[len(webServiceMatches)-1]) routeParams := r.extractParams(routeExpr, routeMatches) for key, value := range routeParams { pathParameters[key] = value } return pathParameters }
[ "func", "(", "r", "RouterJSR311", ")", "ExtractParameters", "(", "route", "*", "Route", ",", "webService", "*", "WebService", ",", "urlPath", "string", ")", "map", "[", "string", "]", "string", "{", "webServiceExpr", ":=", "webService", ".", "pathExpr", "\n"...
// ExtractParameters is used to obtain the path parameters from the route using the same matching // engine as the JSR 311 router.
[ "ExtractParameters", "is", "used", "to", "obtain", "the", "path", "parameters", "from", "the", "route", "using", "the", "same", "matching", "engine", "as", "the", "JSR", "311", "router", "." ]
d2b8501d30f1b2c552dafdb21e3434bbafdaa124
https://github.com/emicklei/go-restful/blob/d2b8501d30f1b2c552dafdb21e3434bbafdaa124/jsr311.go#L44-L55
train
emicklei/go-restful
container.go
Add
func (c *Container) Add(service *WebService) *Container { c.webServicesLock.Lock() defer c.webServicesLock.Unlock() // if rootPath was not set then lazy initialize it if len(service.rootPath) == 0 { service.Path("/") } // cannot have duplicate root paths for _, each := range c.webServices { if each.RootPath() == service.RootPath() { log.Printf("WebService with duplicate root path detected:['%v']", each) os.Exit(1) } } // If not registered on root then add specific mapping if !c.isRegisteredOnRoot { c.isRegisteredOnRoot = c.addHandler(service, c.ServeMux) } c.webServices = append(c.webServices, service) return c }
go
func (c *Container) Add(service *WebService) *Container { c.webServicesLock.Lock() defer c.webServicesLock.Unlock() // if rootPath was not set then lazy initialize it if len(service.rootPath) == 0 { service.Path("/") } // cannot have duplicate root paths for _, each := range c.webServices { if each.RootPath() == service.RootPath() { log.Printf("WebService with duplicate root path detected:['%v']", each) os.Exit(1) } } // If not registered on root then add specific mapping if !c.isRegisteredOnRoot { c.isRegisteredOnRoot = c.addHandler(service, c.ServeMux) } c.webServices = append(c.webServices, service) return c }
[ "func", "(", "c", "*", "Container", ")", "Add", "(", "service", "*", "WebService", ")", "*", "Container", "{", "c", ".", "webServicesLock", ".", "Lock", "(", ")", "\n", "defer", "c", ".", "webServicesLock", ".", "Unlock", "(", ")", "\n\n", "// if rootP...
// Add a WebService to the Container. It will detect duplicate root paths and exit in that case.
[ "Add", "a", "WebService", "to", "the", "Container", ".", "It", "will", "detect", "duplicate", "root", "paths", "and", "exit", "in", "that", "case", "." ]
d2b8501d30f1b2c552dafdb21e3434bbafdaa124
https://github.com/emicklei/go-restful/blob/d2b8501d30f1b2c552dafdb21e3434bbafdaa124/container.go#L88-L111
train
emicklei/go-restful
container.go
logStackOnRecover
func logStackOnRecover(panicReason interface{}, httpWriter http.ResponseWriter) { var buffer bytes.Buffer buffer.WriteString(fmt.Sprintf("recover from panic situation: - %v\r\n", panicReason)) for i := 2; ; i += 1 { _, file, line, ok := runtime.Caller(i) if !ok { break } buffer.WriteString(fmt.Sprintf(" %s:%d\r\n", file, line)) } log.Print(buffer.String()) httpWriter.WriteHeader(http.StatusInternalServerError) httpWriter.Write(buffer.Bytes()) }
go
func logStackOnRecover(panicReason interface{}, httpWriter http.ResponseWriter) { var buffer bytes.Buffer buffer.WriteString(fmt.Sprintf("recover from panic situation: - %v\r\n", panicReason)) for i := 2; ; i += 1 { _, file, line, ok := runtime.Caller(i) if !ok { break } buffer.WriteString(fmt.Sprintf(" %s:%d\r\n", file, line)) } log.Print(buffer.String()) httpWriter.WriteHeader(http.StatusInternalServerError) httpWriter.Write(buffer.Bytes()) }
[ "func", "logStackOnRecover", "(", "panicReason", "interface", "{", "}", ",", "httpWriter", "http", ".", "ResponseWriter", ")", "{", "var", "buffer", "bytes", ".", "Buffer", "\n", "buffer", ".", "WriteString", "(", "fmt", ".", "Sprintf", "(", "\"", "\\r", "...
// logStackOnRecover is the default RecoverHandleFunction and is called // when DoNotRecover is false and the recoverHandleFunc is not set for the container. // Default implementation logs the stacktrace and writes the stacktrace on the response. // This may be a security issue as it exposes sourcecode information.
[ "logStackOnRecover", "is", "the", "default", "RecoverHandleFunction", "and", "is", "called", "when", "DoNotRecover", "is", "false", "and", "the", "recoverHandleFunc", "is", "not", "set", "for", "the", "container", ".", "Default", "implementation", "logs", "the", "...
d2b8501d30f1b2c552dafdb21e3434bbafdaa124
https://github.com/emicklei/go-restful/blob/d2b8501d30f1b2c552dafdb21e3434bbafdaa124/container.go#L169-L182
train
emicklei/go-restful
container.go
HandleWithFilter
func (c *Container) HandleWithFilter(pattern string, handler http.Handler) { f := func(httpResponse http.ResponseWriter, httpRequest *http.Request) { if len(c.containerFilters) == 0 { handler.ServeHTTP(httpResponse, httpRequest) return } chain := FilterChain{Filters: c.containerFilters, Target: func(req *Request, resp *Response) { handler.ServeHTTP(httpResponse, httpRequest) }} chain.ProcessFilter(NewRequest(httpRequest), NewResponse(httpResponse)) } c.Handle(pattern, http.HandlerFunc(f)) }
go
func (c *Container) HandleWithFilter(pattern string, handler http.Handler) { f := func(httpResponse http.ResponseWriter, httpRequest *http.Request) { if len(c.containerFilters) == 0 { handler.ServeHTTP(httpResponse, httpRequest) return } chain := FilterChain{Filters: c.containerFilters, Target: func(req *Request, resp *Response) { handler.ServeHTTP(httpResponse, httpRequest) }} chain.ProcessFilter(NewRequest(httpRequest), NewResponse(httpResponse)) } c.Handle(pattern, http.HandlerFunc(f)) }
[ "func", "(", "c", "*", "Container", ")", "HandleWithFilter", "(", "pattern", "string", ",", "handler", "http", ".", "Handler", ")", "{", "f", ":=", "func", "(", "httpResponse", "http", ".", "ResponseWriter", ",", "httpRequest", "*", "http", ".", "Request",...
// HandleWithFilter registers the handler for the given pattern. // Container's filter chain is applied for handler. // If a handler already exists for pattern, HandleWithFilter panics.
[ "HandleWithFilter", "registers", "the", "handler", "for", "the", "given", "pattern", ".", "Container", "s", "filter", "chain", "is", "applied", "for", "handler", ".", "If", "a", "handler", "already", "exists", "for", "pattern", "HandleWithFilter", "panics", "." ...
d2b8501d30f1b2c552dafdb21e3434bbafdaa124
https://github.com/emicklei/go-restful/blob/d2b8501d30f1b2c552dafdb21e3434bbafdaa124/container.go#L314-L328
train
emicklei/go-restful
container.go
Filter
func (c *Container) Filter(filter FilterFunction) { c.containerFilters = append(c.containerFilters, filter) }
go
func (c *Container) Filter(filter FilterFunction) { c.containerFilters = append(c.containerFilters, filter) }
[ "func", "(", "c", "*", "Container", ")", "Filter", "(", "filter", "FilterFunction", ")", "{", "c", ".", "containerFilters", "=", "append", "(", "c", ".", "containerFilters", ",", "filter", ")", "\n", "}" ]
// Filter appends a container FilterFunction. These are called before dispatching // a http.Request to a WebService from the container
[ "Filter", "appends", "a", "container", "FilterFunction", ".", "These", "are", "called", "before", "dispatching", "a", "http", ".", "Request", "to", "a", "WebService", "from", "the", "container" ]
d2b8501d30f1b2c552dafdb21e3434bbafdaa124
https://github.com/emicklei/go-restful/blob/d2b8501d30f1b2c552dafdb21e3434bbafdaa124/container.go#L332-L334
train
emicklei/go-restful
container.go
RegisteredWebServices
func (c *Container) RegisteredWebServices() []*WebService { c.webServicesLock.RLock() defer c.webServicesLock.RUnlock() result := make([]*WebService, len(c.webServices)) for ix := range c.webServices { result[ix] = c.webServices[ix] } return result }
go
func (c *Container) RegisteredWebServices() []*WebService { c.webServicesLock.RLock() defer c.webServicesLock.RUnlock() result := make([]*WebService, len(c.webServices)) for ix := range c.webServices { result[ix] = c.webServices[ix] } return result }
[ "func", "(", "c", "*", "Container", ")", "RegisteredWebServices", "(", ")", "[", "]", "*", "WebService", "{", "c", ".", "webServicesLock", ".", "RLock", "(", ")", "\n", "defer", "c", ".", "webServicesLock", ".", "RUnlock", "(", ")", "\n", "result", ":=...
// RegisteredWebServices returns the collections of added WebServices
[ "RegisteredWebServices", "returns", "the", "collections", "of", "added", "WebServices" ]
d2b8501d30f1b2c552dafdb21e3434bbafdaa124
https://github.com/emicklei/go-restful/blob/d2b8501d30f1b2c552dafdb21e3434bbafdaa124/container.go#L337-L345
train
emicklei/go-restful
container.go
computeAllowedMethods
func (c *Container) computeAllowedMethods(req *Request) []string { // Go through all RegisteredWebServices() and all its Routes to collect the options methods := []string{} requestPath := req.Request.URL.Path for _, ws := range c.RegisteredWebServices() { matches := ws.pathExpr.Matcher.FindStringSubmatch(requestPath) if matches != nil { finalMatch := matches[len(matches)-1] for _, rt := range ws.Routes() { matches := rt.pathExpr.Matcher.FindStringSubmatch(finalMatch) if matches != nil { lastMatch := matches[len(matches)-1] if lastMatch == "" || lastMatch == "/" { // do not include if value is neither empty nor ‘/’. methods = append(methods, rt.Method) } } } } } // methods = append(methods, "OPTIONS") not sure about this return methods }
go
func (c *Container) computeAllowedMethods(req *Request) []string { // Go through all RegisteredWebServices() and all its Routes to collect the options methods := []string{} requestPath := req.Request.URL.Path for _, ws := range c.RegisteredWebServices() { matches := ws.pathExpr.Matcher.FindStringSubmatch(requestPath) if matches != nil { finalMatch := matches[len(matches)-1] for _, rt := range ws.Routes() { matches := rt.pathExpr.Matcher.FindStringSubmatch(finalMatch) if matches != nil { lastMatch := matches[len(matches)-1] if lastMatch == "" || lastMatch == "/" { // do not include if value is neither empty nor ‘/’. methods = append(methods, rt.Method) } } } } } // methods = append(methods, "OPTIONS") not sure about this return methods }
[ "func", "(", "c", "*", "Container", ")", "computeAllowedMethods", "(", "req", "*", "Request", ")", "[", "]", "string", "{", "// Go through all RegisteredWebServices() and all its Routes to collect the options", "methods", ":=", "[", "]", "string", "{", "}", "\n", "r...
// computeAllowedMethods returns a list of HTTP methods that are valid for a Request
[ "computeAllowedMethods", "returns", "a", "list", "of", "HTTP", "methods", "that", "are", "valid", "for", "a", "Request" ]
d2b8501d30f1b2c552dafdb21e3434bbafdaa124
https://github.com/emicklei/go-restful/blob/d2b8501d30f1b2c552dafdb21e3434bbafdaa124/container.go#L348-L369
train
emicklei/go-restful
compress.go
Write
func (c *CompressingResponseWriter) Write(bytes []byte) (int, error) { if c.isCompressorClosed() { return -1, errors.New("Compressing error: tried to write data using closed compressor") } return c.compressor.Write(bytes) }
go
func (c *CompressingResponseWriter) Write(bytes []byte) (int, error) { if c.isCompressorClosed() { return -1, errors.New("Compressing error: tried to write data using closed compressor") } return c.compressor.Write(bytes) }
[ "func", "(", "c", "*", "CompressingResponseWriter", ")", "Write", "(", "bytes", "[", "]", "byte", ")", "(", "int", ",", "error", ")", "{", "if", "c", ".", "isCompressorClosed", "(", ")", "{", "return", "-", "1", ",", "errors", ".", "New", "(", "\""...
// Write is part of http.ResponseWriter interface // It is passed through the compressor
[ "Write", "is", "part", "of", "http", ".", "ResponseWriter", "interface", "It", "is", "passed", "through", "the", "compressor" ]
d2b8501d30f1b2c552dafdb21e3434bbafdaa124
https://github.com/emicklei/go-restful/blob/d2b8501d30f1b2c552dafdb21e3434bbafdaa124/compress.go#L40-L45
train
emicklei/go-restful
compress.go
wantsCompressedResponse
func wantsCompressedResponse(httpRequest *http.Request) (bool, string) { header := httpRequest.Header.Get(HEADER_AcceptEncoding) gi := strings.Index(header, ENCODING_GZIP) zi := strings.Index(header, ENCODING_DEFLATE) // use in order of appearance if gi == -1 { return zi != -1, ENCODING_DEFLATE } else if zi == -1 { return gi != -1, ENCODING_GZIP } else { if gi < zi { return true, ENCODING_GZIP } return true, ENCODING_DEFLATE } }
go
func wantsCompressedResponse(httpRequest *http.Request) (bool, string) { header := httpRequest.Header.Get(HEADER_AcceptEncoding) gi := strings.Index(header, ENCODING_GZIP) zi := strings.Index(header, ENCODING_DEFLATE) // use in order of appearance if gi == -1 { return zi != -1, ENCODING_DEFLATE } else if zi == -1 { return gi != -1, ENCODING_GZIP } else { if gi < zi { return true, ENCODING_GZIP } return true, ENCODING_DEFLATE } }
[ "func", "wantsCompressedResponse", "(", "httpRequest", "*", "http", ".", "Request", ")", "(", "bool", ",", "string", ")", "{", "header", ":=", "httpRequest", ".", "Header", ".", "Get", "(", "HEADER_AcceptEncoding", ")", "\n", "gi", ":=", "strings", ".", "I...
// WantsCompressedResponse reads the Accept-Encoding header to see if and which encoding is requested.
[ "WantsCompressedResponse", "reads", "the", "Accept", "-", "Encoding", "header", "to", "see", "if", "and", "which", "encoding", "is", "requested", "." ]
d2b8501d30f1b2c552dafdb21e3434bbafdaa124
https://github.com/emicklei/go-restful/blob/d2b8501d30f1b2c552dafdb21e3434bbafdaa124/compress.go#L86-L101
train
emicklei/go-restful
path_processor.go
ExtractParameters
func (d defaultPathProcessor) ExtractParameters(r *Route, _ *WebService, urlPath string) map[string]string { urlParts := tokenizePath(urlPath) pathParameters := map[string]string{} for i, key := range r.pathParts { var value string if i >= len(urlParts) { value = "" } else { value = urlParts[i] } if strings.HasPrefix(key, "{") { // path-parameter if colon := strings.Index(key, ":"); colon != -1 { // extract by regex regPart := key[colon+1 : len(key)-1] keyPart := key[1:colon] if regPart == "*" { pathParameters[keyPart] = untokenizePath(i, urlParts) break } else { pathParameters[keyPart] = value } } else { // without enclosing {} pathParameters[key[1:len(key)-1]] = value } } } return pathParameters }
go
func (d defaultPathProcessor) ExtractParameters(r *Route, _ *WebService, urlPath string) map[string]string { urlParts := tokenizePath(urlPath) pathParameters := map[string]string{} for i, key := range r.pathParts { var value string if i >= len(urlParts) { value = "" } else { value = urlParts[i] } if strings.HasPrefix(key, "{") { // path-parameter if colon := strings.Index(key, ":"); colon != -1 { // extract by regex regPart := key[colon+1 : len(key)-1] keyPart := key[1:colon] if regPart == "*" { pathParameters[keyPart] = untokenizePath(i, urlParts) break } else { pathParameters[keyPart] = value } } else { // without enclosing {} pathParameters[key[1:len(key)-1]] = value } } } return pathParameters }
[ "func", "(", "d", "defaultPathProcessor", ")", "ExtractParameters", "(", "r", "*", "Route", ",", "_", "*", "WebService", ",", "urlPath", "string", ")", "map", "[", "string", "]", "string", "{", "urlParts", ":=", "tokenizePath", "(", "urlPath", ")", "\n", ...
// Extract the parameters from the request url path
[ "Extract", "the", "parameters", "from", "the", "request", "url", "path" ]
d2b8501d30f1b2c552dafdb21e3434bbafdaa124
https://github.com/emicklei/go-restful/blob/d2b8501d30f1b2c552dafdb21e3434bbafdaa124/path_processor.go#L22-L50
train
emicklei/go-restful
path_processor.go
untokenizePath
func untokenizePath(offset int, parts []string) string { var buffer bytes.Buffer for p := offset; p < len(parts); p++ { buffer.WriteString(parts[p]) // do not end if p < len(parts)-1 { buffer.WriteString("/") } } return buffer.String() }
go
func untokenizePath(offset int, parts []string) string { var buffer bytes.Buffer for p := offset; p < len(parts); p++ { buffer.WriteString(parts[p]) // do not end if p < len(parts)-1 { buffer.WriteString("/") } } return buffer.String() }
[ "func", "untokenizePath", "(", "offset", "int", ",", "parts", "[", "]", "string", ")", "string", "{", "var", "buffer", "bytes", ".", "Buffer", "\n", "for", "p", ":=", "offset", ";", "p", "<", "len", "(", "parts", ")", ";", "p", "++", "{", "buffer",...
// Untokenize back into an URL path using the slash separator
[ "Untokenize", "back", "into", "an", "URL", "path", "using", "the", "slash", "separator" ]
d2b8501d30f1b2c552dafdb21e3434bbafdaa124
https://github.com/emicklei/go-restful/blob/d2b8501d30f1b2c552dafdb21e3434bbafdaa124/path_processor.go#L53-L63
train
emicklei/go-restful
web_service.go
compilePathExpression
func (w *WebService) compilePathExpression() { compiled, err := newPathExpression(w.rootPath) if err != nil { log.Printf("invalid path:%s because:%v", w.rootPath, err) os.Exit(1) } w.pathExpr = compiled }
go
func (w *WebService) compilePathExpression() { compiled, err := newPathExpression(w.rootPath) if err != nil { log.Printf("invalid path:%s because:%v", w.rootPath, err) os.Exit(1) } w.pathExpr = compiled }
[ "func", "(", "w", "*", "WebService", ")", "compilePathExpression", "(", ")", "{", "compiled", ",", "err", ":=", "newPathExpression", "(", "w", ".", "rootPath", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Printf", "(", "\"", "\"", ",", "w",...
// compilePathExpression ensures that the path is compiled into a RegEx for those routers that need it.
[ "compilePathExpression", "ensures", "that", "the", "path", "is", "compiled", "into", "a", "RegEx", "for", "those", "routers", "that", "need", "it", "." ]
d2b8501d30f1b2c552dafdb21e3434bbafdaa124
https://github.com/emicklei/go-restful/blob/d2b8501d30f1b2c552dafdb21e3434bbafdaa124/web_service.go#L60-L67
train
emicklei/go-restful
web_service.go
ApiVersion
func (w *WebService) ApiVersion(apiVersion string) *WebService { w.apiVersion = apiVersion return w }
go
func (w *WebService) ApiVersion(apiVersion string) *WebService { w.apiVersion = apiVersion return w }
[ "func", "(", "w", "*", "WebService", ")", "ApiVersion", "(", "apiVersion", "string", ")", "*", "WebService", "{", "w", ".", "apiVersion", "=", "apiVersion", "\n", "return", "w", "\n", "}" ]
// ApiVersion sets the API version for documentation purposes.
[ "ApiVersion", "sets", "the", "API", "version", "for", "documentation", "purposes", "." ]
d2b8501d30f1b2c552dafdb21e3434bbafdaa124
https://github.com/emicklei/go-restful/blob/d2b8501d30f1b2c552dafdb21e3434bbafdaa124/web_service.go#L70-L73
train
emicklei/go-restful
web_service.go
Path
func (w *WebService) Path(root string) *WebService { w.rootPath = root if len(w.rootPath) == 0 { w.rootPath = "/" } w.compilePathExpression() return w }
go
func (w *WebService) Path(root string) *WebService { w.rootPath = root if len(w.rootPath) == 0 { w.rootPath = "/" } w.compilePathExpression() return w }
[ "func", "(", "w", "*", "WebService", ")", "Path", "(", "root", "string", ")", "*", "WebService", "{", "w", ".", "rootPath", "=", "root", "\n", "if", "len", "(", "w", ".", "rootPath", ")", "==", "0", "{", "w", ".", "rootPath", "=", "\"", "\"", "...
// Path specifies the root URL template path of the WebService. // All Routes will be relative to this path.
[ "Path", "specifies", "the", "root", "URL", "template", "path", "of", "the", "WebService", ".", "All", "Routes", "will", "be", "relative", "to", "this", "path", "." ]
d2b8501d30f1b2c552dafdb21e3434bbafdaa124
https://github.com/emicklei/go-restful/blob/d2b8501d30f1b2c552dafdb21e3434bbafdaa124/web_service.go#L80-L87
train
emicklei/go-restful
web_service.go
Param
func (w *WebService) Param(parameter *Parameter) *WebService { if w.pathParameters == nil { w.pathParameters = []*Parameter{} } w.pathParameters = append(w.pathParameters, parameter) return w }
go
func (w *WebService) Param(parameter *Parameter) *WebService { if w.pathParameters == nil { w.pathParameters = []*Parameter{} } w.pathParameters = append(w.pathParameters, parameter) return w }
[ "func", "(", "w", "*", "WebService", ")", "Param", "(", "parameter", "*", "Parameter", ")", "*", "WebService", "{", "if", "w", ".", "pathParameters", "==", "nil", "{", "w", ".", "pathParameters", "=", "[", "]", "*", "Parameter", "{", "}", "\n", "}", ...
// Param adds a PathParameter to document parameters used in the root path.
[ "Param", "adds", "a", "PathParameter", "to", "document", "parameters", "used", "in", "the", "root", "path", "." ]
d2b8501d30f1b2c552dafdb21e3434bbafdaa124
https://github.com/emicklei/go-restful/blob/d2b8501d30f1b2c552dafdb21e3434bbafdaa124/web_service.go#L90-L96
train
emicklei/go-restful
web_service.go
Route
func (w *WebService) Route(builder *RouteBuilder) *WebService { w.routesLock.Lock() defer w.routesLock.Unlock() builder.copyDefaults(w.produces, w.consumes) w.routes = append(w.routes, builder.Build()) return w }
go
func (w *WebService) Route(builder *RouteBuilder) *WebService { w.routesLock.Lock() defer w.routesLock.Unlock() builder.copyDefaults(w.produces, w.consumes) w.routes = append(w.routes, builder.Build()) return w }
[ "func", "(", "w", "*", "WebService", ")", "Route", "(", "builder", "*", "RouteBuilder", ")", "*", "WebService", "{", "w", ".", "routesLock", ".", "Lock", "(", ")", "\n", "defer", "w", ".", "routesLock", ".", "Unlock", "(", ")", "\n", "builder", ".", ...
// Route creates a new Route using the RouteBuilder and add to the ordered list of Routes.
[ "Route", "creates", "a", "new", "Route", "using", "the", "RouteBuilder", "and", "add", "to", "the", "ordered", "list", "of", "Routes", "." ]
d2b8501d30f1b2c552dafdb21e3434bbafdaa124
https://github.com/emicklei/go-restful/blob/d2b8501d30f1b2c552dafdb21e3434bbafdaa124/web_service.go#L169-L175
train
emicklei/go-restful
web_service.go
RemoveRoute
func (w *WebService) RemoveRoute(path, method string) error { if !w.dynamicRoutes { return errors.New("dynamic routes are not enabled.") } w.routesLock.Lock() defer w.routesLock.Unlock() newRoutes := make([]Route, (len(w.routes) - 1)) current := 0 for ix := range w.routes { if w.routes[ix].Method == method && w.routes[ix].Path == path { continue } newRoutes[current] = w.routes[ix] current = current + 1 } w.routes = newRoutes return nil }
go
func (w *WebService) RemoveRoute(path, method string) error { if !w.dynamicRoutes { return errors.New("dynamic routes are not enabled.") } w.routesLock.Lock() defer w.routesLock.Unlock() newRoutes := make([]Route, (len(w.routes) - 1)) current := 0 for ix := range w.routes { if w.routes[ix].Method == method && w.routes[ix].Path == path { continue } newRoutes[current] = w.routes[ix] current = current + 1 } w.routes = newRoutes return nil }
[ "func", "(", "w", "*", "WebService", ")", "RemoveRoute", "(", "path", ",", "method", "string", ")", "error", "{", "if", "!", "w", ".", "dynamicRoutes", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n", "w", ".", "routesLoc...
// RemoveRoute removes the specified route, looks for something that matches 'path' and 'method'
[ "RemoveRoute", "removes", "the", "specified", "route", "looks", "for", "something", "that", "matches", "path", "and", "method" ]
d2b8501d30f1b2c552dafdb21e3434bbafdaa124
https://github.com/emicklei/go-restful/blob/d2b8501d30f1b2c552dafdb21e3434bbafdaa124/web_service.go#L178-L195
train