repo
stringlengths
5
67
path
stringlengths
4
218
func_name
stringlengths
0
151
original_string
stringlengths
52
373k
language
stringclasses
6 values
code
stringlengths
52
373k
code_tokens
listlengths
10
512
docstring
stringlengths
3
47.2k
docstring_tokens
listlengths
3
234
sha
stringlengths
40
40
url
stringlengths
85
339
partition
stringclasses
3 values
golang/appengine
internal/api_classic.go
ClassicContextFromContext
func ClassicContextFromContext(ctx netcontext.Context) (appengine.Context, error) { c := fromContext(ctx) if c == nil { return nil, errNotAppEngineContext } return c, nil }
go
func ClassicContextFromContext(ctx netcontext.Context) (appengine.Context, error) { c := fromContext(ctx) if c == nil { return nil, errNotAppEngineContext } return c, nil }
[ "func", "ClassicContextFromContext", "(", "ctx", "netcontext", ".", "Context", ")", "(", "appengine", ".", "Context", ",", "error", ")", "{", "c", ":=", "fromContext", "(", "ctx", ")", "\n", "if", "c", "==", "nil", "{", "return", "nil", ",", "errNotAppEn...
// This is only for classic App Engine adapters.
[ "This", "is", "only", "for", "classic", "App", "Engine", "adapters", "." ]
54a98f90d1c46b7731eb8fb305d2a321c30ef610
https://github.com/golang/appengine/blob/54a98f90d1c46b7731eb8fb305d2a321c30ef610/internal/api_classic.go#L33-L39
test
golang/appengine
mail/mail.go
Send
func Send(c context.Context, msg *Message) error { return send(c, "Send", msg) }
go
func Send(c context.Context, msg *Message) error { return send(c, "Send", msg) }
[ "func", "Send", "(", "c", "context", ".", "Context", ",", "msg", "*", "Message", ")", "error", "{", "return", "send", "(", "c", ",", "\"Send\"", ",", "msg", ")", "\n", "}" ]
// Send sends an email message.
[ "Send", "sends", "an", "email", "message", "." ]
54a98f90d1c46b7731eb8fb305d2a321c30ef610
https://github.com/golang/appengine/blob/54a98f90d1c46b7731eb8fb305d2a321c30ef610/mail/mail.go#L68-L70
test
golang/appengine
mail/mail.go
SendToAdmins
func SendToAdmins(c context.Context, msg *Message) error { return send(c, "SendToAdmins", msg) }
go
func SendToAdmins(c context.Context, msg *Message) error { return send(c, "SendToAdmins", msg) }
[ "func", "SendToAdmins", "(", "c", "context", ".", "Context", ",", "msg", "*", "Message", ")", "error", "{", "return", "send", "(", "c", ",", "\"SendToAdmins\"", ",", "msg", ")", "\n", "}" ]
// SendToAdmins sends an email message to the application's administrators.
[ "SendToAdmins", "sends", "an", "email", "message", "to", "the", "application", "s", "administrators", "." ]
54a98f90d1c46b7731eb8fb305d2a321c30ef610
https://github.com/golang/appengine/blob/54a98f90d1c46b7731eb8fb305d2a321c30ef610/mail/mail.go#L73-L75
test
jstemmer/go-junit-report
parser/parser.go
Failures
func (r *Report) Failures() int { count := 0 for _, p := range r.Packages { for _, t := range p.Tests { if t.Result == FAIL { count++ } } } return count }
go
func (r *Report) Failures() int { count := 0 for _, p := range r.Packages { for _, t := range p.Tests { if t.Result == FAIL { count++ } } } return count }
[ "func", "(", "r", "*", "Report", ")", "Failures", "(", ")", "int", "{", "count", ":=", "0", "\n", "for", "_", ",", "p", ":=", "range", "r", ".", "Packages", "{", "for", "_", ",", "t", ":=", "range", "p", ".", "Tests", "{", "if", "t", ".", "...
// Failures counts the number of failed tests in this report
[ "Failures", "counts", "the", "number", "of", "failed", "tests", "in", "this", "report" ]
af01ea7f8024089b458d804d5cdf190f962a9a0c
https://github.com/jstemmer/go-junit-report/blob/af01ea7f8024089b458d804d5cdf190f962a9a0c/parser/parser.go#L291-L303
test
tendermint/go-amino
binary-decode.go
decodeFieldNumberAndTyp3
func decodeFieldNumberAndTyp3(bz []byte) (num uint32, typ Typ3, n int, err error) { // Read uvarint value. var value64 = uint64(0) value64, n, err = DecodeUvarint(bz) if err != nil { return } // Decode first typ3 byte. typ = Typ3(value64 & 0x07) // Decode num. var num64 uint64 num64 = value64 >> 3 if nu...
go
func decodeFieldNumberAndTyp3(bz []byte) (num uint32, typ Typ3, n int, err error) { // Read uvarint value. var value64 = uint64(0) value64, n, err = DecodeUvarint(bz) if err != nil { return } // Decode first typ3 byte. typ = Typ3(value64 & 0x07) // Decode num. var num64 uint64 num64 = value64 >> 3 if nu...
[ "func", "decodeFieldNumberAndTyp3", "(", "bz", "[", "]", "byte", ")", "(", "num", "uint32", ",", "typ", "Typ3", ",", "n", "int", ",", "err", "error", ")", "{", "var", "value64", "=", "uint64", "(", "0", ")", "\n", "value64", ",", "n", ",", "err", ...
// Read field key.
[ "Read", "field", "key", "." ]
dc14acf9ef15f85828bfbc561ed9dd9d2a284885
https://github.com/tendermint/go-amino/blob/dc14acf9ef15f85828bfbc561ed9dd9d2a284885/binary-decode.go#L891-L912
test
tendermint/go-amino
binary-decode.go
checkTyp3
func checkTyp3(rt reflect.Type, typ Typ3, fopts FieldOptions) (err error) { typWanted := typeToTyp3(rt, fopts) if typ != typWanted { err = fmt.Errorf("unexpected Typ3. want %v, got %v", typWanted, typ) } return }
go
func checkTyp3(rt reflect.Type, typ Typ3, fopts FieldOptions) (err error) { typWanted := typeToTyp3(rt, fopts) if typ != typWanted { err = fmt.Errorf("unexpected Typ3. want %v, got %v", typWanted, typ) } return }
[ "func", "checkTyp3", "(", "rt", "reflect", ".", "Type", ",", "typ", "Typ3", ",", "fopts", "FieldOptions", ")", "(", "err", "error", ")", "{", "typWanted", ":=", "typeToTyp3", "(", "rt", ",", "fopts", ")", "\n", "if", "typ", "!=", "typWanted", "{", "e...
// Error if typ doesn't match rt.
[ "Error", "if", "typ", "doesn", "t", "match", "rt", "." ]
dc14acf9ef15f85828bfbc561ed9dd9d2a284885
https://github.com/tendermint/go-amino/blob/dc14acf9ef15f85828bfbc561ed9dd9d2a284885/binary-decode.go#L915-L921
test
tendermint/go-amino
binary-decode.go
decodeTyp3
func decodeTyp3(bz []byte) (typ Typ3, n int, err error) { if len(bz) == 0 { err = fmt.Errorf("EOF while reading typ3 byte") return } if bz[0]&0xF8 != 0 { err = fmt.Errorf("invalid typ3 byte: %v", Typ3(bz[0]).String()) return } typ = Typ3(bz[0]) n = 1 return }
go
func decodeTyp3(bz []byte) (typ Typ3, n int, err error) { if len(bz) == 0 { err = fmt.Errorf("EOF while reading typ3 byte") return } if bz[0]&0xF8 != 0 { err = fmt.Errorf("invalid typ3 byte: %v", Typ3(bz[0]).String()) return } typ = Typ3(bz[0]) n = 1 return }
[ "func", "decodeTyp3", "(", "bz", "[", "]", "byte", ")", "(", "typ", "Typ3", ",", "n", "int", ",", "err", "error", ")", "{", "if", "len", "(", "bz", ")", "==", "0", "{", "err", "=", "fmt", ".", "Errorf", "(", "\"EOF while reading typ3 byte\"", ")", ...
// Read typ3 byte.
[ "Read", "typ3", "byte", "." ]
dc14acf9ef15f85828bfbc561ed9dd9d2a284885
https://github.com/tendermint/go-amino/blob/dc14acf9ef15f85828bfbc561ed9dd9d2a284885/binary-decode.go#L924-L936
test
tendermint/go-amino
codec.go
NewPrefixBytes
func NewPrefixBytes(prefixBytes []byte) PrefixBytes { pb := PrefixBytes{} copy(pb[:], prefixBytes) return pb }
go
func NewPrefixBytes(prefixBytes []byte) PrefixBytes { pb := PrefixBytes{} copy(pb[:], prefixBytes) return pb }
[ "func", "NewPrefixBytes", "(", "prefixBytes", "[", "]", "byte", ")", "PrefixBytes", "{", "pb", ":=", "PrefixBytes", "{", "}", "\n", "copy", "(", "pb", "[", ":", "]", ",", "prefixBytes", ")", "\n", "return", "pb", "\n", "}" ]
// Copy into PrefixBytes
[ "Copy", "into", "PrefixBytes" ]
dc14acf9ef15f85828bfbc561ed9dd9d2a284885
https://github.com/tendermint/go-amino/blob/dc14acf9ef15f85828bfbc561ed9dd9d2a284885/codec.go#L32-L36
test
tendermint/go-amino
codec.go
getLengthStr
func getLengthStr(info *TypeInfo) string { switch info.Type.Kind() { case reflect.Array, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64, reflect.Float32, reflect.Float64, reflect.Complex64, reflect.Complex128: s := info.Type.Size() return fmt.Sprintf("0x%X", s) default: return "variable" } ...
go
func getLengthStr(info *TypeInfo) string { switch info.Type.Kind() { case reflect.Array, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64, reflect.Float32, reflect.Float64, reflect.Complex64, reflect.Complex128: s := info.Type.Size() return fmt.Sprintf("0x%X", s) default: return "variable" } ...
[ "func", "getLengthStr", "(", "info", "*", "TypeInfo", ")", "string", "{", "switch", "info", ".", "Type", ".", "Kind", "(", ")", "{", "case", "reflect", ".", "Array", ",", "reflect", ".", "Int8", ",", "reflect", ".", "Int16", ",", "reflect", ".", "Int...
// A heuristic to guess the size of a registered type and return it as a string. // If the size is not fixed it returns "variable".
[ "A", "heuristic", "to", "guess", "the", "size", "of", "a", "registered", "type", "and", "return", "it", "as", "a", "string", ".", "If", "the", "size", "is", "not", "fixed", "it", "returns", "variable", "." ]
dc14acf9ef15f85828bfbc561ed9dd9d2a284885
https://github.com/tendermint/go-amino/blob/dc14acf9ef15f85828bfbc561ed9dd9d2a284885/codec.go#L307-L319
test
tendermint/go-amino
codec.go
collectImplementers_nolock
func (cdc *Codec) collectImplementers_nolock(info *TypeInfo) { for _, cinfo := range cdc.concreteInfos { if cinfo.PtrToType.Implements(info.Type) { info.Implementers[cinfo.Prefix] = append( info.Implementers[cinfo.Prefix], cinfo) } } }
go
func (cdc *Codec) collectImplementers_nolock(info *TypeInfo) { for _, cinfo := range cdc.concreteInfos { if cinfo.PtrToType.Implements(info.Type) { info.Implementers[cinfo.Prefix] = append( info.Implementers[cinfo.Prefix], cinfo) } } }
[ "func", "(", "cdc", "*", "Codec", ")", "collectImplementers_nolock", "(", "info", "*", "TypeInfo", ")", "{", "for", "_", ",", "cinfo", ":=", "range", "cdc", ".", "concreteInfos", "{", "if", "cinfo", ".", "PtrToType", ".", "Implements", "(", "info", ".", ...
// Find all conflicting prefixes for concrete types // that "implement" the interface. "Implement" in quotes because // we only consider the pointer, for extra safety.
[ "Find", "all", "conflicting", "prefixes", "for", "concrete", "types", "that", "implement", "the", "interface", ".", "Implement", "in", "quotes", "because", "we", "only", "consider", "the", "pointer", "for", "extra", "safety", "." ]
dc14acf9ef15f85828bfbc561ed9dd9d2a284885
https://github.com/tendermint/go-amino/blob/dc14acf9ef15f85828bfbc561ed9dd9d2a284885/codec.go#L617-L624
test
tendermint/go-amino
codec.go
checkConflictsInPrio_nolock
func (cdc *Codec) checkConflictsInPrio_nolock(iinfo *TypeInfo) error { for _, cinfos := range iinfo.Implementers { if len(cinfos) < 2 { continue } for _, cinfo := range cinfos { var inPrio = false for _, disfix := range iinfo.InterfaceInfo.Priority { if cinfo.GetDisfix() == disfix { inPrio = t...
go
func (cdc *Codec) checkConflictsInPrio_nolock(iinfo *TypeInfo) error { for _, cinfos := range iinfo.Implementers { if len(cinfos) < 2 { continue } for _, cinfo := range cinfos { var inPrio = false for _, disfix := range iinfo.InterfaceInfo.Priority { if cinfo.GetDisfix() == disfix { inPrio = t...
[ "func", "(", "cdc", "*", "Codec", ")", "checkConflictsInPrio_nolock", "(", "iinfo", "*", "TypeInfo", ")", "error", "{", "for", "_", ",", "cinfos", ":=", "range", "iinfo", ".", "Implementers", "{", "if", "len", "(", "cinfos", ")", "<", "2", "{", "contin...
// Ensure that prefix-conflicting implementing concrete types // are all registered in the priority list. // Returns an error if a disamb conflict is found.
[ "Ensure", "that", "prefix", "-", "conflicting", "implementing", "concrete", "types", "are", "all", "registered", "in", "the", "priority", "list", ".", "Returns", "an", "error", "if", "a", "disamb", "conflict", "is", "found", "." ]
dc14acf9ef15f85828bfbc561ed9dd9d2a284885
https://github.com/tendermint/go-amino/blob/dc14acf9ef15f85828bfbc561ed9dd9d2a284885/codec.go#L629-L649
test
tendermint/go-amino
reflect.go
constructConcreteType
func constructConcreteType(cinfo *TypeInfo) (crv, irvSet reflect.Value) { // Construct new concrete type. if cinfo.PointerPreferred { cPtrRv := reflect.New(cinfo.Type) crv = cPtrRv.Elem() irvSet = cPtrRv } else { crv = reflect.New(cinfo.Type).Elem() irvSet = crv } return }
go
func constructConcreteType(cinfo *TypeInfo) (crv, irvSet reflect.Value) { // Construct new concrete type. if cinfo.PointerPreferred { cPtrRv := reflect.New(cinfo.Type) crv = cPtrRv.Elem() irvSet = cPtrRv } else { crv = reflect.New(cinfo.Type).Elem() irvSet = crv } return }
[ "func", "constructConcreteType", "(", "cinfo", "*", "TypeInfo", ")", "(", "crv", ",", "irvSet", "reflect", ".", "Value", ")", "{", "if", "cinfo", ".", "PointerPreferred", "{", "cPtrRv", ":=", "reflect", ".", "New", "(", "cinfo", ".", "Type", ")", "\n", ...
// constructConcreteType creates the concrete value as // well as the corresponding settable value for it. // Return irvSet which should be set on caller's interface rv.
[ "constructConcreteType", "creates", "the", "concrete", "value", "as", "well", "as", "the", "corresponding", "settable", "value", "for", "it", ".", "Return", "irvSet", "which", "should", "be", "set", "on", "caller", "s", "interface", "rv", "." ]
dc14acf9ef15f85828bfbc561ed9dd9d2a284885
https://github.com/tendermint/go-amino/blob/dc14acf9ef15f85828bfbc561ed9dd9d2a284885/reflect.go#L181-L192
test
tendermint/go-amino
amino.go
MarshalBinaryLengthPrefixedWriter
func (cdc *Codec) MarshalBinaryLengthPrefixedWriter(w io.Writer, o interface{}) (n int64, err error) { var bz, _n = []byte(nil), int(0) bz, err = cdc.MarshalBinaryLengthPrefixed(o) if err != nil { return 0, err } _n, err = w.Write(bz) // TODO: handle overflow in 32-bit systems. n = int64(_n) return }
go
func (cdc *Codec) MarshalBinaryLengthPrefixedWriter(w io.Writer, o interface{}) (n int64, err error) { var bz, _n = []byte(nil), int(0) bz, err = cdc.MarshalBinaryLengthPrefixed(o) if err != nil { return 0, err } _n, err = w.Write(bz) // TODO: handle overflow in 32-bit systems. n = int64(_n) return }
[ "func", "(", "cdc", "*", "Codec", ")", "MarshalBinaryLengthPrefixedWriter", "(", "w", "io", ".", "Writer", ",", "o", "interface", "{", "}", ")", "(", "n", "int64", ",", "err", "error", ")", "{", "var", "bz", ",", "_n", "=", "[", "]", "byte", "(", ...
// MarshalBinaryLengthPrefixedWriter writes the bytes as would be returned from // MarshalBinaryLengthPrefixed to the writer w.
[ "MarshalBinaryLengthPrefixedWriter", "writes", "the", "bytes", "as", "would", "be", "returned", "from", "MarshalBinaryLengthPrefixed", "to", "the", "writer", "w", "." ]
dc14acf9ef15f85828bfbc561ed9dd9d2a284885
https://github.com/tendermint/go-amino/blob/dc14acf9ef15f85828bfbc561ed9dd9d2a284885/amino.go#L165-L174
test
tendermint/go-amino
amino.go
MarshalBinaryBare
func (cdc *Codec) MarshalBinaryBare(o interface{}) ([]byte, error) { // Dereference value if pointer. var rv, _, isNilPtr = derefPointers(reflect.ValueOf(o)) if isNilPtr { // NOTE: You can still do so by calling // `.MarshalBinaryLengthPrefixed(struct{ *SomeType })` or so on. panic("MarshalBinaryBare cannot m...
go
func (cdc *Codec) MarshalBinaryBare(o interface{}) ([]byte, error) { // Dereference value if pointer. var rv, _, isNilPtr = derefPointers(reflect.ValueOf(o)) if isNilPtr { // NOTE: You can still do so by calling // `.MarshalBinaryLengthPrefixed(struct{ *SomeType })` or so on. panic("MarshalBinaryBare cannot m...
[ "func", "(", "cdc", "*", "Codec", ")", "MarshalBinaryBare", "(", "o", "interface", "{", "}", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "var", "rv", ",", "_", ",", "isNilPtr", "=", "derefPointers", "(", "reflect", ".", "ValueOf", "(", "o",...
// MarshalBinaryBare encodes the object o according to the Amino spec. // MarshalBinaryBare doesn't prefix the byte-length of the encoding, // so the caller must handle framing.
[ "MarshalBinaryBare", "encodes", "the", "object", "o", "according", "to", "the", "Amino", "spec", ".", "MarshalBinaryBare", "doesn", "t", "prefix", "the", "byte", "-", "length", "of", "the", "encoding", "so", "the", "caller", "must", "handle", "framing", "." ]
dc14acf9ef15f85828bfbc561ed9dd9d2a284885
https://github.com/tendermint/go-amino/blob/dc14acf9ef15f85828bfbc561ed9dd9d2a284885/amino.go#L188-L219
test
tendermint/go-amino
amino.go
UnmarshalBinaryLengthPrefixed
func (cdc *Codec) UnmarshalBinaryLengthPrefixed(bz []byte, ptr interface{}) error { if len(bz) == 0 { return errors.New("UnmarshalBinaryLengthPrefixed cannot decode empty bytes") } // Read byte-length prefix. u64, n := binary.Uvarint(bz) if n < 0 { return fmt.Errorf("Error reading msg byte-length prefix: got ...
go
func (cdc *Codec) UnmarshalBinaryLengthPrefixed(bz []byte, ptr interface{}) error { if len(bz) == 0 { return errors.New("UnmarshalBinaryLengthPrefixed cannot decode empty bytes") } // Read byte-length prefix. u64, n := binary.Uvarint(bz) if n < 0 { return fmt.Errorf("Error reading msg byte-length prefix: got ...
[ "func", "(", "cdc", "*", "Codec", ")", "UnmarshalBinaryLengthPrefixed", "(", "bz", "[", "]", "byte", ",", "ptr", "interface", "{", "}", ")", "error", "{", "if", "len", "(", "bz", ")", "==", "0", "{", "return", "errors", ".", "New", "(", "\"UnmarshalB...
// Like UnmarshalBinaryBare, but will first decode the byte-length prefix. // UnmarshalBinaryLengthPrefixed will panic if ptr is a nil-pointer. // Returns an error if not all of bz is consumed.
[ "Like", "UnmarshalBinaryBare", "but", "will", "first", "decode", "the", "byte", "-", "length", "prefix", ".", "UnmarshalBinaryLengthPrefixed", "will", "panic", "if", "ptr", "is", "a", "nil", "-", "pointer", ".", "Returns", "an", "error", "if", "not", "all", ...
dc14acf9ef15f85828bfbc561ed9dd9d2a284885
https://github.com/tendermint/go-amino/blob/dc14acf9ef15f85828bfbc561ed9dd9d2a284885/amino.go#L233-L254
test
tendermint/go-amino
amino.go
UnmarshalBinaryBare
func (cdc *Codec) UnmarshalBinaryBare(bz []byte, ptr interface{}) error { rv := reflect.ValueOf(ptr) if rv.Kind() != reflect.Ptr { panic("Unmarshal expects a pointer") } rv = rv.Elem() rt := rv.Type() info, err := cdc.getTypeInfo_wlock(rt) if err != nil { return err } // If registered concrete, consume an...
go
func (cdc *Codec) UnmarshalBinaryBare(bz []byte, ptr interface{}) error { rv := reflect.ValueOf(ptr) if rv.Kind() != reflect.Ptr { panic("Unmarshal expects a pointer") } rv = rv.Elem() rt := rv.Type() info, err := cdc.getTypeInfo_wlock(rt) if err != nil { return err } // If registered concrete, consume an...
[ "func", "(", "cdc", "*", "Codec", ")", "UnmarshalBinaryBare", "(", "bz", "[", "]", "byte", ",", "ptr", "interface", "{", "}", ")", "error", "{", "rv", ":=", "reflect", ".", "ValueOf", "(", "ptr", ")", "\n", "if", "rv", ".", "Kind", "(", ")", "!="...
// UnmarshalBinaryBare will panic if ptr is a nil-pointer.
[ "UnmarshalBinaryBare", "will", "panic", "if", "ptr", "is", "a", "nil", "-", "pointer", "." ]
dc14acf9ef15f85828bfbc561ed9dd9d2a284885
https://github.com/tendermint/go-amino/blob/dc14acf9ef15f85828bfbc561ed9dd9d2a284885/amino.go#L321-L352
test
tendermint/go-amino
amino.go
MustMarshalJSON
func (cdc *Codec) MustMarshalJSON(o interface{}) []byte { bz, err := cdc.MarshalJSON(o) if err != nil { panic(err) } return bz }
go
func (cdc *Codec) MustMarshalJSON(o interface{}) []byte { bz, err := cdc.MarshalJSON(o) if err != nil { panic(err) } return bz }
[ "func", "(", "cdc", "*", "Codec", ")", "MustMarshalJSON", "(", "o", "interface", "{", "}", ")", "[", "]", "byte", "{", "bz", ",", "err", ":=", "cdc", ".", "MarshalJSON", "(", "o", ")", "\n", "if", "err", "!=", "nil", "{", "panic", "(", "err", "...
// MustMarshalJSON panics if an error occurs. Besides tha behaves exactly like MarshalJSON.
[ "MustMarshalJSON", "panics", "if", "an", "error", "occurs", ".", "Besides", "tha", "behaves", "exactly", "like", "MarshalJSON", "." ]
dc14acf9ef15f85828bfbc561ed9dd9d2a284885
https://github.com/tendermint/go-amino/blob/dc14acf9ef15f85828bfbc561ed9dd9d2a284885/amino.go#L403-L409
test
tendermint/go-amino
amino.go
MustUnmarshalJSON
func (cdc *Codec) MustUnmarshalJSON(bz []byte, ptr interface{}) { if err := cdc.UnmarshalJSON(bz, ptr); err != nil { panic(err) } }
go
func (cdc *Codec) MustUnmarshalJSON(bz []byte, ptr interface{}) { if err := cdc.UnmarshalJSON(bz, ptr); err != nil { panic(err) } }
[ "func", "(", "cdc", "*", "Codec", ")", "MustUnmarshalJSON", "(", "bz", "[", "]", "byte", ",", "ptr", "interface", "{", "}", ")", "{", "if", "err", ":=", "cdc", ".", "UnmarshalJSON", "(", "bz", ",", "ptr", ")", ";", "err", "!=", "nil", "{", "panic...
// MustUnmarshalJSON panics if an error occurs. Besides tha behaves exactly like UnmarshalJSON.
[ "MustUnmarshalJSON", "panics", "if", "an", "error", "occurs", ".", "Besides", "tha", "behaves", "exactly", "like", "UnmarshalJSON", "." ]
dc14acf9ef15f85828bfbc561ed9dd9d2a284885
https://github.com/tendermint/go-amino/blob/dc14acf9ef15f85828bfbc561ed9dd9d2a284885/amino.go#L443-L447
test
tendermint/go-amino
amino.go
MarshalJSONIndent
func (cdc *Codec) MarshalJSONIndent(o interface{}, prefix, indent string) ([]byte, error) { bz, err := cdc.MarshalJSON(o) if err != nil { return nil, err } var out bytes.Buffer err = json.Indent(&out, bz, prefix, indent) if err != nil { return nil, err } return out.Bytes(), nil }
go
func (cdc *Codec) MarshalJSONIndent(o interface{}, prefix, indent string) ([]byte, error) { bz, err := cdc.MarshalJSON(o) if err != nil { return nil, err } var out bytes.Buffer err = json.Indent(&out, bz, prefix, indent) if err != nil { return nil, err } return out.Bytes(), nil }
[ "func", "(", "cdc", "*", "Codec", ")", "MarshalJSONIndent", "(", "o", "interface", "{", "}", ",", "prefix", ",", "indent", "string", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "bz", ",", "err", ":=", "cdc", ".", "MarshalJSON", "(", "o", ...
// MarshalJSONIndent calls json.Indent on the output of cdc.MarshalJSON // using the given prefix and indent string.
[ "MarshalJSONIndent", "calls", "json", ".", "Indent", "on", "the", "output", "of", "cdc", ".", "MarshalJSON", "using", "the", "given", "prefix", "and", "indent", "string", "." ]
dc14acf9ef15f85828bfbc561ed9dd9d2a284885
https://github.com/tendermint/go-amino/blob/dc14acf9ef15f85828bfbc561ed9dd9d2a284885/amino.go#L451-L462
test
reiver/go-telnet
data_reader.go
newDataReader
func newDataReader(r io.Reader) *internalDataReader { buffered := bufio.NewReader(r) reader := internalDataReader{ wrapped:r, buffered:buffered, } return &reader }
go
func newDataReader(r io.Reader) *internalDataReader { buffered := bufio.NewReader(r) reader := internalDataReader{ wrapped:r, buffered:buffered, } return &reader }
[ "func", "newDataReader", "(", "r", "io", ".", "Reader", ")", "*", "internalDataReader", "{", "buffered", ":=", "bufio", ".", "NewReader", "(", "r", ")", "\n", "reader", ":=", "internalDataReader", "{", "wrapped", ":", "r", ",", "buffered", ":", "buffered",...
// newDataReader creates a new DataReader reading from 'r'.
[ "newDataReader", "creates", "a", "new", "DataReader", "reading", "from", "r", "." ]
9ff0b2ab096ebe42bf8e2ffd1366e7ed2223b04c
https://github.com/reiver/go-telnet/blob/9ff0b2ab096ebe42bf8e2ffd1366e7ed2223b04c/data_reader.go#L65-L74
test
reiver/go-telnet
data_reader.go
Read
func (r *internalDataReader) Read(data []byte) (n int, err error) { const IAC = 255 const SB = 250 const SE = 240 const WILL = 251 const WONT = 252 const DO = 253 const DONT = 254 p := data for len(p) > 0 { var b byte b, err = r.buffered.ReadByte() if nil != err { return n, err } if IAC =...
go
func (r *internalDataReader) Read(data []byte) (n int, err error) { const IAC = 255 const SB = 250 const SE = 240 const WILL = 251 const WONT = 252 const DO = 253 const DONT = 254 p := data for len(p) > 0 { var b byte b, err = r.buffered.ReadByte() if nil != err { return n, err } if IAC =...
[ "func", "(", "r", "*", "internalDataReader", ")", "Read", "(", "data", "[", "]", "byte", ")", "(", "n", "int", ",", "err", "error", ")", "{", "const", "IAC", "=", "255", "\n", "const", "SB", "=", "250", "\n", "const", "SE", "=", "240", "\n", "c...
// Read reads the TELNET escaped data from the wrapped io.Reader, and "un-escapes" it into 'data'.
[ "Read", "reads", "the", "TELNET", "escaped", "data", "from", "the", "wrapped", "io", ".", "Reader", "and", "un", "-", "escapes", "it", "into", "data", "." ]
9ff0b2ab096ebe42bf8e2ffd1366e7ed2223b04c
https://github.com/reiver/go-telnet/blob/9ff0b2ab096ebe42bf8e2ffd1366e7ed2223b04c/data_reader.go#L78-L173
test
reiver/go-telnet
tls.go
ListenAndServeTLS
func (server *Server) ListenAndServeTLS(certFile string, keyFile string) error { addr := server.Addr if "" == addr { addr = ":telnets" } listener, err := net.Listen("tcp", addr) if nil != err { return err } // Apparently have to make a copy of the TLS config this way, rather than by // simple assignmen...
go
func (server *Server) ListenAndServeTLS(certFile string, keyFile string) error { addr := server.Addr if "" == addr { addr = ":telnets" } listener, err := net.Listen("tcp", addr) if nil != err { return err } // Apparently have to make a copy of the TLS config this way, rather than by // simple assignmen...
[ "func", "(", "server", "*", "Server", ")", "ListenAndServeTLS", "(", "certFile", "string", ",", "keyFile", "string", ")", "error", "{", "addr", ":=", "server", ".", "Addr", "\n", "if", "\"\"", "==", "addr", "{", "addr", "=", "\":telnets\"", "\n", "}", ...
// ListenAndServeTLS acts identically to ListenAndServe, except that it // uses the TELNET protocol over TLS. // // From a TELNET protocol point-of-view, it allows for 'secured telnet', also known as TELNETS, // which by default listens to port 992.
[ "ListenAndServeTLS", "acts", "identically", "to", "ListenAndServe", "except", "that", "it", "uses", "the", "TELNET", "protocol", "over", "TLS", ".", "From", "a", "TELNET", "protocol", "point", "-", "of", "-", "view", "it", "allows", "for", "secured", "telnet",...
9ff0b2ab096ebe42bf8e2ffd1366e7ed2223b04c
https://github.com/reiver/go-telnet/blob/9ff0b2ab096ebe42bf8e2ffd1366e7ed2223b04c/tls.go#L49-L113
test
reiver/go-telnet
telsh/producer.go
Produce
func (fn ProducerFunc) Produce(ctx telnet.Context, name string, args ...string) Handler { return fn(ctx, name, args...) }
go
func (fn ProducerFunc) Produce(ctx telnet.Context, name string, args ...string) Handler { return fn(ctx, name, args...) }
[ "func", "(", "fn", "ProducerFunc", ")", "Produce", "(", "ctx", "telnet", ".", "Context", ",", "name", "string", ",", "args", "...", "string", ")", "Handler", "{", "return", "fn", "(", "ctx", ",", "name", ",", "args", "...", ")", "\n", "}" ]
// Produce makes ProducerFunc fit the Producer interface.
[ "Produce", "makes", "ProducerFunc", "fit", "the", "Producer", "interface", "." ]
9ff0b2ab096ebe42bf8e2ffd1366e7ed2223b04c
https://github.com/reiver/go-telnet/blob/9ff0b2ab096ebe42bf8e2ffd1366e7ed2223b04c/telsh/producer.go#L34-L36
test
reiver/go-telnet
telsh/handler.go
PromoteHandlerFunc
func PromoteHandlerFunc(fn HandlerFunc, args ...string) Handler { stdin, stdinPipe := io.Pipe() stdoutPipe, stdout := io.Pipe() stderrPipe, stderr := io.Pipe() argsCopy := make([]string, len(args)) for i, datum := range args { argsCopy[i] = datum } handler := internalPromotedHandlerFunc{ err:nil...
go
func PromoteHandlerFunc(fn HandlerFunc, args ...string) Handler { stdin, stdinPipe := io.Pipe() stdoutPipe, stdout := io.Pipe() stderrPipe, stderr := io.Pipe() argsCopy := make([]string, len(args)) for i, datum := range args { argsCopy[i] = datum } handler := internalPromotedHandlerFunc{ err:nil...
[ "func", "PromoteHandlerFunc", "(", "fn", "HandlerFunc", ",", "args", "...", "string", ")", "Handler", "{", "stdin", ",", "stdinPipe", ":=", "io", ".", "Pipe", "(", ")", "\n", "stdoutPipe", ",", "stdout", ":=", "io", ".", "Pipe", "(", ")", "\n", "stderr...
// PromoteHandlerFunc turns a HandlerFunc into a Handler.
[ "PromoteHandlerFunc", "turns", "a", "HandlerFunc", "into", "a", "Handler", "." ]
9ff0b2ab096ebe42bf8e2ffd1366e7ed2223b04c
https://github.com/reiver/go-telnet/blob/9ff0b2ab096ebe42bf8e2ffd1366e7ed2223b04c/telsh/handler.go#L74-L101
test
reiver/go-telnet
server.go
Serve
func Serve(listener net.Listener, handler Handler) error { server := &Server{Handler: handler} return server.Serve(listener) }
go
func Serve(listener net.Listener, handler Handler) error { server := &Server{Handler: handler} return server.Serve(listener) }
[ "func", "Serve", "(", "listener", "net", ".", "Listener", ",", "handler", "Handler", ")", "error", "{", "server", ":=", "&", "Server", "{", "Handler", ":", "handler", "}", "\n", "return", "server", ".", "Serve", "(", "listener", ")", "\n", "}" ]
// Serve accepts an incoming TELNET or TELNETS client connection on the net.Listener `listener`.
[ "Serve", "accepts", "an", "incoming", "TELNET", "or", "TELNETS", "client", "connection", "on", "the", "net", ".", "Listener", "listener", "." ]
9ff0b2ab096ebe42bf8e2ffd1366e7ed2223b04c
https://github.com/reiver/go-telnet/blob/9ff0b2ab096ebe42bf8e2ffd1366e7ed2223b04c/server.go#L39-L43
test
reiver/go-telnet
server.go
Serve
func (server *Server) Serve(listener net.Listener) error { defer listener.Close() logger := server.logger() handler := server.Handler if nil == handler { //@TODO: Should this be a "ShellHandler" instead, that gives a shell-like experience by default // If this is changd, then need to change the comment i...
go
func (server *Server) Serve(listener net.Listener) error { defer listener.Close() logger := server.logger() handler := server.Handler if nil == handler { //@TODO: Should this be a "ShellHandler" instead, that gives a shell-like experience by default // If this is changd, then need to change the comment i...
[ "func", "(", "server", "*", "Server", ")", "Serve", "(", "listener", "net", ".", "Listener", ")", "error", "{", "defer", "listener", ".", "Close", "(", ")", "\n", "logger", ":=", "server", ".", "logger", "(", ")", "\n", "handler", ":=", "server", "."...
// Serve accepts an incoming TELNET client connection on the net.Listener `listener`.
[ "Serve", "accepts", "an", "incoming", "TELNET", "client", "connection", "on", "the", "net", ".", "Listener", "listener", "." ]
9ff0b2ab096ebe42bf8e2ffd1366e7ed2223b04c
https://github.com/reiver/go-telnet/blob/9ff0b2ab096ebe42bf8e2ffd1366e7ed2223b04c/server.go#L125-L157
test
alexflint/go-arg
usage.go
Fail
func (p *Parser) Fail(msg string) { p.WriteUsage(os.Stderr) fmt.Fprintln(os.Stderr, "error:", msg) os.Exit(-1) }
go
func (p *Parser) Fail(msg string) { p.WriteUsage(os.Stderr) fmt.Fprintln(os.Stderr, "error:", msg) os.Exit(-1) }
[ "func", "(", "p", "*", "Parser", ")", "Fail", "(", "msg", "string", ")", "{", "p", ".", "WriteUsage", "(", "os", ".", "Stderr", ")", "\n", "fmt", ".", "Fprintln", "(", "os", ".", "Stderr", ",", "\"error:\"", ",", "msg", ")", "\n", "os", ".", "E...
// Fail prints usage information to stderr and exits with non-zero status
[ "Fail", "prints", "usage", "information", "to", "stderr", "and", "exits", "with", "non", "-", "zero", "status" ]
fb1ae1c3e0bd00d45333c3d51384afc05846f7a0
https://github.com/alexflint/go-arg/blob/fb1ae1c3e0bd00d45333c3d51384afc05846f7a0/usage.go#L16-L20
test
alexflint/go-arg
usage.go
WriteUsage
func (p *Parser) WriteUsage(w io.Writer) { var positionals, options []*spec for _, spec := range p.specs { if spec.positional { positionals = append(positionals, spec) } else { options = append(options, spec) } } if p.version != "" { fmt.Fprintln(w, p.version) } fmt.Fprintf(w, "Usage: %s", p.confi...
go
func (p *Parser) WriteUsage(w io.Writer) { var positionals, options []*spec for _, spec := range p.specs { if spec.positional { positionals = append(positionals, spec) } else { options = append(options, spec) } } if p.version != "" { fmt.Fprintln(w, p.version) } fmt.Fprintf(w, "Usage: %s", p.confi...
[ "func", "(", "p", "*", "Parser", ")", "WriteUsage", "(", "w", "io", ".", "Writer", ")", "{", "var", "positionals", ",", "options", "[", "]", "*", "spec", "\n", "for", "_", ",", "spec", ":=", "range", "p", ".", "specs", "{", "if", "spec", ".", "...
// WriteUsage writes usage information to the given writer
[ "WriteUsage", "writes", "usage", "information", "to", "the", "given", "writer" ]
fb1ae1c3e0bd00d45333c3d51384afc05846f7a0
https://github.com/alexflint/go-arg/blob/fb1ae1c3e0bd00d45333c3d51384afc05846f7a0/usage.go#L23-L70
test
alexflint/go-arg
usage.go
WriteHelp
func (p *Parser) WriteHelp(w io.Writer) { var positionals, options []*spec for _, spec := range p.specs { if spec.positional { positionals = append(positionals, spec) } else { options = append(options, spec) } } if p.description != "" { fmt.Fprintln(w, p.description) } p.WriteUsage(w) // write th...
go
func (p *Parser) WriteHelp(w io.Writer) { var positionals, options []*spec for _, spec := range p.specs { if spec.positional { positionals = append(positionals, spec) } else { options = append(options, spec) } } if p.description != "" { fmt.Fprintln(w, p.description) } p.WriteUsage(w) // write th...
[ "func", "(", "p", "*", "Parser", ")", "WriteHelp", "(", "w", "io", ".", "Writer", ")", "{", "var", "positionals", ",", "options", "[", "]", "*", "spec", "\n", "for", "_", ",", "spec", ":=", "range", "p", ".", "specs", "{", "if", "spec", ".", "p...
// WriteHelp writes the usage string followed by the full help string for each option
[ "WriteHelp", "writes", "the", "usage", "string", "followed", "by", "the", "full", "help", "string", "for", "each", "option" ]
fb1ae1c3e0bd00d45333c3d51384afc05846f7a0
https://github.com/alexflint/go-arg/blob/fb1ae1c3e0bd00d45333c3d51384afc05846f7a0/usage.go#L73-L117
test
alexflint/go-arg
parse.go
MustParse
func MustParse(dest ...interface{}) *Parser { p, err := NewParser(Config{}, dest...) if err != nil { fmt.Println(err) os.Exit(-1) } err = p.Parse(flags()) if err == ErrHelp { p.WriteHelp(os.Stdout) os.Exit(0) } if err == ErrVersion { fmt.Println(p.version) os.Exit(0) } if err != nil { p.Fail(err....
go
func MustParse(dest ...interface{}) *Parser { p, err := NewParser(Config{}, dest...) if err != nil { fmt.Println(err) os.Exit(-1) } err = p.Parse(flags()) if err == ErrHelp { p.WriteHelp(os.Stdout) os.Exit(0) } if err == ErrVersion { fmt.Println(p.version) os.Exit(0) } if err != nil { p.Fail(err....
[ "func", "MustParse", "(", "dest", "...", "interface", "{", "}", ")", "*", "Parser", "{", "p", ",", "err", ":=", "NewParser", "(", "Config", "{", "}", ",", "dest", "...", ")", "\n", "if", "err", "!=", "nil", "{", "fmt", ".", "Println", "(", "err",...
// MustParse processes command line arguments and exits upon failure
[ "MustParse", "processes", "command", "line", "arguments", "and", "exits", "upon", "failure" ]
fb1ae1c3e0bd00d45333c3d51384afc05846f7a0
https://github.com/alexflint/go-arg/blob/fb1ae1c3e0bd00d45333c3d51384afc05846f7a0/parse.go#L37-L56
test
alexflint/go-arg
parse.go
Parse
func Parse(dest ...interface{}) error { p, err := NewParser(Config{}, dest...) if err != nil { return err } return p.Parse(flags()) }
go
func Parse(dest ...interface{}) error { p, err := NewParser(Config{}, dest...) if err != nil { return err } return p.Parse(flags()) }
[ "func", "Parse", "(", "dest", "...", "interface", "{", "}", ")", "error", "{", "p", ",", "err", ":=", "NewParser", "(", "Config", "{", "}", ",", "dest", "...", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", ...
// Parse processes command line arguments and stores them in dest
[ "Parse", "processes", "command", "line", "arguments", "and", "stores", "them", "in", "dest" ]
fb1ae1c3e0bd00d45333c3d51384afc05846f7a0
https://github.com/alexflint/go-arg/blob/fb1ae1c3e0bd00d45333c3d51384afc05846f7a0/parse.go#L59-L65
test
alexflint/go-arg
parse.go
walkFields
func walkFields(v reflect.Value, visit func(field reflect.StructField, val reflect.Value, owner reflect.Type) bool) { t := v.Type() for i := 0; i < t.NumField(); i++ { field := t.Field(i) val := v.Field(i) expand := visit(field, val, t) if expand && field.Type.Kind() == reflect.Struct { walkFields(val, vis...
go
func walkFields(v reflect.Value, visit func(field reflect.StructField, val reflect.Value, owner reflect.Type) bool) { t := v.Type() for i := 0; i < t.NumField(); i++ { field := t.Field(i) val := v.Field(i) expand := visit(field, val, t) if expand && field.Type.Kind() == reflect.Struct { walkFields(val, vis...
[ "func", "walkFields", "(", "v", "reflect", ".", "Value", ",", "visit", "func", "(", "field", "reflect", ".", "StructField", ",", "val", "reflect", ".", "Value", ",", "owner", "reflect", ".", "Type", ")", "bool", ")", "{", "t", ":=", "v", ".", "Type",...
// walkFields calls a function for each field of a struct, recursively expanding struct fields.
[ "walkFields", "calls", "a", "function", "for", "each", "field", "of", "a", "struct", "recursively", "expanding", "struct", "fields", "." ]
fb1ae1c3e0bd00d45333c3d51384afc05846f7a0
https://github.com/alexflint/go-arg/blob/fb1ae1c3e0bd00d45333c3d51384afc05846f7a0/parse.go#L105-L115
test
alexflint/go-arg
parse.go
Parse
func (p *Parser) Parse(args []string) error { // If -h or --help were specified then print usage for _, arg := range args { if arg == "-h" || arg == "--help" { return ErrHelp } if arg == "--version" { return ErrVersion } if arg == "--" { break } } // Process all command line arguments return ...
go
func (p *Parser) Parse(args []string) error { // If -h or --help were specified then print usage for _, arg := range args { if arg == "-h" || arg == "--help" { return ErrHelp } if arg == "--version" { return ErrVersion } if arg == "--" { break } } // Process all command line arguments return ...
[ "func", "(", "p", "*", "Parser", ")", "Parse", "(", "args", "[", "]", "string", ")", "error", "{", "for", "_", ",", "arg", ":=", "range", "args", "{", "if", "arg", "==", "\"-h\"", "||", "arg", "==", "\"--help\"", "{", "return", "ErrHelp", "\n", "...
// Parse processes the given command line option, storing the results in the field // of the structs from which NewParser was constructed
[ "Parse", "processes", "the", "given", "command", "line", "option", "storing", "the", "results", "in", "the", "field", "of", "the", "structs", "from", "which", "NewParser", "was", "constructed" ]
fb1ae1c3e0bd00d45333c3d51384afc05846f7a0
https://github.com/alexflint/go-arg/blob/fb1ae1c3e0bd00d45333c3d51384afc05846f7a0/parse.go#L237-L253
test
alexflint/go-arg
parse.go
setSlice
func setSlice(dest reflect.Value, values []string, trunc bool) error { if !dest.CanSet() { return fmt.Errorf("field is not writable") } var ptr bool elem := dest.Type().Elem() if elem.Kind() == reflect.Ptr && !elem.Implements(textUnmarshalerType) { ptr = true elem = elem.Elem() } // Truncate the dest sli...
go
func setSlice(dest reflect.Value, values []string, trunc bool) error { if !dest.CanSet() { return fmt.Errorf("field is not writable") } var ptr bool elem := dest.Type().Elem() if elem.Kind() == reflect.Ptr && !elem.Implements(textUnmarshalerType) { ptr = true elem = elem.Elem() } // Truncate the dest sli...
[ "func", "setSlice", "(", "dest", "reflect", ".", "Value", ",", "values", "[", "]", "string", ",", "trunc", "bool", ")", "error", "{", "if", "!", "dest", ".", "CanSet", "(", ")", "{", "return", "fmt", ".", "Errorf", "(", "\"field is not writable\"", ")"...
// parse a value as the appropriate type and store it in the struct
[ "parse", "a", "value", "as", "the", "appropriate", "type", "and", "store", "it", "in", "the", "struct" ]
fb1ae1c3e0bd00d45333c3d51384afc05846f7a0
https://github.com/alexflint/go-arg/blob/fb1ae1c3e0bd00d45333c3d51384afc05846f7a0/parse.go#L449-L477
test
alexflint/go-arg
parse.go
canParse
func canParse(t reflect.Type) (parseable, boolean, multiple bool) { parseable = scalar.CanParse(t) boolean = isBoolean(t) if parseable { return } // Look inside pointer types if t.Kind() == reflect.Ptr { t = t.Elem() } // Look inside slice types if t.Kind() == reflect.Slice { multiple = true t = t.Ele...
go
func canParse(t reflect.Type) (parseable, boolean, multiple bool) { parseable = scalar.CanParse(t) boolean = isBoolean(t) if parseable { return } // Look inside pointer types if t.Kind() == reflect.Ptr { t = t.Elem() } // Look inside slice types if t.Kind() == reflect.Slice { multiple = true t = t.Ele...
[ "func", "canParse", "(", "t", "reflect", ".", "Type", ")", "(", "parseable", ",", "boolean", ",", "multiple", "bool", ")", "{", "parseable", "=", "scalar", ".", "CanParse", "(", "t", ")", "\n", "boolean", "=", "isBoolean", "(", "t", ")", "\n", "if", ...
// canParse returns true if the type can be parsed from a string
[ "canParse", "returns", "true", "if", "the", "type", "can", "be", "parsed", "from", "a", "string" ]
fb1ae1c3e0bd00d45333c3d51384afc05846f7a0
https://github.com/alexflint/go-arg/blob/fb1ae1c3e0bd00d45333c3d51384afc05846f7a0/parse.go#L480-L515
test
alexflint/go-arg
parse.go
isBoolean
func isBoolean(t reflect.Type) bool { switch { case t.Implements(textUnmarshalerType): return false case t.Kind() == reflect.Bool: return true case t.Kind() == reflect.Ptr && t.Elem().Kind() == reflect.Bool: return true default: return false } }
go
func isBoolean(t reflect.Type) bool { switch { case t.Implements(textUnmarshalerType): return false case t.Kind() == reflect.Bool: return true case t.Kind() == reflect.Ptr && t.Elem().Kind() == reflect.Bool: return true default: return false } }
[ "func", "isBoolean", "(", "t", "reflect", ".", "Type", ")", "bool", "{", "switch", "{", "case", "t", ".", "Implements", "(", "textUnmarshalerType", ")", ":", "return", "false", "\n", "case", "t", ".", "Kind", "(", ")", "==", "reflect", ".", "Bool", "...
// isBoolean returns true if the type can be parsed from a single string
[ "isBoolean", "returns", "true", "if", "the", "type", "can", "be", "parsed", "from", "a", "single", "string" ]
fb1ae1c3e0bd00d45333c3d51384afc05846f7a0
https://github.com/alexflint/go-arg/blob/fb1ae1c3e0bd00d45333c3d51384afc05846f7a0/parse.go#L520-L531
test
armon/go-radix
radix.go
NewFromMap
func NewFromMap(m map[string]interface{}) *Tree { t := &Tree{root: &node{}} for k, v := range m { t.Insert(k, v) } return t }
go
func NewFromMap(m map[string]interface{}) *Tree { t := &Tree{root: &node{}} for k, v := range m { t.Insert(k, v) } return t }
[ "func", "NewFromMap", "(", "m", "map", "[", "string", "]", "interface", "{", "}", ")", "*", "Tree", "{", "t", ":=", "&", "Tree", "{", "root", ":", "&", "node", "{", "}", "}", "\n", "for", "k", ",", "v", ":=", "range", "m", "{", "t", ".", "I...
// NewFromMap returns a new tree containing the keys // from an existing map
[ "NewFromMap", "returns", "a", "new", "tree", "containing", "the", "keys", "from", "an", "existing", "map" ]
1a2de0c21c94309923825da3df33a4381872c795
https://github.com/armon/go-radix/blob/1a2de0c21c94309923825da3df33a4381872c795/radix.go#L116-L122
test
armon/go-radix
radix.go
Insert
func (t *Tree) Insert(s string, v interface{}) (interface{}, bool) { var parent *node n := t.root search := s for { // Handle key exhaution if len(search) == 0 { if n.isLeaf() { old := n.leaf.val n.leaf.val = v return old, true } n.leaf = &leafNode{ key: s, val: v, } t.size++...
go
func (t *Tree) Insert(s string, v interface{}) (interface{}, bool) { var parent *node n := t.root search := s for { // Handle key exhaution if len(search) == 0 { if n.isLeaf() { old := n.leaf.val n.leaf.val = v return old, true } n.leaf = &leafNode{ key: s, val: v, } t.size++...
[ "func", "(", "t", "*", "Tree", ")", "Insert", "(", "s", "string", ",", "v", "interface", "{", "}", ")", "(", "interface", "{", "}", ",", "bool", ")", "{", "var", "parent", "*", "node", "\n", "n", ":=", "t", ".", "root", "\n", "search", ":=", ...
// Insert is used to add a newentry or update // an existing entry. Returns if updated.
[ "Insert", "is", "used", "to", "add", "a", "newentry", "or", "update", "an", "existing", "entry", ".", "Returns", "if", "updated", "." ]
1a2de0c21c94309923825da3df33a4381872c795
https://github.com/armon/go-radix/blob/1a2de0c21c94309923825da3df33a4381872c795/radix.go#L147-L233
test
armon/go-radix
radix.go
Delete
func (t *Tree) Delete(s string) (interface{}, bool) { var parent *node var label byte n := t.root search := s for { // Check for key exhaution if len(search) == 0 { if !n.isLeaf() { break } goto DELETE } // Look for an edge parent = n label = search[0] n = n.getEdge(label) if n == nil...
go
func (t *Tree) Delete(s string) (interface{}, bool) { var parent *node var label byte n := t.root search := s for { // Check for key exhaution if len(search) == 0 { if !n.isLeaf() { break } goto DELETE } // Look for an edge parent = n label = search[0] n = n.getEdge(label) if n == nil...
[ "func", "(", "t", "*", "Tree", ")", "Delete", "(", "s", "string", ")", "(", "interface", "{", "}", ",", "bool", ")", "{", "var", "parent", "*", "node", "\n", "var", "label", "byte", "\n", "n", ":=", "t", ".", "root", "\n", "search", ":=", "s", ...
// Delete is used to delete a key, returning the previous // value and if it was deleted
[ "Delete", "is", "used", "to", "delete", "a", "key", "returning", "the", "previous", "value", "and", "if", "it", "was", "deleted" ]
1a2de0c21c94309923825da3df33a4381872c795
https://github.com/armon/go-radix/blob/1a2de0c21c94309923825da3df33a4381872c795/radix.go#L237-L290
test
armon/go-radix
radix.go
DeletePrefix
func (t *Tree) DeletePrefix(s string) int { return t.deletePrefix(nil, t.root, s) }
go
func (t *Tree) DeletePrefix(s string) int { return t.deletePrefix(nil, t.root, s) }
[ "func", "(", "t", "*", "Tree", ")", "DeletePrefix", "(", "s", "string", ")", "int", "{", "return", "t", ".", "deletePrefix", "(", "nil", ",", "t", ".", "root", ",", "s", ")", "\n", "}" ]
// DeletePrefix is used to delete the subtree under a prefix // Returns how many nodes were deleted // Use this to delete large subtrees efficiently
[ "DeletePrefix", "is", "used", "to", "delete", "the", "subtree", "under", "a", "prefix", "Returns", "how", "many", "nodes", "were", "deleted", "Use", "this", "to", "delete", "large", "subtrees", "efficiently" ]
1a2de0c21c94309923825da3df33a4381872c795
https://github.com/armon/go-radix/blob/1a2de0c21c94309923825da3df33a4381872c795/radix.go#L295-L297
test
armon/go-radix
radix.go
deletePrefix
func (t *Tree) deletePrefix(parent, n *node, prefix string) int { // Check for key exhaustion if len(prefix) == 0 { // Remove the leaf node subTreeSize := 0 //recursively walk from all edges of the node to be deleted recursiveWalk(n, func(s string, v interface{}) bool { subTreeSize++ return false }) ...
go
func (t *Tree) deletePrefix(parent, n *node, prefix string) int { // Check for key exhaustion if len(prefix) == 0 { // Remove the leaf node subTreeSize := 0 //recursively walk from all edges of the node to be deleted recursiveWalk(n, func(s string, v interface{}) bool { subTreeSize++ return false }) ...
[ "func", "(", "t", "*", "Tree", ")", "deletePrefix", "(", "parent", ",", "n", "*", "node", ",", "prefix", "string", ")", "int", "{", "if", "len", "(", "prefix", ")", "==", "0", "{", "subTreeSize", ":=", "0", "\n", "recursiveWalk", "(", "n", ",", "...
// delete does a recursive deletion
[ "delete", "does", "a", "recursive", "deletion" ]
1a2de0c21c94309923825da3df33a4381872c795
https://github.com/armon/go-radix/blob/1a2de0c21c94309923825da3df33a4381872c795/radix.go#L300-L337
test
armon/go-radix
radix.go
Get
func (t *Tree) Get(s string) (interface{}, bool) { n := t.root search := s for { // Check for key exhaution if len(search) == 0 { if n.isLeaf() { return n.leaf.val, true } break } // Look for an edge n = n.getEdge(search[0]) if n == nil { break } // Consume the search prefix if st...
go
func (t *Tree) Get(s string) (interface{}, bool) { n := t.root search := s for { // Check for key exhaution if len(search) == 0 { if n.isLeaf() { return n.leaf.val, true } break } // Look for an edge n = n.getEdge(search[0]) if n == nil { break } // Consume the search prefix if st...
[ "func", "(", "t", "*", "Tree", ")", "Get", "(", "s", "string", ")", "(", "interface", "{", "}", ",", "bool", ")", "{", "n", ":=", "t", ".", "root", "\n", "search", ":=", "s", "\n", "for", "{", "if", "len", "(", "search", ")", "==", "0", "{"...
// Get is used to lookup a specific key, returning // the value and if it was found
[ "Get", "is", "used", "to", "lookup", "a", "specific", "key", "returning", "the", "value", "and", "if", "it", "was", "found" ]
1a2de0c21c94309923825da3df33a4381872c795
https://github.com/armon/go-radix/blob/1a2de0c21c94309923825da3df33a4381872c795/radix.go#L349-L375
test
armon/go-radix
radix.go
LongestPrefix
func (t *Tree) LongestPrefix(s string) (string, interface{}, bool) { var last *leafNode n := t.root search := s for { // Look for a leaf node if n.isLeaf() { last = n.leaf } // Check for key exhaution if len(search) == 0 { break } // Look for an edge n = n.getEdge(search[0]) if n == nil { ...
go
func (t *Tree) LongestPrefix(s string) (string, interface{}, bool) { var last *leafNode n := t.root search := s for { // Look for a leaf node if n.isLeaf() { last = n.leaf } // Check for key exhaution if len(search) == 0 { break } // Look for an edge n = n.getEdge(search[0]) if n == nil { ...
[ "func", "(", "t", "*", "Tree", ")", "LongestPrefix", "(", "s", "string", ")", "(", "string", ",", "interface", "{", "}", ",", "bool", ")", "{", "var", "last", "*", "leafNode", "\n", "n", ":=", "t", ".", "root", "\n", "search", ":=", "s", "\n", ...
// LongestPrefix is like Get, but instead of an // exact match, it will return the longest prefix match.
[ "LongestPrefix", "is", "like", "Get", "but", "instead", "of", "an", "exact", "match", "it", "will", "return", "the", "longest", "prefix", "match", "." ]
1a2de0c21c94309923825da3df33a4381872c795
https://github.com/armon/go-radix/blob/1a2de0c21c94309923825da3df33a4381872c795/radix.go#L379-L411
test
armon/go-radix
radix.go
Minimum
func (t *Tree) Minimum() (string, interface{}, bool) { n := t.root for { if n.isLeaf() { return n.leaf.key, n.leaf.val, true } if len(n.edges) > 0 { n = n.edges[0].node } else { break } } return "", nil, false }
go
func (t *Tree) Minimum() (string, interface{}, bool) { n := t.root for { if n.isLeaf() { return n.leaf.key, n.leaf.val, true } if len(n.edges) > 0 { n = n.edges[0].node } else { break } } return "", nil, false }
[ "func", "(", "t", "*", "Tree", ")", "Minimum", "(", ")", "(", "string", ",", "interface", "{", "}", ",", "bool", ")", "{", "n", ":=", "t", ".", "root", "\n", "for", "{", "if", "n", ".", "isLeaf", "(", ")", "{", "return", "n", ".", "leaf", "...
// Minimum is used to return the minimum value in the tree
[ "Minimum", "is", "used", "to", "return", "the", "minimum", "value", "in", "the", "tree" ]
1a2de0c21c94309923825da3df33a4381872c795
https://github.com/armon/go-radix/blob/1a2de0c21c94309923825da3df33a4381872c795/radix.go#L414-L427
test
armon/go-radix
radix.go
WalkPrefix
func (t *Tree) WalkPrefix(prefix string, fn WalkFn) { n := t.root search := prefix for { // Check for key exhaution if len(search) == 0 { recursiveWalk(n, fn) return } // Look for an edge n = n.getEdge(search[0]) if n == nil { break } // Consume the search prefix if strings.HasPrefix(sea...
go
func (t *Tree) WalkPrefix(prefix string, fn WalkFn) { n := t.root search := prefix for { // Check for key exhaution if len(search) == 0 { recursiveWalk(n, fn) return } // Look for an edge n = n.getEdge(search[0]) if n == nil { break } // Consume the search prefix if strings.HasPrefix(sea...
[ "func", "(", "t", "*", "Tree", ")", "WalkPrefix", "(", "prefix", "string", ",", "fn", "WalkFn", ")", "{", "n", ":=", "t", ".", "root", "\n", "search", ":=", "prefix", "\n", "for", "{", "if", "len", "(", "search", ")", "==", "0", "{", "recursiveWa...
// WalkPrefix is used to walk the tree under a prefix
[ "WalkPrefix", "is", "used", "to", "walk", "the", "tree", "under", "a", "prefix" ]
1a2de0c21c94309923825da3df33a4381872c795
https://github.com/armon/go-radix/blob/1a2de0c21c94309923825da3df33a4381872c795/radix.go#L451-L480
test
armon/go-radix
radix.go
recursiveWalk
func recursiveWalk(n *node, fn WalkFn) bool { // Visit the leaf values if any if n.leaf != nil && fn(n.leaf.key, n.leaf.val) { return true } // Recurse on the children for _, e := range n.edges { if recursiveWalk(e.node, fn) { return true } } return false }
go
func recursiveWalk(n *node, fn WalkFn) bool { // Visit the leaf values if any if n.leaf != nil && fn(n.leaf.key, n.leaf.val) { return true } // Recurse on the children for _, e := range n.edges { if recursiveWalk(e.node, fn) { return true } } return false }
[ "func", "recursiveWalk", "(", "n", "*", "node", ",", "fn", "WalkFn", ")", "bool", "{", "if", "n", ".", "leaf", "!=", "nil", "&&", "fn", "(", "n", ".", "leaf", ".", "key", ",", "n", ".", "leaf", ".", "val", ")", "{", "return", "true", "\n", "}...
// recursiveWalk is used to do a pre-order walk of a node // recursively. Returns true if the walk should be aborted
[ "recursiveWalk", "is", "used", "to", "do", "a", "pre", "-", "order", "walk", "of", "a", "node", "recursively", ".", "Returns", "true", "if", "the", "walk", "should", "be", "aborted" ]
1a2de0c21c94309923825da3df33a4381872c795
https://github.com/armon/go-radix/blob/1a2de0c21c94309923825da3df33a4381872c795/radix.go#L517-L530
test
armon/go-radix
radix.go
ToMap
func (t *Tree) ToMap() map[string]interface{} { out := make(map[string]interface{}, t.size) t.Walk(func(k string, v interface{}) bool { out[k] = v return false }) return out }
go
func (t *Tree) ToMap() map[string]interface{} { out := make(map[string]interface{}, t.size) t.Walk(func(k string, v interface{}) bool { out[k] = v return false }) return out }
[ "func", "(", "t", "*", "Tree", ")", "ToMap", "(", ")", "map", "[", "string", "]", "interface", "{", "}", "{", "out", ":=", "make", "(", "map", "[", "string", "]", "interface", "{", "}", ",", "t", ".", "size", ")", "\n", "t", ".", "Walk", "(",...
// ToMap is used to walk the tree and convert it into a map
[ "ToMap", "is", "used", "to", "walk", "the", "tree", "and", "convert", "it", "into", "a", "map" ]
1a2de0c21c94309923825da3df33a4381872c795
https://github.com/armon/go-radix/blob/1a2de0c21c94309923825da3df33a4381872c795/radix.go#L533-L540
test
ip2location/ip2location-go
ip2location.go
checkip
func checkip(ip string) (iptype uint32, ipnum *big.Int, ipindex uint32) { iptype = 0 ipnum = big.NewInt(0) ipnumtmp := big.NewInt(0) ipindex = 0 ipaddress := net.ParseIP(ip) if ipaddress != nil { v4 := ipaddress.To4() if v4 != nil { iptype = 4 ipnum.SetBytes(v4) } else { v6 := ipaddress.To16()...
go
func checkip(ip string) (iptype uint32, ipnum *big.Int, ipindex uint32) { iptype = 0 ipnum = big.NewInt(0) ipnumtmp := big.NewInt(0) ipindex = 0 ipaddress := net.ParseIP(ip) if ipaddress != nil { v4 := ipaddress.To4() if v4 != nil { iptype = 4 ipnum.SetBytes(v4) } else { v6 := ipaddress.To16()...
[ "func", "checkip", "(", "ip", "string", ")", "(", "iptype", "uint32", ",", "ipnum", "*", "big", ".", "Int", ",", "ipindex", "uint32", ")", "{", "iptype", "=", "0", "\n", "ipnum", "=", "big", ".", "NewInt", "(", "0", ")", "\n", "ipnumtmp", ":=", "...
// get IP type and calculate IP number; calculates index too if exists
[ "get", "IP", "type", "and", "calculate", "IP", "number", ";", "calculates", "index", "too", "if", "exists" ]
a417f19539fd2a0eb0adf273b4190241cacc0499
https://github.com/ip2location/ip2location-go/blob/a417f19539fd2a0eb0adf273b4190241cacc0499/ip2location.go#L150-L186
test
ip2location/ip2location-go
ip2location.go
readuint32
func readuint32(pos uint32) uint32 { pos2 := int64(pos) var retval uint32 data := make([]byte, 4) _, err := f.ReadAt(data, pos2 - 1) if err != nil { fmt.Println("File read failed:", err) } buf := bytes.NewReader(data) err = binary.Read(buf, binary.LittleEndian, &retval) if err != nil { fmt.Println("Binary ...
go
func readuint32(pos uint32) uint32 { pos2 := int64(pos) var retval uint32 data := make([]byte, 4) _, err := f.ReadAt(data, pos2 - 1) if err != nil { fmt.Println("File read failed:", err) } buf := bytes.NewReader(data) err = binary.Read(buf, binary.LittleEndian, &retval) if err != nil { fmt.Println("Binary ...
[ "func", "readuint32", "(", "pos", "uint32", ")", "uint32", "{", "pos2", ":=", "int64", "(", "pos", ")", "\n", "var", "retval", "uint32", "\n", "data", ":=", "make", "(", "[", "]", "byte", ",", "4", ")", "\n", "_", ",", "err", ":=", "f", ".", "R...
// read unsigned 32-bit integer
[ "read", "unsigned", "32", "-", "bit", "integer" ]
a417f19539fd2a0eb0adf273b4190241cacc0499
https://github.com/ip2location/ip2location-go/blob/a417f19539fd2a0eb0adf273b4190241cacc0499/ip2location.go#L201-L215
test
ip2location/ip2location-go
ip2location.go
readuint128
func readuint128(pos uint32) *big.Int { pos2 := int64(pos) retval := big.NewInt(0) data := make([]byte, 16) _, err := f.ReadAt(data, pos2 - 1) if err != nil { fmt.Println("File read failed:", err) } // little endian to big endian for i, j := 0, len(data)-1; i < j; i, j = i+1, j-1 { data[i], data[j] = data...
go
func readuint128(pos uint32) *big.Int { pos2 := int64(pos) retval := big.NewInt(0) data := make([]byte, 16) _, err := f.ReadAt(data, pos2 - 1) if err != nil { fmt.Println("File read failed:", err) } // little endian to big endian for i, j := 0, len(data)-1; i < j; i, j = i+1, j-1 { data[i], data[j] = data...
[ "func", "readuint128", "(", "pos", "uint32", ")", "*", "big", ".", "Int", "{", "pos2", ":=", "int64", "(", "pos", ")", "\n", "retval", ":=", "big", ".", "NewInt", "(", "0", ")", "\n", "data", ":=", "make", "(", "[", "]", "byte", ",", "16", ")",...
// read unsigned 128-bit integer
[ "read", "unsigned", "128", "-", "bit", "integer" ]
a417f19539fd2a0eb0adf273b4190241cacc0499
https://github.com/ip2location/ip2location-go/blob/a417f19539fd2a0eb0adf273b4190241cacc0499/ip2location.go#L218-L233
test
ip2location/ip2location-go
ip2location.go
loadmessage
func loadmessage (mesg string) IP2Locationrecord { var x IP2Locationrecord x.Country_short = mesg x.Country_long = mesg x.Region = mesg x.City = mesg x.Isp = mesg x.Domain = mesg x.Zipcode = mesg x.Timezone = mesg x.Netspeed = mesg x.Iddcode = mesg x.Areacode = mesg x.Weatherstationcode = mesg x.Weather...
go
func loadmessage (mesg string) IP2Locationrecord { var x IP2Locationrecord x.Country_short = mesg x.Country_long = mesg x.Region = mesg x.City = mesg x.Isp = mesg x.Domain = mesg x.Zipcode = mesg x.Timezone = mesg x.Netspeed = mesg x.Iddcode = mesg x.Areacode = mesg x.Weatherstationcode = mesg x.Weather...
[ "func", "loadmessage", "(", "mesg", "string", ")", "IP2Locationrecord", "{", "var", "x", "IP2Locationrecord", "\n", "x", ".", "Country_short", "=", "mesg", "\n", "x", ".", "Country_long", "=", "mesg", "\n", "x", ".", "Region", "=", "mesg", "\n", "x", "."...
// populate record with message
[ "populate", "record", "with", "message" ]
a417f19539fd2a0eb0adf273b4190241cacc0499
https://github.com/ip2location/ip2location-go/blob/a417f19539fd2a0eb0adf273b4190241cacc0499/ip2location.go#L389-L411
test
ip2location/ip2location-go
ip2location.go
Printrecord
func Printrecord(x IP2Locationrecord) { fmt.Printf("country_short: %s\n", x.Country_short) fmt.Printf("country_long: %s\n", x.Country_long) fmt.Printf("region: %s\n", x.Region) fmt.Printf("city: %s\n", x.City) fmt.Printf("isp: %s\n", x.Isp) fmt.Printf("latitude: %f\n", x.Latitude) fmt.Printf("longitude: %f\n", x...
go
func Printrecord(x IP2Locationrecord) { fmt.Printf("country_short: %s\n", x.Country_short) fmt.Printf("country_long: %s\n", x.Country_long) fmt.Printf("region: %s\n", x.Region) fmt.Printf("city: %s\n", x.City) fmt.Printf("isp: %s\n", x.Isp) fmt.Printf("latitude: %f\n", x.Latitude) fmt.Printf("longitude: %f\n", x...
[ "func", "Printrecord", "(", "x", "IP2Locationrecord", ")", "{", "fmt", ".", "Printf", "(", "\"country_short: %s\\n\"", ",", "\\n", ")", "\n", "x", ".", "Country_short", "\n", "fmt", ".", "Printf", "(", "\"country_long: %s\\n\"", ",", "\\n", ")", "\n", "x", ...
// for debugging purposes
[ "for", "debugging", "purposes" ]
a417f19539fd2a0eb0adf273b4190241cacc0499
https://github.com/ip2location/ip2location-go/blob/a417f19539fd2a0eb0adf273b4190241cacc0499/ip2location.go#L681-L702
test
llgcode/draw2d
samples/gopher/gopher.go
Main
func Main(gc draw2d.GraphicContext, ext string) (string, error) { gc.Save() gc.Scale(0.5, 0.5) // Draw a (partial) gopher Draw(gc) gc.Restore() // Return the output filename return samples.Output("gopher", ext), nil }
go
func Main(gc draw2d.GraphicContext, ext string) (string, error) { gc.Save() gc.Scale(0.5, 0.5) // Draw a (partial) gopher Draw(gc) gc.Restore() // Return the output filename return samples.Output("gopher", ext), nil }
[ "func", "Main", "(", "gc", "draw2d", ".", "GraphicContext", ",", "ext", "string", ")", "(", "string", ",", "error", ")", "{", "gc", ".", "Save", "(", ")", "\n", "gc", ".", "Scale", "(", "0.5", ",", "0.5", ")", "\n", "Draw", "(", "gc", ")", "\n"...
// Main draws a left hand and ear of a gopher. Afterwards it returns // the filename. This should only be used during testing.
[ "Main", "draws", "a", "left", "hand", "and", "ear", "of", "a", "gopher", ".", "Afterwards", "it", "returns", "the", "filename", ".", "This", "should", "only", "be", "used", "during", "testing", "." ]
f52c8a71aff06ab8df41843d33ab167b36c971cd
https://github.com/llgcode/draw2d/blob/f52c8a71aff06ab8df41843d33ab167b36c971cd/samples/gopher/gopher.go#L17-L26
test
llgcode/draw2d
draw2dpdf/fileutil.go
SaveToPdfFile
func SaveToPdfFile(filePath string, pdf *gofpdf.Fpdf) error { return pdf.OutputFileAndClose(filePath) }
go
func SaveToPdfFile(filePath string, pdf *gofpdf.Fpdf) error { return pdf.OutputFileAndClose(filePath) }
[ "func", "SaveToPdfFile", "(", "filePath", "string", ",", "pdf", "*", "gofpdf", ".", "Fpdf", ")", "error", "{", "return", "pdf", ".", "OutputFileAndClose", "(", "filePath", ")", "\n", "}" ]
// SaveToPdfFile creates and saves a pdf document to a file
[ "SaveToPdfFile", "creates", "and", "saves", "a", "pdf", "document", "to", "a", "file" ]
f52c8a71aff06ab8df41843d33ab167b36c971cd
https://github.com/llgcode/draw2d/blob/f52c8a71aff06ab8df41843d33ab167b36c971cd/draw2dpdf/fileutil.go#L9-L11
test
llgcode/draw2d
path.go
CubicCurveTo
func (p *Path) CubicCurveTo(cx1, cy1, cx2, cy2, x, y float64) { if len(p.Components) == 0 { //special case when no move has been done p.MoveTo(x, y) } else { p.appendToPath(CubicCurveToCmp, cx1, cy1, cx2, cy2, x, y) } p.x = x p.y = y }
go
func (p *Path) CubicCurveTo(cx1, cy1, cx2, cy2, x, y float64) { if len(p.Components) == 0 { //special case when no move has been done p.MoveTo(x, y) } else { p.appendToPath(CubicCurveToCmp, cx1, cy1, cx2, cy2, x, y) } p.x = x p.y = y }
[ "func", "(", "p", "*", "Path", ")", "CubicCurveTo", "(", "cx1", ",", "cy1", ",", "cx2", ",", "cy2", ",", "x", ",", "y", "float64", ")", "{", "if", "len", "(", "p", ".", "Components", ")", "==", "0", "{", "p", ".", "MoveTo", "(", "x", ",", "...
// CubicCurveTo adds a cubic bezier curve to the current path
[ "CubicCurveTo", "adds", "a", "cubic", "bezier", "curve", "to", "the", "current", "path" ]
f52c8a71aff06ab8df41843d33ab167b36c971cd
https://github.com/llgcode/draw2d/blob/f52c8a71aff06ab8df41843d33ab167b36c971cd/path.go#L99-L107
test
llgcode/draw2d
path.go
ArcTo
func (p *Path) ArcTo(cx, cy, rx, ry, startAngle, angle float64) { endAngle := startAngle + angle clockWise := true if angle < 0 { clockWise = false } // normalize if clockWise { for endAngle < startAngle { endAngle += math.Pi * 2.0 } } else { for startAngle < endAngle { startAngle += math.Pi * 2.0 ...
go
func (p *Path) ArcTo(cx, cy, rx, ry, startAngle, angle float64) { endAngle := startAngle + angle clockWise := true if angle < 0 { clockWise = false } // normalize if clockWise { for endAngle < startAngle { endAngle += math.Pi * 2.0 } } else { for startAngle < endAngle { startAngle += math.Pi * 2.0 ...
[ "func", "(", "p", "*", "Path", ")", "ArcTo", "(", "cx", ",", "cy", ",", "rx", ",", "ry", ",", "startAngle", ",", "angle", "float64", ")", "{", "endAngle", ":=", "startAngle", "+", "angle", "\n", "clockWise", ":=", "true", "\n", "if", "angle", "<", ...
// ArcTo adds an arc to the path
[ "ArcTo", "adds", "an", "arc", "to", "the", "path" ]
f52c8a71aff06ab8df41843d33ab167b36c971cd
https://github.com/llgcode/draw2d/blob/f52c8a71aff06ab8df41843d33ab167b36c971cd/path.go#L110-L136
test
llgcode/draw2d
path.go
String
func (p *Path) String() string { s := "" j := 0 for _, cmd := range p.Components { switch cmd { case MoveToCmp: s += fmt.Sprintf("MoveTo: %f, %f\n", p.Points[j], p.Points[j+1]) j = j + 2 case LineToCmp: s += fmt.Sprintf("LineTo: %f, %f\n", p.Points[j], p.Points[j+1]) j = j + 2 case QuadCurveToCmp...
go
func (p *Path) String() string { s := "" j := 0 for _, cmd := range p.Components { switch cmd { case MoveToCmp: s += fmt.Sprintf("MoveTo: %f, %f\n", p.Points[j], p.Points[j+1]) j = j + 2 case LineToCmp: s += fmt.Sprintf("LineTo: %f, %f\n", p.Points[j], p.Points[j+1]) j = j + 2 case QuadCurveToCmp...
[ "func", "(", "p", "*", "Path", ")", "String", "(", ")", "string", "{", "s", ":=", "\"\"", "\n", "j", ":=", "0", "\n", "for", "_", ",", "cmd", ":=", "range", "p", ".", "Components", "{", "switch", "cmd", "{", "case", "MoveToCmp", ":", "s", "+=",...
// String returns a debug text view of the path
[ "String", "returns", "a", "debug", "text", "view", "of", "the", "path" ]
f52c8a71aff06ab8df41843d33ab167b36c971cd
https://github.com/llgcode/draw2d/blob/f52c8a71aff06ab8df41843d33ab167b36c971cd/path.go#L167-L192
test
llgcode/draw2d
path.go
VerticalFlip
func (path *Path) VerticalFlip() *Path { p := path.Copy() j := 0 for _, cmd := range p.Components { switch cmd { case MoveToCmp, LineToCmp: p.Points[j+1] = -p.Points[j+1] j = j + 2 case QuadCurveToCmp: p.Points[j+1] = -p.Points[j+1] p.Points[j+3] = -p.Points[j+3] j = j + 4 case CubicCurveToCmp...
go
func (path *Path) VerticalFlip() *Path { p := path.Copy() j := 0 for _, cmd := range p.Components { switch cmd { case MoveToCmp, LineToCmp: p.Points[j+1] = -p.Points[j+1] j = j + 2 case QuadCurveToCmp: p.Points[j+1] = -p.Points[j+1] p.Points[j+3] = -p.Points[j+3] j = j + 4 case CubicCurveToCmp...
[ "func", "(", "path", "*", "Path", ")", "VerticalFlip", "(", ")", "*", "Path", "{", "p", ":=", "path", ".", "Copy", "(", ")", "\n", "j", ":=", "0", "\n", "for", "_", ",", "cmd", ":=", "range", "p", ".", "Components", "{", "switch", "cmd", "{", ...
// Returns new Path with flipped y axes
[ "Returns", "new", "Path", "with", "flipped", "y", "axes" ]
f52c8a71aff06ab8df41843d33ab167b36c971cd
https://github.com/llgcode/draw2d/blob/f52c8a71aff06ab8df41843d33ab167b36c971cd/path.go#L195-L223
test
llgcode/draw2d
draw2dbase/text.go
NewGlyphCache
func NewGlyphCache() *GlyphCacheImp { glyphs := make(map[string]map[rune]*Glyph) return &GlyphCacheImp { glyphs: glyphs, } }
go
func NewGlyphCache() *GlyphCacheImp { glyphs := make(map[string]map[rune]*Glyph) return &GlyphCacheImp { glyphs: glyphs, } }
[ "func", "NewGlyphCache", "(", ")", "*", "GlyphCacheImp", "{", "glyphs", ":=", "make", "(", "map", "[", "string", "]", "map", "[", "rune", "]", "*", "Glyph", ")", "\n", "return", "&", "GlyphCacheImp", "{", "glyphs", ":", "glyphs", ",", "}", "\n", "}" ...
// NewGlyphCache initializes a GlyphCache
[ "NewGlyphCache", "initializes", "a", "GlyphCache" ]
f52c8a71aff06ab8df41843d33ab167b36c971cd
https://github.com/llgcode/draw2d/blob/f52c8a71aff06ab8df41843d33ab167b36c971cd/draw2dbase/text.go#L18-L23
test
llgcode/draw2d
draw2dbase/text.go
Fetch
func (glyphCache *GlyphCacheImp) Fetch(gc draw2d.GraphicContext, fontName string, chr rune) *Glyph { if glyphCache.glyphs[fontName] == nil { glyphCache.glyphs[fontName] = make(map[rune]*Glyph, 60) } if glyphCache.glyphs[fontName][chr] == nil { glyphCache.glyphs[fontName][chr] = renderGlyph(gc, fontName, chr) } ...
go
func (glyphCache *GlyphCacheImp) Fetch(gc draw2d.GraphicContext, fontName string, chr rune) *Glyph { if glyphCache.glyphs[fontName] == nil { glyphCache.glyphs[fontName] = make(map[rune]*Glyph, 60) } if glyphCache.glyphs[fontName][chr] == nil { glyphCache.glyphs[fontName][chr] = renderGlyph(gc, fontName, chr) } ...
[ "func", "(", "glyphCache", "*", "GlyphCacheImp", ")", "Fetch", "(", "gc", "draw2d", ".", "GraphicContext", ",", "fontName", "string", ",", "chr", "rune", ")", "*", "Glyph", "{", "if", "glyphCache", ".", "glyphs", "[", "fontName", "]", "==", "nil", "{", ...
// Fetch fetches a glyph from the cache, calling renderGlyph first if it doesn't already exist
[ "Fetch", "fetches", "a", "glyph", "from", "the", "cache", "calling", "renderGlyph", "first", "if", "it", "doesn", "t", "already", "exist" ]
f52c8a71aff06ab8df41843d33ab167b36c971cd
https://github.com/llgcode/draw2d/blob/f52c8a71aff06ab8df41843d33ab167b36c971cd/draw2dbase/text.go#L26-L34
test
llgcode/draw2d
draw2dbase/text.go
renderGlyph
func renderGlyph(gc draw2d.GraphicContext, fontName string, chr rune) *Glyph { gc.Save() defer gc.Restore() gc.BeginPath() width := gc.CreateStringPath(string(chr), 0, 0) path := gc.GetPath() return &Glyph{ Path: &path, Width: width, } }
go
func renderGlyph(gc draw2d.GraphicContext, fontName string, chr rune) *Glyph { gc.Save() defer gc.Restore() gc.BeginPath() width := gc.CreateStringPath(string(chr), 0, 0) path := gc.GetPath() return &Glyph{ Path: &path, Width: width, } }
[ "func", "renderGlyph", "(", "gc", "draw2d", ".", "GraphicContext", ",", "fontName", "string", ",", "chr", "rune", ")", "*", "Glyph", "{", "gc", ".", "Save", "(", ")", "\n", "defer", "gc", ".", "Restore", "(", ")", "\n", "gc", ".", "BeginPath", "(", ...
// renderGlyph renders a glyph then caches and returns it
[ "renderGlyph", "renders", "a", "glyph", "then", "caches", "and", "returns", "it" ]
f52c8a71aff06ab8df41843d33ab167b36c971cd
https://github.com/llgcode/draw2d/blob/f52c8a71aff06ab8df41843d33ab167b36c971cd/draw2dbase/text.go#L37-L47
test
llgcode/draw2d
draw2dbase/text.go
Copy
func (g *Glyph) Copy() *Glyph { return &Glyph{ Path: g.Path.Copy(), Width: g.Width, } }
go
func (g *Glyph) Copy() *Glyph { return &Glyph{ Path: g.Path.Copy(), Width: g.Width, } }
[ "func", "(", "g", "*", "Glyph", ")", "Copy", "(", ")", "*", "Glyph", "{", "return", "&", "Glyph", "{", "Path", ":", "g", ".", "Path", ".", "Copy", "(", ")", ",", "Width", ":", "g", ".", "Width", ",", "}", "\n", "}" ]
// Copy Returns a copy of a Glyph
[ "Copy", "Returns", "a", "copy", "of", "a", "Glyph" ]
f52c8a71aff06ab8df41843d33ab167b36c971cd
https://github.com/llgcode/draw2d/blob/f52c8a71aff06ab8df41843d33ab167b36c971cd/draw2dbase/text.go#L58-L63
test
llgcode/draw2d
draw2dbase/text.go
Fill
func (g *Glyph) Fill(gc draw2d.GraphicContext, x, y float64) float64 { gc.Save() gc.BeginPath() gc.Translate(x, y) gc.Fill(g.Path) gc.Restore() return g.Width }
go
func (g *Glyph) Fill(gc draw2d.GraphicContext, x, y float64) float64 { gc.Save() gc.BeginPath() gc.Translate(x, y) gc.Fill(g.Path) gc.Restore() return g.Width }
[ "func", "(", "g", "*", "Glyph", ")", "Fill", "(", "gc", "draw2d", ".", "GraphicContext", ",", "x", ",", "y", "float64", ")", "float64", "{", "gc", ".", "Save", "(", ")", "\n", "gc", ".", "BeginPath", "(", ")", "\n", "gc", ".", "Translate", "(", ...
// Fill copies a glyph from the cache, and fills it
[ "Fill", "copies", "a", "glyph", "from", "the", "cache", "and", "fills", "it" ]
f52c8a71aff06ab8df41843d33ab167b36c971cd
https://github.com/llgcode/draw2d/blob/f52c8a71aff06ab8df41843d33ab167b36c971cd/draw2dbase/text.go#L66-L73
test
llgcode/draw2d
samples/line/line.go
Main
func Main(gc draw2d.GraphicContext, ext string) (string, error) { gc.SetFillRule(draw2d.FillRuleWinding) gc.Clear() // Draw the line for x := 5.0; x < 297; x += 10 { Draw(gc, x, 0, x, 210) } gc.ClearRect(100, 75, 197, 135) draw2dkit.Ellipse(gc, 148.5, 105, 35, 25) gc.SetFillColor(color.RGBA{0xff, 0xff, 0x44, ...
go
func Main(gc draw2d.GraphicContext, ext string) (string, error) { gc.SetFillRule(draw2d.FillRuleWinding) gc.Clear() // Draw the line for x := 5.0; x < 297; x += 10 { Draw(gc, x, 0, x, 210) } gc.ClearRect(100, 75, 197, 135) draw2dkit.Ellipse(gc, 148.5, 105, 35, 25) gc.SetFillColor(color.RGBA{0xff, 0xff, 0x44, ...
[ "func", "Main", "(", "gc", "draw2d", ".", "GraphicContext", ",", "ext", "string", ")", "(", "string", ",", "error", ")", "{", "gc", ".", "SetFillRule", "(", "draw2d", ".", "FillRuleWinding", ")", "\n", "gc", ".", "Clear", "(", ")", "\n", "for", "x", ...
// Main draws vertically spaced lines and returns the filename. // This should only be used during testing.
[ "Main", "draws", "vertically", "spaced", "lines", "and", "returns", "the", "filename", ".", "This", "should", "only", "be", "used", "during", "testing", "." ]
f52c8a71aff06ab8df41843d33ab167b36c971cd
https://github.com/llgcode/draw2d/blob/f52c8a71aff06ab8df41843d33ab167b36c971cd/samples/line/line.go#L17-L31
test
llgcode/draw2d
samples/line/line.go
Draw
func Draw(gc draw2d.GraphicContext, x0, y0, x1, y1 float64) { // Draw a line gc.MoveTo(x0, y0) gc.LineTo(x1, y1) gc.Stroke() }
go
func Draw(gc draw2d.GraphicContext, x0, y0, x1, y1 float64) { // Draw a line gc.MoveTo(x0, y0) gc.LineTo(x1, y1) gc.Stroke() }
[ "func", "Draw", "(", "gc", "draw2d", ".", "GraphicContext", ",", "x0", ",", "y0", ",", "x1", ",", "y1", "float64", ")", "{", "gc", ".", "MoveTo", "(", "x0", ",", "y0", ")", "\n", "gc", ".", "LineTo", "(", "x1", ",", "y1", ")", "\n", "gc", "."...
// Draw vertically spaced lines
[ "Draw", "vertically", "spaced", "lines" ]
f52c8a71aff06ab8df41843d33ab167b36c971cd
https://github.com/llgcode/draw2d/blob/f52c8a71aff06ab8df41843d33ab167b36c971cd/samples/line/line.go#L34-L39
test
llgcode/draw2d
draw2dgl/gc.go
Paint
func (p *Painter) Paint(ss []raster.Span, done bool) { //gl.Begin(gl.LINES) sslen := len(ss) clenrequired := sslen * 8 vlenrequired := sslen * 4 if clenrequired >= (cap(p.colors) - len(p.colors)) { p.Flush() if clenrequired >= cap(p.colors) { p.vertices = make([]int32, 0, vlenrequired+(vlenrequired/2)) ...
go
func (p *Painter) Paint(ss []raster.Span, done bool) { //gl.Begin(gl.LINES) sslen := len(ss) clenrequired := sslen * 8 vlenrequired := sslen * 4 if clenrequired >= (cap(p.colors) - len(p.colors)) { p.Flush() if clenrequired >= cap(p.colors) { p.vertices = make([]int32, 0, vlenrequired+(vlenrequired/2)) ...
[ "func", "(", "p", "*", "Painter", ")", "Paint", "(", "ss", "[", "]", "raster", ".", "Span", ",", "done", "bool", ")", "{", "sslen", ":=", "len", "(", "ss", ")", "\n", "clenrequired", ":=", "sslen", "*", "8", "\n", "vlenrequired", ":=", "sslen", "...
// Paint satisfies the Painter interface by painting ss onto an image.RGBA.
[ "Paint", "satisfies", "the", "Painter", "interface", "by", "painting", "ss", "onto", "an", "image", ".", "RGBA", "." ]
f52c8a71aff06ab8df41843d33ab167b36c971cd
https://github.com/llgcode/draw2d/blob/f52c8a71aff06ab8df41843d33ab167b36c971cd/draw2dgl/gc.go#L39-L80
test
llgcode/draw2d
draw2dgl/gc.go
SetColor
func (p *Painter) SetColor(c color.Color) { r, g, b, a := c.RGBA() if a == 0 { p.cr = 0 p.cg = 0 p.cb = 0 p.ca = a } else { p.cr = uint8((r * M16 / a) >> 8) p.cg = uint8((g * M16 / a) >> 8) p.cb = uint8((b * M16 / a) >> 8) p.ca = a } }
go
func (p *Painter) SetColor(c color.Color) { r, g, b, a := c.RGBA() if a == 0 { p.cr = 0 p.cg = 0 p.cb = 0 p.ca = a } else { p.cr = uint8((r * M16 / a) >> 8) p.cg = uint8((g * M16 / a) >> 8) p.cb = uint8((b * M16 / a) >> 8) p.ca = a } }
[ "func", "(", "p", "*", "Painter", ")", "SetColor", "(", "c", "color", ".", "Color", ")", "{", "r", ",", "g", ",", "b", ",", "a", ":=", "c", ".", "RGBA", "(", ")", "\n", "if", "a", "==", "0", "{", "p", ".", "cr", "=", "0", "\n", "p", "."...
// SetColor sets the color to paint the spans.
[ "SetColor", "sets", "the", "color", "to", "paint", "the", "spans", "." ]
f52c8a71aff06ab8df41843d33ab167b36c971cd
https://github.com/llgcode/draw2d/blob/f52c8a71aff06ab8df41843d33ab167b36c971cd/draw2dgl/gc.go#L99-L112
test
llgcode/draw2d
draw2dgl/gc.go
NewPainter
func NewPainter() *Painter { p := new(Painter) p.vertices = make([]int32, 0, 1024) p.colors = make([]uint8, 0, 1024) return p }
go
func NewPainter() *Painter { p := new(Painter) p.vertices = make([]int32, 0, 1024) p.colors = make([]uint8, 0, 1024) return p }
[ "func", "NewPainter", "(", ")", "*", "Painter", "{", "p", ":=", "new", "(", "Painter", ")", "\n", "p", ".", "vertices", "=", "make", "(", "[", "]", "int32", ",", "0", ",", "1024", ")", "\n", "p", ".", "colors", "=", "make", "(", "[", "]", "ui...
// NewRGBAPainter creates a new RGBAPainter for the given image.
[ "NewRGBAPainter", "creates", "a", "new", "RGBAPainter", "for", "the", "given", "image", "." ]
f52c8a71aff06ab8df41843d33ab167b36c971cd
https://github.com/llgcode/draw2d/blob/f52c8a71aff06ab8df41843d33ab167b36c971cd/draw2dgl/gc.go#L115-L120
test
llgcode/draw2d
draw2dgl/gc.go
GetStringBounds
func (gc *GraphicContext) GetStringBounds(s string) (left, top, right, bottom float64) { f, err := gc.loadCurrentFont() if err != nil { log.Println(err) return 0, 0, 0, 0 } top, left, bottom, right = 10e6, 10e6, -10e6, -10e6 cursor := 0.0 prev, hasPrev := truetype.Index(0), false for _, rune := range s { i...
go
func (gc *GraphicContext) GetStringBounds(s string) (left, top, right, bottom float64) { f, err := gc.loadCurrentFont() if err != nil { log.Println(err) return 0, 0, 0, 0 } top, left, bottom, right = 10e6, 10e6, -10e6, -10e6 cursor := 0.0 prev, hasPrev := truetype.Index(0), false for _, rune := range s { i...
[ "func", "(", "gc", "*", "GraphicContext", ")", "GetStringBounds", "(", "s", "string", ")", "(", "left", ",", "top", ",", "right", ",", "bottom", "float64", ")", "{", "f", ",", "err", ":=", "gc", ".", "loadCurrentFont", "(", ")", "\n", "if", "err", ...
// GetStringBounds returns the approximate pixel bounds of the string s at x, y. // The the left edge of the em square of the first character of s // and the baseline intersect at 0, 0 in the returned coordinates. // Therefore the top and left coordinates may well be negative.
[ "GetStringBounds", "returns", "the", "approximate", "pixel", "bounds", "of", "the", "string", "s", "at", "x", "y", ".", "The", "the", "left", "edge", "of", "the", "em", "square", "of", "the", "first", "character", "of", "s", "and", "the", "baseline", "in...
f52c8a71aff06ab8df41843d33ab167b36c971cd
https://github.com/llgcode/draw2d/blob/f52c8a71aff06ab8df41843d33ab167b36c971cd/draw2dgl/gc.go#L233-L266
test
llgcode/draw2d
draw2dgl/gc.go
recalc
func (gc *GraphicContext) recalc() { gc.Current.Scale = gc.Current.FontSize * float64(gc.DPI) * (64.0 / 72.0) }
go
func (gc *GraphicContext) recalc() { gc.Current.Scale = gc.Current.FontSize * float64(gc.DPI) * (64.0 / 72.0) }
[ "func", "(", "gc", "*", "GraphicContext", ")", "recalc", "(", ")", "{", "gc", ".", "Current", ".", "Scale", "=", "gc", ".", "Current", ".", "FontSize", "*", "float64", "(", "gc", ".", "DPI", ")", "*", "(", "64.0", "/", "72.0", ")", "\n", "}" ]
// recalc recalculates scale and bounds values from the font size, screen // resolution and font metrics, and invalidates the glyph cache.
[ "recalc", "recalculates", "scale", "and", "bounds", "values", "from", "the", "font", "size", "screen", "resolution", "and", "font", "metrics", "and", "invalidates", "the", "glyph", "cache", "." ]
f52c8a71aff06ab8df41843d33ab167b36c971cd
https://github.com/llgcode/draw2d/blob/f52c8a71aff06ab8df41843d33ab167b36c971cd/draw2dgl/gc.go#L297-L299
test
llgcode/draw2d
draw2dgl/gc.go
SetFont
func (gc *GraphicContext) SetFont(font *truetype.Font) { gc.Current.Font = font }
go
func (gc *GraphicContext) SetFont(font *truetype.Font) { gc.Current.Font = font }
[ "func", "(", "gc", "*", "GraphicContext", ")", "SetFont", "(", "font", "*", "truetype", ".", "Font", ")", "{", "gc", ".", "Current", ".", "Font", "=", "font", "\n", "}" ]
// SetFont sets the font used to draw text.
[ "SetFont", "sets", "the", "font", "used", "to", "draw", "text", "." ]
f52c8a71aff06ab8df41843d33ab167b36c971cd
https://github.com/llgcode/draw2d/blob/f52c8a71aff06ab8df41843d33ab167b36c971cd/draw2dgl/gc.go#L307-L309
test
llgcode/draw2d
draw2dsvg/gc.go
ClearRect
func (gc *GraphicContext) ClearRect(x1, y1, x2, y2 int) { mask := gc.newMask(x1, y1, x2-x1, y2-y1) newGroup := &Group{ Groups: gc.svg.Groups, Mask: "url(#" + mask.Id + ")", } // replace groups with new masked group gc.svg.Groups = []*Group{newGroup} }
go
func (gc *GraphicContext) ClearRect(x1, y1, x2, y2 int) { mask := gc.newMask(x1, y1, x2-x1, y2-y1) newGroup := &Group{ Groups: gc.svg.Groups, Mask: "url(#" + mask.Id + ")", } // replace groups with new masked group gc.svg.Groups = []*Group{newGroup} }
[ "func", "(", "gc", "*", "GraphicContext", ")", "ClearRect", "(", "x1", ",", "y1", ",", "x2", ",", "y2", "int", ")", "{", "mask", ":=", "gc", ".", "newMask", "(", "x1", ",", "y1", ",", "x2", "-", "x1", ",", "y2", "-", "y1", ")", "\n", "newGrou...
// ClearRect fills the specified rectangle with a default transparent color
[ "ClearRect", "fills", "the", "specified", "rectangle", "with", "a", "default", "transparent", "color" ]
f52c8a71aff06ab8df41843d33ab167b36c971cd
https://github.com/llgcode/draw2d/blob/f52c8a71aff06ab8df41843d33ab167b36c971cd/draw2dsvg/gc.go#L137-L147
test
llgcode/draw2d
draw2dsvg/gc.go
drawString
func (gc *GraphicContext) drawString(text string, drawType drawType, x, y float64) float64 { switch gc.svg.FontMode { case PathFontMode: w := gc.CreateStringPath(text, x, y) gc.drawPaths(drawType) gc.Current.Path.Clear() return w case SvgFontMode: gc.embedSvgFont(text) } // create elements svgText := T...
go
func (gc *GraphicContext) drawString(text string, drawType drawType, x, y float64) float64 { switch gc.svg.FontMode { case PathFontMode: w := gc.CreateStringPath(text, x, y) gc.drawPaths(drawType) gc.Current.Path.Clear() return w case SvgFontMode: gc.embedSvgFont(text) } // create elements svgText := T...
[ "func", "(", "gc", "*", "GraphicContext", ")", "drawString", "(", "text", "string", ",", "drawType", "drawType", ",", "x", ",", "y", "float64", ")", "float64", "{", "switch", "gc", ".", "svg", ".", "FontMode", "{", "case", "PathFontMode", ":", "w", ":=...
// Add text element to svg and returns its expected width
[ "Add", "text", "element", "to", "svg", "and", "returns", "its", "expected", "width" ]
f52c8a71aff06ab8df41843d33ab167b36c971cd
https://github.com/llgcode/draw2d/blob/f52c8a71aff06ab8df41843d33ab167b36c971cd/draw2dsvg/gc.go#L248-L274
test
llgcode/draw2d
draw2dsvg/gc.go
newGroup
func (gc *GraphicContext) newGroup(drawType drawType) *Group { group := Group{} // set attrs to group if drawType&stroked == stroked { group.Stroke = toSvgRGBA(gc.Current.StrokeColor) group.StrokeWidth = toSvgLength(gc.Current.LineWidth) group.StrokeLinecap = gc.Current.Cap.String() group.StrokeLinejoin = gc...
go
func (gc *GraphicContext) newGroup(drawType drawType) *Group { group := Group{} // set attrs to group if drawType&stroked == stroked { group.Stroke = toSvgRGBA(gc.Current.StrokeColor) group.StrokeWidth = toSvgLength(gc.Current.LineWidth) group.StrokeLinecap = gc.Current.Cap.String() group.StrokeLinejoin = gc...
[ "func", "(", "gc", "*", "GraphicContext", ")", "newGroup", "(", "drawType", "drawType", ")", "*", "Group", "{", "group", ":=", "Group", "{", "}", "\n", "if", "drawType", "&", "stroked", "==", "stroked", "{", "group", ".", "Stroke", "=", "toSvgRGBA", "(...
// Creates new group from current context // attach it to svg and return
[ "Creates", "new", "group", "from", "current", "context", "attach", "it", "to", "svg", "and", "return" ]
f52c8a71aff06ab8df41843d33ab167b36c971cd
https://github.com/llgcode/draw2d/blob/f52c8a71aff06ab8df41843d33ab167b36c971cd/draw2dsvg/gc.go#L278-L303
test
llgcode/draw2d
draw2dsvg/gc.go
newMask
func (gc *GraphicContext) newMask(x, y, width, height int) *Mask { mask := &Mask{} mask.X = float64(x) mask.Y = float64(y) mask.Width = toSvgLength(float64(width)) mask.Height = toSvgLength(float64(height)) // attach mask gc.svg.Masks = append(gc.svg.Masks, mask) mask.Id = "mask-" + strconv.Itoa(len(gc.svg.Mas...
go
func (gc *GraphicContext) newMask(x, y, width, height int) *Mask { mask := &Mask{} mask.X = float64(x) mask.Y = float64(y) mask.Width = toSvgLength(float64(width)) mask.Height = toSvgLength(float64(height)) // attach mask gc.svg.Masks = append(gc.svg.Masks, mask) mask.Id = "mask-" + strconv.Itoa(len(gc.svg.Mas...
[ "func", "(", "gc", "*", "GraphicContext", ")", "newMask", "(", "x", ",", "y", ",", "width", ",", "height", "int", ")", "*", "Mask", "{", "mask", ":=", "&", "Mask", "{", "}", "\n", "mask", ".", "X", "=", "float64", "(", "x", ")", "\n", "mask", ...
// creates new mask attached to svg
[ "creates", "new", "mask", "attached", "to", "svg" ]
f52c8a71aff06ab8df41843d33ab167b36c971cd
https://github.com/llgcode/draw2d/blob/f52c8a71aff06ab8df41843d33ab167b36c971cd/draw2dsvg/gc.go#L306-L317
test
llgcode/draw2d
draw2dsvg/gc.go
embedSvgFont
func (gc *GraphicContext) embedSvgFont(text string) *Font { fontName := gc.Current.FontData.Name gc.loadCurrentFont() // find or create font Element svgFont := (*Font)(nil) for _, font := range gc.svg.Fonts { if font.Name == fontName { svgFont = font break } } if svgFont == nil { // create new svg...
go
func (gc *GraphicContext) embedSvgFont(text string) *Font { fontName := gc.Current.FontData.Name gc.loadCurrentFont() // find or create font Element svgFont := (*Font)(nil) for _, font := range gc.svg.Fonts { if font.Name == fontName { svgFont = font break } } if svgFont == nil { // create new svg...
[ "func", "(", "gc", "*", "GraphicContext", ")", "embedSvgFont", "(", "text", "string", ")", "*", "Font", "{", "fontName", ":=", "gc", ".", "Current", ".", "FontData", ".", "Name", "\n", "gc", ".", "loadCurrentFont", "(", ")", "\n", "svgFont", ":=", "(",...
// Embed svg font definition to svg tree itself // Or update existing if already exists for curent font data
[ "Embed", "svg", "font", "definition", "to", "svg", "tree", "itself", "Or", "update", "existing", "if", "already", "exists", "for", "curent", "font", "data" ]
f52c8a71aff06ab8df41843d33ab167b36c971cd
https://github.com/llgcode/draw2d/blob/f52c8a71aff06ab8df41843d33ab167b36c971cd/draw2dsvg/gc.go#L321-L372
test
llgcode/draw2d
draw2dbase/curve.go
TraceQuad
func TraceQuad(t Liner, quad []float64, flatteningThreshold float64) error { if len(quad) < 6 { return errors.New("quad length must be >= 6") } // Allocates curves stack var curves [CurveRecursionLimit * 6]float64 copy(curves[0:6], quad[0:6]) i := 0 // current curve var c []float64 var dx, dy, d float64 fo...
go
func TraceQuad(t Liner, quad []float64, flatteningThreshold float64) error { if len(quad) < 6 { return errors.New("quad length must be >= 6") } // Allocates curves stack var curves [CurveRecursionLimit * 6]float64 copy(curves[0:6], quad[0:6]) i := 0 // current curve var c []float64 var dx, dy, d float64 fo...
[ "func", "TraceQuad", "(", "t", "Liner", ",", "quad", "[", "]", "float64", ",", "flatteningThreshold", "float64", ")", "error", "{", "if", "len", "(", "quad", ")", "<", "6", "{", "return", "errors", ".", "New", "(", "\"quad length must be >= 6\"", ")", "\...
// TraceQuad generate lines subdividing the curve using a Liner // flattening_threshold helps determines the flattening expectation of the curve
[ "TraceQuad", "generate", "lines", "subdividing", "the", "curve", "using", "a", "Liner", "flattening_threshold", "helps", "determines", "the", "flattening", "expectation", "of", "the", "curve" ]
f52c8a71aff06ab8df41843d33ab167b36c971cd
https://github.com/llgcode/draw2d/blob/f52c8a71aff06ab8df41843d33ab167b36c971cd/draw2dbase/curve.go#L113-L143
test
llgcode/draw2d
draw2dbase/stack_gc.go
GetFontName
func (cs *ContextStack) GetFontName() string { fontData := cs.FontData return fmt.Sprintf("%s:%d:%d:%9.2f", fontData.Name, fontData.Family, fontData.Style, cs.FontSize) }
go
func (cs *ContextStack) GetFontName() string { fontData := cs.FontData return fmt.Sprintf("%s:%d:%d:%9.2f", fontData.Name, fontData.Family, fontData.Style, cs.FontSize) }
[ "func", "(", "cs", "*", "ContextStack", ")", "GetFontName", "(", ")", "string", "{", "fontData", ":=", "cs", ".", "FontData", "\n", "return", "fmt", ".", "Sprintf", "(", "\"%s:%d:%d:%9.2f\"", ",", "fontData", ".", "Name", ",", "fontData", ".", "Family", ...
// GetFontName gets the current FontData with fontSize as a string
[ "GetFontName", "gets", "the", "current", "FontData", "with", "fontSize", "as", "a", "string" ]
f52c8a71aff06ab8df41843d33ab167b36c971cd
https://github.com/llgcode/draw2d/blob/f52c8a71aff06ab8df41843d33ab167b36c971cd/draw2dbase/stack_gc.go#L45-L48
test
llgcode/draw2d
draw2dbase/stack_gc.go
NewStackGraphicContext
func NewStackGraphicContext() *StackGraphicContext { gc := &StackGraphicContext{} gc.Current = new(ContextStack) gc.Current.Tr = draw2d.NewIdentityMatrix() gc.Current.Path = new(draw2d.Path) gc.Current.LineWidth = 1.0 gc.Current.StrokeColor = image.Black gc.Current.FillColor = image.White gc.Current.Cap = draw2...
go
func NewStackGraphicContext() *StackGraphicContext { gc := &StackGraphicContext{} gc.Current = new(ContextStack) gc.Current.Tr = draw2d.NewIdentityMatrix() gc.Current.Path = new(draw2d.Path) gc.Current.LineWidth = 1.0 gc.Current.StrokeColor = image.Black gc.Current.FillColor = image.White gc.Current.Cap = draw2...
[ "func", "NewStackGraphicContext", "(", ")", "*", "StackGraphicContext", "{", "gc", ":=", "&", "StackGraphicContext", "{", "}", "\n", "gc", ".", "Current", "=", "new", "(", "ContextStack", ")", "\n", "gc", ".", "Current", ".", "Tr", "=", "draw2d", ".", "N...
/** * Create a new Graphic context from an image */
[ "Create", "a", "new", "Graphic", "context", "from", "an", "image" ]
f52c8a71aff06ab8df41843d33ab167b36c971cd
https://github.com/llgcode/draw2d/blob/f52c8a71aff06ab8df41843d33ab167b36c971cd/draw2dbase/stack_gc.go#L54-L68
test
llgcode/draw2d
font.go
NewFolderFontCache
func NewFolderFontCache(folder string) *FolderFontCache { return &FolderFontCache{ fonts: make(map[string]*truetype.Font), folder: folder, namer: FontFileName, } }
go
func NewFolderFontCache(folder string) *FolderFontCache { return &FolderFontCache{ fonts: make(map[string]*truetype.Font), folder: folder, namer: FontFileName, } }
[ "func", "NewFolderFontCache", "(", "folder", "string", ")", "*", "FolderFontCache", "{", "return", "&", "FolderFontCache", "{", "fonts", ":", "make", "(", "map", "[", "string", "]", "*", "truetype", ".", "Font", ")", ",", "folder", ":", "folder", ",", "n...
// NewFolderFontCache creates FolderFontCache
[ "NewFolderFontCache", "creates", "FolderFontCache" ]
f52c8a71aff06ab8df41843d33ab167b36c971cd
https://github.com/llgcode/draw2d/blob/f52c8a71aff06ab8df41843d33ab167b36c971cd/font.go#L129-L135
test
llgcode/draw2d
font.go
NewSyncFolderFontCache
func NewSyncFolderFontCache(folder string) *SyncFolderFontCache { return &SyncFolderFontCache{ fonts: make(map[string]*truetype.Font), folder: folder, namer: FontFileName, } }
go
func NewSyncFolderFontCache(folder string) *SyncFolderFontCache { return &SyncFolderFontCache{ fonts: make(map[string]*truetype.Font), folder: folder, namer: FontFileName, } }
[ "func", "NewSyncFolderFontCache", "(", "folder", "string", ")", "*", "SyncFolderFontCache", "{", "return", "&", "SyncFolderFontCache", "{", "fonts", ":", "make", "(", "map", "[", "string", "]", "*", "truetype", ".", "Font", ")", ",", "folder", ":", "folder",...
// NewSyncFolderFontCache creates SyncFolderFontCache
[ "NewSyncFolderFontCache", "creates", "SyncFolderFontCache" ]
f52c8a71aff06ab8df41843d33ab167b36c971cd
https://github.com/llgcode/draw2d/blob/f52c8a71aff06ab8df41843d33ab167b36c971cd/font.go#L172-L178
test
llgcode/draw2d
samples/gopher2/gopher2.go
Main
func Main(gc draw2d.GraphicContext, ext string) (string, error) { gc.SetStrokeColor(image.Black) gc.SetFillColor(image.White) gc.Save() // Draw a (partial) gopher gc.Translate(-60, 65) gc.Rotate(-30 * (math.Pi / 180.0)) Draw(gc, 48, 48, 240, 72) gc.Restore() // Return the output filename return samples.Outpu...
go
func Main(gc draw2d.GraphicContext, ext string) (string, error) { gc.SetStrokeColor(image.Black) gc.SetFillColor(image.White) gc.Save() // Draw a (partial) gopher gc.Translate(-60, 65) gc.Rotate(-30 * (math.Pi / 180.0)) Draw(gc, 48, 48, 240, 72) gc.Restore() // Return the output filename return samples.Outpu...
[ "func", "Main", "(", "gc", "draw2d", ".", "GraphicContext", ",", "ext", "string", ")", "(", "string", ",", "error", ")", "{", "gc", ".", "SetStrokeColor", "(", "image", ".", "Black", ")", "\n", "gc", ".", "SetFillColor", "(", "image", ".", "White", "...
// Main draws a rotated face of the gopher. Afterwards it returns // the filename. This should only be used during testing.
[ "Main", "draws", "a", "rotated", "face", "of", "the", "gopher", ".", "Afterwards", "it", "returns", "the", "filename", ".", "This", "should", "only", "be", "used", "during", "testing", "." ]
f52c8a71aff06ab8df41843d33ab167b36c971cd
https://github.com/llgcode/draw2d/blob/f52c8a71aff06ab8df41843d33ab167b36c971cd/samples/gopher2/gopher2.go#L20-L32
test
llgcode/draw2d
draw2dpdf/gc.go
NewPdf
func NewPdf(orientationStr, unitStr, sizeStr string) *gofpdf.Fpdf { pdf := gofpdf.New(orientationStr, unitStr, sizeStr, draw2d.GetFontFolder()) // to be compatible with draw2d pdf.SetMargins(0, 0, 0) pdf.SetDrawColor(0, 0, 0) pdf.SetFillColor(255, 255, 255) pdf.SetLineCapStyle("round") pdf.SetLineJoinStyle("roun...
go
func NewPdf(orientationStr, unitStr, sizeStr string) *gofpdf.Fpdf { pdf := gofpdf.New(orientationStr, unitStr, sizeStr, draw2d.GetFontFolder()) // to be compatible with draw2d pdf.SetMargins(0, 0, 0) pdf.SetDrawColor(0, 0, 0) pdf.SetFillColor(255, 255, 255) pdf.SetLineCapStyle("round") pdf.SetLineJoinStyle("roun...
[ "func", "NewPdf", "(", "orientationStr", ",", "unitStr", ",", "sizeStr", "string", ")", "*", "gofpdf", ".", "Fpdf", "{", "pdf", ":=", "gofpdf", ".", "New", "(", "orientationStr", ",", "unitStr", ",", "sizeStr", ",", "draw2d", ".", "GetFontFolder", "(", "...
// NewPdf creates a new pdf document with the draw2d fontfolder, adds // a page and set fill color to white.
[ "NewPdf", "creates", "a", "new", "pdf", "document", "with", "the", "draw2d", "fontfolder", "adds", "a", "page", "and", "set", "fill", "color", "to", "white", "." ]
f52c8a71aff06ab8df41843d33ab167b36c971cd
https://github.com/llgcode/draw2d/blob/f52c8a71aff06ab8df41843d33ab167b36c971cd/draw2dpdf/gc.go#L47-L58
test
llgcode/draw2d
draw2dpdf/gc.go
clearRect
func clearRect(gc *GraphicContext, x1, y1, x2, y2 float64) { // save state f := gc.Current.FillColor x, y := gc.pdf.GetXY() // cover page with white rectangle gc.SetFillColor(white) draw2dkit.Rectangle(gc, x1, y1, x2, y2) gc.Fill() // restore state gc.SetFillColor(f) gc.pdf.MoveTo(x, y) }
go
func clearRect(gc *GraphicContext, x1, y1, x2, y2 float64) { // save state f := gc.Current.FillColor x, y := gc.pdf.GetXY() // cover page with white rectangle gc.SetFillColor(white) draw2dkit.Rectangle(gc, x1, y1, x2, y2) gc.Fill() // restore state gc.SetFillColor(f) gc.pdf.MoveTo(x, y) }
[ "func", "clearRect", "(", "gc", "*", "GraphicContext", ",", "x1", ",", "y1", ",", "x2", ",", "y2", "float64", ")", "{", "f", ":=", "gc", ".", "Current", ".", "FillColor", "\n", "x", ",", "y", ":=", "gc", ".", "pdf", ".", "GetXY", "(", ")", "\n"...
// clearRect draws a white rectangle
[ "clearRect", "draws", "a", "white", "rectangle" ]
f52c8a71aff06ab8df41843d33ab167b36c971cd
https://github.com/llgcode/draw2d/blob/f52c8a71aff06ab8df41843d33ab167b36c971cd/draw2dpdf/gc.go#L67-L78
test
llgcode/draw2d
draw2dpdf/gc.go
NewGraphicContext
func NewGraphicContext(pdf *gofpdf.Fpdf) *GraphicContext { gc := &GraphicContext{draw2dbase.NewStackGraphicContext(), pdf, DPI} gc.SetDPI(DPI) return gc }
go
func NewGraphicContext(pdf *gofpdf.Fpdf) *GraphicContext { gc := &GraphicContext{draw2dbase.NewStackGraphicContext(), pdf, DPI} gc.SetDPI(DPI) return gc }
[ "func", "NewGraphicContext", "(", "pdf", "*", "gofpdf", ".", "Fpdf", ")", "*", "GraphicContext", "{", "gc", ":=", "&", "GraphicContext", "{", "draw2dbase", ".", "NewStackGraphicContext", "(", ")", ",", "pdf", ",", "DPI", "}", "\n", "gc", ".", "SetDPI", "...
// NewGraphicContext creates a new pdf GraphicContext
[ "NewGraphicContext", "creates", "a", "new", "pdf", "GraphicContext" ]
f52c8a71aff06ab8df41843d33ab167b36c971cd
https://github.com/llgcode/draw2d/blob/f52c8a71aff06ab8df41843d33ab167b36c971cd/draw2dpdf/gc.go#L89-L93
test
llgcode/draw2d
draw2dpdf/gc.go
Clear
func (gc *GraphicContext) Clear() { width, height := gc.pdf.GetPageSize() clearRect(gc, 0, 0, width, height) }
go
func (gc *GraphicContext) Clear() { width, height := gc.pdf.GetPageSize() clearRect(gc, 0, 0, width, height) }
[ "func", "(", "gc", "*", "GraphicContext", ")", "Clear", "(", ")", "{", "width", ",", "height", ":=", "gc", ".", "pdf", ".", "GetPageSize", "(", ")", "\n", "clearRect", "(", "gc", ",", "0", ",", "0", ",", "width", ",", "height", ")", "\n", "}" ]
// Clear draws a white rectangle over the whole page
[ "Clear", "draws", "a", "white", "rectangle", "over", "the", "whole", "page" ]
f52c8a71aff06ab8df41843d33ab167b36c971cd
https://github.com/llgcode/draw2d/blob/f52c8a71aff06ab8df41843d33ab167b36c971cd/draw2dpdf/gc.go#L111-L114
test
llgcode/draw2d
draw2dpdf/gc.go
GetStringBounds
func (gc *GraphicContext) GetStringBounds(s string) (left, top, right, bottom float64) { _, h := gc.pdf.GetFontSize() d := gc.pdf.GetFontDesc("", "") if d.Ascent == 0 { // not defined (standard font?), use average of 81% top = 0.81 * h } else { top = -float64(d.Ascent) * h / float64(d.Ascent-d.Descent) } re...
go
func (gc *GraphicContext) GetStringBounds(s string) (left, top, right, bottom float64) { _, h := gc.pdf.GetFontSize() d := gc.pdf.GetFontDesc("", "") if d.Ascent == 0 { // not defined (standard font?), use average of 81% top = 0.81 * h } else { top = -float64(d.Ascent) * h / float64(d.Ascent-d.Descent) } re...
[ "func", "(", "gc", "*", "GraphicContext", ")", "GetStringBounds", "(", "s", "string", ")", "(", "left", ",", "top", ",", "right", ",", "bottom", "float64", ")", "{", "_", ",", "h", ":=", "gc", ".", "pdf", ".", "GetFontSize", "(", ")", "\n", "d", ...
// GetStringBounds returns the approximate pixel bounds of the string s at x, y. // The left edge of the em square of the first character of s // and the baseline intersect at 0, 0 in the returned coordinates. // Therefore the top and left coordinates may well be negative.
[ "GetStringBounds", "returns", "the", "approximate", "pixel", "bounds", "of", "the", "string", "s", "at", "x", "y", ".", "The", "left", "edge", "of", "the", "em", "square", "of", "the", "first", "character", "of", "s", "and", "the", "baseline", "intersect",...
f52c8a71aff06ab8df41843d33ab167b36c971cd
https://github.com/llgcode/draw2d/blob/f52c8a71aff06ab8df41843d33ab167b36c971cd/draw2dpdf/gc.go#L146-L156
test
llgcode/draw2d
draw2dpdf/gc.go
CreateStringPath
func (gc *GraphicContext) CreateStringPath(text string, x, y float64) (cursor float64) { //fpdf uses the top left corner left, top, right, bottom := gc.GetStringBounds(text) w := right - left h := bottom - top // gc.pdf.SetXY(x, y-h) do not use this as y-h might be negative margin := gc.pdf.GetCellMargin() gc.pd...
go
func (gc *GraphicContext) CreateStringPath(text string, x, y float64) (cursor float64) { //fpdf uses the top left corner left, top, right, bottom := gc.GetStringBounds(text) w := right - left h := bottom - top // gc.pdf.SetXY(x, y-h) do not use this as y-h might be negative margin := gc.pdf.GetCellMargin() gc.pd...
[ "func", "(", "gc", "*", "GraphicContext", ")", "CreateStringPath", "(", "text", "string", ",", "x", ",", "y", "float64", ")", "(", "cursor", "float64", ")", "{", "left", ",", "top", ",", "right", ",", "bottom", ":=", "gc", ".", "GetStringBounds", "(", ...
// CreateStringPath creates a path from the string s at x, y, and returns the string width.
[ "CreateStringPath", "creates", "a", "path", "from", "the", "string", "s", "at", "x", "y", "and", "returns", "the", "string", "width", "." ]
f52c8a71aff06ab8df41843d33ab167b36c971cd
https://github.com/llgcode/draw2d/blob/f52c8a71aff06ab8df41843d33ab167b36c971cd/draw2dpdf/gc.go#L159-L169
test
llgcode/draw2d
draw2dpdf/gc.go
FillStringAt
func (gc *GraphicContext) FillStringAt(text string, x, y float64) (cursor float64) { return gc.CreateStringPath(text, x, y) }
go
func (gc *GraphicContext) FillStringAt(text string, x, y float64) (cursor float64) { return gc.CreateStringPath(text, x, y) }
[ "func", "(", "gc", "*", "GraphicContext", ")", "FillStringAt", "(", "text", "string", ",", "x", ",", "y", "float64", ")", "(", "cursor", "float64", ")", "{", "return", "gc", ".", "CreateStringPath", "(", "text", ",", "x", ",", "y", ")", "\n", "}" ]
// FillStringAt draws a string at x, y
[ "FillStringAt", "draws", "a", "string", "at", "x", "y" ]
f52c8a71aff06ab8df41843d33ab167b36c971cd
https://github.com/llgcode/draw2d/blob/f52c8a71aff06ab8df41843d33ab167b36c971cd/draw2dpdf/gc.go#L177-L179
test
llgcode/draw2d
draw2dpdf/gc.go
SetStrokeColor
func (gc *GraphicContext) SetStrokeColor(c color.Color) { gc.StackGraphicContext.SetStrokeColor(c) gc.pdf.SetDrawColor(rgb(c)) }
go
func (gc *GraphicContext) SetStrokeColor(c color.Color) { gc.StackGraphicContext.SetStrokeColor(c) gc.pdf.SetDrawColor(rgb(c)) }
[ "func", "(", "gc", "*", "GraphicContext", ")", "SetStrokeColor", "(", "c", "color", ".", "Color", ")", "{", "gc", ".", "StackGraphicContext", ".", "SetStrokeColor", "(", "c", ")", "\n", "gc", ".", "pdf", ".", "SetDrawColor", "(", "rgb", "(", "c", ")", ...
// overwrite StackGraphicContext methods // SetStrokeColor sets the stroke color
[ "overwrite", "StackGraphicContext", "methods", "SetStrokeColor", "sets", "the", "stroke", "color" ]
f52c8a71aff06ab8df41843d33ab167b36c971cd
https://github.com/llgcode/draw2d/blob/f52c8a71aff06ab8df41843d33ab167b36c971cd/draw2dpdf/gc.go#L249-L252
test
llgcode/draw2d
draw2dpdf/gc.go
SetFillColor
func (gc *GraphicContext) SetFillColor(c color.Color) { gc.StackGraphicContext.SetFillColor(c) gc.pdf.SetFillColor(rgb(c)) gc.pdf.SetTextColor(rgb(c)) }
go
func (gc *GraphicContext) SetFillColor(c color.Color) { gc.StackGraphicContext.SetFillColor(c) gc.pdf.SetFillColor(rgb(c)) gc.pdf.SetTextColor(rgb(c)) }
[ "func", "(", "gc", "*", "GraphicContext", ")", "SetFillColor", "(", "c", "color", ".", "Color", ")", "{", "gc", ".", "StackGraphicContext", ".", "SetFillColor", "(", "c", ")", "\n", "gc", ".", "pdf", ".", "SetFillColor", "(", "rgb", "(", "c", ")", ")...
// SetFillColor sets the fill and text color
[ "SetFillColor", "sets", "the", "fill", "and", "text", "color" ]
f52c8a71aff06ab8df41843d33ab167b36c971cd
https://github.com/llgcode/draw2d/blob/f52c8a71aff06ab8df41843d33ab167b36c971cd/draw2dpdf/gc.go#L255-L259
test
llgcode/draw2d
draw2dpdf/gc.go
SetLineDash
func (gc *GraphicContext) SetLineDash(Dash []float64, DashOffset float64) { gc.StackGraphicContext.SetLineDash(Dash, DashOffset) gc.pdf.SetDashPattern(Dash, DashOffset) }
go
func (gc *GraphicContext) SetLineDash(Dash []float64, DashOffset float64) { gc.StackGraphicContext.SetLineDash(Dash, DashOffset) gc.pdf.SetDashPattern(Dash, DashOffset) }
[ "func", "(", "gc", "*", "GraphicContext", ")", "SetLineDash", "(", "Dash", "[", "]", "float64", ",", "DashOffset", "float64", ")", "{", "gc", ".", "StackGraphicContext", ".", "SetLineDash", "(", "Dash", ",", "DashOffset", ")", "\n", "gc", ".", "pdf", "."...
// SetLineDash sets the line dash pattern
[ "SetLineDash", "sets", "the", "line", "dash", "pattern" ]
f52c8a71aff06ab8df41843d33ab167b36c971cd
https://github.com/llgcode/draw2d/blob/f52c8a71aff06ab8df41843d33ab167b36c971cd/draw2dpdf/gc.go#L302-L305
test
llgcode/draw2d
draw2dpdf/gc.go
SetLineWidth
func (gc *GraphicContext) SetLineWidth(LineWidth float64) { gc.StackGraphicContext.SetLineWidth(LineWidth) gc.pdf.SetLineWidth(LineWidth) }
go
func (gc *GraphicContext) SetLineWidth(LineWidth float64) { gc.StackGraphicContext.SetLineWidth(LineWidth) gc.pdf.SetLineWidth(LineWidth) }
[ "func", "(", "gc", "*", "GraphicContext", ")", "SetLineWidth", "(", "LineWidth", "float64", ")", "{", "gc", ".", "StackGraphicContext", ".", "SetLineWidth", "(", "LineWidth", ")", "\n", "gc", ".", "pdf", ".", "SetLineWidth", "(", "LineWidth", ")", "\n", "}...
// SetLineWidth sets the line width
[ "SetLineWidth", "sets", "the", "line", "width" ]
f52c8a71aff06ab8df41843d33ab167b36c971cd
https://github.com/llgcode/draw2d/blob/f52c8a71aff06ab8df41843d33ab167b36c971cd/draw2dpdf/gc.go#L308-L311
test
llgcode/draw2d
samples/helloworld/helloworld.go
Main
func Main(gc draw2d.GraphicContext, ext string) (string, error) { // Draw hello world Draw(gc, fmt.Sprintf("Hello World %d dpi", gc.GetDPI())) // Return the output filename return samples.Output("helloworld", ext), nil }
go
func Main(gc draw2d.GraphicContext, ext string) (string, error) { // Draw hello world Draw(gc, fmt.Sprintf("Hello World %d dpi", gc.GetDPI())) // Return the output filename return samples.Output("helloworld", ext), nil }
[ "func", "Main", "(", "gc", "draw2d", ".", "GraphicContext", ",", "ext", "string", ")", "(", "string", ",", "error", ")", "{", "Draw", "(", "gc", ",", "fmt", ".", "Sprintf", "(", "\"Hello World %d dpi\"", ",", "gc", ".", "GetDPI", "(", ")", ")", ")", ...
// Main draws "Hello World" and returns the filename. This should only be // used during testing.
[ "Main", "draws", "Hello", "World", "and", "returns", "the", "filename", ".", "This", "should", "only", "be", "used", "during", "testing", "." ]
f52c8a71aff06ab8df41843d33ab167b36c971cd
https://github.com/llgcode/draw2d/blob/f52c8a71aff06ab8df41843d33ab167b36c971cd/samples/helloworld/helloworld.go#L19-L25
test
llgcode/draw2d
samples/helloworld/helloworld.go
Draw
func Draw(gc draw2d.GraphicContext, text string) { // Draw a rounded rectangle using default colors draw2dkit.RoundedRectangle(gc, 5, 5, 135, 95, 10, 10) gc.FillStroke() // Set the font luximbi.ttf gc.SetFontData(draw2d.FontData{Name: "luxi", Family: draw2d.FontFamilyMono, Style: draw2d.FontStyleBold | draw2d.Fon...
go
func Draw(gc draw2d.GraphicContext, text string) { // Draw a rounded rectangle using default colors draw2dkit.RoundedRectangle(gc, 5, 5, 135, 95, 10, 10) gc.FillStroke() // Set the font luximbi.ttf gc.SetFontData(draw2d.FontData{Name: "luxi", Family: draw2d.FontFamilyMono, Style: draw2d.FontStyleBold | draw2d.Fon...
[ "func", "Draw", "(", "gc", "draw2d", ".", "GraphicContext", ",", "text", "string", ")", "{", "draw2dkit", ".", "RoundedRectangle", "(", "gc", ",", "5", ",", "5", ",", "135", ",", "95", ",", "10", ",", "10", ")", "\n", "gc", ".", "FillStroke", "(", ...
// Draw "Hello World"
[ "Draw", "Hello", "World" ]
f52c8a71aff06ab8df41843d33ab167b36c971cd
https://github.com/llgcode/draw2d/blob/f52c8a71aff06ab8df41843d33ab167b36c971cd/samples/helloworld/helloworld.go#L28-L40
test
llgcode/draw2d
draw2dimg/fileutil.go
SaveToPngFile
func SaveToPngFile(filePath string, m image.Image) error { // Create the file f, err := os.Create(filePath) if err != nil { return err } defer f.Close() // Create Writer from file b := bufio.NewWriter(f) // Write the image into the buffer err = png.Encode(b, m) if err != nil { return err } err = b.Flush...
go
func SaveToPngFile(filePath string, m image.Image) error { // Create the file f, err := os.Create(filePath) if err != nil { return err } defer f.Close() // Create Writer from file b := bufio.NewWriter(f) // Write the image into the buffer err = png.Encode(b, m) if err != nil { return err } err = b.Flush...
[ "func", "SaveToPngFile", "(", "filePath", "string", ",", "m", "image", ".", "Image", ")", "error", "{", "f", ",", "err", ":=", "os", ".", "Create", "(", "filePath", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "defer"...
// SaveToPngFile create and save an image to a file using PNG format
[ "SaveToPngFile", "create", "and", "save", "an", "image", "to", "a", "file", "using", "PNG", "format" ]
f52c8a71aff06ab8df41843d33ab167b36c971cd
https://github.com/llgcode/draw2d/blob/f52c8a71aff06ab8df41843d33ab167b36c971cd/draw2dimg/fileutil.go#L11-L30
test
llgcode/draw2d
draw2dimg/fileutil.go
LoadFromPngFile
func LoadFromPngFile(filePath string) (image.Image, error) { // Open file f, err := os.OpenFile(filePath, 0, 0) if err != nil { return nil, err } defer f.Close() b := bufio.NewReader(f) img, err := png.Decode(b) if err != nil { return nil, err } return img, nil }
go
func LoadFromPngFile(filePath string) (image.Image, error) { // Open file f, err := os.OpenFile(filePath, 0, 0) if err != nil { return nil, err } defer f.Close() b := bufio.NewReader(f) img, err := png.Decode(b) if err != nil { return nil, err } return img, nil }
[ "func", "LoadFromPngFile", "(", "filePath", "string", ")", "(", "image", ".", "Image", ",", "error", ")", "{", "f", ",", "err", ":=", "os", ".", "OpenFile", "(", "filePath", ",", "0", ",", "0", ")", "\n", "if", "err", "!=", "nil", "{", "return", ...
// LoadFromPngFile Open a png file
[ "LoadFromPngFile", "Open", "a", "png", "file" ]
f52c8a71aff06ab8df41843d33ab167b36c971cd
https://github.com/llgcode/draw2d/blob/f52c8a71aff06ab8df41843d33ab167b36c971cd/draw2dimg/fileutil.go#L33-L46
test
llgcode/draw2d
samples/samples.go
Resource
func Resource(folder, filename, ext string) string { var root string if ext == "pdf" || ext == "svg" { root = "../" } return fmt.Sprintf("%sresource/%s/%s", root, folder, filename) }
go
func Resource(folder, filename, ext string) string { var root string if ext == "pdf" || ext == "svg" { root = "../" } return fmt.Sprintf("%sresource/%s/%s", root, folder, filename) }
[ "func", "Resource", "(", "folder", ",", "filename", ",", "ext", "string", ")", "string", "{", "var", "root", "string", "\n", "if", "ext", "==", "\"pdf\"", "||", "ext", "==", "\"svg\"", "{", "root", "=", "\"../\"", "\n", "}", "\n", "return", "fmt", "....
// Resource returns a resource filename for testing.
[ "Resource", "returns", "a", "resource", "filename", "for", "testing", "." ]
f52c8a71aff06ab8df41843d33ab167b36c971cd
https://github.com/llgcode/draw2d/blob/f52c8a71aff06ab8df41843d33ab167b36c971cd/samples/samples.go#L9-L15
test
llgcode/draw2d
samples/samples.go
Output
func Output(name, ext string) string { var root string if ext == "pdf" || ext == "svg" { root = "../" } return fmt.Sprintf("%soutput/samples/%s.%s", root, name, ext) }
go
func Output(name, ext string) string { var root string if ext == "pdf" || ext == "svg" { root = "../" } return fmt.Sprintf("%soutput/samples/%s.%s", root, name, ext) }
[ "func", "Output", "(", "name", ",", "ext", "string", ")", "string", "{", "var", "root", "string", "\n", "if", "ext", "==", "\"pdf\"", "||", "ext", "==", "\"svg\"", "{", "root", "=", "\"../\"", "\n", "}", "\n", "return", "fmt", ".", "Sprintf", "(", ...
// Output returns the output filename for testing.
[ "Output", "returns", "the", "output", "filename", "for", "testing", "." ]
f52c8a71aff06ab8df41843d33ab167b36c971cd
https://github.com/llgcode/draw2d/blob/f52c8a71aff06ab8df41843d33ab167b36c971cd/samples/samples.go#L18-L24
test
llgcode/draw2d
samples/postscript/postscript.go
Main
func Main(gc draw2d.GraphicContext, ext string) (string, error) { gc.Save() // flip the image gc.Translate(0, 200) gc.Scale(0.35, -0.35) gc.Translate(70, -200) // Tiger postscript drawing tiger := samples.Resource("image", "tiger.ps", ext) // Draw tiger Draw(gc, tiger) gc.Restore() // Return the output f...
go
func Main(gc draw2d.GraphicContext, ext string) (string, error) { gc.Save() // flip the image gc.Translate(0, 200) gc.Scale(0.35, -0.35) gc.Translate(70, -200) // Tiger postscript drawing tiger := samples.Resource("image", "tiger.ps", ext) // Draw tiger Draw(gc, tiger) gc.Restore() // Return the output f...
[ "func", "Main", "(", "gc", "draw2d", ".", "GraphicContext", ",", "ext", "string", ")", "(", "string", ",", "error", ")", "{", "gc", ".", "Save", "(", ")", "\n", "gc", ".", "Translate", "(", "0", ",", "200", ")", "\n", "gc", ".", "Scale", "(", "...
// Main draws the tiger
[ "Main", "draws", "the", "tiger" ]
f52c8a71aff06ab8df41843d33ab167b36c971cd
https://github.com/llgcode/draw2d/blob/f52c8a71aff06ab8df41843d33ab167b36c971cd/samples/postscript/postscript.go#L16-L33
test