repo
stringlengths
5
54
path
stringlengths
4
155
func_name
stringlengths
1
118
original_string
stringlengths
52
85.5k
language
stringclasses
1 value
code
stringlengths
52
85.5k
code_tokens
list
docstring
stringlengths
6
2.61k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
85
252
partition
stringclasses
1 value
gobuffalo/packr
v2/pointer.go
Resolve
func (p Pointer) Resolve(box string, path string) (file.File, error) { plog.Debug(p, "Resolve", "box", box, "path", path, "forward-box", p.ForwardBox, "forward-path", p.ForwardPath) b, err := findBox(p.ForwardBox) if err != nil { return nil, err } f, err := b.Resolve(p.ForwardPath) if err != nil { return f, e...
go
func (p Pointer) Resolve(box string, path string) (file.File, error) { plog.Debug(p, "Resolve", "box", box, "path", path, "forward-box", p.ForwardBox, "forward-path", p.ForwardPath) b, err := findBox(p.ForwardBox) if err != nil { return nil, err } f, err := b.Resolve(p.ForwardPath) if err != nil { return f, e...
[ "func", "(", "p", "Pointer", ")", "Resolve", "(", "box", "string", ",", "path", "string", ")", "(", "file", ".", "File", ",", "error", ")", "{", "plog", ".", "Debug", "(", "p", ",", "\"", "\"", ",", "\"", "\"", ",", "box", ",", "\"", "\"", ",...
// Resolve attempts to find the file in the specific box // with the specified key
[ "Resolve", "attempts", "to", "find", "the", "file", "in", "the", "specific", "box", "with", "the", "specified", "key" ]
9819ef1571983a956c49475cb0524d8a4971620f
https://github.com/gobuffalo/packr/blob/9819ef1571983a956c49475cb0524d8a4971620f/v2/pointer.go#L21-L33
train
gobuffalo/packr
v2/jam/parser/parser.go
Run
func (p *Parser) Run() (Boxes, error) { var boxes Boxes for _, pros := range p.Prospects { plog.Debug(p, "Run", "parsing", pros.Name()) v := NewVisitor(pros) pbr, err := v.Run() if err != nil { return boxes, err } for _, b := range pbr { plog.Debug(p, "Run", "file", pros.Name(), "box", b.Name) bo...
go
func (p *Parser) Run() (Boxes, error) { var boxes Boxes for _, pros := range p.Prospects { plog.Debug(p, "Run", "parsing", pros.Name()) v := NewVisitor(pros) pbr, err := v.Run() if err != nil { return boxes, err } for _, b := range pbr { plog.Debug(p, "Run", "file", pros.Name(), "box", b.Name) bo...
[ "func", "(", "p", "*", "Parser", ")", "Run", "(", ")", "(", "Boxes", ",", "error", ")", "{", "var", "boxes", "Boxes", "\n", "for", "_", ",", "pros", ":=", "range", "p", ".", "Prospects", "{", "plog", ".", "Debug", "(", "p", ",", "\"", "\"", "...
// Run the parser and run any boxes found
[ "Run", "the", "parser", "and", "run", "any", "boxes", "found" ]
9819ef1571983a956c49475cb0524d8a4971620f
https://github.com/gobuffalo/packr/blob/9819ef1571983a956c49475cb0524d8a4971620f/v2/jam/parser/parser.go#L18-L39
train
gobuffalo/packr
packr.go
PackBytes
func PackBytes(box string, name string, bb []byte) { gil.Lock() defer gil.Unlock() if _, ok := data[box]; !ok { data[box] = map[string][]byte{} } data[box][name] = bb }
go
func PackBytes(box string, name string, bb []byte) { gil.Lock() defer gil.Unlock() if _, ok := data[box]; !ok { data[box] = map[string][]byte{} } data[box][name] = bb }
[ "func", "PackBytes", "(", "box", "string", ",", "name", "string", ",", "bb", "[", "]", "byte", ")", "{", "gil", ".", "Lock", "(", ")", "\n", "defer", "gil", ".", "Unlock", "(", ")", "\n", "if", "_", ",", "ok", ":=", "data", "[", "box", "]", "...
// PackBytes packs bytes for a file into a box.
[ "PackBytes", "packs", "bytes", "for", "a", "file", "into", "a", "box", "." ]
9819ef1571983a956c49475cb0524d8a4971620f
https://github.com/gobuffalo/packr/blob/9819ef1571983a956c49475cb0524d8a4971620f/packr.go#L16-L23
train
gobuffalo/packr
packr.go
PackBytesGzip
func PackBytesGzip(box string, name string, bb []byte) error { var buf bytes.Buffer w := gzip.NewWriter(&buf) _, err := w.Write(bb) if err != nil { return err } err = w.Close() if err != nil { return err } PackBytes(box, name, buf.Bytes()) return nil }
go
func PackBytesGzip(box string, name string, bb []byte) error { var buf bytes.Buffer w := gzip.NewWriter(&buf) _, err := w.Write(bb) if err != nil { return err } err = w.Close() if err != nil { return err } PackBytes(box, name, buf.Bytes()) return nil }
[ "func", "PackBytesGzip", "(", "box", "string", ",", "name", "string", ",", "bb", "[", "]", "byte", ")", "error", "{", "var", "buf", "bytes", ".", "Buffer", "\n", "w", ":=", "gzip", ".", "NewWriter", "(", "&", "buf", ")", "\n", "_", ",", "err", ":...
// PackBytesGzip packets the gzipped compressed bytes into a box.
[ "PackBytesGzip", "packets", "the", "gzipped", "compressed", "bytes", "into", "a", "box", "." ]
9819ef1571983a956c49475cb0524d8a4971620f
https://github.com/gobuffalo/packr/blob/9819ef1571983a956c49475cb0524d8a4971620f/packr.go#L26-L39
train
gobuffalo/packr
packr.go
PackJSONBytes
func PackJSONBytes(box string, name string, jbb string) error { var bb []byte err := json.Unmarshal([]byte(jbb), &bb) if err != nil { return err } PackBytes(box, name, bb) return nil }
go
func PackJSONBytes(box string, name string, jbb string) error { var bb []byte err := json.Unmarshal([]byte(jbb), &bb) if err != nil { return err } PackBytes(box, name, bb) return nil }
[ "func", "PackJSONBytes", "(", "box", "string", ",", "name", "string", ",", "jbb", "string", ")", "error", "{", "var", "bb", "[", "]", "byte", "\n", "err", ":=", "json", ".", "Unmarshal", "(", "[", "]", "byte", "(", "jbb", ")", ",", "&", "bb", ")"...
// PackJSONBytes packs JSON encoded bytes for a file into a box.
[ "PackJSONBytes", "packs", "JSON", "encoded", "bytes", "for", "a", "file", "into", "a", "box", "." ]
9819ef1571983a956c49475cb0524d8a4971620f
https://github.com/gobuffalo/packr/blob/9819ef1571983a956c49475cb0524d8a4971620f/packr.go#L42-L50
train
gobuffalo/packr
packr.go
UnpackBytes
func UnpackBytes(box string) { gil.Lock() defer gil.Unlock() delete(data, box) }
go
func UnpackBytes(box string) { gil.Lock() defer gil.Unlock() delete(data, box) }
[ "func", "UnpackBytes", "(", "box", "string", ")", "{", "gil", ".", "Lock", "(", ")", "\n", "defer", "gil", ".", "Unlock", "(", ")", "\n", "delete", "(", "data", ",", "box", ")", "\n", "}" ]
// UnpackBytes unpacks bytes for specific box.
[ "UnpackBytes", "unpacks", "bytes", "for", "specific", "box", "." ]
9819ef1571983a956c49475cb0524d8a4971620f
https://github.com/gobuffalo/packr/blob/9819ef1571983a956c49475cb0524d8a4971620f/packr.go#L53-L57
train
gobuffalo/packr
v2/file/resolver/encoding/hex/hex.go
DecodeString
func DecodeString(s string) ([]byte, error) { src := []byte(s) // We can use the source slice itself as the destination // because the decode loop increments by one and then the 'seen' byte is not used anymore. n, err := Decode(src, src) return src[:n], err }
go
func DecodeString(s string) ([]byte, error) { src := []byte(s) // We can use the source slice itself as the destination // because the decode loop increments by one and then the 'seen' byte is not used anymore. n, err := Decode(src, src) return src[:n], err }
[ "func", "DecodeString", "(", "s", "string", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "src", ":=", "[", "]", "byte", "(", "s", ")", "\n", "// We can use the source slice itself as the destination", "// because the decode loop increments by one and then the '...
// DecodeString returns the bytes represented by the hexadecimal string s. // // DecodeString expects that src contains only hexadecimal // characters and that src has even length. // If the input is malformed, DecodeString returns // the bytes decoded before the error.
[ "DecodeString", "returns", "the", "bytes", "represented", "by", "the", "hexadecimal", "string", "s", ".", "DecodeString", "expects", "that", "src", "contains", "only", "hexadecimal", "characters", "and", "that", "src", "has", "even", "length", ".", "If", "the", ...
9819ef1571983a956c49475cb0524d8a4971620f
https://github.com/gobuffalo/packr/blob/9819ef1571983a956c49475cb0524d8a4971620f/v2/file/resolver/encoding/hex/hex.go#L108-L114
train
gobuffalo/packr
v2/file/resolver/encoding/hex/hex.go
Dump
func Dump(data []byte) string { var buf bytes.Buffer dumper := Dumper(&buf) dumper.Write(data) dumper.Close() return buf.String() }
go
func Dump(data []byte) string { var buf bytes.Buffer dumper := Dumper(&buf) dumper.Write(data) dumper.Close() return buf.String() }
[ "func", "Dump", "(", "data", "[", "]", "byte", ")", "string", "{", "var", "buf", "bytes", ".", "Buffer", "\n", "dumper", ":=", "Dumper", "(", "&", "buf", ")", "\n", "dumper", ".", "Write", "(", "data", ")", "\n", "dumper", ".", "Close", "(", ")",...
// Dump returns a string that contains a hex dump of the given data. The format // of the hex dump matches the output of `hexdump -C` on the command line.
[ "Dump", "returns", "a", "string", "that", "contains", "a", "hex", "dump", "of", "the", "given", "data", ".", "The", "format", "of", "the", "hex", "dump", "matches", "the", "output", "of", "hexdump", "-", "C", "on", "the", "command", "line", "." ]
9819ef1571983a956c49475cb0524d8a4971620f
https://github.com/gobuffalo/packr/blob/9819ef1571983a956c49475cb0524d8a4971620f/v2/file/resolver/encoding/hex/hex.go#L118-L124
train
gobuffalo/packr
v2/resolvers_map.go
Load
func (m *resolversMap) Load(key string) (resolver.Resolver, bool) { i, ok := m.data.Load(key) if !ok { return nil, false } s, ok := i.(resolver.Resolver) return s, ok }
go
func (m *resolversMap) Load(key string) (resolver.Resolver, bool) { i, ok := m.data.Load(key) if !ok { return nil, false } s, ok := i.(resolver.Resolver) return s, ok }
[ "func", "(", "m", "*", "resolversMap", ")", "Load", "(", "key", "string", ")", "(", "resolver", ".", "Resolver", ",", "bool", ")", "{", "i", ",", "ok", ":=", "m", ".", "data", ".", "Load", "(", "key", ")", "\n", "if", "!", "ok", "{", "return", ...
// Load the key from the map. // Returns resolver.Resolver or bool. // A false return indicates either the key was not found // or the value is not of type resolver.Resolver
[ "Load", "the", "key", "from", "the", "map", ".", "Returns", "resolver", ".", "Resolver", "or", "bool", ".", "A", "false", "return", "indicates", "either", "the", "key", "was", "not", "found", "or", "the", "value", "is", "not", "of", "type", "resolver", ...
9819ef1571983a956c49475cb0524d8a4971620f
https://github.com/gobuffalo/packr/blob/9819ef1571983a956c49475cb0524d8a4971620f/v2/resolvers_map.go#L29-L36
train
gobuffalo/packr
v2/resolvers_map.go
Range
func (m *resolversMap) Range(f func(key string, value resolver.Resolver) bool) { m.data.Range(func(k, v interface{}) bool { key, ok := k.(string) if !ok { return false } value, ok := v.(resolver.Resolver) if !ok { return false } return f(key, value) }) }
go
func (m *resolversMap) Range(f func(key string, value resolver.Resolver) bool) { m.data.Range(func(k, v interface{}) bool { key, ok := k.(string) if !ok { return false } value, ok := v.(resolver.Resolver) if !ok { return false } return f(key, value) }) }
[ "func", "(", "m", "*", "resolversMap", ")", "Range", "(", "f", "func", "(", "key", "string", ",", "value", "resolver", ".", "Resolver", ")", "bool", ")", "{", "m", ".", "data", ".", "Range", "(", "func", "(", "k", ",", "v", "interface", "{", "}",...
// Range over the resolver.Resolver values in the map
[ "Range", "over", "the", "resolver", ".", "Resolver", "values", "in", "the", "map" ]
9819ef1571983a956c49475cb0524d8a4971620f
https://github.com/gobuffalo/packr/blob/9819ef1571983a956c49475cb0524d8a4971620f/v2/resolvers_map.go#L47-L59
train
gobuffalo/packr
v2/resolvers_map.go
Store
func (m *resolversMap) Store(key string, value resolver.Resolver) { m.data.Store(key, value) }
go
func (m *resolversMap) Store(key string, value resolver.Resolver) { m.data.Store(key, value) }
[ "func", "(", "m", "*", "resolversMap", ")", "Store", "(", "key", "string", ",", "value", "resolver", ".", "Resolver", ")", "{", "m", ".", "data", ".", "Store", "(", "key", ",", "value", ")", "\n", "}" ]
// Store a resolver.Resolver in the map
[ "Store", "a", "resolver", ".", "Resolver", "in", "the", "map" ]
9819ef1571983a956c49475cb0524d8a4971620f
https://github.com/gobuffalo/packr/blob/9819ef1571983a956c49475cb0524d8a4971620f/v2/resolvers_map.go#L62-L64
train
gobuffalo/packr
v2/deprecated.go
PackBytes
func PackBytes(box string, name string, bb []byte) { b := NewBox(box) d := resolver.NewInMemory(map[string]file.File{}) f, err := file.NewFile(name, bb) if err != nil { panic(err) } if err := d.Pack(name, f); err != nil { panic(err) } b.SetResolver(name, d) }
go
func PackBytes(box string, name string, bb []byte) { b := NewBox(box) d := resolver.NewInMemory(map[string]file.File{}) f, err := file.NewFile(name, bb) if err != nil { panic(err) } if err := d.Pack(name, f); err != nil { panic(err) } b.SetResolver(name, d) }
[ "func", "PackBytes", "(", "box", "string", ",", "name", "string", ",", "bb", "[", "]", "byte", ")", "{", "b", ":=", "NewBox", "(", "box", ")", "\n", "d", ":=", "resolver", ".", "NewInMemory", "(", "map", "[", "string", "]", "file", ".", "File", "...
// PackBytes packs bytes for a file into a box. // Deprecated
[ "PackBytes", "packs", "bytes", "for", "a", "file", "into", "a", "box", ".", "Deprecated" ]
9819ef1571983a956c49475cb0524d8a4971620f
https://github.com/gobuffalo/packr/blob/9819ef1571983a956c49475cb0524d8a4971620f/v2/deprecated.go#L23-L34
train
gobuffalo/packr
v2/deprecated.go
PackBytesGzip
func PackBytesGzip(box string, name string, bb []byte) error { // TODO: this function never did what it was supposed to do! PackBytes(box, name, bb) return nil }
go
func PackBytesGzip(box string, name string, bb []byte) error { // TODO: this function never did what it was supposed to do! PackBytes(box, name, bb) return nil }
[ "func", "PackBytesGzip", "(", "box", "string", ",", "name", "string", ",", "bb", "[", "]", "byte", ")", "error", "{", "// TODO: this function never did what it was supposed to do!", "PackBytes", "(", "box", ",", "name", ",", "bb", ")", "\n", "return", "nil", "...
// PackBytesGzip packets the gzipped compressed bytes into a box. // Deprecated
[ "PackBytesGzip", "packets", "the", "gzipped", "compressed", "bytes", "into", "a", "box", ".", "Deprecated" ]
9819ef1571983a956c49475cb0524d8a4971620f
https://github.com/gobuffalo/packr/blob/9819ef1571983a956c49475cb0524d8a4971620f/v2/deprecated.go#L38-L42
train
gobuffalo/packr
v2/deprecated.go
String
func (b *Box) String(name string) string { oncer.Deprecate(0, "github.com/gobuffalo/packr/v2#Box.String", "Use github.com/gobuffalo/packr/v2#Box.FindString instead.") return string(b.Bytes(name)) }
go
func (b *Box) String(name string) string { oncer.Deprecate(0, "github.com/gobuffalo/packr/v2#Box.String", "Use github.com/gobuffalo/packr/v2#Box.FindString instead.") return string(b.Bytes(name)) }
[ "func", "(", "b", "*", "Box", ")", "String", "(", "name", "string", ")", "string", "{", "oncer", ".", "Deprecate", "(", "0", ",", "\"", "\"", ",", "\"", "\"", ")", "\n", "return", "string", "(", "b", ".", "Bytes", "(", "name", ")", ")", "\n", ...
// String is deprecated. Use FindString instead
[ "String", "is", "deprecated", ".", "Use", "FindString", "instead" ]
9819ef1571983a956c49475cb0524d8a4971620f
https://github.com/gobuffalo/packr/blob/9819ef1571983a956c49475cb0524d8a4971620f/v2/deprecated.go#L70-L73
train
gobuffalo/packr
v2/deprecated.go
MustString
func (b *Box) MustString(name string) (string, error) { oncer.Deprecate(0, "github.com/gobuffalo/packr/v2#Box.MustString", "Use github.com/gobuffalo/packr/v2#Box.FindString instead.") return b.FindString(name) }
go
func (b *Box) MustString(name string) (string, error) { oncer.Deprecate(0, "github.com/gobuffalo/packr/v2#Box.MustString", "Use github.com/gobuffalo/packr/v2#Box.FindString instead.") return b.FindString(name) }
[ "func", "(", "b", "*", "Box", ")", "MustString", "(", "name", "string", ")", "(", "string", ",", "error", ")", "{", "oncer", ".", "Deprecate", "(", "0", ",", "\"", "\"", ",", "\"", "\"", ")", "\n", "return", "b", ".", "FindString", "(", "name", ...
// MustString is deprecated. Use FindString instead
[ "MustString", "is", "deprecated", ".", "Use", "FindString", "instead" ]
9819ef1571983a956c49475cb0524d8a4971620f
https://github.com/gobuffalo/packr/blob/9819ef1571983a956c49475cb0524d8a4971620f/v2/deprecated.go#L76-L79
train
gobuffalo/packr
v2/dirs_map.go
Delete
func (m *dirsMap) Delete(key string) { m.data.Delete(m.normalizeKey(key)) }
go
func (m *dirsMap) Delete(key string) { m.data.Delete(m.normalizeKey(key)) }
[ "func", "(", "m", "*", "dirsMap", ")", "Delete", "(", "key", "string", ")", "{", "m", ".", "data", ".", "Delete", "(", "m", ".", "normalizeKey", "(", "key", ")", ")", "\n", "}" ]
// Delete the key from the map
[ "Delete", "the", "key", "from", "the", "map" ]
9819ef1571983a956c49475cb0524d8a4971620f
https://github.com/gobuffalo/packr/blob/9819ef1571983a956c49475cb0524d8a4971620f/v2/dirs_map.go#L20-L22
train
gobuffalo/packr
v2/dirs_map.go
Load
func (m *dirsMap) Load(key string) (bool, bool) { i, ok := m.data.Load(m.normalizeKey(key)) if !ok { return false, false } s, ok := i.(bool) return s, ok }
go
func (m *dirsMap) Load(key string) (bool, bool) { i, ok := m.data.Load(m.normalizeKey(key)) if !ok { return false, false } s, ok := i.(bool) return s, ok }
[ "func", "(", "m", "*", "dirsMap", ")", "Load", "(", "key", "string", ")", "(", "bool", ",", "bool", ")", "{", "i", ",", "ok", ":=", "m", ".", "data", ".", "Load", "(", "m", ".", "normalizeKey", "(", "key", ")", ")", "\n", "if", "!", "ok", "...
// Load the key from the map. // Returns bool or bool. // A false return indicates either the key was not found // or the value is not of type bool
[ "Load", "the", "key", "from", "the", "map", ".", "Returns", "bool", "or", "bool", ".", "A", "false", "return", "indicates", "either", "the", "key", "was", "not", "found", "or", "the", "value", "is", "not", "of", "type", "bool" ]
9819ef1571983a956c49475cb0524d8a4971620f
https://github.com/gobuffalo/packr/blob/9819ef1571983a956c49475cb0524d8a4971620f/v2/dirs_map.go#L28-L35
train
gobuffalo/packr
v2/dirs_map.go
Store
func (m *dirsMap) Store(key string, value bool) { d := m.normalizeKey(key) m.data.Store(d, value) m.data.Store(strings.TrimPrefix(d, "/"), value) }
go
func (m *dirsMap) Store(key string, value bool) { d := m.normalizeKey(key) m.data.Store(d, value) m.data.Store(strings.TrimPrefix(d, "/"), value) }
[ "func", "(", "m", "*", "dirsMap", ")", "Store", "(", "key", "string", ",", "value", "bool", ")", "{", "d", ":=", "m", ".", "normalizeKey", "(", "key", ")", "\n", "m", ".", "data", ".", "Store", "(", "d", ",", "value", ")", "\n", "m", ".", "da...
// Store a bool in the map
[ "Store", "a", "bool", "in", "the", "map" ]
9819ef1571983a956c49475cb0524d8a4971620f
https://github.com/gobuffalo/packr/blob/9819ef1571983a956c49475cb0524d8a4971620f/v2/dirs_map.go#L61-L65
train
gobuffalo/packr
v2/packr2/cmd/fix/runner.go
Run
func Run() error { fmt.Printf("! This updater will attempt to update your application to packr version: %s\n", packr.Version) if !ask("Do you wish to continue?") { fmt.Println("~~~ cancelling update ~~~") return nil } r := &Runner{ Warnings: []string{}, } defer func() { if len(r.Warnings) == 0 { retu...
go
func Run() error { fmt.Printf("! This updater will attempt to update your application to packr version: %s\n", packr.Version) if !ask("Do you wish to continue?") { fmt.Println("~~~ cancelling update ~~~") return nil } r := &Runner{ Warnings: []string{}, } defer func() { if len(r.Warnings) == 0 { retu...
[ "func", "Run", "(", ")", "error", "{", "fmt", ".", "Printf", "(", "\"", "\\n", "\"", ",", "packr", ".", "Version", ")", "\n", "if", "!", "ask", "(", "\"", "\"", ")", "{", "fmt", ".", "Println", "(", "\"", "\"", ")", "\n", "return", "nil", "\n...
// Run all compatible checks
[ "Run", "all", "compatible", "checks" ]
9819ef1571983a956c49475cb0524d8a4971620f
https://github.com/gobuffalo/packr/blob/9819ef1571983a956c49475cb0524d8a4971620f/v2/packr2/cmd/fix/runner.go#L18-L47
train
gobuffalo/packr
v2/box.go
New
func New(name string, path string) *Box { plog.Debug("packr", "New", "name", name, "path", path) b, _ := findBox(name) if b != nil { return b } b = construct(name, path) plog.Debug(b, "New", "Box", b, "ResolutionDir", b.ResolutionDir) b, err := placeBox(b) if err != nil { panic(err) } return b }
go
func New(name string, path string) *Box { plog.Debug("packr", "New", "name", name, "path", path) b, _ := findBox(name) if b != nil { return b } b = construct(name, path) plog.Debug(b, "New", "Box", b, "ResolutionDir", b.ResolutionDir) b, err := placeBox(b) if err != nil { panic(err) } return b }
[ "func", "New", "(", "name", "string", ",", "path", "string", ")", "*", "Box", "{", "plog", ".", "Debug", "(", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "name", ",", "\"", "\"", ",", "path", ")", "\n", "b", ",", "_", ":=", "findBox", ...
// New returns a new Box with the name of the box // and the path of the box.
[ "New", "returns", "a", "new", "Box", "with", "the", "name", "of", "the", "box", "and", "the", "path", "of", "the", "box", "." ]
9819ef1571983a956c49475cb0524d8a4971620f
https://github.com/gobuffalo/packr/blob/9819ef1571983a956c49475cb0524d8a4971620f/v2/box.go#L51-L66
train
gobuffalo/packr
v2/box.go
SetResolver
func (b *Box) SetResolver(file string, res resolver.Resolver) { d := filepath.Dir(file) b.dirs.Store(d, true) plog.Debug(b, "SetResolver", "file", file, "resolver", fmt.Sprintf("%T", res)) b.resolvers.Store(resolver.Key(file), res) }
go
func (b *Box) SetResolver(file string, res resolver.Resolver) { d := filepath.Dir(file) b.dirs.Store(d, true) plog.Debug(b, "SetResolver", "file", file, "resolver", fmt.Sprintf("%T", res)) b.resolvers.Store(resolver.Key(file), res) }
[ "func", "(", "b", "*", "Box", ")", "SetResolver", "(", "file", "string", ",", "res", "resolver", ".", "Resolver", ")", "{", "d", ":=", "filepath", ".", "Dir", "(", "file", ")", "\n", "b", ".", "dirs", ".", "Store", "(", "d", ",", "true", ")", "...
// SetResolver allows for the use of a custom resolver for // the specified file
[ "SetResolver", "allows", "for", "the", "use", "of", "a", "custom", "resolver", "for", "the", "specified", "file" ]
9819ef1571983a956c49475cb0524d8a4971620f
https://github.com/gobuffalo/packr/blob/9819ef1571983a956c49475cb0524d8a4971620f/v2/box.go#L77-L82
train
gobuffalo/packr
v2/box.go
AddString
func (b *Box) AddString(path string, t string) error { return b.AddBytes(path, []byte(t)) }
go
func (b *Box) AddString(path string, t string) error { return b.AddBytes(path, []byte(t)) }
[ "func", "(", "b", "*", "Box", ")", "AddString", "(", "path", "string", ",", "t", "string", ")", "error", "{", "return", "b", ".", "AddBytes", "(", "path", ",", "[", "]", "byte", "(", "t", ")", ")", "\n", "}" ]
// AddString converts t to a byteslice and delegates to AddBytes to add to b.data
[ "AddString", "converts", "t", "to", "a", "byteslice", "and", "delegates", "to", "AddBytes", "to", "add", "to", "b", ".", "data" ]
9819ef1571983a956c49475cb0524d8a4971620f
https://github.com/gobuffalo/packr/blob/9819ef1571983a956c49475cb0524d8a4971620f/v2/box.go#L85-L87
train
gobuffalo/packr
v2/box.go
AddBytes
func (b *Box) AddBytes(path string, t []byte) error { m := map[string]file.File{} f, err := file.NewFile(path, t) if err != nil { return err } m[resolver.Key(path)] = f res := resolver.NewInMemory(m) b.SetResolver(path, res) return nil }
go
func (b *Box) AddBytes(path string, t []byte) error { m := map[string]file.File{} f, err := file.NewFile(path, t) if err != nil { return err } m[resolver.Key(path)] = f res := resolver.NewInMemory(m) b.SetResolver(path, res) return nil }
[ "func", "(", "b", "*", "Box", ")", "AddBytes", "(", "path", "string", ",", "t", "[", "]", "byte", ")", "error", "{", "m", ":=", "map", "[", "string", "]", "file", ".", "File", "{", "}", "\n", "f", ",", "err", ":=", "file", ".", "NewFile", "("...
// AddBytes sets t in b.data by the given path
[ "AddBytes", "sets", "t", "in", "b", ".", "data", "by", "the", "given", "path" ]
9819ef1571983a956c49475cb0524d8a4971620f
https://github.com/gobuffalo/packr/blob/9819ef1571983a956c49475cb0524d8a4971620f/v2/box.go#L90-L100
train
gobuffalo/packr
v2/box.go
FindString
func (b *Box) FindString(name string) (string, error) { bb, err := b.Find(name) return string(bb), err }
go
func (b *Box) FindString(name string) (string, error) { bb, err := b.Find(name) return string(bb), err }
[ "func", "(", "b", "*", "Box", ")", "FindString", "(", "name", "string", ")", "(", "string", ",", "error", ")", "{", "bb", ",", "err", ":=", "b", ".", "Find", "(", "name", ")", "\n", "return", "string", "(", "bb", ")", ",", "err", "\n", "}" ]
// FindString returns either the string of the requested // file or an error if it can not be found.
[ "FindString", "returns", "either", "the", "string", "of", "the", "requested", "file", "or", "an", "error", "if", "it", "can", "not", "be", "found", "." ]
9819ef1571983a956c49475cb0524d8a4971620f
https://github.com/gobuffalo/packr/blob/9819ef1571983a956c49475cb0524d8a4971620f/v2/box.go#L104-L107
train
gobuffalo/packr
v2/box.go
HasDir
func (b *Box) HasDir(name string) bool { oncer.Do("packr2/box/HasDir"+b.Name, func() { for _, f := range b.List() { for d := filepath.Dir(f); d != "."; d = filepath.Dir(d) { b.dirs.Store(d, true) } } }) if name == "/" { return b.Has("index.html") } _, ok := b.dirs.Load(name) return ok }
go
func (b *Box) HasDir(name string) bool { oncer.Do("packr2/box/HasDir"+b.Name, func() { for _, f := range b.List() { for d := filepath.Dir(f); d != "."; d = filepath.Dir(d) { b.dirs.Store(d, true) } } }) if name == "/" { return b.Has("index.html") } _, ok := b.dirs.Load(name) return ok }
[ "func", "(", "b", "*", "Box", ")", "HasDir", "(", "name", "string", ")", "bool", "{", "oncer", ".", "Do", "(", "\"", "\"", "+", "b", ".", "Name", ",", "func", "(", ")", "{", "for", "_", ",", "f", ":=", "range", "b", ".", "List", "(", ")", ...
// HasDir returns true if the directory exists in the box
[ "HasDir", "returns", "true", "if", "the", "directory", "exists", "in", "the", "box" ]
9819ef1571983a956c49475cb0524d8a4971620f
https://github.com/gobuffalo/packr/blob/9819ef1571983a956c49475cb0524d8a4971620f/v2/box.go#L128-L141
train
gobuffalo/packr
v2/box.go
Resolve
func (b *Box) Resolve(key string) (file.File, error) { key = strings.TrimPrefix(key, "/") var r resolver.Resolver b.resolvers.Range(func(k string, vr resolver.Resolver) bool { lk := strings.ToLower(resolver.Key(k)) lkey := strings.ToLower(resolver.Key(key)) if lk == lkey { r = vr return false } ret...
go
func (b *Box) Resolve(key string) (file.File, error) { key = strings.TrimPrefix(key, "/") var r resolver.Resolver b.resolvers.Range(func(k string, vr resolver.Resolver) bool { lk := strings.ToLower(resolver.Key(k)) lkey := strings.ToLower(resolver.Key(key)) if lk == lkey { r = vr return false } ret...
[ "func", "(", "b", "*", "Box", ")", "Resolve", "(", "key", "string", ")", "(", "file", ".", "File", ",", "error", ")", "{", "key", "=", "strings", ".", "TrimPrefix", "(", "key", ",", "\"", "\"", ")", "\n\n", "var", "r", "resolver", ".", "Resolver"...
// Resolve will attempt to find the file in the box, // returning an error if the find can not be found.
[ "Resolve", "will", "attempt", "to", "find", "the", "file", "in", "the", "box", "returning", "an", "error", "if", "the", "find", "can", "not", "be", "found", "." ]
9819ef1571983a956c49475cb0524d8a4971620f
https://github.com/gobuffalo/packr/blob/9819ef1571983a956c49475cb0524d8a4971620f/v2/box.go#L191-L236
train
gobuffalo/packr
v2/jam/parser/roots.go
NewFromRoots
func NewFromRoots(roots []string, opts *RootsOptions) (*Parser, error) { if opts == nil { opts = &RootsOptions{} } if len(roots) == 0 { pwd, _ := os.Getwd() roots = append(roots, pwd) } p := New() plog.Debug(p, "NewFromRoots", "roots", roots, "options", opts) callback := func(path string, de *godirwalk.Di...
go
func NewFromRoots(roots []string, opts *RootsOptions) (*Parser, error) { if opts == nil { opts = &RootsOptions{} } if len(roots) == 0 { pwd, _ := os.Getwd() roots = append(roots, pwd) } p := New() plog.Debug(p, "NewFromRoots", "roots", roots, "options", opts) callback := func(path string, de *godirwalk.Di...
[ "func", "NewFromRoots", "(", "roots", "[", "]", "string", ",", "opts", "*", "RootsOptions", ")", "(", "*", "Parser", ",", "error", ")", "{", "if", "opts", "==", "nil", "{", "opts", "=", "&", "RootsOptions", "{", "}", "\n", "}", "\n\n", "if", "len",...
// NewFromRoots scans the file roots provided and returns a // new Parser containing the prospects
[ "NewFromRoots", "scans", "the", "file", "roots", "provided", "and", "returns", "a", "new", "Parser", "containing", "the", "prospects" ]
9819ef1571983a956c49475cb0524d8a4971620f
https://github.com/gobuffalo/packr/blob/9819ef1571983a956c49475cb0524d8a4971620f/v2/jam/parser/roots.go#L27-L89
train
gobuffalo/packr
v2/file/file.go
NewFile
func NewFile(name string, b []byte) (File, error) { return packd.NewFile(name, bytes.NewReader(b)) }
go
func NewFile(name string, b []byte) (File, error) { return packd.NewFile(name, bytes.NewReader(b)) }
[ "func", "NewFile", "(", "name", "string", ",", "b", "[", "]", "byte", ")", "(", "File", ",", "error", ")", "{", "return", "packd", ".", "NewFile", "(", "name", ",", "bytes", ".", "NewReader", "(", "b", ")", ")", "\n", "}" ]
// NewFile returns a virtual File implementation
[ "NewFile", "returns", "a", "virtual", "File", "implementation" ]
9819ef1571983a956c49475cb0524d8a4971620f
https://github.com/gobuffalo/packr/blob/9819ef1571983a956c49475cb0524d8a4971620f/v2/file/file.go#L21-L23
train
koding/kite
heartbeat.go
RegisterHTTPForever
func (k *Kite) RegisterHTTPForever(kiteURL *url.URL) { // Create the httpBackoffRegister that RegisterHTTPForever will // use to backoff repeated register attempts. httpRegisterBackOff := backoff.NewExponentialBackOff() httpRegisterBackOff.InitialInterval = 30 * time.Second httpRegisterBackOff.MaxInterval = 5 * ti...
go
func (k *Kite) RegisterHTTPForever(kiteURL *url.URL) { // Create the httpBackoffRegister that RegisterHTTPForever will // use to backoff repeated register attempts. httpRegisterBackOff := backoff.NewExponentialBackOff() httpRegisterBackOff.InitialInterval = 30 * time.Second httpRegisterBackOff.MaxInterval = 5 * ti...
[ "func", "(", "k", "*", "Kite", ")", "RegisterHTTPForever", "(", "kiteURL", "*", "url", ".", "URL", ")", "{", "// Create the httpBackoffRegister that RegisterHTTPForever will", "// use to backoff repeated register attempts.", "httpRegisterBackOff", ":=", "backoff", ".", "New...
// RegisterHTTPForever is just like RegisterHTTP however it first tries to // register forever until a response from kontrol is received. It's useful to // use it during app initializations. After the registration a reconnect is // automatically handled inside the RegisterHTTP method.
[ "RegisterHTTPForever", "is", "just", "like", "RegisterHTTP", "however", "it", "first", "tries", "to", "register", "forever", "until", "a", "response", "from", "kontrol", "is", "received", ".", "It", "s", "useful", "to", "use", "it", "during", "app", "initializ...
baa1a54919e3035417f7571dd46005e91afe8abe
https://github.com/koding/kite/blob/baa1a54919e3035417f7571dd46005e91afe8abe/heartbeat.go#L90-L116
train
koding/kite
heartbeat.go
handleHeartbeat
func (k *Kite) handleHeartbeat(r *Request) (interface{}, error) { req, err := newHeartbeatReq(r) if err != nil { return nil, err } k.heartbeatC <- req return nil, req.ping() }
go
func (k *Kite) handleHeartbeat(r *Request) (interface{}, error) { req, err := newHeartbeatReq(r) if err != nil { return nil, err } k.heartbeatC <- req return nil, req.ping() }
[ "func", "(", "k", "*", "Kite", ")", "handleHeartbeat", "(", "r", "*", "Request", ")", "(", "interface", "{", "}", ",", "error", ")", "{", "req", ",", "err", ":=", "newHeartbeatReq", "(", "r", ")", "\n", "if", "err", "!=", "nil", "{", "return", "n...
// handleHeartbeat pings the callback with the given interval seconds.
[ "handleHeartbeat", "pings", "the", "callback", "with", "the", "given", "interval", "seconds", "." ]
baa1a54919e3035417f7571dd46005e91afe8abe
https://github.com/koding/kite/blob/baa1a54919e3035417f7571dd46005e91afe8abe/heartbeat.go#L246-L255
train
koding/kite
dnode/callback.go
Call
func (f Function) Call(args ...interface{}) error { if !f.IsValid() { return errors.New("invalid function") } return f.Caller.Call(args...) }
go
func (f Function) Call(args ...interface{}) error { if !f.IsValid() { return errors.New("invalid function") } return f.Caller.Call(args...) }
[ "func", "(", "f", "Function", ")", "Call", "(", "args", "...", "interface", "{", "}", ")", "error", "{", "if", "!", "f", ".", "IsValid", "(", ")", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n", "return", "f", ".", ...
// Call the received function.
[ "Call", "the", "received", "function", "." ]
baa1a54919e3035417f7571dd46005e91afe8abe
https://github.com/koding/kite/blob/baa1a54919e3035417f7571dd46005e91afe8abe/dnode/callback.go#L18-L23
train
koding/kite
dnode/callback.go
ParseCallbacks
func ParseCallbacks(msg *Message, sender func(id uint64, args []interface{}) error) error { // Parse callbacks field and create callback functions. for methodID, path := range msg.Callbacks { id, err := strconv.ParseUint(methodID, 10, 64) if err != nil { return err } f := func(args ...interface{}) error {...
go
func ParseCallbacks(msg *Message, sender func(id uint64, args []interface{}) error) error { // Parse callbacks field and create callback functions. for methodID, path := range msg.Callbacks { id, err := strconv.ParseUint(methodID, 10, 64) if err != nil { return err } f := func(args ...interface{}) error {...
[ "func", "ParseCallbacks", "(", "msg", "*", "Message", ",", "sender", "func", "(", "id", "uint64", ",", "args", "[", "]", "interface", "{", "}", ")", "error", ")", "error", "{", "// Parse callbacks field and create callback functions.", "for", "methodID", ",", ...
// parseCallbacks parses the message's "callbacks" field and prepares // callback functions in "arguments" field.
[ "parseCallbacks", "parses", "the", "message", "s", "callbacks", "field", "and", "prepares", "callback", "functions", "in", "arguments", "field", "." ]
baa1a54919e3035417f7571dd46005e91afe8abe
https://github.com/koding/kite/blob/baa1a54919e3035417f7571dd46005e91afe8abe/dnode/callback.go#L78-L92
train
koding/kite
kontrol/node.go
Flatten
func (n *Node) Flatten() []*Node { nodes := make([]*Node, 0) for _, node := range n.Node.Nodes { if node.Dir { nodes = append(nodes, NewNode(node).Flatten()...) continue } nodes = append(nodes, NewNode(node)) } return nodes }
go
func (n *Node) Flatten() []*Node { nodes := make([]*Node, 0) for _, node := range n.Node.Nodes { if node.Dir { nodes = append(nodes, NewNode(node).Flatten()...) continue } nodes = append(nodes, NewNode(node)) } return nodes }
[ "func", "(", "n", "*", "Node", ")", "Flatten", "(", ")", "[", "]", "*", "Node", "{", "nodes", ":=", "make", "(", "[", "]", "*", "Node", ",", "0", ")", "\n", "for", "_", ",", "node", ":=", "range", "n", ".", "Node", ".", "Nodes", "{", "if", ...
// Flatten converts the recursive etcd directory structure to a flat one that // contains all kontrolNodes
[ "Flatten", "converts", "the", "recursive", "etcd", "directory", "structure", "to", "a", "flat", "one", "that", "contains", "all", "kontrolNodes" ]
baa1a54919e3035417f7571dd46005e91afe8abe
https://github.com/koding/kite/blob/baa1a54919e3035417f7571dd46005e91afe8abe/kontrol/node.go#L33-L45
train
koding/kite
kontrol/node.go
Kite
func (n *Node) Kite() (*protocol.KiteWithToken, error) { kite, err := n.KiteFromKey() if err != nil { return nil, err } val, err := n.Value() if err != nil { return nil, err } return &protocol.KiteWithToken{ Kite: *kite, URL: val.URL, KeyID: val.KeyID, }, nil }
go
func (n *Node) Kite() (*protocol.KiteWithToken, error) { kite, err := n.KiteFromKey() if err != nil { return nil, err } val, err := n.Value() if err != nil { return nil, err } return &protocol.KiteWithToken{ Kite: *kite, URL: val.URL, KeyID: val.KeyID, }, nil }
[ "func", "(", "n", "*", "Node", ")", "Kite", "(", ")", "(", "*", "protocol", ".", "KiteWithToken", ",", "error", ")", "{", "kite", ",", "err", ":=", "n", ".", "KiteFromKey", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "e...
// Kite returns a single kite gathered from the key and the value for the // current node.
[ "Kite", "returns", "a", "single", "kite", "gathered", "from", "the", "key", "and", "the", "value", "for", "the", "current", "node", "." ]
baa1a54919e3035417f7571dd46005e91afe8abe
https://github.com/koding/kite/blob/baa1a54919e3035417f7571dd46005e91afe8abe/kontrol/node.go#L49-L65
train
koding/kite
kontrol/node.go
Value
func (n *Node) Value() (kontrolprotocol.RegisterValue, error) { var rv kontrolprotocol.RegisterValue err := json.Unmarshal([]byte(n.Node.Value), &rv) return rv, err }
go
func (n *Node) Value() (kontrolprotocol.RegisterValue, error) { var rv kontrolprotocol.RegisterValue err := json.Unmarshal([]byte(n.Node.Value), &rv) return rv, err }
[ "func", "(", "n", "*", "Node", ")", "Value", "(", ")", "(", "kontrolprotocol", ".", "RegisterValue", ",", "error", ")", "{", "var", "rv", "kontrolprotocol", ".", "RegisterValue", "\n", "err", ":=", "json", ".", "Unmarshal", "(", "[", "]", "byte", "(", ...
// Value returns the value associated with the current node.
[ "Value", "returns", "the", "value", "associated", "with", "the", "current", "node", "." ]
baa1a54919e3035417f7571dd46005e91afe8abe
https://github.com/koding/kite/blob/baa1a54919e3035417f7571dd46005e91afe8abe/kontrol/node.go#L88-L92
train
koding/kite
kontrol/node.go
Kites
func (n *Node) Kites() (Kites, error) { // Get all nodes recursively. nodes := n.Flatten() // Convert etcd nodes to kites. var err error kites := make(Kites, len(nodes)) for i, n := range nodes { kites[i], err = n.Kite() if err != nil { return nil, err } } return kites, nil }
go
func (n *Node) Kites() (Kites, error) { // Get all nodes recursively. nodes := n.Flatten() // Convert etcd nodes to kites. var err error kites := make(Kites, len(nodes)) for i, n := range nodes { kites[i], err = n.Kite() if err != nil { return nil, err } } return kites, nil }
[ "func", "(", "n", "*", "Node", ")", "Kites", "(", ")", "(", "Kites", ",", "error", ")", "{", "// Get all nodes recursively.", "nodes", ":=", "n", ".", "Flatten", "(", ")", "\n\n", "// Convert etcd nodes to kites.", "var", "err", "error", "\n", "kites", ":=...
// Kites returns a list of kites that are gathered by collecting recursively // all nodes under the current node.
[ "Kites", "returns", "a", "list", "of", "kites", "that", "are", "gathered", "by", "collecting", "recursively", "all", "nodes", "under", "the", "current", "node", "." ]
baa1a54919e3035417f7571dd46005e91afe8abe
https://github.com/koding/kite/blob/baa1a54919e3035417f7571dd46005e91afe8abe/kontrol/node.go#L96-L111
train
koding/kite
errors.go
createError
func createError(req *Request, r interface{}) *Error { if r == nil { return nil } var kiteErr *Error switch err := r.(type) { case *Error: kiteErr = err case *dnode.ArgumentError: kiteErr = &Error{ Type: "argumentError", Message: err.Error(), } default: kiteErr = &Error{ Type: "genericE...
go
func createError(req *Request, r interface{}) *Error { if r == nil { return nil } var kiteErr *Error switch err := r.(type) { case *Error: kiteErr = err case *dnode.ArgumentError: kiteErr = &Error{ Type: "argumentError", Message: err.Error(), } default: kiteErr = &Error{ Type: "genericE...
[ "func", "createError", "(", "req", "*", "Request", ",", "r", "interface", "{", "}", ")", "*", "Error", "{", "if", "r", "==", "nil", "{", "return", "nil", "\n", "}", "\n\n", "var", "kiteErr", "*", "Error", "\n", "switch", "err", ":=", "r", ".", "(...
// createError creates a new kite.Error for the given r variable
[ "createError", "creates", "a", "new", "kite", ".", "Error", "for", "the", "given", "r", "variable" ]
baa1a54919e3035417f7571dd46005e91afe8abe
https://github.com/koding/kite/blob/baa1a54919e3035417f7571dd46005e91afe8abe/errors.go#L41-L67
train
koding/kite
reverseproxy/reverseproxy.go
isWebsocket
func isWebsocket(req *http.Request) bool { if strings.ToLower(req.Header.Get("Upgrade")) != "websocket" || !strings.Contains(strings.ToLower(req.Header.Get("Connection")), "upgrade") { return false } return true }
go
func isWebsocket(req *http.Request) bool { if strings.ToLower(req.Header.Get("Upgrade")) != "websocket" || !strings.Contains(strings.ToLower(req.Header.Get("Connection")), "upgrade") { return false } return true }
[ "func", "isWebsocket", "(", "req", "*", "http", ".", "Request", ")", "bool", "{", "if", "strings", ".", "ToLower", "(", "req", ".", "Header", ".", "Get", "(", "\"", "\"", ")", ")", "!=", "\"", "\"", "||", "!", "strings", ".", "Contains", "(", "st...
// isWebsocket checks wether the incoming request is a part of websocket // handshake
[ "isWebsocket", "checks", "wether", "the", "incoming", "request", "is", "a", "part", "of", "websocket", "handshake" ]
baa1a54919e3035417f7571dd46005e91afe8abe
https://github.com/koding/kite/blob/baa1a54919e3035417f7571dd46005e91afe8abe/reverseproxy/reverseproxy.go#L109-L115
train
koding/kite
reverseproxy/reverseproxy.go
ListenAndServe
func (p *Proxy) ListenAndServe() error { var err error p.listener, err = net.Listen("tcp4", net.JoinHostPort(p.Kite.Config.IP, strconv.Itoa(p.Kite.Config.Port))) if err != nil { return err } p.Kite.Log.Info("Listening on: %s", p.listener.Addr().String()) close(p.readyC) server := http.Server{ Handler: p....
go
func (p *Proxy) ListenAndServe() error { var err error p.listener, err = net.Listen("tcp4", net.JoinHostPort(p.Kite.Config.IP, strconv.Itoa(p.Kite.Config.Port))) if err != nil { return err } p.Kite.Log.Info("Listening on: %s", p.listener.Addr().String()) close(p.readyC) server := http.Server{ Handler: p....
[ "func", "(", "p", "*", "Proxy", ")", "ListenAndServe", "(", ")", "error", "{", "var", "err", "error", "\n", "p", ".", "listener", ",", "err", "=", "net", ".", "Listen", "(", "\"", "\"", ",", "net", ".", "JoinHostPort", "(", "p", ".", "Kite", ".",...
// ListenAndServe listens on the TCP network address addr and then calls Serve // with handler to handle requests on incoming connections.
[ "ListenAndServe", "listens", "on", "the", "TCP", "network", "address", "addr", "and", "then", "calls", "Serve", "with", "handler", "to", "handle", "requests", "on", "incoming", "connections", "." ]
baa1a54919e3035417f7571dd46005e91afe8abe
https://github.com/koding/kite/blob/baa1a54919e3035417f7571dd46005e91afe8abe/reverseproxy/reverseproxy.go#L195-L212
train
koding/kite
systeminfo/systeminfo_windows.go
diskStats
func diskStats() (*disk, error) { var ( freeBytes uint64 = 0 totalBytes uint64 = 0 ) // windows sets return value to 0 when function fails. ret, _, err := procGetDiskFreeSpaceExW.Call( 0, uintptr(unsafe.Pointer(&freeBytes)), uintptr(unsafe.Pointer(&totalBytes)), 0, ) if ret == 0 { return nil, err ...
go
func diskStats() (*disk, error) { var ( freeBytes uint64 = 0 totalBytes uint64 = 0 ) // windows sets return value to 0 when function fails. ret, _, err := procGetDiskFreeSpaceExW.Call( 0, uintptr(unsafe.Pointer(&freeBytes)), uintptr(unsafe.Pointer(&totalBytes)), 0, ) if ret == 0 { return nil, err ...
[ "func", "diskStats", "(", ")", "(", "*", "disk", ",", "error", ")", "{", "var", "(", "freeBytes", "uint64", "=", "0", "\n", "totalBytes", "uint64", "=", "0", "\n", ")", "\n\n", "// windows sets return value to 0 when function fails.", "ret", ",", "_", ",", ...
// diskStats returns information about the amount of space that is available on // a current disk volume for the user who calls this function.
[ "diskStats", "returns", "information", "about", "the", "amount", "of", "space", "that", "is", "available", "on", "a", "current", "disk", "volume", "for", "the", "user", "who", "calls", "this", "function", "." ]
baa1a54919e3035417f7571dd46005e91afe8abe
https://github.com/koding/kite/blob/baa1a54919e3035417f7571dd46005e91afe8abe/systeminfo/systeminfo_windows.go#L17-L39
train
koding/kite
systeminfo/systeminfo_windows.go
memoryStats
func memoryStats() (*memory, error) { mstat := struct { size uint32 _ uint32 totalPhys uint64 availPhys uint64 _ [5]uint64 }{} // windows sets return value to 0 when function fails. mstat.size = uint32(unsafe.Sizeof(mstat)) ret, _, err := procGlobalMemoryStatusEx.Call(uintptr(unsafe...
go
func memoryStats() (*memory, error) { mstat := struct { size uint32 _ uint32 totalPhys uint64 availPhys uint64 _ [5]uint64 }{} // windows sets return value to 0 when function fails. mstat.size = uint32(unsafe.Sizeof(mstat)) ret, _, err := procGlobalMemoryStatusEx.Call(uintptr(unsafe...
[ "func", "memoryStats", "(", ")", "(", "*", "memory", ",", "error", ")", "{", "mstat", ":=", "struct", "{", "size", "uint32", "\n", "_", "uint32", "\n", "totalPhys", "uint64", "\n", "availPhys", "uint64", "\n", "_", "[", "5", "]", "uint64", "\n", "}",...
// memoryStatus retrieves information about the system's current usage of // physical memory.
[ "memoryStatus", "retrieves", "information", "about", "the", "system", "s", "current", "usage", "of", "physical", "memory", "." ]
baa1a54919e3035417f7571dd46005e91afe8abe
https://github.com/koding/kite/blob/baa1a54919e3035417f7571dd46005e91afe8abe/systeminfo/systeminfo_windows.go#L43-L65
train
koding/kite
protocol/webrtc.go
ParsePayload
func (w *WebRTCSignalMessage) ParsePayload() (*Payload, error) { w.mu.Lock() defer w.mu.Unlock() if w.isParsed { return w.parsedPayload, nil } payload := &Payload{} if err := json.Unmarshal(w.Payload, payload); err != nil { return nil, err } w.parsedPayload = payload return payload, nil }
go
func (w *WebRTCSignalMessage) ParsePayload() (*Payload, error) { w.mu.Lock() defer w.mu.Unlock() if w.isParsed { return w.parsedPayload, nil } payload := &Payload{} if err := json.Unmarshal(w.Payload, payload); err != nil { return nil, err } w.parsedPayload = payload return payload, nil }
[ "func", "(", "w", "*", "WebRTCSignalMessage", ")", "ParsePayload", "(", ")", "(", "*", "Payload", ",", "error", ")", "{", "w", ".", "mu", ".", "Lock", "(", ")", "\n", "defer", "w", ".", "mu", ".", "Unlock", "(", ")", "\n\n", "if", "w", ".", "is...
// ParsePayload parses the payload if it is not parsed previously. This method // can be called concurrently.
[ "ParsePayload", "parses", "the", "payload", "if", "it", "is", "not", "parsed", "previously", ".", "This", "method", "can", "be", "called", "concurrently", "." ]
baa1a54919e3035417f7571dd46005e91afe8abe
https://github.com/koding/kite/blob/baa1a54919e3035417f7571dd46005e91afe8abe/protocol/webrtc.go#L50-L65
train
koding/kite
logger.go
getLogLevel
func getLogLevel() Level { switch strings.ToUpper(os.Getenv("KITE_LOG_LEVEL")) { case "DEBUG": return DEBUG case "WARNING": return WARNING case "ERROR": return ERROR case "FATAL": return FATAL default: return INFO } }
go
func getLogLevel() Level { switch strings.ToUpper(os.Getenv("KITE_LOG_LEVEL")) { case "DEBUG": return DEBUG case "WARNING": return WARNING case "ERROR": return ERROR case "FATAL": return FATAL default: return INFO } }
[ "func", "getLogLevel", "(", ")", "Level", "{", "switch", "strings", ".", "ToUpper", "(", "os", ".", "Getenv", "(", "\"", "\"", ")", ")", "{", "case", "\"", "\"", ":", "return", "DEBUG", "\n", "case", "\"", "\"", ":", "return", "WARNING", "\n", "cas...
// getLogLevel returns the logging level defined via the KITE_LOG_LEVEL // environment. It returns Info by default if no environment variable // is set.
[ "getLogLevel", "returns", "the", "logging", "level", "defined", "via", "the", "KITE_LOG_LEVEL", "environment", ".", "It", "returns", "Info", "by", "default", "if", "no", "environment", "variable", "is", "set", "." ]
baa1a54919e3035417f7571dd46005e91afe8abe
https://github.com/koding/kite/blob/baa1a54919e3035417f7571dd46005e91afe8abe/logger.go#L46-L59
train
koding/kite
logger.go
convertLevel
func convertLevel(l Level) logging.Level { switch l { case DEBUG: return logging.DEBUG case WARNING: return logging.WARNING case ERROR: return logging.ERROR case FATAL: return logging.CRITICAL default: return logging.INFO } }
go
func convertLevel(l Level) logging.Level { switch l { case DEBUG: return logging.DEBUG case WARNING: return logging.WARNING case ERROR: return logging.ERROR case FATAL: return logging.CRITICAL default: return logging.INFO } }
[ "func", "convertLevel", "(", "l", "Level", ")", "logging", ".", "Level", "{", "switch", "l", "{", "case", "DEBUG", ":", "return", "logging", ".", "DEBUG", "\n", "case", "WARNING", ":", "return", "logging", ".", "WARNING", "\n", "case", "ERROR", ":", "r...
// convertLevel converts a kite level into logging level
[ "convertLevel", "converts", "a", "kite", "level", "into", "logging", "level" ]
baa1a54919e3035417f7571dd46005e91afe8abe
https://github.com/koding/kite/blob/baa1a54919e3035417f7571dd46005e91afe8abe/logger.go#L62-L75
train
koding/kite
dnode/scrub.go
fields
func (s *Scrubber) fields(rv reflect.Value, path Path, callbacks map[string]Path) { for i := 0; i < rv.NumField(); i++ { sf := rv.Type().Field(i) if sf.PkgPath != "" && !sf.Anonymous { // unexported. continue } // dnode uses JSON package tags for field naming so we need to // discard their comma-separate...
go
func (s *Scrubber) fields(rv reflect.Value, path Path, callbacks map[string]Path) { for i := 0; i < rv.NumField(); i++ { sf := rv.Type().Field(i) if sf.PkgPath != "" && !sf.Anonymous { // unexported. continue } // dnode uses JSON package tags for field naming so we need to // discard their comma-separate...
[ "func", "(", "s", "*", "Scrubber", ")", "fields", "(", "rv", "reflect", ".", "Value", ",", "path", "Path", ",", "callbacks", "map", "[", "string", "]", "Path", ")", "{", "for", "i", ":=", "0", ";", "i", "<", "rv", ".", "NumField", "(", ")", ";"...
// fields walks over a structure and scrubs its fields.
[ "fields", "walks", "over", "a", "structure", "and", "scrubs", "its", "fields", "." ]
baa1a54919e3035417f7571dd46005e91afe8abe
https://github.com/koding/kite/blob/baa1a54919e3035417f7571dd46005e91afe8abe/dnode/scrub.go#L71-L103
train
koding/kite
dnode/scrub.go
methods
func (s *Scrubber) methods(rv reflect.Value, path Path, callbacks map[string]Path) { for i := 0; i < rv.NumMethod(); i++ { if rv.Type().Method(i).PkgPath == "" { // exported cb, ok := rv.Method(i).Interface().(func(*Partial)) if !ok { continue } name := rv.Type().Method(i).Name name = strings.ToL...
go
func (s *Scrubber) methods(rv reflect.Value, path Path, callbacks map[string]Path) { for i := 0; i < rv.NumMethod(); i++ { if rv.Type().Method(i).PkgPath == "" { // exported cb, ok := rv.Method(i).Interface().(func(*Partial)) if !ok { continue } name := rv.Type().Method(i).Name name = strings.ToL...
[ "func", "(", "s", "*", "Scrubber", ")", "methods", "(", "rv", "reflect", ".", "Value", ",", "path", "Path", ",", "callbacks", "map", "[", "string", "]", "Path", ")", "{", "for", "i", ":=", "0", ";", "i", "<", "rv", ".", "NumMethod", "(", ")", "...
// methods walks over a structure and scrubs its exported methods.
[ "methods", "walks", "over", "a", "structure", "and", "scrubs", "its", "exported", "methods", "." ]
baa1a54919e3035417f7571dd46005e91afe8abe
https://github.com/koding/kite/blob/baa1a54919e3035417f7571dd46005e91afe8abe/dnode/scrub.go#L106-L119
train
koding/kite
kontrolclient.go
SetupKontrolClient
func (k *Kite) SetupKontrolClient() error { if k.kontrol.Client != nil { return nil // already prepared } if k.Config.KontrolURL == "" { return errors.New("no kontrol URL given in config") } client := k.NewClient(k.Config.KontrolURL) client.Kite = protocol.Kite{Name: "kontrol"} // for logging purposes clie...
go
func (k *Kite) SetupKontrolClient() error { if k.kontrol.Client != nil { return nil // already prepared } if k.Config.KontrolURL == "" { return errors.New("no kontrol URL given in config") } client := k.NewClient(k.Config.KontrolURL) client.Kite = protocol.Kite{Name: "kontrol"} // for logging purposes clie...
[ "func", "(", "k", "*", "Kite", ")", "SetupKontrolClient", "(", ")", "error", "{", "if", "k", ".", "kontrol", ".", "Client", "!=", "nil", "{", "return", "nil", "// already prepared", "\n", "}", "\n\n", "if", "k", ".", "Config", ".", "KontrolURL", "==", ...
// SetupKontrolClient setups and prepares a the kontrol instance. It connects // to kontrol and reconnects again if there is any disconnections. This method // is called internally whenever a kontrol client specific action is taking. // However if you wish to connect earlier you may call this method.
[ "SetupKontrolClient", "setups", "and", "prepares", "a", "the", "kontrol", "instance", ".", "It", "connects", "to", "kontrol", "and", "reconnects", "again", "if", "there", "is", "any", "disconnections", ".", "This", "method", "is", "called", "internally", "whenev...
baa1a54919e3035417f7571dd46005e91afe8abe
https://github.com/koding/kite/blob/baa1a54919e3035417f7571dd46005e91afe8abe/kontrolclient.go#L53-L102
train
koding/kite
kontrolclient.go
GetToken
func (k *Kite) GetToken(kite *protocol.Kite) (string, error) { if err := k.SetupKontrolClient(); err != nil { return "", err } <-k.kontrol.readyConnected result, err := k.kontrol.TellWithTimeout("getToken", k.Config.Timeout, kite) if err != nil { return "", err } var tkn string err = result.Unmarshal(&tk...
go
func (k *Kite) GetToken(kite *protocol.Kite) (string, error) { if err := k.SetupKontrolClient(); err != nil { return "", err } <-k.kontrol.readyConnected result, err := k.kontrol.TellWithTimeout("getToken", k.Config.Timeout, kite) if err != nil { return "", err } var tkn string err = result.Unmarshal(&tk...
[ "func", "(", "k", "*", "Kite", ")", "GetToken", "(", "kite", "*", "protocol", ".", "Kite", ")", "(", "string", ",", "error", ")", "{", "if", "err", ":=", "k", ".", "SetupKontrolClient", "(", ")", ";", "err", "!=", "nil", "{", "return", "\"", "\""...
// GetToken is used to get a token for a single Kite. // // In case of calling GetToken multiple times, it usually // returns the same token until it expires on Kontrol side.
[ "GetToken", "is", "used", "to", "get", "a", "token", "for", "a", "single", "Kite", ".", "In", "case", "of", "calling", "GetToken", "multiple", "times", "it", "usually", "returns", "the", "same", "token", "until", "it", "expires", "on", "Kontrol", "side", ...
baa1a54919e3035417f7571dd46005e91afe8abe
https://github.com/koding/kite/blob/baa1a54919e3035417f7571dd46005e91afe8abe/kontrolclient.go#L187-L206
train
koding/kite
kontrolclient.go
GetTokenForce
func (k *Kite) GetTokenForce(kite *protocol.Kite) (string, error) { if err := k.SetupKontrolClient(); err != nil { return "", err } <-k.kontrol.readyConnected args := &protocol.GetTokenArgs{ KontrolQuery: *kite.Query(), Force: true, } result, err := k.kontrol.TellWithTimeout("getToken", k.Config.T...
go
func (k *Kite) GetTokenForce(kite *protocol.Kite) (string, error) { if err := k.SetupKontrolClient(); err != nil { return "", err } <-k.kontrol.readyConnected args := &protocol.GetTokenArgs{ KontrolQuery: *kite.Query(), Force: true, } result, err := k.kontrol.TellWithTimeout("getToken", k.Config.T...
[ "func", "(", "k", "*", "Kite", ")", "GetTokenForce", "(", "kite", "*", "protocol", ".", "Kite", ")", "(", "string", ",", "error", ")", "{", "if", "err", ":=", "k", ".", "SetupKontrolClient", "(", ")", ";", "err", "!=", "nil", "{", "return", "\"", ...
// GetTokenForce is used to obtain a new token for the given kite. // // It always returns a new token and forces a Kontrol to // forget about any previous ones.
[ "GetTokenForce", "is", "used", "to", "obtain", "a", "new", "token", "for", "the", "given", "kite", ".", "It", "always", "returns", "a", "new", "token", "and", "forces", "a", "Kontrol", "to", "forget", "about", "any", "previous", "ones", "." ]
baa1a54919e3035417f7571dd46005e91afe8abe
https://github.com/koding/kite/blob/baa1a54919e3035417f7571dd46005e91afe8abe/kontrolclient.go#L224-L248
train
koding/kite
kontrolclient.go
GetKey
func (k *Kite) GetKey() (string, error) { if err := k.SetupKontrolClient(); err != nil { return "", err } <-k.kontrol.readyConnected result, err := k.kontrol.TellWithTimeout("getKey", k.Config.Timeout) if err != nil { return "", err } var key string err = result.Unmarshal(&key) if err != nil { return ...
go
func (k *Kite) GetKey() (string, error) { if err := k.SetupKontrolClient(); err != nil { return "", err } <-k.kontrol.readyConnected result, err := k.kontrol.TellWithTimeout("getKey", k.Config.Timeout) if err != nil { return "", err } var key string err = result.Unmarshal(&key) if err != nil { return ...
[ "func", "(", "k", "*", "Kite", ")", "GetKey", "(", ")", "(", "string", ",", "error", ")", "{", "if", "err", ":=", "k", ".", "SetupKontrolClient", "(", ")", ";", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "err", "\n", "}", "\n\n", "<-",...
// GetKey is used to get a new public key from kontrol if the current one is // invalidated. The key is also replaced in memory and every request is going // to use it. This means even if kite.key contains the old key, the kite itself // uses the new one.
[ "GetKey", "is", "used", "to", "get", "a", "new", "public", "key", "from", "kontrol", "if", "the", "current", "one", "is", "invalidated", ".", "The", "key", "is", "also", "replaced", "in", "memory", "and", "every", "request", "is", "going", "to", "use", ...
baa1a54919e3035417f7571dd46005e91afe8abe
https://github.com/koding/kite/blob/baa1a54919e3035417f7571dd46005e91afe8abe/kontrolclient.go#L254-L277
train
koding/kite
kontrolclient.go
NewKeyRenewer
func (k *Kite) NewKeyRenewer(interval time.Duration) { ticker := time.NewTicker(interval) for range ticker.C { _, err := k.GetKey() if err != nil { k.Log.Warning("Key renew failed: %s", err) } } }
go
func (k *Kite) NewKeyRenewer(interval time.Duration) { ticker := time.NewTicker(interval) for range ticker.C { _, err := k.GetKey() if err != nil { k.Log.Warning("Key renew failed: %s", err) } } }
[ "func", "(", "k", "*", "Kite", ")", "NewKeyRenewer", "(", "interval", "time", ".", "Duration", ")", "{", "ticker", ":=", "time", ".", "NewTicker", "(", "interval", ")", "\n", "for", "range", "ticker", ".", "C", "{", "_", ",", "err", ":=", "k", ".",...
// NewKeyRenewer renews the internal key every given interval
[ "NewKeyRenewer", "renews", "the", "internal", "key", "every", "given", "interval" ]
baa1a54919e3035417f7571dd46005e91afe8abe
https://github.com/koding/kite/blob/baa1a54919e3035417f7571dd46005e91afe8abe/kontrolclient.go#L280-L288
train
koding/kite
kontrolclient.go
signalReady
func (k *Kite) signalReady() { k.kontrol.onceRegistered.Do(func() { close(k.kontrol.readyRegistered) }) }
go
func (k *Kite) signalReady() { k.kontrol.onceRegistered.Do(func() { close(k.kontrol.readyRegistered) }) }
[ "func", "(", "k", "*", "Kite", ")", "signalReady", "(", ")", "{", "k", ".", "kontrol", ".", "onceRegistered", ".", "Do", "(", "func", "(", ")", "{", "close", "(", "k", ".", "kontrol", ".", "readyRegistered", ")", "}", ")", "\n", "}" ]
// signalReady is an internal method to notify that a successful registration // is done.
[ "signalReady", "is", "an", "internal", "method", "to", "notify", "that", "a", "successful", "registration", "is", "done", "." ]
baa1a54919e3035417f7571dd46005e91afe8abe
https://github.com/koding/kite/blob/baa1a54919e3035417f7571dd46005e91afe8abe/kontrolclient.go#L298-L300
train
koding/kite
kontrolclient.go
RegisterToTunnel
func (k *Kite) RegisterToTunnel() { query := &protocol.KontrolQuery{ Username: k.Config.KontrolUser, Environment: k.Config.Environment, Name: "tunnelproxy", } k.RegisterToProxy(nil, query) }
go
func (k *Kite) RegisterToTunnel() { query := &protocol.KontrolQuery{ Username: k.Config.KontrolUser, Environment: k.Config.Environment, Name: "tunnelproxy", } k.RegisterToProxy(nil, query) }
[ "func", "(", "k", "*", "Kite", ")", "RegisterToTunnel", "(", ")", "{", "query", ":=", "&", "protocol", ".", "KontrolQuery", "{", "Username", ":", "k", ".", "Config", ".", "KontrolUser", ",", "Environment", ":", "k", ".", "Config", ".", "Environment", "...
// RegisterToTunnel finds a tunnel proxy kite by asking kontrol then registers // itself on proxy. On error, retries forever. On every successful // registration, it sends the proxied URL to the registerChan channel. There is // no register URL needed because the Tunnel Proxy automatically gets the IP // from tunneling...
[ "RegisterToTunnel", "finds", "a", "tunnel", "proxy", "kite", "by", "asking", "kontrol", "then", "registers", "itself", "on", "proxy", ".", "On", "error", "retries", "forever", ".", "On", "every", "successful", "registration", "it", "sends", "the", "proxied", "...
baa1a54919e3035417f7571dd46005e91afe8abe
https://github.com/koding/kite/blob/baa1a54919e3035417f7571dd46005e91afe8abe/kontrolclient.go#L398-L406
train
koding/kite
kontrolclient.go
RegisterToProxy
func (k *Kite) RegisterToProxy(registerURL *url.URL, query *protocol.KontrolQuery) { go k.RegisterForever(nil) for { var proxyKite *Client // The proxy kite to connect can be overridden with the // environmental variable "KITE_PROXY_URL". If it is not set // we will ask Kontrol for available Proxy kites. ...
go
func (k *Kite) RegisterToProxy(registerURL *url.URL, query *protocol.KontrolQuery) { go k.RegisterForever(nil) for { var proxyKite *Client // The proxy kite to connect can be overridden with the // environmental variable "KITE_PROXY_URL". If it is not set // we will ask Kontrol for available Proxy kites. ...
[ "func", "(", "k", "*", "Kite", ")", "RegisterToProxy", "(", "registerURL", "*", "url", ".", "URL", ",", "query", "*", "protocol", ".", "KontrolQuery", ")", "{", "go", "k", ".", "RegisterForever", "(", "nil", ")", "\n\n", "for", "{", "var", "proxyKite",...
// RegisterToProxy is just like RegisterForever but registers the given URL // to kontrol over a kite-proxy. A Kiteproxy is a reverseproxy that can be used // for SSL termination or handling hundreds of kites behind a single. This is a // blocking function.
[ "RegisterToProxy", "is", "just", "like", "RegisterForever", "but", "registers", "the", "given", "URL", "to", "kontrol", "over", "a", "kite", "-", "proxy", ".", "A", "Kiteproxy", "is", "a", "reverseproxy", "that", "can", "be", "used", "for", "SSL", "terminati...
baa1a54919e3035417f7571dd46005e91afe8abe
https://github.com/koding/kite/blob/baa1a54919e3035417f7571dd46005e91afe8abe/kontrolclient.go#L412-L463
train
koding/kite
kontrolclient.go
registerToProxyKite
func (k *Kite) registerToProxyKite(c *Client, kiteURL *url.URL) (*url.URL, error) { err := c.Dial() if err != nil { k.Log.Error("Cannot connect to Proxy kite: %s", err.Error()) return nil, err } // Disconnect from Proxy Kite if error happens while registering. defer func() { if err != nil { c.Close() }...
go
func (k *Kite) registerToProxyKite(c *Client, kiteURL *url.URL) (*url.URL, error) { err := c.Dial() if err != nil { k.Log.Error("Cannot connect to Proxy kite: %s", err.Error()) return nil, err } // Disconnect from Proxy Kite if error happens while registering. defer func() { if err != nil { c.Close() }...
[ "func", "(", "k", "*", "Kite", ")", "registerToProxyKite", "(", "c", "*", "Client", ",", "kiteURL", "*", "url", ".", "URL", ")", "(", "*", "url", ".", "URL", ",", "error", ")", "{", "err", ":=", "c", ".", "Dial", "(", ")", "\n", "if", "err", ...
// registerToProxyKite dials the proxy kite and calls register method then // returns the reverse-proxy URL.
[ "registerToProxyKite", "dials", "the", "proxy", "kite", "and", "calls", "register", "method", "then", "returns", "the", "reverse", "-", "proxy", "URL", "." ]
baa1a54919e3035417f7571dd46005e91afe8abe
https://github.com/koding/kite/blob/baa1a54919e3035417f7571dd46005e91afe8abe/kontrolclient.go#L467-L507
train
koding/kite
kontrolclient.go
TellKontrolWithTimeout
func (k *Kite) TellKontrolWithTimeout(method string, timeout time.Duration, args ...interface{}) (result *dnode.Partial, err error) { if err := k.SetupKontrolClient(); err != nil { return nil, err } // Wait for readyConnect, or timeout select { case <-time.After(k.Config.Timeout): return nil, &Error{ Type:...
go
func (k *Kite) TellKontrolWithTimeout(method string, timeout time.Duration, args ...interface{}) (result *dnode.Partial, err error) { if err := k.SetupKontrolClient(); err != nil { return nil, err } // Wait for readyConnect, or timeout select { case <-time.After(k.Config.Timeout): return nil, &Error{ Type:...
[ "func", "(", "k", "*", "Kite", ")", "TellKontrolWithTimeout", "(", "method", "string", ",", "timeout", "time", ".", "Duration", ",", "args", "...", "interface", "{", "}", ")", "(", "result", "*", "dnode", ".", "Partial", ",", "err", "error", ")", "{", ...
// TellKontrolWithTimeout is a lower level function for communicating directly with // kontrol. Like GetKites and GetToken, this automatically sets up and connects to // kontrol as needed.
[ "TellKontrolWithTimeout", "is", "a", "lower", "level", "function", "for", "communicating", "directly", "with", "kontrol", ".", "Like", "GetKites", "and", "GetToken", "this", "automatically", "sets", "up", "and", "connects", "to", "kontrol", "as", "needed", "." ]
baa1a54919e3035417f7571dd46005e91afe8abe
https://github.com/koding/kite/blob/baa1a54919e3035417f7571dd46005e91afe8abe/kontrolclient.go#L512-L531
train
koding/kite
kontrol/idlock.go
Get
func (i *IdLock) Get(id string) sync.Locker { i.locksMu.Lock() defer i.locksMu.Unlock() var l sync.Locker var ok bool l, ok = i.locks[id] if !ok { l = &sync.Mutex{} i.locks[id] = l } return l }
go
func (i *IdLock) Get(id string) sync.Locker { i.locksMu.Lock() defer i.locksMu.Unlock() var l sync.Locker var ok bool l, ok = i.locks[id] if !ok { l = &sync.Mutex{} i.locks[id] = l } return l }
[ "func", "(", "i", "*", "IdLock", ")", "Get", "(", "id", "string", ")", "sync", ".", "Locker", "{", "i", ".", "locksMu", ".", "Lock", "(", ")", "\n", "defer", "i", ".", "locksMu", ".", "Unlock", "(", ")", "\n\n", "var", "l", "sync", ".", "Locker...
// Get returns a lock that is bound to a specific id.
[ "Get", "returns", "a", "lock", "that", "is", "bound", "to", "a", "specific", "id", "." ]
baa1a54919e3035417f7571dd46005e91afe8abe
https://github.com/koding/kite/blob/baa1a54919e3035417f7571dd46005e91afe8abe/kontrol/idlock.go#L19-L33
train
koding/kite
kitectl/command/list.go
BinPath
func (k *InstalledKite) BinPath() string { return filepath.Join(k.Domain, k.User, k.Repo, k.Version, "bin", strings.TrimSuffix(k.Repo, ".kite")) }
go
func (k *InstalledKite) BinPath() string { return filepath.Join(k.Domain, k.User, k.Repo, k.Version, "bin", strings.TrimSuffix(k.Repo, ".kite")) }
[ "func", "(", "k", "*", "InstalledKite", ")", "BinPath", "(", ")", "string", "{", "return", "filepath", ".", "Join", "(", "k", ".", "Domain", ",", "k", ".", "User", ",", "k", ".", "Repo", ",", "k", ".", "Version", ",", "\"", "\"", ",", "strings", ...
// BinPath returns the path of the executable binary file.
[ "BinPath", "returns", "the", "path", "of", "the", "executable", "binary", "file", "." ]
baa1a54919e3035417f7571dd46005e91afe8abe
https://github.com/koding/kite/blob/baa1a54919e3035417f7571dd46005e91afe8abe/kitectl/command/list.go#L134-L136
train
koding/kite
sockjsclient/sockjsclient.go
Error
func (err *ErrSession) Error() string { if err.Err == nil { return fmt.Sprintf("%s (%s)", stateTexts[err.State], err.Type) } return fmt.Sprintf("%s: %s (%s)", stateTexts[err.State], err.Err, err.Type) }
go
func (err *ErrSession) Error() string { if err.Err == nil { return fmt.Sprintf("%s (%s)", stateTexts[err.State], err.Type) } return fmt.Sprintf("%s: %s (%s)", stateTexts[err.State], err.Err, err.Type) }
[ "func", "(", "err", "*", "ErrSession", ")", "Error", "(", ")", "string", "{", "if", "err", ".", "Err", "==", "nil", "{", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "stateTexts", "[", "err", ".", "State", "]", ",", "err", ".", "Type", ...
// Error implements the buildin error interface.
[ "Error", "implements", "the", "buildin", "error", "interface", "." ]
baa1a54919e3035417f7571dd46005e91afe8abe
https://github.com/koding/kite/blob/baa1a54919e3035417f7571dd46005e91afe8abe/sockjsclient/sockjsclient.go#L51-L56
train
koding/kite
sockjsclient/sockjsclient.go
IsSessionClosed
func IsSessionClosed(err error) bool { switch err { case ErrSessionClosed, sockjs.ErrSessionNotOpen, websocket.ErrCloseSent: return true } if e, ok := err.(*ErrSession); ok && e.State > sockjs.SessionActive { return true } _, ok := err.(*websocket.CloseError) return ok }
go
func IsSessionClosed(err error) bool { switch err { case ErrSessionClosed, sockjs.ErrSessionNotOpen, websocket.ErrCloseSent: return true } if e, ok := err.(*ErrSession); ok && e.State > sockjs.SessionActive { return true } _, ok := err.(*websocket.CloseError) return ok }
[ "func", "IsSessionClosed", "(", "err", "error", ")", "bool", "{", "switch", "err", "{", "case", "ErrSessionClosed", ",", "sockjs", ".", "ErrSessionNotOpen", ",", "websocket", ".", "ErrCloseSent", ":", "return", "true", "\n", "}", "\n", "if", "e", ",", "ok"...
// IsSessionClosed tests whether given error is caused // by a closed session.
[ "IsSessionClosed", "tests", "whether", "given", "error", "is", "caused", "by", "a", "closed", "session", "." ]
baa1a54919e3035417f7571dd46005e91afe8abe
https://github.com/koding/kite/blob/baa1a54919e3035417f7571dd46005e91afe8abe/sockjsclient/sockjsclient.go#L60-L70
train
koding/kite
sockjsclient/sockjsclient.go
DialWebsocket
func DialWebsocket(uri string, cfg *config.Config) (*WebsocketSession, error) { u, err := url.Parse(uri) if err != nil { return nil, err } h := http.Header{ "Origin": {u.Scheme + "://" + u.Host}, } serverID := threeDigits() sessionID := utils.RandomString(20) u = makeWebsocketURL(u, serverID, sessionID) ...
go
func DialWebsocket(uri string, cfg *config.Config) (*WebsocketSession, error) { u, err := url.Parse(uri) if err != nil { return nil, err } h := http.Header{ "Origin": {u.Scheme + "://" + u.Host}, } serverID := threeDigits() sessionID := utils.RandomString(20) u = makeWebsocketURL(u, serverID, sessionID) ...
[ "func", "DialWebsocket", "(", "uri", "string", ",", "cfg", "*", "config", ".", "Config", ")", "(", "*", "WebsocketSession", ",", "error", ")", "{", "u", ",", "err", ":=", "url", ".", "Parse", "(", "uri", ")", "\n", "if", "err", "!=", "nil", "{", ...
// DialWebsocket establishes a SockJS session over a websocket connection. // // Requires cfg.Websocket to be a valid client.
[ "DialWebsocket", "establishes", "a", "SockJS", "session", "over", "a", "websocket", "connection", ".", "Requires", "cfg", ".", "Websocket", "to", "be", "a", "valid", "client", "." ]
baa1a54919e3035417f7571dd46005e91afe8abe
https://github.com/koding/kite/blob/baa1a54919e3035417f7571dd46005e91afe8abe/sockjsclient/sockjsclient.go#L136-L164
train
koding/kite
sockjsclient/sockjsclient.go
Recv
func (w *WebsocketSession) Recv() (string, error) { // Return previously received messages if there is any. if len(w.messages) > 0 { msg := w.messages[0] w.messages = w.messages[1:] return msg, nil } read_frame: if atomic.LoadInt32(&w.closed) == 1 { return "", ErrSessionClosed } // Read one SockJS frame...
go
func (w *WebsocketSession) Recv() (string, error) { // Return previously received messages if there is any. if len(w.messages) > 0 { msg := w.messages[0] w.messages = w.messages[1:] return msg, nil } read_frame: if atomic.LoadInt32(&w.closed) == 1 { return "", ErrSessionClosed } // Read one SockJS frame...
[ "func", "(", "w", "*", "WebsocketSession", ")", "Recv", "(", ")", "(", "string", ",", "error", ")", "{", "// Return previously received messages if there is any.", "if", "len", "(", "w", ".", "messages", ")", ">", "0", "{", "msg", ":=", "w", ".", "messages...
// Recv reads one text frame from session.
[ "Recv", "reads", "one", "text", "frame", "from", "session", "." ]
baa1a54919e3035417f7571dd46005e91afe8abe
https://github.com/koding/kite/blob/baa1a54919e3035417f7571dd46005e91afe8abe/sockjsclient/sockjsclient.go#L198-L259
train
koding/kite
sockjsclient/sockjsclient.go
Send
func (w *WebsocketSession) Send(str string) error { if atomic.LoadInt32(&w.closed) == 1 { return ErrSessionClosed } w.mu.Lock() defer w.mu.Unlock() b, _ := json.Marshal([]string{str}) return w.conn.WriteMessage(websocket.TextMessage, b) }
go
func (w *WebsocketSession) Send(str string) error { if atomic.LoadInt32(&w.closed) == 1 { return ErrSessionClosed } w.mu.Lock() defer w.mu.Unlock() b, _ := json.Marshal([]string{str}) return w.conn.WriteMessage(websocket.TextMessage, b) }
[ "func", "(", "w", "*", "WebsocketSession", ")", "Send", "(", "str", "string", ")", "error", "{", "if", "atomic", ".", "LoadInt32", "(", "&", "w", ".", "closed", ")", "==", "1", "{", "return", "ErrSessionClosed", "\n", "}", "\n\n", "w", ".", "mu", "...
// Send sends one text frame to session
[ "Send", "sends", "one", "text", "frame", "to", "session" ]
baa1a54919e3035417f7571dd46005e91afe8abe
https://github.com/koding/kite/blob/baa1a54919e3035417f7571dd46005e91afe8abe/sockjsclient/sockjsclient.go#L262-L272
train
koding/kite
sockjsclient/sockjsclient.go
Close
func (w *WebsocketSession) Close(uint32, string) error { if atomic.CompareAndSwapInt32(&w.closed, 0, 1) { return w.conn.Close() } return ErrSessionClosed }
go
func (w *WebsocketSession) Close(uint32, string) error { if atomic.CompareAndSwapInt32(&w.closed, 0, 1) { return w.conn.Close() } return ErrSessionClosed }
[ "func", "(", "w", "*", "WebsocketSession", ")", "Close", "(", "uint32", ",", "string", ")", "error", "{", "if", "atomic", ".", "CompareAndSwapInt32", "(", "&", "w", ".", "closed", ",", "0", ",", "1", ")", "{", "return", "w", ".", "conn", ".", "Clos...
// Close closes the session with provided code and reason.
[ "Close", "closes", "the", "session", "with", "provided", "code", "and", "reason", "." ]
baa1a54919e3035417f7571dd46005e91afe8abe
https://github.com/koding/kite/blob/baa1a54919e3035417f7571dd46005e91afe8abe/sockjsclient/sockjsclient.go#L275-L281
train
koding/kite
kitectl/command/uninstall.go
isInstalled
func isInstalled(fullKiteName string) (bool, error) { bundlePath, err := getBundlePath(fullKiteName) if err != nil { return false, err } return exists(bundlePath) }
go
func isInstalled(fullKiteName string) (bool, error) { bundlePath, err := getBundlePath(fullKiteName) if err != nil { return false, err } return exists(bundlePath) }
[ "func", "isInstalled", "(", "fullKiteName", "string", ")", "(", "bool", ",", "error", ")", "{", "bundlePath", ",", "err", ":=", "getBundlePath", "(", "fullKiteName", ")", "\n", "if", "err", "!=", "nil", "{", "return", "false", ",", "err", "\n", "}", "\...
// isInstalled returns true if the kite is installed.
[ "isInstalled", "returns", "true", "if", "the", "kite", "is", "installed", "." ]
baa1a54919e3035417f7571dd46005e91afe8abe
https://github.com/koding/kite/blob/baa1a54919e3035417f7571dd46005e91afe8abe/kitectl/command/uninstall.go#L83-L89
train
koding/kite
kontrol/keypair.go
NewCachedStorage
func NewCachedStorage(backend KeyPairStorage, cache KeyPairStorage) *CachedStorage { return &CachedStorage{ cache: cache, backend: backend, } }
go
func NewCachedStorage(backend KeyPairStorage, cache KeyPairStorage) *CachedStorage { return &CachedStorage{ cache: cache, backend: backend, } }
[ "func", "NewCachedStorage", "(", "backend", "KeyPairStorage", ",", "cache", "KeyPairStorage", ")", "*", "CachedStorage", "{", "return", "&", "CachedStorage", "{", "cache", ":", "cache", ",", "backend", ":", "backend", ",", "}", "\n", "}" ]
// NewCachedStorage creates a new CachedStorage
[ "NewCachedStorage", "creates", "a", "new", "CachedStorage" ]
baa1a54919e3035417f7571dd46005e91afe8abe
https://github.com/koding/kite/blob/baa1a54919e3035417f7571dd46005e91afe8abe/kontrol/keypair.go#L150-L155
train
koding/kite
kontrol/kites.go
Attach
func (k Kites) Attach(token string) { for _, kite := range k { kite.Token = token } }
go
func (k Kites) Attach(token string) { for _, kite := range k { kite.Token = token } }
[ "func", "(", "k", "Kites", ")", "Attach", "(", "token", "string", ")", "{", "for", "_", ",", "kite", ":=", "range", "k", "{", "kite", ".", "Token", "=", "token", "\n", "}", "\n", "}" ]
// Attach attaches the given token to each kite. It replaces any previous // token.
[ "Attach", "attaches", "the", "given", "token", "to", "each", "kite", ".", "It", "replaces", "any", "previous", "token", "." ]
baa1a54919e3035417f7571dd46005e91afe8abe
https://github.com/koding/kite/blob/baa1a54919e3035417f7571dd46005e91afe8abe/kontrol/kites.go#L16-L20
train
koding/kite
kontrol/kites.go
Shuffle
func (k *Kites) Shuffle() { shuffled := make(Kites, len(*k)) for i, v := range rand.Perm(len(*k)) { shuffled[v] = (*k)[i] } *k = shuffled }
go
func (k *Kites) Shuffle() { shuffled := make(Kites, len(*k)) for i, v := range rand.Perm(len(*k)) { shuffled[v] = (*k)[i] } *k = shuffled }
[ "func", "(", "k", "*", "Kites", ")", "Shuffle", "(", ")", "{", "shuffled", ":=", "make", "(", "Kites", ",", "len", "(", "*", "k", ")", ")", "\n", "for", "i", ",", "v", ":=", "range", "rand", ".", "Perm", "(", "len", "(", "*", "k", ")", ")",...
// Shuffle shuffles the order of the kites. This is useful if you want send // back a randomized list of kites.
[ "Shuffle", "shuffles", "the", "order", "of", "the", "kites", ".", "This", "is", "useful", "if", "you", "want", "send", "back", "a", "randomized", "list", "of", "kites", "." ]
baa1a54919e3035417f7571dd46005e91afe8abe
https://github.com/koding/kite/blob/baa1a54919e3035417f7571dd46005e91afe8abe/kontrol/kites.go#L24-L31
train
koding/kite
kontrol/kites.go
Filter
func (k *Kites) Filter(constraint version.Constraints, keyRest string) { filtered := make(Kites, 0) for _, kite := range *k { if isValid(&kite.Kite, constraint, keyRest) { filtered = append(filtered, kite) } } *k = filtered }
go
func (k *Kites) Filter(constraint version.Constraints, keyRest string) { filtered := make(Kites, 0) for _, kite := range *k { if isValid(&kite.Kite, constraint, keyRest) { filtered = append(filtered, kite) } } *k = filtered }
[ "func", "(", "k", "*", "Kites", ")", "Filter", "(", "constraint", "version", ".", "Constraints", ",", "keyRest", "string", ")", "{", "filtered", ":=", "make", "(", "Kites", ",", "0", ")", "\n", "for", "_", ",", "kite", ":=", "range", "*", "k", "{",...
// Filter filters out kites with the given constraints
[ "Filter", "filters", "out", "kites", "with", "the", "given", "constraints" ]
baa1a54919e3035417f7571dd46005e91afe8abe
https://github.com/koding/kite/blob/baa1a54919e3035417f7571dd46005e91afe8abe/kontrol/kites.go#L34-L43
train
koding/kite
client.go
DialForever
func (c *Client) DialForever() (connected chan bool, err error) { c.Reconnect = true connected = make(chan bool, 1) // This will be closed on first connection. go c.dialForever(connected) return }
go
func (c *Client) DialForever() (connected chan bool, err error) { c.Reconnect = true connected = make(chan bool, 1) // This will be closed on first connection. go c.dialForever(connected) return }
[ "func", "(", "c", "*", "Client", ")", "DialForever", "(", ")", "(", "connected", "chan", "bool", ",", "err", "error", ")", "{", "c", ".", "Reconnect", "=", "true", "\n", "connected", "=", "make", "(", "chan", "bool", ",", "1", ")", "// This will be c...
// Dial connects to the remote Kite. If it can't connect, it retries // indefinitely. It returns a channel to check if it's connected or not.
[ "Dial", "connects", "to", "the", "remote", "Kite", ".", "If", "it", "can", "t", "connect", "it", "retries", "indefinitely", ".", "It", "returns", "a", "channel", "to", "check", "if", "it", "s", "connected", "or", "not", "." ]
baa1a54919e3035417f7571dd46005e91afe8abe
https://github.com/koding/kite/blob/baa1a54919e3035417f7571dd46005e91afe8abe/client.go#L256-L261
train
koding/kite
client.go
run
func (c *Client) run() { err := c.readLoop() if err != nil { c.LocalKite.Log.Debug("readloop err: %s", err) } // falls here when connection disconnects c.callOnDisconnectHandlers() // let others know that the client has disconnected c.disconnectMu.Lock() if c.disconnect != nil { close(c.disconnect) c.di...
go
func (c *Client) run() { err := c.readLoop() if err != nil { c.LocalKite.Log.Debug("readloop err: %s", err) } // falls here when connection disconnects c.callOnDisconnectHandlers() // let others know that the client has disconnected c.disconnectMu.Lock() if c.disconnect != nil { close(c.disconnect) c.di...
[ "func", "(", "c", "*", "Client", ")", "run", "(", ")", "{", "err", ":=", "c", ".", "readLoop", "(", ")", "\n", "if", "err", "!=", "nil", "{", "c", ".", "LocalKite", ".", "Log", ".", "Debug", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\...
// run consumes incoming dnode messages. Reconnects if necessary.
[ "run", "consumes", "incoming", "dnode", "messages", ".", "Reconnects", "if", "necessary", "." ]
baa1a54919e3035417f7571dd46005e91afe8abe
https://github.com/koding/kite/blob/baa1a54919e3035417f7571dd46005e91afe8abe/client.go#L388-L415
train
koding/kite
client.go
readLoop
func (c *Client) readLoop() error { for { p, err := c.receiveData() c.LocalKite.Log.Debug("readloop received: %s %v", p, err) if err != nil { return err } msg, fn, err := c.processMessage(p) if err != nil { if _, ok := err.(dnode.CallbackNotFoundError); !ok { c.LocalKite.Log.Warning("error pro...
go
func (c *Client) readLoop() error { for { p, err := c.receiveData() c.LocalKite.Log.Debug("readloop received: %s %v", p, err) if err != nil { return err } msg, fn, err := c.processMessage(p) if err != nil { if _, ok := err.(dnode.CallbackNotFoundError); !ok { c.LocalKite.Log.Warning("error pro...
[ "func", "(", "c", "*", "Client", ")", "readLoop", "(", ")", "error", "{", "for", "{", "p", ",", "err", ":=", "c", ".", "receiveData", "(", ")", "\n\n", "c", ".", "LocalKite", ".", "Log", ".", "Debug", "(", "\"", "\"", ",", "p", ",", "err", ")...
// readLoop reads a message from websocket and processes it.
[ "readLoop", "reads", "a", "message", "from", "websocket", "and", "processes", "it", "." ]
baa1a54919e3035417f7571dd46005e91afe8abe
https://github.com/koding/kite/blob/baa1a54919e3035417f7571dd46005e91afe8abe/client.go#L425-L457
train
koding/kite
client.go
receiveData
func (c *Client) receiveData() ([]byte, error) { type recv struct { msg []byte err error } session := c.getSession() if session == nil { return nil, errors.New("not connected") } done := make(chan recv, 1) go func() { msg, err := session.Recv() done <- recv{[]byte(msg), err} }() select { case r ...
go
func (c *Client) receiveData() ([]byte, error) { type recv struct { msg []byte err error } session := c.getSession() if session == nil { return nil, errors.New("not connected") } done := make(chan recv, 1) go func() { msg, err := session.Recv() done <- recv{[]byte(msg), err} }() select { case r ...
[ "func", "(", "c", "*", "Client", ")", "receiveData", "(", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "type", "recv", "struct", "{", "msg", "[", "]", "byte", "\n", "err", "error", "\n", "}", "\n\n", "session", ":=", "c", ".", "getSession"...
// receiveData reads a message from session.
[ "receiveData", "reads", "a", "message", "from", "session", "." ]
baa1a54919e3035417f7571dd46005e91afe8abe
https://github.com/koding/kite/blob/baa1a54919e3035417f7571dd46005e91afe8abe/client.go#L460-L484
train
koding/kite
client.go
processMessage
func (c *Client) processMessage(data []byte) (msg *dnode.Message, fn interface{}, err error) { // Call error handler. defer func() { if err != nil { onError(err) } }() msg = &dnode.Message{} if err = json.Unmarshal(data, &msg); err != nil { return nil, nil, err } sender := func(id uint64, args []inte...
go
func (c *Client) processMessage(data []byte) (msg *dnode.Message, fn interface{}, err error) { // Call error handler. defer func() { if err != nil { onError(err) } }() msg = &dnode.Message{} if err = json.Unmarshal(data, &msg); err != nil { return nil, nil, err } sender := func(id uint64, args []inte...
[ "func", "(", "c", "*", "Client", ")", "processMessage", "(", "data", "[", "]", "byte", ")", "(", "msg", "*", "dnode", ".", "Message", ",", "fn", "interface", "{", "}", ",", "err", "error", ")", "{", "// Call error handler.", "defer", "func", "(", ")"...
// processMessage processes a single message and calls a handler or callback.
[ "processMessage", "processes", "a", "single", "message", "and", "calls", "a", "handler", "or", "callback", "." ]
baa1a54919e3035417f7571dd46005e91afe8abe
https://github.com/koding/kite/blob/baa1a54919e3035417f7571dd46005e91afe8abe/client.go#L487-L541
train
koding/kite
client.go
sendHub
func (c *Client) sendHub() { defer c.wg.Done() for { select { case msg := <-c.send: c.LocalKite.Log.Debug("sending: %s", msg) session := c.getSession() if session == nil { c.LocalKite.Log.Error("not connected") continue } err := session.Send(string(msg.p)) if err != nil { if msg.er...
go
func (c *Client) sendHub() { defer c.wg.Done() for { select { case msg := <-c.send: c.LocalKite.Log.Debug("sending: %s", msg) session := c.getSession() if session == nil { c.LocalKite.Log.Error("not connected") continue } err := session.Send(string(msg.p)) if err != nil { if msg.er...
[ "func", "(", "c", "*", "Client", ")", "sendHub", "(", ")", "{", "defer", "c", ".", "wg", ".", "Done", "(", ")", "\n\n", "for", "{", "select", "{", "case", "msg", ":=", "<-", "c", ".", "send", ":", "c", ".", "LocalKite", ".", "Log", ".", "Debu...
// sendhub sends the msg received from the send channel to the remote client
[ "sendhub", "sends", "the", "msg", "received", "from", "the", "send", "channel", "to", "the", "remote", "client" ]
baa1a54919e3035417f7571dd46005e91afe8abe
https://github.com/koding/kite/blob/baa1a54919e3035417f7571dd46005e91afe8abe/client.go#L572-L607
train
koding/kite
client.go
OnConnect
func (c *Client) OnConnect(handler func()) { c.m.Lock() c.onConnectHandlers = append(c.onConnectHandlers, handler) c.m.Unlock() }
go
func (c *Client) OnConnect(handler func()) { c.m.Lock() c.onConnectHandlers = append(c.onConnectHandlers, handler) c.m.Unlock() }
[ "func", "(", "c", "*", "Client", ")", "OnConnect", "(", "handler", "func", "(", ")", ")", "{", "c", ".", "m", ".", "Lock", "(", ")", "\n", "c", ".", "onConnectHandlers", "=", "append", "(", "c", ".", "onConnectHandlers", ",", "handler", ")", "\n", ...
// OnConnect adds a callback which is called when client connects // to a remote kite.
[ "OnConnect", "adds", "a", "callback", "which", "is", "called", "when", "client", "connects", "to", "a", "remote", "kite", "." ]
baa1a54919e3035417f7571dd46005e91afe8abe
https://github.com/koding/kite/blob/baa1a54919e3035417f7571dd46005e91afe8abe/client.go#L611-L615
train
koding/kite
client.go
OnDisconnect
func (c *Client) OnDisconnect(handler func()) { c.m.Lock() c.onDisconnectHandlers = append(c.onDisconnectHandlers, handler) c.m.Unlock() }
go
func (c *Client) OnDisconnect(handler func()) { c.m.Lock() c.onDisconnectHandlers = append(c.onDisconnectHandlers, handler) c.m.Unlock() }
[ "func", "(", "c", "*", "Client", ")", "OnDisconnect", "(", "handler", "func", "(", ")", ")", "{", "c", ".", "m", ".", "Lock", "(", ")", "\n", "c", ".", "onDisconnectHandlers", "=", "append", "(", "c", ".", "onDisconnectHandlers", ",", "handler", ")",...
// OnDisconnect adds a callback which is called when client disconnects // from a remote kite.
[ "OnDisconnect", "adds", "a", "callback", "which", "is", "called", "when", "client", "disconnects", "from", "a", "remote", "kite", "." ]
baa1a54919e3035417f7571dd46005e91afe8abe
https://github.com/koding/kite/blob/baa1a54919e3035417f7571dd46005e91afe8abe/client.go#L619-L623
train
koding/kite
client.go
OnTokenExpire
func (c *Client) OnTokenExpire(handler func()) { c.m.Lock() c.onTokenExpireHandlers = append(c.onTokenExpireHandlers, handler) c.m.Unlock() }
go
func (c *Client) OnTokenExpire(handler func()) { c.m.Lock() c.onTokenExpireHandlers = append(c.onTokenExpireHandlers, handler) c.m.Unlock() }
[ "func", "(", "c", "*", "Client", ")", "OnTokenExpire", "(", "handler", "func", "(", ")", ")", "{", "c", ".", "m", ".", "Lock", "(", ")", "\n", "c", ".", "onTokenExpireHandlers", "=", "append", "(", "c", ".", "onTokenExpireHandlers", ",", "handler", "...
// OnTokenExpire adds a callback which is called when client receives // token-is-expired error from a remote kite.
[ "OnTokenExpire", "adds", "a", "callback", "which", "is", "called", "when", "client", "receives", "token", "-", "is", "-", "expired", "error", "from", "a", "remote", "kite", "." ]
baa1a54919e3035417f7571dd46005e91afe8abe
https://github.com/koding/kite/blob/baa1a54919e3035417f7571dd46005e91afe8abe/client.go#L627-L631
train
koding/kite
client.go
OnTokenRenew
func (c *Client) OnTokenRenew(handler func(token string)) { c.m.Lock() c.onTokenRenewHandlers = append(c.onTokenRenewHandlers, handler) c.m.Unlock() }
go
func (c *Client) OnTokenRenew(handler func(token string)) { c.m.Lock() c.onTokenRenewHandlers = append(c.onTokenRenewHandlers, handler) c.m.Unlock() }
[ "func", "(", "c", "*", "Client", ")", "OnTokenRenew", "(", "handler", "func", "(", "token", "string", ")", ")", "{", "c", ".", "m", ".", "Lock", "(", ")", "\n", "c", ".", "onTokenRenewHandlers", "=", "append", "(", "c", ".", "onTokenRenewHandlers", "...
// OnTokenRenew adds a callback which is called when client successfully // renews its token.
[ "OnTokenRenew", "adds", "a", "callback", "which", "is", "called", "when", "client", "successfully", "renews", "its", "token", "." ]
baa1a54919e3035417f7571dd46005e91afe8abe
https://github.com/koding/kite/blob/baa1a54919e3035417f7571dd46005e91afe8abe/client.go#L635-L639
train
koding/kite
client.go
callOnConnectHandlers
func (c *Client) callOnConnectHandlers() { c.m.RLock() defer c.m.RUnlock() for _, handler := range c.onConnectHandlers { func() { defer nopRecover() handler() }() } }
go
func (c *Client) callOnConnectHandlers() { c.m.RLock() defer c.m.RUnlock() for _, handler := range c.onConnectHandlers { func() { defer nopRecover() handler() }() } }
[ "func", "(", "c", "*", "Client", ")", "callOnConnectHandlers", "(", ")", "{", "c", ".", "m", ".", "RLock", "(", ")", "\n", "defer", "c", ".", "m", ".", "RUnlock", "(", ")", "\n\n", "for", "_", ",", "handler", ":=", "range", "c", ".", "onConnectHa...
// callOnConnectHandlers runs the registered connect handlers.
[ "callOnConnectHandlers", "runs", "the", "registered", "connect", "handlers", "." ]
baa1a54919e3035417f7571dd46005e91afe8abe
https://github.com/koding/kite/blob/baa1a54919e3035417f7571dd46005e91afe8abe/client.go#L642-L652
train
koding/kite
client.go
callOnDisconnectHandlers
func (c *Client) callOnDisconnectHandlers() { c.m.RLock() defer c.m.RUnlock() for _, handler := range c.onDisconnectHandlers { func() { defer nopRecover() handler() }() } }
go
func (c *Client) callOnDisconnectHandlers() { c.m.RLock() defer c.m.RUnlock() for _, handler := range c.onDisconnectHandlers { func() { defer nopRecover() handler() }() } }
[ "func", "(", "c", "*", "Client", ")", "callOnDisconnectHandlers", "(", ")", "{", "c", ".", "m", ".", "RLock", "(", ")", "\n", "defer", "c", ".", "m", ".", "RUnlock", "(", ")", "\n\n", "for", "_", ",", "handler", ":=", "range", "c", ".", "onDiscon...
// callOnDisconnectHandlers runs the registered disconnect handlers.
[ "callOnDisconnectHandlers", "runs", "the", "registered", "disconnect", "handlers", "." ]
baa1a54919e3035417f7571dd46005e91afe8abe
https://github.com/koding/kite/blob/baa1a54919e3035417f7571dd46005e91afe8abe/client.go#L655-L665
train
koding/kite
client.go
callOnTokenExpireHandlers
func (c *Client) callOnTokenExpireHandlers() { c.m.RLock() defer c.m.RUnlock() for _, handler := range c.onTokenExpireHandlers { func() { defer nopRecover() handler() }() } }
go
func (c *Client) callOnTokenExpireHandlers() { c.m.RLock() defer c.m.RUnlock() for _, handler := range c.onTokenExpireHandlers { func() { defer nopRecover() handler() }() } }
[ "func", "(", "c", "*", "Client", ")", "callOnTokenExpireHandlers", "(", ")", "{", "c", ".", "m", ".", "RLock", "(", ")", "\n", "defer", "c", ".", "m", ".", "RUnlock", "(", ")", "\n\n", "for", "_", ",", "handler", ":=", "range", "c", ".", "onToken...
// callOnTokenExpireHandlers calls registered functions when an error // from remote kite is received that token used is expired.
[ "callOnTokenExpireHandlers", "calls", "registered", "functions", "when", "an", "error", "from", "remote", "kite", "is", "received", "that", "token", "used", "is", "expired", "." ]
baa1a54919e3035417f7571dd46005e91afe8abe
https://github.com/koding/kite/blob/baa1a54919e3035417f7571dd46005e91afe8abe/client.go#L669-L679
train
koding/kite
client.go
callOnTokenRenewHandlers
func (c *Client) callOnTokenRenewHandlers(token string) { c.m.RLock() defer c.m.RUnlock() for _, handler := range c.onTokenRenewHandlers { func() { defer nopRecover() handler(token) }() } }
go
func (c *Client) callOnTokenRenewHandlers(token string) { c.m.RLock() defer c.m.RUnlock() for _, handler := range c.onTokenRenewHandlers { func() { defer nopRecover() handler(token) }() } }
[ "func", "(", "c", "*", "Client", ")", "callOnTokenRenewHandlers", "(", "token", "string", ")", "{", "c", ".", "m", ".", "RLock", "(", ")", "\n", "defer", "c", ".", "m", ".", "RUnlock", "(", ")", "\n\n", "for", "_", ",", "handler", ":=", "range", ...
// callOnTokenRenewHandlers calls all registered functions when // we successfully obtain new token from kontrol.
[ "callOnTokenRenewHandlers", "calls", "all", "registered", "functions", "when", "we", "successfully", "obtain", "new", "token", "from", "kontrol", "." ]
baa1a54919e3035417f7571dd46005e91afe8abe
https://github.com/koding/kite/blob/baa1a54919e3035417f7571dd46005e91afe8abe/client.go#L683-L693
train
koding/kite
client.go
Tell
func (c *Client) Tell(method string, args ...interface{}) (result *dnode.Partial, err error) { return c.TellWithTimeout(method, 0, args...) }
go
func (c *Client) Tell(method string, args ...interface{}) (result *dnode.Partial, err error) { return c.TellWithTimeout(method, 0, args...) }
[ "func", "(", "c", "*", "Client", ")", "Tell", "(", "method", "string", ",", "args", "...", "interface", "{", "}", ")", "(", "result", "*", "dnode", ".", "Partial", ",", "err", "error", ")", "{", "return", "c", ".", "TellWithTimeout", "(", "method", ...
// Tell makes a blocking method call to the server. // Waits until the callback function is called by the other side and // returns the result and the error.
[ "Tell", "makes", "a", "blocking", "method", "call", "to", "the", "server", ".", "Waits", "until", "the", "callback", "function", "is", "called", "by", "the", "other", "side", "and", "returns", "the", "result", "and", "the", "error", "." ]
baa1a54919e3035417f7571dd46005e91afe8abe
https://github.com/koding/kite/blob/baa1a54919e3035417f7571dd46005e91afe8abe/client.go#L710-L712
train
koding/kite
client.go
Go
func (c *Client) Go(method string, args ...interface{}) chan *response { return c.GoWithTimeout(method, 0, args...) }
go
func (c *Client) Go(method string, args ...interface{}) chan *response { return c.GoWithTimeout(method, 0, args...) }
[ "func", "(", "c", "*", "Client", ")", "Go", "(", "method", "string", ",", "args", "...", "interface", "{", "}", ")", "chan", "*", "response", "{", "return", "c", ".", "GoWithTimeout", "(", "method", ",", "0", ",", "args", "...", ")", "\n", "}" ]
// Go makes an unblocking method call to the server. // It returns a channel that the caller can wait on it to get the response.
[ "Go", "makes", "an", "unblocking", "method", "call", "to", "the", "server", ".", "It", "returns", "a", "channel", "that", "the", "caller", "can", "wait", "on", "it", "to", "get", "the", "response", "." ]
baa1a54919e3035417f7571dd46005e91afe8abe
https://github.com/koding/kite/blob/baa1a54919e3035417f7571dd46005e91afe8abe/client.go#L734-L736
train
koding/kite
client.go
sendMethod
func (c *Client) sendMethod(method string, args []interface{}, timeout time.Duration, responseChan chan *response) { // To clean the sent callback after response is received. // Send/Receive in a channel to prevent race condition because // the callback is run in a separate goroutine. removeCallback := make(chan ui...
go
func (c *Client) sendMethod(method string, args []interface{}, timeout time.Duration, responseChan chan *response) { // To clean the sent callback after response is received. // Send/Receive in a channel to prevent race condition because // the callback is run in a separate goroutine. removeCallback := make(chan ui...
[ "func", "(", "c", "*", "Client", ")", "sendMethod", "(", "method", "string", ",", "args", "[", "]", "interface", "{", "}", ",", "timeout", "time", ".", "Duration", ",", "responseChan", "chan", "*", "response", ")", "{", "// To clean the sent callback after r...
// sendMethod wraps the arguments, adds a response callback, // marshals the message and send it over the wire.
[ "sendMethod", "wraps", "the", "arguments", "adds", "a", "response", "callback", "marshals", "the", "message", "and", "send", "it", "over", "the", "wire", "." ]
baa1a54919e3035417f7571dd46005e91afe8abe
https://github.com/koding/kite/blob/baa1a54919e3035417f7571dd46005e91afe8abe/client.go#L753-L834
train
koding/kite
client.go
marshalAndSend
func (c *Client) marshalAndSend(method interface{}, arguments []interface{}) (callbacks map[string]dnode.Path, errC <-chan error, err error) { // scrub trough the arguments and save any callbacks. callbacks = c.scrubber.Scrub(arguments) defer func() { if err != nil { c.removeCallbacks(callbacks) } }() // ...
go
func (c *Client) marshalAndSend(method interface{}, arguments []interface{}) (callbacks map[string]dnode.Path, errC <-chan error, err error) { // scrub trough the arguments and save any callbacks. callbacks = c.scrubber.Scrub(arguments) defer func() { if err != nil { c.removeCallbacks(callbacks) } }() // ...
[ "func", "(", "c", "*", "Client", ")", "marshalAndSend", "(", "method", "interface", "{", "}", ",", "arguments", "[", "]", "interface", "{", "}", ")", "(", "callbacks", "map", "[", "string", "]", "dnode", ".", "Path", ",", "errC", "<-", "chan", "error...
// marshalAndSend takes a method and arguments, scrubs the arguments to create // a dnode message, marshals the message to JSON and sends it over the wire.
[ "marshalAndSend", "takes", "a", "method", "and", "arguments", "scrubs", "the", "arguments", "to", "create", "a", "dnode", "message", "marshals", "the", "message", "to", "JSON", "and", "sends", "it", "over", "the", "wire", "." ]
baa1a54919e3035417f7571dd46005e91afe8abe
https://github.com/koding/kite/blob/baa1a54919e3035417f7571dd46005e91afe8abe/client.go#L838-L886
train
koding/kite
client.go
sendCallbackID
func sendCallbackID(callbacks map[string]dnode.Path, ch chan<- uint64) { // TODO fix finding of responseCallback in dnode message when removing callback for id, path := range callbacks { if len(path) != 2 { continue } p0, ok := path[0].(string) if !ok { continue } p1, ok := path[1].(string) if !ok...
go
func sendCallbackID(callbacks map[string]dnode.Path, ch chan<- uint64) { // TODO fix finding of responseCallback in dnode message when removing callback for id, path := range callbacks { if len(path) != 2 { continue } p0, ok := path[0].(string) if !ok { continue } p1, ok := path[1].(string) if !ok...
[ "func", "sendCallbackID", "(", "callbacks", "map", "[", "string", "]", "dnode", ".", "Path", ",", "ch", "chan", "<-", "uint64", ")", "{", "// TODO fix finding of responseCallback in dnode message when removing callback", "for", "id", ",", "path", ":=", "range", "cal...
// sendCallbackID send the callback number to be deleted after response is received.
[ "sendCallbackID", "send", "the", "callback", "number", "to", "be", "deleted", "after", "response", "is", "received", "." ]
baa1a54919e3035417f7571dd46005e91afe8abe
https://github.com/koding/kite/blob/baa1a54919e3035417f7571dd46005e91afe8abe/client.go#L922-L944
train
koding/kite
client.go
onError
func onError(err error) { // TODO do not marshal options again here switch e := err.(type) { case dnode.MethodNotFoundError: // Tell the requester "method is not found". args, err2 := e.Args.Slice() if err2 != nil { return } if len(args) < 1 { return } var options callOptions if err := args[0]....
go
func onError(err error) { // TODO do not marshal options again here switch e := err.(type) { case dnode.MethodNotFoundError: // Tell the requester "method is not found". args, err2 := e.Args.Slice() if err2 != nil { return } if len(args) < 1 { return } var options callOptions if err := args[0]....
[ "func", "onError", "(", "err", "error", ")", "{", "// TODO do not marshal options again here", "switch", "e", ":=", "err", ".", "(", "type", ")", "{", "case", "dnode", ".", "MethodNotFoundError", ":", "// Tell the requester \"method is not found\".", "args", ",", "e...
// onError is called when an error happened in a method handler.
[ "onError", "is", "called", "when", "an", "error", "happened", "in", "a", "method", "handler", "." ]
baa1a54919e3035417f7571dd46005e91afe8abe
https://github.com/koding/kite/blob/baa1a54919e3035417f7571dd46005e91afe8abe/client.go#L1003-L1032
train
koding/kite
server.go
Run
func (k *Kite) Run() { if os.Getenv("KITE_VERSION") != "" { fmt.Println(k.Kite().Version) os.Exit(0) } // An error string equivalent to net.errClosing for using with http.Serve() // during a graceful exit. Needed to declare here again because it is not // exported by "net" package. const errClosing = "use of...
go
func (k *Kite) Run() { if os.Getenv("KITE_VERSION") != "" { fmt.Println(k.Kite().Version) os.Exit(0) } // An error string equivalent to net.errClosing for using with http.Serve() // during a graceful exit. Needed to declare here again because it is not // exported by "net" package. const errClosing = "use of...
[ "func", "(", "k", "*", "Kite", ")", "Run", "(", ")", "{", "if", "os", ".", "Getenv", "(", "\"", "\"", ")", "!=", "\"", "\"", "{", "fmt", ".", "Println", "(", "k", ".", "Kite", "(", ")", ".", "Version", ")", "\n", "os", ".", "Exit", "(", "...
// Run is a blocking method. It runs the kite server and then accepts requests // asynchronously. It supports graceful restart via SIGUSR2.
[ "Run", "is", "a", "blocking", "method", ".", "It", "runs", "the", "kite", "server", "and", "then", "accepts", "requests", "asynchronously", ".", "It", "supports", "graceful", "restart", "via", "SIGUSR2", "." ]
baa1a54919e3035417f7571dd46005e91afe8abe
https://github.com/koding/kite/blob/baa1a54919e3035417f7571dd46005e91afe8abe/server.go#L18-L38
train
koding/kite
server.go
Close
func (k *Kite) Close() { k.Log.Info("Closing kite...") k.kontrol.Lock() if k.kontrol != nil && k.kontrol.Client != nil { k.kontrol.Close() } k.kontrol.Unlock() if k.listener != nil { k.listener.Close() k.listener = nil } k.mu.Lock() cache := k.verifyCache k.mu.Unlock() if cache != nil { cache.Sto...
go
func (k *Kite) Close() { k.Log.Info("Closing kite...") k.kontrol.Lock() if k.kontrol != nil && k.kontrol.Client != nil { k.kontrol.Close() } k.kontrol.Unlock() if k.listener != nil { k.listener.Close() k.listener = nil } k.mu.Lock() cache := k.verifyCache k.mu.Unlock() if cache != nil { cache.Sto...
[ "func", "(", "k", "*", "Kite", ")", "Close", "(", ")", "{", "k", ".", "Log", ".", "Info", "(", "\"", "\"", ")", "\n\n", "k", ".", "kontrol", ".", "Lock", "(", ")", "\n", "if", "k", ".", "kontrol", "!=", "nil", "&&", "k", ".", "kontrol", "."...
// Close stops the server and the kontrol client instance.
[ "Close", "stops", "the", "server", "and", "the", "kontrol", "client", "instance", "." ]
baa1a54919e3035417f7571dd46005e91afe8abe
https://github.com/koding/kite/blob/baa1a54919e3035417f7571dd46005e91afe8abe/server.go#L41-L62
train
koding/kite
server.go
listenAndServe
func (k *Kite) listenAndServe() error { // create a new one if there doesn't exist l, err := net.Listen("tcp4", k.Addr()) if err != nil { return err } k.Log.Info("New listening: %s", l.Addr()) if k.TLSConfig != nil { if k.TLSConfig.NextProtos == nil { k.TLSConfig.NextProtos = []string{"http/1.1"} } l...
go
func (k *Kite) listenAndServe() error { // create a new one if there doesn't exist l, err := net.Listen("tcp4", k.Addr()) if err != nil { return err } k.Log.Info("New listening: %s", l.Addr()) if k.TLSConfig != nil { if k.TLSConfig.NextProtos == nil { k.TLSConfig.NextProtos = []string{"http/1.1"} } l...
[ "func", "(", "k", "*", "Kite", ")", "listenAndServe", "(", ")", "error", "{", "// create a new one if there doesn't exist", "l", ",", "err", ":=", "net", ".", "Listen", "(", "\"", "\"", ",", "k", ".", "Addr", "(", ")", ")", "\n", "if", "err", "!=", "...
// listenAndServe listens on the TCP network address k.URL.Host and then // calls Serve to handle requests on incoming connectionk.
[ "listenAndServe", "listens", "on", "the", "TCP", "network", "address", "k", ".", "URL", ".", "Host", "and", "then", "calls", "Serve", "to", "handle", "requests", "on", "incoming", "connectionk", "." ]
baa1a54919e3035417f7571dd46005e91afe8abe
https://github.com/koding/kite/blob/baa1a54919e3035417f7571dd46005e91afe8abe/server.go#L70-L95
train
koding/kite
kontrol/onceevery/onceevery.go
Do
func (o *OnceEvery) Do(f func()) { if f == nil { panic("passed function is nil") } o.mu.Lock() now := time.Now() ok := o.last.Add(o.Interval).Before(now) if ok { o.last = now } o.mu.Unlock() if ok { f() } }
go
func (o *OnceEvery) Do(f func()) { if f == nil { panic("passed function is nil") } o.mu.Lock() now := time.Now() ok := o.last.Add(o.Interval).Before(now) if ok { o.last = now } o.mu.Unlock() if ok { f() } }
[ "func", "(", "o", "*", "OnceEvery", ")", "Do", "(", "f", "func", "(", ")", ")", "{", "if", "f", "==", "nil", "{", "panic", "(", "\"", "\"", ")", "\n", "}", "\n\n", "o", ".", "mu", ".", "Lock", "(", ")", "\n", "now", ":=", "time", ".", "No...
// Do calls the function f if and only if Do hits the given periodic interval. // In other words Do can be called multiple times during the interval but it // gets called only once if it hits the interval tick. So if the interval is // 10 seconds, and a total of 100 calls are made during this period, f will // be calle...
[ "Do", "calls", "the", "function", "f", "if", "and", "only", "if", "Do", "hits", "the", "given", "periodic", "interval", ".", "In", "other", "words", "Do", "can", "be", "called", "multiple", "times", "during", "the", "interval", "but", "it", "gets", "call...
baa1a54919e3035417f7571dd46005e91afe8abe
https://github.com/koding/kite/blob/baa1a54919e3035417f7571dd46005e91afe8abe/kontrol/onceevery/onceevery.go#L28-L44
train
koding/kite
systeminfo/systeminfo_darwin.go
sysctlbyname
func sysctlbyname(name string, data interface{}) (err error) { val, err := syscall.Sysctl(name) if err != nil { return err } buf := []byte(val) switch v := data.(type) { case *uint64: *v = *(*uint64)(unsafe.Pointer(&buf[0])) return } bbuf := bytes.NewBuffer([]byte(val)) return binary.Read(bbuf, binary...
go
func sysctlbyname(name string, data interface{}) (err error) { val, err := syscall.Sysctl(name) if err != nil { return err } buf := []byte(val) switch v := data.(type) { case *uint64: *v = *(*uint64)(unsafe.Pointer(&buf[0])) return } bbuf := bytes.NewBuffer([]byte(val)) return binary.Read(bbuf, binary...
[ "func", "sysctlbyname", "(", "name", "string", ",", "data", "interface", "{", "}", ")", "(", "err", "error", ")", "{", "val", ",", "err", ":=", "syscall", ".", "Sysctl", "(", "name", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", ...
// generic Sysctl buffer unmarshalling
[ "generic", "Sysctl", "buffer", "unmarshalling" ]
baa1a54919e3035417f7571dd46005e91afe8abe
https://github.com/koding/kite/blob/baa1a54919e3035417f7571dd46005e91afe8abe/systeminfo/systeminfo_darwin.go#L79-L95
train
koding/kite
kitekey/kitekey.go
KiteHome
func KiteHome() (string, error) { kiteHome := os.Getenv("KITE_HOME") if kiteHome != "" { return kiteHome, nil } usr, err := user.Current() if err != nil { return "", err } return filepath.Join(usr.HomeDir, kiteDirName), nil }
go
func KiteHome() (string, error) { kiteHome := os.Getenv("KITE_HOME") if kiteHome != "" { return kiteHome, nil } usr, err := user.Current() if err != nil { return "", err } return filepath.Join(usr.HomeDir, kiteDirName), nil }
[ "func", "KiteHome", "(", ")", "(", "string", ",", "error", ")", "{", "kiteHome", ":=", "os", ".", "Getenv", "(", "\"", "\"", ")", "\n", "if", "kiteHome", "!=", "\"", "\"", "{", "return", "kiteHome", ",", "nil", "\n", "}", "\n", "usr", ",", "err",...
// KiteHome returns the home path of Kite directory. // The returned value can be overridden by setting KITE_HOME environment variable.
[ "KiteHome", "returns", "the", "home", "path", "of", "Kite", "directory", ".", "The", "returned", "value", "can", "be", "overridden", "by", "setting", "KITE_HOME", "environment", "variable", "." ]
baa1a54919e3035417f7571dd46005e91afe8abe
https://github.com/koding/kite/blob/baa1a54919e3035417f7571dd46005e91afe8abe/kitekey/kitekey.go#L31-L41
train
koding/kite
kitekey/kitekey.go
Read
func Read() (string, error) { keyPath, err := kiteKeyPath() if err != nil { return "", err } data, err := ioutil.ReadFile(keyPath) if err != nil { return "", err } return strings.TrimSpace(string(data)), nil }
go
func Read() (string, error) { keyPath, err := kiteKeyPath() if err != nil { return "", err } data, err := ioutil.ReadFile(keyPath) if err != nil { return "", err } return strings.TrimSpace(string(data)), nil }
[ "func", "Read", "(", ")", "(", "string", ",", "error", ")", "{", "keyPath", ",", "err", ":=", "kiteKeyPath", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "err", "\n", "}", "\n", "data", ",", "err", ":=", "ioutil", "...
// Read the contents of the kite.key file.
[ "Read", "the", "contents", "of", "the", "kite", ".", "key", "file", "." ]
baa1a54919e3035417f7571dd46005e91afe8abe
https://github.com/koding/kite/blob/baa1a54919e3035417f7571dd46005e91afe8abe/kitekey/kitekey.go#L52-L62
train
koding/kite
kitekey/kitekey.go
Write
func Write(kiteKey string) error { keyPath, err := kiteKeyPath() if err != nil { return err } err = os.MkdirAll(filepath.Dir(keyPath), 0700) if err != nil { return err } // Need to remove the previous key first because we can't write over // when previous file's mode is 0400. os.Remove(keyPath) return ...
go
func Write(kiteKey string) error { keyPath, err := kiteKeyPath() if err != nil { return err } err = os.MkdirAll(filepath.Dir(keyPath), 0700) if err != nil { return err } // Need to remove the previous key first because we can't write over // when previous file's mode is 0400. os.Remove(keyPath) return ...
[ "func", "Write", "(", "kiteKey", "string", ")", "error", "{", "keyPath", ",", "err", ":=", "kiteKeyPath", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "err", "=", "os", ".", "MkdirAll", "(", "filepath", ".", "D...
// Write over the kite.key file.
[ "Write", "over", "the", "kite", ".", "key", "file", "." ]
baa1a54919e3035417f7571dd46005e91afe8abe
https://github.com/koding/kite/blob/baa1a54919e3035417f7571dd46005e91afe8abe/kitekey/kitekey.go#L65-L81
train
koding/kite
kitekey/kitekey.go
Parse
func Parse() (*jwt.Token, error) { kiteKey, err := Read() if err != nil { return nil, err } return jwt.ParseWithClaims(kiteKey, &KiteClaims{}, GetKontrolKey) }
go
func Parse() (*jwt.Token, error) { kiteKey, err := Read() if err != nil { return nil, err } return jwt.ParseWithClaims(kiteKey, &KiteClaims{}, GetKontrolKey) }
[ "func", "Parse", "(", ")", "(", "*", "jwt", ".", "Token", ",", "error", ")", "{", "kiteKey", ",", "err", ":=", "Read", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "jwt", ".", "ParseWi...
// Parse the kite.key file and return it as JWT token.
[ "Parse", "the", "kite", ".", "key", "file", "and", "return", "it", "as", "JWT", "token", "." ]
baa1a54919e3035417f7571dd46005e91afe8abe
https://github.com/koding/kite/blob/baa1a54919e3035417f7571dd46005e91afe8abe/kitekey/kitekey.go#L84-L91
train
koding/kite
kitekey/kitekey.go
ParseFile
func ParseFile(file string) (*jwt.Token, error) { kiteKey, err := ioutil.ReadFile(file) if err != nil { return nil, err } return jwt.ParseWithClaims(string(bytes.TrimSpace(kiteKey)), &KiteClaims{}, GetKontrolKey) }
go
func ParseFile(file string) (*jwt.Token, error) { kiteKey, err := ioutil.ReadFile(file) if err != nil { return nil, err } return jwt.ParseWithClaims(string(bytes.TrimSpace(kiteKey)), &KiteClaims{}, GetKontrolKey) }
[ "func", "ParseFile", "(", "file", "string", ")", "(", "*", "jwt", ".", "Token", ",", "error", ")", "{", "kiteKey", ",", "err", ":=", "ioutil", ".", "ReadFile", "(", "file", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\...
// ParseFile reads the given kite key file and parses it as a JWT token.
[ "ParseFile", "reads", "the", "given", "kite", "key", "file", "and", "parses", "it", "as", "a", "JWT", "token", "." ]
baa1a54919e3035417f7571dd46005e91afe8abe
https://github.com/koding/kite/blob/baa1a54919e3035417f7571dd46005e91afe8abe/kitekey/kitekey.go#L94-L101
train
koding/kite
kitekey/kitekey.go
Extract
func (e *Extractor) Extract(token *jwt.Token) (interface{}, error) { e.Token = token if _, ok := token.Method.(*jwt.SigningMethodRSA); !ok { return nil, errors.New("invalid signing method") } claims, ok := token.Claims.(*KiteClaims) if !ok { return nil, fmt.Errorf("no kontrol key found") } e.Claims = clai...
go
func (e *Extractor) Extract(token *jwt.Token) (interface{}, error) { e.Token = token if _, ok := token.Method.(*jwt.SigningMethodRSA); !ok { return nil, errors.New("invalid signing method") } claims, ok := token.Claims.(*KiteClaims) if !ok { return nil, fmt.Errorf("no kontrol key found") } e.Claims = clai...
[ "func", "(", "e", "*", "Extractor", ")", "Extract", "(", "token", "*", "jwt", ".", "Token", ")", "(", "interface", "{", "}", ",", "error", ")", "{", "e", ".", "Token", "=", "token", "\n\n", "if", "_", ",", "ok", ":=", "token", ".", "Method", "....
// Extract is a keyFunc argument for jwt.Parse function.
[ "Extract", "is", "a", "keyFunc", "argument", "for", "jwt", ".", "Parse", "function", "." ]
baa1a54919e3035417f7571dd46005e91afe8abe
https://github.com/koding/kite/blob/baa1a54919e3035417f7571dd46005e91afe8abe/kitekey/kitekey.go#L110-L125
train