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
apache/qpid-proton
go/src/qpid.apache.org/amqp/unmarshal.go
getMap
func getMap(data *C.pn_data_t, v interface{}) { panicUnless(C.pn_data_type(data) == C.PN_MAP, data, v) n := int(C.pn_data_get_map(data)) / 2 mapValue := reflect.ValueOf(v).Elem() mapValue.Set(reflect.MakeMap(mapValue.Type())) // Clear the map data.enter(v) defer data.exit(v) // Allocate re-usable key/val values keyType := mapValue.Type().Key() keyPtr := reflect.New(keyType) valPtr := reflect.New(mapValue.Type().Elem()) for i := 0; i < n; i++ { data.next(v) unmarshal(keyPtr.Interface(), data) if keyType.Kind() == reflect.Interface && !keyPtr.Elem().Elem().Type().Comparable() { doPanicMsg(data, v, fmt.Sprintf("key %#v is not comparable", keyPtr.Elem().Interface())) } data.next(v) unmarshal(valPtr.Interface(), data) mapValue.SetMapIndex(keyPtr.Elem(), valPtr.Elem()) } }
go
func getMap(data *C.pn_data_t, v interface{}) { panicUnless(C.pn_data_type(data) == C.PN_MAP, data, v) n := int(C.pn_data_get_map(data)) / 2 mapValue := reflect.ValueOf(v).Elem() mapValue.Set(reflect.MakeMap(mapValue.Type())) // Clear the map data.enter(v) defer data.exit(v) // Allocate re-usable key/val values keyType := mapValue.Type().Key() keyPtr := reflect.New(keyType) valPtr := reflect.New(mapValue.Type().Elem()) for i := 0; i < n; i++ { data.next(v) unmarshal(keyPtr.Interface(), data) if keyType.Kind() == reflect.Interface && !keyPtr.Elem().Elem().Type().Comparable() { doPanicMsg(data, v, fmt.Sprintf("key %#v is not comparable", keyPtr.Elem().Interface())) } data.next(v) unmarshal(valPtr.Interface(), data) mapValue.SetMapIndex(keyPtr.Elem(), valPtr.Elem()) } }
[ "func", "getMap", "(", "data", "*", "C", ".", "pn_data_t", ",", "v", "interface", "{", "}", ")", "{", "panicUnless", "(", "C", ".", "pn_data_type", "(", "data", ")", "==", "C", ".", "PN_MAP", ",", "data", ",", "v", ")", "\n", "n", ":=", "int", "(", "C", ".", "pn_data_get_map", "(", "data", ")", ")", "/", "2", "\n", "mapValue", ":=", "reflect", ".", "ValueOf", "(", "v", ")", ".", "Elem", "(", ")", "\n", "mapValue", ".", "Set", "(", "reflect", ".", "MakeMap", "(", "mapValue", ".", "Type", "(", ")", ")", ")", "// Clear the map", "\n", "data", ".", "enter", "(", "v", ")", "\n", "defer", "data", ".", "exit", "(", "v", ")", "\n", "// Allocate re-usable key/val values", "keyType", ":=", "mapValue", ".", "Type", "(", ")", ".", "Key", "(", ")", "\n", "keyPtr", ":=", "reflect", ".", "New", "(", "keyType", ")", "\n", "valPtr", ":=", "reflect", ".", "New", "(", "mapValue", ".", "Type", "(", ")", ".", "Elem", "(", ")", ")", "\n", "for", "i", ":=", "0", ";", "i", "<", "n", ";", "i", "++", "{", "data", ".", "next", "(", "v", ")", "\n", "unmarshal", "(", "keyPtr", ".", "Interface", "(", ")", ",", "data", ")", "\n", "if", "keyType", ".", "Kind", "(", ")", "==", "reflect", ".", "Interface", "&&", "!", "keyPtr", ".", "Elem", "(", ")", ".", "Elem", "(", ")", ".", "Type", "(", ")", ".", "Comparable", "(", ")", "{", "doPanicMsg", "(", "data", ",", "v", ",", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "keyPtr", ".", "Elem", "(", ")", ".", "Interface", "(", ")", ")", ")", "\n", "}", "\n", "data", ".", "next", "(", "v", ")", "\n", "unmarshal", "(", "valPtr", ".", "Interface", "(", ")", ",", "data", ")", "\n", "mapValue", ".", "SetMapIndex", "(", "keyPtr", ".", "Elem", "(", ")", ",", "valPtr", ".", "Elem", "(", ")", ")", "\n", "}", "\n", "}" ]
// get into map pointed at by v
[ "get", "into", "map", "pointed", "at", "by", "v" ]
713c3aa0a2423b34ebffb8a2b2a43f0271966e4b
https://github.com/apache/qpid-proton/blob/713c3aa0a2423b34ebffb8a2b2a43f0271966e4b/go/src/qpid.apache.org/amqp/unmarshal.go#L652-L673
train
apache/qpid-proton
go/src/qpid.apache.org/amqp/unmarshal.go
decode
func decode(data *C.pn_data_t, bytes []byte) (int, error) { n := C.pn_data_decode(data, cPtr(bytes), cLen(bytes)) if n == C.PN_UNDERFLOW { C.pn_error_clear(C.pn_data_error(data)) return 0, EndOfData } else if n <= 0 { return 0, &UnmarshalError{s: fmt.Sprintf("unmarshal %v", PnErrorCode(n))} } return int(n), nil }
go
func decode(data *C.pn_data_t, bytes []byte) (int, error) { n := C.pn_data_decode(data, cPtr(bytes), cLen(bytes)) if n == C.PN_UNDERFLOW { C.pn_error_clear(C.pn_data_error(data)) return 0, EndOfData } else if n <= 0 { return 0, &UnmarshalError{s: fmt.Sprintf("unmarshal %v", PnErrorCode(n))} } return int(n), nil }
[ "func", "decode", "(", "data", "*", "C", ".", "pn_data_t", ",", "bytes", "[", "]", "byte", ")", "(", "int", ",", "error", ")", "{", "n", ":=", "C", ".", "pn_data_decode", "(", "data", ",", "cPtr", "(", "bytes", ")", ",", "cLen", "(", "bytes", ")", ")", "\n", "if", "n", "==", "C", ".", "PN_UNDERFLOW", "{", "C", ".", "pn_error_clear", "(", "C", ".", "pn_data_error", "(", "data", ")", ")", "\n", "return", "0", ",", "EndOfData", "\n", "}", "else", "if", "n", "<=", "0", "{", "return", "0", ",", "&", "UnmarshalError", "{", "s", ":", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "PnErrorCode", "(", "n", ")", ")", "}", "\n", "}", "\n", "return", "int", "(", "n", ")", ",", "nil", "\n", "}" ]
// decode from bytes. // Return bytes decoded or 0 if we could not decode a complete object. //
[ "decode", "from", "bytes", ".", "Return", "bytes", "decoded", "or", "0", "if", "we", "could", "not", "decode", "a", "complete", "object", "." ]
713c3aa0a2423b34ebffb8a2b2a43f0271966e4b
https://github.com/apache/qpid-proton/blob/713c3aa0a2423b34ebffb8a2b2a43f0271966e4b/go/src/qpid.apache.org/amqp/unmarshal.go#L716-L725
train
apache/qpid-proton
go/src/qpid.apache.org/electron/sender.go
String
func (s SentStatus) String() string { switch s { case Unsent: return "unsent" case Unacknowledged: return "unacknowledged" case Accepted: return "accepted" case Rejected: return "rejected" case Released: return "released" case Unknown: return "unknown" default: return fmt.Sprintf("invalid(%d)", s) } }
go
func (s SentStatus) String() string { switch s { case Unsent: return "unsent" case Unacknowledged: return "unacknowledged" case Accepted: return "accepted" case Rejected: return "rejected" case Released: return "released" case Unknown: return "unknown" default: return fmt.Sprintf("invalid(%d)", s) } }
[ "func", "(", "s", "SentStatus", ")", "String", "(", ")", "string", "{", "switch", "s", "{", "case", "Unsent", ":", "return", "\"", "\"", "\n", "case", "Unacknowledged", ":", "return", "\"", "\"", "\n", "case", "Accepted", ":", "return", "\"", "\"", "\n", "case", "Rejected", ":", "return", "\"", "\"", "\n", "case", "Released", ":", "return", "\"", "\"", "\n", "case", "Unknown", ":", "return", "\"", "\"", "\n", "default", ":", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "s", ")", "\n", "}", "\n", "}" ]
// String human readable name for SentStatus.
[ "String", "human", "readable", "name", "for", "SentStatus", "." ]
713c3aa0a2423b34ebffb8a2b2a43f0271966e4b
https://github.com/apache/qpid-proton/blob/713c3aa0a2423b34ebffb8a2b2a43f0271966e4b/go/src/qpid.apache.org/electron/sender.go#L119-L136
train
apache/qpid-proton
go/src/qpid.apache.org/electron/sender.go
sentStatus
func sentStatus(d uint64) SentStatus { switch d { case proton.Accepted: return Accepted case proton.Rejected: return Rejected case proton.Released, proton.Modified: return Released default: return Unknown } }
go
func sentStatus(d uint64) SentStatus { switch d { case proton.Accepted: return Accepted case proton.Rejected: return Rejected case proton.Released, proton.Modified: return Released default: return Unknown } }
[ "func", "sentStatus", "(", "d", "uint64", ")", "SentStatus", "{", "switch", "d", "{", "case", "proton", ".", "Accepted", ":", "return", "Accepted", "\n", "case", "proton", ".", "Rejected", ":", "return", "Rejected", "\n", "case", "proton", ".", "Released", ",", "proton", ".", "Modified", ":", "return", "Released", "\n", "default", ":", "return", "Unknown", "\n", "}", "\n", "}" ]
// Convert proton delivery state code to SentStatus value
[ "Convert", "proton", "delivery", "state", "code", "to", "SentStatus", "value" ]
713c3aa0a2423b34ebffb8a2b2a43f0271966e4b
https://github.com/apache/qpid-proton/blob/713c3aa0a2423b34ebffb8a2b2a43f0271966e4b/go/src/qpid.apache.org/electron/sender.go#L139-L150
train
apache/qpid-proton
go/src/qpid.apache.org/electron/sender.go
send
func (s *sender) send(sm *sendable) { if err := s.Error(); err != nil { sm.unsent(err) return } bytes, err := s.session.connection.mc.Encode(sm.m, nil) close(sm.sent) // Safe to re-use sm.m now if err != nil { sm.unsent(err) return } d, err := s.pLink.SendMessageBytes(bytes) if err != nil { sm.unsent(err) return } if s.SndSettle() == SndSettled || (s.SndSettle() == SndMixed && sm.ack == nil) { d.Settle() // Pre-settled Outcome{Accepted, nil, sm.v}.send(sm.ack) // Assume accepted } else { // Register with handler to receive the remote outcome s.handler().sent[d] = sm } }
go
func (s *sender) send(sm *sendable) { if err := s.Error(); err != nil { sm.unsent(err) return } bytes, err := s.session.connection.mc.Encode(sm.m, nil) close(sm.sent) // Safe to re-use sm.m now if err != nil { sm.unsent(err) return } d, err := s.pLink.SendMessageBytes(bytes) if err != nil { sm.unsent(err) return } if s.SndSettle() == SndSettled || (s.SndSettle() == SndMixed && sm.ack == nil) { d.Settle() // Pre-settled Outcome{Accepted, nil, sm.v}.send(sm.ack) // Assume accepted } else { // Register with handler to receive the remote outcome s.handler().sent[d] = sm } }
[ "func", "(", "s", "*", "sender", ")", "send", "(", "sm", "*", "sendable", ")", "{", "if", "err", ":=", "s", ".", "Error", "(", ")", ";", "err", "!=", "nil", "{", "sm", ".", "unsent", "(", "err", ")", "\n", "return", "\n", "}", "\n", "bytes", ",", "err", ":=", "s", ".", "session", ".", "connection", ".", "mc", ".", "Encode", "(", "sm", ".", "m", ",", "nil", ")", "\n", "close", "(", "sm", ".", "sent", ")", "// Safe to re-use sm.m now", "\n", "if", "err", "!=", "nil", "{", "sm", ".", "unsent", "(", "err", ")", "\n", "return", "\n", "}", "\n", "d", ",", "err", ":=", "s", ".", "pLink", ".", "SendMessageBytes", "(", "bytes", ")", "\n", "if", "err", "!=", "nil", "{", "sm", ".", "unsent", "(", "err", ")", "\n", "return", "\n", "}", "\n", "if", "s", ".", "SndSettle", "(", ")", "==", "SndSettled", "||", "(", "s", ".", "SndSettle", "(", ")", "==", "SndMixed", "&&", "sm", ".", "ack", "==", "nil", ")", "{", "d", ".", "Settle", "(", ")", "// Pre-settled", "\n", "Outcome", "{", "Accepted", ",", "nil", ",", "sm", ".", "v", "}", ".", "send", "(", "sm", ".", "ack", ")", "// Assume accepted", "\n", "}", "else", "{", "// Register with handler to receive the remote outcome", "s", ".", "handler", "(", ")", ".", "sent", "[", "d", "]", "=", "sm", "\n", "}", "\n", "}" ]
// Called in handler goroutine with credit > 0
[ "Called", "in", "handler", "goroutine", "with", "credit", ">", "0" ]
713c3aa0a2423b34ebffb8a2b2a43f0271966e4b
https://github.com/apache/qpid-proton/blob/713c3aa0a2423b34ebffb8a2b2a43f0271966e4b/go/src/qpid.apache.org/electron/sender.go#L192-L215
train
apache/qpid-proton
go/src/qpid.apache.org/electron/sender.go
Accept
func (in *IncomingSender) Accept() Endpoint { return in.accept(func() Endpoint { return newSender(in.linkSettings) }) }
go
func (in *IncomingSender) Accept() Endpoint { return in.accept(func() Endpoint { return newSender(in.linkSettings) }) }
[ "func", "(", "in", "*", "IncomingSender", ")", "Accept", "(", ")", "Endpoint", "{", "return", "in", ".", "accept", "(", "func", "(", ")", "Endpoint", "{", "return", "newSender", "(", "in", ".", "linkSettings", ")", "}", ")", "\n", "}" ]
// Accept accepts an incoming sender endpoint
[ "Accept", "accepts", "an", "incoming", "sender", "endpoint" ]
713c3aa0a2423b34ebffb8a2b2a43f0271966e4b
https://github.com/apache/qpid-proton/blob/713c3aa0a2423b34ebffb8a2b2a43f0271966e4b/go/src/qpid.apache.org/electron/sender.go#L305-L307
train
apache/qpid-proton
go/src/qpid.apache.org/electron/sender.go
valid
func (s *sender) valid() bool { s2, ok := s.handler().links[s.pLink].(*sender) return ok && s2 == s }
go
func (s *sender) valid() bool { s2, ok := s.handler().links[s.pLink].(*sender) return ok && s2 == s }
[ "func", "(", "s", "*", "sender", ")", "valid", "(", ")", "bool", "{", "s2", ",", "ok", ":=", "s", ".", "handler", "(", ")", ".", "links", "[", "s", ".", "pLink", "]", ".", "(", "*", "sender", ")", "\n", "return", "ok", "&&", "s2", "==", "s", "\n", "}" ]
// Call in injected functions to check if the sender is valid.
[ "Call", "in", "injected", "functions", "to", "check", "if", "the", "sender", "is", "valid", "." ]
713c3aa0a2423b34ebffb8a2b2a43f0271966e4b
https://github.com/apache/qpid-proton/blob/713c3aa0a2423b34ebffb8a2b2a43f0271966e4b/go/src/qpid.apache.org/electron/sender.go#L310-L313
train
jmhodges/levigo
db.go
RepairDatabase
func RepairDatabase(dbname string, o *Options) error { var errStr *C.char ldbname := C.CString(dbname) defer C.free(unsafe.Pointer(ldbname)) C.leveldb_repair_db(o.Opt, ldbname, &errStr) if errStr != nil { gs := C.GoString(errStr) C.leveldb_free(unsafe.Pointer(errStr)) return DatabaseError(gs) } return nil }
go
func RepairDatabase(dbname string, o *Options) error { var errStr *C.char ldbname := C.CString(dbname) defer C.free(unsafe.Pointer(ldbname)) C.leveldb_repair_db(o.Opt, ldbname, &errStr) if errStr != nil { gs := C.GoString(errStr) C.leveldb_free(unsafe.Pointer(errStr)) return DatabaseError(gs) } return nil }
[ "func", "RepairDatabase", "(", "dbname", "string", ",", "o", "*", "Options", ")", "error", "{", "var", "errStr", "*", "C", ".", "char", "\n", "ldbname", ":=", "C", ".", "CString", "(", "dbname", ")", "\n", "defer", "C", ".", "free", "(", "unsafe", ".", "Pointer", "(", "ldbname", ")", ")", "\n\n", "C", ".", "leveldb_repair_db", "(", "o", ".", "Opt", ",", "ldbname", ",", "&", "errStr", ")", "\n", "if", "errStr", "!=", "nil", "{", "gs", ":=", "C", ".", "GoString", "(", "errStr", ")", "\n", "C", ".", "leveldb_free", "(", "unsafe", ".", "Pointer", "(", "errStr", ")", ")", "\n", "return", "DatabaseError", "(", "gs", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// RepairDatabase attempts to repair a database. // // If the database is unrepairable, an error is returned.
[ "RepairDatabase", "attempts", "to", "repair", "a", "database", ".", "If", "the", "database", "is", "unrepairable", "an", "error", "is", "returned", "." ]
853d788c5c416eaaee5b044570784a96c7a26975
https://github.com/jmhodges/levigo/blob/853d788c5c416eaaee5b044570784a96c7a26975/db.go#L128-L140
train
jmhodges/levigo
db.go
Delete
func (db *DB) Delete(wo *WriteOptions, key []byte) error { if db.closed { panic(ErrDBClosed) } var errStr *C.char var k *C.char if len(key) != 0 { k = (*C.char)(unsafe.Pointer(&key[0])) } C.leveldb_delete( db.Ldb, wo.Opt, k, C.size_t(len(key)), &errStr) if errStr != nil { gs := C.GoString(errStr) C.leveldb_free(unsafe.Pointer(errStr)) return DatabaseError(gs) } return nil }
go
func (db *DB) Delete(wo *WriteOptions, key []byte) error { if db.closed { panic(ErrDBClosed) } var errStr *C.char var k *C.char if len(key) != 0 { k = (*C.char)(unsafe.Pointer(&key[0])) } C.leveldb_delete( db.Ldb, wo.Opt, k, C.size_t(len(key)), &errStr) if errStr != nil { gs := C.GoString(errStr) C.leveldb_free(unsafe.Pointer(errStr)) return DatabaseError(gs) } return nil }
[ "func", "(", "db", "*", "DB", ")", "Delete", "(", "wo", "*", "WriteOptions", ",", "key", "[", "]", "byte", ")", "error", "{", "if", "db", ".", "closed", "{", "panic", "(", "ErrDBClosed", ")", "\n", "}", "\n\n", "var", "errStr", "*", "C", ".", "char", "\n", "var", "k", "*", "C", ".", "char", "\n", "if", "len", "(", "key", ")", "!=", "0", "{", "k", "=", "(", "*", "C", ".", "char", ")", "(", "unsafe", ".", "Pointer", "(", "&", "key", "[", "0", "]", ")", ")", "\n", "}", "\n\n", "C", ".", "leveldb_delete", "(", "db", ".", "Ldb", ",", "wo", ".", "Opt", ",", "k", ",", "C", ".", "size_t", "(", "len", "(", "key", ")", ")", ",", "&", "errStr", ")", "\n\n", "if", "errStr", "!=", "nil", "{", "gs", ":=", "C", ".", "GoString", "(", "errStr", ")", "\n", "C", ".", "leveldb_free", "(", "unsafe", ".", "Pointer", "(", "errStr", ")", ")", "\n", "return", "DatabaseError", "(", "gs", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Delete removes the data associated with the key from the database. // // The key byte slice may be reused safely. Delete takes a copy of // them before returning. The WriteOptions passed in can be reused by // multiple calls to this and if the WriteOptions is left unchanged.
[ "Delete", "removes", "the", "data", "associated", "with", "the", "key", "from", "the", "database", ".", "The", "key", "byte", "slice", "may", "be", "reused", "safely", ".", "Delete", "takes", "a", "copy", "of", "them", "before", "returning", ".", "The", "WriteOptions", "passed", "in", "can", "be", "reused", "by", "multiple", "calls", "to", "this", "and", "if", "the", "WriteOptions", "is", "left", "unchanged", "." ]
853d788c5c416eaaee5b044570784a96c7a26975
https://github.com/jmhodges/levigo/blob/853d788c5c416eaaee5b044570784a96c7a26975/db.go#L222-L242
train
jmhodges/levigo
db.go
Write
func (db *DB) Write(wo *WriteOptions, w *WriteBatch) error { if db.closed { panic(ErrDBClosed) } var errStr *C.char C.leveldb_write(db.Ldb, wo.Opt, w.wbatch, &errStr) if errStr != nil { gs := C.GoString(errStr) C.leveldb_free(unsafe.Pointer(errStr)) return DatabaseError(gs) } return nil }
go
func (db *DB) Write(wo *WriteOptions, w *WriteBatch) error { if db.closed { panic(ErrDBClosed) } var errStr *C.char C.leveldb_write(db.Ldb, wo.Opt, w.wbatch, &errStr) if errStr != nil { gs := C.GoString(errStr) C.leveldb_free(unsafe.Pointer(errStr)) return DatabaseError(gs) } return nil }
[ "func", "(", "db", "*", "DB", ")", "Write", "(", "wo", "*", "WriteOptions", ",", "w", "*", "WriteBatch", ")", "error", "{", "if", "db", ".", "closed", "{", "panic", "(", "ErrDBClosed", ")", "\n", "}", "\n\n", "var", "errStr", "*", "C", ".", "char", "\n", "C", ".", "leveldb_write", "(", "db", ".", "Ldb", ",", "wo", ".", "Opt", ",", "w", ".", "wbatch", ",", "&", "errStr", ")", "\n", "if", "errStr", "!=", "nil", "{", "gs", ":=", "C", ".", "GoString", "(", "errStr", ")", "\n", "C", ".", "leveldb_free", "(", "unsafe", ".", "Pointer", "(", "errStr", ")", ")", "\n", "return", "DatabaseError", "(", "gs", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Write atomically writes a WriteBatch to disk. The WriteOptions // passed in can be reused by multiple calls to this and other methods.
[ "Write", "atomically", "writes", "a", "WriteBatch", "to", "disk", ".", "The", "WriteOptions", "passed", "in", "can", "be", "reused", "by", "multiple", "calls", "to", "this", "and", "other", "methods", "." ]
853d788c5c416eaaee5b044570784a96c7a26975
https://github.com/jmhodges/levigo/blob/853d788c5c416eaaee5b044570784a96c7a26975/db.go#L246-L259
train
jmhodges/levigo
db.go
PropertyValue
func (db *DB) PropertyValue(propName string) string { if db.closed { panic(ErrDBClosed) } cname := C.CString(propName) value := C.GoString(C.leveldb_property_value(db.Ldb, cname)) C.free(unsafe.Pointer(cname)) return value }
go
func (db *DB) PropertyValue(propName string) string { if db.closed { panic(ErrDBClosed) } cname := C.CString(propName) value := C.GoString(C.leveldb_property_value(db.Ldb, cname)) C.free(unsafe.Pointer(cname)) return value }
[ "func", "(", "db", "*", "DB", ")", "PropertyValue", "(", "propName", "string", ")", "string", "{", "if", "db", ".", "closed", "{", "panic", "(", "ErrDBClosed", ")", "\n", "}", "\n\n", "cname", ":=", "C", ".", "CString", "(", "propName", ")", "\n", "value", ":=", "C", ".", "GoString", "(", "C", ".", "leveldb_property_value", "(", "db", ".", "Ldb", ",", "cname", ")", ")", "\n", "C", ".", "free", "(", "unsafe", ".", "Pointer", "(", "cname", ")", ")", "\n", "return", "value", "\n", "}" ]
// PropertyValue returns the value of a database property. // // Examples of properties include "leveldb.stats", "leveldb.sstables", // and "leveldb.num-files-at-level0".
[ "PropertyValue", "returns", "the", "value", "of", "a", "database", "property", ".", "Examples", "of", "properties", "include", "leveldb", ".", "stats", "leveldb", ".", "sstables", "and", "leveldb", ".", "num", "-", "files", "-", "at", "-", "level0", "." ]
853d788c5c416eaaee5b044570784a96c7a26975
https://github.com/jmhodges/levigo/blob/853d788c5c416eaaee5b044570784a96c7a26975/db.go#L320-L329
train
jmhodges/levigo
db.go
NewSnapshot
func (db *DB) NewSnapshot() *Snapshot { if db.closed { panic(ErrDBClosed) } return &Snapshot{C.leveldb_create_snapshot(db.Ldb)} }
go
func (db *DB) NewSnapshot() *Snapshot { if db.closed { panic(ErrDBClosed) } return &Snapshot{C.leveldb_create_snapshot(db.Ldb)} }
[ "func", "(", "db", "*", "DB", ")", "NewSnapshot", "(", ")", "*", "Snapshot", "{", "if", "db", ".", "closed", "{", "panic", "(", "ErrDBClosed", ")", "\n", "}", "\n\n", "return", "&", "Snapshot", "{", "C", ".", "leveldb_create_snapshot", "(", "db", ".", "Ldb", ")", "}", "\n", "}" ]
// NewSnapshot creates a new snapshot of the database. // // The Snapshot, when used in a ReadOptions, provides a consistent // view of state of the database at the the snapshot was created. // // To prevent memory leaks and resource strain in the database, the snapshot // returned must be released with DB.ReleaseSnapshot method on the DB that // created it. // // See the LevelDB documentation for details.
[ "NewSnapshot", "creates", "a", "new", "snapshot", "of", "the", "database", ".", "The", "Snapshot", "when", "used", "in", "a", "ReadOptions", "provides", "a", "consistent", "view", "of", "state", "of", "the", "database", "at", "the", "the", "snapshot", "was", "created", ".", "To", "prevent", "memory", "leaks", "and", "resource", "strain", "in", "the", "database", "the", "snapshot", "returned", "must", "be", "released", "with", "DB", ".", "ReleaseSnapshot", "method", "on", "the", "DB", "that", "created", "it", ".", "See", "the", "LevelDB", "documentation", "for", "details", "." ]
853d788c5c416eaaee5b044570784a96c7a26975
https://github.com/jmhodges/levigo/blob/853d788c5c416eaaee5b044570784a96c7a26975/db.go#L341-L347
train
jmhodges/levigo
db.go
ReleaseSnapshot
func (db *DB) ReleaseSnapshot(snap *Snapshot) { if db.closed { panic(ErrDBClosed) } C.leveldb_release_snapshot(db.Ldb, snap.snap) }
go
func (db *DB) ReleaseSnapshot(snap *Snapshot) { if db.closed { panic(ErrDBClosed) } C.leveldb_release_snapshot(db.Ldb, snap.snap) }
[ "func", "(", "db", "*", "DB", ")", "ReleaseSnapshot", "(", "snap", "*", "Snapshot", ")", "{", "if", "db", ".", "closed", "{", "panic", "(", "ErrDBClosed", ")", "\n", "}", "\n\n", "C", ".", "leveldb_release_snapshot", "(", "db", ".", "Ldb", ",", "snap", ".", "snap", ")", "\n", "}" ]
// ReleaseSnapshot removes the snapshot from the database's list of snapshots, // and deallocates it.
[ "ReleaseSnapshot", "removes", "the", "snapshot", "from", "the", "database", "s", "list", "of", "snapshots", "and", "deallocates", "it", "." ]
853d788c5c416eaaee5b044570784a96c7a26975
https://github.com/jmhodges/levigo/blob/853d788c5c416eaaee5b044570784a96c7a26975/db.go#L351-L357
train
jmhodges/levigo
iterator.go
Seek
func (it *Iterator) Seek(key []byte) { C.leveldb_iter_seek(it.Iter, (*C.char)(unsafe.Pointer(&key[0])), C.size_t(len(key))) }
go
func (it *Iterator) Seek(key []byte) { C.leveldb_iter_seek(it.Iter, (*C.char)(unsafe.Pointer(&key[0])), C.size_t(len(key))) }
[ "func", "(", "it", "*", "Iterator", ")", "Seek", "(", "key", "[", "]", "byte", ")", "{", "C", ".", "leveldb_iter_seek", "(", "it", ".", "Iter", ",", "(", "*", "C", ".", "char", ")", "(", "unsafe", ".", "Pointer", "(", "&", "key", "[", "0", "]", ")", ")", ",", "C", ".", "size_t", "(", "len", "(", "key", ")", ")", ")", "\n", "}" ]
// Seek moves the iterator the position of the key given or, if the key // doesn't exist, the next key that does exist in the database. If the key // doesn't exist, and there is no next key, the Iterator becomes invalid. // // This method is safe to call when Valid returns false.
[ "Seek", "moves", "the", "iterator", "the", "position", "of", "the", "key", "given", "or", "if", "the", "key", "doesn", "t", "exist", "the", "next", "key", "that", "does", "exist", "in", "the", "database", ".", "If", "the", "key", "doesn", "t", "exist", "and", "there", "is", "no", "next", "key", "the", "Iterator", "becomes", "invalid", ".", "This", "method", "is", "safe", "to", "call", "when", "Valid", "returns", "false", "." ]
853d788c5c416eaaee5b044570784a96c7a26975
https://github.com/jmhodges/levigo/blob/853d788c5c416eaaee5b044570784a96c7a26975/iterator.go#L126-L128
train
jmhodges/levigo
iterator.go
GetError
func (it *Iterator) GetError() error { var errStr *C.char C.leveldb_iter_get_error(it.Iter, &errStr) if errStr != nil { gs := C.GoString(errStr) C.leveldb_free(unsafe.Pointer(errStr)) return IteratorError(gs) } return nil }
go
func (it *Iterator) GetError() error { var errStr *C.char C.leveldb_iter_get_error(it.Iter, &errStr) if errStr != nil { gs := C.GoString(errStr) C.leveldb_free(unsafe.Pointer(errStr)) return IteratorError(gs) } return nil }
[ "func", "(", "it", "*", "Iterator", ")", "GetError", "(", ")", "error", "{", "var", "errStr", "*", "C", ".", "char", "\n", "C", ".", "leveldb_iter_get_error", "(", "it", ".", "Iter", ",", "&", "errStr", ")", "\n", "if", "errStr", "!=", "nil", "{", "gs", ":=", "C", ".", "GoString", "(", "errStr", ")", "\n", "C", ".", "leveldb_free", "(", "unsafe", ".", "Pointer", "(", "errStr", ")", ")", "\n", "return", "IteratorError", "(", "gs", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// GetError returns an IteratorError from LevelDB if it had one during // iteration. // // This method is safe to call when Valid returns false.
[ "GetError", "returns", "an", "IteratorError", "from", "LevelDB", "if", "it", "had", "one", "during", "iteration", ".", "This", "method", "is", "safe", "to", "call", "when", "Valid", "returns", "false", "." ]
853d788c5c416eaaee5b044570784a96c7a26975
https://github.com/jmhodges/levigo/blob/853d788c5c416eaaee5b044570784a96c7a26975/iterator.go#L134-L143
train
jmhodges/levigo
iterator.go
Close
func (it *Iterator) Close() { C.leveldb_iter_destroy(it.Iter) it.Iter = nil }
go
func (it *Iterator) Close() { C.leveldb_iter_destroy(it.Iter) it.Iter = nil }
[ "func", "(", "it", "*", "Iterator", ")", "Close", "(", ")", "{", "C", ".", "leveldb_iter_destroy", "(", "it", ".", "Iter", ")", "\n", "it", ".", "Iter", "=", "nil", "\n", "}" ]
// Close deallocates the given Iterator, freeing the underlying C struct.
[ "Close", "deallocates", "the", "given", "Iterator", "freeing", "the", "underlying", "C", "struct", "." ]
853d788c5c416eaaee5b044570784a96c7a26975
https://github.com/jmhodges/levigo/blob/853d788c5c416eaaee5b044570784a96c7a26975/iterator.go#L146-L149
train
jmhodges/levigo
options.go
SetEnv
func (o *Options) SetEnv(env *Env) { C.leveldb_options_set_env(o.Opt, env.Env) }
go
func (o *Options) SetEnv(env *Env) { C.leveldb_options_set_env(o.Opt, env.Env) }
[ "func", "(", "o", "*", "Options", ")", "SetEnv", "(", "env", "*", "Env", ")", "{", "C", ".", "leveldb_options_set_env", "(", "o", ".", "Opt", ",", "env", ".", "Env", ")", "\n", "}" ]
// SetEnv sets the Env object for the new database handle.
[ "SetEnv", "sets", "the", "Env", "object", "for", "the", "new", "database", "handle", "." ]
853d788c5c416eaaee5b044570784a96c7a26975
https://github.com/jmhodges/levigo/blob/853d788c5c416eaaee5b044570784a96c7a26975/options.go#L96-L98
train
NaySoftware/go-fcm
fcm.go
NewFcmClient
func NewFcmClient(apiKey string) *FcmClient { fcmc := new(FcmClient) fcmc.ApiKey = apiKey return fcmc }
go
func NewFcmClient(apiKey string) *FcmClient { fcmc := new(FcmClient) fcmc.ApiKey = apiKey return fcmc }
[ "func", "NewFcmClient", "(", "apiKey", "string", ")", "*", "FcmClient", "{", "fcmc", ":=", "new", "(", "FcmClient", ")", "\n", "fcmc", ".", "ApiKey", "=", "apiKey", "\n\n", "return", "fcmc", "\n", "}" ]
// NewFcmClient init and create fcm client
[ "NewFcmClient", "init", "and", "create", "fcm", "client" ]
28fff9381d17f35619309c7a5ada41d26030d976
https://github.com/NaySoftware/go-fcm/blob/28fff9381d17f35619309c7a5ada41d26030d976/fcm.go#L93-L98
train
NaySoftware/go-fcm
fcm.go
SetMsgData
func (this *FcmClient) SetMsgData(body interface{}) *FcmClient { this.Message.Data = body return this }
go
func (this *FcmClient) SetMsgData(body interface{}) *FcmClient { this.Message.Data = body return this }
[ "func", "(", "this", "*", "FcmClient", ")", "SetMsgData", "(", "body", "interface", "{", "}", ")", "*", "FcmClient", "{", "this", ".", "Message", ".", "Data", "=", "body", "\n\n", "return", "this", "\n\n", "}" ]
// SetMsgData sets data payload
[ "SetMsgData", "sets", "data", "payload" ]
28fff9381d17f35619309c7a5ada41d26030d976
https://github.com/NaySoftware/go-fcm/blob/28fff9381d17f35619309c7a5ada41d26030d976/fcm.go#L117-L123
train
NaySoftware/go-fcm
fcm.go
NewFcmRegIdsMsg
func (this *FcmClient) NewFcmRegIdsMsg(list []string, body interface{}) *FcmClient { this.newDevicesList(list) this.Message.Data = body return this }
go
func (this *FcmClient) NewFcmRegIdsMsg(list []string, body interface{}) *FcmClient { this.newDevicesList(list) this.Message.Data = body return this }
[ "func", "(", "this", "*", "FcmClient", ")", "NewFcmRegIdsMsg", "(", "list", "[", "]", "string", ",", "body", "interface", "{", "}", ")", "*", "FcmClient", "{", "this", ".", "newDevicesList", "(", "list", ")", "\n", "this", ".", "Message", ".", "Data", "=", "body", "\n\n", "return", "this", "\n\n", "}" ]
// NewFcmRegIdsMsg gets a list of devices with data payload
[ "NewFcmRegIdsMsg", "gets", "a", "list", "of", "devices", "with", "data", "payload" ]
28fff9381d17f35619309c7a5ada41d26030d976
https://github.com/NaySoftware/go-fcm/blob/28fff9381d17f35619309c7a5ada41d26030d976/fcm.go#L126-L132
train
NaySoftware/go-fcm
fcm.go
newDevicesList
func (this *FcmClient) newDevicesList(list []string) *FcmClient { this.Message.RegistrationIds = make([]string, len(list)) copy(this.Message.RegistrationIds, list) return this }
go
func (this *FcmClient) newDevicesList(list []string) *FcmClient { this.Message.RegistrationIds = make([]string, len(list)) copy(this.Message.RegistrationIds, list) return this }
[ "func", "(", "this", "*", "FcmClient", ")", "newDevicesList", "(", "list", "[", "]", "string", ")", "*", "FcmClient", "{", "this", ".", "Message", ".", "RegistrationIds", "=", "make", "(", "[", "]", "string", ",", "len", "(", "list", ")", ")", "\n", "copy", "(", "this", ".", "Message", ".", "RegistrationIds", ",", "list", ")", "\n\n", "return", "this", "\n\n", "}" ]
// newDevicesList init the devices list
[ "newDevicesList", "init", "the", "devices", "list" ]
28fff9381d17f35619309c7a5ada41d26030d976
https://github.com/NaySoftware/go-fcm/blob/28fff9381d17f35619309c7a5ada41d26030d976/fcm.go#L135-L141
train
NaySoftware/go-fcm
fcm.go
sendOnce
func (this *FcmClient) sendOnce() (*FcmResponseStatus, error) { fcmRespStatus := new(FcmResponseStatus) jsonByte, err := this.Message.toJsonByte() if err != nil { return fcmRespStatus, err } request, err := http.NewRequest("POST", fcmServerUrl, bytes.NewBuffer(jsonByte)) request.Header.Set("Authorization", this.apiKeyHeader()) request.Header.Set("Content-Type", "application/json") client := &http.Client{} response, err := client.Do(request) if err != nil { return fcmRespStatus, err } defer response.Body.Close() body, err := ioutil.ReadAll(response.Body) if err != nil { return fcmRespStatus, err } fcmRespStatus.StatusCode = response.StatusCode fcmRespStatus.RetryAfter = response.Header.Get(retry_after_header) if response.StatusCode != 200 { return fcmRespStatus, nil } err = fcmRespStatus.parseStatusBody(body) if err != nil { return fcmRespStatus, err } fcmRespStatus.Ok = true return fcmRespStatus, nil }
go
func (this *FcmClient) sendOnce() (*FcmResponseStatus, error) { fcmRespStatus := new(FcmResponseStatus) jsonByte, err := this.Message.toJsonByte() if err != nil { return fcmRespStatus, err } request, err := http.NewRequest("POST", fcmServerUrl, bytes.NewBuffer(jsonByte)) request.Header.Set("Authorization", this.apiKeyHeader()) request.Header.Set("Content-Type", "application/json") client := &http.Client{} response, err := client.Do(request) if err != nil { return fcmRespStatus, err } defer response.Body.Close() body, err := ioutil.ReadAll(response.Body) if err != nil { return fcmRespStatus, err } fcmRespStatus.StatusCode = response.StatusCode fcmRespStatus.RetryAfter = response.Header.Get(retry_after_header) if response.StatusCode != 200 { return fcmRespStatus, nil } err = fcmRespStatus.parseStatusBody(body) if err != nil { return fcmRespStatus, err } fcmRespStatus.Ok = true return fcmRespStatus, nil }
[ "func", "(", "this", "*", "FcmClient", ")", "sendOnce", "(", ")", "(", "*", "FcmResponseStatus", ",", "error", ")", "{", "fcmRespStatus", ":=", "new", "(", "FcmResponseStatus", ")", "\n\n", "jsonByte", ",", "err", ":=", "this", ".", "Message", ".", "toJsonByte", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "fcmRespStatus", ",", "err", "\n", "}", "\n\n", "request", ",", "err", ":=", "http", ".", "NewRequest", "(", "\"", "\"", ",", "fcmServerUrl", ",", "bytes", ".", "NewBuffer", "(", "jsonByte", ")", ")", "\n", "request", ".", "Header", ".", "Set", "(", "\"", "\"", ",", "this", ".", "apiKeyHeader", "(", ")", ")", "\n", "request", ".", "Header", ".", "Set", "(", "\"", "\"", ",", "\"", "\"", ")", "\n\n", "client", ":=", "&", "http", ".", "Client", "{", "}", "\n", "response", ",", "err", ":=", "client", ".", "Do", "(", "request", ")", "\n\n", "if", "err", "!=", "nil", "{", "return", "fcmRespStatus", ",", "err", "\n", "}", "\n", "defer", "response", ".", "Body", ".", "Close", "(", ")", "\n\n", "body", ",", "err", ":=", "ioutil", ".", "ReadAll", "(", "response", ".", "Body", ")", "\n", "if", "err", "!=", "nil", "{", "return", "fcmRespStatus", ",", "err", "\n", "}", "\n\n", "fcmRespStatus", ".", "StatusCode", "=", "response", ".", "StatusCode", "\n\n", "fcmRespStatus", ".", "RetryAfter", "=", "response", ".", "Header", ".", "Get", "(", "retry_after_header", ")", "\n\n", "if", "response", ".", "StatusCode", "!=", "200", "{", "return", "fcmRespStatus", ",", "nil", "\n", "}", "\n\n", "err", "=", "fcmRespStatus", ".", "parseStatusBody", "(", "body", ")", "\n", "if", "err", "!=", "nil", "{", "return", "fcmRespStatus", ",", "err", "\n", "}", "\n", "fcmRespStatus", ".", "Ok", "=", "true", "\n\n", "return", "fcmRespStatus", ",", "nil", "\n", "}" ]
// sendOnce send a single request to fcm
[ "sendOnce", "send", "a", "single", "request", "to", "fcm" ]
28fff9381d17f35619309c7a5ada41d26030d976
https://github.com/NaySoftware/go-fcm/blob/28fff9381d17f35619309c7a5ada41d26030d976/fcm.go#L157-L198
train
NaySoftware/go-fcm
fcm.go
parseStatusBody
func (this *FcmResponseStatus) parseStatusBody(body []byte) error { if err := json.Unmarshal([]byte(body), &this); err != nil { return err } return nil }
go
func (this *FcmResponseStatus) parseStatusBody(body []byte) error { if err := json.Unmarshal([]byte(body), &this); err != nil { return err } return nil }
[ "func", "(", "this", "*", "FcmResponseStatus", ")", "parseStatusBody", "(", "body", "[", "]", "byte", ")", "error", "{", "if", "err", ":=", "json", ".", "Unmarshal", "(", "[", "]", "byte", "(", "body", ")", ",", "&", "this", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", "nil", "\n\n", "}" ]
// parseStatusBody parse FCM response body
[ "parseStatusBody", "parse", "FCM", "response", "body" ]
28fff9381d17f35619309c7a5ada41d26030d976
https://github.com/NaySoftware/go-fcm/blob/28fff9381d17f35619309c7a5ada41d26030d976/fcm.go#L214-L221
train
NaySoftware/go-fcm
fcm.go
SetPriority
func (this *FcmClient) SetPriority(p string) *FcmClient { if p == Priority_HIGH { this.Message.Priority = Priority_HIGH } else { this.Message.Priority = Priority_NORMAL } return this }
go
func (this *FcmClient) SetPriority(p string) *FcmClient { if p == Priority_HIGH { this.Message.Priority = Priority_HIGH } else { this.Message.Priority = Priority_NORMAL } return this }
[ "func", "(", "this", "*", "FcmClient", ")", "SetPriority", "(", "p", "string", ")", "*", "FcmClient", "{", "if", "p", "==", "Priority_HIGH", "{", "this", ".", "Message", ".", "Priority", "=", "Priority_HIGH", "\n", "}", "else", "{", "this", ".", "Message", ".", "Priority", "=", "Priority_NORMAL", "\n", "}", "\n\n", "return", "this", "\n", "}" ]
// SetPriority Sets the priority of the message. // Priority_HIGH or Priority_NORMAL
[ "SetPriority", "Sets", "the", "priority", "of", "the", "message", ".", "Priority_HIGH", "or", "Priority_NORMAL" ]
28fff9381d17f35619309c7a5ada41d26030d976
https://github.com/NaySoftware/go-fcm/blob/28fff9381d17f35619309c7a5ada41d26030d976/fcm.go#L225-L234
train
NaySoftware/go-fcm
fcm.go
SetContentAvailable
func (this *FcmClient) SetContentAvailable(isContentAvailable bool) *FcmClient { this.Message.ContentAvailable = isContentAvailable return this }
go
func (this *FcmClient) SetContentAvailable(isContentAvailable bool) *FcmClient { this.Message.ContentAvailable = isContentAvailable return this }
[ "func", "(", "this", "*", "FcmClient", ")", "SetContentAvailable", "(", "isContentAvailable", "bool", ")", "*", "FcmClient", "{", "this", ".", "Message", ".", "ContentAvailable", "=", "isContentAvailable", "\n\n", "return", "this", "\n", "}" ]
// SetContentAvailable On iOS, use this field to represent content-available // in the APNS payload. When a notification or message is sent and this is set // to true, an inactive client app is awoken. On Android, data messages wake // the app by default. On Chrome, currently not supported.
[ "SetContentAvailable", "On", "iOS", "use", "this", "field", "to", "represent", "content", "-", "available", "in", "the", "APNS", "payload", ".", "When", "a", "notification", "or", "message", "is", "sent", "and", "this", "is", "set", "to", "true", "an", "inactive", "client", "app", "is", "awoken", ".", "On", "Android", "data", "messages", "wake", "the", "app", "by", "default", ".", "On", "Chrome", "currently", "not", "supported", "." ]
28fff9381d17f35619309c7a5ada41d26030d976
https://github.com/NaySoftware/go-fcm/blob/28fff9381d17f35619309c7a5ada41d26030d976/fcm.go#L261-L266
train
NaySoftware/go-fcm
fcm.go
SetDelayWhileIdle
func (this *FcmClient) SetDelayWhileIdle(isDelayWhileIdle bool) *FcmClient { this.Message.DelayWhileIdle = isDelayWhileIdle return this }
go
func (this *FcmClient) SetDelayWhileIdle(isDelayWhileIdle bool) *FcmClient { this.Message.DelayWhileIdle = isDelayWhileIdle return this }
[ "func", "(", "this", "*", "FcmClient", ")", "SetDelayWhileIdle", "(", "isDelayWhileIdle", "bool", ")", "*", "FcmClient", "{", "this", ".", "Message", ".", "DelayWhileIdle", "=", "isDelayWhileIdle", "\n\n", "return", "this", "\n", "}" ]
// SetDelayWhileIdle When this parameter is set to true, it indicates that // the message should not be sent until the device becomes active. // The default value is false.
[ "SetDelayWhileIdle", "When", "this", "parameter", "is", "set", "to", "true", "it", "indicates", "that", "the", "message", "should", "not", "be", "sent", "until", "the", "device", "becomes", "active", ".", "The", "default", "value", "is", "false", "." ]
28fff9381d17f35619309c7a5ada41d26030d976
https://github.com/NaySoftware/go-fcm/blob/28fff9381d17f35619309c7a5ada41d26030d976/fcm.go#L271-L276
train
NaySoftware/go-fcm
fcm.go
SetRestrictedPackageName
func (this *FcmClient) SetRestrictedPackageName(pkg string) *FcmClient { this.Message.RestrictedPackageName = pkg return this }
go
func (this *FcmClient) SetRestrictedPackageName(pkg string) *FcmClient { this.Message.RestrictedPackageName = pkg return this }
[ "func", "(", "this", "*", "FcmClient", ")", "SetRestrictedPackageName", "(", "pkg", "string", ")", "*", "FcmClient", "{", "this", ".", "Message", ".", "RestrictedPackageName", "=", "pkg", "\n\n", "return", "this", "\n", "}" ]
// SetRestrictedPackageName This parameter specifies the package name of the // application where the registration tokens must match in order to // receive the message.
[ "SetRestrictedPackageName", "This", "parameter", "specifies", "the", "package", "name", "of", "the", "application", "where", "the", "registration", "tokens", "must", "match", "in", "order", "to", "receive", "the", "message", "." ]
28fff9381d17f35619309c7a5ada41d26030d976
https://github.com/NaySoftware/go-fcm/blob/28fff9381d17f35619309c7a5ada41d26030d976/fcm.go#L300-L305
train
NaySoftware/go-fcm
fcm.go
SetDryRun
func (this *FcmClient) SetDryRun(drun bool) *FcmClient { this.Message.DryRun = drun return this }
go
func (this *FcmClient) SetDryRun(drun bool) *FcmClient { this.Message.DryRun = drun return this }
[ "func", "(", "this", "*", "FcmClient", ")", "SetDryRun", "(", "drun", "bool", ")", "*", "FcmClient", "{", "this", ".", "Message", ".", "DryRun", "=", "drun", "\n\n", "return", "this", "\n", "}" ]
// SetDryRun This parameter, when set to true, allows developers to test // a request without actually sending a message. // The default value is false
[ "SetDryRun", "This", "parameter", "when", "set", "to", "true", "allows", "developers", "to", "test", "a", "request", "without", "actually", "sending", "a", "message", ".", "The", "default", "value", "is", "false" ]
28fff9381d17f35619309c7a5ada41d26030d976
https://github.com/NaySoftware/go-fcm/blob/28fff9381d17f35619309c7a5ada41d26030d976/fcm.go#L310-L315
train
NaySoftware/go-fcm
fcm.go
SetMutableContent
func (this *FcmClient) SetMutableContent(mc bool) *FcmClient { this.Message.MutableContent = mc return this }
go
func (this *FcmClient) SetMutableContent(mc bool) *FcmClient { this.Message.MutableContent = mc return this }
[ "func", "(", "this", "*", "FcmClient", ")", "SetMutableContent", "(", "mc", "bool", ")", "*", "FcmClient", "{", "this", ".", "Message", ".", "MutableContent", "=", "mc", "\n\n", "return", "this", "\n", "}" ]
// SetMutableContent Currently for iOS 10+ devices only. On iOS, // use this field to represent mutable-content in the APNs payload. // When a notification is sent and this is set to true, the content // of the notification can be modified before it is displayed, // using a Notification Service app extension. // This parameter will be ignored for Android and web.
[ "SetMutableContent", "Currently", "for", "iOS", "10", "+", "devices", "only", ".", "On", "iOS", "use", "this", "field", "to", "represent", "mutable", "-", "content", "in", "the", "APNs", "payload", ".", "When", "a", "notification", "is", "sent", "and", "this", "is", "set", "to", "true", "the", "content", "of", "the", "notification", "can", "be", "modified", "before", "it", "is", "displayed", "using", "a", "Notification", "Service", "app", "extension", ".", "This", "parameter", "will", "be", "ignored", "for", "Android", "and", "web", "." ]
28fff9381d17f35619309c7a5ada41d26030d976
https://github.com/NaySoftware/go-fcm/blob/28fff9381d17f35619309c7a5ada41d26030d976/fcm.go#L323-L328
train
NaySoftware/go-fcm
fcm.go
PrintResults
func (this *FcmResponseStatus) PrintResults() { fmt.Println("Status Code :", this.StatusCode) fmt.Println("Success :", this.Success) fmt.Println("Fail :", this.Fail) fmt.Println("Canonical_ids :", this.Canonical_ids) fmt.Println("Topic MsgId :", this.MsgId) fmt.Println("Topic Err :", this.Err) for i, val := range this.Results { fmt.Printf("Result(%d)> \n", i) for k, v := range val { fmt.Println("\t", k, " : ", v) } } }
go
func (this *FcmResponseStatus) PrintResults() { fmt.Println("Status Code :", this.StatusCode) fmt.Println("Success :", this.Success) fmt.Println("Fail :", this.Fail) fmt.Println("Canonical_ids :", this.Canonical_ids) fmt.Println("Topic MsgId :", this.MsgId) fmt.Println("Topic Err :", this.Err) for i, val := range this.Results { fmt.Printf("Result(%d)> \n", i) for k, v := range val { fmt.Println("\t", k, " : ", v) } } }
[ "func", "(", "this", "*", "FcmResponseStatus", ")", "PrintResults", "(", ")", "{", "fmt", ".", "Println", "(", "\"", "\"", ",", "this", ".", "StatusCode", ")", "\n", "fmt", ".", "Println", "(", "\"", "\"", ",", "this", ".", "Success", ")", "\n", "fmt", ".", "Println", "(", "\"", "\"", ",", "this", ".", "Fail", ")", "\n", "fmt", ".", "Println", "(", "\"", "\"", ",", "this", ".", "Canonical_ids", ")", "\n", "fmt", ".", "Println", "(", "\"", "\"", ",", "this", ".", "MsgId", ")", "\n", "fmt", ".", "Println", "(", "\"", "\"", ",", "this", ".", "Err", ")", "\n", "for", "i", ",", "val", ":=", "range", "this", ".", "Results", "{", "fmt", ".", "Printf", "(", "\"", "\\n", "\"", ",", "i", ")", "\n", "for", "k", ",", "v", ":=", "range", "val", "{", "fmt", ".", "Println", "(", "\"", "\\t", "\"", ",", "k", ",", "\"", "\"", ",", "v", ")", "\n", "}", "\n", "}", "\n", "}" ]
// PrintResults prints the FcmResponseStatus results for fast using and debugging
[ "PrintResults", "prints", "the", "FcmResponseStatus", "results", "for", "fast", "using", "and", "debugging" ]
28fff9381d17f35619309c7a5ada41d26030d976
https://github.com/NaySoftware/go-fcm/blob/28fff9381d17f35619309c7a5ada41d26030d976/fcm.go#L331-L344
train
NaySoftware/go-fcm
fcm.go
IsTimeout
func (this *FcmResponseStatus) IsTimeout() bool { if this.StatusCode >= 500 { return true } else if this.StatusCode == 200 { for _, val := range this.Results { for k, v := range val { if k == error_key && retreyableErrors[v] == true { return true } } } } return false }
go
func (this *FcmResponseStatus) IsTimeout() bool { if this.StatusCode >= 500 { return true } else if this.StatusCode == 200 { for _, val := range this.Results { for k, v := range val { if k == error_key && retreyableErrors[v] == true { return true } } } } return false }
[ "func", "(", "this", "*", "FcmResponseStatus", ")", "IsTimeout", "(", ")", "bool", "{", "if", "this", ".", "StatusCode", ">=", "500", "{", "return", "true", "\n", "}", "else", "if", "this", ".", "StatusCode", "==", "200", "{", "for", "_", ",", "val", ":=", "range", "this", ".", "Results", "{", "for", "k", ",", "v", ":=", "range", "val", "{", "if", "k", "==", "error_key", "&&", "retreyableErrors", "[", "v", "]", "==", "true", "{", "return", "true", "\n", "}", "\n", "}", "\n", "}", "\n", "}", "\n\n", "return", "false", "\n", "}" ]
// IsTimeout check whether the response timeout based on http response status // code and if any error is retryable
[ "IsTimeout", "check", "whether", "the", "response", "timeout", "based", "on", "http", "response", "status", "code", "and", "if", "any", "error", "is", "retryable" ]
28fff9381d17f35619309c7a5ada41d26030d976
https://github.com/NaySoftware/go-fcm/blob/28fff9381d17f35619309c7a5ada41d26030d976/fcm.go#L348-L362
train
NaySoftware/go-fcm
fcm.go
GetRetryAfterTime
func (this *FcmResponseStatus) GetRetryAfterTime() (t time.Duration, e error) { t, e = time.ParseDuration(this.RetryAfter) return }
go
func (this *FcmResponseStatus) GetRetryAfterTime() (t time.Duration, e error) { t, e = time.ParseDuration(this.RetryAfter) return }
[ "func", "(", "this", "*", "FcmResponseStatus", ")", "GetRetryAfterTime", "(", ")", "(", "t", "time", ".", "Duration", ",", "e", "error", ")", "{", "t", ",", "e", "=", "time", ".", "ParseDuration", "(", "this", ".", "RetryAfter", ")", "\n", "return", "\n", "}" ]
// GetRetryAfterTime converts the retrey after response header // to a time.Duration
[ "GetRetryAfterTime", "converts", "the", "retrey", "after", "response", "header", "to", "a", "time", ".", "Duration" ]
28fff9381d17f35619309c7a5ada41d26030d976
https://github.com/NaySoftware/go-fcm/blob/28fff9381d17f35619309c7a5ada41d26030d976/fcm.go#L366-L369
train
NaySoftware/go-fcm
fcm.go
SetCondition
func (this *FcmClient) SetCondition(condition string) *FcmClient { this.Message.Condition = condition return this }
go
func (this *FcmClient) SetCondition(condition string) *FcmClient { this.Message.Condition = condition return this }
[ "func", "(", "this", "*", "FcmClient", ")", "SetCondition", "(", "condition", "string", ")", "*", "FcmClient", "{", "this", ".", "Message", ".", "Condition", "=", "condition", "\n", "return", "this", "\n", "}" ]
// SetCondition to set a logical expression of conditions that determine the message target
[ "SetCondition", "to", "set", "a", "logical", "expression", "of", "conditions", "that", "determine", "the", "message", "target" ]
28fff9381d17f35619309c7a5ada41d26030d976
https://github.com/NaySoftware/go-fcm/blob/28fff9381d17f35619309c7a5ada41d26030d976/fcm.go#L372-L375
train
NaySoftware/go-fcm
instanceid.go
GetInfo
func (this *FcmClient) GetInfo(withDetails bool, instanceIdToken string) (*InstanceIdInfoResponse, error) { var request_url string = generateGetInfoUrl(instance_id_info_no_details_srv_url, instanceIdToken) if withDetails == true { request_url = generateGetInfoUrl(instance_id_info_with_details_srv_url, instanceIdToken) } request, err := http.NewRequest("GET", request_url, nil) request.Header.Set("Authorization", this.apiKeyHeader()) request.Header.Set("Content-Type", "application/json") if err != nil { return nil, err } client := &http.Client{} response, err := client.Do(request) if err != nil { return nil, err } defer response.Body.Close() body, err := ioutil.ReadAll(response.Body) if err != nil { return nil, err } infoResponse, err := parseGetInfo(body) if err != nil { return nil, err } return infoResponse, nil }
go
func (this *FcmClient) GetInfo(withDetails bool, instanceIdToken string) (*InstanceIdInfoResponse, error) { var request_url string = generateGetInfoUrl(instance_id_info_no_details_srv_url, instanceIdToken) if withDetails == true { request_url = generateGetInfoUrl(instance_id_info_with_details_srv_url, instanceIdToken) } request, err := http.NewRequest("GET", request_url, nil) request.Header.Set("Authorization", this.apiKeyHeader()) request.Header.Set("Content-Type", "application/json") if err != nil { return nil, err } client := &http.Client{} response, err := client.Do(request) if err != nil { return nil, err } defer response.Body.Close() body, err := ioutil.ReadAll(response.Body) if err != nil { return nil, err } infoResponse, err := parseGetInfo(body) if err != nil { return nil, err } return infoResponse, nil }
[ "func", "(", "this", "*", "FcmClient", ")", "GetInfo", "(", "withDetails", "bool", ",", "instanceIdToken", "string", ")", "(", "*", "InstanceIdInfoResponse", ",", "error", ")", "{", "var", "request_url", "string", "=", "generateGetInfoUrl", "(", "instance_id_info_no_details_srv_url", ",", "instanceIdToken", ")", "\n\n", "if", "withDetails", "==", "true", "{", "request_url", "=", "generateGetInfoUrl", "(", "instance_id_info_with_details_srv_url", ",", "instanceIdToken", ")", "\n", "}", "\n\n", "request", ",", "err", ":=", "http", ".", "NewRequest", "(", "\"", "\"", ",", "request_url", ",", "nil", ")", "\n", "request", ".", "Header", ".", "Set", "(", "\"", "\"", ",", "this", ".", "apiKeyHeader", "(", ")", ")", "\n", "request", ".", "Header", ".", "Set", "(", "\"", "\"", ",", "\"", "\"", ")", "\n\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "client", ":=", "&", "http", ".", "Client", "{", "}", "\n", "response", ",", "err", ":=", "client", ".", "Do", "(", "request", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "defer", "response", ".", "Body", ".", "Close", "(", ")", "\n\n", "body", ",", "err", ":=", "ioutil", ".", "ReadAll", "(", "response", ".", "Body", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "infoResponse", ",", "err", ":=", "parseGetInfo", "(", "body", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "infoResponse", ",", "nil", "\n", "}" ]
// GetInfo gets the instance id info
[ "GetInfo", "gets", "the", "instance", "id", "info" ]
28fff9381d17f35619309c7a5ada41d26030d976
https://github.com/NaySoftware/go-fcm/blob/28fff9381d17f35619309c7a5ada41d26030d976/instanceid.go#L104-L139
train
NaySoftware/go-fcm
instanceid.go
parseGetInfo
func parseGetInfo(body []byte) (*InstanceIdInfoResponse, error) { info := new(InstanceIdInfoResponse) if err := json.Unmarshal([]byte(body), &info); err != nil { return nil, err } return info, nil }
go
func parseGetInfo(body []byte) (*InstanceIdInfoResponse, error) { info := new(InstanceIdInfoResponse) if err := json.Unmarshal([]byte(body), &info); err != nil { return nil, err } return info, nil }
[ "func", "parseGetInfo", "(", "body", "[", "]", "byte", ")", "(", "*", "InstanceIdInfoResponse", ",", "error", ")", "{", "info", ":=", "new", "(", "InstanceIdInfoResponse", ")", "\n\n", "if", "err", ":=", "json", ".", "Unmarshal", "(", "[", "]", "byte", "(", "body", ")", ",", "&", "info", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "info", ",", "nil", "\n\n", "}" ]
// parseGetInfo parses response to InstanceIdInfoResponse
[ "parseGetInfo", "parses", "response", "to", "InstanceIdInfoResponse" ]
28fff9381d17f35619309c7a5ada41d26030d976
https://github.com/NaySoftware/go-fcm/blob/28fff9381d17f35619309c7a5ada41d26030d976/instanceid.go#L142-L152
train
NaySoftware/go-fcm
instanceid.go
PrintResults
func (this *InstanceIdInfoResponse) PrintResults() { fmt.Println("Error : ", this.Error) fmt.Println("App : ", this.Application) fmt.Println("Auth : ", this.AuthorizedEntity) fmt.Println("Ver : ", this.ApplicationVersion) fmt.Println("Sig : ", this.AppSigner) fmt.Println("Att : ", this.AttestStatus) fmt.Println("Platform : ", this.Platform) fmt.Println("Connection: ", this.ConnectionType) fmt.Println("ConnDate : ", this.ConnectDate) fmt.Println("Rel : ") for k, v := range this.Rel { fmt.Println(k, " --> ") for k2, v2 := range v { fmt.Println("\t", k2, "\t|") fmt.Println("\t\t", "addDate", " : ", v2["addDate"]) } } }
go
func (this *InstanceIdInfoResponse) PrintResults() { fmt.Println("Error : ", this.Error) fmt.Println("App : ", this.Application) fmt.Println("Auth : ", this.AuthorizedEntity) fmt.Println("Ver : ", this.ApplicationVersion) fmt.Println("Sig : ", this.AppSigner) fmt.Println("Att : ", this.AttestStatus) fmt.Println("Platform : ", this.Platform) fmt.Println("Connection: ", this.ConnectionType) fmt.Println("ConnDate : ", this.ConnectDate) fmt.Println("Rel : ") for k, v := range this.Rel { fmt.Println(k, " --> ") for k2, v2 := range v { fmt.Println("\t", k2, "\t|") fmt.Println("\t\t", "addDate", " : ", v2["addDate"]) } } }
[ "func", "(", "this", "*", "InstanceIdInfoResponse", ")", "PrintResults", "(", ")", "{", "fmt", ".", "Println", "(", "\"", "\"", ",", "this", ".", "Error", ")", "\n", "fmt", ".", "Println", "(", "\"", "\"", ",", "this", ".", "Application", ")", "\n", "fmt", ".", "Println", "(", "\"", "\"", ",", "this", ".", "AuthorizedEntity", ")", "\n", "fmt", ".", "Println", "(", "\"", "\"", ",", "this", ".", "ApplicationVersion", ")", "\n", "fmt", ".", "Println", "(", "\"", "\"", ",", "this", ".", "AppSigner", ")", "\n", "fmt", ".", "Println", "(", "\"", "\"", ",", "this", ".", "AttestStatus", ")", "\n", "fmt", ".", "Println", "(", "\"", "\"", ",", "this", ".", "Platform", ")", "\n", "fmt", ".", "Println", "(", "\"", "\"", ",", "this", ".", "ConnectionType", ")", "\n", "fmt", ".", "Println", "(", "\"", "\"", ",", "this", ".", "ConnectDate", ")", "\n", "fmt", ".", "Println", "(", "\"", "\"", ")", "\n", "for", "k", ",", "v", ":=", "range", "this", ".", "Rel", "{", "fmt", ".", "Println", "(", "k", ",", "\"", "\"", ")", "\n", "for", "k2", ",", "v2", ":=", "range", "v", "{", "fmt", ".", "Println", "(", "\"", "\\t", "\"", ",", "k2", ",", "\"", "\\t", "\"", ")", "\n", "fmt", ".", "Println", "(", "\"", "\\t", "\\t", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "v2", "[", "\"", "\"", "]", ")", "\n", "}", "\n", "}", "\n", "}" ]
// PrintResults prints InstanceIdInfoResponse, for faster debugging
[ "PrintResults", "prints", "InstanceIdInfoResponse", "for", "faster", "debugging" ]
28fff9381d17f35619309c7a5ada41d26030d976
https://github.com/NaySoftware/go-fcm/blob/28fff9381d17f35619309c7a5ada41d26030d976/instanceid.go#L155-L173
train
NaySoftware/go-fcm
instanceid.go
generateGetInfoUrl
func generateGetInfoUrl(srv string, instanceIdToken string) string { return fmt.Sprintf(srv, instanceIdToken) }
go
func generateGetInfoUrl(srv string, instanceIdToken string) string { return fmt.Sprintf(srv, instanceIdToken) }
[ "func", "generateGetInfoUrl", "(", "srv", "string", ",", "instanceIdToken", "string", ")", "string", "{", "return", "fmt", ".", "Sprintf", "(", "srv", ",", "instanceIdToken", ")", "\n", "}" ]
// generateGetInfoUrl generate based on with details and the instance token
[ "generateGetInfoUrl", "generate", "based", "on", "with", "details", "and", "the", "instance", "token" ]
28fff9381d17f35619309c7a5ada41d26030d976
https://github.com/NaySoftware/go-fcm/blob/28fff9381d17f35619309c7a5ada41d26030d976/instanceid.go#L176-L178
train
NaySoftware/go-fcm
instanceid.go
parseSubscribeResponse
func parseSubscribeResponse(body []byte, resp *http.Response) (*SubscribeResponse, error) { subResp := new(SubscribeResponse) subResp.Status = resp.Status subResp.StatusCode = resp.StatusCode if err := json.Unmarshal(body, &subResp); err != nil { return nil, err } return subResp, nil }
go
func parseSubscribeResponse(body []byte, resp *http.Response) (*SubscribeResponse, error) { subResp := new(SubscribeResponse) subResp.Status = resp.Status subResp.StatusCode = resp.StatusCode if err := json.Unmarshal(body, &subResp); err != nil { return nil, err } return subResp, nil }
[ "func", "parseSubscribeResponse", "(", "body", "[", "]", "byte", ",", "resp", "*", "http", ".", "Response", ")", "(", "*", "SubscribeResponse", ",", "error", ")", "{", "subResp", ":=", "new", "(", "SubscribeResponse", ")", "\n\n", "subResp", ".", "Status", "=", "resp", ".", "Status", "\n", "subResp", ".", "StatusCode", "=", "resp", ".", "StatusCode", "\n\n", "if", "err", ":=", "json", ".", "Unmarshal", "(", "body", ",", "&", "subResp", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "subResp", ",", "nil", "\n", "}" ]
// parseSubscribeResponse converts a byte response to a SubscribeResponse
[ "parseSubscribeResponse", "converts", "a", "byte", "response", "to", "a", "SubscribeResponse" ]
28fff9381d17f35619309c7a5ada41d26030d976
https://github.com/NaySoftware/go-fcm/blob/28fff9381d17f35619309c7a5ada41d26030d976/instanceid.go#L213-L224
train
NaySoftware/go-fcm
instanceid.go
PrintResults
func (this *SubscribeResponse) PrintResults() { fmt.Println("Response Status: ", this.Status) fmt.Println("Response Code : ", this.StatusCode) if this.StatusCode != 200 { fmt.Println("Error : ", this.Error) } }
go
func (this *SubscribeResponse) PrintResults() { fmt.Println("Response Status: ", this.Status) fmt.Println("Response Code : ", this.StatusCode) if this.StatusCode != 200 { fmt.Println("Error : ", this.Error) } }
[ "func", "(", "this", "*", "SubscribeResponse", ")", "PrintResults", "(", ")", "{", "fmt", ".", "Println", "(", "\"", "\"", ",", "this", ".", "Status", ")", "\n", "fmt", ".", "Println", "(", "\"", "\"", ",", "this", ".", "StatusCode", ")", "\n", "if", "this", ".", "StatusCode", "!=", "200", "{", "fmt", ".", "Println", "(", "\"", "\"", ",", "this", ".", "Error", ")", "\n", "}", "\n\n", "}" ]
// PrintResults prints SubscribeResponse, for faster debugging
[ "PrintResults", "prints", "SubscribeResponse", "for", "faster", "debugging" ]
28fff9381d17f35619309c7a5ada41d26030d976
https://github.com/NaySoftware/go-fcm/blob/28fff9381d17f35619309c7a5ada41d26030d976/instanceid.go#L227-L235
train
NaySoftware/go-fcm
instanceid.go
generateSubToTopicUrl
func generateSubToTopicUrl(instaceId string, topic string) string { Tmptopic := strings.ToLower(topic) if strings.Contains(Tmptopic, "/topics/") { tmp := strings.Split(topic, "/") topic = tmp[len(tmp)-1] } return fmt.Sprintf(subscribe_instanceid_to_topic_srv_url, instaceId, topic) }
go
func generateSubToTopicUrl(instaceId string, topic string) string { Tmptopic := strings.ToLower(topic) if strings.Contains(Tmptopic, "/topics/") { tmp := strings.Split(topic, "/") topic = tmp[len(tmp)-1] } return fmt.Sprintf(subscribe_instanceid_to_topic_srv_url, instaceId, topic) }
[ "func", "generateSubToTopicUrl", "(", "instaceId", "string", ",", "topic", "string", ")", "string", "{", "Tmptopic", ":=", "strings", ".", "ToLower", "(", "topic", ")", "\n", "if", "strings", ".", "Contains", "(", "Tmptopic", ",", "\"", "\"", ")", "{", "tmp", ":=", "strings", ".", "Split", "(", "topic", ",", "\"", "\"", ")", "\n", "topic", "=", "tmp", "[", "len", "(", "tmp", ")", "-", "1", "]", "\n", "}", "\n", "return", "fmt", ".", "Sprintf", "(", "subscribe_instanceid_to_topic_srv_url", ",", "instaceId", ",", "topic", ")", "\n", "}" ]
// generateSubToTopicUrl generates a url based on the instnace id and topic name
[ "generateSubToTopicUrl", "generates", "a", "url", "based", "on", "the", "instnace", "id", "and", "topic", "name" ]
28fff9381d17f35619309c7a5ada41d26030d976
https://github.com/NaySoftware/go-fcm/blob/28fff9381d17f35619309c7a5ada41d26030d976/instanceid.go#L238-L245
train
NaySoftware/go-fcm
instanceid.go
PrintResults
func (this *BatchResponse) PrintResults() { fmt.Println("Error : ", this.Error) fmt.Println("Status : ", this.Status) fmt.Println("Status Code : ", this.StatusCode) for i, val := range this.Results { if batchErrors[val["error"]] == true { fmt.Println("ID: ", i, " | ", val["error"]) } } }
go
func (this *BatchResponse) PrintResults() { fmt.Println("Error : ", this.Error) fmt.Println("Status : ", this.Status) fmt.Println("Status Code : ", this.StatusCode) for i, val := range this.Results { if batchErrors[val["error"]] == true { fmt.Println("ID: ", i, " | ", val["error"]) } } }
[ "func", "(", "this", "*", "BatchResponse", ")", "PrintResults", "(", ")", "{", "fmt", ".", "Println", "(", "\"", "\"", ",", "this", ".", "Error", ")", "\n", "fmt", ".", "Println", "(", "\"", "\"", ",", "this", ".", "Status", ")", "\n", "fmt", ".", "Println", "(", "\"", "\"", ",", "this", ".", "StatusCode", ")", "\n", "for", "i", ",", "val", ":=", "range", "this", ".", "Results", "{", "if", "batchErrors", "[", "val", "[", "\"", "\"", "]", "]", "==", "true", "{", "fmt", ".", "Println", "(", "\"", "\"", ",", "i", ",", "\"", "\"", ",", "val", "[", "\"", "\"", "]", ")", "\n", "}", "\n", "}", "\n", "}" ]
// PrintResults prints BatchResponse, for faster debugging
[ "PrintResults", "prints", "BatchResponse", "for", "faster", "debugging" ]
28fff9381d17f35619309c7a5ada41d26030d976
https://github.com/NaySoftware/go-fcm/blob/28fff9381d17f35619309c7a5ada41d26030d976/instanceid.go#L331-L340
train
NaySoftware/go-fcm
instanceid.go
generateBatchRequest
func generateBatchRequest(tokens []string, topic string) ([]byte, error) { envelope := new(BatchRequest) envelope.To = topics + extractTopicName(topic) envelope.RegTokens = make([]string, len(tokens)) copy(envelope.RegTokens, tokens) return json.Marshal(envelope) }
go
func generateBatchRequest(tokens []string, topic string) ([]byte, error) { envelope := new(BatchRequest) envelope.To = topics + extractTopicName(topic) envelope.RegTokens = make([]string, len(tokens)) copy(envelope.RegTokens, tokens) return json.Marshal(envelope) }
[ "func", "generateBatchRequest", "(", "tokens", "[", "]", "string", ",", "topic", "string", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "envelope", ":=", "new", "(", "BatchRequest", ")", "\n", "envelope", ".", "To", "=", "topics", "+", "extractTopicName", "(", "topic", ")", "\n", "envelope", ".", "RegTokens", "=", "make", "(", "[", "]", "string", ",", "len", "(", "tokens", ")", ")", "\n", "copy", "(", "envelope", ".", "RegTokens", ",", "tokens", ")", "\n\n", "return", "json", ".", "Marshal", "(", "envelope", ")", "\n\n", "}" ]
// generateBatchRequest based on tokens and topic
[ "generateBatchRequest", "based", "on", "tokens", "and", "topic" ]
28fff9381d17f35619309c7a5ada41d26030d976
https://github.com/NaySoftware/go-fcm/blob/28fff9381d17f35619309c7a5ada41d26030d976/instanceid.go#L343-L351
train
NaySoftware/go-fcm
instanceid.go
extractTopicName
func extractTopicName(inTopic string) (result string) { Tmptopic := strings.ToLower(inTopic) if strings.Contains(Tmptopic, "/topics/") { tmp := strings.Split(inTopic, "/") result = tmp[len(tmp)-1] return } result = inTopic return }
go
func extractTopicName(inTopic string) (result string) { Tmptopic := strings.ToLower(inTopic) if strings.Contains(Tmptopic, "/topics/") { tmp := strings.Split(inTopic, "/") result = tmp[len(tmp)-1] return } result = inTopic return }
[ "func", "extractTopicName", "(", "inTopic", "string", ")", "(", "result", "string", ")", "{", "Tmptopic", ":=", "strings", ".", "ToLower", "(", "inTopic", ")", "\n", "if", "strings", ".", "Contains", "(", "Tmptopic", ",", "\"", "\"", ")", "{", "tmp", ":=", "strings", ".", "Split", "(", "inTopic", ",", "\"", "\"", ")", "\n", "result", "=", "tmp", "[", "len", "(", "tmp", ")", "-", "1", "]", "\n", "return", "\n", "}", "\n\n", "result", "=", "inTopic", "\n", "return", "\n", "}" ]
// extractTopicName extract topic name for valid topic name input
[ "extractTopicName", "extract", "topic", "name", "for", "valid", "topic", "name", "input" ]
28fff9381d17f35619309c7a5ada41d26030d976
https://github.com/NaySoftware/go-fcm/blob/28fff9381d17f35619309c7a5ada41d26030d976/instanceid.go#L354-L364
train
NaySoftware/go-fcm
instanceid.go
generateBatchResponse
func generateBatchResponse(resp []byte) (*BatchResponse, error) { result := new(BatchResponse) if err := json.Unmarshal(resp, &result); err != nil { return nil, err } return result, nil }
go
func generateBatchResponse(resp []byte) (*BatchResponse, error) { result := new(BatchResponse) if err := json.Unmarshal(resp, &result); err != nil { return nil, err } return result, nil }
[ "func", "generateBatchResponse", "(", "resp", "[", "]", "byte", ")", "(", "*", "BatchResponse", ",", "error", ")", "{", "result", ":=", "new", "(", "BatchResponse", ")", "\n\n", "if", "err", ":=", "json", ".", "Unmarshal", "(", "resp", ",", "&", "result", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "result", ",", "nil", "\n\n", "}" ]
// generateBatchResponse converts a byte response to BatchResponse
[ "generateBatchResponse", "converts", "a", "byte", "response", "to", "BatchResponse" ]
28fff9381d17f35619309c7a5ada41d26030d976
https://github.com/NaySoftware/go-fcm/blob/28fff9381d17f35619309c7a5ada41d26030d976/instanceid.go#L367-L376
train
NaySoftware/go-fcm
instanceid.go
ApnsBatchImportRequest
func (this *FcmClient) ApnsBatchImportRequest(apnsReq *ApnsBatchRequest) (*ApnsBatchResponse, error) { jsonByte, err := apnsReq.ToByte() if err != nil { return nil, err } request, err := http.NewRequest("POST", apns_batch_import_srv_url, bytes.NewBuffer(jsonByte)) request.Header.Set("Authorization", this.apiKeyHeader()) request.Header.Set("Content-Type", "application/json") if err != nil { return nil, err } client := &http.Client{} response, err := client.Do(request) if err != nil { return nil, err } defer response.Body.Close() body, err := ioutil.ReadAll(response.Body) if err != nil { return nil, err } result, err := parseApnsBatchResponse(body) if err != nil { return nil, err } if result == nil { return nil, errors.New("Parsing Request error") } result.Status = response.Status result.StatusCode = response.StatusCode return result, nil }
go
func (this *FcmClient) ApnsBatchImportRequest(apnsReq *ApnsBatchRequest) (*ApnsBatchResponse, error) { jsonByte, err := apnsReq.ToByte() if err != nil { return nil, err } request, err := http.NewRequest("POST", apns_batch_import_srv_url, bytes.NewBuffer(jsonByte)) request.Header.Set("Authorization", this.apiKeyHeader()) request.Header.Set("Content-Type", "application/json") if err != nil { return nil, err } client := &http.Client{} response, err := client.Do(request) if err != nil { return nil, err } defer response.Body.Close() body, err := ioutil.ReadAll(response.Body) if err != nil { return nil, err } result, err := parseApnsBatchResponse(body) if err != nil { return nil, err } if result == nil { return nil, errors.New("Parsing Request error") } result.Status = response.Status result.StatusCode = response.StatusCode return result, nil }
[ "func", "(", "this", "*", "FcmClient", ")", "ApnsBatchImportRequest", "(", "apnsReq", "*", "ApnsBatchRequest", ")", "(", "*", "ApnsBatchResponse", ",", "error", ")", "{", "jsonByte", ",", "err", ":=", "apnsReq", ".", "ToByte", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "request", ",", "err", ":=", "http", ".", "NewRequest", "(", "\"", "\"", ",", "apns_batch_import_srv_url", ",", "bytes", ".", "NewBuffer", "(", "jsonByte", ")", ")", "\n", "request", ".", "Header", ".", "Set", "(", "\"", "\"", ",", "this", ".", "apiKeyHeader", "(", ")", ")", "\n", "request", ".", "Header", ".", "Set", "(", "\"", "\"", ",", "\"", "\"", ")", "\n\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "client", ":=", "&", "http", ".", "Client", "{", "}", "\n", "response", ",", "err", ":=", "client", ".", "Do", "(", "request", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "defer", "response", ".", "Body", ".", "Close", "(", ")", "\n\n", "body", ",", "err", ":=", "ioutil", ".", "ReadAll", "(", "response", ".", "Body", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "result", ",", "err", ":=", "parseApnsBatchResponse", "(", "body", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "if", "result", "==", "nil", "{", "return", "nil", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "result", ".", "Status", "=", "response", ".", "Status", "\n", "result", ".", "StatusCode", "=", "response", ".", "StatusCode", "\n\n", "return", "result", ",", "nil", "\n", "}" ]
// ApnsBatchImportRequest apns import requst
[ "ApnsBatchImportRequest", "apns", "import", "requst" ]
28fff9381d17f35619309c7a5ada41d26030d976
https://github.com/NaySoftware/go-fcm/blob/28fff9381d17f35619309c7a5ada41d26030d976/instanceid.go#L379-L420
train
NaySoftware/go-fcm
instanceid.go
ToByte
func (this *ApnsBatchRequest) ToByte() ([]byte, error) { data, err := json.Marshal(this) if err != nil { return nil, err } return data, nil }
go
func (this *ApnsBatchRequest) ToByte() ([]byte, error) { data, err := json.Marshal(this) if err != nil { return nil, err } return data, nil }
[ "func", "(", "this", "*", "ApnsBatchRequest", ")", "ToByte", "(", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "data", ",", "err", ":=", "json", ".", "Marshal", "(", "this", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "data", ",", "nil", "\n", "}" ]
// ToByte converts ApnsBatchRequest to a byte
[ "ToByte", "converts", "ApnsBatchRequest", "to", "a", "byte" ]
28fff9381d17f35619309c7a5ada41d26030d976
https://github.com/NaySoftware/go-fcm/blob/28fff9381d17f35619309c7a5ada41d26030d976/instanceid.go#L423-L430
train
NaySoftware/go-fcm
instanceid.go
parseApnsBatchResponse
func parseApnsBatchResponse(resp []byte) (*ApnsBatchResponse, error) { result := new(ApnsBatchResponse) if err := json.Unmarshal(resp, &result); err != nil { return nil, err } return result, nil }
go
func parseApnsBatchResponse(resp []byte) (*ApnsBatchResponse, error) { result := new(ApnsBatchResponse) if err := json.Unmarshal(resp, &result); err != nil { return nil, err } return result, nil }
[ "func", "parseApnsBatchResponse", "(", "resp", "[", "]", "byte", ")", "(", "*", "ApnsBatchResponse", ",", "error", ")", "{", "result", ":=", "new", "(", "ApnsBatchResponse", ")", "\n", "if", "err", ":=", "json", ".", "Unmarshal", "(", "resp", ",", "&", "result", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "result", ",", "nil", "\n\n", "}" ]
// parseApnsBatchResponse converts apns byte response to ApnsBatchResponse
[ "parseApnsBatchResponse", "converts", "apns", "byte", "response", "to", "ApnsBatchResponse" ]
28fff9381d17f35619309c7a5ada41d26030d976
https://github.com/NaySoftware/go-fcm/blob/28fff9381d17f35619309c7a5ada41d26030d976/instanceid.go#L433-L442
train
NaySoftware/go-fcm
instanceid.go
PrintResults
func (this *ApnsBatchResponse) PrintResults() { fmt.Println("Status : ", this.Status) fmt.Println("StatusCode : ", this.StatusCode) fmt.Println("Error : ", this.Error) for i, val := range this.Results { fmt.Println(i, ":") fmt.Println("\tAPNS Token", val[apns_token_key]) fmt.Println("\tStatus ", val[status_key]) fmt.Println("\tReg Token ", val[reg_token_key]) } }
go
func (this *ApnsBatchResponse) PrintResults() { fmt.Println("Status : ", this.Status) fmt.Println("StatusCode : ", this.StatusCode) fmt.Println("Error : ", this.Error) for i, val := range this.Results { fmt.Println(i, ":") fmt.Println("\tAPNS Token", val[apns_token_key]) fmt.Println("\tStatus ", val[status_key]) fmt.Println("\tReg Token ", val[reg_token_key]) } }
[ "func", "(", "this", "*", "ApnsBatchResponse", ")", "PrintResults", "(", ")", "{", "fmt", ".", "Println", "(", "\"", "\"", ",", "this", ".", "Status", ")", "\n", "fmt", ".", "Println", "(", "\"", "\"", ",", "this", ".", "StatusCode", ")", "\n", "fmt", ".", "Println", "(", "\"", "\"", ",", "this", ".", "Error", ")", "\n", "for", "i", ",", "val", ":=", "range", "this", ".", "Results", "{", "fmt", ".", "Println", "(", "i", ",", "\"", "\"", ")", "\n", "fmt", ".", "Println", "(", "\"", "\\t", "\"", ",", "val", "[", "apns_token_key", "]", ")", "\n", "fmt", ".", "Println", "(", "\"", "\\t", "\"", ",", "val", "[", "status_key", "]", ")", "\n", "fmt", ".", "Println", "(", "\"", "\\t", "\"", ",", "val", "[", "reg_token_key", "]", ")", "\n", "}", "\n", "}" ]
// PrintResults prints ApnsBatchResponse, for faster debugging
[ "PrintResults", "prints", "ApnsBatchResponse", "for", "faster", "debugging" ]
28fff9381d17f35619309c7a5ada41d26030d976
https://github.com/NaySoftware/go-fcm/blob/28fff9381d17f35619309c7a5ada41d26030d976/instanceid.go#L445-L455
train
kavu/go_reuseport
reuseport.go
Listen
func Listen(proto, addr string) (l net.Listener, err error) { return NewReusablePortListener(proto, addr) }
go
func Listen(proto, addr string) (l net.Listener, err error) { return NewReusablePortListener(proto, addr) }
[ "func", "Listen", "(", "proto", ",", "addr", "string", ")", "(", "l", "net", ".", "Listener", ",", "err", "error", ")", "{", "return", "NewReusablePortListener", "(", "proto", ",", "addr", ")", "\n", "}" ]
// Listen function is an alias for NewReusablePortListener.
[ "Listen", "function", "is", "an", "alias", "for", "NewReusablePortListener", "." ]
1f6171f327ed3893406d2a802c563390993c4bb5
https://github.com/kavu/go_reuseport/blob/1f6171f327ed3893406d2a802c563390993c4bb5/reuseport.go#L43-L45
train
kavu/go_reuseport
reuseport.go
ListenPacket
func ListenPacket(proto, addr string) (l net.PacketConn, err error) { return NewReusablePortPacketConn(proto, addr) }
go
func ListenPacket(proto, addr string) (l net.PacketConn, err error) { return NewReusablePortPacketConn(proto, addr) }
[ "func", "ListenPacket", "(", "proto", ",", "addr", "string", ")", "(", "l", "net", ".", "PacketConn", ",", "err", "error", ")", "{", "return", "NewReusablePortPacketConn", "(", "proto", ",", "addr", ")", "\n", "}" ]
// ListenPacket is an alias for NewReusablePortPacketConn.
[ "ListenPacket", "is", "an", "alias", "for", "NewReusablePortPacketConn", "." ]
1f6171f327ed3893406d2a802c563390993c4bb5
https://github.com/kavu/go_reuseport/blob/1f6171f327ed3893406d2a802c563390993c4bb5/reuseport.go#L48-L50
train
kavu/go_reuseport
udp.go
NewReusablePortPacketConn
func NewReusablePortPacketConn(proto, addr string) (l net.PacketConn, err error) { var ( soType, fd int file *os.File sockaddr syscall.Sockaddr ) if sockaddr, soType, err = getSockaddr(proto, addr); err != nil { return nil, err } syscall.ForkLock.RLock() fd, err = syscall.Socket(soType, syscall.SOCK_DGRAM, syscall.IPPROTO_UDP) if err == nil { syscall.CloseOnExec(fd) } syscall.ForkLock.RUnlock() if err != nil { syscall.Close(fd) return nil, err } defer func() { if err != nil { syscall.Close(fd) } }() if err = syscall.SetsockoptInt(fd, syscall.SOL_SOCKET, syscall.SO_REUSEADDR, 1); err != nil { return nil, err } if err = syscall.SetsockoptInt(fd, syscall.SOL_SOCKET, reusePort, 1); err != nil { return nil, err } if err = syscall.SetsockoptInt(fd, syscall.SOL_SOCKET, syscall.SO_BROADCAST, 1); err != nil { return nil, err } if err = syscall.Bind(fd, sockaddr); err != nil { return nil, err } file = os.NewFile(uintptr(fd), getSocketFileName(proto, addr)) if l, err = net.FilePacketConn(file); err != nil { return nil, err } if err = file.Close(); err != nil { return nil, err } return l, err }
go
func NewReusablePortPacketConn(proto, addr string) (l net.PacketConn, err error) { var ( soType, fd int file *os.File sockaddr syscall.Sockaddr ) if sockaddr, soType, err = getSockaddr(proto, addr); err != nil { return nil, err } syscall.ForkLock.RLock() fd, err = syscall.Socket(soType, syscall.SOCK_DGRAM, syscall.IPPROTO_UDP) if err == nil { syscall.CloseOnExec(fd) } syscall.ForkLock.RUnlock() if err != nil { syscall.Close(fd) return nil, err } defer func() { if err != nil { syscall.Close(fd) } }() if err = syscall.SetsockoptInt(fd, syscall.SOL_SOCKET, syscall.SO_REUSEADDR, 1); err != nil { return nil, err } if err = syscall.SetsockoptInt(fd, syscall.SOL_SOCKET, reusePort, 1); err != nil { return nil, err } if err = syscall.SetsockoptInt(fd, syscall.SOL_SOCKET, syscall.SO_BROADCAST, 1); err != nil { return nil, err } if err = syscall.Bind(fd, sockaddr); err != nil { return nil, err } file = os.NewFile(uintptr(fd), getSocketFileName(proto, addr)) if l, err = net.FilePacketConn(file); err != nil { return nil, err } if err = file.Close(); err != nil { return nil, err } return l, err }
[ "func", "NewReusablePortPacketConn", "(", "proto", ",", "addr", "string", ")", "(", "l", "net", ".", "PacketConn", ",", "err", "error", ")", "{", "var", "(", "soType", ",", "fd", "int", "\n", "file", "*", "os", ".", "File", "\n", "sockaddr", "syscall", ".", "Sockaddr", "\n", ")", "\n\n", "if", "sockaddr", ",", "soType", ",", "err", "=", "getSockaddr", "(", "proto", ",", "addr", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "syscall", ".", "ForkLock", ".", "RLock", "(", ")", "\n", "fd", ",", "err", "=", "syscall", ".", "Socket", "(", "soType", ",", "syscall", ".", "SOCK_DGRAM", ",", "syscall", ".", "IPPROTO_UDP", ")", "\n", "if", "err", "==", "nil", "{", "syscall", ".", "CloseOnExec", "(", "fd", ")", "\n", "}", "\n", "syscall", ".", "ForkLock", ".", "RUnlock", "(", ")", "\n", "if", "err", "!=", "nil", "{", "syscall", ".", "Close", "(", "fd", ")", "\n", "return", "nil", ",", "err", "\n", "}", "\n\n", "defer", "func", "(", ")", "{", "if", "err", "!=", "nil", "{", "syscall", ".", "Close", "(", "fd", ")", "\n", "}", "\n", "}", "(", ")", "\n\n", "if", "err", "=", "syscall", ".", "SetsockoptInt", "(", "fd", ",", "syscall", ".", "SOL_SOCKET", ",", "syscall", ".", "SO_REUSEADDR", ",", "1", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "if", "err", "=", "syscall", ".", "SetsockoptInt", "(", "fd", ",", "syscall", ".", "SOL_SOCKET", ",", "reusePort", ",", "1", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "if", "err", "=", "syscall", ".", "SetsockoptInt", "(", "fd", ",", "syscall", ".", "SOL_SOCKET", ",", "syscall", ".", "SO_BROADCAST", ",", "1", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "if", "err", "=", "syscall", ".", "Bind", "(", "fd", ",", "sockaddr", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "file", "=", "os", ".", "NewFile", "(", "uintptr", "(", "fd", ")", ",", "getSocketFileName", "(", "proto", ",", "addr", ")", ")", "\n", "if", "l", ",", "err", "=", "net", ".", "FilePacketConn", "(", "file", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "if", "err", "=", "file", ".", "Close", "(", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "l", ",", "err", "\n", "}" ]
// NewReusablePortPacketConn returns net.FilePacketConn that created from // a file discriptor for a socket with SO_REUSEPORT option.
[ "NewReusablePortPacketConn", "returns", "net", ".", "FilePacketConn", "that", "created", "from", "a", "file", "discriptor", "for", "a", "socket", "with", "SO_REUSEPORT", "option", "." ]
1f6171f327ed3893406d2a802c563390993c4bb5
https://github.com/kavu/go_reuseport/blob/1f6171f327ed3893406d2a802c563390993c4bb5/udp.go#L93-L147
train
kavu/go_reuseport
tcp.go
NewReusablePortListener
func NewReusablePortListener(proto, addr string) (l net.Listener, err error) { var ( soType, fd int file *os.File sockaddr syscall.Sockaddr ) if sockaddr, soType, err = getSockaddr(proto, addr); err != nil { return nil, err } syscall.ForkLock.RLock() if fd, err = syscall.Socket(soType, syscall.SOCK_STREAM, syscall.IPPROTO_TCP); err != nil { syscall.ForkLock.RUnlock() return nil, err } syscall.ForkLock.RUnlock() if err = syscall.SetsockoptInt(fd, syscall.SOL_SOCKET, syscall.SO_REUSEADDR, 1); err != nil { syscall.Close(fd) return nil, err } if err = syscall.SetsockoptInt(fd, syscall.SOL_SOCKET, reusePort, 1); err != nil { syscall.Close(fd) return nil, err } if err = syscall.Bind(fd, sockaddr); err != nil { syscall.Close(fd) return nil, err } // Set backlog size to the maximum if err = syscall.Listen(fd, listenerBacklogMaxSize); err != nil { syscall.Close(fd) return nil, err } file = os.NewFile(uintptr(fd), getSocketFileName(proto, addr)) if l, err = net.FileListener(file); err != nil { file.Close() return nil, err } if err = file.Close(); err != nil { return nil, err } return l, err }
go
func NewReusablePortListener(proto, addr string) (l net.Listener, err error) { var ( soType, fd int file *os.File sockaddr syscall.Sockaddr ) if sockaddr, soType, err = getSockaddr(proto, addr); err != nil { return nil, err } syscall.ForkLock.RLock() if fd, err = syscall.Socket(soType, syscall.SOCK_STREAM, syscall.IPPROTO_TCP); err != nil { syscall.ForkLock.RUnlock() return nil, err } syscall.ForkLock.RUnlock() if err = syscall.SetsockoptInt(fd, syscall.SOL_SOCKET, syscall.SO_REUSEADDR, 1); err != nil { syscall.Close(fd) return nil, err } if err = syscall.SetsockoptInt(fd, syscall.SOL_SOCKET, reusePort, 1); err != nil { syscall.Close(fd) return nil, err } if err = syscall.Bind(fd, sockaddr); err != nil { syscall.Close(fd) return nil, err } // Set backlog size to the maximum if err = syscall.Listen(fd, listenerBacklogMaxSize); err != nil { syscall.Close(fd) return nil, err } file = os.NewFile(uintptr(fd), getSocketFileName(proto, addr)) if l, err = net.FileListener(file); err != nil { file.Close() return nil, err } if err = file.Close(); err != nil { return nil, err } return l, err }
[ "func", "NewReusablePortListener", "(", "proto", ",", "addr", "string", ")", "(", "l", "net", ".", "Listener", ",", "err", "error", ")", "{", "var", "(", "soType", ",", "fd", "int", "\n", "file", "*", "os", ".", "File", "\n", "sockaddr", "syscall", ".", "Sockaddr", "\n", ")", "\n\n", "if", "sockaddr", ",", "soType", ",", "err", "=", "getSockaddr", "(", "proto", ",", "addr", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "syscall", ".", "ForkLock", ".", "RLock", "(", ")", "\n", "if", "fd", ",", "err", "=", "syscall", ".", "Socket", "(", "soType", ",", "syscall", ".", "SOCK_STREAM", ",", "syscall", ".", "IPPROTO_TCP", ")", ";", "err", "!=", "nil", "{", "syscall", ".", "ForkLock", ".", "RUnlock", "(", ")", "\n\n", "return", "nil", ",", "err", "\n", "}", "\n", "syscall", ".", "ForkLock", ".", "RUnlock", "(", ")", "\n\n", "if", "err", "=", "syscall", ".", "SetsockoptInt", "(", "fd", ",", "syscall", ".", "SOL_SOCKET", ",", "syscall", ".", "SO_REUSEADDR", ",", "1", ")", ";", "err", "!=", "nil", "{", "syscall", ".", "Close", "(", "fd", ")", "\n", "return", "nil", ",", "err", "\n", "}", "\n\n", "if", "err", "=", "syscall", ".", "SetsockoptInt", "(", "fd", ",", "syscall", ".", "SOL_SOCKET", ",", "reusePort", ",", "1", ")", ";", "err", "!=", "nil", "{", "syscall", ".", "Close", "(", "fd", ")", "\n", "return", "nil", ",", "err", "\n", "}", "\n\n", "if", "err", "=", "syscall", ".", "Bind", "(", "fd", ",", "sockaddr", ")", ";", "err", "!=", "nil", "{", "syscall", ".", "Close", "(", "fd", ")", "\n", "return", "nil", ",", "err", "\n", "}", "\n\n", "// Set backlog size to the maximum", "if", "err", "=", "syscall", ".", "Listen", "(", "fd", ",", "listenerBacklogMaxSize", ")", ";", "err", "!=", "nil", "{", "syscall", ".", "Close", "(", "fd", ")", "\n", "return", "nil", ",", "err", "\n", "}", "\n\n", "file", "=", "os", ".", "NewFile", "(", "uintptr", "(", "fd", ")", ",", "getSocketFileName", "(", "proto", ",", "addr", ")", ")", "\n", "if", "l", ",", "err", "=", "net", ".", "FileListener", "(", "file", ")", ";", "err", "!=", "nil", "{", "file", ".", "Close", "(", ")", "\n", "return", "nil", ",", "err", "\n", "}", "\n\n", "if", "err", "=", "file", ".", "Close", "(", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "l", ",", "err", "\n", "}" ]
// NewReusablePortListener returns net.FileListener that created from // a file discriptor for a socket with SO_REUSEPORT option.
[ "NewReusablePortListener", "returns", "net", ".", "FileListener", "that", "created", "from", "a", "file", "discriptor", "for", "a", "socket", "with", "SO_REUSEPORT", "option", "." ]
1f6171f327ed3893406d2a802c563390993c4bb5
https://github.com/kavu/go_reuseport/blob/1f6171f327ed3893406d2a802c563390993c4bb5/tcp.go#L96-L147
train
sohlich/elogrus
hook.go
Fire
func (hook *ElasticHook) Fire(entry *logrus.Entry) error { return hook.fireFunc(entry, hook, hook.index()) }
go
func (hook *ElasticHook) Fire(entry *logrus.Entry) error { return hook.fireFunc(entry, hook, hook.index()) }
[ "func", "(", "hook", "*", "ElasticHook", ")", "Fire", "(", "entry", "*", "logrus", ".", "Entry", ")", "error", "{", "return", "hook", ".", "fireFunc", "(", "entry", ",", "hook", ",", "hook", ".", "index", "(", ")", ")", "\n", "}" ]
// Fire is required to implement // Logrus hook
[ "Fire", "is", "required", "to", "implement", "Logrus", "hook" ]
1fa29e2f2009c129693c7079e5f6361bfbd34080
https://github.com/sohlich/elogrus/blob/1fa29e2f2009c129693c7079e5f6361bfbd34080/hook.go#L125-L127
train
adrianmo/go-nmea
parser.go
AssertType
func (p *parser) AssertType(typ string) { if p.Type != typ { p.SetErr("type", p.Type) } }
go
func (p *parser) AssertType(typ string) { if p.Type != typ { p.SetErr("type", p.Type) } }
[ "func", "(", "p", "*", "parser", ")", "AssertType", "(", "typ", "string", ")", "{", "if", "p", ".", "Type", "!=", "typ", "{", "p", ".", "SetErr", "(", "\"", "\"", ",", "p", ".", "Type", ")", "\n", "}", "\n", "}" ]
// AssertType makes sure the sentence's type matches the provided one.
[ "AssertType", "makes", "sure", "the", "sentence", "s", "type", "matches", "the", "provided", "one", "." ]
7572fbeb90aaa0bd3d1dcb674938ffbc0a943123
https://github.com/adrianmo/go-nmea/blob/7572fbeb90aaa0bd3d1dcb674938ffbc0a943123/parser.go#L21-L25
train
adrianmo/go-nmea
parser.go
SetErr
func (p *parser) SetErr(context, value string) { if p.err == nil { p.err = fmt.Errorf("nmea: %s invalid %s: %s", p.Prefix(), context, value) } }
go
func (p *parser) SetErr(context, value string) { if p.err == nil { p.err = fmt.Errorf("nmea: %s invalid %s: %s", p.Prefix(), context, value) } }
[ "func", "(", "p", "*", "parser", ")", "SetErr", "(", "context", ",", "value", "string", ")", "{", "if", "p", ".", "err", "==", "nil", "{", "p", ".", "err", "=", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "p", ".", "Prefix", "(", ")", ",", "context", ",", "value", ")", "\n", "}", "\n", "}" ]
// SetErr assigns an error. Calling this method has no // effect if there is already an error.
[ "SetErr", "assigns", "an", "error", ".", "Calling", "this", "method", "has", "no", "effect", "if", "there", "is", "already", "an", "error", "." ]
7572fbeb90aaa0bd3d1dcb674938ffbc0a943123
https://github.com/adrianmo/go-nmea/blob/7572fbeb90aaa0bd3d1dcb674938ffbc0a943123/parser.go#L34-L38
train
adrianmo/go-nmea
parser.go
String
func (p *parser) String(i int, context string) string { if p.err != nil { return "" } if i < 0 || i >= len(p.Fields) { p.SetErr(context, "index out of range") return "" } return p.Fields[i] }
go
func (p *parser) String(i int, context string) string { if p.err != nil { return "" } if i < 0 || i >= len(p.Fields) { p.SetErr(context, "index out of range") return "" } return p.Fields[i] }
[ "func", "(", "p", "*", "parser", ")", "String", "(", "i", "int", ",", "context", "string", ")", "string", "{", "if", "p", ".", "err", "!=", "nil", "{", "return", "\"", "\"", "\n", "}", "\n", "if", "i", "<", "0", "||", "i", ">=", "len", "(", "p", ".", "Fields", ")", "{", "p", ".", "SetErr", "(", "context", ",", "\"", "\"", ")", "\n", "return", "\"", "\"", "\n", "}", "\n", "return", "p", ".", "Fields", "[", "i", "]", "\n", "}" ]
// String returns the field value at the specified index.
[ "String", "returns", "the", "field", "value", "at", "the", "specified", "index", "." ]
7572fbeb90aaa0bd3d1dcb674938ffbc0a943123
https://github.com/adrianmo/go-nmea/blob/7572fbeb90aaa0bd3d1dcb674938ffbc0a943123/parser.go#L41-L50
train
adrianmo/go-nmea
parser.go
EnumString
func (p *parser) EnumString(i int, context string, options ...string) string { s := p.String(i, context) if p.err != nil || s == "" { return "" } for _, o := range options { if o == s { return s } } p.SetErr(context, s) return "" }
go
func (p *parser) EnumString(i int, context string, options ...string) string { s := p.String(i, context) if p.err != nil || s == "" { return "" } for _, o := range options { if o == s { return s } } p.SetErr(context, s) return "" }
[ "func", "(", "p", "*", "parser", ")", "EnumString", "(", "i", "int", ",", "context", "string", ",", "options", "...", "string", ")", "string", "{", "s", ":=", "p", ".", "String", "(", "i", ",", "context", ")", "\n", "if", "p", ".", "err", "!=", "nil", "||", "s", "==", "\"", "\"", "{", "return", "\"", "\"", "\n", "}", "\n", "for", "_", ",", "o", ":=", "range", "options", "{", "if", "o", "==", "s", "{", "return", "s", "\n", "}", "\n", "}", "\n", "p", ".", "SetErr", "(", "context", ",", "s", ")", "\n", "return", "\"", "\"", "\n", "}" ]
// EnumString returns the field value at the specified index. // An error occurs if the value is not one of the options and not empty.
[ "EnumString", "returns", "the", "field", "value", "at", "the", "specified", "index", ".", "An", "error", "occurs", "if", "the", "value", "is", "not", "one", "of", "the", "options", "and", "not", "empty", "." ]
7572fbeb90aaa0bd3d1dcb674938ffbc0a943123
https://github.com/adrianmo/go-nmea/blob/7572fbeb90aaa0bd3d1dcb674938ffbc0a943123/parser.go#L54-L66
train
adrianmo/go-nmea
parser.go
EnumChars
func (p *parser) EnumChars(i int, context string, options ...string) []string { s := p.String(i, context) if p.err != nil || s == "" { return []string{} } strs := []string{} for _, r := range s { rs := string(r) for _, o := range options { if o == rs { strs = append(strs, o) break } } } if len(strs) != len(s) { p.SetErr(context, s) return []string{} } return strs }
go
func (p *parser) EnumChars(i int, context string, options ...string) []string { s := p.String(i, context) if p.err != nil || s == "" { return []string{} } strs := []string{} for _, r := range s { rs := string(r) for _, o := range options { if o == rs { strs = append(strs, o) break } } } if len(strs) != len(s) { p.SetErr(context, s) return []string{} } return strs }
[ "func", "(", "p", "*", "parser", ")", "EnumChars", "(", "i", "int", ",", "context", "string", ",", "options", "...", "string", ")", "[", "]", "string", "{", "s", ":=", "p", ".", "String", "(", "i", ",", "context", ")", "\n", "if", "p", ".", "err", "!=", "nil", "||", "s", "==", "\"", "\"", "{", "return", "[", "]", "string", "{", "}", "\n", "}", "\n", "strs", ":=", "[", "]", "string", "{", "}", "\n", "for", "_", ",", "r", ":=", "range", "s", "{", "rs", ":=", "string", "(", "r", ")", "\n", "for", "_", ",", "o", ":=", "range", "options", "{", "if", "o", "==", "rs", "{", "strs", "=", "append", "(", "strs", ",", "o", ")", "\n", "break", "\n", "}", "\n", "}", "\n", "}", "\n", "if", "len", "(", "strs", ")", "!=", "len", "(", "s", ")", "{", "p", ".", "SetErr", "(", "context", ",", "s", ")", "\n", "return", "[", "]", "string", "{", "}", "\n", "}", "\n", "return", "strs", "\n", "}" ]
// EnumChars returns an array of strings that are matched in the Mode field. // It will only match the number of characters that are in the Mode field. // If the value is empty, it will return an empty array
[ "EnumChars", "returns", "an", "array", "of", "strings", "that", "are", "matched", "in", "the", "Mode", "field", ".", "It", "will", "only", "match", "the", "number", "of", "characters", "that", "are", "in", "the", "Mode", "field", ".", "If", "the", "value", "is", "empty", "it", "will", "return", "an", "empty", "array" ]
7572fbeb90aaa0bd3d1dcb674938ffbc0a943123
https://github.com/adrianmo/go-nmea/blob/7572fbeb90aaa0bd3d1dcb674938ffbc0a943123/parser.go#L71-L92
train
adrianmo/go-nmea
parser.go
Int64
func (p *parser) Int64(i int, context string) int64 { s := p.String(i, context) if p.err != nil { return 0 } if s == "" { return 0 } v, err := strconv.ParseInt(s, 10, 64) if err != nil { p.SetErr(context, s) } return v }
go
func (p *parser) Int64(i int, context string) int64 { s := p.String(i, context) if p.err != nil { return 0 } if s == "" { return 0 } v, err := strconv.ParseInt(s, 10, 64) if err != nil { p.SetErr(context, s) } return v }
[ "func", "(", "p", "*", "parser", ")", "Int64", "(", "i", "int", ",", "context", "string", ")", "int64", "{", "s", ":=", "p", ".", "String", "(", "i", ",", "context", ")", "\n", "if", "p", ".", "err", "!=", "nil", "{", "return", "0", "\n", "}", "\n", "if", "s", "==", "\"", "\"", "{", "return", "0", "\n", "}", "\n", "v", ",", "err", ":=", "strconv", ".", "ParseInt", "(", "s", ",", "10", ",", "64", ")", "\n", "if", "err", "!=", "nil", "{", "p", ".", "SetErr", "(", "context", ",", "s", ")", "\n", "}", "\n", "return", "v", "\n", "}" ]
// Int64 returns the int64 value at the specified index. // If the value is an empty string, 0 is returned.
[ "Int64", "returns", "the", "int64", "value", "at", "the", "specified", "index", ".", "If", "the", "value", "is", "an", "empty", "string", "0", "is", "returned", "." ]
7572fbeb90aaa0bd3d1dcb674938ffbc0a943123
https://github.com/adrianmo/go-nmea/blob/7572fbeb90aaa0bd3d1dcb674938ffbc0a943123/parser.go#L96-L109
train
adrianmo/go-nmea
parser.go
Float64
func (p *parser) Float64(i int, context string) float64 { s := p.String(i, context) if p.err != nil { return 0 } if s == "" { return 0 } v, err := strconv.ParseFloat(s, 64) if err != nil { p.SetErr(context, s) } return v }
go
func (p *parser) Float64(i int, context string) float64 { s := p.String(i, context) if p.err != nil { return 0 } if s == "" { return 0 } v, err := strconv.ParseFloat(s, 64) if err != nil { p.SetErr(context, s) } return v }
[ "func", "(", "p", "*", "parser", ")", "Float64", "(", "i", "int", ",", "context", "string", ")", "float64", "{", "s", ":=", "p", ".", "String", "(", "i", ",", "context", ")", "\n", "if", "p", ".", "err", "!=", "nil", "{", "return", "0", "\n", "}", "\n", "if", "s", "==", "\"", "\"", "{", "return", "0", "\n", "}", "\n", "v", ",", "err", ":=", "strconv", ".", "ParseFloat", "(", "s", ",", "64", ")", "\n", "if", "err", "!=", "nil", "{", "p", ".", "SetErr", "(", "context", ",", "s", ")", "\n", "}", "\n", "return", "v", "\n", "}" ]
// Float64 returns the float64 value at the specified index. // If the value is an empty string, 0 is returned.
[ "Float64", "returns", "the", "float64", "value", "at", "the", "specified", "index", ".", "If", "the", "value", "is", "an", "empty", "string", "0", "is", "returned", "." ]
7572fbeb90aaa0bd3d1dcb674938ffbc0a943123
https://github.com/adrianmo/go-nmea/blob/7572fbeb90aaa0bd3d1dcb674938ffbc0a943123/parser.go#L113-L126
train
adrianmo/go-nmea
parser.go
Time
func (p *parser) Time(i int, context string) Time { s := p.String(i, context) if p.err != nil { return Time{} } v, err := ParseTime(s) if err != nil { p.SetErr(context, s) } return v }
go
func (p *parser) Time(i int, context string) Time { s := p.String(i, context) if p.err != nil { return Time{} } v, err := ParseTime(s) if err != nil { p.SetErr(context, s) } return v }
[ "func", "(", "p", "*", "parser", ")", "Time", "(", "i", "int", ",", "context", "string", ")", "Time", "{", "s", ":=", "p", ".", "String", "(", "i", ",", "context", ")", "\n", "if", "p", ".", "err", "!=", "nil", "{", "return", "Time", "{", "}", "\n", "}", "\n", "v", ",", "err", ":=", "ParseTime", "(", "s", ")", "\n", "if", "err", "!=", "nil", "{", "p", ".", "SetErr", "(", "context", ",", "s", ")", "\n", "}", "\n", "return", "v", "\n", "}" ]
// Time returns the Time value at the specified index. // If the value is empty, the Time is marked as invalid.
[ "Time", "returns", "the", "Time", "value", "at", "the", "specified", "index", ".", "If", "the", "value", "is", "empty", "the", "Time", "is", "marked", "as", "invalid", "." ]
7572fbeb90aaa0bd3d1dcb674938ffbc0a943123
https://github.com/adrianmo/go-nmea/blob/7572fbeb90aaa0bd3d1dcb674938ffbc0a943123/parser.go#L130-L140
train
adrianmo/go-nmea
parser.go
Date
func (p *parser) Date(i int, context string) Date { s := p.String(i, context) if p.err != nil { return Date{} } v, err := ParseDate(s) if err != nil { p.SetErr(context, s) } return v }
go
func (p *parser) Date(i int, context string) Date { s := p.String(i, context) if p.err != nil { return Date{} } v, err := ParseDate(s) if err != nil { p.SetErr(context, s) } return v }
[ "func", "(", "p", "*", "parser", ")", "Date", "(", "i", "int", ",", "context", "string", ")", "Date", "{", "s", ":=", "p", ".", "String", "(", "i", ",", "context", ")", "\n", "if", "p", ".", "err", "!=", "nil", "{", "return", "Date", "{", "}", "\n", "}", "\n", "v", ",", "err", ":=", "ParseDate", "(", "s", ")", "\n", "if", "err", "!=", "nil", "{", "p", ".", "SetErr", "(", "context", ",", "s", ")", "\n", "}", "\n", "return", "v", "\n", "}" ]
// Date returns the Date value at the specified index. // If the value is empty, the Date is marked as invalid.
[ "Date", "returns", "the", "Date", "value", "at", "the", "specified", "index", ".", "If", "the", "value", "is", "empty", "the", "Date", "is", "marked", "as", "invalid", "." ]
7572fbeb90aaa0bd3d1dcb674938ffbc0a943123
https://github.com/adrianmo/go-nmea/blob/7572fbeb90aaa0bd3d1dcb674938ffbc0a943123/parser.go#L144-L154
train
adrianmo/go-nmea
parser.go
LatLong
func (p *parser) LatLong(i, j int, context string) float64 { a := p.String(i, context) b := p.String(j, context) if p.err != nil { return 0 } s := fmt.Sprintf("%s %s", a, b) v, err := ParseLatLong(s) if err != nil { p.SetErr(context, err.Error()) } return v }
go
func (p *parser) LatLong(i, j int, context string) float64 { a := p.String(i, context) b := p.String(j, context) if p.err != nil { return 0 } s := fmt.Sprintf("%s %s", a, b) v, err := ParseLatLong(s) if err != nil { p.SetErr(context, err.Error()) } return v }
[ "func", "(", "p", "*", "parser", ")", "LatLong", "(", "i", ",", "j", "int", ",", "context", "string", ")", "float64", "{", "a", ":=", "p", ".", "String", "(", "i", ",", "context", ")", "\n", "b", ":=", "p", ".", "String", "(", "j", ",", "context", ")", "\n", "if", "p", ".", "err", "!=", "nil", "{", "return", "0", "\n", "}", "\n", "s", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "a", ",", "b", ")", "\n", "v", ",", "err", ":=", "ParseLatLong", "(", "s", ")", "\n", "if", "err", "!=", "nil", "{", "p", ".", "SetErr", "(", "context", ",", "err", ".", "Error", "(", ")", ")", "\n", "}", "\n", "return", "v", "\n", "}" ]
// LatLong returns the coordinate value of the specified fields.
[ "LatLong", "returns", "the", "coordinate", "value", "of", "the", "specified", "fields", "." ]
7572fbeb90aaa0bd3d1dcb674938ffbc0a943123
https://github.com/adrianmo/go-nmea/blob/7572fbeb90aaa0bd3d1dcb674938ffbc0a943123/parser.go#L157-L169
train
adrianmo/go-nmea
parser.go
SixBitASCIIArmour
func (p *parser) SixBitASCIIArmour(i int, fillBits int, context string) []byte { if p.err != nil { return nil } if fillBits < 0 || fillBits >= 6 { p.SetErr(context, "fill bits") return nil } payload := []byte(p.String(i, "encoded payload")) numBits := len(payload)*6 - fillBits if numBits < 0 { p.SetErr(context, "num bits") return nil } result := make([]byte, numBits) resultIndex := 0 for _, v := range payload { if v < 48 || v >= 120 { p.SetErr(context, "data byte") return nil } d := v - 48 if d > 40 { d -= 8 } for i := 5; i >= 0 && resultIndex < len(result); i-- { result[resultIndex] = (d >> uint(i)) & 1 resultIndex++ } } return result }
go
func (p *parser) SixBitASCIIArmour(i int, fillBits int, context string) []byte { if p.err != nil { return nil } if fillBits < 0 || fillBits >= 6 { p.SetErr(context, "fill bits") return nil } payload := []byte(p.String(i, "encoded payload")) numBits := len(payload)*6 - fillBits if numBits < 0 { p.SetErr(context, "num bits") return nil } result := make([]byte, numBits) resultIndex := 0 for _, v := range payload { if v < 48 || v >= 120 { p.SetErr(context, "data byte") return nil } d := v - 48 if d > 40 { d -= 8 } for i := 5; i >= 0 && resultIndex < len(result); i-- { result[resultIndex] = (d >> uint(i)) & 1 resultIndex++ } } return result }
[ "func", "(", "p", "*", "parser", ")", "SixBitASCIIArmour", "(", "i", "int", ",", "fillBits", "int", ",", "context", "string", ")", "[", "]", "byte", "{", "if", "p", ".", "err", "!=", "nil", "{", "return", "nil", "\n", "}", "\n", "if", "fillBits", "<", "0", "||", "fillBits", ">=", "6", "{", "p", ".", "SetErr", "(", "context", ",", "\"", "\"", ")", "\n", "return", "nil", "\n", "}", "\n\n", "payload", ":=", "[", "]", "byte", "(", "p", ".", "String", "(", "i", ",", "\"", "\"", ")", ")", "\n", "numBits", ":=", "len", "(", "payload", ")", "*", "6", "-", "fillBits", "\n\n", "if", "numBits", "<", "0", "{", "p", ".", "SetErr", "(", "context", ",", "\"", "\"", ")", "\n", "return", "nil", "\n", "}", "\n\n", "result", ":=", "make", "(", "[", "]", "byte", ",", "numBits", ")", "\n", "resultIndex", ":=", "0", "\n\n", "for", "_", ",", "v", ":=", "range", "payload", "{", "if", "v", "<", "48", "||", "v", ">=", "120", "{", "p", ".", "SetErr", "(", "context", ",", "\"", "\"", ")", "\n", "return", "nil", "\n", "}", "\n\n", "d", ":=", "v", "-", "48", "\n", "if", "d", ">", "40", "{", "d", "-=", "8", "\n", "}", "\n\n", "for", "i", ":=", "5", ";", "i", ">=", "0", "&&", "resultIndex", "<", "len", "(", "result", ")", ";", "i", "--", "{", "result", "[", "resultIndex", "]", "=", "(", "d", ">>", "uint", "(", "i", ")", ")", "&", "1", "\n", "resultIndex", "++", "\n", "}", "\n", "}", "\n\n", "return", "result", "\n", "}" ]
// SixBitASCIIArmour decodes the 6-bit ascii armor used for VDM and VDO messages
[ "SixBitASCIIArmour", "decodes", "the", "6", "-", "bit", "ascii", "armor", "used", "for", "VDM", "and", "VDO", "messages" ]
7572fbeb90aaa0bd3d1dcb674938ffbc0a943123
https://github.com/adrianmo/go-nmea/blob/7572fbeb90aaa0bd3d1dcb674938ffbc0a943123/parser.go#L172-L210
train
adrianmo/go-nmea
gsa.go
newGSA
func newGSA(s BaseSentence) (GSA, error) { p := newParser(s) p.AssertType(TypeGSA) m := GSA{ BaseSentence: s, Mode: p.EnumString(0, "selection mode", Auto, Manual), FixType: p.EnumString(1, "fix type", FixNone, Fix2D, Fix3D), } // Satellites in view. for i := 2; i < 14; i++ { if v := p.String(i, "satellite in view"); v != "" { m.SV = append(m.SV, v) } } // Dilution of precision. m.PDOP = p.Float64(14, "pdop") m.HDOP = p.Float64(15, "hdop") m.VDOP = p.Float64(16, "vdop") return m, p.Err() }
go
func newGSA(s BaseSentence) (GSA, error) { p := newParser(s) p.AssertType(TypeGSA) m := GSA{ BaseSentence: s, Mode: p.EnumString(0, "selection mode", Auto, Manual), FixType: p.EnumString(1, "fix type", FixNone, Fix2D, Fix3D), } // Satellites in view. for i := 2; i < 14; i++ { if v := p.String(i, "satellite in view"); v != "" { m.SV = append(m.SV, v) } } // Dilution of precision. m.PDOP = p.Float64(14, "pdop") m.HDOP = p.Float64(15, "hdop") m.VDOP = p.Float64(16, "vdop") return m, p.Err() }
[ "func", "newGSA", "(", "s", "BaseSentence", ")", "(", "GSA", ",", "error", ")", "{", "p", ":=", "newParser", "(", "s", ")", "\n", "p", ".", "AssertType", "(", "TypeGSA", ")", "\n", "m", ":=", "GSA", "{", "BaseSentence", ":", "s", ",", "Mode", ":", "p", ".", "EnumString", "(", "0", ",", "\"", "\"", ",", "Auto", ",", "Manual", ")", ",", "FixType", ":", "p", ".", "EnumString", "(", "1", ",", "\"", "\"", ",", "FixNone", ",", "Fix2D", ",", "Fix3D", ")", ",", "}", "\n", "// Satellites in view.", "for", "i", ":=", "2", ";", "i", "<", "14", ";", "i", "++", "{", "if", "v", ":=", "p", ".", "String", "(", "i", ",", "\"", "\"", ")", ";", "v", "!=", "\"", "\"", "{", "m", ".", "SV", "=", "append", "(", "m", ".", "SV", ",", "v", ")", "\n", "}", "\n", "}", "\n", "// Dilution of precision.", "m", ".", "PDOP", "=", "p", ".", "Float64", "(", "14", ",", "\"", "\"", ")", "\n", "m", ".", "HDOP", "=", "p", ".", "Float64", "(", "15", ",", "\"", "\"", ")", "\n", "m", ".", "VDOP", "=", "p", ".", "Float64", "(", "16", ",", "\"", "\"", ")", "\n", "return", "m", ",", "p", ".", "Err", "(", ")", "\n", "}" ]
// newGSA parses the GSA sentence into this struct.
[ "newGSA", "parses", "the", "GSA", "sentence", "into", "this", "struct", "." ]
7572fbeb90aaa0bd3d1dcb674938ffbc0a943123
https://github.com/adrianmo/go-nmea/blob/7572fbeb90aaa0bd3d1dcb674938ffbc0a943123/gsa.go#L31-L50
train
adrianmo/go-nmea
sentence.go
parseSentence
func parseSentence(raw string) (BaseSentence, error) { startIndex := strings.IndexAny(raw, SentenceStart+SentenceStartEncapsulated) if startIndex != 0 { return BaseSentence{}, fmt.Errorf("nmea: sentence does not start with a '$' or '!'") } sumSepIndex := strings.Index(raw, ChecksumSep) if sumSepIndex == -1 { return BaseSentence{}, fmt.Errorf("nmea: sentence does not contain checksum separator") } var ( fieldsRaw = raw[startIndex+1 : sumSepIndex] fields = strings.Split(fieldsRaw, FieldSep) checksumRaw = strings.ToUpper(raw[sumSepIndex+1:]) checksum = xorChecksum(fieldsRaw) ) // Validate the checksum if checksum != checksumRaw { return BaseSentence{}, fmt.Errorf( "nmea: sentence checksum mismatch [%s != %s]", checksum, checksumRaw) } talker, typ := parsePrefix(fields[0]) return BaseSentence{ Talker: talker, Type: typ, Fields: fields[1:], Checksum: checksumRaw, Raw: raw, }, nil }
go
func parseSentence(raw string) (BaseSentence, error) { startIndex := strings.IndexAny(raw, SentenceStart+SentenceStartEncapsulated) if startIndex != 0 { return BaseSentence{}, fmt.Errorf("nmea: sentence does not start with a '$' or '!'") } sumSepIndex := strings.Index(raw, ChecksumSep) if sumSepIndex == -1 { return BaseSentence{}, fmt.Errorf("nmea: sentence does not contain checksum separator") } var ( fieldsRaw = raw[startIndex+1 : sumSepIndex] fields = strings.Split(fieldsRaw, FieldSep) checksumRaw = strings.ToUpper(raw[sumSepIndex+1:]) checksum = xorChecksum(fieldsRaw) ) // Validate the checksum if checksum != checksumRaw { return BaseSentence{}, fmt.Errorf( "nmea: sentence checksum mismatch [%s != %s]", checksum, checksumRaw) } talker, typ := parsePrefix(fields[0]) return BaseSentence{ Talker: talker, Type: typ, Fields: fields[1:], Checksum: checksumRaw, Raw: raw, }, nil }
[ "func", "parseSentence", "(", "raw", "string", ")", "(", "BaseSentence", ",", "error", ")", "{", "startIndex", ":=", "strings", ".", "IndexAny", "(", "raw", ",", "SentenceStart", "+", "SentenceStartEncapsulated", ")", "\n", "if", "startIndex", "!=", "0", "{", "return", "BaseSentence", "{", "}", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n", "sumSepIndex", ":=", "strings", ".", "Index", "(", "raw", ",", "ChecksumSep", ")", "\n", "if", "sumSepIndex", "==", "-", "1", "{", "return", "BaseSentence", "{", "}", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n", "var", "(", "fieldsRaw", "=", "raw", "[", "startIndex", "+", "1", ":", "sumSepIndex", "]", "\n", "fields", "=", "strings", ".", "Split", "(", "fieldsRaw", ",", "FieldSep", ")", "\n", "checksumRaw", "=", "strings", ".", "ToUpper", "(", "raw", "[", "sumSepIndex", "+", "1", ":", "]", ")", "\n", "checksum", "=", "xorChecksum", "(", "fieldsRaw", ")", "\n", ")", "\n", "// Validate the checksum", "if", "checksum", "!=", "checksumRaw", "{", "return", "BaseSentence", "{", "}", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "checksum", ",", "checksumRaw", ")", "\n", "}", "\n", "talker", ",", "typ", ":=", "parsePrefix", "(", "fields", "[", "0", "]", ")", "\n", "return", "BaseSentence", "{", "Talker", ":", "talker", ",", "Type", ":", "typ", ",", "Fields", ":", "fields", "[", "1", ":", "]", ",", "Checksum", ":", "checksumRaw", ",", "Raw", ":", "raw", ",", "}", ",", "nil", "\n", "}" ]
// parseSentence parses a raw message into it's fields
[ "parseSentence", "parses", "a", "raw", "message", "into", "it", "s", "fields" ]
7572fbeb90aaa0bd3d1dcb674938ffbc0a943123
https://github.com/adrianmo/go-nmea/blob/7572fbeb90aaa0bd3d1dcb674938ffbc0a943123/sentence.go#L58-L86
train
adrianmo/go-nmea
sentence.go
parsePrefix
func parsePrefix(s string) (string, string) { if strings.HasPrefix(s, "P") { return "P", s[1:] } if len(s) < 2 { return s, "" } return s[:2], s[2:] }
go
func parsePrefix(s string) (string, string) { if strings.HasPrefix(s, "P") { return "P", s[1:] } if len(s) < 2 { return s, "" } return s[:2], s[2:] }
[ "func", "parsePrefix", "(", "s", "string", ")", "(", "string", ",", "string", ")", "{", "if", "strings", ".", "HasPrefix", "(", "s", ",", "\"", "\"", ")", "{", "return", "\"", "\"", ",", "s", "[", "1", ":", "]", "\n", "}", "\n", "if", "len", "(", "s", ")", "<", "2", "{", "return", "s", ",", "\"", "\"", "\n", "}", "\n", "return", "s", "[", ":", "2", "]", ",", "s", "[", "2", ":", "]", "\n", "}" ]
// parsePrefix takes the first field and splits it into a talker id and data type.
[ "parsePrefix", "takes", "the", "first", "field", "and", "splits", "it", "into", "a", "talker", "id", "and", "data", "type", "." ]
7572fbeb90aaa0bd3d1dcb674938ffbc0a943123
https://github.com/adrianmo/go-nmea/blob/7572fbeb90aaa0bd3d1dcb674938ffbc0a943123/sentence.go#L89-L97
train
adrianmo/go-nmea
sentence.go
xorChecksum
func xorChecksum(s string) string { var checksum uint8 for i := 0; i < len(s); i++ { checksum ^= s[i] } return fmt.Sprintf("%02X", checksum) }
go
func xorChecksum(s string) string { var checksum uint8 for i := 0; i < len(s); i++ { checksum ^= s[i] } return fmt.Sprintf("%02X", checksum) }
[ "func", "xorChecksum", "(", "s", "string", ")", "string", "{", "var", "checksum", "uint8", "\n", "for", "i", ":=", "0", ";", "i", "<", "len", "(", "s", ")", ";", "i", "++", "{", "checksum", "^=", "s", "[", "i", "]", "\n", "}", "\n", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "checksum", ")", "\n", "}" ]
// xor all the bytes in a string an return it // as an uppercase hex string
[ "xor", "all", "the", "bytes", "in", "a", "string", "an", "return", "it", "as", "an", "uppercase", "hex", "string" ]
7572fbeb90aaa0bd3d1dcb674938ffbc0a943123
https://github.com/adrianmo/go-nmea/blob/7572fbeb90aaa0bd3d1dcb674938ffbc0a943123/sentence.go#L101-L107
train
adrianmo/go-nmea
sentence.go
Parse
func Parse(raw string) (Sentence, error) { s, err := parseSentence(raw) if err != nil { return nil, err } if strings.HasPrefix(s.Raw, SentenceStart) { switch s.Type { case TypeRMC: return newRMC(s) case TypeGGA: return newGGA(s) case TypeGSA: return newGSA(s) case TypeGLL: return newGLL(s) case TypeVTG: return newVTG(s) case TypeZDA: return newZDA(s) case TypePGRME: return newPGRME(s) case TypeGSV: return newGSV(s) case TypeHDT: return newHDT(s) case TypeGNS: return newGNS(s) case TypeTHS: return newTHS(s) } } if strings.HasPrefix(s.Raw, SentenceStartEncapsulated) { switch s.Type { case TypeVDM, TypeVDO: return newVDMVDO(s) } } return nil, fmt.Errorf("nmea: sentence prefix '%s' not supported", s.Prefix()) }
go
func Parse(raw string) (Sentence, error) { s, err := parseSentence(raw) if err != nil { return nil, err } if strings.HasPrefix(s.Raw, SentenceStart) { switch s.Type { case TypeRMC: return newRMC(s) case TypeGGA: return newGGA(s) case TypeGSA: return newGSA(s) case TypeGLL: return newGLL(s) case TypeVTG: return newVTG(s) case TypeZDA: return newZDA(s) case TypePGRME: return newPGRME(s) case TypeGSV: return newGSV(s) case TypeHDT: return newHDT(s) case TypeGNS: return newGNS(s) case TypeTHS: return newTHS(s) } } if strings.HasPrefix(s.Raw, SentenceStartEncapsulated) { switch s.Type { case TypeVDM, TypeVDO: return newVDMVDO(s) } } return nil, fmt.Errorf("nmea: sentence prefix '%s' not supported", s.Prefix()) }
[ "func", "Parse", "(", "raw", "string", ")", "(", "Sentence", ",", "error", ")", "{", "s", ",", "err", ":=", "parseSentence", "(", "raw", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "if", "strings", ".", "HasPrefix", "(", "s", ".", "Raw", ",", "SentenceStart", ")", "{", "switch", "s", ".", "Type", "{", "case", "TypeRMC", ":", "return", "newRMC", "(", "s", ")", "\n", "case", "TypeGGA", ":", "return", "newGGA", "(", "s", ")", "\n", "case", "TypeGSA", ":", "return", "newGSA", "(", "s", ")", "\n", "case", "TypeGLL", ":", "return", "newGLL", "(", "s", ")", "\n", "case", "TypeVTG", ":", "return", "newVTG", "(", "s", ")", "\n", "case", "TypeZDA", ":", "return", "newZDA", "(", "s", ")", "\n", "case", "TypePGRME", ":", "return", "newPGRME", "(", "s", ")", "\n", "case", "TypeGSV", ":", "return", "newGSV", "(", "s", ")", "\n", "case", "TypeHDT", ":", "return", "newHDT", "(", "s", ")", "\n", "case", "TypeGNS", ":", "return", "newGNS", "(", "s", ")", "\n", "case", "TypeTHS", ":", "return", "newTHS", "(", "s", ")", "\n", "}", "\n", "}", "\n", "if", "strings", ".", "HasPrefix", "(", "s", ".", "Raw", ",", "SentenceStartEncapsulated", ")", "{", "switch", "s", ".", "Type", "{", "case", "TypeVDM", ",", "TypeVDO", ":", "return", "newVDMVDO", "(", "s", ")", "\n", "}", "\n", "}", "\n", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "s", ".", "Prefix", "(", ")", ")", "\n", "}" ]
// Parse parses the given string into the correct sentence type.
[ "Parse", "parses", "the", "given", "string", "into", "the", "correct", "sentence", "type", "." ]
7572fbeb90aaa0bd3d1dcb674938ffbc0a943123
https://github.com/adrianmo/go-nmea/blob/7572fbeb90aaa0bd3d1dcb674938ffbc0a943123/sentence.go#L110-L148
train
adrianmo/go-nmea
types.go
FormatDMS
func FormatDMS(l float64) string { val := math.Abs(l) degrees := int(math.Floor(val)) minutes := int(math.Floor(60 * (val - float64(degrees)))) seconds := 3600 * (val - float64(degrees) - (float64(minutes) / 60)) return fmt.Sprintf("%d\u00B0 %d' %f\"", degrees, minutes, seconds) }
go
func FormatDMS(l float64) string { val := math.Abs(l) degrees := int(math.Floor(val)) minutes := int(math.Floor(60 * (val - float64(degrees)))) seconds := 3600 * (val - float64(degrees) - (float64(minutes) / 60)) return fmt.Sprintf("%d\u00B0 %d' %f\"", degrees, minutes, seconds) }
[ "func", "FormatDMS", "(", "l", "float64", ")", "string", "{", "val", ":=", "math", ".", "Abs", "(", "l", ")", "\n", "degrees", ":=", "int", "(", "math", ".", "Floor", "(", "val", ")", ")", "\n", "minutes", ":=", "int", "(", "math", ".", "Floor", "(", "60", "*", "(", "val", "-", "float64", "(", "degrees", ")", ")", ")", ")", "\n", "seconds", ":=", "3600", "*", "(", "val", "-", "float64", "(", "degrees", ")", "-", "(", "float64", "(", "minutes", ")", "/", "60", ")", ")", "\n", "return", "fmt", ".", "Sprintf", "(", "\"", "\\u00B0", "\\\"", "\"", ",", "degrees", ",", "minutes", ",", "seconds", ")", "\n", "}" ]
// FormatDMS returns the degrees, minutes, seconds format for the given LatLong.
[ "FormatDMS", "returns", "the", "degrees", "minutes", "seconds", "format", "for", "the", "given", "LatLong", "." ]
7572fbeb90aaa0bd3d1dcb674938ffbc0a943123
https://github.com/adrianmo/go-nmea/blob/7572fbeb90aaa0bd3d1dcb674938ffbc0a943123/types.go#L160-L166
train
adrianmo/go-nmea
types.go
String
func (t Time) String() string { seconds := float64(t.Second) + float64(t.Millisecond)/1000 return fmt.Sprintf("%02d:%02d:%07.4f", t.Hour, t.Minute, seconds) }
go
func (t Time) String() string { seconds := float64(t.Second) + float64(t.Millisecond)/1000 return fmt.Sprintf("%02d:%02d:%07.4f", t.Hour, t.Minute, seconds) }
[ "func", "(", "t", "Time", ")", "String", "(", ")", "string", "{", "seconds", ":=", "float64", "(", "t", ".", "Second", ")", "+", "float64", "(", "t", ".", "Millisecond", ")", "/", "1000", "\n", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "t", ".", "Hour", ",", "t", ".", "Minute", ",", "seconds", ")", "\n", "}" ]
// String representation of Time
[ "String", "representation", "of", "Time" ]
7572fbeb90aaa0bd3d1dcb674938ffbc0a943123
https://github.com/adrianmo/go-nmea/blob/7572fbeb90aaa0bd3d1dcb674938ffbc0a943123/types.go#L178-L181
train
adrianmo/go-nmea
types.go
String
func (d Date) String() string { return fmt.Sprintf("%02d/%02d/%02d", d.DD, d.MM, d.YY) }
go
func (d Date) String() string { return fmt.Sprintf("%02d/%02d/%02d", d.DD, d.MM, d.YY) }
[ "func", "(", "d", "Date", ")", "String", "(", ")", "string", "{", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "d", ".", "DD", ",", "d", ".", "MM", ",", "d", ".", "YY", ")", "\n", "}" ]
// String representation of date
[ "String", "representation", "of", "date" ]
7572fbeb90aaa0bd3d1dcb674938ffbc0a943123
https://github.com/adrianmo/go-nmea/blob/7572fbeb90aaa0bd3d1dcb674938ffbc0a943123/types.go#L223-L225
train
adrianmo/go-nmea
types.go
ParseDate
func ParseDate(ddmmyy string) (Date, error) { if ddmmyy == "" { return Date{}, nil } if len(ddmmyy) != 6 { return Date{}, fmt.Errorf("parse date: exptected ddmmyy format, got '%s'", ddmmyy) } dd, err := strconv.Atoi(ddmmyy[0:2]) if err != nil { return Date{}, errors.New(ddmmyy) } mm, err := strconv.Atoi(ddmmyy[2:4]) if err != nil { return Date{}, errors.New(ddmmyy) } yy, err := strconv.Atoi(ddmmyy[4:6]) if err != nil { return Date{}, errors.New(ddmmyy) } return Date{true, dd, mm, yy}, nil }
go
func ParseDate(ddmmyy string) (Date, error) { if ddmmyy == "" { return Date{}, nil } if len(ddmmyy) != 6 { return Date{}, fmt.Errorf("parse date: exptected ddmmyy format, got '%s'", ddmmyy) } dd, err := strconv.Atoi(ddmmyy[0:2]) if err != nil { return Date{}, errors.New(ddmmyy) } mm, err := strconv.Atoi(ddmmyy[2:4]) if err != nil { return Date{}, errors.New(ddmmyy) } yy, err := strconv.Atoi(ddmmyy[4:6]) if err != nil { return Date{}, errors.New(ddmmyy) } return Date{true, dd, mm, yy}, nil }
[ "func", "ParseDate", "(", "ddmmyy", "string", ")", "(", "Date", ",", "error", ")", "{", "if", "ddmmyy", "==", "\"", "\"", "{", "return", "Date", "{", "}", ",", "nil", "\n", "}", "\n", "if", "len", "(", "ddmmyy", ")", "!=", "6", "{", "return", "Date", "{", "}", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "ddmmyy", ")", "\n", "}", "\n", "dd", ",", "err", ":=", "strconv", ".", "Atoi", "(", "ddmmyy", "[", "0", ":", "2", "]", ")", "\n", "if", "err", "!=", "nil", "{", "return", "Date", "{", "}", ",", "errors", ".", "New", "(", "ddmmyy", ")", "\n", "}", "\n", "mm", ",", "err", ":=", "strconv", ".", "Atoi", "(", "ddmmyy", "[", "2", ":", "4", "]", ")", "\n", "if", "err", "!=", "nil", "{", "return", "Date", "{", "}", ",", "errors", ".", "New", "(", "ddmmyy", ")", "\n", "}", "\n", "yy", ",", "err", ":=", "strconv", ".", "Atoi", "(", "ddmmyy", "[", "4", ":", "6", "]", ")", "\n", "if", "err", "!=", "nil", "{", "return", "Date", "{", "}", ",", "errors", ".", "New", "(", "ddmmyy", ")", "\n", "}", "\n", "return", "Date", "{", "true", ",", "dd", ",", "mm", ",", "yy", "}", ",", "nil", "\n", "}" ]
// ParseDate field ddmmyy format
[ "ParseDate", "field", "ddmmyy", "format" ]
7572fbeb90aaa0bd3d1dcb674938ffbc0a943123
https://github.com/adrianmo/go-nmea/blob/7572fbeb90aaa0bd3d1dcb674938ffbc0a943123/types.go#L228-L248
train
jessevdk/go-flags
group.go
Find
func (g *Group) Find(shortDescription string) *Group { lshortDescription := strings.ToLower(shortDescription) var ret *Group g.eachGroup(func(gg *Group) { if gg != g && strings.ToLower(gg.ShortDescription) == lshortDescription { ret = gg } }) return ret }
go
func (g *Group) Find(shortDescription string) *Group { lshortDescription := strings.ToLower(shortDescription) var ret *Group g.eachGroup(func(gg *Group) { if gg != g && strings.ToLower(gg.ShortDescription) == lshortDescription { ret = gg } }) return ret }
[ "func", "(", "g", "*", "Group", ")", "Find", "(", "shortDescription", "string", ")", "*", "Group", "{", "lshortDescription", ":=", "strings", ".", "ToLower", "(", "shortDescription", ")", "\n\n", "var", "ret", "*", "Group", "\n\n", "g", ".", "eachGroup", "(", "func", "(", "gg", "*", "Group", ")", "{", "if", "gg", "!=", "g", "&&", "strings", ".", "ToLower", "(", "gg", ".", "ShortDescription", ")", "==", "lshortDescription", "{", "ret", "=", "gg", "\n", "}", "\n", "}", ")", "\n\n", "return", "ret", "\n", "}" ]
// Find locates the subgroup with the given short description and returns it. // If no such group can be found Find will return nil. Note that the description // is matched case insensitively.
[ "Find", "locates", "the", "subgroup", "with", "the", "given", "short", "description", "and", "returns", "it", ".", "If", "no", "such", "group", "can", "be", "found", "Find", "will", "return", "nil", ".", "Note", "that", "the", "description", "is", "matched", "case", "insensitively", "." ]
c0795c8afcf41dd1d786bebce68636c199b3bb45
https://github.com/jessevdk/go-flags/blob/c0795c8afcf41dd1d786bebce68636c199b3bb45/group.go#L89-L101
train
jessevdk/go-flags
group.go
FindOptionByShortName
func (g *Group) FindOptionByShortName(shortName rune) *Option { return g.findOption(func(option *Option) bool { return option.ShortName == shortName }) }
go
func (g *Group) FindOptionByShortName(shortName rune) *Option { return g.findOption(func(option *Option) bool { return option.ShortName == shortName }) }
[ "func", "(", "g", "*", "Group", ")", "FindOptionByShortName", "(", "shortName", "rune", ")", "*", "Option", "{", "return", "g", ".", "findOption", "(", "func", "(", "option", "*", "Option", ")", "bool", "{", "return", "option", ".", "ShortName", "==", "shortName", "\n", "}", ")", "\n", "}" ]
// FindOptionByShortName finds an option that is part of the group, or any of // its subgroups, by matching its short name.
[ "FindOptionByShortName", "finds", "an", "option", "that", "is", "part", "of", "the", "group", "or", "any", "of", "its", "subgroups", "by", "matching", "its", "short", "name", "." ]
c0795c8afcf41dd1d786bebce68636c199b3bb45
https://github.com/jessevdk/go-flags/blob/c0795c8afcf41dd1d786bebce68636c199b3bb45/group.go#L125-L129
train
jessevdk/go-flags
man.go
WriteManPage
func (p *Parser) WriteManPage(wr io.Writer) { t := time.Now() source_date_epoch := os.Getenv("SOURCE_DATE_EPOCH") if source_date_epoch != "" { sde, err := strconv.ParseInt(source_date_epoch, 10, 64) if err != nil { panic(fmt.Sprintf("Invalid SOURCE_DATE_EPOCH: %s", err)) } t = time.Unix(sde, 0) } fmt.Fprintf(wr, ".TH %s 1 \"%s\"\n", manQuote(p.Name), t.Format("2 January 2006")) fmt.Fprintln(wr, ".SH NAME") fmt.Fprintf(wr, "%s \\- %s\n", manQuote(p.Name), manQuote(p.ShortDescription)) fmt.Fprintln(wr, ".SH SYNOPSIS") usage := p.Usage if len(usage) == 0 { usage = "[OPTIONS]" } fmt.Fprintf(wr, "\\fB%s\\fP %s\n", manQuote(p.Name), manQuote(usage)) fmt.Fprintln(wr, ".SH DESCRIPTION") formatForMan(wr, p.LongDescription) fmt.Fprintln(wr, "") fmt.Fprintln(wr, ".SH OPTIONS") writeManPageOptions(wr, p.Command.Group) if len(p.visibleCommands()) > 0 { fmt.Fprintln(wr, ".SH COMMANDS") writeManPageSubcommands(wr, "", p.Command) } }
go
func (p *Parser) WriteManPage(wr io.Writer) { t := time.Now() source_date_epoch := os.Getenv("SOURCE_DATE_EPOCH") if source_date_epoch != "" { sde, err := strconv.ParseInt(source_date_epoch, 10, 64) if err != nil { panic(fmt.Sprintf("Invalid SOURCE_DATE_EPOCH: %s", err)) } t = time.Unix(sde, 0) } fmt.Fprintf(wr, ".TH %s 1 \"%s\"\n", manQuote(p.Name), t.Format("2 January 2006")) fmt.Fprintln(wr, ".SH NAME") fmt.Fprintf(wr, "%s \\- %s\n", manQuote(p.Name), manQuote(p.ShortDescription)) fmt.Fprintln(wr, ".SH SYNOPSIS") usage := p.Usage if len(usage) == 0 { usage = "[OPTIONS]" } fmt.Fprintf(wr, "\\fB%s\\fP %s\n", manQuote(p.Name), manQuote(usage)) fmt.Fprintln(wr, ".SH DESCRIPTION") formatForMan(wr, p.LongDescription) fmt.Fprintln(wr, "") fmt.Fprintln(wr, ".SH OPTIONS") writeManPageOptions(wr, p.Command.Group) if len(p.visibleCommands()) > 0 { fmt.Fprintln(wr, ".SH COMMANDS") writeManPageSubcommands(wr, "", p.Command) } }
[ "func", "(", "p", "*", "Parser", ")", "WriteManPage", "(", "wr", "io", ".", "Writer", ")", "{", "t", ":=", "time", ".", "Now", "(", ")", "\n", "source_date_epoch", ":=", "os", ".", "Getenv", "(", "\"", "\"", ")", "\n", "if", "source_date_epoch", "!=", "\"", "\"", "{", "sde", ",", "err", ":=", "strconv", ".", "ParseInt", "(", "source_date_epoch", ",", "10", ",", "64", ")", "\n", "if", "err", "!=", "nil", "{", "panic", "(", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "err", ")", ")", "\n", "}", "\n", "t", "=", "time", ".", "Unix", "(", "sde", ",", "0", ")", "\n", "}", "\n\n", "fmt", ".", "Fprintf", "(", "wr", ",", "\"", "\\\"", "\\\"", "\\n", "\"", ",", "manQuote", "(", "p", ".", "Name", ")", ",", "t", ".", "Format", "(", "\"", "\"", ")", ")", "\n", "fmt", ".", "Fprintln", "(", "wr", ",", "\"", "\"", ")", "\n", "fmt", ".", "Fprintf", "(", "wr", ",", "\"", "\\\\", "\\n", "\"", ",", "manQuote", "(", "p", ".", "Name", ")", ",", "manQuote", "(", "p", ".", "ShortDescription", ")", ")", "\n", "fmt", ".", "Fprintln", "(", "wr", ",", "\"", "\"", ")", "\n\n", "usage", ":=", "p", ".", "Usage", "\n\n", "if", "len", "(", "usage", ")", "==", "0", "{", "usage", "=", "\"", "\"", "\n", "}", "\n\n", "fmt", ".", "Fprintf", "(", "wr", ",", "\"", "\\\\", "\\\\", "\\n", "\"", ",", "manQuote", "(", "p", ".", "Name", ")", ",", "manQuote", "(", "usage", ")", ")", "\n", "fmt", ".", "Fprintln", "(", "wr", ",", "\"", "\"", ")", "\n\n", "formatForMan", "(", "wr", ",", "p", ".", "LongDescription", ")", "\n", "fmt", ".", "Fprintln", "(", "wr", ",", "\"", "\"", ")", "\n\n", "fmt", ".", "Fprintln", "(", "wr", ",", "\"", "\"", ")", "\n\n", "writeManPageOptions", "(", "wr", ",", "p", ".", "Command", ".", "Group", ")", "\n\n", "if", "len", "(", "p", ".", "visibleCommands", "(", ")", ")", ">", "0", "{", "fmt", ".", "Fprintln", "(", "wr", ",", "\"", "\"", ")", "\n\n", "writeManPageSubcommands", "(", "wr", ",", "\"", "\"", ",", "p", ".", "Command", ")", "\n", "}", "\n", "}" ]
// WriteManPage writes a basic man page in groff format to the specified // writer.
[ "WriteManPage", "writes", "a", "basic", "man", "page", "in", "groff", "format", "to", "the", "specified", "writer", "." ]
c0795c8afcf41dd1d786bebce68636c199b3bb45
https://github.com/jessevdk/go-flags/blob/c0795c8afcf41dd1d786bebce68636c199b3bb45/man.go#L178-L215
train
jessevdk/go-flags
parser.go
NewNamedParser
func NewNamedParser(appname string, options Options) *Parser { p := &Parser{ Command: newCommand(appname, "", "", nil), Options: options, NamespaceDelimiter: ".", EnvNamespaceDelimiter: "_", } p.Command.parent = p return p }
go
func NewNamedParser(appname string, options Options) *Parser { p := &Parser{ Command: newCommand(appname, "", "", nil), Options: options, NamespaceDelimiter: ".", EnvNamespaceDelimiter: "_", } p.Command.parent = p return p }
[ "func", "NewNamedParser", "(", "appname", "string", ",", "options", "Options", ")", "*", "Parser", "{", "p", ":=", "&", "Parser", "{", "Command", ":", "newCommand", "(", "appname", ",", "\"", "\"", ",", "\"", "\"", ",", "nil", ")", ",", "Options", ":", "options", ",", "NamespaceDelimiter", ":", "\"", "\"", ",", "EnvNamespaceDelimiter", ":", "\"", "\"", ",", "}", "\n\n", "p", ".", "Command", ".", "parent", "=", "p", "\n\n", "return", "p", "\n", "}" ]
// NewNamedParser creates a new parser. The appname is used to display the // executable name in the built-in help message. Option groups and commands can // be added to this parser by using AddGroup and AddCommand.
[ "NewNamedParser", "creates", "a", "new", "parser", ".", "The", "appname", "is", "used", "to", "display", "the", "executable", "name", "in", "the", "built", "-", "in", "help", "message", ".", "Option", "groups", "and", "commands", "can", "be", "added", "to", "this", "parser", "by", "using", "AddGroup", "and", "AddCommand", "." ]
c0795c8afcf41dd1d786bebce68636c199b3bb45
https://github.com/jessevdk/go-flags/blob/c0795c8afcf41dd1d786bebce68636c199b3bb45/parser.go#L174-L185
train
jessevdk/go-flags
ini.go
ParseFile
func (i *IniParser) ParseFile(filename string) error { ini, err := readIniFromFile(filename) if err != nil { return err } return i.parse(ini) }
go
func (i *IniParser) ParseFile(filename string) error { ini, err := readIniFromFile(filename) if err != nil { return err } return i.parse(ini) }
[ "func", "(", "i", "*", "IniParser", ")", "ParseFile", "(", "filename", "string", ")", "error", "{", "ini", ",", "err", ":=", "readIniFromFile", "(", "filename", ")", "\n\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "return", "i", ".", "parse", "(", "ini", ")", "\n", "}" ]
// ParseFile parses flags from an ini formatted file. See Parse for more // information on the ini file format. The returned errors can be of the type // flags.Error or flags.IniError.
[ "ParseFile", "parses", "flags", "from", "an", "ini", "formatted", "file", ".", "See", "Parse", "for", "more", "information", "on", "the", "ini", "file", "format", ".", "The", "returned", "errors", "can", "be", "of", "the", "type", "flags", ".", "Error", "or", "flags", ".", "IniError", "." ]
c0795c8afcf41dd1d786bebce68636c199b3bb45
https://github.com/jessevdk/go-flags/blob/c0795c8afcf41dd1d786bebce68636c199b3bb45/ini.go#L100-L108
train
jessevdk/go-flags
ini.go
WriteFile
func (i *IniParser) WriteFile(filename string, options IniOptions) error { return writeIniToFile(i, filename, options) }
go
func (i *IniParser) WriteFile(filename string, options IniOptions) error { return writeIniToFile(i, filename, options) }
[ "func", "(", "i", "*", "IniParser", ")", "WriteFile", "(", "filename", "string", ",", "options", "IniOptions", ")", "error", "{", "return", "writeIniToFile", "(", "i", ",", "filename", ",", "options", ")", "\n", "}" ]
// WriteFile writes the flags as ini format into a file. See Write // for more information. The returned error occurs when the specified file // could not be opened for writing.
[ "WriteFile", "writes", "the", "flags", "as", "ini", "format", "into", "a", "file", ".", "See", "Write", "for", "more", "information", ".", "The", "returned", "error", "occurs", "when", "the", "specified", "file", "could", "not", "be", "opened", "for", "writing", "." ]
c0795c8afcf41dd1d786bebce68636c199b3bb45
https://github.com/jessevdk/go-flags/blob/c0795c8afcf41dd1d786bebce68636c199b3bb45/ini.go#L147-L149
train
jessevdk/go-flags
completion.go
Complete
func (f *Filename) Complete(match string) []Completion { ret, _ := filepath.Glob(match + "*") if len(ret) == 1 { if info, err := os.Stat(ret[0]); err == nil && info.IsDir() { ret[0] = ret[0] + "/" } } return completionsWithoutDescriptions(ret) }
go
func (f *Filename) Complete(match string) []Completion { ret, _ := filepath.Glob(match + "*") if len(ret) == 1 { if info, err := os.Stat(ret[0]); err == nil && info.IsDir() { ret[0] = ret[0] + "/" } } return completionsWithoutDescriptions(ret) }
[ "func", "(", "f", "*", "Filename", ")", "Complete", "(", "match", "string", ")", "[", "]", "Completion", "{", "ret", ",", "_", ":=", "filepath", ".", "Glob", "(", "match", "+", "\"", "\"", ")", "\n", "if", "len", "(", "ret", ")", "==", "1", "{", "if", "info", ",", "err", ":=", "os", ".", "Stat", "(", "ret", "[", "0", "]", ")", ";", "err", "==", "nil", "&&", "info", ".", "IsDir", "(", ")", "{", "ret", "[", "0", "]", "=", "ret", "[", "0", "]", "+", "\"", "\"", "\n", "}", "\n", "}", "\n", "return", "completionsWithoutDescriptions", "(", "ret", ")", "\n", "}" ]
// Complete returns a list of existing files with the given // prefix.
[ "Complete", "returns", "a", "list", "of", "existing", "files", "with", "the", "given", "prefix", "." ]
c0795c8afcf41dd1d786bebce68636c199b3bb45
https://github.com/jessevdk/go-flags/blob/c0795c8afcf41dd1d786bebce68636c199b3bb45/completion.go#L64-L72
train
jessevdk/go-flags
option.go
LongNameWithNamespace
func (option *Option) LongNameWithNamespace() string { if len(option.LongName) == 0 { return "" } // fetch the namespace delimiter from the parser which is always at the // end of the group hierarchy namespaceDelimiter := "" g := option.group for { if p, ok := g.parent.(*Parser); ok { namespaceDelimiter = p.NamespaceDelimiter break } switch i := g.parent.(type) { case *Command: g = i.Group case *Group: g = i } } // concatenate long name with namespace longName := option.LongName g = option.group for g != nil { if g.Namespace != "" { longName = g.Namespace + namespaceDelimiter + longName } switch i := g.parent.(type) { case *Command: g = i.Group case *Group: g = i case *Parser: g = nil } } return longName }
go
func (option *Option) LongNameWithNamespace() string { if len(option.LongName) == 0 { return "" } // fetch the namespace delimiter from the parser which is always at the // end of the group hierarchy namespaceDelimiter := "" g := option.group for { if p, ok := g.parent.(*Parser); ok { namespaceDelimiter = p.NamespaceDelimiter break } switch i := g.parent.(type) { case *Command: g = i.Group case *Group: g = i } } // concatenate long name with namespace longName := option.LongName g = option.group for g != nil { if g.Namespace != "" { longName = g.Namespace + namespaceDelimiter + longName } switch i := g.parent.(type) { case *Command: g = i.Group case *Group: g = i case *Parser: g = nil } } return longName }
[ "func", "(", "option", "*", "Option", ")", "LongNameWithNamespace", "(", ")", "string", "{", "if", "len", "(", "option", ".", "LongName", ")", "==", "0", "{", "return", "\"", "\"", "\n", "}", "\n\n", "// fetch the namespace delimiter from the parser which is always at the", "// end of the group hierarchy", "namespaceDelimiter", ":=", "\"", "\"", "\n", "g", ":=", "option", ".", "group", "\n\n", "for", "{", "if", "p", ",", "ok", ":=", "g", ".", "parent", ".", "(", "*", "Parser", ")", ";", "ok", "{", "namespaceDelimiter", "=", "p", ".", "NamespaceDelimiter", "\n\n", "break", "\n", "}", "\n\n", "switch", "i", ":=", "g", ".", "parent", ".", "(", "type", ")", "{", "case", "*", "Command", ":", "g", "=", "i", ".", "Group", "\n", "case", "*", "Group", ":", "g", "=", "i", "\n", "}", "\n", "}", "\n\n", "// concatenate long name with namespace", "longName", ":=", "option", ".", "LongName", "\n", "g", "=", "option", ".", "group", "\n\n", "for", "g", "!=", "nil", "{", "if", "g", ".", "Namespace", "!=", "\"", "\"", "{", "longName", "=", "g", ".", "Namespace", "+", "namespaceDelimiter", "+", "longName", "\n", "}", "\n\n", "switch", "i", ":=", "g", ".", "parent", ".", "(", "type", ")", "{", "case", "*", "Command", ":", "g", "=", "i", ".", "Group", "\n", "case", "*", "Group", ":", "g", "=", "i", "\n", "case", "*", "Parser", ":", "g", "=", "nil", "\n", "}", "\n", "}", "\n\n", "return", "longName", "\n", "}" ]
// LongNameWithNamespace returns the option's long name with the group namespaces // prepended by walking up the option's group tree. Namespaces and the long name // itself are separated by the parser's namespace delimiter. If the long name is // empty an empty string is returned.
[ "LongNameWithNamespace", "returns", "the", "option", "s", "long", "name", "with", "the", "group", "namespaces", "prepended", "by", "walking", "up", "the", "option", "s", "group", "tree", ".", "Namespaces", "and", "the", "long", "name", "itself", "are", "separated", "by", "the", "parser", "s", "namespace", "delimiter", ".", "If", "the", "long", "name", "is", "empty", "an", "empty", "string", "is", "returned", "." ]
c0795c8afcf41dd1d786bebce68636c199b3bb45
https://github.com/jessevdk/go-flags/blob/c0795c8afcf41dd1d786bebce68636c199b3bb45/option.go#L95-L140
train
jessevdk/go-flags
option.go
EnvKeyWithNamespace
func (option *Option) EnvKeyWithNamespace() string { if len(option.EnvDefaultKey) == 0 { return "" } // fetch the namespace delimiter from the parser which is always at the // end of the group hierarchy namespaceDelimiter := "" g := option.group for { if p, ok := g.parent.(*Parser); ok { namespaceDelimiter = p.EnvNamespaceDelimiter break } switch i := g.parent.(type) { case *Command: g = i.Group case *Group: g = i } } // concatenate long name with namespace key := option.EnvDefaultKey g = option.group for g != nil { if g.EnvNamespace != "" { key = g.EnvNamespace + namespaceDelimiter + key } switch i := g.parent.(type) { case *Command: g = i.Group case *Group: g = i case *Parser: g = nil } } return key }
go
func (option *Option) EnvKeyWithNamespace() string { if len(option.EnvDefaultKey) == 0 { return "" } // fetch the namespace delimiter from the parser which is always at the // end of the group hierarchy namespaceDelimiter := "" g := option.group for { if p, ok := g.parent.(*Parser); ok { namespaceDelimiter = p.EnvNamespaceDelimiter break } switch i := g.parent.(type) { case *Command: g = i.Group case *Group: g = i } } // concatenate long name with namespace key := option.EnvDefaultKey g = option.group for g != nil { if g.EnvNamespace != "" { key = g.EnvNamespace + namespaceDelimiter + key } switch i := g.parent.(type) { case *Command: g = i.Group case *Group: g = i case *Parser: g = nil } } return key }
[ "func", "(", "option", "*", "Option", ")", "EnvKeyWithNamespace", "(", ")", "string", "{", "if", "len", "(", "option", ".", "EnvDefaultKey", ")", "==", "0", "{", "return", "\"", "\"", "\n", "}", "\n\n", "// fetch the namespace delimiter from the parser which is always at the", "// end of the group hierarchy", "namespaceDelimiter", ":=", "\"", "\"", "\n", "g", ":=", "option", ".", "group", "\n\n", "for", "{", "if", "p", ",", "ok", ":=", "g", ".", "parent", ".", "(", "*", "Parser", ")", ";", "ok", "{", "namespaceDelimiter", "=", "p", ".", "EnvNamespaceDelimiter", "\n\n", "break", "\n", "}", "\n\n", "switch", "i", ":=", "g", ".", "parent", ".", "(", "type", ")", "{", "case", "*", "Command", ":", "g", "=", "i", ".", "Group", "\n", "case", "*", "Group", ":", "g", "=", "i", "\n", "}", "\n", "}", "\n\n", "// concatenate long name with namespace", "key", ":=", "option", ".", "EnvDefaultKey", "\n", "g", "=", "option", ".", "group", "\n\n", "for", "g", "!=", "nil", "{", "if", "g", ".", "EnvNamespace", "!=", "\"", "\"", "{", "key", "=", "g", ".", "EnvNamespace", "+", "namespaceDelimiter", "+", "key", "\n", "}", "\n\n", "switch", "i", ":=", "g", ".", "parent", ".", "(", "type", ")", "{", "case", "*", "Command", ":", "g", "=", "i", ".", "Group", "\n", "case", "*", "Group", ":", "g", "=", "i", "\n", "case", "*", "Parser", ":", "g", "=", "nil", "\n", "}", "\n", "}", "\n\n", "return", "key", "\n", "}" ]
// EnvKeyWithNamespace returns the option's env key with the group namespaces // prepended by walking up the option's group tree. Namespaces and the env key // itself are separated by the parser's namespace delimiter. If the env key is // empty an empty string is returned.
[ "EnvKeyWithNamespace", "returns", "the", "option", "s", "env", "key", "with", "the", "group", "namespaces", "prepended", "by", "walking", "up", "the", "option", "s", "group", "tree", ".", "Namespaces", "and", "the", "env", "key", "itself", "are", "separated", "by", "the", "parser", "s", "namespace", "delimiter", ".", "If", "the", "env", "key", "is", "empty", "an", "empty", "string", "is", "returned", "." ]
c0795c8afcf41dd1d786bebce68636c199b3bb45
https://github.com/jessevdk/go-flags/blob/c0795c8afcf41dd1d786bebce68636c199b3bb45/option.go#L146-L191
train
jessevdk/go-flags
option.go
String
func (option *Option) String() string { var s string var short string if option.ShortName != 0 { data := make([]byte, utf8.RuneLen(option.ShortName)) utf8.EncodeRune(data, option.ShortName) short = string(data) if len(option.LongName) != 0 { s = fmt.Sprintf("%s%s, %s%s", string(defaultShortOptDelimiter), short, defaultLongOptDelimiter, option.LongNameWithNamespace()) } else { s = fmt.Sprintf("%s%s", string(defaultShortOptDelimiter), short) } } else if len(option.LongName) != 0 { s = fmt.Sprintf("%s%s", defaultLongOptDelimiter, option.LongNameWithNamespace()) } return s }
go
func (option *Option) String() string { var s string var short string if option.ShortName != 0 { data := make([]byte, utf8.RuneLen(option.ShortName)) utf8.EncodeRune(data, option.ShortName) short = string(data) if len(option.LongName) != 0 { s = fmt.Sprintf("%s%s, %s%s", string(defaultShortOptDelimiter), short, defaultLongOptDelimiter, option.LongNameWithNamespace()) } else { s = fmt.Sprintf("%s%s", string(defaultShortOptDelimiter), short) } } else if len(option.LongName) != 0 { s = fmt.Sprintf("%s%s", defaultLongOptDelimiter, option.LongNameWithNamespace()) } return s }
[ "func", "(", "option", "*", "Option", ")", "String", "(", ")", "string", "{", "var", "s", "string", "\n", "var", "short", "string", "\n\n", "if", "option", ".", "ShortName", "!=", "0", "{", "data", ":=", "make", "(", "[", "]", "byte", ",", "utf8", ".", "RuneLen", "(", "option", ".", "ShortName", ")", ")", "\n", "utf8", ".", "EncodeRune", "(", "data", ",", "option", ".", "ShortName", ")", "\n", "short", "=", "string", "(", "data", ")", "\n\n", "if", "len", "(", "option", ".", "LongName", ")", "!=", "0", "{", "s", "=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "string", "(", "defaultShortOptDelimiter", ")", ",", "short", ",", "defaultLongOptDelimiter", ",", "option", ".", "LongNameWithNamespace", "(", ")", ")", "\n", "}", "else", "{", "s", "=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "string", "(", "defaultShortOptDelimiter", ")", ",", "short", ")", "\n", "}", "\n", "}", "else", "if", "len", "(", "option", ".", "LongName", ")", "!=", "0", "{", "s", "=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "defaultLongOptDelimiter", ",", "option", ".", "LongNameWithNamespace", "(", ")", ")", "\n", "}", "\n\n", "return", "s", "\n", "}" ]
// String converts an option to a human friendly readable string describing the // option.
[ "String", "converts", "an", "option", "to", "a", "human", "friendly", "readable", "string", "describing", "the", "option", "." ]
c0795c8afcf41dd1d786bebce68636c199b3bb45
https://github.com/jessevdk/go-flags/blob/c0795c8afcf41dd1d786bebce68636c199b3bb45/option.go#L195-L216
train
jessevdk/go-flags
option.go
set
func (option *Option) set(value *string) error { kind := option.value.Type().Kind() if (kind == reflect.Map || kind == reflect.Slice) && !option.isSet { option.empty() } option.isSet = true option.preventDefault = true if len(option.Choices) != 0 { found := false for _, choice := range option.Choices { if choice == *value { found = true break } } if !found { allowed := strings.Join(option.Choices[0:len(option.Choices)-1], ", ") if len(option.Choices) > 1 { allowed += " or " + option.Choices[len(option.Choices)-1] } return newErrorf(ErrInvalidChoice, "Invalid value `%s' for option `%s'. Allowed values are: %s", *value, option, allowed) } } if option.isFunc() { return option.call(value) } else if value != nil { return convert(*value, option.value, option.tag) } return convert("", option.value, option.tag) }
go
func (option *Option) set(value *string) error { kind := option.value.Type().Kind() if (kind == reflect.Map || kind == reflect.Slice) && !option.isSet { option.empty() } option.isSet = true option.preventDefault = true if len(option.Choices) != 0 { found := false for _, choice := range option.Choices { if choice == *value { found = true break } } if !found { allowed := strings.Join(option.Choices[0:len(option.Choices)-1], ", ") if len(option.Choices) > 1 { allowed += " or " + option.Choices[len(option.Choices)-1] } return newErrorf(ErrInvalidChoice, "Invalid value `%s' for option `%s'. Allowed values are: %s", *value, option, allowed) } } if option.isFunc() { return option.call(value) } else if value != nil { return convert(*value, option.value, option.tag) } return convert("", option.value, option.tag) }
[ "func", "(", "option", "*", "Option", ")", "set", "(", "value", "*", "string", ")", "error", "{", "kind", ":=", "option", ".", "value", ".", "Type", "(", ")", ".", "Kind", "(", ")", "\n\n", "if", "(", "kind", "==", "reflect", ".", "Map", "||", "kind", "==", "reflect", ".", "Slice", ")", "&&", "!", "option", ".", "isSet", "{", "option", ".", "empty", "(", ")", "\n", "}", "\n\n", "option", ".", "isSet", "=", "true", "\n", "option", ".", "preventDefault", "=", "true", "\n\n", "if", "len", "(", "option", ".", "Choices", ")", "!=", "0", "{", "found", ":=", "false", "\n\n", "for", "_", ",", "choice", ":=", "range", "option", ".", "Choices", "{", "if", "choice", "==", "*", "value", "{", "found", "=", "true", "\n", "break", "\n", "}", "\n", "}", "\n\n", "if", "!", "found", "{", "allowed", ":=", "strings", ".", "Join", "(", "option", ".", "Choices", "[", "0", ":", "len", "(", "option", ".", "Choices", ")", "-", "1", "]", ",", "\"", "\"", ")", "\n\n", "if", "len", "(", "option", ".", "Choices", ")", ">", "1", "{", "allowed", "+=", "\"", "\"", "+", "option", ".", "Choices", "[", "len", "(", "option", ".", "Choices", ")", "-", "1", "]", "\n", "}", "\n\n", "return", "newErrorf", "(", "ErrInvalidChoice", ",", "\"", "\"", ",", "*", "value", ",", "option", ",", "allowed", ")", "\n", "}", "\n", "}", "\n\n", "if", "option", ".", "isFunc", "(", ")", "{", "return", "option", ".", "call", "(", "value", ")", "\n", "}", "else", "if", "value", "!=", "nil", "{", "return", "convert", "(", "*", "value", ",", "option", ".", "value", ",", "option", ".", "tag", ")", "\n", "}", "\n\n", "return", "convert", "(", "\"", "\"", ",", "option", ".", "value", ",", "option", ".", "tag", ")", "\n", "}" ]
// Set the value of an option to the specified value. An error will be returned // if the specified value could not be converted to the corresponding option // value type.
[ "Set", "the", "value", "of", "an", "option", "to", "the", "specified", "value", ".", "An", "error", "will", "be", "returned", "if", "the", "specified", "value", "could", "not", "be", "converted", "to", "the", "corresponding", "option", "value", "type", "." ]
c0795c8afcf41dd1d786bebce68636c199b3bb45
https://github.com/jessevdk/go-flags/blob/c0795c8afcf41dd1d786bebce68636c199b3bb45/option.go#L241-L281
train
jessevdk/go-flags
command.go
AddCommand
func (c *Command) AddCommand(command string, shortDescription string, longDescription string, data interface{}) (*Command, error) { cmd := newCommand(command, shortDescription, longDescription, data) cmd.parent = c if err := cmd.scan(); err != nil { return nil, err } c.commands = append(c.commands, cmd) return cmd, nil }
go
func (c *Command) AddCommand(command string, shortDescription string, longDescription string, data interface{}) (*Command, error) { cmd := newCommand(command, shortDescription, longDescription, data) cmd.parent = c if err := cmd.scan(); err != nil { return nil, err } c.commands = append(c.commands, cmd) return cmd, nil }
[ "func", "(", "c", "*", "Command", ")", "AddCommand", "(", "command", "string", ",", "shortDescription", "string", ",", "longDescription", "string", ",", "data", "interface", "{", "}", ")", "(", "*", "Command", ",", "error", ")", "{", "cmd", ":=", "newCommand", "(", "command", ",", "shortDescription", ",", "longDescription", ",", "data", ")", "\n\n", "cmd", ".", "parent", "=", "c", "\n\n", "if", "err", ":=", "cmd", ".", "scan", "(", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "c", ".", "commands", "=", "append", "(", "c", ".", "commands", ",", "cmd", ")", "\n", "return", "cmd", ",", "nil", "\n", "}" ]
// AddCommand adds a new command to the parser with the given name and data. The // data needs to be a pointer to a struct from which the fields indicate which // options are in the command. The provided data can implement the Command and // Usage interfaces.
[ "AddCommand", "adds", "a", "new", "command", "to", "the", "parser", "with", "the", "given", "name", "and", "data", ".", "The", "data", "needs", "to", "be", "a", "pointer", "to", "a", "struct", "from", "which", "the", "fields", "indicate", "which", "options", "are", "in", "the", "command", ".", "The", "provided", "data", "can", "implement", "the", "Command", "and", "Usage", "interfaces", "." ]
c0795c8afcf41dd1d786bebce68636c199b3bb45
https://github.com/jessevdk/go-flags/blob/c0795c8afcf41dd1d786bebce68636c199b3bb45/command.go#L68-L79
train
jessevdk/go-flags
command.go
Find
func (c *Command) Find(name string) *Command { for _, cc := range c.commands { if cc.match(name) { return cc } } return nil }
go
func (c *Command) Find(name string) *Command { for _, cc := range c.commands { if cc.match(name) { return cc } } return nil }
[ "func", "(", "c", "*", "Command", ")", "Find", "(", "name", "string", ")", "*", "Command", "{", "for", "_", ",", "cc", ":=", "range", "c", ".", "commands", "{", "if", "cc", ".", "match", "(", "name", ")", "{", "return", "cc", "\n", "}", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// Find locates the subcommand with the given name and returns it. If no such // command can be found Find will return nil.
[ "Find", "locates", "the", "subcommand", "with", "the", "given", "name", "and", "returns", "it", ".", "If", "no", "such", "command", "can", "be", "found", "Find", "will", "return", "nil", "." ]
c0795c8afcf41dd1d786bebce68636c199b3bb45
https://github.com/jessevdk/go-flags/blob/c0795c8afcf41dd1d786bebce68636c199b3bb45/command.go#L104-L112
train
jessevdk/go-flags
command.go
Args
func (c *Command) Args() []*Arg { ret := make([]*Arg, len(c.args)) copy(ret, c.args) return ret }
go
func (c *Command) Args() []*Arg { ret := make([]*Arg, len(c.args)) copy(ret, c.args) return ret }
[ "func", "(", "c", "*", "Command", ")", "Args", "(", ")", "[", "]", "*", "Arg", "{", "ret", ":=", "make", "(", "[", "]", "*", "Arg", ",", "len", "(", "c", ".", "args", ")", ")", "\n", "copy", "(", "ret", ",", "c", ".", "args", ")", "\n\n", "return", "ret", "\n", "}" ]
// Args returns a list of positional arguments associated with this command.
[ "Args", "returns", "a", "list", "of", "positional", "arguments", "associated", "with", "this", "command", "." ]
c0795c8afcf41dd1d786bebce68636c199b3bb45
https://github.com/jessevdk/go-flags/blob/c0795c8afcf41dd1d786bebce68636c199b3bb45/command.go#L141-L146
train
motemen/ghq
commands.go
mkCommandsTemplate
func mkCommandsTemplate(genTemplate func(commandDoc) string) string { template := "{{if false}}" for _, command := range append(commands) { template = template + fmt.Sprintf("{{else if (eq .Name %q)}}%s", command.Name, genTemplate(commandDocs[command.Name])) } return template + "{{end}}" }
go
func mkCommandsTemplate(genTemplate func(commandDoc) string) string { template := "{{if false}}" for _, command := range append(commands) { template = template + fmt.Sprintf("{{else if (eq .Name %q)}}%s", command.Name, genTemplate(commandDocs[command.Name])) } return template + "{{end}}" }
[ "func", "mkCommandsTemplate", "(", "genTemplate", "func", "(", "commandDoc", ")", "string", ")", "string", "{", "template", ":=", "\"", "\"", "\n", "for", "_", ",", "command", ":=", "range", "append", "(", "commands", ")", "{", "template", "=", "template", "+", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "command", ".", "Name", ",", "genTemplate", "(", "commandDocs", "[", "command", ".", "Name", "]", ")", ")", "\n", "}", "\n", "return", "template", "+", "\"", "\"", "\n", "}" ]
// Makes template conditionals to generate per-command documents.
[ "Makes", "template", "conditionals", "to", "generate", "per", "-", "command", "documents", "." ]
f311c7108b66c3c94d7730882fdf53a170fd6722
https://github.com/motemen/ghq/blob/f311c7108b66c3c94d7730882fdf53a170fd6722/commands.go#L105-L111
train
motemen/ghq
git.go
GitConfigAll
func GitConfigAll(key string) ([]string, error) { value, err := GitConfig("--get-all", key) if err != nil { return nil, err } // No results found, return an empty slice if value == "" { return nil, nil } return strings.Split(value, "\000"), nil }
go
func GitConfigAll(key string) ([]string, error) { value, err := GitConfig("--get-all", key) if err != nil { return nil, err } // No results found, return an empty slice if value == "" { return nil, nil } return strings.Split(value, "\000"), nil }
[ "func", "GitConfigAll", "(", "key", "string", ")", "(", "[", "]", "string", ",", "error", ")", "{", "value", ",", "err", ":=", "GitConfig", "(", "\"", "\"", ",", "key", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "// No results found, return an empty slice", "if", "value", "==", "\"", "\"", "{", "return", "nil", ",", "nil", "\n", "}", "\n\n", "return", "strings", ".", "Split", "(", "value", ",", "\"", "\\000", "\"", ")", ",", "nil", "\n", "}" ]
// GitConfigAll fetches git-config variable of multiple values.
[ "GitConfigAll", "fetches", "git", "-", "config", "variable", "of", "multiple", "values", "." ]
f311c7108b66c3c94d7730882fdf53a170fd6722
https://github.com/motemen/ghq/blob/f311c7108b66c3c94d7730882fdf53a170fd6722/git.go#L21-L33
train
motemen/ghq
git.go
GitConfig
func GitConfig(args ...string) (string, error) { gitArgs := append([]string{"config", "--path", "--null"}, args...) cmd := exec.Command("git", gitArgs...) cmd.Stderr = os.Stderr buf, err := cmd.Output() if exitError, ok := err.(*exec.ExitError); ok { if waitStatus, ok := exitError.Sys().(syscall.WaitStatus); ok { if waitStatus.ExitStatus() == 1 { // The key was not found, do not treat as an error return "", nil } } return "", err } return strings.TrimRight(string(buf), "\000"), nil }
go
func GitConfig(args ...string) (string, error) { gitArgs := append([]string{"config", "--path", "--null"}, args...) cmd := exec.Command("git", gitArgs...) cmd.Stderr = os.Stderr buf, err := cmd.Output() if exitError, ok := err.(*exec.ExitError); ok { if waitStatus, ok := exitError.Sys().(syscall.WaitStatus); ok { if waitStatus.ExitStatus() == 1 { // The key was not found, do not treat as an error return "", nil } } return "", err } return strings.TrimRight(string(buf), "\000"), nil }
[ "func", "GitConfig", "(", "args", "...", "string", ")", "(", "string", ",", "error", ")", "{", "gitArgs", ":=", "append", "(", "[", "]", "string", "{", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", "}", ",", "args", "...", ")", "\n", "cmd", ":=", "exec", ".", "Command", "(", "\"", "\"", ",", "gitArgs", "...", ")", "\n", "cmd", ".", "Stderr", "=", "os", ".", "Stderr", "\n\n", "buf", ",", "err", ":=", "cmd", ".", "Output", "(", ")", "\n\n", "if", "exitError", ",", "ok", ":=", "err", ".", "(", "*", "exec", ".", "ExitError", ")", ";", "ok", "{", "if", "waitStatus", ",", "ok", ":=", "exitError", ".", "Sys", "(", ")", ".", "(", "syscall", ".", "WaitStatus", ")", ";", "ok", "{", "if", "waitStatus", ".", "ExitStatus", "(", ")", "==", "1", "{", "// The key was not found, do not treat as an error", "return", "\"", "\"", ",", "nil", "\n", "}", "\n", "}", "\n\n", "return", "\"", "\"", ",", "err", "\n", "}", "\n\n", "return", "strings", ".", "TrimRight", "(", "string", "(", "buf", ")", ",", "\"", "\\000", "\"", ")", ",", "nil", "\n", "}" ]
// GitConfig invokes 'git config' and handles some errors properly.
[ "GitConfig", "invokes", "git", "config", "and", "handles", "some", "errors", "properly", "." ]
f311c7108b66c3c94d7730882fdf53a170fd6722
https://github.com/motemen/ghq/blob/f311c7108b66c3c94d7730882fdf53a170fd6722/git.go#L36-L55
train
motemen/ghq
cmdutil/run.go
Run
func Run(command string, args ...string) error { cmd := exec.Command(command, args...) cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr return RunCommand(cmd, false) }
go
func Run(command string, args ...string) error { cmd := exec.Command(command, args...) cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr return RunCommand(cmd, false) }
[ "func", "Run", "(", "command", "string", ",", "args", "...", "string", ")", "error", "{", "cmd", ":=", "exec", ".", "Command", "(", "command", ",", "args", "...", ")", "\n", "cmd", ".", "Stdout", "=", "os", ".", "Stdout", "\n", "cmd", ".", "Stderr", "=", "os", ".", "Stderr", "\n\n", "return", "RunCommand", "(", "cmd", ",", "false", ")", "\n", "}" ]
// Run the command
[ "Run", "the", "command" ]
f311c7108b66c3c94d7730882fdf53a170fd6722
https://github.com/motemen/ghq/blob/f311c7108b66c3c94d7730882fdf53a170fd6722/cmdutil/run.go#L14-L20
train
motemen/ghq
cmdutil/run.go
RunSilently
func RunSilently(command string, args ...string) error { cmd := exec.Command(command, args...) cmd.Stdout = ioutil.Discard cmd.Stderr = ioutil.Discard return RunCommand(cmd, true) }
go
func RunSilently(command string, args ...string) error { cmd := exec.Command(command, args...) cmd.Stdout = ioutil.Discard cmd.Stderr = ioutil.Discard return RunCommand(cmd, true) }
[ "func", "RunSilently", "(", "command", "string", ",", "args", "...", "string", ")", "error", "{", "cmd", ":=", "exec", ".", "Command", "(", "command", ",", "args", "...", ")", "\n", "cmd", ".", "Stdout", "=", "ioutil", ".", "Discard", "\n", "cmd", ".", "Stderr", "=", "ioutil", ".", "Discard", "\n\n", "return", "RunCommand", "(", "cmd", ",", "true", ")", "\n", "}" ]
// RunSilently runs the command silently
[ "RunSilently", "runs", "the", "command", "silently" ]
f311c7108b66c3c94d7730882fdf53a170fd6722
https://github.com/motemen/ghq/blob/f311c7108b66c3c94d7730882fdf53a170fd6722/cmdutil/run.go#L23-L29
train
motemen/ghq
cmdutil/run.go
RunInDir
func RunInDir(dir, command string, args ...string) error { cmd := exec.Command(command, args...) cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr cmd.Dir = dir return RunCommand(cmd, false) }
go
func RunInDir(dir, command string, args ...string) error { cmd := exec.Command(command, args...) cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr cmd.Dir = dir return RunCommand(cmd, false) }
[ "func", "RunInDir", "(", "dir", ",", "command", "string", ",", "args", "...", "string", ")", "error", "{", "cmd", ":=", "exec", ".", "Command", "(", "command", ",", "args", "...", ")", "\n", "cmd", ".", "Stdout", "=", "os", ".", "Stdout", "\n", "cmd", ".", "Stderr", "=", "os", ".", "Stderr", "\n", "cmd", ".", "Dir", "=", "dir", "\n\n", "return", "RunCommand", "(", "cmd", ",", "false", ")", "\n", "}" ]
// RunInDir runs the command in the specified directory
[ "RunInDir", "runs", "the", "command", "in", "the", "specified", "directory" ]
f311c7108b66c3c94d7730882fdf53a170fd6722
https://github.com/motemen/ghq/blob/f311c7108b66c3c94d7730882fdf53a170fd6722/cmdutil/run.go#L32-L39
train
motemen/ghq
cmdutil/run.go
RunInDirSilently
func RunInDirSilently(dir, command string, args ...string) error { cmd := exec.Command(command, args...) cmd.Stdout = ioutil.Discard cmd.Stderr = ioutil.Discard cmd.Dir = dir return RunCommand(cmd, true) }
go
func RunInDirSilently(dir, command string, args ...string) error { cmd := exec.Command(command, args...) cmd.Stdout = ioutil.Discard cmd.Stderr = ioutil.Discard cmd.Dir = dir return RunCommand(cmd, true) }
[ "func", "RunInDirSilently", "(", "dir", ",", "command", "string", ",", "args", "...", "string", ")", "error", "{", "cmd", ":=", "exec", ".", "Command", "(", "command", ",", "args", "...", ")", "\n", "cmd", ".", "Stdout", "=", "ioutil", ".", "Discard", "\n", "cmd", ".", "Stderr", "=", "ioutil", ".", "Discard", "\n", "cmd", ".", "Dir", "=", "dir", "\n\n", "return", "RunCommand", "(", "cmd", ",", "true", ")", "\n", "}" ]
// RunInDirSilently run the command in the specified directory silently
[ "RunInDirSilently", "run", "the", "command", "in", "the", "specified", "directory", "silently" ]
f311c7108b66c3c94d7730882fdf53a170fd6722
https://github.com/motemen/ghq/blob/f311c7108b66c3c94d7730882fdf53a170fd6722/cmdutil/run.go#L42-L49
train
motemen/ghq
cmdutil/run.go
RunCommand
func RunCommand(cmd *exec.Cmd, silent bool) error { if !silent { logger.Log(cmd.Args[0], strings.Join(cmd.Args[1:], " ")) } err := CommandRunner(cmd) if err != nil { if execErr, ok := err.(*exec.Error); ok { logger.Log("warning", fmt.Sprintf("%q: %s", execErr.Name, execErr.Err)) } return &RunError{cmd, err} } return nil }
go
func RunCommand(cmd *exec.Cmd, silent bool) error { if !silent { logger.Log(cmd.Args[0], strings.Join(cmd.Args[1:], " ")) } err := CommandRunner(cmd) if err != nil { if execErr, ok := err.(*exec.Error); ok { logger.Log("warning", fmt.Sprintf("%q: %s", execErr.Name, execErr.Err)) } return &RunError{cmd, err} } return nil }
[ "func", "RunCommand", "(", "cmd", "*", "exec", ".", "Cmd", ",", "silent", "bool", ")", "error", "{", "if", "!", "silent", "{", "logger", ".", "Log", "(", "cmd", ".", "Args", "[", "0", "]", ",", "strings", ".", "Join", "(", "cmd", ".", "Args", "[", "1", ":", "]", ",", "\"", "\"", ")", ")", "\n", "}", "\n", "err", ":=", "CommandRunner", "(", "cmd", ")", "\n", "if", "err", "!=", "nil", "{", "if", "execErr", ",", "ok", ":=", "err", ".", "(", "*", "exec", ".", "Error", ")", ";", "ok", "{", "logger", ".", "Log", "(", "\"", "\"", ",", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "execErr", ".", "Name", ",", "execErr", ".", "Err", ")", ")", "\n", "}", "\n", "return", "&", "RunError", "{", "cmd", ",", "err", "}", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// RunCommand run the command
[ "RunCommand", "run", "the", "command" ]
f311c7108b66c3c94d7730882fdf53a170fd6722
https://github.com/motemen/ghq/blob/f311c7108b66c3c94d7730882fdf53a170fd6722/cmdutil/run.go#L60-L73
train
motemen/ghq
cmdutil/run.go
Error
func (e *RunError) Error() string { return fmt.Sprintf("%s: %s", e.Command.Path, e.ExecError) }
go
func (e *RunError) Error() string { return fmt.Sprintf("%s: %s", e.Command.Path, e.ExecError) }
[ "func", "(", "e", "*", "RunError", ")", "Error", "(", ")", "string", "{", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "e", ".", "Command", ".", "Path", ",", "e", ".", "ExecError", ")", "\n", "}" ]
// Error to implement error interface
[ "Error", "to", "implement", "error", "interface" ]
f311c7108b66c3c94d7730882fdf53a170fd6722
https://github.com/motemen/ghq/blob/f311c7108b66c3c94d7730882fdf53a170fd6722/cmdutil/run.go#L82-L84
train
motemen/ghq
local_repository.go
Matches
func (repo *LocalRepository) Matches(pathQuery string) bool { for _, p := range repo.Subpaths() { if p == pathQuery { return true } } return false }
go
func (repo *LocalRepository) Matches(pathQuery string) bool { for _, p := range repo.Subpaths() { if p == pathQuery { return true } } return false }
[ "func", "(", "repo", "*", "LocalRepository", ")", "Matches", "(", "pathQuery", "string", ")", "bool", "{", "for", "_", ",", "p", ":=", "range", "repo", ".", "Subpaths", "(", ")", "{", "if", "p", "==", "pathQuery", "{", "return", "true", "\n", "}", "\n", "}", "\n\n", "return", "false", "\n", "}" ]
// Matches checks if any subpath of the local repository equals the query.
[ "Matches", "checks", "if", "any", "subpath", "of", "the", "local", "repository", "equals", "the", "query", "." ]
f311c7108b66c3c94d7730882fdf53a170fd6722
https://github.com/motemen/ghq/blob/f311c7108b66c3c94d7730882fdf53a170fd6722/local_repository.go#L112-L120
train
openzipkin-contrib/zipkin-go-opentracing
zipkin-recorder.go
annotate
func annotate(span *zipkincore.Span, timestamp time.Time, value string, host *zipkincore.Endpoint) { if timestamp.IsZero() { timestamp = time.Now() } span.Annotations = append(span.Annotations, &zipkincore.Annotation{ Timestamp: timestamp.UnixNano() / 1e3, Value: value, Host: host, }) }
go
func annotate(span *zipkincore.Span, timestamp time.Time, value string, host *zipkincore.Endpoint) { if timestamp.IsZero() { timestamp = time.Now() } span.Annotations = append(span.Annotations, &zipkincore.Annotation{ Timestamp: timestamp.UnixNano() / 1e3, Value: value, Host: host, }) }
[ "func", "annotate", "(", "span", "*", "zipkincore", ".", "Span", ",", "timestamp", "time", ".", "Time", ",", "value", "string", ",", "host", "*", "zipkincore", ".", "Endpoint", ")", "{", "if", "timestamp", ".", "IsZero", "(", ")", "{", "timestamp", "=", "time", ".", "Now", "(", ")", "\n", "}", "\n", "span", ".", "Annotations", "=", "append", "(", "span", ".", "Annotations", ",", "&", "zipkincore", ".", "Annotation", "{", "Timestamp", ":", "timestamp", ".", "UnixNano", "(", ")", "/", "1e3", ",", "Value", ":", "value", ",", "Host", ":", "host", ",", "}", ")", "\n", "}" ]
// annotate annotates the span with the given value.
[ "annotate", "annotates", "the", "span", "with", "the", "given", "value", "." ]
f0f479ad013a498e4cbfb369414e5d3880903779
https://github.com/openzipkin-contrib/zipkin-go-opentracing/blob/f0f479ad013a498e4cbfb369414e5d3880903779/zipkin-recorder.go#L191-L200
train
openzipkin-contrib/zipkin-go-opentracing
examples/cli_with_2_services/svc2/httpclient.go
NewHTTPClient
func NewHTTPClient(tracer opentracing.Tracer, baseURL string) Service { return &client{ baseURL: baseURL, httpClient: &http.Client{}, tracer: tracer, traceRequest: middleware.ToHTTPRequest(tracer), } }
go
func NewHTTPClient(tracer opentracing.Tracer, baseURL string) Service { return &client{ baseURL: baseURL, httpClient: &http.Client{}, tracer: tracer, traceRequest: middleware.ToHTTPRequest(tracer), } }
[ "func", "NewHTTPClient", "(", "tracer", "opentracing", ".", "Tracer", ",", "baseURL", "string", ")", "Service", "{", "return", "&", "client", "{", "baseURL", ":", "baseURL", ",", "httpClient", ":", "&", "http", ".", "Client", "{", "}", ",", "tracer", ":", "tracer", ",", "traceRequest", ":", "middleware", ".", "ToHTTPRequest", "(", "tracer", ")", ",", "}", "\n", "}" ]
// NewHTTPClient returns a new client instance to our svc2 using the HTTP // transport.
[ "NewHTTPClient", "returns", "a", "new", "client", "instance", "to", "our", "svc2", "using", "the", "HTTP", "transport", "." ]
f0f479ad013a498e4cbfb369414e5d3880903779
https://github.com/openzipkin-contrib/zipkin-go-opentracing/blob/f0f479ad013a498e4cbfb369414e5d3880903779/examples/cli_with_2_services/svc2/httpclient.go#L75-L82
train
openzipkin-contrib/zipkin-go-opentracing
logger.go
Log
func (l *wrappedLogger) Log(k ...interface{}) error { if len(k)%2 == 1 { k = append(k, ErrMissingValue) } o := make([]string, len(k)/2) for i := 0; i < len(k); i += 2 { o[i/2] = fmt.Sprintf("%s=%q", k[i], k[i+1]) } l.l.Println(strings.Join(o, " ")) return nil }
go
func (l *wrappedLogger) Log(k ...interface{}) error { if len(k)%2 == 1 { k = append(k, ErrMissingValue) } o := make([]string, len(k)/2) for i := 0; i < len(k); i += 2 { o[i/2] = fmt.Sprintf("%s=%q", k[i], k[i+1]) } l.l.Println(strings.Join(o, " ")) return nil }
[ "func", "(", "l", "*", "wrappedLogger", ")", "Log", "(", "k", "...", "interface", "{", "}", ")", "error", "{", "if", "len", "(", "k", ")", "%", "2", "==", "1", "{", "k", "=", "append", "(", "k", ",", "ErrMissingValue", ")", "\n", "}", "\n", "o", ":=", "make", "(", "[", "]", "string", ",", "len", "(", "k", ")", "/", "2", ")", "\n", "for", "i", ":=", "0", ";", "i", "<", "len", "(", "k", ")", ";", "i", "+=", "2", "{", "o", "[", "i", "/", "2", "]", "=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "k", "[", "i", "]", ",", "k", "[", "i", "+", "1", "]", ")", "\n", "}", "\n", "l", ".", "l", ".", "Println", "(", "strings", ".", "Join", "(", "o", ",", "\"", "\"", ")", ")", "\n", "return", "nil", "\n", "}" ]
// Log implements Logger
[ "Log", "implements", "Logger" ]
f0f479ad013a498e4cbfb369414e5d3880903779
https://github.com/openzipkin-contrib/zipkin-go-opentracing/blob/f0f479ad013a498e4cbfb369414e5d3880903779/logger.go#L38-L48
train