id
int32
0
167k
repo
stringlengths
5
54
path
stringlengths
4
155
func_name
stringlengths
1
118
original_string
stringlengths
52
85.5k
language
stringclasses
1 value
code
stringlengths
52
85.5k
code_tokens
listlengths
21
1.41k
docstring
stringlengths
6
2.61k
docstring_tokens
listlengths
3
215
sha
stringlengths
40
40
url
stringlengths
85
252
146,300
couchbase/go-couchbase
client.go
GetsMC
func (b *Bucket) GetsMC(key string, reqDeadline time.Time) (*gomemcached.MCResponse, error) { var err error var response *gomemcached.MCResponse if key == "" { return nil, nil } if ClientOpCallback != nil { defer func(t time.Time) { ClientOpCallback("GetsMC", key, t, err) }(time.Now()) } err = b.Do2(key, func(mc *memcached.Client, vb uint16) error { var err1 error mc.SetDeadline(getDeadline(reqDeadline, DefaultTimeout)) response, err1 = mc.Get(vb, key) mc.SetDeadline(noDeadline) if err1 != nil { return err1 } return nil }, false) return response, err }
go
func (b *Bucket) GetsMC(key string, reqDeadline time.Time) (*gomemcached.MCResponse, error) { var err error var response *gomemcached.MCResponse if key == "" { return nil, nil } if ClientOpCallback != nil { defer func(t time.Time) { ClientOpCallback("GetsMC", key, t, err) }(time.Now()) } err = b.Do2(key, func(mc *memcached.Client, vb uint16) error { var err1 error mc.SetDeadline(getDeadline(reqDeadline, DefaultTimeout)) response, err1 = mc.Get(vb, key) mc.SetDeadline(noDeadline) if err1 != nil { return err1 } return nil }, false) return response, err }
[ "func", "(", "b", "*", "Bucket", ")", "GetsMC", "(", "key", "string", ",", "reqDeadline", "time", ".", "Time", ")", "(", "*", "gomemcached", ".", "MCResponse", ",", "error", ")", "{", "var", "err", "error", "\n", "var", "response", "*", "gomemcached", ".", "MCResponse", "\n\n", "if", "key", "==", "\"", "\"", "{", "return", "nil", ",", "nil", "\n", "}", "\n\n", "if", "ClientOpCallback", "!=", "nil", "{", "defer", "func", "(", "t", "time", ".", "Time", ")", "{", "ClientOpCallback", "(", "\"", "\"", ",", "key", ",", "t", ",", "err", ")", "}", "(", "time", ".", "Now", "(", ")", ")", "\n", "}", "\n\n", "err", "=", "b", ".", "Do2", "(", "key", ",", "func", "(", "mc", "*", "memcached", ".", "Client", ",", "vb", "uint16", ")", "error", "{", "var", "err1", "error", "\n\n", "mc", ".", "SetDeadline", "(", "getDeadline", "(", "reqDeadline", ",", "DefaultTimeout", ")", ")", "\n", "response", ",", "err1", "=", "mc", ".", "Get", "(", "vb", ",", "key", ")", "\n", "mc", ".", "SetDeadline", "(", "noDeadline", ")", "\n", "if", "err1", "!=", "nil", "{", "return", "err1", "\n", "}", "\n", "return", "nil", "\n", "}", ",", "false", ")", "\n", "return", "response", ",", "err", "\n", "}" ]
// Get a value straight from Memcached
[ "Get", "a", "value", "straight", "from", "Memcached" ]
6aeabeae85e5645306382779e3ee55a330ec558c
https://github.com/couchbase/go-couchbase/blob/6aeabeae85e5645306382779e3ee55a330ec558c/client.go#L1076-L1100
146,301
couchbase/go-couchbase
client.go
GetsRaw
func (b *Bucket) GetsRaw(k string) (data []byte, flags int, cas uint64, err error) { if ClientOpCallback != nil { defer func(t time.Time) { ClientOpCallback("GetsRaw", k, t, err) }(time.Now()) } err = b.Do(k, func(mc *memcached.Client, vb uint16) error { res, err := mc.Get(vb, k) if err != nil { return err } cas = res.Cas if len(res.Extras) >= 4 { flags = int(binary.BigEndian.Uint32(res.Extras)) } data = res.Body return nil }) return }
go
func (b *Bucket) GetsRaw(k string) (data []byte, flags int, cas uint64, err error) { if ClientOpCallback != nil { defer func(t time.Time) { ClientOpCallback("GetsRaw", k, t, err) }(time.Now()) } err = b.Do(k, func(mc *memcached.Client, vb uint16) error { res, err := mc.Get(vb, k) if err != nil { return err } cas = res.Cas if len(res.Extras) >= 4 { flags = int(binary.BigEndian.Uint32(res.Extras)) } data = res.Body return nil }) return }
[ "func", "(", "b", "*", "Bucket", ")", "GetsRaw", "(", "k", "string", ")", "(", "data", "[", "]", "byte", ",", "flags", "int", ",", "cas", "uint64", ",", "err", "error", ")", "{", "if", "ClientOpCallback", "!=", "nil", "{", "defer", "func", "(", "t", "time", ".", "Time", ")", "{", "ClientOpCallback", "(", "\"", "\"", ",", "k", ",", "t", ",", "err", ")", "}", "(", "time", ".", "Now", "(", ")", ")", "\n", "}", "\n\n", "err", "=", "b", ".", "Do", "(", "k", ",", "func", "(", "mc", "*", "memcached", ".", "Client", ",", "vb", "uint16", ")", "error", "{", "res", ",", "err", ":=", "mc", ".", "Get", "(", "vb", ",", "k", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "cas", "=", "res", ".", "Cas", "\n", "if", "len", "(", "res", ".", "Extras", ")", ">=", "4", "{", "flags", "=", "int", "(", "binary", ".", "BigEndian", ".", "Uint32", "(", "res", ".", "Extras", ")", ")", "\n", "}", "\n", "data", "=", "res", ".", "Body", "\n", "return", "nil", "\n", "}", ")", "\n", "return", "\n", "}" ]
// GetsRaw gets a raw value from this bucket including its CAS // counter and flags.
[ "GetsRaw", "gets", "a", "raw", "value", "from", "this", "bucket", "including", "its", "CAS", "counter", "and", "flags", "." ]
6aeabeae85e5645306382779e3ee55a330ec558c
https://github.com/couchbase/go-couchbase/blob/6aeabeae85e5645306382779e3ee55a330ec558c/client.go#L1131-L1151
146,302
couchbase/go-couchbase
client.go
Gets
func (b *Bucket) Gets(k string, rv interface{}, caso *uint64) error { data, _, cas, err := b.GetsRaw(k) if err != nil { return err } if caso != nil { *caso = cas } return json.Unmarshal(data, rv) }
go
func (b *Bucket) Gets(k string, rv interface{}, caso *uint64) error { data, _, cas, err := b.GetsRaw(k) if err != nil { return err } if caso != nil { *caso = cas } return json.Unmarshal(data, rv) }
[ "func", "(", "b", "*", "Bucket", ")", "Gets", "(", "k", "string", ",", "rv", "interface", "{", "}", ",", "caso", "*", "uint64", ")", "error", "{", "data", ",", "_", ",", "cas", ",", "err", ":=", "b", ".", "GetsRaw", "(", "k", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "if", "caso", "!=", "nil", "{", "*", "caso", "=", "cas", "\n", "}", "\n", "return", "json", ".", "Unmarshal", "(", "data", ",", "rv", ")", "\n", "}" ]
// Gets gets a value from this bucket, including its CAS counter. The // value is expected to be a JSON stream and will be deserialized into // rv.
[ "Gets", "gets", "a", "value", "from", "this", "bucket", "including", "its", "CAS", "counter", ".", "The", "value", "is", "expected", "to", "be", "a", "JSON", "stream", "and", "will", "be", "deserialized", "into", "rv", "." ]
6aeabeae85e5645306382779e3ee55a330ec558c
https://github.com/couchbase/go-couchbase/blob/6aeabeae85e5645306382779e3ee55a330ec558c/client.go#L1156-L1165
146,303
couchbase/go-couchbase
client.go
Get
func (b *Bucket) Get(k string, rv interface{}) error { return b.Gets(k, rv, nil) }
go
func (b *Bucket) Get(k string, rv interface{}) error { return b.Gets(k, rv, nil) }
[ "func", "(", "b", "*", "Bucket", ")", "Get", "(", "k", "string", ",", "rv", "interface", "{", "}", ")", "error", "{", "return", "b", ".", "Gets", "(", "k", ",", "rv", ",", "nil", ")", "\n", "}" ]
// Get a value from this bucket. // The value is expected to be a JSON stream and will be deserialized // into rv.
[ "Get", "a", "value", "from", "this", "bucket", ".", "The", "value", "is", "expected", "to", "be", "a", "JSON", "stream", "and", "will", "be", "deserialized", "into", "rv", "." ]
6aeabeae85e5645306382779e3ee55a330ec558c
https://github.com/couchbase/go-couchbase/blob/6aeabeae85e5645306382779e3ee55a330ec558c/client.go#L1170-L1172
146,304
couchbase/go-couchbase
client.go
GetRaw
func (b *Bucket) GetRaw(k string) ([]byte, error) { d, _, _, err := b.GetsRaw(k) return d, err }
go
func (b *Bucket) GetRaw(k string) ([]byte, error) { d, _, _, err := b.GetsRaw(k) return d, err }
[ "func", "(", "b", "*", "Bucket", ")", "GetRaw", "(", "k", "string", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "d", ",", "_", ",", "_", ",", "err", ":=", "b", ".", "GetsRaw", "(", "k", ")", "\n", "return", "d", ",", "err", "\n", "}" ]
// GetRaw gets a raw value from this bucket. No marshaling is performed.
[ "GetRaw", "gets", "a", "raw", "value", "from", "this", "bucket", ".", "No", "marshaling", "is", "performed", "." ]
6aeabeae85e5645306382779e3ee55a330ec558c
https://github.com/couchbase/go-couchbase/blob/6aeabeae85e5645306382779e3ee55a330ec558c/client.go#L1175-L1178
146,305
couchbase/go-couchbase
client.go
GetAndTouchRaw
func (b *Bucket) GetAndTouchRaw(k string, exp int) (data []byte, cas uint64, err error) { if ClientOpCallback != nil { defer func(t time.Time) { ClientOpCallback("GetsRaw", k, t, err) }(time.Now()) } err = b.Do(k, func(mc *memcached.Client, vb uint16) error { res, err := mc.GetAndTouch(vb, k, exp) if err != nil { return err } cas = res.Cas data = res.Body return nil }) return data, cas, err }
go
func (b *Bucket) GetAndTouchRaw(k string, exp int) (data []byte, cas uint64, err error) { if ClientOpCallback != nil { defer func(t time.Time) { ClientOpCallback("GetsRaw", k, t, err) }(time.Now()) } err = b.Do(k, func(mc *memcached.Client, vb uint16) error { res, err := mc.GetAndTouch(vb, k, exp) if err != nil { return err } cas = res.Cas data = res.Body return nil }) return data, cas, err }
[ "func", "(", "b", "*", "Bucket", ")", "GetAndTouchRaw", "(", "k", "string", ",", "exp", "int", ")", "(", "data", "[", "]", "byte", ",", "cas", "uint64", ",", "err", "error", ")", "{", "if", "ClientOpCallback", "!=", "nil", "{", "defer", "func", "(", "t", "time", ".", "Time", ")", "{", "ClientOpCallback", "(", "\"", "\"", ",", "k", ",", "t", ",", "err", ")", "}", "(", "time", ".", "Now", "(", ")", ")", "\n", "}", "\n\n", "err", "=", "b", ".", "Do", "(", "k", ",", "func", "(", "mc", "*", "memcached", ".", "Client", ",", "vb", "uint16", ")", "error", "{", "res", ",", "err", ":=", "mc", ".", "GetAndTouch", "(", "vb", ",", "k", ",", "exp", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "cas", "=", "res", ".", "Cas", "\n", "data", "=", "res", ".", "Body", "\n", "return", "nil", "\n", "}", ")", "\n", "return", "data", ",", "cas", ",", "err", "\n", "}" ]
// GetAndTouchRaw gets a raw value from this bucket including its CAS // counter and flags, and updates the expiry on the doc.
[ "GetAndTouchRaw", "gets", "a", "raw", "value", "from", "this", "bucket", "including", "its", "CAS", "counter", "and", "flags", "and", "updates", "the", "expiry", "on", "the", "doc", "." ]
6aeabeae85e5645306382779e3ee55a330ec558c
https://github.com/couchbase/go-couchbase/blob/6aeabeae85e5645306382779e3ee55a330ec558c/client.go#L1182-L1199
146,306
couchbase/go-couchbase
client.go
GetMeta
func (b *Bucket) GetMeta(k string, flags *int, expiry *int, cas *uint64, seqNo *uint64) (err error) { if ClientOpCallback != nil { defer func(t time.Time) { ClientOpCallback("GetsMeta", k, t, err) }(time.Now()) } err = b.Do(k, func(mc *memcached.Client, vb uint16) error { res, err := mc.GetMeta(vb, k) if err != nil { return err } *cas = res.Cas if len(res.Extras) >= 8 { *flags = int(binary.BigEndian.Uint32(res.Extras[4:])) } if len(res.Extras) >= 12 { *expiry = int(binary.BigEndian.Uint32(res.Extras[8:])) } if len(res.Extras) >= 20 { *seqNo = uint64(binary.BigEndian.Uint64(res.Extras[12:])) } return nil }) return err }
go
func (b *Bucket) GetMeta(k string, flags *int, expiry *int, cas *uint64, seqNo *uint64) (err error) { if ClientOpCallback != nil { defer func(t time.Time) { ClientOpCallback("GetsMeta", k, t, err) }(time.Now()) } err = b.Do(k, func(mc *memcached.Client, vb uint16) error { res, err := mc.GetMeta(vb, k) if err != nil { return err } *cas = res.Cas if len(res.Extras) >= 8 { *flags = int(binary.BigEndian.Uint32(res.Extras[4:])) } if len(res.Extras) >= 12 { *expiry = int(binary.BigEndian.Uint32(res.Extras[8:])) } if len(res.Extras) >= 20 { *seqNo = uint64(binary.BigEndian.Uint64(res.Extras[12:])) } return nil }) return err }
[ "func", "(", "b", "*", "Bucket", ")", "GetMeta", "(", "k", "string", ",", "flags", "*", "int", ",", "expiry", "*", "int", ",", "cas", "*", "uint64", ",", "seqNo", "*", "uint64", ")", "(", "err", "error", ")", "{", "if", "ClientOpCallback", "!=", "nil", "{", "defer", "func", "(", "t", "time", ".", "Time", ")", "{", "ClientOpCallback", "(", "\"", "\"", ",", "k", ",", "t", ",", "err", ")", "}", "(", "time", ".", "Now", "(", ")", ")", "\n", "}", "\n\n", "err", "=", "b", ".", "Do", "(", "k", ",", "func", "(", "mc", "*", "memcached", ".", "Client", ",", "vb", "uint16", ")", "error", "{", "res", ",", "err", ":=", "mc", ".", "GetMeta", "(", "vb", ",", "k", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "*", "cas", "=", "res", ".", "Cas", "\n", "if", "len", "(", "res", ".", "Extras", ")", ">=", "8", "{", "*", "flags", "=", "int", "(", "binary", ".", "BigEndian", ".", "Uint32", "(", "res", ".", "Extras", "[", "4", ":", "]", ")", ")", "\n", "}", "\n\n", "if", "len", "(", "res", ".", "Extras", ")", ">=", "12", "{", "*", "expiry", "=", "int", "(", "binary", ".", "BigEndian", ".", "Uint32", "(", "res", ".", "Extras", "[", "8", ":", "]", ")", ")", "\n", "}", "\n\n", "if", "len", "(", "res", ".", "Extras", ")", ">=", "20", "{", "*", "seqNo", "=", "uint64", "(", "binary", ".", "BigEndian", ".", "Uint64", "(", "res", ".", "Extras", "[", "12", ":", "]", ")", ")", "\n", "}", "\n\n", "return", "nil", "\n", "}", ")", "\n\n", "return", "err", "\n", "}" ]
// GetMeta returns the meta values for a key
[ "GetMeta", "returns", "the", "meta", "values", "for", "a", "key" ]
6aeabeae85e5645306382779e3ee55a330ec558c
https://github.com/couchbase/go-couchbase/blob/6aeabeae85e5645306382779e3ee55a330ec558c/client.go#L1202-L1231
146,307
couchbase/go-couchbase
client.go
Delete
func (b *Bucket) Delete(k string) error { return b.Write(k, 0, 0, nil, Raw) }
go
func (b *Bucket) Delete(k string) error { return b.Write(k, 0, 0, nil, Raw) }
[ "func", "(", "b", "*", "Bucket", ")", "Delete", "(", "k", "string", ")", "error", "{", "return", "b", ".", "Write", "(", "k", ",", "0", ",", "0", ",", "nil", ",", "Raw", ")", "\n", "}" ]
// Delete a key from this bucket.
[ "Delete", "a", "key", "from", "this", "bucket", "." ]
6aeabeae85e5645306382779e3ee55a330ec558c
https://github.com/couchbase/go-couchbase/blob/6aeabeae85e5645306382779e3ee55a330ec558c/client.go#L1234-L1236
146,308
couchbase/go-couchbase
client.go
Incr
func (b *Bucket) Incr(k string, amt, def uint64, exp int) (val uint64, err error) { if ClientOpCallback != nil { defer func(t time.Time) { ClientOpCallback("Incr", k, t, err) }(time.Now()) } var rv uint64 err = b.Do(k, func(mc *memcached.Client, vb uint16) error { res, err := mc.Incr(vb, k, amt, def, exp) if err != nil { return err } rv = res return nil }) return rv, err }
go
func (b *Bucket) Incr(k string, amt, def uint64, exp int) (val uint64, err error) { if ClientOpCallback != nil { defer func(t time.Time) { ClientOpCallback("Incr", k, t, err) }(time.Now()) } var rv uint64 err = b.Do(k, func(mc *memcached.Client, vb uint16) error { res, err := mc.Incr(vb, k, amt, def, exp) if err != nil { return err } rv = res return nil }) return rv, err }
[ "func", "(", "b", "*", "Bucket", ")", "Incr", "(", "k", "string", ",", "amt", ",", "def", "uint64", ",", "exp", "int", ")", "(", "val", "uint64", ",", "err", "error", ")", "{", "if", "ClientOpCallback", "!=", "nil", "{", "defer", "func", "(", "t", "time", ".", "Time", ")", "{", "ClientOpCallback", "(", "\"", "\"", ",", "k", ",", "t", ",", "err", ")", "}", "(", "time", ".", "Now", "(", ")", ")", "\n", "}", "\n\n", "var", "rv", "uint64", "\n", "err", "=", "b", ".", "Do", "(", "k", ",", "func", "(", "mc", "*", "memcached", ".", "Client", ",", "vb", "uint16", ")", "error", "{", "res", ",", "err", ":=", "mc", ".", "Incr", "(", "vb", ",", "k", ",", "amt", ",", "def", ",", "exp", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "rv", "=", "res", "\n", "return", "nil", "\n", "}", ")", "\n", "return", "rv", ",", "err", "\n", "}" ]
// Incr increments the value at a given key by amt and defaults to def if no value present.
[ "Incr", "increments", "the", "value", "at", "a", "given", "key", "by", "amt", "and", "defaults", "to", "def", "if", "no", "value", "present", "." ]
6aeabeae85e5645306382779e3ee55a330ec558c
https://github.com/couchbase/go-couchbase/blob/6aeabeae85e5645306382779e3ee55a330ec558c/client.go#L1239-L1254
146,309
couchbase/go-couchbase
client.go
update
func (b *Bucket) update(k string, exp int, callback UpdateFunc) (newCas uint64, err error) { var state memcached.CASState for b.casNext(k, exp, &state) { var err error if state.Value, err = callback(state.Value); err != nil { return 0, err } } return state.Cas, state.Err }
go
func (b *Bucket) update(k string, exp int, callback UpdateFunc) (newCas uint64, err error) { var state memcached.CASState for b.casNext(k, exp, &state) { var err error if state.Value, err = callback(state.Value); err != nil { return 0, err } } return state.Cas, state.Err }
[ "func", "(", "b", "*", "Bucket", ")", "update", "(", "k", "string", ",", "exp", "int", ",", "callback", "UpdateFunc", ")", "(", "newCas", "uint64", ",", "err", "error", ")", "{", "var", "state", "memcached", ".", "CASState", "\n", "for", "b", ".", "casNext", "(", "k", ",", "exp", ",", "&", "state", ")", "{", "var", "err", "error", "\n", "if", "state", ".", "Value", ",", "err", "=", "callback", "(", "state", ".", "Value", ")", ";", "err", "!=", "nil", "{", "return", "0", ",", "err", "\n", "}", "\n", "}", "\n", "return", "state", ".", "Cas", ",", "state", ".", "Err", "\n", "}" ]
// internal version of Update that returns a CAS value
[ "internal", "version", "of", "Update", "that", "returns", "a", "CAS", "value" ]
6aeabeae85e5645306382779e3ee55a330ec558c
https://github.com/couchbase/go-couchbase/blob/6aeabeae85e5645306382779e3ee55a330ec558c/client.go#L1313-L1322
146,310
couchbase/go-couchbase
client.go
Observe
func (b *Bucket) Observe(k string) (result memcached.ObserveResult, err error) { if ClientOpCallback != nil { defer func(t time.Time) { ClientOpCallback("Observe", k, t, err) }(time.Now()) } err = b.Do(k, func(mc *memcached.Client, vb uint16) error { result, err = mc.Observe(vb, k) return err }) return }
go
func (b *Bucket) Observe(k string) (result memcached.ObserveResult, err error) { if ClientOpCallback != nil { defer func(t time.Time) { ClientOpCallback("Observe", k, t, err) }(time.Now()) } err = b.Do(k, func(mc *memcached.Client, vb uint16) error { result, err = mc.Observe(vb, k) return err }) return }
[ "func", "(", "b", "*", "Bucket", ")", "Observe", "(", "k", "string", ")", "(", "result", "memcached", ".", "ObserveResult", ",", "err", "error", ")", "{", "if", "ClientOpCallback", "!=", "nil", "{", "defer", "func", "(", "t", "time", ".", "Time", ")", "{", "ClientOpCallback", "(", "\"", "\"", ",", "k", ",", "t", ",", "err", ")", "}", "(", "time", ".", "Now", "(", ")", ")", "\n", "}", "\n\n", "err", "=", "b", ".", "Do", "(", "k", ",", "func", "(", "mc", "*", "memcached", ".", "Client", ",", "vb", "uint16", ")", "error", "{", "result", ",", "err", "=", "mc", ".", "Observe", "(", "vb", ",", "k", ")", "\n", "return", "err", "\n", "}", ")", "\n", "return", "\n", "}" ]
// Observe observes the current state of a document.
[ "Observe", "observes", "the", "current", "state", "of", "a", "document", "." ]
6aeabeae85e5645306382779e3ee55a330ec558c
https://github.com/couchbase/go-couchbase/blob/6aeabeae85e5645306382779e3ee55a330ec558c/client.go#L1355-L1365
146,311
couchbase/go-couchbase
client.go
WaitForPersistence
func (b *Bucket) WaitForPersistence(k string, cas uint64, deletion bool) error { timeout := 10 * time.Second sleepDelay := 5 * time.Millisecond start := time.Now() for { time.Sleep(sleepDelay) sleepDelay += sleepDelay / 2 // multiply delay by 1.5 every time result, err := b.Observe(k) if err != nil { return err } if persisted, overwritten := result.CheckPersistence(cas, deletion); overwritten { return ErrOverwritten } else if persisted { return nil } if result.PersistenceTime > 0 { timeout = 2 * result.PersistenceTime } if time.Since(start) >= timeout-sleepDelay { return ErrTimeout } } }
go
func (b *Bucket) WaitForPersistence(k string, cas uint64, deletion bool) error { timeout := 10 * time.Second sleepDelay := 5 * time.Millisecond start := time.Now() for { time.Sleep(sleepDelay) sleepDelay += sleepDelay / 2 // multiply delay by 1.5 every time result, err := b.Observe(k) if err != nil { return err } if persisted, overwritten := result.CheckPersistence(cas, deletion); overwritten { return ErrOverwritten } else if persisted { return nil } if result.PersistenceTime > 0 { timeout = 2 * result.PersistenceTime } if time.Since(start) >= timeout-sleepDelay { return ErrTimeout } } }
[ "func", "(", "b", "*", "Bucket", ")", "WaitForPersistence", "(", "k", "string", ",", "cas", "uint64", ",", "deletion", "bool", ")", "error", "{", "timeout", ":=", "10", "*", "time", ".", "Second", "\n", "sleepDelay", ":=", "5", "*", "time", ".", "Millisecond", "\n", "start", ":=", "time", ".", "Now", "(", ")", "\n", "for", "{", "time", ".", "Sleep", "(", "sleepDelay", ")", "\n", "sleepDelay", "+=", "sleepDelay", "/", "2", "// multiply delay by 1.5 every time", "\n\n", "result", ",", "err", ":=", "b", ".", "Observe", "(", "k", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "if", "persisted", ",", "overwritten", ":=", "result", ".", "CheckPersistence", "(", "cas", ",", "deletion", ")", ";", "overwritten", "{", "return", "ErrOverwritten", "\n", "}", "else", "if", "persisted", "{", "return", "nil", "\n", "}", "\n\n", "if", "result", ".", "PersistenceTime", ">", "0", "{", "timeout", "=", "2", "*", "result", ".", "PersistenceTime", "\n", "}", "\n", "if", "time", ".", "Since", "(", "start", ")", ">=", "timeout", "-", "sleepDelay", "{", "return", "ErrTimeout", "\n", "}", "\n", "}", "\n", "}" ]
// WaitForPersistence waits for an item to be considered durable. // // Besides transport errors, ErrOverwritten may be returned if the // item is overwritten before it reaches durability. ErrTimeout may // occur if the item isn't found durable in a reasonable amount of // time.
[ "WaitForPersistence", "waits", "for", "an", "item", "to", "be", "considered", "durable", ".", "Besides", "transport", "errors", "ErrOverwritten", "may", "be", "returned", "if", "the", "item", "is", "overwritten", "before", "it", "reaches", "durability", ".", "ErrTimeout", "may", "occur", "if", "the", "item", "isn", "t", "found", "durable", "in", "a", "reasonable", "amount", "of", "time", "." ]
6aeabeae85e5645306382779e3ee55a330ec558c
https://github.com/couchbase/go-couchbase/blob/6aeabeae85e5645306382779e3ee55a330ec558c/client.go#L1381-L1406
146,312
couchbase/go-couchbase
tap.go
StartTapFeed
func (b *Bucket) StartTapFeed(args *memcached.TapArguments) (*TapFeed, error) { if args == nil { defaultArgs := memcached.DefaultTapArguments() args = &defaultArgs } feed := &TapFeed{ bucket: b, args: args, output: make(chan memcached.TapEvent, 10), quit: make(chan bool), } go feed.run() feed.C = feed.output return feed, nil }
go
func (b *Bucket) StartTapFeed(args *memcached.TapArguments) (*TapFeed, error) { if args == nil { defaultArgs := memcached.DefaultTapArguments() args = &defaultArgs } feed := &TapFeed{ bucket: b, args: args, output: make(chan memcached.TapEvent, 10), quit: make(chan bool), } go feed.run() feed.C = feed.output return feed, nil }
[ "func", "(", "b", "*", "Bucket", ")", "StartTapFeed", "(", "args", "*", "memcached", ".", "TapArguments", ")", "(", "*", "TapFeed", ",", "error", ")", "{", "if", "args", "==", "nil", "{", "defaultArgs", ":=", "memcached", ".", "DefaultTapArguments", "(", ")", "\n", "args", "=", "&", "defaultArgs", "\n", "}", "\n\n", "feed", ":=", "&", "TapFeed", "{", "bucket", ":", "b", ",", "args", ":", "args", ",", "output", ":", "make", "(", "chan", "memcached", ".", "TapEvent", ",", "10", ")", ",", "quit", ":", "make", "(", "chan", "bool", ")", ",", "}", "\n\n", "go", "feed", ".", "run", "(", ")", "\n\n", "feed", ".", "C", "=", "feed", ".", "output", "\n", "return", "feed", ",", "nil", "\n", "}" ]
// StartTapFeed creates and starts a new Tap feed
[ "StartTapFeed", "creates", "and", "starts", "a", "new", "Tap", "feed" ]
6aeabeae85e5645306382779e3ee55a330ec558c
https://github.com/couchbase/go-couchbase/blob/6aeabeae85e5645306382779e3ee55a330ec558c/tap.go#L30-L47
146,313
couchbase/go-couchbase
tap.go
forwardTapEvents
func (feed *TapFeed) forwardTapEvents(singleFeed *memcached.TapFeed, killSwitch chan bool, host string) { defer feed.wg.Done() for { select { case event, ok := <-singleFeed.C: if !ok { if singleFeed.Error != nil { logging.Errorf("go-couchbase: Tap feed from %s failed: %v", host, singleFeed.Error) } killSwitch <- true return } feed.output <- event case <-feed.quit: return } } }
go
func (feed *TapFeed) forwardTapEvents(singleFeed *memcached.TapFeed, killSwitch chan bool, host string) { defer feed.wg.Done() for { select { case event, ok := <-singleFeed.C: if !ok { if singleFeed.Error != nil { logging.Errorf("go-couchbase: Tap feed from %s failed: %v", host, singleFeed.Error) } killSwitch <- true return } feed.output <- event case <-feed.quit: return } } }
[ "func", "(", "feed", "*", "TapFeed", ")", "forwardTapEvents", "(", "singleFeed", "*", "memcached", ".", "TapFeed", ",", "killSwitch", "chan", "bool", ",", "host", "string", ")", "{", "defer", "feed", ".", "wg", ".", "Done", "(", ")", "\n", "for", "{", "select", "{", "case", "event", ",", "ok", ":=", "<-", "singleFeed", ".", "C", ":", "if", "!", "ok", "{", "if", "singleFeed", ".", "Error", "!=", "nil", "{", "logging", ".", "Errorf", "(", "\"", "\"", ",", "host", ",", "singleFeed", ".", "Error", ")", "\n", "}", "\n", "killSwitch", "<-", "true", "\n", "return", "\n", "}", "\n", "feed", ".", "output", "<-", "event", "\n", "case", "<-", "feed", ".", "quit", ":", "return", "\n", "}", "\n", "}", "\n", "}" ]
// Goroutine that forwards Tap events from a single node's feed to the aggregate feed.
[ "Goroutine", "that", "forwards", "Tap", "events", "from", "a", "single", "node", "s", "feed", "to", "the", "aggregate", "feed", "." ]
6aeabeae85e5645306382779e3ee55a330ec558c
https://github.com/couchbase/go-couchbase/blob/6aeabeae85e5645306382779e3ee55a330ec558c/tap.go#L104-L121
146,314
couchbase/go-couchbase
tap.go
Close
func (feed *TapFeed) Close() error { select { case <-feed.quit: return nil default: } feed.closeNodeFeeds() close(feed.quit) feed.wg.Wait() close(feed.output) return nil }
go
func (feed *TapFeed) Close() error { select { case <-feed.quit: return nil default: } feed.closeNodeFeeds() close(feed.quit) feed.wg.Wait() close(feed.output) return nil }
[ "func", "(", "feed", "*", "TapFeed", ")", "Close", "(", ")", "error", "{", "select", "{", "case", "<-", "feed", ".", "quit", ":", "return", "nil", "\n", "default", ":", "}", "\n\n", "feed", ".", "closeNodeFeeds", "(", ")", "\n", "close", "(", "feed", ".", "quit", ")", "\n", "feed", ".", "wg", ".", "Wait", "(", ")", "\n", "close", "(", "feed", ".", "output", ")", "\n", "return", "nil", "\n", "}" ]
// Close a Tap feed.
[ "Close", "a", "Tap", "feed", "." ]
6aeabeae85e5645306382779e3ee55a330ec558c
https://github.com/couchbase/go-couchbase/blob/6aeabeae85e5645306382779e3ee55a330ec558c/tap.go#L131-L143
146,315
couchbase/go-couchbase
util/viewmgmt.go
UpdateView
func UpdateView(d *couchbase.Bucket, ddocName, markerKey, ddocBody string, version int) error { marker := ViewMarker{} err := d.Get(markerKey, &marker) if err != nil { log.Printf("Error checking view version: %v", err) } if marker.Version < version { log.Printf("Installing new version of views (old version=%v)", marker.Version) doc := json.RawMessage([]byte(ddocBody)) err = d.PutDDoc(ddocName, &doc) if err != nil { return err } marker.Version = version marker.Timestamp = time.Now().UTC() marker.Type = "viewmarker" return d.Set(markerKey, 0, &marker) } return nil }
go
func UpdateView(d *couchbase.Bucket, ddocName, markerKey, ddocBody string, version int) error { marker := ViewMarker{} err := d.Get(markerKey, &marker) if err != nil { log.Printf("Error checking view version: %v", err) } if marker.Version < version { log.Printf("Installing new version of views (old version=%v)", marker.Version) doc := json.RawMessage([]byte(ddocBody)) err = d.PutDDoc(ddocName, &doc) if err != nil { return err } marker.Version = version marker.Timestamp = time.Now().UTC() marker.Type = "viewmarker" return d.Set(markerKey, 0, &marker) } return nil }
[ "func", "UpdateView", "(", "d", "*", "couchbase", ".", "Bucket", ",", "ddocName", ",", "markerKey", ",", "ddocBody", "string", ",", "version", "int", ")", "error", "{", "marker", ":=", "ViewMarker", "{", "}", "\n", "err", ":=", "d", ".", "Get", "(", "markerKey", ",", "&", "marker", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Printf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "if", "marker", ".", "Version", "<", "version", "{", "log", ".", "Printf", "(", "\"", "\"", ",", "marker", ".", "Version", ")", "\n", "doc", ":=", "json", ".", "RawMessage", "(", "[", "]", "byte", "(", "ddocBody", ")", ")", "\n", "err", "=", "d", ".", "PutDDoc", "(", "ddocName", ",", "&", "doc", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "marker", ".", "Version", "=", "version", "\n", "marker", ".", "Timestamp", "=", "time", ".", "Now", "(", ")", ".", "UTC", "(", ")", "\n", "marker", ".", "Type", "=", "\"", "\"", "\n\n", "return", "d", ".", "Set", "(", "markerKey", ",", "0", ",", "&", "marker", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// UpdateView installs or updates a view. // // This creates a document that tracks the version of design document // in couchbase and updates it if it's behind the version specified. // // A ViewMarker is stored with a type of "viewmarker" under the key // specified by `markerKey` to keep up with the view info.
[ "UpdateView", "installs", "or", "updates", "a", "view", ".", "This", "creates", "a", "document", "that", "tracks", "the", "version", "of", "design", "document", "in", "couchbase", "and", "updates", "it", "if", "it", "s", "behind", "the", "version", "specified", ".", "A", "ViewMarker", "is", "stored", "with", "a", "type", "of", "viewmarker", "under", "the", "key", "specified", "by", "markerKey", "to", "keep", "up", "with", "the", "view", "info", "." ]
6aeabeae85e5645306382779e3ee55a330ec558c
https://github.com/couchbase/go-couchbase/blob/6aeabeae85e5645306382779e3ee55a330ec558c/util/viewmgmt.go#L28-L51
146,316
couchbase/go-couchbase
views.go
ViewURL
func (b *Bucket) ViewURL(ddoc, name string, params map[string]interface{}) (string, error) { u, err := b.randomBaseURL() if err != nil { return "", err } values := url.Values{} for k, v := range params { switch t := v.(type) { case DocID: values[k] = []string{string(t)} case string: values[k] = []string{qParam(k, t)} case int: values[k] = []string{fmt.Sprintf(`%d`, t)} case bool: values[k] = []string{fmt.Sprintf(`%v`, t)} default: b, err := json.Marshal(v) if err != nil { return "", fmt.Errorf("unsupported value-type %T in Query, "+ "json encoder said %v", t, err) } values[k] = []string{fmt.Sprintf(`%v`, string(b))} } } if ddoc == "" && name == "_all_docs" { u.Path = fmt.Sprintf("/%s/_all_docs", b.GetName()) } else { u.Path = fmt.Sprintf("/%s/_design/%s/_view/%s", b.GetName(), ddoc, name) } u.RawQuery = values.Encode() return u.String(), nil }
go
func (b *Bucket) ViewURL(ddoc, name string, params map[string]interface{}) (string, error) { u, err := b.randomBaseURL() if err != nil { return "", err } values := url.Values{} for k, v := range params { switch t := v.(type) { case DocID: values[k] = []string{string(t)} case string: values[k] = []string{qParam(k, t)} case int: values[k] = []string{fmt.Sprintf(`%d`, t)} case bool: values[k] = []string{fmt.Sprintf(`%v`, t)} default: b, err := json.Marshal(v) if err != nil { return "", fmt.Errorf("unsupported value-type %T in Query, "+ "json encoder said %v", t, err) } values[k] = []string{fmt.Sprintf(`%v`, string(b))} } } if ddoc == "" && name == "_all_docs" { u.Path = fmt.Sprintf("/%s/_all_docs", b.GetName()) } else { u.Path = fmt.Sprintf("/%s/_design/%s/_view/%s", b.GetName(), ddoc, name) } u.RawQuery = values.Encode() return u.String(), nil }
[ "func", "(", "b", "*", "Bucket", ")", "ViewURL", "(", "ddoc", ",", "name", "string", ",", "params", "map", "[", "string", "]", "interface", "{", "}", ")", "(", "string", ",", "error", ")", "{", "u", ",", "err", ":=", "b", ".", "randomBaseURL", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "err", "\n", "}", "\n\n", "values", ":=", "url", ".", "Values", "{", "}", "\n", "for", "k", ",", "v", ":=", "range", "params", "{", "switch", "t", ":=", "v", ".", "(", "type", ")", "{", "case", "DocID", ":", "values", "[", "k", "]", "=", "[", "]", "string", "{", "string", "(", "t", ")", "}", "\n", "case", "string", ":", "values", "[", "k", "]", "=", "[", "]", "string", "{", "qParam", "(", "k", ",", "t", ")", "}", "\n", "case", "int", ":", "values", "[", "k", "]", "=", "[", "]", "string", "{", "fmt", ".", "Sprintf", "(", "`%d`", ",", "t", ")", "}", "\n", "case", "bool", ":", "values", "[", "k", "]", "=", "[", "]", "string", "{", "fmt", ".", "Sprintf", "(", "`%v`", ",", "t", ")", "}", "\n", "default", ":", "b", ",", "err", ":=", "json", ".", "Marshal", "(", "v", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "fmt", ".", "Errorf", "(", "\"", "\"", "+", "\"", "\"", ",", "t", ",", "err", ")", "\n", "}", "\n", "values", "[", "k", "]", "=", "[", "]", "string", "{", "fmt", ".", "Sprintf", "(", "`%v`", ",", "string", "(", "b", ")", ")", "}", "\n", "}", "\n", "}", "\n\n", "if", "ddoc", "==", "\"", "\"", "&&", "name", "==", "\"", "\"", "{", "u", ".", "Path", "=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "b", ".", "GetName", "(", ")", ")", "\n", "}", "else", "{", "u", ".", "Path", "=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "b", ".", "GetName", "(", ")", ",", "ddoc", ",", "name", ")", "\n", "}", "\n", "u", ".", "RawQuery", "=", "values", ".", "Encode", "(", ")", "\n\n", "return", "u", ".", "String", "(", ")", ",", "nil", "\n", "}" ]
// ViewURL constructs a URL for a view with the given ddoc, view name, // and parameters.
[ "ViewURL", "constructs", "a", "URL", "for", "a", "view", "with", "the", "given", "ddoc", "view", "name", "and", "parameters", "." ]
6aeabeae85e5645306382779e3ee55a330ec558c
https://github.com/couchbase/go-couchbase/blob/6aeabeae85e5645306382779e3ee55a330ec558c/views.go#L114-L150
146,317
couchbase/go-couchbase
views.go
ViewCustom
func (b *Bucket) ViewCustom(ddoc, name string, params map[string]interface{}, vres interface{}) (err error) { if SlowServerCallWarningThreshold > 0 { defer slowLog(time.Now(), "call to ViewCustom(%q, %q)", ddoc, name) } if ViewCallback != nil { defer func(t time.Time) { ViewCallback(ddoc, name, t, err) }(time.Now()) } u, err := b.ViewURL(ddoc, name, params) if err != nil { return err } req, err := http.NewRequest("GET", u, nil) if err != nil { return err } ah := b.authHandler(false /* bucket not yet locked */) maybeAddAuth(req, ah) res, err := doHTTPRequest(req) if err != nil { return fmt.Errorf("error starting view req at %v: %v", u, err) } defer res.Body.Close() if res.StatusCode != 200 { bod := make([]byte, 512) l, _ := res.Body.Read(bod) return fmt.Errorf("error executing view req at %v: %v - %s", u, res.Status, bod[:l]) } body, err := ioutil.ReadAll(res.Body) if err := json.Unmarshal(body, vres); err != nil { return nil } return nil }
go
func (b *Bucket) ViewCustom(ddoc, name string, params map[string]interface{}, vres interface{}) (err error) { if SlowServerCallWarningThreshold > 0 { defer slowLog(time.Now(), "call to ViewCustom(%q, %q)", ddoc, name) } if ViewCallback != nil { defer func(t time.Time) { ViewCallback(ddoc, name, t, err) }(time.Now()) } u, err := b.ViewURL(ddoc, name, params) if err != nil { return err } req, err := http.NewRequest("GET", u, nil) if err != nil { return err } ah := b.authHandler(false /* bucket not yet locked */) maybeAddAuth(req, ah) res, err := doHTTPRequest(req) if err != nil { return fmt.Errorf("error starting view req at %v: %v", u, err) } defer res.Body.Close() if res.StatusCode != 200 { bod := make([]byte, 512) l, _ := res.Body.Read(bod) return fmt.Errorf("error executing view req at %v: %v - %s", u, res.Status, bod[:l]) } body, err := ioutil.ReadAll(res.Body) if err := json.Unmarshal(body, vres); err != nil { return nil } return nil }
[ "func", "(", "b", "*", "Bucket", ")", "ViewCustom", "(", "ddoc", ",", "name", "string", ",", "params", "map", "[", "string", "]", "interface", "{", "}", ",", "vres", "interface", "{", "}", ")", "(", "err", "error", ")", "{", "if", "SlowServerCallWarningThreshold", ">", "0", "{", "defer", "slowLog", "(", "time", ".", "Now", "(", ")", ",", "\"", "\"", ",", "ddoc", ",", "name", ")", "\n", "}", "\n\n", "if", "ViewCallback", "!=", "nil", "{", "defer", "func", "(", "t", "time", ".", "Time", ")", "{", "ViewCallback", "(", "ddoc", ",", "name", ",", "t", ",", "err", ")", "}", "(", "time", ".", "Now", "(", ")", ")", "\n", "}", "\n\n", "u", ",", "err", ":=", "b", ".", "ViewURL", "(", "ddoc", ",", "name", ",", "params", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "req", ",", "err", ":=", "http", ".", "NewRequest", "(", "\"", "\"", ",", "u", ",", "nil", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "ah", ":=", "b", ".", "authHandler", "(", "false", "/* bucket not yet locked */", ")", "\n", "maybeAddAuth", "(", "req", ",", "ah", ")", "\n\n", "res", ",", "err", ":=", "doHTTPRequest", "(", "req", ")", "\n", "if", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "u", ",", "err", ")", "\n", "}", "\n", "defer", "res", ".", "Body", ".", "Close", "(", ")", "\n\n", "if", "res", ".", "StatusCode", "!=", "200", "{", "bod", ":=", "make", "(", "[", "]", "byte", ",", "512", ")", "\n", "l", ",", "_", ":=", "res", ".", "Body", ".", "Read", "(", "bod", ")", "\n", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "u", ",", "res", ".", "Status", ",", "bod", "[", ":", "l", "]", ")", "\n", "}", "\n\n", "body", ",", "err", ":=", "ioutil", ".", "ReadAll", "(", "res", ".", "Body", ")", "\n", "if", "err", ":=", "json", ".", "Unmarshal", "(", "body", ",", "vres", ")", ";", "err", "!=", "nil", "{", "return", "nil", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// ViewCustom performs a view request that can map row values to a // custom type. // // See the source to View for an example usage.
[ "ViewCustom", "performs", "a", "view", "request", "that", "can", "map", "row", "values", "to", "a", "custom", "type", ".", "See", "the", "source", "to", "View", "for", "an", "example", "usage", "." ]
6aeabeae85e5645306382779e3ee55a330ec558c
https://github.com/couchbase/go-couchbase/blob/6aeabeae85e5645306382779e3ee55a330ec558c/views.go#L159-L201
146,318
gogs/go-gogs-client
repo.go
ListMyRepos
func (c *Client) ListMyRepos() ([]*Repository, error) { repos := make([]*Repository, 0, 10) return repos, c.getParsedResponse("GET", "/user/repos", nil, nil, &repos) }
go
func (c *Client) ListMyRepos() ([]*Repository, error) { repos := make([]*Repository, 0, 10) return repos, c.getParsedResponse("GET", "/user/repos", nil, nil, &repos) }
[ "func", "(", "c", "*", "Client", ")", "ListMyRepos", "(", ")", "(", "[", "]", "*", "Repository", ",", "error", ")", "{", "repos", ":=", "make", "(", "[", "]", "*", "Repository", ",", "0", ",", "10", ")", "\n", "return", "repos", ",", "c", ".", "getParsedResponse", "(", "\"", "\"", ",", "\"", "\"", ",", "nil", ",", "nil", ",", "&", "repos", ")", "\n", "}" ]
// ListMyRepos lists all repositories for the authenticated user that has access to.
[ "ListMyRepos", "lists", "all", "repositories", "for", "the", "authenticated", "user", "that", "has", "access", "to", "." ]
1cd0db3113de87dbac702b9f1a08d9bd0e7142bb
https://github.com/gogs/go-gogs-client/blob/1cd0db3113de87dbac702b9f1a08d9bd0e7142bb/repo.go#L49-L52
146,319
gogs/go-gogs-client
repo.go
CreateRepo
func (c *Client) CreateRepo(opt CreateRepoOption) (*Repository, error) { body, err := json.Marshal(&opt) if err != nil { return nil, err } repo := new(Repository) return repo, c.getParsedResponse("POST", "/user/repos", jsonHeader, bytes.NewReader(body), repo) }
go
func (c *Client) CreateRepo(opt CreateRepoOption) (*Repository, error) { body, err := json.Marshal(&opt) if err != nil { return nil, err } repo := new(Repository) return repo, c.getParsedResponse("POST", "/user/repos", jsonHeader, bytes.NewReader(body), repo) }
[ "func", "(", "c", "*", "Client", ")", "CreateRepo", "(", "opt", "CreateRepoOption", ")", "(", "*", "Repository", ",", "error", ")", "{", "body", ",", "err", ":=", "json", ".", "Marshal", "(", "&", "opt", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "repo", ":=", "new", "(", "Repository", ")", "\n", "return", "repo", ",", "c", ".", "getParsedResponse", "(", "\"", "\"", ",", "\"", "\"", ",", "jsonHeader", ",", "bytes", ".", "NewReader", "(", "body", ")", ",", "repo", ")", "\n", "}" ]
// CreateRepo creates a repository for authenticated user.
[ "CreateRepo", "creates", "a", "repository", "for", "authenticated", "user", "." ]
1cd0db3113de87dbac702b9f1a08d9bd0e7142bb
https://github.com/gogs/go-gogs-client/blob/1cd0db3113de87dbac702b9f1a08d9bd0e7142bb/repo.go#L75-L82
146,320
gogs/go-gogs-client
repo.go
CreateOrgRepo
func (c *Client) CreateOrgRepo(org string, opt CreateRepoOption) (*Repository, error) { body, err := json.Marshal(&opt) if err != nil { return nil, err } repo := new(Repository) return repo, c.getParsedResponse("POST", fmt.Sprintf("/org/%s/repos", org), jsonHeader, bytes.NewReader(body), repo) }
go
func (c *Client) CreateOrgRepo(org string, opt CreateRepoOption) (*Repository, error) { body, err := json.Marshal(&opt) if err != nil { return nil, err } repo := new(Repository) return repo, c.getParsedResponse("POST", fmt.Sprintf("/org/%s/repos", org), jsonHeader, bytes.NewReader(body), repo) }
[ "func", "(", "c", "*", "Client", ")", "CreateOrgRepo", "(", "org", "string", ",", "opt", "CreateRepoOption", ")", "(", "*", "Repository", ",", "error", ")", "{", "body", ",", "err", ":=", "json", ".", "Marshal", "(", "&", "opt", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "repo", ":=", "new", "(", "Repository", ")", "\n", "return", "repo", ",", "c", ".", "getParsedResponse", "(", "\"", "\"", ",", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "org", ")", ",", "jsonHeader", ",", "bytes", ".", "NewReader", "(", "body", ")", ",", "repo", ")", "\n", "}" ]
// CreateOrgRepo creates an organization repository for authenticated user.
[ "CreateOrgRepo", "creates", "an", "organization", "repository", "for", "authenticated", "user", "." ]
1cd0db3113de87dbac702b9f1a08d9bd0e7142bb
https://github.com/gogs/go-gogs-client/blob/1cd0db3113de87dbac702b9f1a08d9bd0e7142bb/repo.go#L85-L92
146,321
gogs/go-gogs-client
repo.go
GetRepo
func (c *Client) GetRepo(owner, reponame string) (*Repository, error) { repo := new(Repository) return repo, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s", owner, reponame), nil, nil, repo) }
go
func (c *Client) GetRepo(owner, reponame string) (*Repository, error) { repo := new(Repository) return repo, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s", owner, reponame), nil, nil, repo) }
[ "func", "(", "c", "*", "Client", ")", "GetRepo", "(", "owner", ",", "reponame", "string", ")", "(", "*", "Repository", ",", "error", ")", "{", "repo", ":=", "new", "(", "Repository", ")", "\n", "return", "repo", ",", "c", ".", "getParsedResponse", "(", "\"", "\"", ",", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "owner", ",", "reponame", ")", ",", "nil", ",", "nil", ",", "repo", ")", "\n", "}" ]
// GetRepo returns information of a repository of given owner.
[ "GetRepo", "returns", "information", "of", "a", "repository", "of", "given", "owner", "." ]
1cd0db3113de87dbac702b9f1a08d9bd0e7142bb
https://github.com/gogs/go-gogs-client/blob/1cd0db3113de87dbac702b9f1a08d9bd0e7142bb/repo.go#L95-L98
146,322
gogs/go-gogs-client
repo.go
DeleteRepo
func (c *Client) DeleteRepo(owner, repo string) error { _, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s", owner, repo), nil, nil) return err }
go
func (c *Client) DeleteRepo(owner, repo string) error { _, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s", owner, repo), nil, nil) return err }
[ "func", "(", "c", "*", "Client", ")", "DeleteRepo", "(", "owner", ",", "repo", "string", ")", "error", "{", "_", ",", "err", ":=", "c", ".", "getResponse", "(", "\"", "\"", ",", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "owner", ",", "repo", ")", ",", "nil", ",", "nil", ")", "\n", "return", "err", "\n", "}" ]
// DeleteRepo deletes a repository of user or organization.
[ "DeleteRepo", "deletes", "a", "repository", "of", "user", "or", "organization", "." ]
1cd0db3113de87dbac702b9f1a08d9bd0e7142bb
https://github.com/gogs/go-gogs-client/blob/1cd0db3113de87dbac702b9f1a08d9bd0e7142bb/repo.go#L101-L104
146,323
gogs/go-gogs-client
repo.go
EditIssueTracker
func (c *Client) EditIssueTracker(owner, repo string, opt EditIssueTrackerOption) error { body, err := json.Marshal(&opt) if err != nil { return err } _, err = c.getResponse("PATCH", fmt.Sprintf("/repos/%s/%s/issue-tracker", owner, repo), jsonHeader, bytes.NewReader(body)) return err }
go
func (c *Client) EditIssueTracker(owner, repo string, opt EditIssueTrackerOption) error { body, err := json.Marshal(&opt) if err != nil { return err } _, err = c.getResponse("PATCH", fmt.Sprintf("/repos/%s/%s/issue-tracker", owner, repo), jsonHeader, bytes.NewReader(body)) return err }
[ "func", "(", "c", "*", "Client", ")", "EditIssueTracker", "(", "owner", ",", "repo", "string", ",", "opt", "EditIssueTrackerOption", ")", "error", "{", "body", ",", "err", ":=", "json", ".", "Marshal", "(", "&", "opt", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "_", ",", "err", "=", "c", ".", "getResponse", "(", "\"", "\"", ",", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "owner", ",", "repo", ")", ",", "jsonHeader", ",", "bytes", ".", "NewReader", "(", "body", ")", ")", "\n", "return", "err", "\n", "}" ]
// EditIssueTracker updates issue tracker options of the repository.
[ "EditIssueTracker", "updates", "issue", "tracker", "options", "of", "the", "repository", "." ]
1cd0db3113de87dbac702b9f1a08d9bd0e7142bb
https://github.com/gogs/go-gogs-client/blob/1cd0db3113de87dbac702b9f1a08d9bd0e7142bb/repo.go#L140-L147
146,324
gogs/go-gogs-client
issue_comment.go
ListIssueComments
func (c *Client) ListIssueComments(owner, repo string, index int64) ([]*Comment, error) { comments := make([]*Comment, 0, 10) return comments, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/issues/%d/comments", owner, repo, index), nil, nil, &comments) }
go
func (c *Client) ListIssueComments(owner, repo string, index int64) ([]*Comment, error) { comments := make([]*Comment, 0, 10) return comments, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/issues/%d/comments", owner, repo, index), nil, nil, &comments) }
[ "func", "(", "c", "*", "Client", ")", "ListIssueComments", "(", "owner", ",", "repo", "string", ",", "index", "int64", ")", "(", "[", "]", "*", "Comment", ",", "error", ")", "{", "comments", ":=", "make", "(", "[", "]", "*", "Comment", ",", "0", ",", "10", ")", "\n", "return", "comments", ",", "c", ".", "getParsedResponse", "(", "\"", "\"", ",", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "owner", ",", "repo", ",", "index", ")", ",", "nil", ",", "nil", ",", "&", "comments", ")", "\n", "}" ]
// ListIssueComments list comments on an issue.
[ "ListIssueComments", "list", "comments", "on", "an", "issue", "." ]
1cd0db3113de87dbac702b9f1a08d9bd0e7142bb
https://github.com/gogs/go-gogs-client/blob/1cd0db3113de87dbac702b9f1a08d9bd0e7142bb/issue_comment.go#L25-L28
146,325
gogs/go-gogs-client
issue_comment.go
ListRepoIssueComments
func (c *Client) ListRepoIssueComments(owner, repo string) ([]*Comment, error) { comments := make([]*Comment, 0, 10) return comments, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/issues/comments", owner, repo), nil, nil, &comments) }
go
func (c *Client) ListRepoIssueComments(owner, repo string) ([]*Comment, error) { comments := make([]*Comment, 0, 10) return comments, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/issues/comments", owner, repo), nil, nil, &comments) }
[ "func", "(", "c", "*", "Client", ")", "ListRepoIssueComments", "(", "owner", ",", "repo", "string", ")", "(", "[", "]", "*", "Comment", ",", "error", ")", "{", "comments", ":=", "make", "(", "[", "]", "*", "Comment", ",", "0", ",", "10", ")", "\n", "return", "comments", ",", "c", ".", "getParsedResponse", "(", "\"", "\"", ",", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "owner", ",", "repo", ")", ",", "nil", ",", "nil", ",", "&", "comments", ")", "\n", "}" ]
// ListRepoIssueComments list comments for a given repo.
[ "ListRepoIssueComments", "list", "comments", "for", "a", "given", "repo", "." ]
1cd0db3113de87dbac702b9f1a08d9bd0e7142bb
https://github.com/gogs/go-gogs-client/blob/1cd0db3113de87dbac702b9f1a08d9bd0e7142bb/issue_comment.go#L31-L34
146,326
gogs/go-gogs-client
issue_comment.go
CreateIssueComment
func (c *Client) CreateIssueComment(owner, repo string, index int64, opt CreateIssueCommentOption) (*Comment, error) { body, err := json.Marshal(&opt) if err != nil { return nil, err } comment := new(Comment) return comment, c.getParsedResponse("POST", fmt.Sprintf("/repos/%s/%s/issues/%d/comments", owner, repo, index), jsonHeader, bytes.NewReader(body), comment) }
go
func (c *Client) CreateIssueComment(owner, repo string, index int64, opt CreateIssueCommentOption) (*Comment, error) { body, err := json.Marshal(&opt) if err != nil { return nil, err } comment := new(Comment) return comment, c.getParsedResponse("POST", fmt.Sprintf("/repos/%s/%s/issues/%d/comments", owner, repo, index), jsonHeader, bytes.NewReader(body), comment) }
[ "func", "(", "c", "*", "Client", ")", "CreateIssueComment", "(", "owner", ",", "repo", "string", ",", "index", "int64", ",", "opt", "CreateIssueCommentOption", ")", "(", "*", "Comment", ",", "error", ")", "{", "body", ",", "err", ":=", "json", ".", "Marshal", "(", "&", "opt", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "comment", ":=", "new", "(", "Comment", ")", "\n", "return", "comment", ",", "c", ".", "getParsedResponse", "(", "\"", "\"", ",", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "owner", ",", "repo", ",", "index", ")", ",", "jsonHeader", ",", "bytes", ".", "NewReader", "(", "body", ")", ",", "comment", ")", "\n", "}" ]
// CreateIssueComment create comment on an issue.
[ "CreateIssueComment", "create", "comment", "on", "an", "issue", "." ]
1cd0db3113de87dbac702b9f1a08d9bd0e7142bb
https://github.com/gogs/go-gogs-client/blob/1cd0db3113de87dbac702b9f1a08d9bd0e7142bb/issue_comment.go#L42-L49
146,327
gogs/go-gogs-client
issue_comment.go
DeleteIssueComment
func (c *Client) DeleteIssueComment(owner, repo string, index, commentID int64) error { _, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/issues/%d/comments/%d", owner, repo, index, commentID), nil, nil) return err }
go
func (c *Client) DeleteIssueComment(owner, repo string, index, commentID int64) error { _, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/issues/%d/comments/%d", owner, repo, index, commentID), nil, nil) return err }
[ "func", "(", "c", "*", "Client", ")", "DeleteIssueComment", "(", "owner", ",", "repo", "string", ",", "index", ",", "commentID", "int64", ")", "error", "{", "_", ",", "err", ":=", "c", ".", "getResponse", "(", "\"", "\"", ",", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "owner", ",", "repo", ",", "index", ",", "commentID", ")", ",", "nil", ",", "nil", ")", "\n", "return", "err", "\n", "}" ]
// DeleteIssueComment deletes an issue comment.
[ "DeleteIssueComment", "deletes", "an", "issue", "comment", "." ]
1cd0db3113de87dbac702b9f1a08d9bd0e7142bb
https://github.com/gogs/go-gogs-client/blob/1cd0db3113de87dbac702b9f1a08d9bd0e7142bb/issue_comment.go#L67-L70
146,328
gogs/go-gogs-client
repo_hook.go
ParseCreateHook
func ParseCreateHook(raw []byte) (*CreatePayload, error) { hook := new(CreatePayload) if err := json.Unmarshal(raw, hook); err != nil { return nil, err } // it is possible the JSON was parsed, however, // was not from Gogs (maybe was from Bitbucket) // So we'll check to be sure certain key fields // were populated switch { case hook.Repo == nil: return nil, ErrInvalidReceiveHook case len(hook.Ref) == 0: return nil, ErrInvalidReceiveHook } return hook, nil }
go
func ParseCreateHook(raw []byte) (*CreatePayload, error) { hook := new(CreatePayload) if err := json.Unmarshal(raw, hook); err != nil { return nil, err } // it is possible the JSON was parsed, however, // was not from Gogs (maybe was from Bitbucket) // So we'll check to be sure certain key fields // were populated switch { case hook.Repo == nil: return nil, ErrInvalidReceiveHook case len(hook.Ref) == 0: return nil, ErrInvalidReceiveHook } return hook, nil }
[ "func", "ParseCreateHook", "(", "raw", "[", "]", "byte", ")", "(", "*", "CreatePayload", ",", "error", ")", "{", "hook", ":=", "new", "(", "CreatePayload", ")", "\n", "if", "err", ":=", "json", ".", "Unmarshal", "(", "raw", ",", "hook", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "// it is possible the JSON was parsed, however,", "// was not from Gogs (maybe was from Bitbucket)", "// So we'll check to be sure certain key fields", "// were populated", "switch", "{", "case", "hook", ".", "Repo", "==", "nil", ":", "return", "nil", ",", "ErrInvalidReceiveHook", "\n", "case", "len", "(", "hook", ".", "Ref", ")", "==", "0", ":", "return", "nil", ",", "ErrInvalidReceiveHook", "\n", "}", "\n", "return", "hook", ",", "nil", "\n", "}" ]
// ParseCreateHook parses create event hook content.
[ "ParseCreateHook", "parses", "create", "event", "hook", "content", "." ]
1cd0db3113de87dbac702b9f1a08d9bd0e7142bb
https://github.com/gogs/go-gogs-client/blob/1cd0db3113de87dbac702b9f1a08d9bd0e7142bb/repo_hook.go#L127-L144
146,329
gogs/go-gogs-client
repo_hook.go
ParsePushHook
func ParsePushHook(raw []byte) (*PushPayload, error) { hook := new(PushPayload) if err := json.Unmarshal(raw, hook); err != nil { return nil, err } switch { case hook.Repo == nil: return nil, ErrInvalidReceiveHook case len(hook.Ref) == 0: return nil, ErrInvalidReceiveHook } return hook, nil }
go
func ParsePushHook(raw []byte) (*PushPayload, error) { hook := new(PushPayload) if err := json.Unmarshal(raw, hook); err != nil { return nil, err } switch { case hook.Repo == nil: return nil, ErrInvalidReceiveHook case len(hook.Ref) == 0: return nil, ErrInvalidReceiveHook } return hook, nil }
[ "func", "ParsePushHook", "(", "raw", "[", "]", "byte", ")", "(", "*", "PushPayload", ",", "error", ")", "{", "hook", ":=", "new", "(", "PushPayload", ")", "\n", "if", "err", ":=", "json", ".", "Unmarshal", "(", "raw", ",", "hook", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "switch", "{", "case", "hook", ".", "Repo", "==", "nil", ":", "return", "nil", ",", "ErrInvalidReceiveHook", "\n", "case", "len", "(", "hook", ".", "Ref", ")", "==", "0", ":", "return", "nil", ",", "ErrInvalidReceiveHook", "\n", "}", "\n", "return", "hook", ",", "nil", "\n", "}" ]
// ParsePushHook parses push event hook content.
[ "ParsePushHook", "parses", "push", "event", "hook", "content", "." ]
1cd0db3113de87dbac702b9f1a08d9bd0e7142bb
https://github.com/gogs/go-gogs-client/blob/1cd0db3113de87dbac702b9f1a08d9bd0e7142bb/repo_hook.go#L212-L225
146,330
gogs/go-gogs-client
gogs.go
NewClient
func NewClient(url, token string) *Client { return &Client{ url: strings.TrimSuffix(url, "/"), accessToken: token, client: &http.Client{}, } }
go
func NewClient(url, token string) *Client { return &Client{ url: strings.TrimSuffix(url, "/"), accessToken: token, client: &http.Client{}, } }
[ "func", "NewClient", "(", "url", ",", "token", "string", ")", "*", "Client", "{", "return", "&", "Client", "{", "url", ":", "strings", ".", "TrimSuffix", "(", "url", ",", "\"", "\"", ")", ",", "accessToken", ":", "token", ",", "client", ":", "&", "http", ".", "Client", "{", "}", ",", "}", "\n", "}" ]
// NewClient initializes and returns an API client.
[ "NewClient", "initializes", "and", "returns", "an", "API", "client", "." ]
1cd0db3113de87dbac702b9f1a08d9bd0e7142bb
https://github.com/gogs/go-gogs-client/blob/1cd0db3113de87dbac702b9f1a08d9bd0e7142bb/gogs.go#L28-L34
146,331
iron-io/functions
api/models/app.go
UpdateConfig
func (a *App) UpdateConfig(patch Config) { if patch != nil { if a.Config == nil { a.Config = make(Config) } for k, v := range patch { if v == "" { delete(a.Config, k) } else { a.Config[k] = v } } } }
go
func (a *App) UpdateConfig(patch Config) { if patch != nil { if a.Config == nil { a.Config = make(Config) } for k, v := range patch { if v == "" { delete(a.Config, k) } else { a.Config[k] = v } } } }
[ "func", "(", "a", "*", "App", ")", "UpdateConfig", "(", "patch", "Config", ")", "{", "if", "patch", "!=", "nil", "{", "if", "a", ".", "Config", "==", "nil", "{", "a", ".", "Config", "=", "make", "(", "Config", ")", "\n", "}", "\n", "for", "k", ",", "v", ":=", "range", "patch", "{", "if", "v", "==", "\"", "\"", "{", "delete", "(", "a", ".", "Config", ",", "k", ")", "\n", "}", "else", "{", "a", ".", "Config", "[", "k", "]", "=", "v", "\n", "}", "\n", "}", "\n", "}", "\n", "}" ]
// UpdateConfig adds entries from patch to a.Config, and removes entries with empty values.
[ "UpdateConfig", "adds", "entries", "from", "patch", "to", "a", ".", "Config", "and", "removes", "entries", "with", "empty", "values", "." ]
d59d7d1c40b2ff26b1afee31bde64df444e96525
https://github.com/iron-io/functions/blob/d59d7d1c40b2ff26b1afee31bde64df444e96525/api/models/app.go#L74-L87
146,332
iron-io/functions
api/server/singleflight.go
do
func (g *singleflight) do(key models.RouteFilter, fn func() (interface{}, error)) (interface{}, error) { g.mu.Lock() if g.m == nil { g.m = make(map[models.RouteFilter]*call) } if c, ok := g.m[key]; ok { g.mu.Unlock() c.wg.Wait() return c.val, c.err } c := new(call) c.wg.Add(1) g.m[key] = c g.mu.Unlock() c.val, c.err = fn() c.wg.Done() g.mu.Lock() delete(g.m, key) g.mu.Unlock() return c.val, c.err }
go
func (g *singleflight) do(key models.RouteFilter, fn func() (interface{}, error)) (interface{}, error) { g.mu.Lock() if g.m == nil { g.m = make(map[models.RouteFilter]*call) } if c, ok := g.m[key]; ok { g.mu.Unlock() c.wg.Wait() return c.val, c.err } c := new(call) c.wg.Add(1) g.m[key] = c g.mu.Unlock() c.val, c.err = fn() c.wg.Done() g.mu.Lock() delete(g.m, key) g.mu.Unlock() return c.val, c.err }
[ "func", "(", "g", "*", "singleflight", ")", "do", "(", "key", "models", ".", "RouteFilter", ",", "fn", "func", "(", ")", "(", "interface", "{", "}", ",", "error", ")", ")", "(", "interface", "{", "}", ",", "error", ")", "{", "g", ".", "mu", ".", "Lock", "(", ")", "\n", "if", "g", ".", "m", "==", "nil", "{", "g", ".", "m", "=", "make", "(", "map", "[", "models", ".", "RouteFilter", "]", "*", "call", ")", "\n", "}", "\n", "if", "c", ",", "ok", ":=", "g", ".", "m", "[", "key", "]", ";", "ok", "{", "g", ".", "mu", ".", "Unlock", "(", ")", "\n", "c", ".", "wg", ".", "Wait", "(", ")", "\n", "return", "c", ".", "val", ",", "c", ".", "err", "\n", "}", "\n", "c", ":=", "new", "(", "call", ")", "\n", "c", ".", "wg", ".", "Add", "(", "1", ")", "\n", "g", ".", "m", "[", "key", "]", "=", "c", "\n", "g", ".", "mu", ".", "Unlock", "(", ")", "\n\n", "c", ".", "val", ",", "c", ".", "err", "=", "fn", "(", ")", "\n", "c", ".", "wg", ".", "Done", "(", ")", "\n\n", "g", ".", "mu", ".", "Lock", "(", ")", "\n", "delete", "(", "g", ".", "m", ",", "key", ")", "\n", "g", ".", "mu", ".", "Unlock", "(", ")", "\n\n", "return", "c", ".", "val", ",", "c", ".", "err", "\n", "}" ]
// do executes and returns the results of the given function, making // sure that only one execution is in-flight for a given key at a // time. If a duplicate comes in, the duplicate caller waits for the // original to complete and receives the same results.
[ "do", "executes", "and", "returns", "the", "results", "of", "the", "given", "function", "making", "sure", "that", "only", "one", "execution", "is", "in", "-", "flight", "for", "a", "given", "key", "at", "a", "time", ".", "If", "a", "duplicate", "comes", "in", "the", "duplicate", "caller", "waits", "for", "the", "original", "to", "complete", "and", "receives", "the", "same", "results", "." ]
d59d7d1c40b2ff26b1afee31bde64df444e96525
https://github.com/iron-io/functions/blob/d59d7d1c40b2ff26b1afee31bde64df444e96525/api/server/singleflight.go#L27-L50
146,333
iron-io/functions
lb/roundtripper.go
NewRoundTripper
func NewRoundTripper(ctx context.Context, nodes []string) *FallbackRoundTripper { frt := &FallbackRoundTripper{ nodes: nodes, fallback: make(map[string]string), } go frt.checkHealth(ctx) return frt }
go
func NewRoundTripper(ctx context.Context, nodes []string) *FallbackRoundTripper { frt := &FallbackRoundTripper{ nodes: nodes, fallback: make(map[string]string), } go frt.checkHealth(ctx) return frt }
[ "func", "NewRoundTripper", "(", "ctx", "context", ".", "Context", ",", "nodes", "[", "]", "string", ")", "*", "FallbackRoundTripper", "{", "frt", ":=", "&", "FallbackRoundTripper", "{", "nodes", ":", "nodes", ",", "fallback", ":", "make", "(", "map", "[", "string", "]", "string", ")", ",", "}", "\n", "go", "frt", ".", "checkHealth", "(", "ctx", ")", "\n", "return", "frt", "\n", "}" ]
// NewRoundTripper creates a new FallbackRoundTripper and triggers the internal // host TCP health checks.
[ "NewRoundTripper", "creates", "a", "new", "FallbackRoundTripper", "and", "triggers", "the", "internal", "host", "TCP", "health", "checks", "." ]
d59d7d1c40b2ff26b1afee31bde64df444e96525
https://github.com/iron-io/functions/blob/d59d7d1c40b2ff26b1afee31bde64df444e96525/lb/roundtripper.go#L36-L43
146,334
iron-io/functions
api/models/new_task.go
Validate
func (m *NewTask) Validate(formats strfmt.Registry) error { var res []error if err := m.validateImage(formats); err != nil { // prop res = append(res, err) } if err := m.validatePriority(formats); err != nil { // prop res = append(res, err) } if len(res) > 0 { return errors.CompositeValidationError(res...) } return nil }
go
func (m *NewTask) Validate(formats strfmt.Registry) error { var res []error if err := m.validateImage(formats); err != nil { // prop res = append(res, err) } if err := m.validatePriority(formats); err != nil { // prop res = append(res, err) } if len(res) > 0 { return errors.CompositeValidationError(res...) } return nil }
[ "func", "(", "m", "*", "NewTask", ")", "Validate", "(", "formats", "strfmt", ".", "Registry", ")", "error", "{", "var", "res", "[", "]", "error", "\n\n", "if", "err", ":=", "m", ".", "validateImage", "(", "formats", ")", ";", "err", "!=", "nil", "{", "// prop", "res", "=", "append", "(", "res", ",", "err", ")", "\n", "}", "\n\n", "if", "err", ":=", "m", ".", "validatePriority", "(", "formats", ")", ";", "err", "!=", "nil", "{", "// prop", "res", "=", "append", "(", "res", ",", "err", ")", "\n", "}", "\n\n", "if", "len", "(", "res", ")", ">", "0", "{", "return", "errors", ".", "CompositeValidationError", "(", "res", "...", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Validate validates this new task
[ "Validate", "validates", "this", "new", "task" ]
d59d7d1c40b2ff26b1afee31bde64df444e96525
https://github.com/iron-io/functions/blob/d59d7d1c40b2ff26b1afee31bde64df444e96525/api/models/new_task.go#L65-L82
146,335
iron-io/functions
fn/commands/images/build.go
Build
func (b *Buildcmd) Build(c *cli.Context) error { verbwriter := common.Verbwriter(b.Verbose) path, err := os.Getwd() if err != nil { return err } fn, err := common.FindFuncfile(path) if err != nil { return err } fmt.Fprintln(verbwriter, "building", fn) ff, err := common.Buildfunc(verbwriter, fn) if err != nil { return err } fmt.Printf("Function %v built successfully.\n", ff.FullName()) return nil }
go
func (b *Buildcmd) Build(c *cli.Context) error { verbwriter := common.Verbwriter(b.Verbose) path, err := os.Getwd() if err != nil { return err } fn, err := common.FindFuncfile(path) if err != nil { return err } fmt.Fprintln(verbwriter, "building", fn) ff, err := common.Buildfunc(verbwriter, fn) if err != nil { return err } fmt.Printf("Function %v built successfully.\n", ff.FullName()) return nil }
[ "func", "(", "b", "*", "Buildcmd", ")", "Build", "(", "c", "*", "cli", ".", "Context", ")", "error", "{", "verbwriter", ":=", "common", ".", "Verbwriter", "(", "b", ".", "Verbose", ")", "\n\n", "path", ",", "err", ":=", "os", ".", "Getwd", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "fn", ",", "err", ":=", "common", ".", "FindFuncfile", "(", "path", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "fmt", ".", "Fprintln", "(", "verbwriter", ",", "\"", "\"", ",", "fn", ")", "\n", "ff", ",", "err", ":=", "common", ".", "Buildfunc", "(", "verbwriter", ",", "fn", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "fmt", ".", "Printf", "(", "\"", "\\n", "\"", ",", "ff", ".", "FullName", "(", ")", ")", "\n", "return", "nil", "\n", "}" ]
// build will take the found valid function and build it
[ "build", "will", "take", "the", "found", "valid", "function", "and", "build", "it" ]
d59d7d1c40b2ff26b1afee31bde64df444e96525
https://github.com/iron-io/functions/blob/d59d7d1c40b2ff26b1afee31bde64df444e96525/fn/commands/images/build.go#L37-L57
146,336
iron-io/functions
api/mqs/new.go
New
func New(mqURL string) (models.MessageQueue, error) { // Play with URL schemes here: https://play.golang.org/p/xWAf9SpCBW u, err := url.Parse(mqURL) if err != nil { logrus.WithError(err).WithFields(logrus.Fields{"url": mqURL}).Fatal("bad MQ URL") } logrus.WithFields(logrus.Fields{"mq": u.Scheme}).Debug("selecting MQ") switch u.Scheme { case "memory": return NewMemoryMQ(), nil case "redis": return NewRedisMQ(u) case "bolt": return NewBoltMQ(u) } if strings.HasPrefix(u.Scheme, "ironmq") { return NewIronMQ(u), nil } return nil, fmt.Errorf("mq type not supported %v", u.Scheme) }
go
func New(mqURL string) (models.MessageQueue, error) { // Play with URL schemes here: https://play.golang.org/p/xWAf9SpCBW u, err := url.Parse(mqURL) if err != nil { logrus.WithError(err).WithFields(logrus.Fields{"url": mqURL}).Fatal("bad MQ URL") } logrus.WithFields(logrus.Fields{"mq": u.Scheme}).Debug("selecting MQ") switch u.Scheme { case "memory": return NewMemoryMQ(), nil case "redis": return NewRedisMQ(u) case "bolt": return NewBoltMQ(u) } if strings.HasPrefix(u.Scheme, "ironmq") { return NewIronMQ(u), nil } return nil, fmt.Errorf("mq type not supported %v", u.Scheme) }
[ "func", "New", "(", "mqURL", "string", ")", "(", "models", ".", "MessageQueue", ",", "error", ")", "{", "// Play with URL schemes here: https://play.golang.org/p/xWAf9SpCBW", "u", ",", "err", ":=", "url", ".", "Parse", "(", "mqURL", ")", "\n", "if", "err", "!=", "nil", "{", "logrus", ".", "WithError", "(", "err", ")", ".", "WithFields", "(", "logrus", ".", "Fields", "{", "\"", "\"", ":", "mqURL", "}", ")", ".", "Fatal", "(", "\"", "\"", ")", "\n", "}", "\n", "logrus", ".", "WithFields", "(", "logrus", ".", "Fields", "{", "\"", "\"", ":", "u", ".", "Scheme", "}", ")", ".", "Debug", "(", "\"", "\"", ")", "\n", "switch", "u", ".", "Scheme", "{", "case", "\"", "\"", ":", "return", "NewMemoryMQ", "(", ")", ",", "nil", "\n", "case", "\"", "\"", ":", "return", "NewRedisMQ", "(", "u", ")", "\n", "case", "\"", "\"", ":", "return", "NewBoltMQ", "(", "u", ")", "\n", "}", "\n", "if", "strings", ".", "HasPrefix", "(", "u", ".", "Scheme", ",", "\"", "\"", ")", "{", "return", "NewIronMQ", "(", "u", ")", ",", "nil", "\n", "}", "\n\n", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "u", ".", "Scheme", ")", "\n", "}" ]
// New will parse the URL and return the correct MQ implementation.
[ "New", "will", "parse", "the", "URL", "and", "return", "the", "correct", "MQ", "implementation", "." ]
d59d7d1c40b2ff26b1afee31bde64df444e96525
https://github.com/iron-io/functions/blob/d59d7d1c40b2ff26b1afee31bde64df444e96525/api/mqs/new.go#L13-L33
146,337
iron-io/functions
api/runner/worker.go
StartWorkers
func StartWorkers(ctx context.Context, rnr *Runner, tasks <-chan task.Request) { var wg sync.WaitGroup defer wg.Wait() var hcmgr htfnmgr for { select { case <-ctx.Done(): return case task := <-tasks: p := hcmgr.getPipe(ctx, rnr, task.Config) if p == nil { wg.Add(1) go runTaskReq(rnr, &wg, task) continue } rnr.Start() select { case <-ctx.Done(): return case p <- task: rnr.Complete() } } } }
go
func StartWorkers(ctx context.Context, rnr *Runner, tasks <-chan task.Request) { var wg sync.WaitGroup defer wg.Wait() var hcmgr htfnmgr for { select { case <-ctx.Done(): return case task := <-tasks: p := hcmgr.getPipe(ctx, rnr, task.Config) if p == nil { wg.Add(1) go runTaskReq(rnr, &wg, task) continue } rnr.Start() select { case <-ctx.Done(): return case p <- task: rnr.Complete() } } } }
[ "func", "StartWorkers", "(", "ctx", "context", ".", "Context", ",", "rnr", "*", "Runner", ",", "tasks", "<-", "chan", "task", ".", "Request", ")", "{", "var", "wg", "sync", ".", "WaitGroup", "\n", "defer", "wg", ".", "Wait", "(", ")", "\n", "var", "hcmgr", "htfnmgr", "\n\n", "for", "{", "select", "{", "case", "<-", "ctx", ".", "Done", "(", ")", ":", "return", "\n", "case", "task", ":=", "<-", "tasks", ":", "p", ":=", "hcmgr", ".", "getPipe", "(", "ctx", ",", "rnr", ",", "task", ".", "Config", ")", "\n", "if", "p", "==", "nil", "{", "wg", ".", "Add", "(", "1", ")", "\n", "go", "runTaskReq", "(", "rnr", ",", "&", "wg", ",", "task", ")", "\n", "continue", "\n", "}", "\n\n", "rnr", ".", "Start", "(", ")", "\n", "select", "{", "case", "<-", "ctx", ".", "Done", "(", ")", ":", "return", "\n", "case", "p", "<-", "task", ":", "rnr", ".", "Complete", "(", ")", "\n", "}", "\n", "}", "\n", "}", "\n", "}" ]
// StartWorkers operates the common concurrency stream, ie, it will process all // IronFunctions tasks, either sync or async. In the process, it also dispatches // the workload to either regular or hot functions.
[ "StartWorkers", "operates", "the", "common", "concurrency", "stream", "ie", "it", "will", "process", "all", "IronFunctions", "tasks", "either", "sync", "or", "async", ".", "In", "the", "process", "it", "also", "dispatches", "the", "workload", "to", "either", "regular", "or", "hot", "functions", "." ]
d59d7d1c40b2ff26b1afee31bde64df444e96525
https://github.com/iron-io/functions/blob/d59d7d1c40b2ff26b1afee31bde64df444e96525/api/runner/worker.go#L77-L103
146,338
iron-io/functions
api/server/runner_listeners.go
AddRunnerListener
func (s *Server) AddRunnerListener(listener RunnerListener) { s.runnerListeners = append(s.runnerListeners, listener) }
go
func (s *Server) AddRunnerListener(listener RunnerListener) { s.runnerListeners = append(s.runnerListeners, listener) }
[ "func", "(", "s", "*", "Server", ")", "AddRunnerListener", "(", "listener", "RunnerListener", ")", "{", "s", ".", "runnerListeners", "=", "append", "(", "s", ".", "runnerListeners", ",", "listener", ")", "\n", "}" ]
// AddRunListeners adds a listener that will be fired before and after a function run.
[ "AddRunListeners", "adds", "a", "listener", "that", "will", "be", "fired", "before", "and", "after", "a", "function", "run", "." ]
d59d7d1c40b2ff26b1afee31bde64df444e96525
https://github.com/iron-io/functions/blob/d59d7d1c40b2ff26b1afee31bde64df444e96525/api/server/runner_listeners.go#L16-L18
146,339
iron-io/functions
api/runner/async_runner.go
RunAsyncRunner
func RunAsyncRunner(ctx context.Context, tasksrv string, tasks chan task.Request, rnr *Runner) { u := tasksrvURL(tasksrv) startAsyncRunners(ctx, u, tasks, rnr) <-ctx.Done() }
go
func RunAsyncRunner(ctx context.Context, tasksrv string, tasks chan task.Request, rnr *Runner) { u := tasksrvURL(tasksrv) startAsyncRunners(ctx, u, tasks, rnr) <-ctx.Done() }
[ "func", "RunAsyncRunner", "(", "ctx", "context", ".", "Context", ",", "tasksrv", "string", ",", "tasks", "chan", "task", ".", "Request", ",", "rnr", "*", "Runner", ")", "{", "u", ":=", "tasksrvURL", "(", "tasksrv", ")", "\n\n", "startAsyncRunners", "(", "ctx", ",", "u", ",", "tasks", ",", "rnr", ")", "\n", "<-", "ctx", ".", "Done", "(", ")", "\n", "}" ]
// RunAsyncRunner pulls tasks off a queue and processes them
[ "RunAsyncRunner", "pulls", "tasks", "off", "a", "queue", "and", "processes", "them" ]
d59d7d1c40b2ff26b1afee31bde64df444e96525
https://github.com/iron-io/functions/blob/d59d7d1c40b2ff26b1afee31bde64df444e96525/api/runner/async_runner.go#L92-L97
146,340
iron-io/functions
api/server/server.go
NewFromEnv
func NewFromEnv(ctx context.Context) *Server { ds, err := datastore.New(viper.GetString(EnvDBURL)) if err != nil { logrus.WithError(err).Fatalln("Error initializing datastore.") } mq, err := mqs.New(viper.GetString(EnvMQURL)) if err != nil { logrus.WithError(err).Fatal("Error initializing message queue.") } apiURL := viper.GetString(EnvAPIURL) return New(ctx, ds, mq, apiURL) }
go
func NewFromEnv(ctx context.Context) *Server { ds, err := datastore.New(viper.GetString(EnvDBURL)) if err != nil { logrus.WithError(err).Fatalln("Error initializing datastore.") } mq, err := mqs.New(viper.GetString(EnvMQURL)) if err != nil { logrus.WithError(err).Fatal("Error initializing message queue.") } apiURL := viper.GetString(EnvAPIURL) return New(ctx, ds, mq, apiURL) }
[ "func", "NewFromEnv", "(", "ctx", "context", ".", "Context", ")", "*", "Server", "{", "ds", ",", "err", ":=", "datastore", ".", "New", "(", "viper", ".", "GetString", "(", "EnvDBURL", ")", ")", "\n", "if", "err", "!=", "nil", "{", "logrus", ".", "WithError", "(", "err", ")", ".", "Fatalln", "(", "\"", "\"", ")", "\n", "}", "\n\n", "mq", ",", "err", ":=", "mqs", ".", "New", "(", "viper", ".", "GetString", "(", "EnvMQURL", ")", ")", "\n", "if", "err", "!=", "nil", "{", "logrus", ".", "WithError", "(", "err", ")", ".", "Fatal", "(", "\"", "\"", ")", "\n", "}", "\n\n", "apiURL", ":=", "viper", ".", "GetString", "(", "EnvAPIURL", ")", "\n\n", "return", "New", "(", "ctx", ",", "ds", ",", "mq", ",", "apiURL", ")", "\n", "}" ]
// NewFromEnv creates a new IronFunctions server based on env vars.
[ "NewFromEnv", "creates", "a", "new", "IronFunctions", "server", "based", "on", "env", "vars", "." ]
d59d7d1c40b2ff26b1afee31bde64df444e96525
https://github.com/iron-io/functions/blob/d59d7d1c40b2ff26b1afee31bde64df444e96525/api/server/server.go#L59-L73
146,341
iron-io/functions
api/server/server.go
New
func New(ctx context.Context, ds models.Datastore, mq models.MessageQueue, apiURL string, opts ...ServerOption) *Server { metricLogger := runner.NewMetricLogger() funcLogger := runner.NewFuncLogger() rnr, err := runner.New(ctx, funcLogger, metricLogger) if err != nil { logrus.WithError(err).Fatalln("Failed to create a runner") return nil } tasks := make(chan task.Request) s := &Server{ Runner: rnr, Router: gin.New(), Datastore: ds, MQ: mq, hotroutes: routecache.New(cacheSize), tasks: tasks, Enqueue: DefaultEnqueue, apiURL: apiURL, } s.Router.Use(prepareMiddleware(ctx)) s.bindHandlers(ctx) s.setupMiddlewares() for _, opt := range opts { opt(s) } return s }
go
func New(ctx context.Context, ds models.Datastore, mq models.MessageQueue, apiURL string, opts ...ServerOption) *Server { metricLogger := runner.NewMetricLogger() funcLogger := runner.NewFuncLogger() rnr, err := runner.New(ctx, funcLogger, metricLogger) if err != nil { logrus.WithError(err).Fatalln("Failed to create a runner") return nil } tasks := make(chan task.Request) s := &Server{ Runner: rnr, Router: gin.New(), Datastore: ds, MQ: mq, hotroutes: routecache.New(cacheSize), tasks: tasks, Enqueue: DefaultEnqueue, apiURL: apiURL, } s.Router.Use(prepareMiddleware(ctx)) s.bindHandlers(ctx) s.setupMiddlewares() for _, opt := range opts { opt(s) } return s }
[ "func", "New", "(", "ctx", "context", ".", "Context", ",", "ds", "models", ".", "Datastore", ",", "mq", "models", ".", "MessageQueue", ",", "apiURL", "string", ",", "opts", "...", "ServerOption", ")", "*", "Server", "{", "metricLogger", ":=", "runner", ".", "NewMetricLogger", "(", ")", "\n", "funcLogger", ":=", "runner", ".", "NewFuncLogger", "(", ")", "\n\n", "rnr", ",", "err", ":=", "runner", ".", "New", "(", "ctx", ",", "funcLogger", ",", "metricLogger", ")", "\n", "if", "err", "!=", "nil", "{", "logrus", ".", "WithError", "(", "err", ")", ".", "Fatalln", "(", "\"", "\"", ")", "\n", "return", "nil", "\n", "}", "\n\n", "tasks", ":=", "make", "(", "chan", "task", ".", "Request", ")", "\n", "s", ":=", "&", "Server", "{", "Runner", ":", "rnr", ",", "Router", ":", "gin", ".", "New", "(", ")", ",", "Datastore", ":", "ds", ",", "MQ", ":", "mq", ",", "hotroutes", ":", "routecache", ".", "New", "(", "cacheSize", ")", ",", "tasks", ":", "tasks", ",", "Enqueue", ":", "DefaultEnqueue", ",", "apiURL", ":", "apiURL", ",", "}", "\n\n", "s", ".", "Router", ".", "Use", "(", "prepareMiddleware", "(", "ctx", ")", ")", "\n", "s", ".", "bindHandlers", "(", "ctx", ")", "\n", "s", ".", "setupMiddlewares", "(", ")", "\n\n", "for", "_", ",", "opt", ":=", "range", "opts", "{", "opt", "(", "s", ")", "\n", "}", "\n", "return", "s", "\n", "}" ]
// New creates a new IronFunctions server with the passed in datastore, message queue and API URL
[ "New", "creates", "a", "new", "IronFunctions", "server", "with", "the", "passed", "in", "datastore", "message", "queue", "and", "API", "URL" ]
d59d7d1c40b2ff26b1afee31bde64df444e96525
https://github.com/iron-io/functions/blob/d59d7d1c40b2ff26b1afee31bde64df444e96525/api/server/server.go#L76-L106
146,342
iron-io/functions
api/models/id_status.go
Validate
func (m *IDStatus) Validate(formats strfmt.Registry) error { var res []error if err := m.validateStatus(formats); err != nil { // prop res = append(res, err) } if len(res) > 0 { return errors.CompositeValidationError(res...) } return nil }
go
func (m *IDStatus) Validate(formats strfmt.Registry) error { var res []error if err := m.validateStatus(formats); err != nil { // prop res = append(res, err) } if len(res) > 0 { return errors.CompositeValidationError(res...) } return nil }
[ "func", "(", "m", "*", "IDStatus", ")", "Validate", "(", "formats", "strfmt", ".", "Registry", ")", "error", "{", "var", "res", "[", "]", "error", "\n\n", "if", "err", ":=", "m", ".", "validateStatus", "(", "formats", ")", ";", "err", "!=", "nil", "{", "// prop", "res", "=", "append", "(", "res", ",", "err", ")", "\n", "}", "\n\n", "if", "len", "(", "res", ")", ">", "0", "{", "return", "errors", ".", "CompositeValidationError", "(", "res", "...", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Validate validates this Id status
[ "Validate", "validates", "this", "Id", "status" ]
d59d7d1c40b2ff26b1afee31bde64df444e96525
https://github.com/iron-io/functions/blob/d59d7d1c40b2ff26b1afee31bde64df444e96525/api/models/id_status.go#L70-L82
146,343
iron-io/functions
api/mqs/memory.go
pickEarliestNonblocking
func pickEarliestNonblocking(channels ...chan *models.Task) *models.Task { if len(channels) == 0 { return nil } select { case job := <-channels[0]: return job default: return pickEarliestNonblocking(channels[1:]...) } }
go
func pickEarliestNonblocking(channels ...chan *models.Task) *models.Task { if len(channels) == 0 { return nil } select { case job := <-channels[0]: return job default: return pickEarliestNonblocking(channels[1:]...) } }
[ "func", "pickEarliestNonblocking", "(", "channels", "...", "chan", "*", "models", ".", "Task", ")", "*", "models", ".", "Task", "{", "if", "len", "(", "channels", ")", "==", "0", "{", "return", "nil", "\n", "}", "\n\n", "select", "{", "case", "job", ":=", "<-", "channels", "[", "0", "]", ":", "return", "job", "\n", "default", ":", "return", "pickEarliestNonblocking", "(", "channels", "[", "1", ":", "]", "...", ")", "\n", "}", "\n", "}" ]
// This is recursive, so be careful how many channels you pass in.
[ "This", "is", "recursive", "so", "be", "careful", "how", "many", "channels", "you", "pass", "in", "." ]
d59d7d1c40b2ff26b1afee31bde64df444e96525
https://github.com/iron-io/functions/blob/d59d7d1c40b2ff26b1afee31bde64df444e96525/api/mqs/memory.go#L157-L168
146,344
iron-io/functions
fn/commands/images/bump.go
bump
func (b *bumpcmd) bump(c *cli.Context) error { verbwriter := common.Verbwriter(b.verbose) path, err := os.Getwd() if err != nil { return err } fn, err := common.FindFuncfile(path) if err != nil { return err } fmt.Fprintln(verbwriter, "bumping version for", fn) funcfile, err := common.ParseFuncfile(fn) if err != nil { return err } err = funcfile.Bumpversion() if err != nil { return err } if err := common.StoreFuncfile(fn, funcfile); err != nil { return err } fmt.Println("Bumped to version", funcfile.Version) return nil }
go
func (b *bumpcmd) bump(c *cli.Context) error { verbwriter := common.Verbwriter(b.verbose) path, err := os.Getwd() if err != nil { return err } fn, err := common.FindFuncfile(path) if err != nil { return err } fmt.Fprintln(verbwriter, "bumping version for", fn) funcfile, err := common.ParseFuncfile(fn) if err != nil { return err } err = funcfile.Bumpversion() if err != nil { return err } if err := common.StoreFuncfile(fn, funcfile); err != nil { return err } fmt.Println("Bumped to version", funcfile.Version) return nil }
[ "func", "(", "b", "*", "bumpcmd", ")", "bump", "(", "c", "*", "cli", ".", "Context", ")", "error", "{", "verbwriter", ":=", "common", ".", "Verbwriter", "(", "b", ".", "verbose", ")", "\n\n", "path", ",", "err", ":=", "os", ".", "Getwd", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "fn", ",", "err", ":=", "common", ".", "FindFuncfile", "(", "path", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "fmt", ".", "Fprintln", "(", "verbwriter", ",", "\"", "\"", ",", "fn", ")", "\n\n", "funcfile", ",", "err", ":=", "common", ".", "ParseFuncfile", "(", "fn", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "err", "=", "funcfile", ".", "Bumpversion", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "if", "err", ":=", "common", ".", "StoreFuncfile", "(", "fn", ",", "funcfile", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "fmt", ".", "Println", "(", "\"", "\"", ",", "funcfile", ".", "Version", ")", "\n", "return", "nil", "\n", "}" ]
// bump will take the found valid function and bump its version
[ "bump", "will", "take", "the", "found", "valid", "function", "and", "bump", "its", "version" ]
d59d7d1c40b2ff26b1afee31bde64df444e96525
https://github.com/iron-io/functions/blob/d59d7d1c40b2ff26b1afee31bde64df444e96525/fn/commands/images/bump.go#L40-L70
146,345
iron-io/functions
api/models/reason.go
Validate
func (m Reason) Validate(formats strfmt.Registry) error { var res []error // value enum if err := m.validateReasonEnum("", "body", m); err != nil { return err } if len(res) > 0 { return errors.CompositeValidationError(res...) } return nil }
go
func (m Reason) Validate(formats strfmt.Registry) error { var res []error // value enum if err := m.validateReasonEnum("", "body", m); err != nil { return err } if len(res) > 0 { return errors.CompositeValidationError(res...) } return nil }
[ "func", "(", "m", "Reason", ")", "Validate", "(", "formats", "strfmt", ".", "Registry", ")", "error", "{", "var", "res", "[", "]", "error", "\n\n", "// value enum", "if", "err", ":=", "m", ".", "validateReasonEnum", "(", "\"", "\"", ",", "\"", "\"", ",", "m", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "if", "len", "(", "res", ")", ">", "0", "{", "return", "errors", ".", "CompositeValidationError", "(", "res", "...", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Validate validates this reason
[ "Validate", "validates", "this", "reason" ]
d59d7d1c40b2ff26b1afee31bde64df444e96525
https://github.com/iron-io/functions/blob/d59d7d1c40b2ff26b1afee31bde64df444e96525/api/models/reason.go#L45-L57
146,346
iron-io/functions
api/models/route.go
SetDefaults
func (r *Route) SetDefaults() { if r.Memory == 0 { r.Memory = 128 } if r.Type == TypeNone { r.Type = TypeSync } if r.Format == "" { r.Format = FormatDefault } if r.MaxConcurrency == 0 { r.MaxConcurrency = 1 } if r.Headers == nil { r.Headers = http.Header{} } if r.Config == nil { r.Config = map[string]string{} } if r.Timeout == 0 { r.Timeout = defaultRouteTimeout } //if r.IdleTimeout == 0 { // r.IdleTimeout = htfnScaleDownTimeout //} }
go
func (r *Route) SetDefaults() { if r.Memory == 0 { r.Memory = 128 } if r.Type == TypeNone { r.Type = TypeSync } if r.Format == "" { r.Format = FormatDefault } if r.MaxConcurrency == 0 { r.MaxConcurrency = 1 } if r.Headers == nil { r.Headers = http.Header{} } if r.Config == nil { r.Config = map[string]string{} } if r.Timeout == 0 { r.Timeout = defaultRouteTimeout } //if r.IdleTimeout == 0 { // r.IdleTimeout = htfnScaleDownTimeout //} }
[ "func", "(", "r", "*", "Route", ")", "SetDefaults", "(", ")", "{", "if", "r", ".", "Memory", "==", "0", "{", "r", ".", "Memory", "=", "128", "\n", "}", "\n\n", "if", "r", ".", "Type", "==", "TypeNone", "{", "r", ".", "Type", "=", "TypeSync", "\n", "}", "\n\n", "if", "r", ".", "Format", "==", "\"", "\"", "{", "r", ".", "Format", "=", "FormatDefault", "\n", "}", "\n\n", "if", "r", ".", "MaxConcurrency", "==", "0", "{", "r", ".", "MaxConcurrency", "=", "1", "\n", "}", "\n\n", "if", "r", ".", "Headers", "==", "nil", "{", "r", ".", "Headers", "=", "http", ".", "Header", "{", "}", "\n", "}", "\n\n", "if", "r", ".", "Config", "==", "nil", "{", "r", ".", "Config", "=", "map", "[", "string", "]", "string", "{", "}", "\n", "}", "\n\n", "if", "r", ".", "Timeout", "==", "0", "{", "r", ".", "Timeout", "=", "defaultRouteTimeout", "\n", "}", "\n\n", "//if r.IdleTimeout == 0 {", "//\tr.IdleTimeout = htfnScaleDownTimeout", "//}", "}" ]
// SetDefaults sets zeroed field to defaults.
[ "SetDefaults", "sets", "zeroed", "field", "to", "defaults", "." ]
d59d7d1c40b2ff26b1afee31bde64df444e96525
https://github.com/iron-io/functions/blob/d59d7d1c40b2ff26b1afee31bde64df444e96525/api/models/route.go#L65-L97
146,347
iron-io/functions
api/models/route.go
Validate
func (r *Route) Validate(skipZero bool) error { var res []error if !skipZero { if r.AppName == "" { res = append(res, ErrRoutesValidationMissingAppName) } if r.Image == "" { res = append(res, ErrRoutesValidationMissingImage) } if r.Path == "" { res = append(res, ErrRoutesValidationMissingPath) } } if !skipZero || r.Path != "" { u, err := url.Parse(r.Path) if err != nil { res = append(res, ErrRoutesValidationPathMalformed) } if strings.Contains(u.Path, ":") { res = append(res, ErrRoutesValidationFoundDynamicURL) } if !path.IsAbs(u.Path) { res = append(res, ErrRoutesValidationInvalidPath) } } if !skipZero || r.Type != "" { if r.Type != TypeAsync && r.Type != TypeSync { res = append(res, ErrRoutesValidationInvalidType) } } if !skipZero || r.Format != "" { if r.Format != FormatDefault && r.Format != FormatHTTP { res = append(res, ErrRoutesValidationInvalidFormat) } } if r.MaxConcurrency < 0 { res = append(res, ErrRoutesValidationNegativeMaxConcurrency) } if r.Timeout < 0 { res = append(res, ErrRoutesValidationNegativeTimeout) } if r.IdleTimeout < 0 { res = append(res, ErrRoutesValidationNegativeIdleTimeout) } if len(res) > 0 { return apiErrors.CompositeValidationError(res...) } return nil }
go
func (r *Route) Validate(skipZero bool) error { var res []error if !skipZero { if r.AppName == "" { res = append(res, ErrRoutesValidationMissingAppName) } if r.Image == "" { res = append(res, ErrRoutesValidationMissingImage) } if r.Path == "" { res = append(res, ErrRoutesValidationMissingPath) } } if !skipZero || r.Path != "" { u, err := url.Parse(r.Path) if err != nil { res = append(res, ErrRoutesValidationPathMalformed) } if strings.Contains(u.Path, ":") { res = append(res, ErrRoutesValidationFoundDynamicURL) } if !path.IsAbs(u.Path) { res = append(res, ErrRoutesValidationInvalidPath) } } if !skipZero || r.Type != "" { if r.Type != TypeAsync && r.Type != TypeSync { res = append(res, ErrRoutesValidationInvalidType) } } if !skipZero || r.Format != "" { if r.Format != FormatDefault && r.Format != FormatHTTP { res = append(res, ErrRoutesValidationInvalidFormat) } } if r.MaxConcurrency < 0 { res = append(res, ErrRoutesValidationNegativeMaxConcurrency) } if r.Timeout < 0 { res = append(res, ErrRoutesValidationNegativeTimeout) } if r.IdleTimeout < 0 { res = append(res, ErrRoutesValidationNegativeIdleTimeout) } if len(res) > 0 { return apiErrors.CompositeValidationError(res...) } return nil }
[ "func", "(", "r", "*", "Route", ")", "Validate", "(", "skipZero", "bool", ")", "error", "{", "var", "res", "[", "]", "error", "\n\n", "if", "!", "skipZero", "{", "if", "r", ".", "AppName", "==", "\"", "\"", "{", "res", "=", "append", "(", "res", ",", "ErrRoutesValidationMissingAppName", ")", "\n", "}", "\n\n", "if", "r", ".", "Image", "==", "\"", "\"", "{", "res", "=", "append", "(", "res", ",", "ErrRoutesValidationMissingImage", ")", "\n", "}", "\n\n", "if", "r", ".", "Path", "==", "\"", "\"", "{", "res", "=", "append", "(", "res", ",", "ErrRoutesValidationMissingPath", ")", "\n", "}", "\n", "}", "\n\n", "if", "!", "skipZero", "||", "r", ".", "Path", "!=", "\"", "\"", "{", "u", ",", "err", ":=", "url", ".", "Parse", "(", "r", ".", "Path", ")", "\n", "if", "err", "!=", "nil", "{", "res", "=", "append", "(", "res", ",", "ErrRoutesValidationPathMalformed", ")", "\n", "}", "\n\n", "if", "strings", ".", "Contains", "(", "u", ".", "Path", ",", "\"", "\"", ")", "{", "res", "=", "append", "(", "res", ",", "ErrRoutesValidationFoundDynamicURL", ")", "\n", "}", "\n\n", "if", "!", "path", ".", "IsAbs", "(", "u", ".", "Path", ")", "{", "res", "=", "append", "(", "res", ",", "ErrRoutesValidationInvalidPath", ")", "\n", "}", "\n", "}", "\n\n", "if", "!", "skipZero", "||", "r", ".", "Type", "!=", "\"", "\"", "{", "if", "r", ".", "Type", "!=", "TypeAsync", "&&", "r", ".", "Type", "!=", "TypeSync", "{", "res", "=", "append", "(", "res", ",", "ErrRoutesValidationInvalidType", ")", "\n", "}", "\n", "}", "\n\n", "if", "!", "skipZero", "||", "r", ".", "Format", "!=", "\"", "\"", "{", "if", "r", ".", "Format", "!=", "FormatDefault", "&&", "r", ".", "Format", "!=", "FormatHTTP", "{", "res", "=", "append", "(", "res", ",", "ErrRoutesValidationInvalidFormat", ")", "\n", "}", "\n", "}", "\n\n", "if", "r", ".", "MaxConcurrency", "<", "0", "{", "res", "=", "append", "(", "res", ",", "ErrRoutesValidationNegativeMaxConcurrency", ")", "\n", "}", "\n\n", "if", "r", ".", "Timeout", "<", "0", "{", "res", "=", "append", "(", "res", ",", "ErrRoutesValidationNegativeTimeout", ")", "\n", "}", "\n\n", "if", "r", ".", "IdleTimeout", "<", "0", "{", "res", "=", "append", "(", "res", ",", "ErrRoutesValidationNegativeIdleTimeout", ")", "\n", "}", "\n\n", "if", "len", "(", "res", ")", ">", "0", "{", "return", "apiErrors", ".", "CompositeValidationError", "(", "res", "...", ")", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// Validate validates field values, skipping zeroed fields if skipZero is true.
[ "Validate", "validates", "field", "values", "skipping", "zeroed", "fields", "if", "skipZero", "is", "true", "." ]
d59d7d1c40b2ff26b1afee31bde64df444e96525
https://github.com/iron-io/functions/blob/d59d7d1c40b2ff26b1afee31bde64df444e96525/api/models/route.go#L100-L161
146,348
iron-io/functions
api/models/route.go
Update
func (r *Route) Update(new *Route) { if new.Image != "" { r.Image = new.Image } if new.Memory != 0 { r.Memory = new.Memory } if new.Type != "" { r.Type = new.Type } if new.Timeout != 0 { r.Timeout = new.Timeout } if new.IdleTimeout != 0 { r.IdleTimeout = new.IdleTimeout } if new.Format != "" { r.Format = new.Format } if new.MaxConcurrency != 0 { r.MaxConcurrency = new.MaxConcurrency } if new.JwtKey != "" { r.JwtKey = new.JwtKey } if new.Headers != nil { if r.Headers == nil { r.Headers = make(http.Header) } for k, v := range new.Headers { if len(v) == 0 { r.Headers.Del(k) } else { for _, val := range v { r.Headers.Add(k, val) } } } } if new.Config != nil { if r.Config == nil { r.Config = make(Config) } for k, v := range new.Config { if v == "" { delete(r.Config, k) } else { r.Config[k] = v } } } }
go
func (r *Route) Update(new *Route) { if new.Image != "" { r.Image = new.Image } if new.Memory != 0 { r.Memory = new.Memory } if new.Type != "" { r.Type = new.Type } if new.Timeout != 0 { r.Timeout = new.Timeout } if new.IdleTimeout != 0 { r.IdleTimeout = new.IdleTimeout } if new.Format != "" { r.Format = new.Format } if new.MaxConcurrency != 0 { r.MaxConcurrency = new.MaxConcurrency } if new.JwtKey != "" { r.JwtKey = new.JwtKey } if new.Headers != nil { if r.Headers == nil { r.Headers = make(http.Header) } for k, v := range new.Headers { if len(v) == 0 { r.Headers.Del(k) } else { for _, val := range v { r.Headers.Add(k, val) } } } } if new.Config != nil { if r.Config == nil { r.Config = make(Config) } for k, v := range new.Config { if v == "" { delete(r.Config, k) } else { r.Config[k] = v } } } }
[ "func", "(", "r", "*", "Route", ")", "Update", "(", "new", "*", "Route", ")", "{", "if", "new", ".", "Image", "!=", "\"", "\"", "{", "r", ".", "Image", "=", "new", ".", "Image", "\n", "}", "\n", "if", "new", ".", "Memory", "!=", "0", "{", "r", ".", "Memory", "=", "new", ".", "Memory", "\n", "}", "\n", "if", "new", ".", "Type", "!=", "\"", "\"", "{", "r", ".", "Type", "=", "new", ".", "Type", "\n", "}", "\n", "if", "new", ".", "Timeout", "!=", "0", "{", "r", ".", "Timeout", "=", "new", ".", "Timeout", "\n", "}", "\n", "if", "new", ".", "IdleTimeout", "!=", "0", "{", "r", ".", "IdleTimeout", "=", "new", ".", "IdleTimeout", "\n", "}", "\n", "if", "new", ".", "Format", "!=", "\"", "\"", "{", "r", ".", "Format", "=", "new", ".", "Format", "\n", "}", "\n", "if", "new", ".", "MaxConcurrency", "!=", "0", "{", "r", ".", "MaxConcurrency", "=", "new", ".", "MaxConcurrency", "\n", "}", "\n", "if", "new", ".", "JwtKey", "!=", "\"", "\"", "{", "r", ".", "JwtKey", "=", "new", ".", "JwtKey", "\n", "}", "\n\n", "if", "new", ".", "Headers", "!=", "nil", "{", "if", "r", ".", "Headers", "==", "nil", "{", "r", ".", "Headers", "=", "make", "(", "http", ".", "Header", ")", "\n", "}", "\n", "for", "k", ",", "v", ":=", "range", "new", ".", "Headers", "{", "if", "len", "(", "v", ")", "==", "0", "{", "r", ".", "Headers", ".", "Del", "(", "k", ")", "\n", "}", "else", "{", "for", "_", ",", "val", ":=", "range", "v", "{", "r", ".", "Headers", ".", "Add", "(", "k", ",", "val", ")", "\n", "}", "\n", "}", "\n", "}", "\n", "}", "\n", "if", "new", ".", "Config", "!=", "nil", "{", "if", "r", ".", "Config", "==", "nil", "{", "r", ".", "Config", "=", "make", "(", "Config", ")", "\n", "}", "\n", "for", "k", ",", "v", ":=", "range", "new", ".", "Config", "{", "if", "v", "==", "\"", "\"", "{", "delete", "(", "r", ".", "Config", ",", "k", ")", "\n", "}", "else", "{", "r", ".", "Config", "[", "k", "]", "=", "v", "\n", "}", "\n", "}", "\n", "}", "\n", "}" ]
// Update updates fields in r with non-zero field values from new. // 0-length slice Header values, and empty-string Config values trigger removal of map entry.
[ "Update", "updates", "fields", "in", "r", "with", "non", "-", "zero", "field", "values", "from", "new", ".", "0", "-", "length", "slice", "Header", "values", "and", "empty", "-", "string", "Config", "values", "trigger", "removal", "of", "map", "entry", "." ]
d59d7d1c40b2ff26b1afee31bde64df444e96525
https://github.com/iron-io/functions/blob/d59d7d1c40b2ff26b1afee31bde64df444e96525/api/models/route.go#L173-L225
146,349
iron-io/functions
api/runner/protocol/factory.go
IsStreamable
func IsStreamable(p string) (bool, error) { proto, err := New(Protocol(p), nil, nil) if err != nil { return false, err } return proto.IsStreamable(), nil }
go
func IsStreamable(p string) (bool, error) { proto, err := New(Protocol(p), nil, nil) if err != nil { return false, err } return proto.IsStreamable(), nil }
[ "func", "IsStreamable", "(", "p", "string", ")", "(", "bool", ",", "error", ")", "{", "proto", ",", "err", ":=", "New", "(", "Protocol", "(", "p", ")", ",", "nil", ",", "nil", ")", "\n", "if", "err", "!=", "nil", "{", "return", "false", ",", "err", "\n", "}", "\n", "return", "proto", ".", "IsStreamable", "(", ")", ",", "nil", "\n", "}" ]
// IsStreamable says whether the given protocol can be used for streaming into // hot functions.
[ "IsStreamable", "says", "whether", "the", "given", "protocol", "can", "be", "used", "for", "streaming", "into", "hot", "functions", "." ]
d59d7d1c40b2ff26b1afee31bde64df444e96525
https://github.com/iron-io/functions/blob/d59d7d1c40b2ff26b1afee31bde64df444e96525/api/runner/protocol/factory.go#L47-L53
146,350
iron-io/functions
api/server/special_handler.go
UseSpecialHandlers
func (s *Server) UseSpecialHandlers(ctx context.Context, req *http.Request, resp http.ResponseWriter) (context.Context, error) { if len(s.specialHandlers) == 0 { return ctx, ErrNoSpecialHandlerFound } c := &SpecialHandlerContext{ request: req, response: resp, ctx: ctx, } for _, l := range s.specialHandlers { err := l.Handle(c) if err != nil { return c.ctx, err } } return c.ctx, nil }
go
func (s *Server) UseSpecialHandlers(ctx context.Context, req *http.Request, resp http.ResponseWriter) (context.Context, error) { if len(s.specialHandlers) == 0 { return ctx, ErrNoSpecialHandlerFound } c := &SpecialHandlerContext{ request: req, response: resp, ctx: ctx, } for _, l := range s.specialHandlers { err := l.Handle(c) if err != nil { return c.ctx, err } } return c.ctx, nil }
[ "func", "(", "s", "*", "Server", ")", "UseSpecialHandlers", "(", "ctx", "context", ".", "Context", ",", "req", "*", "http", ".", "Request", ",", "resp", "http", ".", "ResponseWriter", ")", "(", "context", ".", "Context", ",", "error", ")", "{", "if", "len", "(", "s", ".", "specialHandlers", ")", "==", "0", "{", "return", "ctx", ",", "ErrNoSpecialHandlerFound", "\n", "}", "\n\n", "c", ":=", "&", "SpecialHandlerContext", "{", "request", ":", "req", ",", "response", ":", "resp", ",", "ctx", ":", "ctx", ",", "}", "\n", "for", "_", ",", "l", ":=", "range", "s", ".", "specialHandlers", "{", "err", ":=", "l", ".", "Handle", "(", "c", ")", "\n", "if", "err", "!=", "nil", "{", "return", "c", ".", "ctx", ",", "err", "\n", "}", "\n", "}", "\n", "return", "c", ".", "ctx", ",", "nil", "\n", "}" ]
// UseSpecialHandlers execute all special handlers
[ "UseSpecialHandlers", "execute", "all", "special", "handlers" ]
d59d7d1c40b2ff26b1afee31bde64df444e96525
https://github.com/iron-io/functions/blob/d59d7d1c40b2ff26b1afee31bde64df444e96525/api/server/special_handler.go#L57-L74
146,351
iron-io/functions
api/server/internal/routecache/lru.go
New
func New(maxentries int) *Cache { return &Cache{ MaxEntries: maxentries, ll: list.New(), cache: make(map[string]*list.Element), } }
go
func New(maxentries int) *Cache { return &Cache{ MaxEntries: maxentries, ll: list.New(), cache: make(map[string]*list.Element), } }
[ "func", "New", "(", "maxentries", "int", ")", "*", "Cache", "{", "return", "&", "Cache", "{", "MaxEntries", ":", "maxentries", ",", "ll", ":", "list", ".", "New", "(", ")", ",", "cache", ":", "make", "(", "map", "[", "string", "]", "*", "list", ".", "Element", ")", ",", "}", "\n", "}" ]
// New returns a route cache.
[ "New", "returns", "a", "route", "cache", "." ]
d59d7d1c40b2ff26b1afee31bde64df444e96525
https://github.com/iron-io/functions/blob/d59d7d1c40b2ff26b1afee31bde64df444e96525/api/server/internal/routecache/lru.go#L24-L30
146,352
iron-io/functions
api/server/internal/routecache/lru.go
Refresh
func (c *Cache) Refresh(route *models.Route) { if c.cache == nil { return } if ee, ok := c.cache[route.AppName+route.Path]; ok { c.ll.MoveToFront(ee) ee.Value = route return } ele := c.ll.PushFront(route) c.cache[route.AppName+route.Path] = ele if c.MaxEntries != 0 && c.ll.Len() > c.MaxEntries { c.removeOldest() } }
go
func (c *Cache) Refresh(route *models.Route) { if c.cache == nil { return } if ee, ok := c.cache[route.AppName+route.Path]; ok { c.ll.MoveToFront(ee) ee.Value = route return } ele := c.ll.PushFront(route) c.cache[route.AppName+route.Path] = ele if c.MaxEntries != 0 && c.ll.Len() > c.MaxEntries { c.removeOldest() } }
[ "func", "(", "c", "*", "Cache", ")", "Refresh", "(", "route", "*", "models", ".", "Route", ")", "{", "if", "c", ".", "cache", "==", "nil", "{", "return", "\n", "}", "\n\n", "if", "ee", ",", "ok", ":=", "c", ".", "cache", "[", "route", ".", "AppName", "+", "route", ".", "Path", "]", ";", "ok", "{", "c", ".", "ll", ".", "MoveToFront", "(", "ee", ")", "\n", "ee", ".", "Value", "=", "route", "\n", "return", "\n", "}", "\n\n", "ele", ":=", "c", ".", "ll", ".", "PushFront", "(", "route", ")", "\n", "c", ".", "cache", "[", "route", ".", "AppName", "+", "route", ".", "Path", "]", "=", "ele", "\n", "if", "c", ".", "MaxEntries", "!=", "0", "&&", "c", ".", "ll", ".", "Len", "(", ")", ">", "c", ".", "MaxEntries", "{", "c", ".", "removeOldest", "(", ")", "\n", "}", "\n", "}" ]
// Refresh updates internal linkedlist either adding a new route to the front, // or moving it to the front when used. It will discard seldom used routes.
[ "Refresh", "updates", "internal", "linkedlist", "either", "adding", "a", "new", "route", "to", "the", "front", "or", "moving", "it", "to", "the", "front", "when", "used", ".", "It", "will", "discard", "seldom", "used", "routes", "." ]
d59d7d1c40b2ff26b1afee31bde64df444e96525
https://github.com/iron-io/functions/blob/d59d7d1c40b2ff26b1afee31bde64df444e96525/api/server/internal/routecache/lru.go#L34-L50
146,353
iron-io/functions
api/server/internal/routecache/lru.go
Get
func (c *Cache) Get(appname, path string) (route *models.Route, ok bool) { if c.cache == nil { return } if ele, hit := c.cache[appname+path]; hit { c.ll.MoveToFront(ele) return ele.Value.(*models.Route), true } return }
go
func (c *Cache) Get(appname, path string) (route *models.Route, ok bool) { if c.cache == nil { return } if ele, hit := c.cache[appname+path]; hit { c.ll.MoveToFront(ele) return ele.Value.(*models.Route), true } return }
[ "func", "(", "c", "*", "Cache", ")", "Get", "(", "appname", ",", "path", "string", ")", "(", "route", "*", "models", ".", "Route", ",", "ok", "bool", ")", "{", "if", "c", ".", "cache", "==", "nil", "{", "return", "\n", "}", "\n", "if", "ele", ",", "hit", ":=", "c", ".", "cache", "[", "appname", "+", "path", "]", ";", "hit", "{", "c", ".", "ll", ".", "MoveToFront", "(", "ele", ")", "\n", "return", "ele", ".", "Value", ".", "(", "*", "models", ".", "Route", ")", ",", "true", "\n", "}", "\n", "return", "\n", "}" ]
// Get looks up a path's route from the cache.
[ "Get", "looks", "up", "a", "path", "s", "route", "from", "the", "cache", "." ]
d59d7d1c40b2ff26b1afee31bde64df444e96525
https://github.com/iron-io/functions/blob/d59d7d1c40b2ff26b1afee31bde64df444e96525/api/server/internal/routecache/lru.go#L53-L62
146,354
iron-io/functions
api/server/internal/routecache/lru.go
Delete
func (c *Cache) Delete(appname, path string) { if ele, hit := c.cache[appname+path]; hit { c.removeElement(ele) } }
go
func (c *Cache) Delete(appname, path string) { if ele, hit := c.cache[appname+path]; hit { c.removeElement(ele) } }
[ "func", "(", "c", "*", "Cache", ")", "Delete", "(", "appname", ",", "path", "string", ")", "{", "if", "ele", ",", "hit", ":=", "c", ".", "cache", "[", "appname", "+", "path", "]", ";", "hit", "{", "c", ".", "removeElement", "(", "ele", ")", "\n", "}", "\n", "}" ]
// Delete removes the element for the given appname and path from the cache.
[ "Delete", "removes", "the", "element", "for", "the", "given", "appname", "and", "path", "from", "the", "cache", "." ]
d59d7d1c40b2ff26b1afee31bde64df444e96525
https://github.com/iron-io/functions/blob/d59d7d1c40b2ff26b1afee31bde64df444e96525/api/server/internal/routecache/lru.go#L65-L69
146,355
iron-io/functions
api/server/app_listeners.go
AddAppListener
func (s *Server) AddAppListener(listener AppListener) { s.appListeners = append(s.appListeners, listener) }
go
func (s *Server) AddAppListener(listener AppListener) { s.appListeners = append(s.appListeners, listener) }
[ "func", "(", "s", "*", "Server", ")", "AddAppListener", "(", "listener", "AppListener", ")", "{", "s", ".", "appListeners", "=", "append", "(", "s", ".", "appListeners", ",", "listener", ")", "\n", "}" ]
// AddAppCreateListener adds a listener that will be notified on App created.
[ "AddAppCreateListener", "adds", "a", "listener", "that", "will", "be", "notified", "on", "App", "created", "." ]
d59d7d1c40b2ff26b1afee31bde64df444e96525
https://github.com/iron-io/functions/blob/d59d7d1c40b2ff26b1afee31bde64df444e96525/api/server/app_listeners.go#L25-L27
146,356
iron-io/functions
api/server/tree.go
findCaseInsensitivePath
func (n *node) findCaseInsensitivePath(path string, fixTrailingSlash bool) (ciPath []byte, found bool) { return n.findCaseInsensitivePathRec( path, strings.ToLower(path), make([]byte, 0, len(path)+1), // preallocate enough memory for new path [4]byte{}, // empty rune buffer fixTrailingSlash, ) }
go
func (n *node) findCaseInsensitivePath(path string, fixTrailingSlash bool) (ciPath []byte, found bool) { return n.findCaseInsensitivePathRec( path, strings.ToLower(path), make([]byte, 0, len(path)+1), // preallocate enough memory for new path [4]byte{}, // empty rune buffer fixTrailingSlash, ) }
[ "func", "(", "n", "*", "node", ")", "findCaseInsensitivePath", "(", "path", "string", ",", "fixTrailingSlash", "bool", ")", "(", "ciPath", "[", "]", "byte", ",", "found", "bool", ")", "{", "return", "n", ".", "findCaseInsensitivePathRec", "(", "path", ",", "strings", ".", "ToLower", "(", "path", ")", ",", "make", "(", "[", "]", "byte", ",", "0", ",", "len", "(", "path", ")", "+", "1", ")", ",", "// preallocate enough memory for new path", "[", "4", "]", "byte", "{", "}", ",", "// empty rune buffer", "fixTrailingSlash", ",", ")", "\n", "}" ]
// Makes a case-insensitive lookup of the given path and tries to find a handler. // It can optionally also fix trailing slashes. // It returns the case-corrected path and a bool indicating whether the lookup // was successful.
[ "Makes", "a", "case", "-", "insensitive", "lookup", "of", "the", "given", "path", "and", "tries", "to", "find", "a", "handler", ".", "It", "can", "optionally", "also", "fix", "trailing", "slashes", ".", "It", "returns", "the", "case", "-", "corrected", "path", "and", "a", "bool", "indicating", "whether", "the", "lookup", "was", "successful", "." ]
d59d7d1c40b2ff26b1afee31bde64df444e96525
https://github.com/iron-io/functions/blob/d59d7d1c40b2ff26b1afee31bde64df444e96525/api/server/tree.go#L458-L466
146,357
iron-io/functions
api/mqs/bolt.go
delayTask
func (mq *BoltDbMQ) delayTask(job *models.Task) (*models.Task, error) { readyAt := time.Now().Add(time.Duration(job.Delay) * time.Second) err := mq.db.Update(func(tx *bolt.Tx) error { b := tx.Bucket(delayQueueName) id, _ := b.NextSequence() buf, err := json.Marshal(job) if err != nil { return err } key := msgKey(id) err = b.Put(key, buf) if err != nil { return err } pb := make([]byte, 4) binary.BigEndian.PutUint32(pb[:], uint32(*job.Priority)) reservation := resKey(key, readyAt) return b.Put(reservation, pb) }) return job, err }
go
func (mq *BoltDbMQ) delayTask(job *models.Task) (*models.Task, error) { readyAt := time.Now().Add(time.Duration(job.Delay) * time.Second) err := mq.db.Update(func(tx *bolt.Tx) error { b := tx.Bucket(delayQueueName) id, _ := b.NextSequence() buf, err := json.Marshal(job) if err != nil { return err } key := msgKey(id) err = b.Put(key, buf) if err != nil { return err } pb := make([]byte, 4) binary.BigEndian.PutUint32(pb[:], uint32(*job.Priority)) reservation := resKey(key, readyAt) return b.Put(reservation, pb) }) return job, err }
[ "func", "(", "mq", "*", "BoltDbMQ", ")", "delayTask", "(", "job", "*", "models", ".", "Task", ")", "(", "*", "models", ".", "Task", ",", "error", ")", "{", "readyAt", ":=", "time", ".", "Now", "(", ")", ".", "Add", "(", "time", ".", "Duration", "(", "job", ".", "Delay", ")", "*", "time", ".", "Second", ")", "\n", "err", ":=", "mq", ".", "db", ".", "Update", "(", "func", "(", "tx", "*", "bolt", ".", "Tx", ")", "error", "{", "b", ":=", "tx", ".", "Bucket", "(", "delayQueueName", ")", "\n", "id", ",", "_", ":=", "b", ".", "NextSequence", "(", ")", "\n", "buf", ",", "err", ":=", "json", ".", "Marshal", "(", "job", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "key", ":=", "msgKey", "(", "id", ")", "\n", "err", "=", "b", ".", "Put", "(", "key", ",", "buf", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "pb", ":=", "make", "(", "[", "]", "byte", ",", "4", ")", "\n", "binary", ".", "BigEndian", ".", "PutUint32", "(", "pb", "[", ":", "]", ",", "uint32", "(", "*", "job", ".", "Priority", ")", ")", "\n", "reservation", ":=", "resKey", "(", "key", ",", "readyAt", ")", "\n", "return", "b", ".", "Put", "(", "reservation", ",", "pb", ")", "\n", "}", ")", "\n", "return", "job", ",", "err", "\n", "}" ]
// We insert a "reservation" at readyAt, and store the json blob at the msg // key. The timer loop plucks this out and puts it in the jobs bucket when the // time elapses. The value stored at the reservation key is the priority.
[ "We", "insert", "a", "reservation", "at", "readyAt", "and", "store", "the", "json", "blob", "at", "the", "msg", "key", ".", "The", "timer", "loop", "plucks", "this", "out", "and", "puts", "it", "in", "the", "jobs", "bucket", "when", "the", "time", "elapses", ".", "The", "value", "stored", "at", "the", "reservation", "key", "is", "the", "priority", "." ]
d59d7d1c40b2ff26b1afee31bde64df444e96525
https://github.com/iron-io/functions/blob/d59d7d1c40b2ff26b1afee31bde64df444e96525/api/mqs/bolt.go#L183-L205
146,358
iron-io/functions
fn/langs/base.go
GetLangHelper
func GetLangHelper(lang string) LangHelper { switch lang { case "go": return &GoLangHelper{} case "node": return &NodeLangHelper{} case "ruby": return &RubyLangHelper{} case "python": return &PythonHelper{} case "rust": return &RustLangHelper{} case "dotnet": return &DotNetLangHelper{} case "java": return &JavaLangHelper{} case "lambda-nodejs4.3": return &LambdaNodeHelper{} } return nil }
go
func GetLangHelper(lang string) LangHelper { switch lang { case "go": return &GoLangHelper{} case "node": return &NodeLangHelper{} case "ruby": return &RubyLangHelper{} case "python": return &PythonHelper{} case "rust": return &RustLangHelper{} case "dotnet": return &DotNetLangHelper{} case "java": return &JavaLangHelper{} case "lambda-nodejs4.3": return &LambdaNodeHelper{} } return nil }
[ "func", "GetLangHelper", "(", "lang", "string", ")", "LangHelper", "{", "switch", "lang", "{", "case", "\"", "\"", ":", "return", "&", "GoLangHelper", "{", "}", "\n", "case", "\"", "\"", ":", "return", "&", "NodeLangHelper", "{", "}", "\n", "case", "\"", "\"", ":", "return", "&", "RubyLangHelper", "{", "}", "\n", "case", "\"", "\"", ":", "return", "&", "PythonHelper", "{", "}", "\n", "case", "\"", "\"", ":", "return", "&", "RustLangHelper", "{", "}", "\n", "case", "\"", "\"", ":", "return", "&", "DotNetLangHelper", "{", "}", "\n", "case", "\"", "\"", ":", "return", "&", "JavaLangHelper", "{", "}", "\n", "case", "\"", "\"", ":", "return", "&", "LambdaNodeHelper", "{", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// GetLangHelper returns a LangHelper for the passed in language
[ "GetLangHelper", "returns", "a", "LangHelper", "for", "the", "passed", "in", "language" ]
d59d7d1c40b2ff26b1afee31bde64df444e96525
https://github.com/iron-io/functions/blob/d59d7d1c40b2ff26b1afee31bde64df444e96525/fn/langs/base.go#L4-L24
146,359
iron-io/functions
api/runner/runner.go
queueHandler
func (r *Runner) queueHandler(ctx context.Context) { consumeQueue: for { select { case task := <-r.taskQueue: r.handleTask(task) case <-ctx.Done(): break consumeQueue } } // consume remainders for len(r.taskQueue) > 0 { r.handleTask(<-r.taskQueue) } }
go
func (r *Runner) queueHandler(ctx context.Context) { consumeQueue: for { select { case task := <-r.taskQueue: r.handleTask(task) case <-ctx.Done(): break consumeQueue } } // consume remainders for len(r.taskQueue) > 0 { r.handleTask(<-r.taskQueue) } }
[ "func", "(", "r", "*", "Runner", ")", "queueHandler", "(", "ctx", "context", ".", "Context", ")", "{", "consumeQueue", ":", "for", "{", "select", "{", "case", "task", ":=", "<-", "r", ".", "taskQueue", ":", "r", ".", "handleTask", "(", "task", ")", "\n", "case", "<-", "ctx", ".", "Done", "(", ")", ":", "break", "consumeQueue", "\n", "}", "\n", "}", "\n\n", "// consume remainders", "for", "len", "(", "r", ".", "taskQueue", ")", ">", "0", "{", "r", ".", "handleTask", "(", "<-", "r", ".", "taskQueue", ")", "\n", "}", "\n", "}" ]
// This routine checks for available memory; // If there's memory then send signal to the task to proceed. // If there's not available memory to run the task it waits // If the task waits for more than X seconds it timeouts
[ "This", "routine", "checks", "for", "available", "memory", ";", "If", "there", "s", "memory", "then", "send", "signal", "to", "the", "task", "to", "proceed", ".", "If", "there", "s", "not", "available", "memory", "to", "run", "the", "task", "it", "waits", "If", "the", "task", "waits", "for", "more", "than", "X", "seconds", "it", "timeouts" ]
d59d7d1c40b2ff26b1afee31bde64df444e96525
https://github.com/iron-io/functions/blob/d59d7d1c40b2ff26b1afee31bde64df444e96525/api/runner/runner.go#L72-L87
146,360
iron-io/functions
api/runner/task.go
DockerAuth
func (t *containerTask) DockerAuth() (docker.AuthConfiguration, error) { reg, _, _ := drivers.ParseImage(t.Image()) authconfig := docker.AuthConfiguration{} if customAuth := registries.Find(reg); customAuth != nil { authconfig = docker.AuthConfiguration{ Password: customAuth.Password, ServerAddress: customAuth.Name, Username: customAuth.Username, } } return authconfig, nil }
go
func (t *containerTask) DockerAuth() (docker.AuthConfiguration, error) { reg, _, _ := drivers.ParseImage(t.Image()) authconfig := docker.AuthConfiguration{} if customAuth := registries.Find(reg); customAuth != nil { authconfig = docker.AuthConfiguration{ Password: customAuth.Password, ServerAddress: customAuth.Name, Username: customAuth.Username, } } return authconfig, nil }
[ "func", "(", "t", "*", "containerTask", ")", "DockerAuth", "(", ")", "(", "docker", ".", "AuthConfiguration", ",", "error", ")", "{", "reg", ",", "_", ",", "_", ":=", "drivers", ".", "ParseImage", "(", "t", ".", "Image", "(", ")", ")", "\n", "authconfig", ":=", "docker", ".", "AuthConfiguration", "{", "}", "\n\n", "if", "customAuth", ":=", "registries", ".", "Find", "(", "reg", ")", ";", "customAuth", "!=", "nil", "{", "authconfig", "=", "docker", ".", "AuthConfiguration", "{", "Password", ":", "customAuth", ".", "Password", ",", "ServerAddress", ":", "customAuth", ".", "Name", ",", "Username", ":", "customAuth", ".", "Username", ",", "}", "\n", "}", "\n\n", "return", "authconfig", ",", "nil", "\n", "}" ]
// Implementing the docker.AuthConfiguration interface. Pulling in // the docker repo password from environment variables
[ "Implementing", "the", "docker", ".", "AuthConfiguration", "interface", ".", "Pulling", "in", "the", "docker", "repo", "password", "from", "environment", "variables" ]
d59d7d1c40b2ff26b1afee31bde64df444e96525
https://github.com/iron-io/functions/blob/d59d7d1c40b2ff26b1afee31bde64df444e96525/api/runner/task.go#L91-L104
146,361
elastic/go-ucfg
flag/file.go
NewFlagFiles
func NewFlagFiles( cfg *ucfg.Config, extensions map[string]FileLoader, opts ...ucfg.Option, ) *FlagValue { return newFlagValue(cfg, opts, func(path string) (*ucfg.Config, error, error) { ext := filepath.Ext(path) loader := extensions[ext] if loader == nil { loader = extensions[""] } if loader == nil { // TODO: better error message? return nil, fmt.Errorf("no loader for file '%v' found", path), nil } cfg, err := loader(path, opts...) return cfg, err, nil }) }
go
func NewFlagFiles( cfg *ucfg.Config, extensions map[string]FileLoader, opts ...ucfg.Option, ) *FlagValue { return newFlagValue(cfg, opts, func(path string) (*ucfg.Config, error, error) { ext := filepath.Ext(path) loader := extensions[ext] if loader == nil { loader = extensions[""] } if loader == nil { // TODO: better error message? return nil, fmt.Errorf("no loader for file '%v' found", path), nil } cfg, err := loader(path, opts...) return cfg, err, nil }) }
[ "func", "NewFlagFiles", "(", "cfg", "*", "ucfg", ".", "Config", ",", "extensions", "map", "[", "string", "]", "FileLoader", ",", "opts", "...", "ucfg", ".", "Option", ",", ")", "*", "FlagValue", "{", "return", "newFlagValue", "(", "cfg", ",", "opts", ",", "func", "(", "path", "string", ")", "(", "*", "ucfg", ".", "Config", ",", "error", ",", "error", ")", "{", "ext", ":=", "filepath", ".", "Ext", "(", "path", ")", "\n", "loader", ":=", "extensions", "[", "ext", "]", "\n", "if", "loader", "==", "nil", "{", "loader", "=", "extensions", "[", "\"", "\"", "]", "\n", "}", "\n", "if", "loader", "==", "nil", "{", "// TODO: better error message?", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "path", ")", ",", "nil", "\n", "}", "\n", "cfg", ",", "err", ":=", "loader", "(", "path", ",", "opts", "...", ")", "\n", "return", "cfg", ",", "err", ",", "nil", "\n", "}", ")", "\n", "}" ]
// NewFlagFiles create a new flag, that will load external configurations file // when being used. Configurations loaded from multiple files will be merged // into one common Config object. If cfg is not nil, then the loaded // configurations will be merged into cfg. // The extensions parameter define custom file loaders for different file // extensions. If extensions contains an entry with key "", then this loader // will be used as default fallback.
[ "NewFlagFiles", "create", "a", "new", "flag", "that", "will", "load", "external", "configurations", "file", "when", "being", "used", ".", "Configurations", "loaded", "from", "multiple", "files", "will", "be", "merged", "into", "one", "common", "Config", "object", ".", "If", "cfg", "is", "not", "nil", "then", "the", "loaded", "configurations", "will", "be", "merged", "into", "cfg", ".", "The", "extensions", "parameter", "define", "custom", "file", "loaders", "for", "different", "file", "extensions", ".", "If", "extensions", "contains", "an", "entry", "with", "key", "then", "this", "loader", "will", "be", "used", "as", "default", "fallback", "." ]
c5859d30d9ff1bf630e2dfbe1498ad3d1b7607ab
https://github.com/elastic/go-ucfg/blob/c5859d30d9ff1bf630e2dfbe1498ad3d1b7607ab/flag/file.go#L38-L56
146,362
elastic/go-ucfg
unpack.go
valueIsUnpacker
func valueIsUnpacker(v reflect.Value) (reflect.Value, bool) { for { if implementsUnpacker(v.Type()) { return v, true } if !v.CanAddr() { break } v = v.Addr() } return reflect.Value{}, false }
go
func valueIsUnpacker(v reflect.Value) (reflect.Value, bool) { for { if implementsUnpacker(v.Type()) { return v, true } if !v.CanAddr() { break } v = v.Addr() } return reflect.Value{}, false }
[ "func", "valueIsUnpacker", "(", "v", "reflect", ".", "Value", ")", "(", "reflect", ".", "Value", ",", "bool", ")", "{", "for", "{", "if", "implementsUnpacker", "(", "v", ".", "Type", "(", ")", ")", "{", "return", "v", ",", "true", "\n", "}", "\n\n", "if", "!", "v", ".", "CanAddr", "(", ")", "{", "break", "\n", "}", "\n", "v", "=", "v", ".", "Addr", "(", ")", "\n", "}", "\n\n", "return", "reflect", ".", "Value", "{", "}", ",", "false", "\n", "}" ]
// valueIsUnpacker checks if v implements the Unpacker interface. // If there exists a pointer to v, the pointer to v is also tested.
[ "valueIsUnpacker", "checks", "if", "v", "implements", "the", "Unpacker", "interface", ".", "If", "there", "exists", "a", "pointer", "to", "v", "the", "pointer", "to", "v", "is", "also", "tested", "." ]
c5859d30d9ff1bf630e2dfbe1498ad3d1b7607ab
https://github.com/elastic/go-ucfg/blob/c5859d30d9ff1bf630e2dfbe1498ad3d1b7607ab/unpack.go#L92-L105
146,363
elastic/go-ucfg
validator.go
RegisterValidator
func RegisterValidator(name string, cb ValidatorCallback) error { if _, exists := validators[name]; exists { return ErrDuplicateValidator } validators[name] = cb return nil }
go
func RegisterValidator(name string, cb ValidatorCallback) error { if _, exists := validators[name]; exists { return ErrDuplicateValidator } validators[name] = cb return nil }
[ "func", "RegisterValidator", "(", "name", "string", ",", "cb", "ValidatorCallback", ")", "error", "{", "if", "_", ",", "exists", ":=", "validators", "[", "name", "]", ";", "exists", "{", "return", "ErrDuplicateValidator", "\n", "}", "\n\n", "validators", "[", "name", "]", "=", "cb", "\n", "return", "nil", "\n", "}" ]
// RegisterValidator adds a new validator option to the "validate" struct tag. // The callback will be executed when unpacking into a struct field.
[ "RegisterValidator", "adds", "a", "new", "validator", "option", "to", "the", "validate", "struct", "tag", ".", "The", "callback", "will", "be", "executed", "when", "unpacking", "into", "a", "struct", "field", "." ]
c5859d30d9ff1bf630e2dfbe1498ad3d1b7607ab
https://github.com/elastic/go-ucfg/blob/c5859d30d9ff1bf630e2dfbe1498ad3d1b7607ab/validator.go#L70-L77
146,364
elastic/go-ucfg
validator.go
validateRequired
func validateRequired(v interface{}, name string) error { if v == nil { return ErrRequired } return validateNonEmpty(v, name) }
go
func validateRequired(v interface{}, name string) error { if v == nil { return ErrRequired } return validateNonEmpty(v, name) }
[ "func", "validateRequired", "(", "v", "interface", "{", "}", ",", "name", "string", ")", "error", "{", "if", "v", "==", "nil", "{", "return", "ErrRequired", "\n", "}", "\n", "return", "validateNonEmpty", "(", "v", ",", "name", ")", "\n", "}" ]
// validateRequired implements the `required` validation tag. // If a field is required, it must be present in the config. // If field is a string, regex or slice its length must be > 0.
[ "validateRequired", "implements", "the", "required", "validation", "tag", ".", "If", "a", "field", "is", "required", "it", "must", "be", "present", "in", "the", "config", ".", "If", "field", "is", "a", "string", "regex", "or", "slice", "its", "length", "must", "be", ">", "0", "." ]
c5859d30d9ff1bf630e2dfbe1498ad3d1b7607ab
https://github.com/elastic/go-ucfg/blob/c5859d30d9ff1bf630e2dfbe1498ad3d1b7607ab/validator.go#L304-L309
146,365
elastic/go-ucfg
yaml/yaml.go
NewConfig
func NewConfig(in []byte, opts ...ucfg.Option) (*ucfg.Config, error) { var m interface{} if err := yaml.Unmarshal(in, &m); err != nil { return nil, err } return ucfg.NewFrom(m, opts...) }
go
func NewConfig(in []byte, opts ...ucfg.Option) (*ucfg.Config, error) { var m interface{} if err := yaml.Unmarshal(in, &m); err != nil { return nil, err } return ucfg.NewFrom(m, opts...) }
[ "func", "NewConfig", "(", "in", "[", "]", "byte", ",", "opts", "...", "ucfg", ".", "Option", ")", "(", "*", "ucfg", ".", "Config", ",", "error", ")", "{", "var", "m", "interface", "{", "}", "\n", "if", "err", ":=", "yaml", ".", "Unmarshal", "(", "in", ",", "&", "m", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "ucfg", ".", "NewFrom", "(", "m", ",", "opts", "...", ")", "\n", "}" ]
// NewConfig creates a new configuration object from the YAML string passed via in.
[ "NewConfig", "creates", "a", "new", "configuration", "object", "from", "the", "YAML", "string", "passed", "via", "in", "." ]
c5859d30d9ff1bf630e2dfbe1498ad3d1b7607ab
https://github.com/elastic/go-ucfg/blob/c5859d30d9ff1bf630e2dfbe1498ad3d1b7607ab/yaml/yaml.go#L29-L36
146,366
elastic/go-ucfg
yaml/yaml.go
NewConfigWithFile
func NewConfigWithFile(name string, opts ...ucfg.Option) (*ucfg.Config, error) { input, err := ioutil.ReadFile(name) if err != nil { return nil, err } opts = append([]ucfg.Option{ ucfg.MetaData(ucfg.Meta{Source: name}), }, opts...) return NewConfig(input, opts...) }
go
func NewConfigWithFile(name string, opts ...ucfg.Option) (*ucfg.Config, error) { input, err := ioutil.ReadFile(name) if err != nil { return nil, err } opts = append([]ucfg.Option{ ucfg.MetaData(ucfg.Meta{Source: name}), }, opts...) return NewConfig(input, opts...) }
[ "func", "NewConfigWithFile", "(", "name", "string", ",", "opts", "...", "ucfg", ".", "Option", ")", "(", "*", "ucfg", ".", "Config", ",", "error", ")", "{", "input", ",", "err", ":=", "ioutil", ".", "ReadFile", "(", "name", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "opts", "=", "append", "(", "[", "]", "ucfg", ".", "Option", "{", "ucfg", ".", "MetaData", "(", "ucfg", ".", "Meta", "{", "Source", ":", "name", "}", ")", ",", "}", ",", "opts", "...", ")", "\n", "return", "NewConfig", "(", "input", ",", "opts", "...", ")", "\n", "}" ]
// NewConfigWithFile loads a new configuration object from an external JSON file.
[ "NewConfigWithFile", "loads", "a", "new", "configuration", "object", "from", "an", "external", "JSON", "file", "." ]
c5859d30d9ff1bf630e2dfbe1498ad3d1b7607ab
https://github.com/elastic/go-ucfg/blob/c5859d30d9ff1bf630e2dfbe1498ad3d1b7607ab/yaml/yaml.go#L39-L49
146,367
elastic/go-ucfg
ucfg.go
GetFields
func (c *Config) GetFields() []string { var names []string for k := range c.fields.dict() { names = append(names, k) } return names }
go
func (c *Config) GetFields() []string { var names []string for k := range c.fields.dict() { names = append(names, k) } return names }
[ "func", "(", "c", "*", "Config", ")", "GetFields", "(", ")", "[", "]", "string", "{", "var", "names", "[", "]", "string", "\n", "for", "k", ":=", "range", "c", ".", "fields", ".", "dict", "(", ")", "{", "names", "=", "append", "(", "names", ",", "k", ")", "\n", "}", "\n", "return", "names", "\n", "}" ]
// GetFields returns a list of all top-level named keys in c.
[ "GetFields", "returns", "a", "list", "of", "all", "top", "-", "level", "named", "keys", "in", "c", "." ]
c5859d30d9ff1bf630e2dfbe1498ad3d1b7607ab
https://github.com/elastic/go-ucfg/blob/c5859d30d9ff1bf630e2dfbe1498ad3d1b7607ab/ucfg.go#L121-L127
146,368
elastic/go-ucfg
ucfg.go
Has
func (c *Config) Has(name string, idx int, options ...Option) (bool, error) { opts := makeOptions(options) p := parsePathIdx(name, opts.pathSep, idx) return p.Has(c, opts) }
go
func (c *Config) Has(name string, idx int, options ...Option) (bool, error) { opts := makeOptions(options) p := parsePathIdx(name, opts.pathSep, idx) return p.Has(c, opts) }
[ "func", "(", "c", "*", "Config", ")", "Has", "(", "name", "string", ",", "idx", "int", ",", "options", "...", "Option", ")", "(", "bool", ",", "error", ")", "{", "opts", ":=", "makeOptions", "(", "options", ")", "\n", "p", ":=", "parsePathIdx", "(", "name", ",", "opts", ".", "pathSep", ",", "idx", ")", "\n", "return", "p", ".", "Has", "(", "c", ",", "opts", ")", "\n", "}" ]
// Has checks if a field by the given path+idx configuration exists. // Has returns an error if the path can not be resolved because a primitive // value is found in the middle of the traversal.
[ "Has", "checks", "if", "a", "field", "by", "the", "given", "path", "+", "idx", "configuration", "exists", ".", "Has", "returns", "an", "error", "if", "the", "path", "can", "not", "be", "resolved", "because", "a", "primitive", "value", "is", "found", "in", "the", "middle", "of", "the", "traversal", "." ]
c5859d30d9ff1bf630e2dfbe1498ad3d1b7607ab
https://github.com/elastic/go-ucfg/blob/c5859d30d9ff1bf630e2dfbe1498ad3d1b7607ab/ucfg.go#L132-L136
146,369
elastic/go-ucfg
ucfg.go
HasField
func (c *Config) HasField(name string) bool { _, ok := c.fields.get(name) return ok }
go
func (c *Config) HasField(name string) bool { _, ok := c.fields.get(name) return ok }
[ "func", "(", "c", "*", "Config", ")", "HasField", "(", "name", "string", ")", "bool", "{", "_", ",", "ok", ":=", "c", ".", "fields", ".", "get", "(", "name", ")", "\n", "return", "ok", "\n", "}" ]
// HasField checks if c has a top-level named key name.
[ "HasField", "checks", "if", "c", "has", "a", "top", "-", "level", "named", "key", "name", "." ]
c5859d30d9ff1bf630e2dfbe1498ad3d1b7607ab
https://github.com/elastic/go-ucfg/blob/c5859d30d9ff1bf630e2dfbe1498ad3d1b7607ab/ucfg.go#L139-L142
146,370
elastic/go-ucfg
ucfg.go
Path
func (c *Config) Path(sep string) string { return c.ctx.path(sep) }
go
func (c *Config) Path(sep string) string { return c.ctx.path(sep) }
[ "func", "(", "c", "*", "Config", ")", "Path", "(", "sep", "string", ")", "string", "{", "return", "c", ".", "ctx", ".", "path", "(", "sep", ")", "\n", "}" ]
// Path gets the absolute path of c separated by sep. If c is a root-Config an // empty string will be returned.
[ "Path", "gets", "the", "absolute", "path", "of", "c", "separated", "by", "sep", ".", "If", "c", "is", "a", "root", "-", "Config", "an", "empty", "string", "will", "be", "returned", "." ]
c5859d30d9ff1bf630e2dfbe1498ad3d1b7607ab
https://github.com/elastic/go-ucfg/blob/c5859d30d9ff1bf630e2dfbe1498ad3d1b7607ab/ucfg.go#L175-L177
146,371
elastic/go-ucfg
ucfg.go
PathOf
func (c *Config) PathOf(field, sep string) string { return c.ctx.pathOf(field, sep) }
go
func (c *Config) PathOf(field, sep string) string { return c.ctx.pathOf(field, sep) }
[ "func", "(", "c", "*", "Config", ")", "PathOf", "(", "field", ",", "sep", "string", ")", "string", "{", "return", "c", ".", "ctx", ".", "pathOf", "(", "field", ",", "sep", ")", "\n", "}" ]
// PathOf gets the absolute path of a potential setting field in c with name // separated by sep.
[ "PathOf", "gets", "the", "absolute", "path", "of", "a", "potential", "setting", "field", "in", "c", "with", "name", "separated", "by", "sep", "." ]
c5859d30d9ff1bf630e2dfbe1498ad3d1b7607ab
https://github.com/elastic/go-ucfg/blob/c5859d30d9ff1bf630e2dfbe1498ad3d1b7607ab/ucfg.go#L181-L183
146,372
elastic/go-ucfg
ucfg.go
Parent
func (c *Config) Parent() *Config { ctx := c.ctx for { if ctx.parent == nil { return nil } switch p := ctx.parent.(type) { case cfgSub: return p.c default: return nil } } }
go
func (c *Config) Parent() *Config { ctx := c.ctx for { if ctx.parent == nil { return nil } switch p := ctx.parent.(type) { case cfgSub: return p.c default: return nil } } }
[ "func", "(", "c", "*", "Config", ")", "Parent", "(", ")", "*", "Config", "{", "ctx", ":=", "c", ".", "ctx", "\n", "for", "{", "if", "ctx", ".", "parent", "==", "nil", "{", "return", "nil", "\n", "}", "\n\n", "switch", "p", ":=", "ctx", ".", "parent", ".", "(", "type", ")", "{", "case", "cfgSub", ":", "return", "p", ".", "c", "\n", "default", ":", "return", "nil", "\n", "}", "\n", "}", "\n", "}" ]
// Parent returns the parent configuration or nil if c is already a root // Configuration.
[ "Parent", "returns", "the", "parent", "configuration", "or", "nil", "if", "c", "is", "already", "a", "root", "Configuration", "." ]
c5859d30d9ff1bf630e2dfbe1498ad3d1b7607ab
https://github.com/elastic/go-ucfg/blob/c5859d30d9ff1bf630e2dfbe1498ad3d1b7607ab/ucfg.go#L187-L201
146,373
elastic/go-ucfg
ucfg.go
FlattenedKeys
func (c *Config) FlattenedKeys(opts ...Option) []string { var keys []string normalizedOptions := makeOptions(opts) if normalizedOptions.pathSep == "" { normalizedOptions.pathSep = "." } if c.IsDict() { for _, v := range c.fields.dict() { subcfg, err := v.toConfig(normalizedOptions) if err != nil { ctx := v.Context() p := ctx.path(normalizedOptions.pathSep) keys = append(keys, p) } else { newKeys := subcfg.FlattenedKeys(opts...) keys = append(keys, newKeys...) } } } else if c.IsArray() { for _, a := range c.fields.array() { scfg, err := a.toConfig(normalizedOptions) if err != nil { ctx := a.Context() p := ctx.path(normalizedOptions.pathSep) keys = append(keys, p) } else { newKeys := scfg.FlattenedKeys(opts...) keys = append(keys, newKeys...) } } } sort.Strings(keys) return keys }
go
func (c *Config) FlattenedKeys(opts ...Option) []string { var keys []string normalizedOptions := makeOptions(opts) if normalizedOptions.pathSep == "" { normalizedOptions.pathSep = "." } if c.IsDict() { for _, v := range c.fields.dict() { subcfg, err := v.toConfig(normalizedOptions) if err != nil { ctx := v.Context() p := ctx.path(normalizedOptions.pathSep) keys = append(keys, p) } else { newKeys := subcfg.FlattenedKeys(opts...) keys = append(keys, newKeys...) } } } else if c.IsArray() { for _, a := range c.fields.array() { scfg, err := a.toConfig(normalizedOptions) if err != nil { ctx := a.Context() p := ctx.path(normalizedOptions.pathSep) keys = append(keys, p) } else { newKeys := scfg.FlattenedKeys(opts...) keys = append(keys, newKeys...) } } } sort.Strings(keys) return keys }
[ "func", "(", "c", "*", "Config", ")", "FlattenedKeys", "(", "opts", "...", "Option", ")", "[", "]", "string", "{", "var", "keys", "[", "]", "string", "\n", "normalizedOptions", ":=", "makeOptions", "(", "opts", ")", "\n\n", "if", "normalizedOptions", ".", "pathSep", "==", "\"", "\"", "{", "normalizedOptions", ".", "pathSep", "=", "\"", "\"", "\n", "}", "\n\n", "if", "c", ".", "IsDict", "(", ")", "{", "for", "_", ",", "v", ":=", "range", "c", ".", "fields", ".", "dict", "(", ")", "{", "subcfg", ",", "err", ":=", "v", ".", "toConfig", "(", "normalizedOptions", ")", "\n", "if", "err", "!=", "nil", "{", "ctx", ":=", "v", ".", "Context", "(", ")", "\n", "p", ":=", "ctx", ".", "path", "(", "normalizedOptions", ".", "pathSep", ")", "\n", "keys", "=", "append", "(", "keys", ",", "p", ")", "\n", "}", "else", "{", "newKeys", ":=", "subcfg", ".", "FlattenedKeys", "(", "opts", "...", ")", "\n", "keys", "=", "append", "(", "keys", ",", "newKeys", "...", ")", "\n", "}", "\n", "}", "\n", "}", "else", "if", "c", ".", "IsArray", "(", ")", "{", "for", "_", ",", "a", ":=", "range", "c", ".", "fields", ".", "array", "(", ")", "{", "scfg", ",", "err", ":=", "a", ".", "toConfig", "(", "normalizedOptions", ")", "\n\n", "if", "err", "!=", "nil", "{", "ctx", ":=", "a", ".", "Context", "(", ")", "\n", "p", ":=", "ctx", ".", "path", "(", "normalizedOptions", ".", "pathSep", ")", "\n", "keys", "=", "append", "(", "keys", ",", "p", ")", "\n", "}", "else", "{", "newKeys", ":=", "scfg", ".", "FlattenedKeys", "(", "opts", "...", ")", "\n", "keys", "=", "append", "(", "keys", ",", "newKeys", "...", ")", "\n", "}", "\n", "}", "\n", "}", "\n\n", "sort", ".", "Strings", "(", "keys", ")", "\n", "return", "keys", "\n", "}" ]
// FlattenedKeys return a sorted flattened views of the set keys in the configuration
[ "FlattenedKeys", "return", "a", "sorted", "flattened", "views", "of", "the", "set", "keys", "in", "the", "configuration" ]
c5859d30d9ff1bf630e2dfbe1498ad3d1b7607ab
https://github.com/elastic/go-ucfg/blob/c5859d30d9ff1bf630e2dfbe1498ad3d1b7607ab/ucfg.go#L204-L242
146,374
elastic/go-ucfg
opts.go
Env
func Env(e *Config) Option { return func(o *options) { o.env = append(o.env, e) } }
go
func Env(e *Config) Option { return func(o *options) { o.env = append(o.env, e) } }
[ "func", "Env", "(", "e", "*", "Config", ")", "Option", "{", "return", "func", "(", "o", "*", "options", ")", "{", "o", ".", "env", "=", "append", "(", "o", ".", "env", ",", "e", ")", "\n", "}", "\n", "}" ]
// Env option adds another configuration for variable expansion to be used, if // the path to look up does not exist in the actual configuration. Env can be used // multiple times in order to add more lookup environments.
[ "Env", "option", "adds", "another", "configuration", "for", "variable", "expansion", "to", "be", "used", "if", "the", "path", "to", "look", "up", "does", "not", "exist", "in", "the", "actual", "configuration", ".", "Env", "can", "be", "used", "multiple", "times", "in", "order", "to", "add", "more", "lookup", "environments", "." ]
c5859d30d9ff1bf630e2dfbe1498ad3d1b7607ab
https://github.com/elastic/go-ucfg/blob/c5859d30d9ff1bf630e2dfbe1498ad3d1b7607ab/opts.go#L98-L102
146,375
elastic/go-ucfg
opts.go
Resolve
func Resolve(fn func(name string) (string, error)) Option { return func(o *options) { o.resolvers = append(o.resolvers, fn) } }
go
func Resolve(fn func(name string) (string, error)) Option { return func(o *options) { o.resolvers = append(o.resolvers, fn) } }
[ "func", "Resolve", "(", "fn", "func", "(", "name", "string", ")", "(", "string", ",", "error", ")", ")", "Option", "{", "return", "func", "(", "o", "*", "options", ")", "{", "o", ".", "resolvers", "=", "append", "(", "o", ".", "resolvers", ",", "fn", ")", "\n", "}", "\n", "}" ]
// Resolve option adds a callback used by variable name expansion. The callback // will be called if a variable can not be resolved from within the actual configuration // or any of its environments.
[ "Resolve", "option", "adds", "a", "callback", "used", "by", "variable", "name", "expansion", ".", "The", "callback", "will", "be", "called", "if", "a", "variable", "can", "not", "be", "resolved", "from", "within", "the", "actual", "configuration", "or", "any", "of", "its", "environments", "." ]
c5859d30d9ff1bf630e2dfbe1498ad3d1b7607ab
https://github.com/elastic/go-ucfg/blob/c5859d30d9ff1bf630e2dfbe1498ad3d1b7607ab/opts.go#L107-L111
146,376
elastic/go-ucfg
diff/keys.go
String
func (d Diff) String() string { var lines []string for k, values := range d { for _, v := range values { lines = append(lines, fmt.Sprintf("%s | key: %s", k, v)) } } return strings.Join(lines, "\n") }
go
func (d Diff) String() string { var lines []string for k, values := range d { for _, v := range values { lines = append(lines, fmt.Sprintf("%s | key: %s", k, v)) } } return strings.Join(lines, "\n") }
[ "func", "(", "d", "Diff", ")", "String", "(", ")", "string", "{", "var", "lines", "[", "]", "string", "\n\n", "for", "k", ",", "values", ":=", "range", "d", "{", "for", "_", ",", "v", ":=", "range", "values", "{", "lines", "=", "append", "(", "lines", ",", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "k", ",", "v", ")", ")", "\n", "}", "\n", "}", "\n\n", "return", "strings", ".", "Join", "(", "lines", ",", "\"", "\\n", "\"", ")", "\n", "}" ]
// String return a human friendly format of the diff
[ "String", "return", "a", "human", "friendly", "format", "of", "the", "diff" ]
c5859d30d9ff1bf630e2dfbe1498ad3d1b7607ab
https://github.com/elastic/go-ucfg/blob/c5859d30d9ff1bf630e2dfbe1498ad3d1b7607ab/diff/keys.go#L53-L63
146,377
elastic/go-ucfg
diff/keys.go
HasChanged
func (d *Diff) HasChanged() bool { if d.HasKeyAdded() || d.HasKeyRemoved() { return true } return false }
go
func (d *Diff) HasChanged() bool { if d.HasKeyAdded() || d.HasKeyRemoved() { return true } return false }
[ "func", "(", "d", "*", "Diff", ")", "HasChanged", "(", ")", "bool", "{", "if", "d", ".", "HasKeyAdded", "(", ")", "||", "d", ".", "HasKeyRemoved", "(", ")", "{", "return", "true", "\n", "}", "\n", "return", "false", "\n", "}" ]
// HasChanged returns true if we have remove of added new elements in the graph
[ "HasChanged", "returns", "true", "if", "we", "have", "remove", "of", "added", "new", "elements", "in", "the", "graph" ]
c5859d30d9ff1bf630e2dfbe1498ad3d1b7607ab
https://github.com/elastic/go-ucfg/blob/c5859d30d9ff1bf630e2dfbe1498ad3d1b7607ab/diff/keys.go#L66-L71
146,378
elastic/go-ucfg
diff/keys.go
CompareConfigs
func CompareConfigs(old, new *ucfg.Config, opts ...ucfg.Option) Diff { oldKeys := old.FlattenedKeys(opts...) newKeys := new.FlattenedKeys(opts...) difference := make(map[string]Type) // Map for candidates check for _, k := range oldKeys { difference[k] = Remove } for _, nk := range newKeys { if _, ok := difference[nk]; ok { difference[nk] = Keep } else { difference[nk] = Add } } invert := make(Diff) for k, v := range difference { invert[v] = append(invert[v], k) } return invert }
go
func CompareConfigs(old, new *ucfg.Config, opts ...ucfg.Option) Diff { oldKeys := old.FlattenedKeys(opts...) newKeys := new.FlattenedKeys(opts...) difference := make(map[string]Type) // Map for candidates check for _, k := range oldKeys { difference[k] = Remove } for _, nk := range newKeys { if _, ok := difference[nk]; ok { difference[nk] = Keep } else { difference[nk] = Add } } invert := make(Diff) for k, v := range difference { invert[v] = append(invert[v], k) } return invert }
[ "func", "CompareConfigs", "(", "old", ",", "new", "*", "ucfg", ".", "Config", ",", "opts", "...", "ucfg", ".", "Option", ")", "Diff", "{", "oldKeys", ":=", "old", ".", "FlattenedKeys", "(", "opts", "...", ")", "\n", "newKeys", ":=", "new", ".", "FlattenedKeys", "(", "opts", "...", ")", "\n\n", "difference", ":=", "make", "(", "map", "[", "string", "]", "Type", ")", "\n\n", "// Map for candidates check", "for", "_", ",", "k", ":=", "range", "oldKeys", "{", "difference", "[", "k", "]", "=", "Remove", "\n", "}", "\n\n", "for", "_", ",", "nk", ":=", "range", "newKeys", "{", "if", "_", ",", "ok", ":=", "difference", "[", "nk", "]", ";", "ok", "{", "difference", "[", "nk", "]", "=", "Keep", "\n", "}", "else", "{", "difference", "[", "nk", "]", "=", "Add", "\n", "}", "\n", "}", "\n\n", "invert", ":=", "make", "(", "Diff", ")", "\n\n", "for", "k", ",", "v", ":=", "range", "difference", "{", "invert", "[", "v", "]", "=", "append", "(", "invert", "[", "v", "]", ",", "k", ")", "\n", "}", "\n\n", "return", "invert", "\n", "}" ]
// CompareConfigs takes two configuration and return the difference between the defined keys
[ "CompareConfigs", "takes", "two", "configuration", "and", "return", "the", "difference", "between", "the", "defined", "keys" ]
c5859d30d9ff1bf630e2dfbe1498ad3d1b7607ab
https://github.com/elastic/go-ucfg/blob/c5859d30d9ff1bf630e2dfbe1498ad3d1b7607ab/diff/keys.go#L96-L122
146,379
cloudfoundry/bytefmt
bytes.go
ToMegabytes
func ToMegabytes(s string) (uint64, error) { bytes, err := ToBytes(s) if err != nil { return 0, err } return bytes / MEGABYTE, nil }
go
func ToMegabytes(s string) (uint64, error) { bytes, err := ToBytes(s) if err != nil { return 0, err } return bytes / MEGABYTE, nil }
[ "func", "ToMegabytes", "(", "s", "string", ")", "(", "uint64", ",", "error", ")", "{", "bytes", ",", "err", ":=", "ToBytes", "(", "s", ")", "\n", "if", "err", "!=", "nil", "{", "return", "0", ",", "err", "\n", "}", "\n\n", "return", "bytes", "/", "MEGABYTE", ",", "nil", "\n", "}" ]
// ToMegabytes parses a string formatted by ByteSize as megabytes.
[ "ToMegabytes", "parses", "a", "string", "formatted", "by", "ByteSize", "as", "megabytes", "." ]
2aa6f33b730c79971cfc3c742f279195b0abc627
https://github.com/cloudfoundry/bytefmt/blob/2aa6f33b730c79971cfc3c742f279195b0abc627/bytes.go#L61-L68
146,380
akamai/AkamaiOPEN-edgegrid-golang
papi-v1/rules.go
NewRules
func NewRules() *Rules { rules := &Rules{} rules.Rule = NewRule() rules.Rule.Name = "default" rules.Init() return rules }
go
func NewRules() *Rules { rules := &Rules{} rules.Rule = NewRule() rules.Rule.Name = "default" rules.Init() return rules }
[ "func", "NewRules", "(", ")", "*", "Rules", "{", "rules", ":=", "&", "Rules", "{", "}", "\n", "rules", ".", "Rule", "=", "NewRule", "(", ")", "\n", "rules", ".", "Rule", ".", "Name", "=", "\"", "\"", "\n", "rules", ".", "Init", "(", ")", "\n\n", "return", "rules", "\n", "}" ]
// NewRules creates a new Rules
[ "NewRules", "creates", "a", "new", "Rules" ]
009960c8b2c7c57a0c5c488a3c8c778c16f3f586
https://github.com/akamai/AkamaiOPEN-edgegrid-golang/blob/009960c8b2c7c57a0c5c488a3c8c778c16f3f586/papi-v1/rules.go#L25-L32
146,381
akamai/AkamaiOPEN-edgegrid-golang
papi-v1/rules.go
Freeze
func (rules *Rules) Freeze(format string) error { rules.Errors = []*RuleErrors{} req, err := client.NewJSONRequest( Config, "PUT", fmt.Sprintf( "/papi/v1/properties/%s/versions/%d/rules", rules.PropertyID, rules.PropertyVersion, ), rules, ) if err != nil { return err } req.Header.Set("Content-Type", fmt.Sprintf("application/vnd.akamai.papirules.%s+json", format)) res, err := client.Do(Config, req) if err != nil { return err } if client.IsError(res) { return client.NewAPIError(res) } if err = client.BodyJSON(res, rules); err != nil { return err } if len(rules.Errors) != 0 { return ErrorMap[ErrInvalidRules] } return nil }
go
func (rules *Rules) Freeze(format string) error { rules.Errors = []*RuleErrors{} req, err := client.NewJSONRequest( Config, "PUT", fmt.Sprintf( "/papi/v1/properties/%s/versions/%d/rules", rules.PropertyID, rules.PropertyVersion, ), rules, ) if err != nil { return err } req.Header.Set("Content-Type", fmt.Sprintf("application/vnd.akamai.papirules.%s+json", format)) res, err := client.Do(Config, req) if err != nil { return err } if client.IsError(res) { return client.NewAPIError(res) } if err = client.BodyJSON(res, rules); err != nil { return err } if len(rules.Errors) != 0 { return ErrorMap[ErrInvalidRules] } return nil }
[ "func", "(", "rules", "*", "Rules", ")", "Freeze", "(", "format", "string", ")", "error", "{", "rules", ".", "Errors", "=", "[", "]", "*", "RuleErrors", "{", "}", "\n\n", "req", ",", "err", ":=", "client", ".", "NewJSONRequest", "(", "Config", ",", "\"", "\"", ",", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "rules", ".", "PropertyID", ",", "rules", ".", "PropertyVersion", ",", ")", ",", "rules", ",", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "req", ".", "Header", ".", "Set", "(", "\"", "\"", ",", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "format", ")", ")", "\n\n", "res", ",", "err", ":=", "client", ".", "Do", "(", "Config", ",", "req", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "if", "client", ".", "IsError", "(", "res", ")", "{", "return", "client", ".", "NewAPIError", "(", "res", ")", "\n", "}", "\n\n", "if", "err", "=", "client", ".", "BodyJSON", "(", "res", ",", "rules", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "if", "len", "(", "rules", ".", "Errors", ")", "!=", "0", "{", "return", "ErrorMap", "[", "ErrInvalidRules", "]", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// Freeze pins a properties rule set to a specific rule set version
[ "Freeze", "pins", "a", "properties", "rule", "set", "to", "a", "specific", "rule", "set", "version" ]
009960c8b2c7c57a0c5c488a3c8c778c16f3f586
https://github.com/akamai/AkamaiOPEN-edgegrid-golang/blob/009960c8b2c7c57a0c5c488a3c8c778c16f3f586/papi-v1/rules.go#L152-L189
146,382
akamai/AkamaiOPEN-edgegrid-golang
papi-v1/rules.go
MergeBehavior
func (rule *Rule) MergeBehavior(behavior *Behavior) { for _, existingBehavior := range rule.Behaviors { if existingBehavior.Name == behavior.Name { existingBehavior.MergeOptions(behavior.Options) return } } rule.Behaviors = append(rule.Behaviors, behavior) }
go
func (rule *Rule) MergeBehavior(behavior *Behavior) { for _, existingBehavior := range rule.Behaviors { if existingBehavior.Name == behavior.Name { existingBehavior.MergeOptions(behavior.Options) return } } rule.Behaviors = append(rule.Behaviors, behavior) }
[ "func", "(", "rule", "*", "Rule", ")", "MergeBehavior", "(", "behavior", "*", "Behavior", ")", "{", "for", "_", ",", "existingBehavior", ":=", "range", "rule", ".", "Behaviors", "{", "if", "existingBehavior", ".", "Name", "==", "behavior", ".", "Name", "{", "existingBehavior", ".", "MergeOptions", "(", "behavior", ".", "Options", ")", "\n", "return", "\n", "}", "\n", "}", "\n\n", "rule", ".", "Behaviors", "=", "append", "(", "rule", ".", "Behaviors", ",", "behavior", ")", "\n", "}" ]
// MergeBehavior merges a behavior into a rule // // If the behavior already exists, it's options are merged with the existing // options.
[ "MergeBehavior", "merges", "a", "behavior", "into", "a", "rule", "If", "the", "behavior", "already", "exists", "it", "s", "options", "are", "merged", "with", "the", "existing", "options", "." ]
009960c8b2c7c57a0c5c488a3c8c778c16f3f586
https://github.com/akamai/AkamaiOPEN-edgegrid-golang/blob/009960c8b2c7c57a0c5c488a3c8c778c16f3f586/papi-v1/rules.go#L225-L234
146,383
akamai/AkamaiOPEN-edgegrid-golang
papi-v1/rules.go
AddBehavior
func (rule *Rule) AddBehavior(behavior *Behavior) { for key, existingBehavior := range rule.Behaviors { if existingBehavior.Name == behavior.Name { rule.Behaviors[key] = behavior return } } rule.Behaviors = append(rule.Behaviors, behavior) }
go
func (rule *Rule) AddBehavior(behavior *Behavior) { for key, existingBehavior := range rule.Behaviors { if existingBehavior.Name == behavior.Name { rule.Behaviors[key] = behavior return } } rule.Behaviors = append(rule.Behaviors, behavior) }
[ "func", "(", "rule", "*", "Rule", ")", "AddBehavior", "(", "behavior", "*", "Behavior", ")", "{", "for", "key", ",", "existingBehavior", ":=", "range", "rule", ".", "Behaviors", "{", "if", "existingBehavior", ".", "Name", "==", "behavior", ".", "Name", "{", "rule", ".", "Behaviors", "[", "key", "]", "=", "behavior", "\n", "return", "\n", "}", "\n", "}", "\n\n", "rule", ".", "Behaviors", "=", "append", "(", "rule", ".", "Behaviors", ",", "behavior", ")", "\n", "}" ]
// AddBehavior adds a behavior to the rule // // If the behavior already exists it is replaced with the given behavior
[ "AddBehavior", "adds", "a", "behavior", "to", "the", "rule", "If", "the", "behavior", "already", "exists", "it", "is", "replaced", "with", "the", "given", "behavior" ]
009960c8b2c7c57a0c5c488a3c8c778c16f3f586
https://github.com/akamai/AkamaiOPEN-edgegrid-golang/blob/009960c8b2c7c57a0c5c488a3c8c778c16f3f586/papi-v1/rules.go#L239-L248
146,384
akamai/AkamaiOPEN-edgegrid-golang
papi-v1/rules.go
MergeCriteria
func (rule *Rule) MergeCriteria(criteria *Criteria) { for _, existingCriteria := range rule.Criteria { if existingCriteria.Name == criteria.Name { existingCriteria.MergeOptions(criteria.Options) return } } rule.Criteria = append(rule.Criteria, criteria) }
go
func (rule *Rule) MergeCriteria(criteria *Criteria) { for _, existingCriteria := range rule.Criteria { if existingCriteria.Name == criteria.Name { existingCriteria.MergeOptions(criteria.Options) return } } rule.Criteria = append(rule.Criteria, criteria) }
[ "func", "(", "rule", "*", "Rule", ")", "MergeCriteria", "(", "criteria", "*", "Criteria", ")", "{", "for", "_", ",", "existingCriteria", ":=", "range", "rule", ".", "Criteria", "{", "if", "existingCriteria", ".", "Name", "==", "criteria", ".", "Name", "{", "existingCriteria", ".", "MergeOptions", "(", "criteria", ".", "Options", ")", "\n", "return", "\n", "}", "\n", "}", "\n\n", "rule", ".", "Criteria", "=", "append", "(", "rule", ".", "Criteria", ",", "criteria", ")", "\n", "}" ]
// MergeCriteria merges a criteria into a rule // // If the criteria already exists, it's options are merged with the existing // options.
[ "MergeCriteria", "merges", "a", "criteria", "into", "a", "rule", "If", "the", "criteria", "already", "exists", "it", "s", "options", "are", "merged", "with", "the", "existing", "options", "." ]
009960c8b2c7c57a0c5c488a3c8c778c16f3f586
https://github.com/akamai/AkamaiOPEN-edgegrid-golang/blob/009960c8b2c7c57a0c5c488a3c8c778c16f3f586/papi-v1/rules.go#L254-L263
146,385
akamai/AkamaiOPEN-edgegrid-golang
papi-v1/rules.go
AddCriteria
func (rule *Rule) AddCriteria(criteria *Criteria) { for key, existingCriteria := range rule.Criteria { if existingCriteria.Name == criteria.Name { rule.Criteria[key] = criteria return } } rule.Criteria = append(rule.Criteria, criteria) }
go
func (rule *Rule) AddCriteria(criteria *Criteria) { for key, existingCriteria := range rule.Criteria { if existingCriteria.Name == criteria.Name { rule.Criteria[key] = criteria return } } rule.Criteria = append(rule.Criteria, criteria) }
[ "func", "(", "rule", "*", "Rule", ")", "AddCriteria", "(", "criteria", "*", "Criteria", ")", "{", "for", "key", ",", "existingCriteria", ":=", "range", "rule", ".", "Criteria", "{", "if", "existingCriteria", ".", "Name", "==", "criteria", ".", "Name", "{", "rule", ".", "Criteria", "[", "key", "]", "=", "criteria", "\n", "return", "\n", "}", "\n", "}", "\n\n", "rule", ".", "Criteria", "=", "append", "(", "rule", ".", "Criteria", ",", "criteria", ")", "\n", "}" ]
// AddCriteria add a criteria to a rule // // If the criteria already exists, it is replaced with the given criteria.
[ "AddCriteria", "add", "a", "criteria", "to", "a", "rule", "If", "the", "criteria", "already", "exists", "it", "is", "replaced", "with", "the", "given", "criteria", "." ]
009960c8b2c7c57a0c5c488a3c8c778c16f3f586
https://github.com/akamai/AkamaiOPEN-edgegrid-golang/blob/009960c8b2c7c57a0c5c488a3c8c778c16f3f586/papi-v1/rules.go#L268-L277
146,386
akamai/AkamaiOPEN-edgegrid-golang
papi-v1/rules.go
MergeChildRule
func (rule *Rule) MergeChildRule(childRule *Rule) { for key, existingChildRule := range rule.Children { if existingChildRule.Name == childRule.Name { for _, behavior := range childRule.Behaviors { rule.Children[key].MergeBehavior(behavior) } for _, criteria := range childRule.Criteria { rule.Children[key].MergeCriteria(criteria) } for _, child := range childRule.Children { rule.Children[key].MergeChildRule(child) } return } } rule.Children = append(rule.Children, childRule) }
go
func (rule *Rule) MergeChildRule(childRule *Rule) { for key, existingChildRule := range rule.Children { if existingChildRule.Name == childRule.Name { for _, behavior := range childRule.Behaviors { rule.Children[key].MergeBehavior(behavior) } for _, criteria := range childRule.Criteria { rule.Children[key].MergeCriteria(criteria) } for _, child := range childRule.Children { rule.Children[key].MergeChildRule(child) } return } } rule.Children = append(rule.Children, childRule) }
[ "func", "(", "rule", "*", "Rule", ")", "MergeChildRule", "(", "childRule", "*", "Rule", ")", "{", "for", "key", ",", "existingChildRule", ":=", "range", "rule", ".", "Children", "{", "if", "existingChildRule", ".", "Name", "==", "childRule", ".", "Name", "{", "for", "_", ",", "behavior", ":=", "range", "childRule", ".", "Behaviors", "{", "rule", ".", "Children", "[", "key", "]", ".", "MergeBehavior", "(", "behavior", ")", "\n", "}", "\n\n", "for", "_", ",", "criteria", ":=", "range", "childRule", ".", "Criteria", "{", "rule", ".", "Children", "[", "key", "]", ".", "MergeCriteria", "(", "criteria", ")", "\n", "}", "\n\n", "for", "_", ",", "child", ":=", "range", "childRule", ".", "Children", "{", "rule", ".", "Children", "[", "key", "]", ".", "MergeChildRule", "(", "child", ")", "\n", "}", "\n\n", "return", "\n", "}", "\n", "}", "\n\n", "rule", ".", "Children", "=", "append", "(", "rule", ".", "Children", ",", "childRule", ")", "\n", "}" ]
// MergeChildRule adds a child rule to this rule // // If the rule already exists, criteria, behaviors, and child rules are added to // the existing rule.
[ "MergeChildRule", "adds", "a", "child", "rule", "to", "this", "rule", "If", "the", "rule", "already", "exists", "criteria", "behaviors", "and", "child", "rules", "are", "added", "to", "the", "existing", "rule", "." ]
009960c8b2c7c57a0c5c488a3c8c778c16f3f586
https://github.com/akamai/AkamaiOPEN-edgegrid-golang/blob/009960c8b2c7c57a0c5c488a3c8c778c16f3f586/papi-v1/rules.go#L283-L303
146,387
akamai/AkamaiOPEN-edgegrid-golang
papi-v1/rules.go
AddChildRule
func (rule *Rule) AddChildRule(childRule *Rule) { for key, existingChildRule := range rule.Children { if existingChildRule.Name == childRule.Name { rule.Children[key] = childRule return } } rule.Children = append(rule.Children, childRule) }
go
func (rule *Rule) AddChildRule(childRule *Rule) { for key, existingChildRule := range rule.Children { if existingChildRule.Name == childRule.Name { rule.Children[key] = childRule return } } rule.Children = append(rule.Children, childRule) }
[ "func", "(", "rule", "*", "Rule", ")", "AddChildRule", "(", "childRule", "*", "Rule", ")", "{", "for", "key", ",", "existingChildRule", ":=", "range", "rule", ".", "Children", "{", "if", "existingChildRule", ".", "Name", "==", "childRule", ".", "Name", "{", "rule", ".", "Children", "[", "key", "]", "=", "childRule", "\n\n", "return", "\n", "}", "\n", "}", "\n\n", "rule", ".", "Children", "=", "append", "(", "rule", ".", "Children", ",", "childRule", ")", "\n", "}" ]
// AddChildRule adds a rule as a child of this rule // // If the rule already exists, it is replaced by the given rule.
[ "AddChildRule", "adds", "a", "rule", "as", "a", "child", "of", "this", "rule", "If", "the", "rule", "already", "exists", "it", "is", "replaced", "by", "the", "given", "rule", "." ]
009960c8b2c7c57a0c5c488a3c8c778c16f3f586
https://github.com/akamai/AkamaiOPEN-edgegrid-golang/blob/009960c8b2c7c57a0c5c488a3c8c778c16f3f586/papi-v1/rules.go#L308-L318
146,388
akamai/AkamaiOPEN-edgegrid-golang
papi-v1/rules.go
AddVariable
func (rule *Rule) AddVariable(variable *Variable) { for key, existingVariable := range rule.Variables { if existingVariable.Name == variable.Name { rule.Variables[key] = variable return } } rule.Variables = append(rule.Variables, variable) }
go
func (rule *Rule) AddVariable(variable *Variable) { for key, existingVariable := range rule.Variables { if existingVariable.Name == variable.Name { rule.Variables[key] = variable return } } rule.Variables = append(rule.Variables, variable) }
[ "func", "(", "rule", "*", "Rule", ")", "AddVariable", "(", "variable", "*", "Variable", ")", "{", "for", "key", ",", "existingVariable", ":=", "range", "rule", ".", "Variables", "{", "if", "existingVariable", ".", "Name", "==", "variable", ".", "Name", "{", "rule", ".", "Variables", "[", "key", "]", "=", "variable", "\n\n", "return", "\n", "}", "\n", "}", "\n\n", "rule", ".", "Variables", "=", "append", "(", "rule", ".", "Variables", ",", "variable", ")", "\n", "}" ]
// AddVariable adds a variable as a child of this rule // // If the rule already exists, it is replaced by the given rule.
[ "AddVariable", "adds", "a", "variable", "as", "a", "child", "of", "this", "rule", "If", "the", "rule", "already", "exists", "it", "is", "replaced", "by", "the", "given", "rule", "." ]
009960c8b2c7c57a0c5c488a3c8c778c16f3f586
https://github.com/akamai/AkamaiOPEN-edgegrid-golang/blob/009960c8b2c7c57a0c5c488a3c8c778c16f3f586/papi-v1/rules.go#L323-L333
146,389
akamai/AkamaiOPEN-edgegrid-golang
papi-v1/rules.go
FindBehavior
func (rules *Rules) FindBehavior(path string) (*Behavior, error) { if len(path) <= 1 { return nil, ErrorMap[ErrInvalidPath] } rule, err := rules.FindParentRule(path) if err != nil { return nil, err } sep := "/" segments := strings.Split(path, sep) behaviorName := strings.ToLower(segments[len(segments)-1]) for _, behavior := range rule.Behaviors { if strings.ToLower(behavior.Name) == behaviorName { return behavior, nil } } return nil, ErrorMap[ErrBehaviorNotFound] }
go
func (rules *Rules) FindBehavior(path string) (*Behavior, error) { if len(path) <= 1 { return nil, ErrorMap[ErrInvalidPath] } rule, err := rules.FindParentRule(path) if err != nil { return nil, err } sep := "/" segments := strings.Split(path, sep) behaviorName := strings.ToLower(segments[len(segments)-1]) for _, behavior := range rule.Behaviors { if strings.ToLower(behavior.Name) == behaviorName { return behavior, nil } } return nil, ErrorMap[ErrBehaviorNotFound] }
[ "func", "(", "rules", "*", "Rules", ")", "FindBehavior", "(", "path", "string", ")", "(", "*", "Behavior", ",", "error", ")", "{", "if", "len", "(", "path", ")", "<=", "1", "{", "return", "nil", ",", "ErrorMap", "[", "ErrInvalidPath", "]", "\n", "}", "\n\n", "rule", ",", "err", ":=", "rules", ".", "FindParentRule", "(", "path", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "sep", ":=", "\"", "\"", "\n", "segments", ":=", "strings", ".", "Split", "(", "path", ",", "sep", ")", "\n", "behaviorName", ":=", "strings", ".", "ToLower", "(", "segments", "[", "len", "(", "segments", ")", "-", "1", "]", ")", "\n", "for", "_", ",", "behavior", ":=", "range", "rule", ".", "Behaviors", "{", "if", "strings", ".", "ToLower", "(", "behavior", ".", "Name", ")", "==", "behaviorName", "{", "return", "behavior", ",", "nil", "\n", "}", "\n", "}", "\n\n", "return", "nil", ",", "ErrorMap", "[", "ErrBehaviorNotFound", "]", "\n", "}" ]
// FindBehavior locates a specific behavior by path
[ "FindBehavior", "locates", "a", "specific", "behavior", "by", "path" ]
009960c8b2c7c57a0c5c488a3c8c778c16f3f586
https://github.com/akamai/AkamaiOPEN-edgegrid-golang/blob/009960c8b2c7c57a0c5c488a3c8c778c16f3f586/papi-v1/rules.go#L336-L356
146,390
akamai/AkamaiOPEN-edgegrid-golang
papi-v1/rules.go
FindCriteria
func (rules *Rules) FindCriteria(path string) (*Criteria, error) { if len(path) <= 1 { return nil, ErrorMap[ErrInvalidPath] } rule, err := rules.FindParentRule(path) if err != nil { return nil, err } sep := "/" segments := strings.Split(path, sep) criteriaName := strings.ToLower(segments[len(segments)-1]) for _, criteria := range rule.Criteria { if strings.ToLower(criteria.Name) == criteriaName { return criteria, nil } } return nil, ErrorMap[ErrCriteriaNotFound] }
go
func (rules *Rules) FindCriteria(path string) (*Criteria, error) { if len(path) <= 1 { return nil, ErrorMap[ErrInvalidPath] } rule, err := rules.FindParentRule(path) if err != nil { return nil, err } sep := "/" segments := strings.Split(path, sep) criteriaName := strings.ToLower(segments[len(segments)-1]) for _, criteria := range rule.Criteria { if strings.ToLower(criteria.Name) == criteriaName { return criteria, nil } } return nil, ErrorMap[ErrCriteriaNotFound] }
[ "func", "(", "rules", "*", "Rules", ")", "FindCriteria", "(", "path", "string", ")", "(", "*", "Criteria", ",", "error", ")", "{", "if", "len", "(", "path", ")", "<=", "1", "{", "return", "nil", ",", "ErrorMap", "[", "ErrInvalidPath", "]", "\n", "}", "\n\n", "rule", ",", "err", ":=", "rules", ".", "FindParentRule", "(", "path", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "sep", ":=", "\"", "\"", "\n", "segments", ":=", "strings", ".", "Split", "(", "path", ",", "sep", ")", "\n", "criteriaName", ":=", "strings", ".", "ToLower", "(", "segments", "[", "len", "(", "segments", ")", "-", "1", "]", ")", "\n", "for", "_", ",", "criteria", ":=", "range", "rule", ".", "Criteria", "{", "if", "strings", ".", "ToLower", "(", "criteria", ".", "Name", ")", "==", "criteriaName", "{", "return", "criteria", ",", "nil", "\n", "}", "\n", "}", "\n\n", "return", "nil", ",", "ErrorMap", "[", "ErrCriteriaNotFound", "]", "\n", "}" ]
// FindCriteria locates a specific Critieria by path
[ "FindCriteria", "locates", "a", "specific", "Critieria", "by", "path" ]
009960c8b2c7c57a0c5c488a3c8c778c16f3f586
https://github.com/akamai/AkamaiOPEN-edgegrid-golang/blob/009960c8b2c7c57a0c5c488a3c8c778c16f3f586/papi-v1/rules.go#L359-L379
146,391
akamai/AkamaiOPEN-edgegrid-golang
papi-v1/rules.go
FindVariable
func (rules *Rules) FindVariable(path string) (*Variable, error) { if len(path) <= 1 { return nil, ErrorMap[ErrInvalidPath] } rule, err := rules.FindParentRule(path) if err != nil { return nil, err } sep := "/" segments := strings.Split(path, sep) variableName := strings.ToLower(segments[len(segments)-1]) for _, variable := range rule.Variables { if strings.ToLower(variable.Name) == variableName { return variable, nil } } return nil, ErrorMap[ErrVariableNotFound] }
go
func (rules *Rules) FindVariable(path string) (*Variable, error) { if len(path) <= 1 { return nil, ErrorMap[ErrInvalidPath] } rule, err := rules.FindParentRule(path) if err != nil { return nil, err } sep := "/" segments := strings.Split(path, sep) variableName := strings.ToLower(segments[len(segments)-1]) for _, variable := range rule.Variables { if strings.ToLower(variable.Name) == variableName { return variable, nil } } return nil, ErrorMap[ErrVariableNotFound] }
[ "func", "(", "rules", "*", "Rules", ")", "FindVariable", "(", "path", "string", ")", "(", "*", "Variable", ",", "error", ")", "{", "if", "len", "(", "path", ")", "<=", "1", "{", "return", "nil", ",", "ErrorMap", "[", "ErrInvalidPath", "]", "\n", "}", "\n\n", "rule", ",", "err", ":=", "rules", ".", "FindParentRule", "(", "path", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "sep", ":=", "\"", "\"", "\n", "segments", ":=", "strings", ".", "Split", "(", "path", ",", "sep", ")", "\n", "variableName", ":=", "strings", ".", "ToLower", "(", "segments", "[", "len", "(", "segments", ")", "-", "1", "]", ")", "\n", "for", "_", ",", "variable", ":=", "range", "rule", ".", "Variables", "{", "if", "strings", ".", "ToLower", "(", "variable", ".", "Name", ")", "==", "variableName", "{", "return", "variable", ",", "nil", "\n", "}", "\n", "}", "\n\n", "return", "nil", ",", "ErrorMap", "[", "ErrVariableNotFound", "]", "\n", "}" ]
// FindVariable locates a specific Variable by path
[ "FindVariable", "locates", "a", "specific", "Variable", "by", "path" ]
009960c8b2c7c57a0c5c488a3c8c778c16f3f586
https://github.com/akamai/AkamaiOPEN-edgegrid-golang/blob/009960c8b2c7c57a0c5c488a3c8c778c16f3f586/papi-v1/rules.go#L382-L402
146,392
akamai/AkamaiOPEN-edgegrid-golang
papi-v1/rules.go
FindRule
func (rules *Rules) FindRule(path string) (*Rule, error) { if path == "" { return rules.Rule, nil } sep := "/" segments := strings.Split(path, sep) currentRule := rules.Rule for _, segment := range segments { found := false for _, rule := range currentRule.Children { if strings.ToLower(rule.Name) == segment { currentRule = rule found = true } } if found != true { return nil, ErrorMap[ErrRuleNotFound] } } return currentRule, nil }
go
func (rules *Rules) FindRule(path string) (*Rule, error) { if path == "" { return rules.Rule, nil } sep := "/" segments := strings.Split(path, sep) currentRule := rules.Rule for _, segment := range segments { found := false for _, rule := range currentRule.Children { if strings.ToLower(rule.Name) == segment { currentRule = rule found = true } } if found != true { return nil, ErrorMap[ErrRuleNotFound] } } return currentRule, nil }
[ "func", "(", "rules", "*", "Rules", ")", "FindRule", "(", "path", "string", ")", "(", "*", "Rule", ",", "error", ")", "{", "if", "path", "==", "\"", "\"", "{", "return", "rules", ".", "Rule", ",", "nil", "\n", "}", "\n\n", "sep", ":=", "\"", "\"", "\n", "segments", ":=", "strings", ".", "Split", "(", "path", ",", "sep", ")", "\n\n", "currentRule", ":=", "rules", ".", "Rule", "\n", "for", "_", ",", "segment", ":=", "range", "segments", "{", "found", ":=", "false", "\n", "for", "_", ",", "rule", ":=", "range", "currentRule", ".", "Children", "{", "if", "strings", ".", "ToLower", "(", "rule", ".", "Name", ")", "==", "segment", "{", "currentRule", "=", "rule", "\n", "found", "=", "true", "\n", "}", "\n", "}", "\n", "if", "found", "!=", "true", "{", "return", "nil", ",", "ErrorMap", "[", "ErrRuleNotFound", "]", "\n", "}", "\n", "}", "\n\n", "return", "currentRule", ",", "nil", "\n", "}" ]
// FindRule locates a specific rule by path
[ "FindRule", "locates", "a", "specific", "rule", "by", "path" ]
009960c8b2c7c57a0c5c488a3c8c778c16f3f586
https://github.com/akamai/AkamaiOPEN-edgegrid-golang/blob/009960c8b2c7c57a0c5c488a3c8c778c16f3f586/papi-v1/rules.go#L405-L428
146,393
akamai/AkamaiOPEN-edgegrid-golang
papi-v1/rules.go
FindParentRule
func (rules *Rules) FindParentRule(path string) (*Rule, error) { sep := "/" segments := strings.Split(strings.ToLower(strings.TrimPrefix(path, sep)), sep) parentPath := strings.Join(segments[0:len(segments)-1], sep) return rules.FindRule(parentPath) }
go
func (rules *Rules) FindParentRule(path string) (*Rule, error) { sep := "/" segments := strings.Split(strings.ToLower(strings.TrimPrefix(path, sep)), sep) parentPath := strings.Join(segments[0:len(segments)-1], sep) return rules.FindRule(parentPath) }
[ "func", "(", "rules", "*", "Rules", ")", "FindParentRule", "(", "path", "string", ")", "(", "*", "Rule", ",", "error", ")", "{", "sep", ":=", "\"", "\"", "\n", "segments", ":=", "strings", ".", "Split", "(", "strings", ".", "ToLower", "(", "strings", ".", "TrimPrefix", "(", "path", ",", "sep", ")", ")", ",", "sep", ")", "\n", "parentPath", ":=", "strings", ".", "Join", "(", "segments", "[", "0", ":", "len", "(", "segments", ")", "-", "1", "]", ",", "sep", ")", "\n\n", "return", "rules", ".", "FindRule", "(", "parentPath", ")", "\n", "}" ]
// Find the parent rule for a given rule, criteria, or behavior path
[ "Find", "the", "parent", "rule", "for", "a", "given", "rule", "criteria", "or", "behavior", "path" ]
009960c8b2c7c57a0c5c488a3c8c778c16f3f586
https://github.com/akamai/AkamaiOPEN-edgegrid-golang/blob/009960c8b2c7c57a0c5c488a3c8c778c16f3f586/papi-v1/rules.go#L431-L437
146,394
akamai/AkamaiOPEN-edgegrid-golang
edgegrid/signer.go
AddRequestHeader
func AddRequestHeader(config Config, req *http.Request) *http.Request { if config.Debug { log.SetLevel(log.DebugLevel) } timestamp := makeEdgeTimeStamp() nonce := createNonce() if req.Header.Get("Content-Type") == "" { req.Header.Set("Content-Type", "application/json") } _, AkamaiCliEnvOK := os.LookupEnv("AKAMAI_CLI") AkamaiCliVersionEnv, AkamaiCliVersionEnvOK := os.LookupEnv("AKAMAI_CLI_VERSION") AkamaiCliCommandEnv, AkamaiCliCommandEnvOK := os.LookupEnv("AKAMAI_CLI_COMMAND") AkamaiCliCommandVersionEnv, AkamaiCliCommandVersionEnvOK := os.LookupEnv("AKAMAI_CLI_COMMAND_VERSION") if AkamaiCliEnvOK && AkamaiCliVersionEnvOK { if req.Header.Get("User-Agent") != "" { req.Header.Set("User-Agent", req.Header.Get("User-Agent")+" AkamaiCLI/"+AkamaiCliVersionEnv) } else { req.Header.Set("User-Agent", "AkamaiCLI/"+AkamaiCliVersionEnv) } } if AkamaiCliCommandEnvOK && AkamaiCliCommandVersionEnvOK { if req.Header.Get("User-Agent") != "" { req.Header.Set("User-Agent", req.Header.Get("User-Agent")+" AkamaiCLI-"+AkamaiCliCommandEnv+"/"+AkamaiCliCommandVersionEnv) } else { req.Header.Set("User-Agent", "AkamaiCLI-"+AkamaiCliCommandEnv+"/"+AkamaiCliCommandVersionEnv) } } req.Header.Set("Authorization", createAuthHeader(config, req, timestamp, nonce)) return req }
go
func AddRequestHeader(config Config, req *http.Request) *http.Request { if config.Debug { log.SetLevel(log.DebugLevel) } timestamp := makeEdgeTimeStamp() nonce := createNonce() if req.Header.Get("Content-Type") == "" { req.Header.Set("Content-Type", "application/json") } _, AkamaiCliEnvOK := os.LookupEnv("AKAMAI_CLI") AkamaiCliVersionEnv, AkamaiCliVersionEnvOK := os.LookupEnv("AKAMAI_CLI_VERSION") AkamaiCliCommandEnv, AkamaiCliCommandEnvOK := os.LookupEnv("AKAMAI_CLI_COMMAND") AkamaiCliCommandVersionEnv, AkamaiCliCommandVersionEnvOK := os.LookupEnv("AKAMAI_CLI_COMMAND_VERSION") if AkamaiCliEnvOK && AkamaiCliVersionEnvOK { if req.Header.Get("User-Agent") != "" { req.Header.Set("User-Agent", req.Header.Get("User-Agent")+" AkamaiCLI/"+AkamaiCliVersionEnv) } else { req.Header.Set("User-Agent", "AkamaiCLI/"+AkamaiCliVersionEnv) } } if AkamaiCliCommandEnvOK && AkamaiCliCommandVersionEnvOK { if req.Header.Get("User-Agent") != "" { req.Header.Set("User-Agent", req.Header.Get("User-Agent")+" AkamaiCLI-"+AkamaiCliCommandEnv+"/"+AkamaiCliCommandVersionEnv) } else { req.Header.Set("User-Agent", "AkamaiCLI-"+AkamaiCliCommandEnv+"/"+AkamaiCliCommandVersionEnv) } } req.Header.Set("Authorization", createAuthHeader(config, req, timestamp, nonce)) return req }
[ "func", "AddRequestHeader", "(", "config", "Config", ",", "req", "*", "http", ".", "Request", ")", "*", "http", ".", "Request", "{", "if", "config", ".", "Debug", "{", "log", ".", "SetLevel", "(", "log", ".", "DebugLevel", ")", "\n", "}", "\n", "timestamp", ":=", "makeEdgeTimeStamp", "(", ")", "\n", "nonce", ":=", "createNonce", "(", ")", "\n\n", "if", "req", ".", "Header", ".", "Get", "(", "\"", "\"", ")", "==", "\"", "\"", "{", "req", ".", "Header", ".", "Set", "(", "\"", "\"", ",", "\"", "\"", ")", "\n", "}", "\n\n", "_", ",", "AkamaiCliEnvOK", ":=", "os", ".", "LookupEnv", "(", "\"", "\"", ")", "\n", "AkamaiCliVersionEnv", ",", "AkamaiCliVersionEnvOK", ":=", "os", ".", "LookupEnv", "(", "\"", "\"", ")", "\n", "AkamaiCliCommandEnv", ",", "AkamaiCliCommandEnvOK", ":=", "os", ".", "LookupEnv", "(", "\"", "\"", ")", "\n", "AkamaiCliCommandVersionEnv", ",", "AkamaiCliCommandVersionEnvOK", ":=", "os", ".", "LookupEnv", "(", "\"", "\"", ")", "\n\n", "if", "AkamaiCliEnvOK", "&&", "AkamaiCliVersionEnvOK", "{", "if", "req", ".", "Header", ".", "Get", "(", "\"", "\"", ")", "!=", "\"", "\"", "{", "req", ".", "Header", ".", "Set", "(", "\"", "\"", ",", "req", ".", "Header", ".", "Get", "(", "\"", "\"", ")", "+", "\"", "\"", "+", "AkamaiCliVersionEnv", ")", "\n", "}", "else", "{", "req", ".", "Header", ".", "Set", "(", "\"", "\"", ",", "\"", "\"", "+", "AkamaiCliVersionEnv", ")", "\n", "}", "\n", "}", "\n", "if", "AkamaiCliCommandEnvOK", "&&", "AkamaiCliCommandVersionEnvOK", "{", "if", "req", ".", "Header", ".", "Get", "(", "\"", "\"", ")", "!=", "\"", "\"", "{", "req", ".", "Header", ".", "Set", "(", "\"", "\"", ",", "req", ".", "Header", ".", "Get", "(", "\"", "\"", ")", "+", "\"", "\"", "+", "AkamaiCliCommandEnv", "+", "\"", "\"", "+", "AkamaiCliCommandVersionEnv", ")", "\n", "}", "else", "{", "req", ".", "Header", ".", "Set", "(", "\"", "\"", ",", "\"", "\"", "+", "AkamaiCliCommandEnv", "+", "\"", "\"", "+", "AkamaiCliCommandVersionEnv", ")", "\n", "}", "\n", "}", "\n\n", "req", ".", "Header", ".", "Set", "(", "\"", "\"", ",", "createAuthHeader", "(", "config", ",", "req", ",", "timestamp", ",", "nonce", ")", ")", "\n", "return", "req", "\n", "}" ]
// AddRequestHeader sets the Authorization header to use Akamai Open API
[ "AddRequestHeader", "sets", "the", "Authorization", "header", "to", "use", "Akamai", "Open", "API" ]
009960c8b2c7c57a0c5c488a3c8c778c16f3f586
https://github.com/akamai/AkamaiOPEN-edgegrid-golang/blob/009960c8b2c7c57a0c5c488a3c8c778c16f3f586/edgegrid/signer.go#L25-L58
146,395
akamai/AkamaiOPEN-edgegrid-golang
papi-v1/cpcodes.go
ID
func (cpcode *CpCode) ID() int { id, err := strconv.Atoi(strings.TrimPrefix(cpcode.CpcodeID, "cpc_")) if err != nil { return 0 } return id }
go
func (cpcode *CpCode) ID() int { id, err := strconv.Atoi(strings.TrimPrefix(cpcode.CpcodeID, "cpc_")) if err != nil { return 0 } return id }
[ "func", "(", "cpcode", "*", "CpCode", ")", "ID", "(", ")", "int", "{", "id", ",", "err", ":=", "strconv", ".", "Atoi", "(", "strings", ".", "TrimPrefix", "(", "cpcode", ".", "CpcodeID", ",", "\"", "\"", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "0", "\n", "}", "\n\n", "return", "id", "\n", "}" ]
// ID retrieves a CP Codes integer ID // // PAPI Behaviors require the integer ID, rather than the prefixed string returned
[ "ID", "retrieves", "a", "CP", "Codes", "integer", "ID", "PAPI", "Behaviors", "require", "the", "integer", "ID", "rather", "than", "the", "prefixed", "string", "returned" ]
009960c8b2c7c57a0c5c488a3c8c778c16f3f586
https://github.com/akamai/AkamaiOPEN-edgegrid-golang/blob/009960c8b2c7c57a0c5c488a3c8c778c16f3f586/papi-v1/cpcodes.go#L217-L224
146,396
akamai/AkamaiOPEN-edgegrid-golang
papi-v1/contracts.go
FindContract
func (contracts *Contracts) FindContract(id string) (*Contract, error) { var contract *Contract var contractFound bool for _, contract = range contracts.Contracts.Items { if contract.ContractID == id { contractFound = true break } } if !contractFound { return nil, fmt.Errorf("Unable to find contract: \"%s\"", id) } return contract, nil }
go
func (contracts *Contracts) FindContract(id string) (*Contract, error) { var contract *Contract var contractFound bool for _, contract = range contracts.Contracts.Items { if contract.ContractID == id { contractFound = true break } } if !contractFound { return nil, fmt.Errorf("Unable to find contract: \"%s\"", id) } return contract, nil }
[ "func", "(", "contracts", "*", "Contracts", ")", "FindContract", "(", "id", "string", ")", "(", "*", "Contract", ",", "error", ")", "{", "var", "contract", "*", "Contract", "\n", "var", "contractFound", "bool", "\n", "for", "_", ",", "contract", "=", "range", "contracts", ".", "Contracts", ".", "Items", "{", "if", "contract", ".", "ContractID", "==", "id", "{", "contractFound", "=", "true", "\n", "break", "\n", "}", "\n", "}", "\n\n", "if", "!", "contractFound", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\\\"", "\\\"", "\"", ",", "id", ")", "\n", "}", "\n\n", "return", "contract", ",", "nil", "\n", "}" ]
// FindContract finds a specific contract by ID
[ "FindContract", "finds", "a", "specific", "contract", "by", "ID" ]
009960c8b2c7c57a0c5c488a3c8c778c16f3f586
https://github.com/akamai/AkamaiOPEN-edgegrid-golang/blob/009960c8b2c7c57a0c5c488a3c8c778c16f3f586/papi-v1/contracts.go#L79-L94
146,397
akamai/AkamaiOPEN-edgegrid-golang
papi-v1/contracts.go
NewContract
func NewContract(parent *Contracts) *Contract { contract := &Contract{ parent: parent, } contract.Init() return contract }
go
func NewContract(parent *Contracts) *Contract { contract := &Contract{ parent: parent, } contract.Init() return contract }
[ "func", "NewContract", "(", "parent", "*", "Contracts", ")", "*", "Contract", "{", "contract", ":=", "&", "Contract", "{", "parent", ":", "parent", ",", "}", "\n", "contract", ".", "Init", "(", ")", "\n", "return", "contract", "\n", "}" ]
// NewContract creates a new Contract
[ "NewContract", "creates", "a", "new", "Contract" ]
009960c8b2c7c57a0c5c488a3c8c778c16f3f586
https://github.com/akamai/AkamaiOPEN-edgegrid-golang/blob/009960c8b2c7c57a0c5c488a3c8c778c16f3f586/papi-v1/contracts.go#L105-L111
146,398
akamai/AkamaiOPEN-edgegrid-golang
papi-v1/contracts.go
GetContract
func (contract *Contract) GetContract() error { contracts, err := GetContracts() if err != nil { return err } for _, c := range contracts.Contracts.Items { if c.ContractID == contract.ContractID { contract.parent = c.parent contract.ContractTypeName = c.ContractTypeName contract.Complete <- true return nil } } contract.Complete <- false return fmt.Errorf("contract \"%s\" not found", contract.ContractID) }
go
func (contract *Contract) GetContract() error { contracts, err := GetContracts() if err != nil { return err } for _, c := range contracts.Contracts.Items { if c.ContractID == contract.ContractID { contract.parent = c.parent contract.ContractTypeName = c.ContractTypeName contract.Complete <- true return nil } } contract.Complete <- false return fmt.Errorf("contract \"%s\" not found", contract.ContractID) }
[ "func", "(", "contract", "*", "Contract", ")", "GetContract", "(", ")", "error", "{", "contracts", ",", "err", ":=", "GetContracts", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "for", "_", ",", "c", ":=", "range", "contracts", ".", "Contracts", ".", "Items", "{", "if", "c", ".", "ContractID", "==", "contract", ".", "ContractID", "{", "contract", ".", "parent", "=", "c", ".", "parent", "\n", "contract", ".", "ContractTypeName", "=", "c", ".", "ContractTypeName", "\n", "contract", ".", "Complete", "<-", "true", "\n", "return", "nil", "\n", "}", "\n", "}", "\n", "contract", ".", "Complete", "<-", "false", "\n", "return", "fmt", ".", "Errorf", "(", "\"", "\\\"", "\\\"", "\"", ",", "contract", ".", "ContractID", ")", "\n", "}" ]
// GetContract populates a Contract
[ "GetContract", "populates", "a", "Contract" ]
009960c8b2c7c57a0c5c488a3c8c778c16f3f586
https://github.com/akamai/AkamaiOPEN-edgegrid-golang/blob/009960c8b2c7c57a0c5c488a3c8c778c16f3f586/papi-v1/contracts.go#L114-L130
146,399
akamai/AkamaiOPEN-edgegrid-golang
papi-v1/contracts.go
GetProducts
func (contract *Contract) GetProducts() (*Products, error) { req, err := client.NewRequest( Config, "GET", fmt.Sprintf( "/papi/v1/products?contractId=%s", contract.ContractID, ), nil, ) if err != nil { return nil, err } res, err := client.Do(Config, req) if err != nil { return nil, err } if client.IsError(res) { return nil, client.NewAPIError(res) } products := NewProducts() if err = client.BodyJSON(res, products); err != nil { return nil, err } return products, nil }
go
func (contract *Contract) GetProducts() (*Products, error) { req, err := client.NewRequest( Config, "GET", fmt.Sprintf( "/papi/v1/products?contractId=%s", contract.ContractID, ), nil, ) if err != nil { return nil, err } res, err := client.Do(Config, req) if err != nil { return nil, err } if client.IsError(res) { return nil, client.NewAPIError(res) } products := NewProducts() if err = client.BodyJSON(res, products); err != nil { return nil, err } return products, nil }
[ "func", "(", "contract", "*", "Contract", ")", "GetProducts", "(", ")", "(", "*", "Products", ",", "error", ")", "{", "req", ",", "err", ":=", "client", ".", "NewRequest", "(", "Config", ",", "\"", "\"", ",", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "contract", ".", "ContractID", ",", ")", ",", "nil", ",", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "res", ",", "err", ":=", "client", ".", "Do", "(", "Config", ",", "req", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "if", "client", ".", "IsError", "(", "res", ")", "{", "return", "nil", ",", "client", ".", "NewAPIError", "(", "res", ")", "\n", "}", "\n\n", "products", ":=", "NewProducts", "(", ")", "\n", "if", "err", "=", "client", ".", "BodyJSON", "(", "res", ",", "products", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "products", ",", "nil", "\n", "}" ]
// GetProducts gets products associated with a contract
[ "GetProducts", "gets", "products", "associated", "with", "a", "contract" ]
009960c8b2c7c57a0c5c488a3c8c778c16f3f586
https://github.com/akamai/AkamaiOPEN-edgegrid-golang/blob/009960c8b2c7c57a0c5c488a3c8c778c16f3f586/papi-v1/contracts.go#L133-L162