id
int32
0
167k
repo
stringlengths
5
54
path
stringlengths
4
155
func_name
stringlengths
1
118
original_string
stringlengths
52
85.5k
language
stringclasses
1 value
code
stringlengths
52
85.5k
code_tokens
list
docstring
stringlengths
6
2.61k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
85
252
141,600
fastly/go-utils
suppress/suppress.go
WrapFor
func WrapFor(depth int, duration time.Duration, id string, f func(int, string)) { pc, file, line, _ := runtime.Caller(depth) key := locKey{pc, id} lock.RLock() state, exists := suppressors[key] lock.RUnlock() if !exists { lock.Lock() state, exists = suppressors[key] if !exists { state = &suppressorState...
go
func WrapFor(depth int, duration time.Duration, id string, f func(int, string)) { pc, file, line, _ := runtime.Caller(depth) key := locKey{pc, id} lock.RLock() state, exists := suppressors[key] lock.RUnlock() if !exists { lock.Lock() state, exists = suppressors[key] if !exists { state = &suppressorState...
[ "func", "WrapFor", "(", "depth", "int", ",", "duration", "time", ".", "Duration", ",", "id", "string", ",", "f", "func", "(", "int", ",", "string", ")", ")", "{", "pc", ",", "file", ",", "line", ",", "_", ":=", "runtime", ".", "Caller", "(", "dep...
// WrapFor is the same as For, except the depth of the call stack can be // chosen for what ID to tag and coalesce. runtime.Caller will have depth 0, and the // call to this function will have depth 1, so any additional layers before calling // this function should have depth >= 1.
[ "WrapFor", "is", "the", "same", "as", "For", "except", "the", "depth", "of", "the", "call", "stack", "can", "be", "chosen", "for", "what", "ID", "to", "tag", "and", "coalesce", ".", "runtime", ".", "Caller", "will", "have", "depth", "0", "and", "the", ...
d95a45783239f69a867fec572fb7675bcee07d88
https://github.com/fastly/go-utils/blob/d95a45783239f69a867fec572fb7675bcee07d88/suppress/suppress.go#L42-L86
141,601
fastly/go-utils
executable/executable_darwin.go
Path
func Path() (string, error) { var buflen C.uint32_t = 1024 buf := make([]C.char, buflen) ret := C._NSGetExecutablePath(&buf[0], &buflen) if ret == -1 { buf = make([]C.char, buflen) C._NSGetExecutablePath(&buf[0], &buflen) } return C.GoString(&buf[0]), nil }
go
func Path() (string, error) { var buflen C.uint32_t = 1024 buf := make([]C.char, buflen) ret := C._NSGetExecutablePath(&buf[0], &buflen) if ret == -1 { buf = make([]C.char, buflen) C._NSGetExecutablePath(&buf[0], &buflen) } return C.GoString(&buf[0]), nil }
[ "func", "Path", "(", ")", "(", "string", ",", "error", ")", "{", "var", "buflen", "C", ".", "uint32_t", "=", "1024", "\n", "buf", ":=", "make", "(", "[", "]", "C", ".", "char", ",", "buflen", ")", "\n\n", "ret", ":=", "C", ".", "_NSGetExecutableP...
// documentation in executable_linux.go
[ "documentation", "in", "executable_linux", ".", "go" ]
d95a45783239f69a867fec572fb7675bcee07d88
https://github.com/fastly/go-utils/blob/d95a45783239f69a867fec572fb7675bcee07d88/executable/executable_darwin.go#L17-L27
141,602
fastly/go-utils
server/server.go
NewServer
func NewServer(addrs map[string]string) (s *Server, err error) { s = &Server{ Listeners: make(map[string]net.Listener), control: make(SignalChan), } for label, addr := range addrs { var listener net.Listener listener, err = net.Listen("tcp", addr) if err != nil { s.closeListeners() s = nil retu...
go
func NewServer(addrs map[string]string) (s *Server, err error) { s = &Server{ Listeners: make(map[string]net.Listener), control: make(SignalChan), } for label, addr := range addrs { var listener net.Listener listener, err = net.Listen("tcp", addr) if err != nil { s.closeListeners() s = nil retu...
[ "func", "NewServer", "(", "addrs", "map", "[", "string", "]", "string", ")", "(", "s", "*", "Server", ",", "err", "error", ")", "{", "s", "=", "&", "Server", "{", "Listeners", ":", "make", "(", "map", "[", "string", "]", "net", ".", "Listener", "...
// addrs is updated with the actual listener address after binding. This allows // requesting a random unused port by omitting the port part of an Addr.
[ "addrs", "is", "updated", "with", "the", "actual", "listener", "address", "after", "binding", ".", "This", "allows", "requesting", "a", "random", "unused", "port", "by", "omitting", "the", "port", "part", "of", "an", "Addr", "." ]
d95a45783239f69a867fec572fb7675bcee07d88
https://github.com/fastly/go-utils/blob/d95a45783239f69a867fec572fb7675bcee07d88/server/server.go#L36-L54
141,603
fastly/go-utils
common/strings.go
EmbeddedLines
func EmbeddedLines(inputs []string) []string { commonalities := make(map[string]int) for _, input := range inputs { split := strings.Split(input, "\n") for _, line := range split { commonalities[line] += 1 } } max := 0 for _, count := range commonalities { if count > max { max = count } } commo...
go
func EmbeddedLines(inputs []string) []string { commonalities := make(map[string]int) for _, input := range inputs { split := strings.Split(input, "\n") for _, line := range split { commonalities[line] += 1 } } max := 0 for _, count := range commonalities { if count > max { max = count } } commo...
[ "func", "EmbeddedLines", "(", "inputs", "[", "]", "string", ")", "[", "]", "string", "{", "commonalities", ":=", "make", "(", "map", "[", "string", "]", "int", ")", "\n", "for", "_", ",", "input", ":=", "range", "inputs", "{", "split", ":=", "strings...
// EmbeddedLines returns a sorted slice of lines that // are common in every input string when the string is split // by \n. That is, the input string has embedded newlines.
[ "EmbeddedLines", "returns", "a", "sorted", "slice", "of", "lines", "that", "are", "common", "in", "every", "input", "string", "when", "the", "string", "is", "split", "by", "\\", "n", ".", "That", "is", "the", "input", "string", "has", "embedded", "newlines...
d95a45783239f69a867fec572fb7675bcee07d88
https://github.com/fastly/go-utils/blob/d95a45783239f69a867fec572fb7675bcee07d88/common/strings.go#L24-L51
141,604
fastly/go-utils
common/strings.go
Strings
func Strings(input []string) []StringPop { commonalities := make(map[string]int) for _, line := range input { commonalities[line] += 1 } lineCounts := []StringPop{} for line, count := range commonalities { lineCounts = append(lineCounts, StringPop{line, count}) } sort.Sort(sort.Reverse(StringPops(lineCount...
go
func Strings(input []string) []StringPop { commonalities := make(map[string]int) for _, line := range input { commonalities[line] += 1 } lineCounts := []StringPop{} for line, count := range commonalities { lineCounts = append(lineCounts, StringPop{line, count}) } sort.Sort(sort.Reverse(StringPops(lineCount...
[ "func", "Strings", "(", "input", "[", "]", "string", ")", "[", "]", "StringPop", "{", "commonalities", ":=", "make", "(", "map", "[", "string", "]", "int", ")", "\n", "for", "_", ",", "line", ":=", "range", "input", "{", "commonalities", "[", "line",...
// Strings returns an descending order slice of StringPop with // each StringPop containing a line and the corresponding // amount of times it it occurs in the input slice.
[ "Strings", "returns", "an", "descending", "order", "slice", "of", "StringPop", "with", "each", "StringPop", "containing", "a", "line", "and", "the", "corresponding", "amount", "of", "times", "it", "it", "occurs", "in", "the", "input", "slice", "." ]
d95a45783239f69a867fec572fb7675bcee07d88
https://github.com/fastly/go-utils/blob/d95a45783239f69a867fec572fb7675bcee07d88/common/strings.go#L56-L69
141,605
fastly/go-utils
executable/executable_linux.go
BinaryDuplicateProcessIDs
func BinaryDuplicateProcessIDs(binary string) (pids []int, err error) { infos, err := ioutil.ReadDir("/proc/") if err != nil { return nil, fmt.Errorf("Couldn't read /proc: %s", err) } for _, info := range infos { // only want numeric directories pid, err := strconv.Atoi(info.Name()) if err != nil || !info.I...
go
func BinaryDuplicateProcessIDs(binary string) (pids []int, err error) { infos, err := ioutil.ReadDir("/proc/") if err != nil { return nil, fmt.Errorf("Couldn't read /proc: %s", err) } for _, info := range infos { // only want numeric directories pid, err := strconv.Atoi(info.Name()) if err != nil || !info.I...
[ "func", "BinaryDuplicateProcessIDs", "(", "binary", "string", ")", "(", "pids", "[", "]", "int", ",", "err", "error", ")", "{", "infos", ",", "err", ":=", "ioutil", ".", "ReadDir", "(", "\"", "\"", ")", "\n", "if", "err", "!=", "nil", "{", "return", ...
// BinaryDuplicateProcessIDs returns all pids belonging to processes with // the same passed binary name.
[ "BinaryDuplicateProcessIDs", "returns", "all", "pids", "belonging", "to", "processes", "with", "the", "same", "passed", "binary", "name", "." ]
d95a45783239f69a867fec572fb7675bcee07d88
https://github.com/fastly/go-utils/blob/d95a45783239f69a867fec572fb7675bcee07d88/executable/executable_linux.go#L20-L41
141,606
xeipuuv/gojsonreference
reference.go
Inherits
func (r *JsonReference) Inherits(child JsonReference) (*JsonReference, error) { if child.GetUrl() == nil { return nil, errors.New("childUrl is nil!") } if r.GetUrl() == nil { return nil, errors.New("parentUrl is nil!") } // Get a copy of the parent url to make sure we do not modify the original. // URL refe...
go
func (r *JsonReference) Inherits(child JsonReference) (*JsonReference, error) { if child.GetUrl() == nil { return nil, errors.New("childUrl is nil!") } if r.GetUrl() == nil { return nil, errors.New("parentUrl is nil!") } // Get a copy of the parent url to make sure we do not modify the original. // URL refe...
[ "func", "(", "r", "*", "JsonReference", ")", "Inherits", "(", "child", "JsonReference", ")", "(", "*", "JsonReference", ",", "error", ")", "{", "if", "child", ".", "GetUrl", "(", ")", "==", "nil", "{", "return", "nil", ",", "errors", ".", "New", "(",...
// Creates a new reference from a parent and a child // If the child cannot inherit from the parent, an error is returned
[ "Creates", "a", "new", "reference", "from", "a", "parent", "and", "a", "child", "If", "the", "child", "cannot", "inherit", "from", "the", "parent", "an", "error", "is", "returned" ]
bd5ef7bd5415a7ac448318e64f11a24cd21e594b
https://github.com/xeipuuv/gojsonreference/blob/bd5ef7bd5415a7ac448318e64f11a24cd21e594b/reference.go#L127-L147
141,607
pivotal-cf/cf-redis-broker
resetter/resetter.go
New
func New(defaultConfPath, liveConfPath string, portChecker checker) *Resetter { return &Resetter{ defaultConfPath: defaultConfPath, liveConfPath: liveConfPath, portChecker: portChecker, timeout: time.Second * 30, Monit: monit.New(), redis: redis.New(), } }
go
func New(defaultConfPath, liveConfPath string, portChecker checker) *Resetter { return &Resetter{ defaultConfPath: defaultConfPath, liveConfPath: liveConfPath, portChecker: portChecker, timeout: time.Second * 30, Monit: monit.New(), redis: redis.New(), } }
[ "func", "New", "(", "defaultConfPath", ",", "liveConfPath", "string", ",", "portChecker", "checker", ")", "*", "Resetter", "{", "return", "&", "Resetter", "{", "defaultConfPath", ":", "defaultConfPath", ",", "liveConfPath", ":", "liveConfPath", ",", "portChecker",...
//New is the correct way to instantiate a Resetter
[ "New", "is", "the", "correct", "way", "to", "instantiate", "a", "Resetter" ]
eee7f27ca7a37f0134586d5e02634ade81be85a2
https://github.com/pivotal-cf/cf-redis-broker/blob/eee7f27ca7a37f0134586d5e02634ade81be85a2/resetter/resetter.go#L31-L40
141,608
pivotal-cf/cf-redis-broker
resetter/resetter.go
ResetRedis
func (resetter *Resetter) ResetRedis() error { if err := resetter.stopRedis(); err != nil { return err } if err := resetter.deleteData(); err != nil { return err } if err := resetter.resetConfigWithNewPassword(); err != nil { return err } if err := resetter.startRedis(); err != nil { return err } c...
go
func (resetter *Resetter) ResetRedis() error { if err := resetter.stopRedis(); err != nil { return err } if err := resetter.deleteData(); err != nil { return err } if err := resetter.resetConfigWithNewPassword(); err != nil { return err } if err := resetter.startRedis(); err != nil { return err } c...
[ "func", "(", "resetter", "*", "Resetter", ")", "ResetRedis", "(", ")", "error", "{", "if", "err", ":=", "resetter", ".", "stopRedis", "(", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "if", "err", ":=", "resetter", ".", "d...
//ResetRedis stops redis, clears the database and starts redis
[ "ResetRedis", "stops", "redis", "clears", "the", "database", "and", "starts", "redis" ]
eee7f27ca7a37f0134586d5e02634ade81be85a2
https://github.com/pivotal-cf/cf-redis-broker/blob/eee7f27ca7a37f0134586d5e02634ade81be85a2/resetter/resetter.go#L43-L71
141,609
pivotal-cf/cf-redis-broker
consistency/instances_provider.go
Instances
func (s *stateFileAvailableInstances) Instances() ([]redis.Instance, error) { reader, err := os.Open(s.path) if err != nil { return nil, err } state := &struct { AvailableInstances []redis.Instance `json:"available_instances"` }{} if err := json.NewDecoder(reader).Decode(state); err != nil { return nil, e...
go
func (s *stateFileAvailableInstances) Instances() ([]redis.Instance, error) { reader, err := os.Open(s.path) if err != nil { return nil, err } state := &struct { AvailableInstances []redis.Instance `json:"available_instances"` }{} if err := json.NewDecoder(reader).Decode(state); err != nil { return nil, e...
[ "func", "(", "s", "*", "stateFileAvailableInstances", ")", "Instances", "(", ")", "(", "[", "]", "redis", ".", "Instance", ",", "error", ")", "{", "reader", ",", "err", ":=", "os", ".", "Open", "(", "s", ".", "path", ")", "\n", "if", "err", "!=", ...
// Instances reads and returns the available instances from the state file.
[ "Instances", "reads", "and", "returns", "the", "available", "instances", "from", "the", "state", "file", "." ]
eee7f27ca7a37f0134586d5e02634ade81be85a2
https://github.com/pivotal-cf/cf-redis-broker/blob/eee7f27ca7a37f0134586d5e02634ade81be85a2/consistency/instances_provider.go#L23-L38
141,610
pivotal-cf/cf-redis-broker
utils/files.go
MoveFile
func MoveFile(source, destination string) error { sourceFile, err := os.Open(source) if err != nil { return err } defer sourceFile.Close() destinationFile, err := os.Create(destination) if err != nil { return err } defer destinationFile.Close() _, err = io.Copy(destinationFile, sourceFile) if err != nil...
go
func MoveFile(source, destination string) error { sourceFile, err := os.Open(source) if err != nil { return err } defer sourceFile.Close() destinationFile, err := os.Create(destination) if err != nil { return err } defer destinationFile.Close() _, err = io.Copy(destinationFile, sourceFile) if err != nil...
[ "func", "MoveFile", "(", "source", ",", "destination", "string", ")", "error", "{", "sourceFile", ",", "err", ":=", "os", ".", "Open", "(", "source", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "defer", "sourceFile", "...
// os.Rename does not work across partition boundaries, have to copy the file // instead, and Go does not have an existing function for it.
[ "os", ".", "Rename", "does", "not", "work", "across", "partition", "boundaries", "have", "to", "copy", "the", "file", "instead", "and", "Go", "does", "not", "have", "an", "existing", "function", "for", "it", "." ]
eee7f27ca7a37f0134586d5e02634ade81be85a2
https://github.com/pivotal-cf/cf-redis-broker/blob/eee7f27ca7a37f0134586d5e02634ade81be85a2/utils/files.go#L10-L32
141,611
chai2010/gettext-go
gettext/po/comment.go
GetFuzzy
func (p *Comment) GetFuzzy() bool { for _, s := range p.Flags { if s == "fuzzy" { return true } } return false }
go
func (p *Comment) GetFuzzy() bool { for _, s := range p.Flags { if s == "fuzzy" { return true } } return false }
[ "func", "(", "p", "*", "Comment", ")", "GetFuzzy", "(", ")", "bool", "{", "for", "_", ",", "s", ":=", "range", "p", ".", "Flags", "{", "if", "s", "==", "\"", "\"", "{", "return", "true", "\n", "}", "\n", "}", "\n", "return", "false", "\n", "}...
// GetFuzzy gets the fuzzy flag.
[ "GetFuzzy", "gets", "the", "fuzzy", "flag", "." ]
bf70f2a70fb1b1f36d90d671a72795984eab0fcb
https://github.com/chai2010/gettext-go/blob/bf70f2a70fb1b1f36d90d671a72795984eab0fcb/gettext/po/comment.go#L218-L225
141,612
chai2010/gettext-go
gettext/po/comment.go
String
func (p Comment) String() string { var buf bytes.Buffer if p.TranslatorComment != "" { ss := strings.Split(p.TranslatorComment, "\n") for i := 0; i < len(ss); i++ { fmt.Fprintf(&buf, "# %s\n", ss[i]) } } if p.ExtractedComment != "" { ss := strings.Split(p.ExtractedComment, "\n") for i := 0; i < len(ss)...
go
func (p Comment) String() string { var buf bytes.Buffer if p.TranslatorComment != "" { ss := strings.Split(p.TranslatorComment, "\n") for i := 0; i < len(ss); i++ { fmt.Fprintf(&buf, "# %s\n", ss[i]) } } if p.ExtractedComment != "" { ss := strings.Split(p.ExtractedComment, "\n") for i := 0; i < len(ss)...
[ "func", "(", "p", "Comment", ")", "String", "(", ")", "string", "{", "var", "buf", "bytes", ".", "Buffer", "\n", "if", "p", ".", "TranslatorComment", "!=", "\"", "\"", "{", "ss", ":=", "strings", ".", "Split", "(", "p", ".", "TranslatorComment", ",",...
// String returns the po format comment string.
[ "String", "returns", "the", "po", "format", "comment", "string", "." ]
bf70f2a70fb1b1f36d90d671a72795984eab0fcb
https://github.com/chai2010/gettext-go/blob/bf70f2a70fb1b1f36d90d671a72795984eab0fcb/gettext/po/comment.go#L233-L270
141,613
chai2010/gettext-go
gettext/po/message.go
String
func (p Message) String() string { var buf bytes.Buffer fmt.Fprintf(&buf, "%s", p.Comment.String()) fmt.Fprintf(&buf, "msgid %s", encodePoString(p.MsgId)) if p.MsgIdPlural != "" { fmt.Fprintf(&buf, "msgid_plural %s", encodePoString(p.MsgIdPlural)) } if p.MsgStr != "" { fmt.Fprintf(&buf, "msgstr %s", encodePoS...
go
func (p Message) String() string { var buf bytes.Buffer fmt.Fprintf(&buf, "%s", p.Comment.String()) fmt.Fprintf(&buf, "msgid %s", encodePoString(p.MsgId)) if p.MsgIdPlural != "" { fmt.Fprintf(&buf, "msgid_plural %s", encodePoString(p.MsgIdPlural)) } if p.MsgStr != "" { fmt.Fprintf(&buf, "msgstr %s", encodePoS...
[ "func", "(", "p", "Message", ")", "String", "(", ")", "string", "{", "var", "buf", "bytes", ".", "Buffer", "\n", "fmt", ".", "Fprintf", "(", "&", "buf", ",", "\"", "\"", ",", "p", ".", "Comment", ".", "String", "(", ")", ")", "\n", "fmt", ".", ...
// String returns the po format entry string.
[ "String", "returns", "the", "po", "format", "entry", "string", "." ]
bf70f2a70fb1b1f36d90d671a72795984eab0fcb
https://github.com/chai2010/gettext-go/blob/bf70f2a70fb1b1f36d90d671a72795984eab0fcb/gettext/po/message.go#L175-L189
141,614
chai2010/gettext-go
gettext/po/header.go
String
func (p Header) String() string { var buf bytes.Buffer fmt.Fprintf(&buf, "%s", p.Comment.String()) fmt.Fprintf(&buf, `msgid ""`+"\n") fmt.Fprintf(&buf, `msgstr ""`+"\n") fmt.Fprintf(&buf, `"%s: %s\n"`+"\n", "Project-Id-Version", p.ProjectIdVersion) fmt.Fprintf(&buf, `"%s: %s\n"`+"\n", "Report-Msgid-Bugs-To", p.Re...
go
func (p Header) String() string { var buf bytes.Buffer fmt.Fprintf(&buf, "%s", p.Comment.String()) fmt.Fprintf(&buf, `msgid ""`+"\n") fmt.Fprintf(&buf, `msgstr ""`+"\n") fmt.Fprintf(&buf, `"%s: %s\n"`+"\n", "Project-Id-Version", p.ProjectIdVersion) fmt.Fprintf(&buf, `"%s: %s\n"`+"\n", "Report-Msgid-Bugs-To", p.Re...
[ "func", "(", "p", "Header", ")", "String", "(", ")", "string", "{", "var", "buf", "bytes", ".", "Buffer", "\n", "fmt", ".", "Fprintf", "(", "&", "buf", ",", "\"", "\"", ",", "p", ".", "Comment", ".", "String", "(", ")", ")", "\n", "fmt", ".", ...
// String returns the po format header string.
[ "String", "returns", "the", "po", "format", "header", "string", "." ]
bf70f2a70fb1b1f36d90d671a72795984eab0fcb
https://github.com/chai2010/gettext-go/blob/bf70f2a70fb1b1f36d90d671a72795984eab0fcb/gettext/po/header.go#L82-L106
141,615
chai2010/gettext-go
gettext/po/file.go
Load
func Load(name string) (*File, error) { data, err := ioutil.ReadFile(name) if err != nil { return nil, err } return LoadData(data) }
go
func Load(name string) (*File, error) { data, err := ioutil.ReadFile(name) if err != nil { return nil, err } return LoadData(data) }
[ "func", "Load", "(", "name", "string", ")", "(", "*", "File", ",", "error", ")", "{", "data", ",", "err", ":=", "ioutil", ".", "ReadFile", "(", "name", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "ret...
// Load loads a named po file.
[ "Load", "loads", "a", "named", "po", "file", "." ]
bf70f2a70fb1b1f36d90d671a72795984eab0fcb
https://github.com/chai2010/gettext-go/blob/bf70f2a70fb1b1f36d90d671a72795984eab0fcb/gettext/po/file.go#L24-L30
141,616
chai2010/gettext-go
gettext/po/file.go
LoadData
func LoadData(data []byte) (*File, error) { r := newLineReader(string(data)) var file File for { var msg Message if err := msg.readPoEntry(r); err != nil { if err == io.EOF { return &file, nil } return nil, err } if msg.MsgId == "" { file.MimeHeader.parseHeader(&msg) continue } file.Me...
go
func LoadData(data []byte) (*File, error) { r := newLineReader(string(data)) var file File for { var msg Message if err := msg.readPoEntry(r); err != nil { if err == io.EOF { return &file, nil } return nil, err } if msg.MsgId == "" { file.MimeHeader.parseHeader(&msg) continue } file.Me...
[ "func", "LoadData", "(", "data", "[", "]", "byte", ")", "(", "*", "File", ",", "error", ")", "{", "r", ":=", "newLineReader", "(", "string", "(", "data", ")", ")", "\n", "var", "file", "File", "\n", "for", "{", "var", "msg", "Message", "\n", "if"...
// LoadData loads po file format data.
[ "LoadData", "loads", "po", "file", "format", "data", "." ]
bf70f2a70fb1b1f36d90d671a72795984eab0fcb
https://github.com/chai2010/gettext-go/blob/bf70f2a70fb1b1f36d90d671a72795984eab0fcb/gettext/po/file.go#L33-L50
141,617
chai2010/gettext-go
gettext/po/file.go
Save
func (f *File) Save(name string) error { return ioutil.WriteFile(name, []byte(f.String()), 0666) }
go
func (f *File) Save(name string) error { return ioutil.WriteFile(name, []byte(f.String()), 0666) }
[ "func", "(", "f", "*", "File", ")", "Save", "(", "name", "string", ")", "error", "{", "return", "ioutil", ".", "WriteFile", "(", "name", ",", "[", "]", "byte", "(", "f", ".", "String", "(", ")", ")", ",", "0666", ")", "\n", "}" ]
// Save saves a po file.
[ "Save", "saves", "a", "po", "file", "." ]
bf70f2a70fb1b1f36d90d671a72795984eab0fcb
https://github.com/chai2010/gettext-go/blob/bf70f2a70fb1b1f36d90d671a72795984eab0fcb/gettext/po/file.go#L53-L55
141,618
chai2010/gettext-go
gettext/po/file.go
Data
func (f *File) Data() []byte { // sort the massge as ReferenceFile/ReferenceLine field var messages []Message messages = append(messages, f.Messages...) sort.Sort(byMessages(messages)) var buf bytes.Buffer fmt.Fprintf(&buf, "%s\n", f.MimeHeader.String()) for i := 0; i < len(messages); i++ { fmt.Fprintf(&buf, ...
go
func (f *File) Data() []byte { // sort the massge as ReferenceFile/ReferenceLine field var messages []Message messages = append(messages, f.Messages...) sort.Sort(byMessages(messages)) var buf bytes.Buffer fmt.Fprintf(&buf, "%s\n", f.MimeHeader.String()) for i := 0; i < len(messages); i++ { fmt.Fprintf(&buf, ...
[ "func", "(", "f", "*", "File", ")", "Data", "(", ")", "[", "]", "byte", "{", "// sort the massge as ReferenceFile/ReferenceLine field", "var", "messages", "[", "]", "Message", "\n", "messages", "=", "append", "(", "messages", ",", "f", ".", "Messages", "..."...
// Save returns a po file format data.
[ "Save", "returns", "a", "po", "file", "format", "data", "." ]
bf70f2a70fb1b1f36d90d671a72795984eab0fcb
https://github.com/chai2010/gettext-go/blob/bf70f2a70fb1b1f36d90d671a72795984eab0fcb/gettext/po/file.go#L58-L70
141,619
chai2010/gettext-go
gettext/mo/file.go
Save
func (f *File) Save(name string) error { return ioutil.WriteFile(name, f.Data(), 0666) }
go
func (f *File) Save(name string) error { return ioutil.WriteFile(name, f.Data(), 0666) }
[ "func", "(", "f", "*", "File", ")", "Save", "(", "name", "string", ")", "error", "{", "return", "ioutil", ".", "WriteFile", "(", "name", ",", "f", ".", "Data", "(", ")", ",", "0666", ")", "\n", "}" ]
// Save saves a mo file.
[ "Save", "saves", "a", "mo", "file", "." ]
bf70f2a70fb1b1f36d90d671a72795984eab0fcb
https://github.com/chai2010/gettext-go/blob/bf70f2a70fb1b1f36d90d671a72795984eab0fcb/gettext/mo/file.go#L170-L172
141,620
chai2010/gettext-go
gettext/mo/file.go
String
func (f *File) String() string { var buf bytes.Buffer fmt.Fprintf(&buf, "# version: %d.%d\n", f.MajorVersion, f.MinorVersion) fmt.Fprintf(&buf, "%s\n", f.MimeHeader.String()) fmt.Fprintf(&buf, "\n") for k, v := range f.Messages { fmt.Fprintf(&buf, `msgid "%v"`+"\n", k) fmt.Fprintf(&buf, `msgstr "%s"`+"\n", v....
go
func (f *File) String() string { var buf bytes.Buffer fmt.Fprintf(&buf, "# version: %d.%d\n", f.MajorVersion, f.MinorVersion) fmt.Fprintf(&buf, "%s\n", f.MimeHeader.String()) fmt.Fprintf(&buf, "\n") for k, v := range f.Messages { fmt.Fprintf(&buf, `msgid "%v"`+"\n", k) fmt.Fprintf(&buf, `msgstr "%s"`+"\n", v....
[ "func", "(", "f", "*", "File", ")", "String", "(", ")", "string", "{", "var", "buf", "bytes", ".", "Buffer", "\n", "fmt", ".", "Fprintf", "(", "&", "buf", ",", "\"", "\\n", "\"", ",", "f", ".", "MajorVersion", ",", "f", ".", "MinorVersion", ")", ...
// String returns the po format file string.
[ "String", "returns", "the", "po", "format", "file", "string", "." ]
bf70f2a70fb1b1f36d90d671a72795984eab0fcb
https://github.com/chai2010/gettext-go/blob/bf70f2a70fb1b1f36d90d671a72795984eab0fcb/gettext/mo/file.go#L180-L193
141,621
chai2010/gettext-go
gettext/plural/formula.go
Formula
func Formula(lang string) func(n int) int { if idx := index(lang); idx != -1 { return formulaTable[fmtForms(FormsTable[idx].Value)] } if idx := index("??"); idx != -1 { return formulaTable[fmtForms(FormsTable[idx].Value)] } return func(n int) int { return n } }
go
func Formula(lang string) func(n int) int { if idx := index(lang); idx != -1 { return formulaTable[fmtForms(FormsTable[idx].Value)] } if idx := index("??"); idx != -1 { return formulaTable[fmtForms(FormsTable[idx].Value)] } return func(n int) int { return n } }
[ "func", "Formula", "(", "lang", "string", ")", "func", "(", "n", "int", ")", "int", "{", "if", "idx", ":=", "index", "(", "lang", ")", ";", "idx", "!=", "-", "1", "{", "return", "formulaTable", "[", "fmtForms", "(", "FormsTable", "[", "idx", "]", ...
// Formula provides the language's standard plural formula.
[ "Formula", "provides", "the", "language", "s", "standard", "plural", "formula", "." ]
bf70f2a70fb1b1f36d90d671a72795984eab0fcb
https://github.com/chai2010/gettext-go/blob/bf70f2a70fb1b1f36d90d671a72795984eab0fcb/gettext/plural/formula.go#L12-L22
141,622
chai2010/gettext-go
gettext/mo/encoder.go
encodeData
func encodeData(hdr *moHeader, f *File) []byte { msgList := []Message{f.MimeHeader.toMessage()} for _, v := range f.Messages { if len(v.MsgId) == 0 { continue } if len(v.MsgStr) == 0 && len(v.MsgStrPlural) == 0 { continue } msgList = append(msgList, v) } sort.Sort(byMessages(msgList)) var buf byte...
go
func encodeData(hdr *moHeader, f *File) []byte { msgList := []Message{f.MimeHeader.toMessage()} for _, v := range f.Messages { if len(v.MsgId) == 0 { continue } if len(v.MsgStr) == 0 && len(v.MsgStrPlural) == 0 { continue } msgList = append(msgList, v) } sort.Sort(byMessages(msgList)) var buf byte...
[ "func", "encodeData", "(", "hdr", "*", "moHeader", ",", "f", "*", "File", ")", "[", "]", "byte", "{", "msgList", ":=", "[", "]", "Message", "{", "f", ".", "MimeHeader", ".", "toMessage", "(", ")", "}", "\n", "for", "_", ",", "v", ":=", "range", ...
// encode data and init moHeader
[ "encode", "data", "and", "init", "moHeader" ]
bf70f2a70fb1b1f36d90d671a72795984eab0fcb
https://github.com/chai2010/gettext-go/blob/bf70f2a70fb1b1f36d90d671a72795984eab0fcb/gettext/mo/encoder.go#L40-L76
141,623
chai2010/gettext-go
gettext/mo/encoder.go
encodeHeader
func encodeHeader(hdr *moHeader) []byte { var buf bytes.Buffer binary.Write(&buf, binary.LittleEndian, hdr) return buf.Bytes() }
go
func encodeHeader(hdr *moHeader) []byte { var buf bytes.Buffer binary.Write(&buf, binary.LittleEndian, hdr) return buf.Bytes() }
[ "func", "encodeHeader", "(", "hdr", "*", "moHeader", ")", "[", "]", "byte", "{", "var", "buf", "bytes", ".", "Buffer", "\n", "binary", ".", "Write", "(", "&", "buf", ",", "binary", ".", "LittleEndian", ",", "hdr", ")", "\n", "return", "buf", ".", "...
// must called after encodeData
[ "must", "called", "after", "encodeData" ]
bf70f2a70fb1b1f36d90d671a72795984eab0fcb
https://github.com/chai2010/gettext-go/blob/bf70f2a70fb1b1f36d90d671a72795984eab0fcb/gettext/mo/encoder.go#L79-L83
141,624
facebookarchive/httpdown
httpdown.go
Serve
func (h HTTP) Serve(s *http.Server, l net.Listener) Server { stopTimeout := h.StopTimeout if stopTimeout == 0 { stopTimeout = defaultStopTimeout } killTimeout := h.KillTimeout if killTimeout == 0 { killTimeout = defaultKillTimeout } klock := h.Clock if klock == nil { klock = clock.New() } ss := &server...
go
func (h HTTP) Serve(s *http.Server, l net.Listener) Server { stopTimeout := h.StopTimeout if stopTimeout == 0 { stopTimeout = defaultStopTimeout } killTimeout := h.KillTimeout if killTimeout == 0 { killTimeout = defaultKillTimeout } klock := h.Clock if klock == nil { klock = clock.New() } ss := &server...
[ "func", "(", "h", "HTTP", ")", "Serve", "(", "s", "*", "http", ".", "Server", ",", "l", "net", ".", "Listener", ")", "Server", "{", "stopTimeout", ":=", "h", ".", "StopTimeout", "\n", "if", "stopTimeout", "==", "0", "{", "stopTimeout", "=", "defaultS...
// Serve provides the low-level API which is useful if you're creating your own // net.Listener.
[ "Serve", "provides", "the", "low", "-", "level", "API", "which", "is", "useful", "if", "you", "re", "creating", "your", "own", "net", ".", "Listener", "." ]
5979d39b15c26299dc282711b0d65b113daccea6
https://github.com/facebookarchive/httpdown/blob/5979d39b15c26299dc282711b0d65b113daccea6/httpdown.go#L64-L99
141,625
facebookarchive/httpdown
httpdown.go
ListenAndServe
func (h HTTP) ListenAndServe(s *http.Server) (Server, error) { addr := s.Addr if addr == "" { if s.TLSConfig == nil { addr = ":http" } else { addr = ":https" } } l, err := net.Listen("tcp", addr) if err != nil { stats.BumpSum(h.Stats, "listen.error", 1) return nil, err } if s.TLSConfig != nil { ...
go
func (h HTTP) ListenAndServe(s *http.Server) (Server, error) { addr := s.Addr if addr == "" { if s.TLSConfig == nil { addr = ":http" } else { addr = ":https" } } l, err := net.Listen("tcp", addr) if err != nil { stats.BumpSum(h.Stats, "listen.error", 1) return nil, err } if s.TLSConfig != nil { ...
[ "func", "(", "h", "HTTP", ")", "ListenAndServe", "(", "s", "*", "http", ".", "Server", ")", "(", "Server", ",", "error", ")", "{", "addr", ":=", "s", ".", "Addr", "\n", "if", "addr", "==", "\"", "\"", "{", "if", "s", ".", "TLSConfig", "==", "ni...
// ListenAndServe returns a Server for the given http.Server. It is equivalent // to ListenAndServe from the standard library, but returns immediately. // Requests will be accepted in a background goroutine. If the http.Server has // a non-nil TLSConfig, a TLS enabled listener will be setup.
[ "ListenAndServe", "returns", "a", "Server", "for", "the", "given", "http", ".", "Server", ".", "It", "is", "equivalent", "to", "ListenAndServe", "from", "the", "standard", "library", "but", "returns", "immediately", ".", "Requests", "will", "be", "accepted", "...
5979d39b15c26299dc282711b0d65b113daccea6
https://github.com/facebookarchive/httpdown/blob/5979d39b15c26299dc282711b0d65b113daccea6/httpdown.go#L105-L123
141,626
facebookarchive/httpdown
httpdown.go
ListenAndServe
func ListenAndServe(s *http.Server, hd *HTTP) error { if hd == nil { hd = &HTTP{} } hs, err := hd.ListenAndServe(s) if err != nil { return err } waiterr := make(chan error, 1) go func() { defer close(waiterr) waiterr <- hs.Wait() }() signals := make(chan os.Signal, 10) signal.Notify(signals, syscall...
go
func ListenAndServe(s *http.Server, hd *HTTP) error { if hd == nil { hd = &HTTP{} } hs, err := hd.ListenAndServe(s) if err != nil { return err } waiterr := make(chan error, 1) go func() { defer close(waiterr) waiterr <- hs.Wait() }() signals := make(chan os.Signal, 10) signal.Notify(signals, syscall...
[ "func", "ListenAndServe", "(", "s", "*", "http", ".", "Server", ",", "hd", "*", "HTTP", ")", "error", "{", "if", "hd", "==", "nil", "{", "hd", "=", "&", "HTTP", "{", "}", "\n", "}", "\n", "hs", ",", "err", ":=", "hd", ".", "ListenAndServe", "("...
// ListenAndServe is a convenience function to serve and wait for a SIGTERM // or SIGINT before shutting down.
[ "ListenAndServe", "is", "a", "convenience", "function", "to", "serve", "and", "wait", "for", "a", "SIGTERM", "or", "SIGINT", "before", "shutting", "down", "." ]
5979d39b15c26299dc282711b0d65b113daccea6
https://github.com/facebookarchive/httpdown/blob/5979d39b15c26299dc282711b0d65b113daccea6/httpdown.go#L343-L376
141,627
Clever/leakybucket
redis/redis.go
New
func New(network, address string) (*Storage, error) { s := &Storage{ pool: redis.NewPool(func() (redis.Conn, error) { return redis.Dial(network, address) }, 5)} // When using a connection pool, you only get connection errors while trying to send commands. // Try to PING so we can fail-fast in the case of inva...
go
func New(network, address string) (*Storage, error) { s := &Storage{ pool: redis.NewPool(func() (redis.Conn, error) { return redis.Dial(network, address) }, 5)} // When using a connection pool, you only get connection errors while trying to send commands. // Try to PING so we can fail-fast in the case of inva...
[ "func", "New", "(", "network", ",", "address", "string", ")", "(", "*", "Storage", ",", "error", ")", "{", "s", ":=", "&", "Storage", "{", "pool", ":", "redis", ".", "NewPool", "(", "func", "(", ")", "(", "redis", ".", "Conn", ",", "error", ")", ...
// New initializes the connection to redis.
[ "New", "initializes", "the", "connection", "to", "redis", "." ]
365a4c736ef804bdd7659d75471cf8f9834b7713
https://github.com/Clever/leakybucket/blob/365a4c736ef804bdd7659d75471cf8f9834b7713/redis/redis.go#L132-L145
141,628
Clever/s3-to-redshift
redshift/redshift.go
NewRedshift
func NewRedshift(ctx context.Context, host, port, db, user, password string, timeout int) (*Redshift, error) { source := fmt.Sprintf("host=%s port=%s dbname=%s keepalive=1 connect_timeout=%d", host, port, db, timeout) log.Println("Connecting to Redshift Source: ", source) source += fmt.Sprintf(" user=%s password=%s"...
go
func NewRedshift(ctx context.Context, host, port, db, user, password string, timeout int) (*Redshift, error) { source := fmt.Sprintf("host=%s port=%s dbname=%s keepalive=1 connect_timeout=%d", host, port, db, timeout) log.Println("Connecting to Redshift Source: ", source) source += fmt.Sprintf(" user=%s password=%s"...
[ "func", "NewRedshift", "(", "ctx", "context", ".", "Context", ",", "host", ",", "port", ",", "db", ",", "user", ",", "password", "string", ",", "timeout", "int", ")", "(", "*", "Redshift", ",", "error", ")", "{", "source", ":=", "fmt", ".", "Sprintf"...
// NewRedshift returns a pointer to a new redshift object using configuration values passed in // on instantiation and the AWS env vars we assume exist // Don't need to pass s3 info unless doing a COPY operation
[ "NewRedshift", "returns", "a", "pointer", "to", "a", "new", "redshift", "object", "using", "configuration", "values", "passed", "in", "on", "instantiation", "and", "the", "AWS", "env", "vars", "we", "assume", "exist", "Don", "t", "need", "to", "pass", "s3", ...
09b5dd7b364d4ff3d205ca0031723e8f1f018dd0
https://github.com/Clever/s3-to-redshift/blob/09b5dd7b364d4ff3d205ca0031723e8f1f018dd0/redshift/redshift.go#L111-L123
141,629
Clever/s3-to-redshift
redshift/redshift.go
Begin
func (r *Redshift) Begin() (*sql.Tx, error) { return r.dbExecCloser.BeginTx(r.ctx, nil) }
go
func (r *Redshift) Begin() (*sql.Tx, error) { return r.dbExecCloser.BeginTx(r.ctx, nil) }
[ "func", "(", "r", "*", "Redshift", ")", "Begin", "(", ")", "(", "*", "sql", ".", "Tx", ",", "error", ")", "{", "return", "r", ".", "dbExecCloser", ".", "BeginTx", "(", "r", ".", "ctx", ",", "nil", ")", "\n", "}" ]
// Begin wraps a new transaction in the databases context
[ "Begin", "wraps", "a", "new", "transaction", "in", "the", "databases", "context" ]
09b5dd7b364d4ff3d205ca0031723e8f1f018dd0
https://github.com/Clever/s3-to-redshift/blob/09b5dd7b364d4ff3d205ca0031723e8f1f018dd0/redshift/redshift.go#L126-L128
141,630
Clever/s3-to-redshift
redshift/redshift.go
GetTableFromConf
func (r *Redshift) GetTableFromConf(f s3filepath.S3File) (*Table, error) { var tempSchema map[string]Table log.Printf("Parsing file: %s", f.ConfFile) reader, err := pathio.Reader(f.ConfFile) if err != nil { return nil, fmt.Errorf("error opening conf file: %s", err) } data, err := ioutil.ReadAll(reader) if err...
go
func (r *Redshift) GetTableFromConf(f s3filepath.S3File) (*Table, error) { var tempSchema map[string]Table log.Printf("Parsing file: %s", f.ConfFile) reader, err := pathio.Reader(f.ConfFile) if err != nil { return nil, fmt.Errorf("error opening conf file: %s", err) } data, err := ioutil.ReadAll(reader) if err...
[ "func", "(", "r", "*", "Redshift", ")", "GetTableFromConf", "(", "f", "s3filepath", ".", "S3File", ")", "(", "*", "Table", ",", "error", ")", "{", "var", "tempSchema", "map", "[", "string", "]", "Table", "\n\n", "log", ".", "Printf", "(", "\"", "\"",...
// GetTableFromConf returns the redshift table representation of the s3 conf file // It opens, unmarshalls, and does very very simple validation of the conf file // This belongs here - s3filepath should not have to know about redshift tables
[ "GetTableFromConf", "returns", "the", "redshift", "table", "representation", "of", "the", "s3", "conf", "file", "It", "opens", "unmarshalls", "and", "does", "very", "very", "simple", "validation", "of", "the", "conf", "file", "This", "belongs", "here", "-", "s...
09b5dd7b364d4ff3d205ca0031723e8f1f018dd0
https://github.com/Clever/s3-to-redshift/blob/09b5dd7b364d4ff3d205ca0031723e8f1f018dd0/redshift/redshift.go#L133-L162
141,631
Clever/s3-to-redshift
redshift/redshift.go
GetTableMetadata
func (r *Redshift) GetTableMetadata(schema, tableName, dataDateCol string) (*Table, *time.Time, error) { var cols []ColInfo // does the table exist? var placeholder string q := fmt.Sprintf(existQueryFormat, schema, tableName) if err := r.QueryRowContext(r.ctx, q).Scan(&placeholder); err != nil { // If the table...
go
func (r *Redshift) GetTableMetadata(schema, tableName, dataDateCol string) (*Table, *time.Time, error) { var cols []ColInfo // does the table exist? var placeholder string q := fmt.Sprintf(existQueryFormat, schema, tableName) if err := r.QueryRowContext(r.ctx, q).Scan(&placeholder); err != nil { // If the table...
[ "func", "(", "r", "*", "Redshift", ")", "GetTableMetadata", "(", "schema", ",", "tableName", ",", "dataDateCol", "string", ")", "(", "*", "Table", ",", "*", "time", ".", "Time", ",", "error", ")", "{", "var", "cols", "[", "]", "ColInfo", "\n\n", "// ...
// GetTableMetadata looks for a table and returns both the Table representation // of the db table and the last data in the table, if that exists // if the table does not exist it returns an empty table but does not error
[ "GetTableMetadata", "looks", "for", "a", "table", "and", "returns", "both", "the", "Table", "representation", "of", "the", "db", "table", "and", "the", "last", "data", "in", "the", "table", "if", "that", "exists", "if", "the", "table", "does", "not", "exis...
09b5dd7b364d4ff3d205ca0031723e8f1f018dd0
https://github.com/Clever/s3-to-redshift/blob/09b5dd7b364d4ff3d205ca0031723e8f1f018dd0/redshift/redshift.go#L167-L225
141,632
Clever/s3-to-redshift
redshift/redshift.go
CreateTable
func (r *Redshift) CreateTable(tx *sql.Tx, table Table) error { var columnSQL []string for _, c := range table.Columns { columnSQL = append(columnSQL, getColumnSQL(c)) } args := []interface{}{strings.Join(columnSQL, ",")} // for some reason prepare here was unable to succeed, perhaps look at this later createSQ...
go
func (r *Redshift) CreateTable(tx *sql.Tx, table Table) error { var columnSQL []string for _, c := range table.Columns { columnSQL = append(columnSQL, getColumnSQL(c)) } args := []interface{}{strings.Join(columnSQL, ",")} // for some reason prepare here was unable to succeed, perhaps look at this later createSQ...
[ "func", "(", "r", "*", "Redshift", ")", "CreateTable", "(", "tx", "*", "sql", ".", "Tx", ",", "table", "Table", ")", "error", "{", "var", "columnSQL", "[", "]", "string", "\n", "for", "_", ",", "c", ":=", "range", "table", ".", "Columns", "{", "c...
// CreateTable runs the full create table command in the provided transaction, given a // redshift representation of the table.
[ "CreateTable", "runs", "the", "full", "create", "table", "command", "in", "the", "provided", "transaction", "given", "a", "redshift", "representation", "of", "the", "table", "." ]
09b5dd7b364d4ff3d205ca0031723e8f1f018dd0
https://github.com/Clever/s3-to-redshift/blob/09b5dd7b364d4ff3d205ca0031723e8f1f018dd0/redshift/redshift.go#L256-L277
141,633
Clever/s3-to-redshift
redshift/redshift.go
checkSchemas
func checkSchemas(inputTable, targetTable Table) ([]string, error) { // If the schema is mongo then we know the input files are json so ordering doesn't matter. At // some point we could handle this in a more general way by checking if the input files are json. // This wouldn't be too hard, but we would have to peak...
go
func checkSchemas(inputTable, targetTable Table) ([]string, error) { // If the schema is mongo then we know the input files are json so ordering doesn't matter. At // some point we could handle this in a more general way by checking if the input files are json. // This wouldn't be too hard, but we would have to peak...
[ "func", "checkSchemas", "(", "inputTable", ",", "targetTable", "Table", ")", "(", "[", "]", "string", ",", "error", ")", "{", "// If the schema is mongo then we know the input files are json so ordering doesn't matter. At", "// some point we could handle this in a more general way ...
// checkSchemas takes in two tables and compares their column schemas to make sure they're compatible. // If they have any mismatched columns they are returned in the errors array. If the input table has // columns at the end that the target table does not then the appropriate alter tables sql commands are // returned.
[ "checkSchemas", "takes", "in", "two", "tables", "and", "compares", "their", "column", "schemas", "to", "make", "sure", "they", "re", "compatible", ".", "If", "they", "have", "any", "mismatched", "columns", "they", "are", "returned", "in", "the", "errors", "a...
09b5dd7b364d4ff3d205ca0031723e8f1f018dd0
https://github.com/Clever/s3-to-redshift/blob/09b5dd7b364d4ff3d205ca0031723e8f1f018dd0/redshift/redshift.go#L309-L318
141,634
Clever/s3-to-redshift
redshift/redshift.go
Copy
func (r *Redshift) Copy(tx *sql.Tx, f s3filepath.S3File, delimiter string, creds, gzip bool) error { var credSQL string if creds { credSQL = fmt.Sprintf(`CREDENTIALS 'aws_iam_role=%s'`, f.Bucket.RedshiftRoleARN) } gzipSQL := "" if gzip { gzipSQL = "GZIP" } manifestSQL := "" if f.Suffix == "manifest" { man...
go
func (r *Redshift) Copy(tx *sql.Tx, f s3filepath.S3File, delimiter string, creds, gzip bool) error { var credSQL string if creds { credSQL = fmt.Sprintf(`CREDENTIALS 'aws_iam_role=%s'`, f.Bucket.RedshiftRoleARN) } gzipSQL := "" if gzip { gzipSQL = "GZIP" } manifestSQL := "" if f.Suffix == "manifest" { man...
[ "func", "(", "r", "*", "Redshift", ")", "Copy", "(", "tx", "*", "sql", ".", "Tx", ",", "f", "s3filepath", ".", "S3File", ",", "delimiter", "string", ",", "creds", ",", "gzip", "bool", ")", "error", "{", "var", "credSQL", "string", "\n", "if", "cred...
// Copy copies either CSV or JSON data present in an S3 file into a redshift table. // It also supports CSV or JSON data pointed at by a manifest file, if you pass in a manifest file. // this is meant to be run in a transaction, so the first arg must be a sql.Tx // if not using jsonPaths, set s3File.JSONPaths to "auto"
[ "Copy", "copies", "either", "CSV", "or", "JSON", "data", "present", "in", "an", "S3", "file", "into", "a", "redshift", "table", ".", "It", "also", "supports", "CSV", "or", "JSON", "data", "pointed", "at", "by", "a", "manifest", "file", "if", "you", "pa...
09b5dd7b364d4ff3d205ca0031723e8f1f018dd0
https://github.com/Clever/s3-to-redshift/blob/09b5dd7b364d4ff3d205ca0031723e8f1f018dd0/redshift/redshift.go#L405-L437
141,635
Clever/s3-to-redshift
redshift/redshift.go
Truncate
func (r *Redshift) Truncate(tx *sql.Tx, schema, table string) error { // We run 'DELETE FROM' instead of 'TRUNCATE' because 'TRUNCATE' can't be run in a transaction. // See http://docs.aws.amazon.com/redshift/latest/dg/r_TRUNCATE.html. truncStmt, err := tx.PrepareContext(r.ctx, fmt.Sprintf(`DELETE FROM "%s"."%s"`, s...
go
func (r *Redshift) Truncate(tx *sql.Tx, schema, table string) error { // We run 'DELETE FROM' instead of 'TRUNCATE' because 'TRUNCATE' can't be run in a transaction. // See http://docs.aws.amazon.com/redshift/latest/dg/r_TRUNCATE.html. truncStmt, err := tx.PrepareContext(r.ctx, fmt.Sprintf(`DELETE FROM "%s"."%s"`, s...
[ "func", "(", "r", "*", "Redshift", ")", "Truncate", "(", "tx", "*", "sql", ".", "Tx", ",", "schema", ",", "table", "string", ")", "error", "{", "// We run 'DELETE FROM' instead of 'TRUNCATE' because 'TRUNCATE' can't be run in a transaction.", "// See http://docs.aws.amazo...
// Truncate deletes all items from a table, given a transaction, a schema string and a table name // you should run vacuum and analyze soon after doing this for performance reasons
[ "Truncate", "deletes", "all", "items", "from", "a", "table", "given", "a", "transaction", "a", "schema", "string", "and", "a", "table", "name", "you", "should", "run", "vacuum", "and", "analyze", "soon", "after", "doing", "this", "for", "performance", "reaso...
09b5dd7b364d4ff3d205ca0031723e8f1f018dd0
https://github.com/Clever/s3-to-redshift/blob/09b5dd7b364d4ff3d205ca0031723e8f1f018dd0/redshift/redshift.go#L441-L450
141,636
Clever/s3-to-redshift
main.go
getMapKeys
func getMapKeys(m map[string]bool) []string { keys := make([]string, 0, len(m)) for k := range m { keys = append(keys, k) } return keys }
go
func getMapKeys(m map[string]bool) []string { keys := make([]string, 0, len(m)) for k := range m { keys = append(keys, k) } return keys }
[ "func", "getMapKeys", "(", "m", "map", "[", "string", "]", "bool", ")", "[", "]", "string", "{", "keys", ":=", "make", "(", "[", "]", "string", ",", "0", ",", "len", "(", "m", ")", ")", "\n", "for", "k", ":=", "range", "m", "{", "keys", "=", ...
// helper function used for verifying inputs
[ "helper", "function", "used", "for", "verifying", "inputs" ]
09b5dd7b364d4ff3d205ca0031723e8f1f018dd0
https://github.com/Clever/s3-to-redshift/blob/09b5dd7b364d4ff3d205ca0031723e8f1f018dd0/main.go#L80-L86
141,637
Clever/s3-to-redshift
s3filepath/s3filepath.go
FileExists
func (S3PathChecker) FileExists(path string) bool { reader, err := pathio.Reader(path) if reader != nil { defer reader.Close() } return err == nil }
go
func (S3PathChecker) FileExists(path string) bool { reader, err := pathio.Reader(path) if reader != nil { defer reader.Close() } return err == nil }
[ "func", "(", "S3PathChecker", ")", "FileExists", "(", "path", "string", ")", "bool", "{", "reader", ",", "err", ":=", "pathio", ".", "Reader", "(", "path", ")", "\n", "if", "reader", "!=", "nil", "{", "defer", "reader", ".", "Close", "(", ")", "\n", ...
// FileExists looks up if the file exists in S3 using the pathio.Reader method.
[ "FileExists", "looks", "up", "if", "the", "file", "exists", "in", "S3", "using", "the", "pathio", ".", "Reader", "method", "." ]
09b5dd7b364d4ff3d205ca0031723e8f1f018dd0
https://github.com/Clever/s3-to-redshift/blob/09b5dd7b364d4ff3d205ca0031723e8f1f018dd0/s3filepath/s3filepath.go#L47-L53
141,638
Clever/s3-to-redshift
s3filepath/s3filepath.go
GetDataFilename
func (f *S3File) GetDataFilename() string { return fmt.Sprintf("s3://%s/%s/%s_%s_%s.%s", f.Bucket.Name, f.Subfolder, f.Schema, f.Table, f.DataDate.Format(time.RFC3339), f.Suffix) }
go
func (f *S3File) GetDataFilename() string { return fmt.Sprintf("s3://%s/%s/%s_%s_%s.%s", f.Bucket.Name, f.Subfolder, f.Schema, f.Table, f.DataDate.Format(time.RFC3339), f.Suffix) }
[ "func", "(", "f", "*", "S3File", ")", "GetDataFilename", "(", ")", "string", "{", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "f", ".", "Bucket", ".", "Name", ",", "f", ".", "Subfolder", ",", "f", ".", "Schema", ",", "f", ".", "Table",...
// GetDataFilename returns the s3 filepath associated with an S3File // 3useful for redshift COPY commands, amongst other things
[ "GetDataFilename", "returns", "the", "s3", "filepath", "associated", "with", "an", "S3File", "3useful", "for", "redshift", "COPY", "commands", "amongst", "other", "things" ]
09b5dd7b364d4ff3d205ca0031723e8f1f018dd0
https://github.com/Clever/s3-to-redshift/blob/09b5dd7b364d4ff3d205ca0031723e8f1f018dd0/s3filepath/s3filepath.go#L57-L59
141,639
Clever/s3-to-redshift
s3filepath/s3filepath.go
CreateS3File
func CreateS3File(pc PathChecker, bucket S3Bucket, schema, table, suppliedConf string, date time.Time) (*S3File, error) { // set configuration location formattedDate := date.Format(time.RFC3339) subfolder := fmt.Sprintf("%s/%s/_data_timestamp_year=%02d/_data_timestamp_month=%02d/_data_timestamp_day=%02d", schema, ...
go
func CreateS3File(pc PathChecker, bucket S3Bucket, schema, table, suppliedConf string, date time.Time) (*S3File, error) { // set configuration location formattedDate := date.Format(time.RFC3339) subfolder := fmt.Sprintf("%s/%s/_data_timestamp_year=%02d/_data_timestamp_month=%02d/_data_timestamp_day=%02d", schema, ...
[ "func", "CreateS3File", "(", "pc", "PathChecker", ",", "bucket", "S3Bucket", ",", "schema", ",", "table", ",", "suppliedConf", "string", ",", "date", "time", ".", "Time", ")", "(", "*", "S3File", ",", "error", ")", "{", "// set configuration location", "form...
// CreateS3File creates an S3File object with either a supplied config // file or the function generates a config file name
[ "CreateS3File", "creates", "an", "S3File", "object", "with", "either", "a", "supplied", "config", "file", "or", "the", "function", "generates", "a", "config", "file", "name" ]
09b5dd7b364d4ff3d205ca0031723e8f1f018dd0
https://github.com/Clever/s3-to-redshift/blob/09b5dd7b364d4ff3d205ca0031723e8f1f018dd0/s3filepath/s3filepath.go#L63-L87
141,640
go-openapi/jsonpointer
pointer.go
New
func New(jsonPointerString string) (Pointer, error) { var p Pointer err := p.parse(jsonPointerString) return p, err }
go
func New(jsonPointerString string) (Pointer, error) { var p Pointer err := p.parse(jsonPointerString) return p, err }
[ "func", "New", "(", "jsonPointerString", "string", ")", "(", "Pointer", ",", "error", ")", "{", "var", "p", "Pointer", "\n", "err", ":=", "p", ".", "parse", "(", "jsonPointerString", ")", "\n", "return", "p", ",", "err", "\n\n", "}" ]
// New creates a new json pointer for the given string
[ "New", "creates", "a", "new", "json", "pointer", "for", "the", "given", "string" ]
ef5f0afec364d3b9396b7b77b43dbe26bf1f8004
https://github.com/go-openapi/jsonpointer/blob/ef5f0afec364d3b9396b7b77b43dbe26bf1f8004/pointer.go#L61-L67
141,641
go-openapi/jsonpointer
pointer.go
parse
func (p *Pointer) parse(jsonPointerString string) error { var err error if jsonPointerString != emptyPointer { if !strings.HasPrefix(jsonPointerString, pointerSeparator) { err = errors.New(invalidStart) } else { referenceTokens := strings.Split(jsonPointerString, pointerSeparator) for _, referenceToken...
go
func (p *Pointer) parse(jsonPointerString string) error { var err error if jsonPointerString != emptyPointer { if !strings.HasPrefix(jsonPointerString, pointerSeparator) { err = errors.New(invalidStart) } else { referenceTokens := strings.Split(jsonPointerString, pointerSeparator) for _, referenceToken...
[ "func", "(", "p", "*", "Pointer", ")", "parse", "(", "jsonPointerString", "string", ")", "error", "{", "var", "err", "error", "\n\n", "if", "jsonPointerString", "!=", "emptyPointer", "{", "if", "!", "strings", ".", "HasPrefix", "(", "jsonPointerString", ",",...
// "Constructor", parses the given string JSON pointer
[ "Constructor", "parses", "the", "given", "string", "JSON", "pointer" ]
ef5f0afec364d3b9396b7b77b43dbe26bf1f8004
https://github.com/go-openapi/jsonpointer/blob/ef5f0afec364d3b9396b7b77b43dbe26bf1f8004/pointer.go#L75-L91
141,642
go-openapi/jsonpointer
pointer.go
Get
func (p *Pointer) Get(document interface{}) (interface{}, reflect.Kind, error) { return p.get(document, swag.DefaultJSONNameProvider) }
go
func (p *Pointer) Get(document interface{}) (interface{}, reflect.Kind, error) { return p.get(document, swag.DefaultJSONNameProvider) }
[ "func", "(", "p", "*", "Pointer", ")", "Get", "(", "document", "interface", "{", "}", ")", "(", "interface", "{", "}", ",", "reflect", ".", "Kind", ",", "error", ")", "{", "return", "p", ".", "get", "(", "document", ",", "swag", ".", "DefaultJSONNa...
// Get uses the pointer to retrieve a value from a JSON document
[ "Get", "uses", "the", "pointer", "to", "retrieve", "a", "value", "from", "a", "JSON", "document" ]
ef5f0afec364d3b9396b7b77b43dbe26bf1f8004
https://github.com/go-openapi/jsonpointer/blob/ef5f0afec364d3b9396b7b77b43dbe26bf1f8004/pointer.go#L94-L96
141,643
go-openapi/jsonpointer
pointer.go
Set
func (p *Pointer) Set(document interface{}, value interface{}) (interface{}, error) { return document, p.set(document, value, swag.DefaultJSONNameProvider) }
go
func (p *Pointer) Set(document interface{}, value interface{}) (interface{}, error) { return document, p.set(document, value, swag.DefaultJSONNameProvider) }
[ "func", "(", "p", "*", "Pointer", ")", "Set", "(", "document", "interface", "{", "}", ",", "value", "interface", "{", "}", ")", "(", "interface", "{", "}", ",", "error", ")", "{", "return", "document", ",", "p", ".", "set", "(", "document", ",", ...
// Set uses the pointer to set a value from a JSON document
[ "Set", "uses", "the", "pointer", "to", "set", "a", "value", "from", "a", "JSON", "document" ]
ef5f0afec364d3b9396b7b77b43dbe26bf1f8004
https://github.com/go-openapi/jsonpointer/blob/ef5f0afec364d3b9396b7b77b43dbe26bf1f8004/pointer.go#L99-L101
141,644
go-openapi/jsonpointer
pointer.go
GetForToken
func GetForToken(document interface{}, decodedToken string) (interface{}, reflect.Kind, error) { return getSingleImpl(document, decodedToken, swag.DefaultJSONNameProvider) }
go
func GetForToken(document interface{}, decodedToken string) (interface{}, reflect.Kind, error) { return getSingleImpl(document, decodedToken, swag.DefaultJSONNameProvider) }
[ "func", "GetForToken", "(", "document", "interface", "{", "}", ",", "decodedToken", "string", ")", "(", "interface", "{", "}", ",", "reflect", ".", "Kind", ",", "error", ")", "{", "return", "getSingleImpl", "(", "document", ",", "decodedToken", ",", "swag"...
// GetForToken gets a value for a json pointer token 1 level deep
[ "GetForToken", "gets", "a", "value", "for", "a", "json", "pointer", "token", "1", "level", "deep" ]
ef5f0afec364d3b9396b7b77b43dbe26bf1f8004
https://github.com/go-openapi/jsonpointer/blob/ef5f0afec364d3b9396b7b77b43dbe26bf1f8004/pointer.go#L104-L106
141,645
go-openapi/jsonpointer
pointer.go
SetForToken
func SetForToken(document interface{}, decodedToken string, value interface{}) (interface{}, error) { return document, setSingleImpl(document, value, decodedToken, swag.DefaultJSONNameProvider) }
go
func SetForToken(document interface{}, decodedToken string, value interface{}) (interface{}, error) { return document, setSingleImpl(document, value, decodedToken, swag.DefaultJSONNameProvider) }
[ "func", "SetForToken", "(", "document", "interface", "{", "}", ",", "decodedToken", "string", ",", "value", "interface", "{", "}", ")", "(", "interface", "{", "}", ",", "error", ")", "{", "return", "document", ",", "setSingleImpl", "(", "document", ",", ...
// SetForToken gets a value for a json pointer token 1 level deep
[ "SetForToken", "gets", "a", "value", "for", "a", "json", "pointer", "token", "1", "level", "deep" ]
ef5f0afec364d3b9396b7b77b43dbe26bf1f8004
https://github.com/go-openapi/jsonpointer/blob/ef5f0afec364d3b9396b7b77b43dbe26bf1f8004/pointer.go#L109-L111
141,646
go-openapi/jsonpointer
pointer.go
DecodedTokens
func (p *Pointer) DecodedTokens() []string { result := make([]string, 0, len(p.referenceTokens)) for _, t := range p.referenceTokens { result = append(result, Unescape(t)) } return result }
go
func (p *Pointer) DecodedTokens() []string { result := make([]string, 0, len(p.referenceTokens)) for _, t := range p.referenceTokens { result = append(result, Unescape(t)) } return result }
[ "func", "(", "p", "*", "Pointer", ")", "DecodedTokens", "(", ")", "[", "]", "string", "{", "result", ":=", "make", "(", "[", "]", "string", ",", "0", ",", "len", "(", "p", ".", "referenceTokens", ")", ")", "\n", "for", "_", ",", "t", ":=", "ran...
// DecodedTokens returns the decoded tokens
[ "DecodedTokens", "returns", "the", "decoded", "tokens" ]
ef5f0afec364d3b9396b7b77b43dbe26bf1f8004
https://github.com/go-openapi/jsonpointer/blob/ef5f0afec364d3b9396b7b77b43dbe26bf1f8004/pointer.go#L340-L346
141,647
go-openapi/jsonpointer
pointer.go
Unescape
func Unescape(token string) string { step1 := strings.Replace(token, encRefTok1, decRefTok1, -1) step2 := strings.Replace(step1, encRefTok0, decRefTok0, -1) return step2 }
go
func Unescape(token string) string { step1 := strings.Replace(token, encRefTok1, decRefTok1, -1) step2 := strings.Replace(step1, encRefTok0, decRefTok0, -1) return step2 }
[ "func", "Unescape", "(", "token", "string", ")", "string", "{", "step1", ":=", "strings", ".", "Replace", "(", "token", ",", "encRefTok1", ",", "decRefTok1", ",", "-", "1", ")", "\n", "step2", ":=", "strings", ".", "Replace", "(", "step1", ",", "encRef...
// Unescape unescapes a json pointer reference token string to the original representation
[ "Unescape", "unescapes", "a", "json", "pointer", "reference", "token", "string", "to", "the", "original", "representation" ]
ef5f0afec364d3b9396b7b77b43dbe26bf1f8004
https://github.com/go-openapi/jsonpointer/blob/ef5f0afec364d3b9396b7b77b43dbe26bf1f8004/pointer.go#L379-L383
141,648
jmcvetta/randutil
randutil.go
IntRange
func IntRange(min, max int) (int, error) { var result int switch { case min > max: // Fail with error return result, MinMaxError case max == min: result = max case max > min: maxRand := max - min b, err := rand.Int(rand.Reader, big.NewInt(int64(maxRand))) if err != nil { return result, err } res...
go
func IntRange(min, max int) (int, error) { var result int switch { case min > max: // Fail with error return result, MinMaxError case max == min: result = max case max > min: maxRand := max - min b, err := rand.Int(rand.Reader, big.NewInt(int64(maxRand))) if err != nil { return result, err } res...
[ "func", "IntRange", "(", "min", ",", "max", "int", ")", "(", "int", ",", "error", ")", "{", "var", "result", "int", "\n", "switch", "{", "case", "min", ">", "max", ":", "// Fail with error", "return", "result", ",", "MinMaxError", "\n", "case", "max", ...
// IntRange returns a random integer in the range from min to max.
[ "IntRange", "returns", "a", "random", "integer", "in", "the", "range", "from", "min", "to", "max", "." ]
2bb1b664bcff821e02b2a0644cd29c7e824d54f8
https://github.com/jmcvetta/randutil/blob/2bb1b664bcff821e02b2a0644cd29c7e824d54f8/randutil.go#L25-L42
141,649
jmcvetta/randutil
randutil.go
String
func String(n int, charset string) (string, error) { randstr := make([]byte, n) // Random string to return charlen := big.NewInt(int64(len(charset))) for i := 0; i < n; i++ { b, err := rand.Int(rand.Reader, charlen) if err != nil { return "", err } r := int(b.Int64()) randstr[i] = charset[r] } return ...
go
func String(n int, charset string) (string, error) { randstr := make([]byte, n) // Random string to return charlen := big.NewInt(int64(len(charset))) for i := 0; i < n; i++ { b, err := rand.Int(rand.Reader, charlen) if err != nil { return "", err } r := int(b.Int64()) randstr[i] = charset[r] } return ...
[ "func", "String", "(", "n", "int", ",", "charset", "string", ")", "(", "string", ",", "error", ")", "{", "randstr", ":=", "make", "(", "[", "]", "byte", ",", "n", ")", "// Random string to return", "\n", "charlen", ":=", "big", ".", "NewInt", "(", "i...
// String returns a random string n characters long, composed of entities // from charset.
[ "String", "returns", "a", "random", "string", "n", "characters", "long", "composed", "of", "entities", "from", "charset", "." ]
2bb1b664bcff821e02b2a0644cd29c7e824d54f8
https://github.com/jmcvetta/randutil/blob/2bb1b664bcff821e02b2a0644cd29c7e824d54f8/randutil.go#L46-L58
141,650
jmcvetta/randutil
randutil.go
StringRange
func StringRange(min, max int, charset string) (string, error) { // // First determine the length of string to be generated // var err error // Holds errors var strlen int // Length of random string to generate var randstr string // Random string to return strlen, err = IntRange(min, max) if err != nil...
go
func StringRange(min, max int, charset string) (string, error) { // // First determine the length of string to be generated // var err error // Holds errors var strlen int // Length of random string to generate var randstr string // Random string to return strlen, err = IntRange(min, max) if err != nil...
[ "func", "StringRange", "(", "min", ",", "max", "int", ",", "charset", "string", ")", "(", "string", ",", "error", ")", "{", "//", "// First determine the length of string to be generated", "//", "var", "err", "error", "// Holds errors", "\n", "var", "strlen", "i...
// StringRange returns a random string at least min and no more than max // characters long, composed of entitites from charset.
[ "StringRange", "returns", "a", "random", "string", "at", "least", "min", "and", "no", "more", "than", "max", "characters", "long", "composed", "of", "entitites", "from", "charset", "." ]
2bb1b664bcff821e02b2a0644cd29c7e824d54f8
https://github.com/jmcvetta/randutil/blob/2bb1b664bcff821e02b2a0644cd29c7e824d54f8/randutil.go#L62-L78
141,651
jmcvetta/randutil
randutil.go
AlphaStringRange
func AlphaStringRange(min, max int) (string, error) { return StringRange(min, max, Alphanumeric) }
go
func AlphaStringRange(min, max int) (string, error) { return StringRange(min, max, Alphanumeric) }
[ "func", "AlphaStringRange", "(", "min", ",", "max", "int", ")", "(", "string", ",", "error", ")", "{", "return", "StringRange", "(", "min", ",", "max", ",", "Alphanumeric", ")", "\n", "}" ]
// AlphaRange returns a random alphanumeric string at least min and no more // than max characters long.
[ "AlphaRange", "returns", "a", "random", "alphanumeric", "string", "at", "least", "min", "and", "no", "more", "than", "max", "characters", "long", "." ]
2bb1b664bcff821e02b2a0644cd29c7e824d54f8
https://github.com/jmcvetta/randutil/blob/2bb1b664bcff821e02b2a0644cd29c7e824d54f8/randutil.go#L82-L84
141,652
jmcvetta/randutil
randutil.go
ChoiceString
func ChoiceString(choices []string) (string, error) { var winner string length := len(choices) i, err := IntRange(0, length) winner = choices[i] return winner, err }
go
func ChoiceString(choices []string) (string, error) { var winner string length := len(choices) i, err := IntRange(0, length) winner = choices[i] return winner, err }
[ "func", "ChoiceString", "(", "choices", "[", "]", "string", ")", "(", "string", ",", "error", ")", "{", "var", "winner", "string", "\n", "length", ":=", "len", "(", "choices", ")", "\n", "i", ",", "err", ":=", "IntRange", "(", "0", ",", "length", "...
// ChoiceString returns a random selection from an array of strings.
[ "ChoiceString", "returns", "a", "random", "selection", "from", "an", "array", "of", "strings", "." ]
2bb1b664bcff821e02b2a0644cd29c7e824d54f8
https://github.com/jmcvetta/randutil/blob/2bb1b664bcff821e02b2a0644cd29c7e824d54f8/randutil.go#L92-L98
141,653
jmcvetta/randutil
randutil.go
ChoiceInt
func ChoiceInt(choices []int) (int, error) { var winner int length := len(choices) i, err := IntRange(0, length) winner = choices[i] return winner, err }
go
func ChoiceInt(choices []int) (int, error) { var winner int length := len(choices) i, err := IntRange(0, length) winner = choices[i] return winner, err }
[ "func", "ChoiceInt", "(", "choices", "[", "]", "int", ")", "(", "int", ",", "error", ")", "{", "var", "winner", "int", "\n", "length", ":=", "len", "(", "choices", ")", "\n", "i", ",", "err", ":=", "IntRange", "(", "0", ",", "length", ")", "\n", ...
// ChoiceInt returns a random selection from an array of integers.
[ "ChoiceInt", "returns", "a", "random", "selection", "from", "an", "array", "of", "integers", "." ]
2bb1b664bcff821e02b2a0644cd29c7e824d54f8
https://github.com/jmcvetta/randutil/blob/2bb1b664bcff821e02b2a0644cd29c7e824d54f8/randutil.go#L101-L107
141,654
jmcvetta/randutil
randutil.go
WeightedChoice
func WeightedChoice(choices []Choice) (Choice, error) { // Based on this algorithm: // http://eli.thegreenplace.net/2010/01/22/weighted-random-generation-in-python/ var ret Choice sum := 0 for _, c := range choices { sum += c.Weight } r, err := IntRange(0, sum) if err != nil { return ret, err } for _,...
go
func WeightedChoice(choices []Choice) (Choice, error) { // Based on this algorithm: // http://eli.thegreenplace.net/2010/01/22/weighted-random-generation-in-python/ var ret Choice sum := 0 for _, c := range choices { sum += c.Weight } r, err := IntRange(0, sum) if err != nil { return ret, err } for _,...
[ "func", "WeightedChoice", "(", "choices", "[", "]", "Choice", ")", "(", "Choice", ",", "error", ")", "{", "// Based on this algorithm:", "// http://eli.thegreenplace.net/2010/01/22/weighted-random-generation-in-python/", "var", "ret", "Choice", "\n", "sum", ":=", "0",...
// WeightedChoice used weighted random selection to return one of the supplied // choices. Weights of 0 are never selected. All other weight values are // relative. E.g. if you have two choices both weighted 3, they will be // returned equally often; and each will be returned 3 times as often as a // choice weighted...
[ "WeightedChoice", "used", "weighted", "random", "selection", "to", "return", "one", "of", "the", "supplied", "choices", ".", "Weights", "of", "0", "are", "never", "selected", ".", "All", "other", "weight", "values", "are", "relative", ".", "E", ".", "g", "...
2bb1b664bcff821e02b2a0644cd29c7e824d54f8
https://github.com/jmcvetta/randutil/blob/2bb1b664bcff821e02b2a0644cd29c7e824d54f8/randutil.go#L121-L141
141,655
emanoelxavier/openid2go
openid/provider.go
NewProvider
func NewProvider(issuer string, clientIDs []string) (Provider, error) { p := Provider{issuer, clientIDs} if err := p.validate(); err != nil { return Provider{}, err } return p, nil }
go
func NewProvider(issuer string, clientIDs []string) (Provider, error) { p := Provider{issuer, clientIDs} if err := p.validate(); err != nil { return Provider{}, err } return p, nil }
[ "func", "NewProvider", "(", "issuer", "string", ",", "clientIDs", "[", "]", "string", ")", "(", "Provider", ",", "error", ")", "{", "p", ":=", "Provider", "{", "issuer", ",", "clientIDs", "}", "\n\n", "if", "err", ":=", "p", ".", "validate", "(", ")"...
// NewProvider returns a new instance of a Provider created with the given issuer and clientIDs.
[ "NewProvider", "returns", "a", "new", "instance", "of", "a", "Provider", "created", "with", "the", "given", "issuer", "and", "clientIDs", "." ]
aa401da4d229952d63c76e4c8200131e408bd57d
https://github.com/emanoelxavier/openid2go/blob/aa401da4d229952d63c76e4c8200131e408bd57d/openid/provider.go#L36-L44
141,656
tmc/keyring
keyring_linux.go
unlock
func (s *ssProvider) unlock(p dbus.ObjectPath) error { var unlocked []dbus.ObjectPath var prompt dbus.ObjectPath method := fmt.Sprint(ssServiceIface, "Unlock") err := s.srv.Call(method, 0, []dbus.ObjectPath{p}).Store(&unlocked, &prompt) if err != nil { return fmt.Errorf("keyring/dbus: Unlock error: %s", err) } ...
go
func (s *ssProvider) unlock(p dbus.ObjectPath) error { var unlocked []dbus.ObjectPath var prompt dbus.ObjectPath method := fmt.Sprint(ssServiceIface, "Unlock") err := s.srv.Call(method, 0, []dbus.ObjectPath{p}).Store(&unlocked, &prompt) if err != nil { return fmt.Errorf("keyring/dbus: Unlock error: %s", err) } ...
[ "func", "(", "s", "*", "ssProvider", ")", "unlock", "(", "p", "dbus", ".", "ObjectPath", ")", "error", "{", "var", "unlocked", "[", "]", "dbus", ".", "ObjectPath", "\n", "var", "prompt", "dbus", ".", "ObjectPath", "\n", "method", ":=", "fmt", ".", "S...
// Unsure how the .Prompt call surfaces, it hasn't come up.
[ "Unsure", "how", "the", ".", "Prompt", "call", "surfaces", "it", "hasn", "t", "come", "up", "." ]
839169085ae146fc7a34bcb34dfd7ab216d23991
https://github.com/tmc/keyring/blob/839169085ae146fc7a34bcb34dfd7ab216d23991/keyring_linux.go#L63-L77
141,657
emanoelxavier/openid2go
openid/readidtoken.go
getIDTokenAuthorizationHeader
func getIDTokenAuthorizationHeader(r *http.Request) (t string, err error) { h := r.Header.Get("Authorization") if h == "" { return h, &ValidationError{ Code: ValidationErrorAuthorizationHeaderNotFound, Message: "The 'Authorization' header was not found or was empty.", HTTPStatus: http.StatusBadReq...
go
func getIDTokenAuthorizationHeader(r *http.Request) (t string, err error) { h := r.Header.Get("Authorization") if h == "" { return h, &ValidationError{ Code: ValidationErrorAuthorizationHeaderNotFound, Message: "The 'Authorization' header was not found or was empty.", HTTPStatus: http.StatusBadReq...
[ "func", "getIDTokenAuthorizationHeader", "(", "r", "*", "http", ".", "Request", ")", "(", "t", "string", ",", "err", "error", ")", "{", "h", ":=", "r", ".", "Header", ".", "Get", "(", "\"", "\"", ")", "\n", "if", "h", "==", "\"", "\"", "{", "retu...
// GetIdTokenAuthorizationHeader is the default implementation of the GetIdTokenFunc // used by this package.I looks for the idToken in the http Authorization header with // the format 'Bearer TokenString'. If found it will return 'TokenString' if not found // or the format does not match it will return an error.
[ "GetIdTokenAuthorizationHeader", "is", "the", "default", "implementation", "of", "the", "GetIdTokenFunc", "used", "by", "this", "package", ".", "I", "looks", "for", "the", "idToken", "in", "the", "http", "Authorization", "header", "with", "the", "format", "Bearer"...
aa401da4d229952d63c76e4c8200131e408bd57d
https://github.com/emanoelxavier/openid2go/blob/aa401da4d229952d63c76e4c8200131e408bd57d/openid/readidtoken.go#L17-L46
141,658
emanoelxavier/openid2go
openid/middleware.go
ProvidersGetter
func ProvidersGetter(pg GetProvidersFunc) func(*Configuration) error { return func(c *Configuration) error { c.tokenValidator.(*idTokenValidator).provGetter = pg return nil } }
go
func ProvidersGetter(pg GetProvidersFunc) func(*Configuration) error { return func(c *Configuration) error { c.tokenValidator.(*idTokenValidator).provGetter = pg return nil } }
[ "func", "ProvidersGetter", "(", "pg", "GetProvidersFunc", ")", "func", "(", "*", "Configuration", ")", "error", "{", "return", "func", "(", "c", "*", "Configuration", ")", "error", "{", "c", ".", "tokenValidator", ".", "(", "*", "idTokenValidator", ")", "....
// ProvidersGetter option registers the function responsible for returning the // providers containing the valid issuer and client IDs used to validate the ID Token.
[ "ProvidersGetter", "option", "registers", "the", "function", "responsible", "for", "returning", "the", "providers", "containing", "the", "valid", "issuer", "and", "client", "IDs", "used", "to", "validate", "the", "ID", "Token", "." ]
aa401da4d229952d63c76e4c8200131e408bd57d
https://github.com/emanoelxavier/openid2go/blob/aa401da4d229952d63c76e4c8200131e408bd57d/openid/middleware.go#L44-L49
141,659
emanoelxavier/openid2go
openid/middleware.go
ErrorHandler
func ErrorHandler(eh ErrorHandlerFunc) func(*Configuration) error { return func(c *Configuration) error { c.errorHandler = eh return nil } }
go
func ErrorHandler(eh ErrorHandlerFunc) func(*Configuration) error { return func(c *Configuration) error { c.errorHandler = eh return nil } }
[ "func", "ErrorHandler", "(", "eh", "ErrorHandlerFunc", ")", "func", "(", "*", "Configuration", ")", "error", "{", "return", "func", "(", "c", "*", "Configuration", ")", "error", "{", "c", ".", "errorHandler", "=", "eh", "\n", "return", "nil", "\n", "}", ...
// ErrorHandler option registers the function responsible for handling // the errors returned during token validation. When this option is not used then the // middleware will use the default internal implementation validationErrorToHTTPStatus.
[ "ErrorHandler", "option", "registers", "the", "function", "responsible", "for", "handling", "the", "errors", "returned", "during", "token", "validation", ".", "When", "this", "option", "is", "not", "used", "then", "the", "middleware", "will", "use", "the", "defa...
aa401da4d229952d63c76e4c8200131e408bd57d
https://github.com/emanoelxavier/openid2go/blob/aa401da4d229952d63c76e4c8200131e408bd57d/openid/middleware.go#L54-L59
141,660
emanoelxavier/openid2go
openid/middleware.go
HTTPGetter
func HTTPGetter(hg HTTPGetFunc) func(*Configuration) error { return func(c *Configuration) error { sksp := c.tokenValidator.(*idTokenValidator). keyGetter.(*signingKeyProvider). keySetGetter.(*signingKeySetProvider) sksp.configGetter.(*httpConfigurationProvider).getter = hg sksp.jwksGetter.(*httpJwksProvid...
go
func HTTPGetter(hg HTTPGetFunc) func(*Configuration) error { return func(c *Configuration) error { sksp := c.tokenValidator.(*idTokenValidator). keyGetter.(*signingKeyProvider). keySetGetter.(*signingKeySetProvider) sksp.configGetter.(*httpConfigurationProvider).getter = hg sksp.jwksGetter.(*httpJwksProvid...
[ "func", "HTTPGetter", "(", "hg", "HTTPGetFunc", ")", "func", "(", "*", "Configuration", ")", "error", "{", "return", "func", "(", "c", "*", "Configuration", ")", "error", "{", "sksp", ":=", "c", ".", "tokenValidator", ".", "(", "*", "idTokenValidator", "...
// HTTPGetter option registers the function responsible for returning the // providers containing the valid issuer and client IDs used to validate the ID Token.
[ "HTTPGetter", "option", "registers", "the", "function", "responsible", "for", "returning", "the", "providers", "containing", "the", "valid", "issuer", "and", "client", "IDs", "used", "to", "validate", "the", "ID", "Token", "." ]
aa401da4d229952d63c76e4c8200131e408bd57d
https://github.com/emanoelxavier/openid2go/blob/aa401da4d229952d63c76e4c8200131e408bd57d/openid/middleware.go#L72-L81
141,661
tmc/keyring
keyring.go
Get
func Get(service, username string) (string, error) { p, err := setupProvider() if err != nil { return "", err } return p.Get(service, username) }
go
func Get(service, username string) (string, error) { p, err := setupProvider() if err != nil { return "", err } return p.Get(service, username) }
[ "func", "Get", "(", "service", ",", "username", "string", ")", "(", "string", ",", "error", ")", "{", "p", ",", "err", ":=", "setupProvider", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "err", "\n", "}", "\n\n", "ret...
// Get gets the password for a paricular Service and Username using the // default keyring provider.
[ "Get", "gets", "the", "password", "for", "a", "paricular", "Service", "and", "Username", "using", "the", "default", "keyring", "provider", "." ]
839169085ae146fc7a34bcb34dfd7ab216d23991
https://github.com/tmc/keyring/blob/839169085ae146fc7a34bcb34dfd7ab216d23991/keyring.go#L40-L47
141,662
tmc/keyring
keyring.go
Set
func Set(service, username, password string) error { p, err := setupProvider() if err != nil { return err } return p.Set(service, username, password) }
go
func Set(service, username, password string) error { p, err := setupProvider() if err != nil { return err } return p.Set(service, username, password) }
[ "func", "Set", "(", "service", ",", "username", ",", "password", "string", ")", "error", "{", "p", ",", "err", ":=", "setupProvider", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "return", "p", ".", "Set", "(",...
// Set sets the password for a particular Service and Username using the // default keyring provider.
[ "Set", "sets", "the", "password", "for", "a", "particular", "Service", "and", "Username", "using", "the", "default", "keyring", "provider", "." ]
839169085ae146fc7a34bcb34dfd7ab216d23991
https://github.com/tmc/keyring/blob/839169085ae146fc7a34bcb34dfd7ab216d23991/keyring.go#L51-L58
141,663
mikkyang/id3-go
encodedbytes/util.go
ByteInt
func ByteInt(buf []byte, base uint) (i uint32, err error) { if len(buf) > BytesPerInt { err = errors.New("byte integer: invalid []byte length") return } for _, b := range buf { if base < NormByteLength && b >= (1<<base) { err = errors.New("byte integer: exceed max bit") return } i = (i << base) | u...
go
func ByteInt(buf []byte, base uint) (i uint32, err error) { if len(buf) > BytesPerInt { err = errors.New("byte integer: invalid []byte length") return } for _, b := range buf { if base < NormByteLength && b >= (1<<base) { err = errors.New("byte integer: exceed max bit") return } i = (i << base) | u...
[ "func", "ByteInt", "(", "buf", "[", "]", "byte", ",", "base", "uint", ")", "(", "i", "uint32", ",", "err", "error", ")", "{", "if", "len", "(", "buf", ")", ">", "BytesPerInt", "{", "err", "=", "errors", ".", "New", "(", "\"", "\"", ")", "\n", ...
// Form an integer from concatenated bits
[ "Form", "an", "integer", "from", "concatenated", "bits" ]
0168d962f1d773af3e29867138593203b653782e
https://github.com/mikkyang/id3-go/blob/0168d962f1d773af3e29867138593203b653782e/encodedbytes/util.go#L44-L60
141,664
mikkyang/id3-go
encodedbytes/util.go
IntBytes
func IntBytes(n uint32, base uint) []byte { mask := uint32(1<<base - 1) bytes := make([]byte, BytesPerInt) for i, _ := range bytes { bytes[len(bytes)-i-1] = byte(n & mask) n >>= base } return bytes }
go
func IntBytes(n uint32, base uint) []byte { mask := uint32(1<<base - 1) bytes := make([]byte, BytesPerInt) for i, _ := range bytes { bytes[len(bytes)-i-1] = byte(n & mask) n >>= base } return bytes }
[ "func", "IntBytes", "(", "n", "uint32", ",", "base", "uint", ")", "[", "]", "byte", "{", "mask", ":=", "uint32", "(", "1", "<<", "base", "-", "1", ")", "\n", "bytes", ":=", "make", "(", "[", "]", "byte", ",", "BytesPerInt", ")", "\n\n", "for", ...
// Form a byte slice from an integer
[ "Form", "a", "byte", "slice", "from", "an", "integer" ]
0168d962f1d773af3e29867138593203b653782e
https://github.com/mikkyang/id3-go/blob/0168d962f1d773af3e29867138593203b653782e/encodedbytes/util.go#L73-L83
141,665
mikkyang/id3-go
id3.go
Open
func Open(name string) (*File, error) { fi, err := os.OpenFile(name, os.O_RDWR, 0666) if err != nil { return nil, err } file := &File{file: fi} if v2Tag := v2.ParseTag(fi); v2Tag != nil { file.Tagger = v2Tag file.originalSize = v2Tag.Size() } else if v1Tag := v1.ParseTag(fi); v1Tag != nil { file.Tagger ...
go
func Open(name string) (*File, error) { fi, err := os.OpenFile(name, os.O_RDWR, 0666) if err != nil { return nil, err } file := &File{file: fi} if v2Tag := v2.ParseTag(fi); v2Tag != nil { file.Tagger = v2Tag file.originalSize = v2Tag.Size() } else if v1Tag := v1.ParseTag(fi); v1Tag != nil { file.Tagger ...
[ "func", "Open", "(", "name", "string", ")", "(", "*", "File", ",", "error", ")", "{", "fi", ",", "err", ":=", "os", ".", "OpenFile", "(", "name", ",", "os", ".", "O_RDWR", ",", "0666", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ...
// Opens a new tagged file
[ "Opens", "a", "new", "tagged", "file" ]
0168d962f1d773af3e29867138593203b653782e
https://github.com/mikkyang/id3-go/blob/0168d962f1d773af3e29867138593203b653782e/id3.go#L50-L69
141,666
mikkyang/id3-go
id3.go
Close
func (f *File) Close() error { defer f.file.Close() if !f.Dirty() { return nil } switch f.Tagger.(type) { case (*v1.Tag): if _, err := f.file.Seek(-v1.TagSize, os.SEEK_END); err != nil { return err } case (*v2.Tag): if f.Size() > f.originalSize { start := int64(f.originalSize + v2.HeaderSize) o...
go
func (f *File) Close() error { defer f.file.Close() if !f.Dirty() { return nil } switch f.Tagger.(type) { case (*v1.Tag): if _, err := f.file.Seek(-v1.TagSize, os.SEEK_END); err != nil { return err } case (*v2.Tag): if f.Size() > f.originalSize { start := int64(f.originalSize + v2.HeaderSize) o...
[ "func", "(", "f", "*", "File", ")", "Close", "(", ")", "error", "{", "defer", "f", ".", "file", ".", "Close", "(", ")", "\n\n", "if", "!", "f", ".", "Dirty", "(", ")", "{", "return", "nil", "\n", "}", "\n\n", "switch", "f", ".", "Tagger", "."...
// Saves any edits to the tagged file
[ "Saves", "any", "edits", "to", "the", "tagged", "file" ]
0168d962f1d773af3e29867138593203b653782e
https://github.com/mikkyang/id3-go/blob/0168d962f1d773af3e29867138593203b653782e/id3.go#L72-L106
141,667
mikkyang/id3-go
encodedbytes/reader.go
ReadNumBytesString
func (r *Reader) ReadNumBytesString(n int) (string, error) { b, err := r.ReadNumBytes(n) return string(b), err }
go
func (r *Reader) ReadNumBytesString(n int) (string, error) { b, err := r.ReadNumBytes(n) return string(b), err }
[ "func", "(", "r", "*", "Reader", ")", "ReadNumBytesString", "(", "n", "int", ")", "(", "string", ",", "error", ")", "{", "b", ",", "err", ":=", "r", ".", "ReadNumBytes", "(", "n", ")", "\n", "return", "string", "(", "b", ")", ",", "err", "\n", ...
// Read a number of bytes and cast to a string
[ "Read", "a", "number", "of", "bytes", "and", "cast", "to", "a", "string" ]
0168d962f1d773af3e29867138593203b653782e
https://github.com/mikkyang/id3-go/blob/0168d962f1d773af3e29867138593203b653782e/encodedbytes/reader.go#L52-L55
141,668
mikkyang/id3-go
encodedbytes/reader.go
ReadRest
func (r *Reader) ReadRest() ([]byte, error) { return r.ReadNumBytes(len(r.data) - r.index) }
go
func (r *Reader) ReadRest() ([]byte, error) { return r.ReadNumBytes(len(r.data) - r.index) }
[ "func", "(", "r", "*", "Reader", ")", "ReadRest", "(", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "return", "r", ".", "ReadNumBytes", "(", "len", "(", "r", ".", "data", ")", "-", "r", ".", "index", ")", "\n", "}" ]
// Read until the end of the data
[ "Read", "until", "the", "end", "of", "the", "data" ]
0168d962f1d773af3e29867138593203b653782e
https://github.com/mikkyang/id3-go/blob/0168d962f1d773af3e29867138593203b653782e/encodedbytes/reader.go#L58-L60
141,669
mikkyang/id3-go
encodedbytes/reader.go
ReadRestString
func (r *Reader) ReadRestString(encoding byte) (string, error) { b, err := r.ReadRest() if err != nil { return "", err } return Decoders[encoding].ConvertString(string(b)) }
go
func (r *Reader) ReadRestString(encoding byte) (string, error) { b, err := r.ReadRest() if err != nil { return "", err } return Decoders[encoding].ConvertString(string(b)) }
[ "func", "(", "r", "*", "Reader", ")", "ReadRestString", "(", "encoding", "byte", ")", "(", "string", ",", "error", ")", "{", "b", ",", "err", ":=", "r", ".", "ReadRest", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", ...
// Read until the end of the data and cast to a string
[ "Read", "until", "the", "end", "of", "the", "data", "and", "cast", "to", "a", "string" ]
0168d962f1d773af3e29867138593203b653782e
https://github.com/mikkyang/id3-go/blob/0168d962f1d773af3e29867138593203b653782e/encodedbytes/reader.go#L63-L70
141,670
mikkyang/id3-go
encodedbytes/reader.go
ReadNullTermString
func (r *Reader) ReadNullTermString(encoding byte) (string, error) { atIndex, afterIndex := nullIndex(r.data[r.index:], encoding) b, err := r.ReadNumBytes(afterIndex) if err != nil { return "", err } return Decoders[encoding].ConvertString(string(b[:atIndex])) }
go
func (r *Reader) ReadNullTermString(encoding byte) (string, error) { atIndex, afterIndex := nullIndex(r.data[r.index:], encoding) b, err := r.ReadNumBytes(afterIndex) if err != nil { return "", err } return Decoders[encoding].ConvertString(string(b[:atIndex])) }
[ "func", "(", "r", "*", "Reader", ")", "ReadNullTermString", "(", "encoding", "byte", ")", "(", "string", ",", "error", ")", "{", "atIndex", ",", "afterIndex", ":=", "nullIndex", "(", "r", ".", "data", "[", "r", ".", "index", ":", "]", ",", "encoding"...
// Read a null terminated string of specified encoding
[ "Read", "a", "null", "terminated", "string", "of", "specified", "encoding" ]
0168d962f1d773af3e29867138593203b653782e
https://github.com/mikkyang/id3-go/blob/0168d962f1d773af3e29867138593203b653782e/encodedbytes/reader.go#L73-L81
141,671
mikkyang/id3-go
v2/id3v2.go
NewTag
func NewTag(version byte) *Tag { header := &Header{version: version} t := &Tag{ Header: header, frames: make(map[string][]Framer), dirty: false, } switch t.version { case 2: t.commonMap = V22CommonFrame t.frameConstructor = ParseV22Frame t.frameHeaderSize = V22FrameHeaderSize t.frameBytesConstruct...
go
func NewTag(version byte) *Tag { header := &Header{version: version} t := &Tag{ Header: header, frames: make(map[string][]Framer), dirty: false, } switch t.version { case 2: t.commonMap = V22CommonFrame t.frameConstructor = ParseV22Frame t.frameHeaderSize = V22FrameHeaderSize t.frameBytesConstruct...
[ "func", "NewTag", "(", "version", "byte", ")", "*", "Tag", "{", "header", ":=", "&", "Header", "{", "version", ":", "version", "}", "\n\n", "t", ":=", "&", "Tag", "{", "Header", ":", "header", ",", "frames", ":", "make", "(", "map", "[", "string", ...
// Creates a new tag
[ "Creates", "a", "new", "tag" ]
0168d962f1d773af3e29867138593203b653782e
https://github.com/mikkyang/id3-go/blob/0168d962f1d773af3e29867138593203b653782e/v2/id3v2.go#L30-L58
141,672
mikkyang/id3-go
v2/id3v2.go
ParseTag
func ParseTag(readSeeker io.ReadSeeker) *Tag { header := ParseHeader(readSeeker) if header == nil { return nil } t := NewTag(header.version) t.Header = header var frame Framer size := int(t.size) for size > 0 { frame = t.frameConstructor(readSeeker) if frame == nil { break } id := frame.Id() ...
go
func ParseTag(readSeeker io.ReadSeeker) *Tag { header := ParseHeader(readSeeker) if header == nil { return nil } t := NewTag(header.version) t.Header = header var frame Framer size := int(t.size) for size > 0 { frame = t.frameConstructor(readSeeker) if frame == nil { break } id := frame.Id() ...
[ "func", "ParseTag", "(", "readSeeker", "io", ".", "ReadSeeker", ")", "*", "Tag", "{", "header", ":=", "ParseHeader", "(", "readSeeker", ")", "\n\n", "if", "header", "==", "nil", "{", "return", "nil", "\n", "}", "\n\n", "t", ":=", "NewTag", "(", "header...
// Parses a new tag
[ "Parses", "a", "new", "tag" ]
0168d962f1d773af3e29867138593203b653782e
https://github.com/mikkyang/id3-go/blob/0168d962f1d773af3e29867138593203b653782e/v2/id3v2.go#L61-L93
141,673
mikkyang/id3-go
v2/id3v2.go
RealSize
func (t Tag) RealSize() int { size := uint(t.size) - t.padding return int(size) }
go
func (t Tag) RealSize() int { size := uint(t.size) - t.padding return int(size) }
[ "func", "(", "t", "Tag", ")", "RealSize", "(", ")", "int", "{", "size", ":=", "uint", "(", "t", ".", "size", ")", "-", "t", ".", "padding", "\n", "return", "int", "(", "size", ")", "\n", "}" ]
// Real size of the tag
[ "Real", "size", "of", "the", "tag" ]
0168d962f1d773af3e29867138593203b653782e
https://github.com/mikkyang/id3-go/blob/0168d962f1d773af3e29867138593203b653782e/v2/id3v2.go#L96-L99
141,674
mikkyang/id3-go
v2/id3v2.go
Frames
func (t Tag) Frames(id string) []Framer { if frames, ok := t.frames[id]; ok && frames != nil { return frames } return []Framer{} }
go
func (t Tag) Frames(id string) []Framer { if frames, ok := t.frames[id]; ok && frames != nil { return frames } return []Framer{} }
[ "func", "(", "t", "Tag", ")", "Frames", "(", "id", "string", ")", "[", "]", "Framer", "{", "if", "frames", ",", "ok", ":=", "t", ".", "frames", "[", "id", "]", ";", "ok", "&&", "frames", "!=", "nil", "{", "return", "frames", "\n", "}", "\n\n", ...
// All frames with specified ID
[ "All", "frames", "with", "specified", "ID" ]
0168d962f1d773af3e29867138593203b653782e
https://github.com/mikkyang/id3-go/blob/0168d962f1d773af3e29867138593203b653782e/v2/id3v2.go#L161-L167
141,675
mikkyang/id3-go
v2/id3v2.go
Frame
func (t Tag) Frame(id string) Framer { if frames := t.Frames(id); len(frames) != 0 { return frames[0] } return nil }
go
func (t Tag) Frame(id string) Framer { if frames := t.Frames(id); len(frames) != 0 { return frames[0] } return nil }
[ "func", "(", "t", "Tag", ")", "Frame", "(", "id", "string", ")", "Framer", "{", "if", "frames", ":=", "t", ".", "Frames", "(", "id", ")", ";", "len", "(", "frames", ")", "!=", "0", "{", "return", "frames", "[", "0", "]", "\n", "}", "\n\n", "r...
// First frame with specified ID
[ "First", "frame", "with", "specified", "ID" ]
0168d962f1d773af3e29867138593203b653782e
https://github.com/mikkyang/id3-go/blob/0168d962f1d773af3e29867138593203b653782e/v2/id3v2.go#L170-L176
141,676
mikkyang/id3-go
v2/id3v2.go
DeleteFrames
func (t *Tag) DeleteFrames(id string) []Framer { frames := t.Frames(id) if frames == nil { return nil } diff := 0 for _, frame := range frames { frame.setOwner(nil) diff += t.frameHeaderSize + int(frame.Size()) } t.changeSize(-diff) delete(t.frames, id) return frames }
go
func (t *Tag) DeleteFrames(id string) []Framer { frames := t.Frames(id) if frames == nil { return nil } diff := 0 for _, frame := range frames { frame.setOwner(nil) diff += t.frameHeaderSize + int(frame.Size()) } t.changeSize(-diff) delete(t.frames, id) return frames }
[ "func", "(", "t", "*", "Tag", ")", "DeleteFrames", "(", "id", "string", ")", "[", "]", "Framer", "{", "frames", ":=", "t", ".", "Frames", "(", "id", ")", "\n", "if", "frames", "==", "nil", "{", "return", "nil", "\n", "}", "\n\n", "diff", ":=", ...
// Delete and return all frames with specified ID
[ "Delete", "and", "return", "all", "frames", "with", "specified", "ID" ]
0168d962f1d773af3e29867138593203b653782e
https://github.com/mikkyang/id3-go/blob/0168d962f1d773af3e29867138593203b653782e/v2/id3v2.go#L179-L195
141,677
mikkyang/id3-go
v2/frame.go
ParseDescTextFrame
func ParseDescTextFrame(head FrameHead, data []byte) Framer { var err error f := new(DescTextFrame) f.FrameHead = head rd := encodedbytes.NewReader(data) if f.encoding, err = rd.ReadByte(); err != nil { return nil } if f.description, err = rd.ReadNullTermString(f.encoding); err != nil { return nil } if ...
go
func ParseDescTextFrame(head FrameHead, data []byte) Framer { var err error f := new(DescTextFrame) f.FrameHead = head rd := encodedbytes.NewReader(data) if f.encoding, err = rd.ReadByte(); err != nil { return nil } if f.description, err = rd.ReadNullTermString(f.encoding); err != nil { return nil } if ...
[ "func", "ParseDescTextFrame", "(", "head", "FrameHead", ",", "data", "[", "]", "byte", ")", "Framer", "{", "var", "err", "error", "\n", "f", ":=", "new", "(", "DescTextFrame", ")", "\n", "f", ".", "FrameHead", "=", "head", "\n", "rd", ":=", "encodedbyt...
// DescTextFrame represents frames that contain encoded text and descriptions
[ "DescTextFrame", "represents", "frames", "that", "contain", "encoded", "text", "and", "descriptions" ]
0168d962f1d773af3e29867138593203b653782e
https://github.com/mikkyang/id3-go/blob/0168d962f1d773af3e29867138593203b653782e/v2/frame.go#L312-L331
141,678
go-openapi/jsonreference
reference.go
New
func New(jsonReferenceString string) (Ref, error) { var r Ref err := r.parse(jsonReferenceString) return r, err }
go
func New(jsonReferenceString string) (Ref, error) { var r Ref err := r.parse(jsonReferenceString) return r, err }
[ "func", "New", "(", "jsonReferenceString", "string", ")", "(", "Ref", ",", "error", ")", "{", "var", "r", "Ref", "\n", "err", ":=", "r", ".", "parse", "(", "jsonReferenceString", ")", "\n", "return", "r", ",", "err", "\n\n", "}" ]
// New creates a new reference for the given string
[ "New", "creates", "a", "new", "reference", "for", "the", "given", "string" ]
8483a886a90412cd6858df4ea3483dce9c8e35a3
https://github.com/go-openapi/jsonreference/blob/8483a886a90412cd6858df4ea3483dce9c8e35a3/reference.go#L42-L48
141,679
go-openapi/jsonreference
reference.go
MustCreateRef
func MustCreateRef(ref string) Ref { r, err := New(ref) if err != nil { panic(err) } return r }
go
func MustCreateRef(ref string) Ref { r, err := New(ref) if err != nil { panic(err) } return r }
[ "func", "MustCreateRef", "(", "ref", "string", ")", "Ref", "{", "r", ",", "err", ":=", "New", "(", "ref", ")", "\n", "if", "err", "!=", "nil", "{", "panic", "(", "err", ")", "\n", "}", "\n", "return", "r", "\n", "}" ]
// MustCreateRef parses the ref string and panics when it's invalid. // Use the New method for a version that returns an error
[ "MustCreateRef", "parses", "the", "ref", "string", "and", "panics", "when", "it", "s", "invalid", ".", "Use", "the", "New", "method", "for", "a", "version", "that", "returns", "an", "error" ]
8483a886a90412cd6858df4ea3483dce9c8e35a3
https://github.com/go-openapi/jsonreference/blob/8483a886a90412cd6858df4ea3483dce9c8e35a3/reference.go#L52-L58
141,680
go-openapi/jsonreference
reference.go
String
func (r *Ref) String() string { if r.referenceURL != nil { return r.referenceURL.String() } if r.HasFragmentOnly { return fragmentRune + r.referencePointer.String() } return r.referencePointer.String() }
go
func (r *Ref) String() string { if r.referenceURL != nil { return r.referenceURL.String() } if r.HasFragmentOnly { return fragmentRune + r.referencePointer.String() } return r.referencePointer.String() }
[ "func", "(", "r", "*", "Ref", ")", "String", "(", ")", "string", "{", "if", "r", ".", "referenceURL", "!=", "nil", "{", "return", "r", ".", "referenceURL", ".", "String", "(", ")", "\n", "}", "\n\n", "if", "r", ".", "HasFragmentOnly", "{", "return"...
// String returns the best version of the url for this reference
[ "String", "returns", "the", "best", "version", "of", "the", "url", "for", "this", "reference" ]
8483a886a90412cd6858df4ea3483dce9c8e35a3
https://github.com/go-openapi/jsonreference/blob/8483a886a90412cd6858df4ea3483dce9c8e35a3/reference.go#L83-L94
141,681
go-openapi/jsonreference
reference.go
IsRoot
func (r *Ref) IsRoot() bool { return r.referenceURL != nil && !r.IsCanonical() && !r.HasURLPathOnly && r.referenceURL.Fragment == "" }
go
func (r *Ref) IsRoot() bool { return r.referenceURL != nil && !r.IsCanonical() && !r.HasURLPathOnly && r.referenceURL.Fragment == "" }
[ "func", "(", "r", "*", "Ref", ")", "IsRoot", "(", ")", "bool", "{", "return", "r", ".", "referenceURL", "!=", "nil", "&&", "!", "r", ".", "IsCanonical", "(", ")", "&&", "!", "r", ".", "HasURLPathOnly", "&&", "r", ".", "referenceURL", ".", "Fragment...
// IsRoot returns true if this reference is a root document
[ "IsRoot", "returns", "true", "if", "this", "reference", "is", "a", "root", "document" ]
8483a886a90412cd6858df4ea3483dce9c8e35a3
https://github.com/go-openapi/jsonreference/blob/8483a886a90412cd6858df4ea3483dce9c8e35a3/reference.go#L97-L102
141,682
go-openapi/jsonreference
reference.go
Inherits
func (r *Ref) Inherits(child Ref) (*Ref, error) { childURL := child.GetURL() parentURL := r.GetURL() if childURL == nil { return nil, errors.New("child url is nil") } if parentURL == nil { return &child, nil } ref, err := New(parentURL.ResolveReference(childURL).String()) if err != nil { return nil, err ...
go
func (r *Ref) Inherits(child Ref) (*Ref, error) { childURL := child.GetURL() parentURL := r.GetURL() if childURL == nil { return nil, errors.New("child url is nil") } if parentURL == nil { return &child, nil } ref, err := New(parentURL.ResolveReference(childURL).String()) if err != nil { return nil, err ...
[ "func", "(", "r", "*", "Ref", ")", "Inherits", "(", "child", "Ref", ")", "(", "*", "Ref", ",", "error", ")", "{", "childURL", ":=", "child", ".", "GetURL", "(", ")", "\n", "parentURL", ":=", "r", ".", "GetURL", "(", ")", "\n", "if", "childURL", ...
// Inherits creates a new reference from a parent and a child // If the child cannot inherit from the parent, an error is returned
[ "Inherits", "creates", "a", "new", "reference", "from", "a", "parent", "and", "a", "child", "If", "the", "child", "cannot", "inherit", "from", "the", "parent", "an", "error", "is", "returned" ]
8483a886a90412cd6858df4ea3483dce9c8e35a3
https://github.com/go-openapi/jsonreference/blob/8483a886a90412cd6858df4ea3483dce9c8e35a3/reference.go#L141-L156
141,683
markbates/inflect
name.go
Title
func (n Name) Title() string { x := strings.Split(string(n), "/") for i, s := range x { x[i] = Titleize(s) } return strings.Join(x, " ") }
go
func (n Name) Title() string { x := strings.Split(string(n), "/") for i, s := range x { x[i] = Titleize(s) } return strings.Join(x, " ") }
[ "func", "(", "n", "Name", ")", "Title", "(", ")", "string", "{", "x", ":=", "strings", ".", "Split", "(", "string", "(", "n", ")", ",", "\"", "\"", ")", "\n", "for", "i", ",", "s", ":=", "range", "x", "{", "x", "[", "i", "]", "=", "Titleize...
// Title version of a name. ie. "foo_bar" => "Foo Bar"
[ "Title", "version", "of", "a", "name", ".", "ie", ".", "foo_bar", "=", ">", "Foo", "Bar" ]
d582c680dc4d29c2279628ae00e743005bfcd4fe
https://github.com/markbates/inflect/blob/d582c680dc4d29c2279628ae00e743005bfcd4fe/name.go#L15-L22
141,684
markbates/inflect
name.go
Underscore
func (n Name) Underscore() string { w := string(n) if strings.ToUpper(w) == w { return strings.ToLower(w) } return Underscore(w) }
go
func (n Name) Underscore() string { w := string(n) if strings.ToUpper(w) == w { return strings.ToLower(w) } return Underscore(w) }
[ "func", "(", "n", "Name", ")", "Underscore", "(", ")", "string", "{", "w", ":=", "string", "(", "n", ")", "\n", "if", "strings", ".", "ToUpper", "(", "w", ")", "==", "w", "{", "return", "strings", ".", "ToLower", "(", "w", ")", "\n", "}", "\n",...
// Underscore version of a name. ie. "FooBar" => "foo_bar"
[ "Underscore", "version", "of", "a", "name", ".", "ie", ".", "FooBar", "=", ">", "foo_bar" ]
d582c680dc4d29c2279628ae00e743005bfcd4fe
https://github.com/markbates/inflect/blob/d582c680dc4d29c2279628ae00e743005bfcd4fe/name.go#L25-L31
141,685
markbates/inflect
name.go
Camel
func (n Name) Camel() string { c := Camelize(string(n)) if strings.HasSuffix(c, "Id") { c = strings.TrimSuffix(c, "Id") c += "ID" } return c }
go
func (n Name) Camel() string { c := Camelize(string(n)) if strings.HasSuffix(c, "Id") { c = strings.TrimSuffix(c, "Id") c += "ID" } return c }
[ "func", "(", "n", "Name", ")", "Camel", "(", ")", "string", "{", "c", ":=", "Camelize", "(", "string", "(", "n", ")", ")", "\n", "if", "strings", ".", "HasSuffix", "(", "c", ",", "\"", "\"", ")", "{", "c", "=", "strings", ".", "TrimSuffix", "("...
// Camel version of a name
[ "Camel", "version", "of", "a", "name" ]
d582c680dc4d29c2279628ae00e743005bfcd4fe
https://github.com/markbates/inflect/blob/d582c680dc4d29c2279628ae00e743005bfcd4fe/name.go#L44-L51
141,686
markbates/inflect
name.go
Model
func (n Name) Model() string { x := strings.Split(string(n), "/") for i, s := range x { x[i] = Camelize(Singularize(s)) } return strings.Join(x, "") }
go
func (n Name) Model() string { x := strings.Split(string(n), "/") for i, s := range x { x[i] = Camelize(Singularize(s)) } return strings.Join(x, "") }
[ "func", "(", "n", "Name", ")", "Model", "(", ")", "string", "{", "x", ":=", "strings", ".", "Split", "(", "string", "(", "n", ")", ",", "\"", "\"", ")", "\n", "for", "i", ",", "s", ":=", "range", "x", "{", "x", "[", "i", "]", "=", "Camelize...
// Model version of a name. ie. "user" => "User"
[ "Model", "version", "of", "a", "name", ".", "ie", ".", "user", "=", ">", "User" ]
d582c680dc4d29c2279628ae00e743005bfcd4fe
https://github.com/markbates/inflect/blob/d582c680dc4d29c2279628ae00e743005bfcd4fe/name.go#L54-L61
141,687
markbates/inflect
name.go
Resource
func (n Name) Resource() string { name := n.Underscore() x := strings.FieldsFunc(name, func(r rune) bool { return r == '_' || r == '/' }) for i, w := range x { if i == len(x)-1 { x[i] = Camelize(Pluralize(strings.ToLower(w))) continue } x[i] = Camelize(w) } return strings.Join(x, "") }
go
func (n Name) Resource() string { name := n.Underscore() x := strings.FieldsFunc(name, func(r rune) bool { return r == '_' || r == '/' }) for i, w := range x { if i == len(x)-1 { x[i] = Camelize(Pluralize(strings.ToLower(w))) continue } x[i] = Camelize(w) } return strings.Join(x, "") }
[ "func", "(", "n", "Name", ")", "Resource", "(", ")", "string", "{", "name", ":=", "n", ".", "Underscore", "(", ")", "\n", "x", ":=", "strings", ".", "FieldsFunc", "(", "name", ",", "func", "(", "r", "rune", ")", "bool", "{", "return", "r", "==", ...
// Resource version of a name
[ "Resource", "version", "of", "a", "name" ]
d582c680dc4d29c2279628ae00e743005bfcd4fe
https://github.com/markbates/inflect/blob/d582c680dc4d29c2279628ae00e743005bfcd4fe/name.go#L64-L80
141,688
markbates/inflect
name.go
ParamID
func (n Name) ParamID() string { return fmt.Sprintf("%s_id", strings.Replace(n.UnderSingular(), "/", "_", -1)) }
go
func (n Name) ParamID() string { return fmt.Sprintf("%s_id", strings.Replace(n.UnderSingular(), "/", "_", -1)) }
[ "func", "(", "n", "Name", ")", "ParamID", "(", ")", "string", "{", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "strings", ".", "Replace", "(", "n", ".", "UnderSingular", "(", ")", ",", "\"", "\"", ",", "\"", "\"", ",", "-", "1", ")",...
// ParamID returns foo_bar_id
[ "ParamID", "returns", "foo_bar_id" ]
d582c680dc4d29c2279628ae00e743005bfcd4fe
https://github.com/markbates/inflect/blob/d582c680dc4d29c2279628ae00e743005bfcd4fe/name.go#L138-L140
141,689
markbates/inflect
name.go
Package
func (n Name) Package() string { key := string(n) for _, gp := range envy.GoPaths() { key = strings.TrimPrefix(key, filepath.Join(gp, "src")) key = strings.TrimPrefix(key, gp) } key = strings.TrimPrefix(key, string(filepath.Separator)) key = strings.Replace(key, "\\", "/", -1) return key }
go
func (n Name) Package() string { key := string(n) for _, gp := range envy.GoPaths() { key = strings.TrimPrefix(key, filepath.Join(gp, "src")) key = strings.TrimPrefix(key, gp) } key = strings.TrimPrefix(key, string(filepath.Separator)) key = strings.Replace(key, "\\", "/", -1) return key }
[ "func", "(", "n", "Name", ")", "Package", "(", ")", "string", "{", "key", ":=", "string", "(", "n", ")", "\n\n", "for", "_", ",", "gp", ":=", "range", "envy", ".", "GoPaths", "(", ")", "{", "key", "=", "strings", ".", "TrimPrefix", "(", "key", ...
// Package returns go package
[ "Package", "returns", "go", "package" ]
d582c680dc4d29c2279628ae00e743005bfcd4fe
https://github.com/markbates/inflect/blob/d582c680dc4d29c2279628ae00e743005bfcd4fe/name.go#L143-L154
141,690
markbates/inflect
inflect.go
AddPlural
func (rs *Ruleset) AddPlural(suffix, replacement string) { rs.AddPluralExact(suffix, replacement, false) }
go
func (rs *Ruleset) AddPlural(suffix, replacement string) { rs.AddPluralExact(suffix, replacement, false) }
[ "func", "(", "rs", "*", "Ruleset", ")", "AddPlural", "(", "suffix", ",", "replacement", "string", ")", "{", "rs", ".", "AddPluralExact", "(", "suffix", ",", "replacement", ",", "false", ")", "\n", "}" ]
// AddPlural add a pluralization rule
[ "AddPlural", "add", "a", "pluralization", "rule" ]
d582c680dc4d29c2279628ae00e743005bfcd4fe
https://github.com/markbates/inflect/blob/d582c680dc4d29c2279628ae00e743005bfcd4fe/inflect.go#L282-L284
141,691
markbates/inflect
inflect.go
AddPluralExact
func (rs *Ruleset) AddPluralExact(suffix, replacement string, exact bool) { // remove uncountable delete(rs.uncountables, suffix) // create rule r := new(Rule) r.suffix = suffix r.replacement = replacement r.exact = exact // prepend rs.plurals = append([]*Rule{r}, rs.plurals...) }
go
func (rs *Ruleset) AddPluralExact(suffix, replacement string, exact bool) { // remove uncountable delete(rs.uncountables, suffix) // create rule r := new(Rule) r.suffix = suffix r.replacement = replacement r.exact = exact // prepend rs.plurals = append([]*Rule{r}, rs.plurals...) }
[ "func", "(", "rs", "*", "Ruleset", ")", "AddPluralExact", "(", "suffix", ",", "replacement", "string", ",", "exact", "bool", ")", "{", "// remove uncountable", "delete", "(", "rs", ".", "uncountables", ",", "suffix", ")", "\n", "// create rule", "r", ":=", ...
// AddPluralExact add a pluralization rule with full string match
[ "AddPluralExact", "add", "a", "pluralization", "rule", "with", "full", "string", "match" ]
d582c680dc4d29c2279628ae00e743005bfcd4fe
https://github.com/markbates/inflect/blob/d582c680dc4d29c2279628ae00e743005bfcd4fe/inflect.go#L287-L297
141,692
markbates/inflect
inflect.go
AddSingular
func (rs *Ruleset) AddSingular(suffix, replacement string) { rs.AddSingularExact(suffix, replacement, false) }
go
func (rs *Ruleset) AddSingular(suffix, replacement string) { rs.AddSingularExact(suffix, replacement, false) }
[ "func", "(", "rs", "*", "Ruleset", ")", "AddSingular", "(", "suffix", ",", "replacement", "string", ")", "{", "rs", ".", "AddSingularExact", "(", "suffix", ",", "replacement", ",", "false", ")", "\n", "}" ]
// AddSingular add a singular rule
[ "AddSingular", "add", "a", "singular", "rule" ]
d582c680dc4d29c2279628ae00e743005bfcd4fe
https://github.com/markbates/inflect/blob/d582c680dc4d29c2279628ae00e743005bfcd4fe/inflect.go#L300-L302
141,693
markbates/inflect
inflect.go
AddSingularExact
func (rs *Ruleset) AddSingularExact(suffix, replacement string, exact bool) { // remove from uncountable delete(rs.uncountables, suffix) // create rule r := new(Rule) r.suffix = suffix r.replacement = replacement r.exact = exact rs.singulars = append([]*Rule{r}, rs.singulars...) }
go
func (rs *Ruleset) AddSingularExact(suffix, replacement string, exact bool) { // remove from uncountable delete(rs.uncountables, suffix) // create rule r := new(Rule) r.suffix = suffix r.replacement = replacement r.exact = exact rs.singulars = append([]*Rule{r}, rs.singulars...) }
[ "func", "(", "rs", "*", "Ruleset", ")", "AddSingularExact", "(", "suffix", ",", "replacement", "string", ",", "exact", "bool", ")", "{", "// remove from uncountable", "delete", "(", "rs", ".", "uncountables", ",", "suffix", ")", "\n", "// create rule", "r", ...
// AddSingularExact same as AddSingular but you can set `exact` to force // a full string match
[ "AddSingularExact", "same", "as", "AddSingular", "but", "you", "can", "set", "exact", "to", "force", "a", "full", "string", "match" ]
d582c680dc4d29c2279628ae00e743005bfcd4fe
https://github.com/markbates/inflect/blob/d582c680dc4d29c2279628ae00e743005bfcd4fe/inflect.go#L306-L315
141,694
markbates/inflect
inflect.go
AddHuman
func (rs *Ruleset) AddHuman(suffix, replacement string) { r := new(Rule) r.suffix = suffix r.replacement = replacement rs.humans = append([]*Rule{r}, rs.humans...) }
go
func (rs *Ruleset) AddHuman(suffix, replacement string) { r := new(Rule) r.suffix = suffix r.replacement = replacement rs.humans = append([]*Rule{r}, rs.humans...) }
[ "func", "(", "rs", "*", "Ruleset", ")", "AddHuman", "(", "suffix", ",", "replacement", "string", ")", "{", "r", ":=", "new", "(", "Rule", ")", "\n", "r", ".", "suffix", "=", "suffix", "\n", "r", ".", "replacement", "=", "replacement", "\n", "rs", "...
// AddHuman Human rules are applied by humanize to show more friendly // versions of words
[ "AddHuman", "Human", "rules", "are", "applied", "by", "humanize", "to", "show", "more", "friendly", "versions", "of", "words" ]
d582c680dc4d29c2279628ae00e743005bfcd4fe
https://github.com/markbates/inflect/blob/d582c680dc4d29c2279628ae00e743005bfcd4fe/inflect.go#L319-L324
141,695
markbates/inflect
inflect.go
AddAcronym
func (rs *Ruleset) AddAcronym(word string) { r := new(Rule) r.suffix = word r.replacement = rs.Titleize(strings.ToLower(word)) rs.acronyms = append(rs.acronyms, r) }
go
func (rs *Ruleset) AddAcronym(word string) { r := new(Rule) r.suffix = word r.replacement = rs.Titleize(strings.ToLower(word)) rs.acronyms = append(rs.acronyms, r) }
[ "func", "(", "rs", "*", "Ruleset", ")", "AddAcronym", "(", "word", "string", ")", "{", "r", ":=", "new", "(", "Rule", ")", "\n", "r", ".", "suffix", "=", "word", "\n", "r", ".", "replacement", "=", "rs", ".", "Titleize", "(", "strings", ".", "ToL...
// AddAcronym if you use acronym you may need to add them to the ruleset // to prevent Underscored words of things like "HTML" coming out // as "h_t_m_l"
[ "AddAcronym", "if", "you", "use", "acronym", "you", "may", "need", "to", "add", "them", "to", "the", "ruleset", "to", "prevent", "Underscored", "words", "of", "things", "like", "HTML", "coming", "out", "as", "h_t_m_l" ]
d582c680dc4d29c2279628ae00e743005bfcd4fe
https://github.com/markbates/inflect/blob/d582c680dc4d29c2279628ae00e743005bfcd4fe/inflect.go#L339-L344
141,696
markbates/inflect
inflect.go
isAcronym
func (rs *Ruleset) isAcronym(word string) bool { for _, rule := range rs.acronyms { if strings.ToUpper(rule.suffix) == strings.ToUpper(word) { return true } } return false }
go
func (rs *Ruleset) isAcronym(word string) bool { for _, rule := range rs.acronyms { if strings.ToUpper(rule.suffix) == strings.ToUpper(word) { return true } } return false }
[ "func", "(", "rs", "*", "Ruleset", ")", "isAcronym", "(", "word", "string", ")", "bool", "{", "for", "_", ",", "rule", ":=", "range", "rs", ".", "acronyms", "{", "if", "strings", ".", "ToUpper", "(", "rule", ".", "suffix", ")", "==", "strings", "."...
//isAcronym returns if a word is acronym or not.
[ "isAcronym", "returns", "if", "a", "word", "is", "acronym", "or", "not", "." ]
d582c680dc4d29c2279628ae00e743005bfcd4fe
https://github.com/markbates/inflect/blob/d582c680dc4d29c2279628ae00e743005bfcd4fe/inflect.go#L362-L370
141,697
markbates/inflect
inflect.go
PluralizeWithSize
func (rs *Ruleset) PluralizeWithSize(word string, size int) string { if size == 1 { return rs.Singularize(word) } return rs.Pluralize(word) }
go
func (rs *Ruleset) PluralizeWithSize(word string, size int) string { if size == 1 { return rs.Singularize(word) } return rs.Pluralize(word) }
[ "func", "(", "rs", "*", "Ruleset", ")", "PluralizeWithSize", "(", "word", "string", ",", "size", "int", ")", "string", "{", "if", "size", "==", "1", "{", "return", "rs", ".", "Singularize", "(", "word", ")", "\n", "}", "\n", "return", "rs", ".", "P...
//PluralizeWithSize pluralize with taking number into account
[ "PluralizeWithSize", "pluralize", "with", "taking", "number", "into", "account" ]
d582c680dc4d29c2279628ae00e743005bfcd4fe
https://github.com/markbates/inflect/blob/d582c680dc4d29c2279628ae00e743005bfcd4fe/inflect.go#L373-L378
141,698
markbates/inflect
inflect.go
Pluralize
func (rs *Ruleset) Pluralize(word string) string { if len(word) == 0 { return word } lWord := strings.ToLower(word) if rs.isUncountable(lWord) { return word } var candidate string for _, rule := range rs.plurals { if rule.exact { if lWord == rule.suffix { // Capitalized word if lWord[0] != word...
go
func (rs *Ruleset) Pluralize(word string) string { if len(word) == 0 { return word } lWord := strings.ToLower(word) if rs.isUncountable(lWord) { return word } var candidate string for _, rule := range rs.plurals { if rule.exact { if lWord == rule.suffix { // Capitalized word if lWord[0] != word...
[ "func", "(", "rs", "*", "Ruleset", ")", "Pluralize", "(", "word", "string", ")", "string", "{", "if", "len", "(", "word", ")", "==", "0", "{", "return", "word", "\n", "}", "\n", "lWord", ":=", "strings", ".", "ToLower", "(", "word", ")", "\n", "i...
// Pluralize returns the plural form of a singular word
[ "Pluralize", "returns", "the", "plural", "form", "of", "a", "singular", "word" ]
d582c680dc4d29c2279628ae00e743005bfcd4fe
https://github.com/markbates/inflect/blob/d582c680dc4d29c2279628ae00e743005bfcd4fe/inflect.go#L381-L416
141,699
markbates/inflect
inflect.go
Capitalize
func (rs *Ruleset) Capitalize(word string) string { if rs.isAcronym(word) { return strings.ToUpper(word) } return strings.ToUpper(word[:1]) + word[1:] }
go
func (rs *Ruleset) Capitalize(word string) string { if rs.isAcronym(word) { return strings.ToUpper(word) } return strings.ToUpper(word[:1]) + word[1:] }
[ "func", "(", "rs", "*", "Ruleset", ")", "Capitalize", "(", "word", "string", ")", "string", "{", "if", "rs", ".", "isAcronym", "(", "word", ")", "{", "return", "strings", ".", "ToUpper", "(", "word", ")", "\n", "}", "\n", "return", "strings", ".", ...
//Capitalize uppercase first character
[ "Capitalize", "uppercase", "first", "character" ]
d582c680dc4d29c2279628ae00e743005bfcd4fe
https://github.com/markbates/inflect/blob/d582c680dc4d29c2279628ae00e743005bfcd4fe/inflect.go#L459-L464