repo stringlengths 5 54 | path stringlengths 4 155 | func_name stringlengths 1 118 | original_string stringlengths 52 85.5k | language stringclasses 1
value | code stringlengths 52 85.5k | code_tokens list | docstring stringlengths 6 2.61k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 85 252 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
sevlyar/go-daemon | command.go | SendCommands | func SendCommands(p *os.Process) (err error) {
for _, sig := range signals() {
if err = p.Signal(sig); err != nil {
return
}
}
return
} | go | func SendCommands(p *os.Process) (err error) {
for _, sig := range signals() {
if err = p.Signal(sig); err != nil {
return
}
}
return
} | [
"func",
"SendCommands",
"(",
"p",
"*",
"os",
".",
"Process",
")",
"(",
"err",
"error",
")",
"{",
"for",
"_",
",",
"sig",
":=",
"range",
"signals",
"(",
")",
"{",
"if",
"err",
"=",
"p",
".",
"Signal",
"(",
"sig",
")",
";",
"err",
"!=",
"nil",
... | // SendCommands sends active signals to the given process. | [
"SendCommands",
"sends",
"active",
"signals",
"to",
"the",
"given",
"process",
"."
] | fedf95d0cd0be92511436dbc84c290ff1c104f61 | https://github.com/sevlyar/go-daemon/blob/fedf95d0cd0be92511436dbc84c290ff1c104f61/command.go#L71-L78 | train |
sevlyar/go-daemon | command.go | ActiveFlags | func ActiveFlags() (ret []Flag) {
ret = make([]Flag, 0, 1)
for f := range flags {
if f.IsSet() {
ret = append(ret, f)
}
}
return
} | go | func ActiveFlags() (ret []Flag) {
ret = make([]Flag, 0, 1)
for f := range flags {
if f.IsSet() {
ret = append(ret, f)
}
}
return
} | [
"func",
"ActiveFlags",
"(",
")",
"(",
"ret",
"[",
"]",
"Flag",
")",
"{",
"ret",
"=",
"make",
"(",
"[",
"]",
"Flag",
",",
"0",
",",
"1",
")",
"\n",
"for",
"f",
":=",
"range",
"flags",
"{",
"if",
"f",
".",
"IsSet",
"(",
")",
"{",
"ret",
"=",
... | // ActiveFlags returns flags that has the state 'set'. | [
"ActiveFlags",
"returns",
"flags",
"that",
"has",
"the",
"state",
"set",
"."
] | fedf95d0cd0be92511436dbc84c290ff1c104f61 | https://github.com/sevlyar/go-daemon/blob/fedf95d0cd0be92511436dbc84c290ff1c104f61/command.go#L81-L89 | train |
sevlyar/go-daemon | signal.go | SetSigHandler | func SetSigHandler(handler SignalHandlerFunc, signals ...os.Signal) {
for _, sig := range signals {
handlers[sig] = handler
}
} | go | func SetSigHandler(handler SignalHandlerFunc, signals ...os.Signal) {
for _, sig := range signals {
handlers[sig] = handler
}
} | [
"func",
"SetSigHandler",
"(",
"handler",
"SignalHandlerFunc",
",",
"signals",
"...",
"os",
".",
"Signal",
")",
"{",
"for",
"_",
",",
"sig",
":=",
"range",
"signals",
"{",
"handlers",
"[",
"sig",
"]",
"=",
"handler",
"\n",
"}",
"\n",
"}"
] | // SetSigHandler sets handler for the given signals.
// SIGTERM has the default handler, he returns ErrStop. | [
"SetSigHandler",
"sets",
"handler",
"for",
"the",
"given",
"signals",
".",
"SIGTERM",
"has",
"the",
"default",
"handler",
"he",
"returns",
"ErrStop",
"."
] | fedf95d0cd0be92511436dbc84c290ff1c104f61 | https://github.com/sevlyar/go-daemon/blob/fedf95d0cd0be92511436dbc84c290ff1c104f61/signal.go#L19-L23 | train |
sevlyar/go-daemon | signal.go | ServeSignals | func ServeSignals() (err error) {
signals := make([]os.Signal, 0, len(handlers))
for sig := range handlers {
signals = append(signals, sig)
}
ch := make(chan os.Signal, 8)
signal.Notify(ch, signals...)
for sig := range ch {
err = handlers[sig](sig)
if err != nil {
break
}
}
signal.Stop(ch)
if er... | go | func ServeSignals() (err error) {
signals := make([]os.Signal, 0, len(handlers))
for sig := range handlers {
signals = append(signals, sig)
}
ch := make(chan os.Signal, 8)
signal.Notify(ch, signals...)
for sig := range ch {
err = handlers[sig](sig)
if err != nil {
break
}
}
signal.Stop(ch)
if er... | [
"func",
"ServeSignals",
"(",
")",
"(",
"err",
"error",
")",
"{",
"signals",
":=",
"make",
"(",
"[",
"]",
"os",
".",
"Signal",
",",
"0",
",",
"len",
"(",
"handlers",
")",
")",
"\n",
"for",
"sig",
":=",
"range",
"handlers",
"{",
"signals",
"=",
"ap... | // ServeSignals calls handlers for system signals. | [
"ServeSignals",
"calls",
"handlers",
"for",
"system",
"signals",
"."
] | fedf95d0cd0be92511436dbc84c290ff1c104f61 | https://github.com/sevlyar/go-daemon/blob/fedf95d0cd0be92511436dbc84c290ff1c104f61/signal.go#L26-L49 | train |
sevlyar/go-daemon | daemon.go | Search | func (d *Context) Search() (daemon *os.Process, err error) {
return d.search()
} | go | func (d *Context) Search() (daemon *os.Process, err error) {
return d.search()
} | [
"func",
"(",
"d",
"*",
"Context",
")",
"Search",
"(",
")",
"(",
"daemon",
"*",
"os",
".",
"Process",
",",
"err",
"error",
")",
"{",
"return",
"d",
".",
"search",
"(",
")",
"\n",
"}"
] | // Search searches daemons process by given in context pid file name.
// If success returns pointer on daemons os.Process structure,
// else returns error. Returns nil if filename is empty. | [
"Search",
"searches",
"daemons",
"process",
"by",
"given",
"in",
"context",
"pid",
"file",
"name",
".",
"If",
"success",
"returns",
"pointer",
"on",
"daemons",
"os",
".",
"Process",
"structure",
"else",
"returns",
"error",
".",
"Returns",
"nil",
"if",
"filen... | fedf95d0cd0be92511436dbc84c290ff1c104f61 | https://github.com/sevlyar/go-daemon/blob/fedf95d0cd0be92511436dbc84c290ff1c104f61/daemon.go#L37-L39 | train |
aelsabbahy/goss | resource/gomega.go | sanitizeExpectedValue | func sanitizeExpectedValue(i interface{}) interface{} {
if e, ok := i.(float64); ok {
return int(e)
}
if e, ok := i.(map[interface{}]interface{}); ok {
out := make(map[string]interface{})
for k, v := range e {
ks, ok := k.(string)
if !ok {
panic(fmt.Sprintf("Matcher key type not string: %T\n\n", k))
... | go | func sanitizeExpectedValue(i interface{}) interface{} {
if e, ok := i.(float64); ok {
return int(e)
}
if e, ok := i.(map[interface{}]interface{}); ok {
out := make(map[string]interface{})
for k, v := range e {
ks, ok := k.(string)
if !ok {
panic(fmt.Sprintf("Matcher key type not string: %T\n\n", k))
... | [
"func",
"sanitizeExpectedValue",
"(",
"i",
"interface",
"{",
"}",
")",
"interface",
"{",
"}",
"{",
"if",
"e",
",",
"ok",
":=",
"i",
".",
"(",
"float64",
")",
";",
"ok",
"{",
"return",
"int",
"(",
"e",
")",
"\n",
"}",
"\n",
"if",
"e",
",",
"ok",... | // Normalize expectedValue so json and yaml are the same | [
"Normalize",
"expectedValue",
"so",
"json",
"and",
"yaml",
"are",
"the",
"same"
] | 9c0d41fbdc8280be6a917e951acaf48f1f5c1f07 | https://github.com/aelsabbahy/goss/blob/9c0d41fbdc8280be6a917e951acaf48f1f5c1f07/resource/gomega.go#L160-L176 | train |
aelsabbahy/goss | system/system.go | detectPackage | func (sys *System) detectPackage(c *cli.Context) {
p := c.GlobalString("package")
if p != "deb" && p != "apk" && p != "pacman" && p != "rpm" {
p = DetectPackageManager()
}
switch p {
case "deb":
sys.NewPackage = NewDebPackage
case "apk":
sys.NewPackage = NewAlpinePackage
case "pacman":
sys.NewPackage = N... | go | func (sys *System) detectPackage(c *cli.Context) {
p := c.GlobalString("package")
if p != "deb" && p != "apk" && p != "pacman" && p != "rpm" {
p = DetectPackageManager()
}
switch p {
case "deb":
sys.NewPackage = NewDebPackage
case "apk":
sys.NewPackage = NewAlpinePackage
case "pacman":
sys.NewPackage = N... | [
"func",
"(",
"sys",
"*",
"System",
")",
"detectPackage",
"(",
"c",
"*",
"cli",
".",
"Context",
")",
"{",
"p",
":=",
"c",
".",
"GlobalString",
"(",
"\"",
"\"",
")",
"\n",
"if",
"p",
"!=",
"\"",
"\"",
"&&",
"p",
"!=",
"\"",
"\"",
"&&",
"p",
"!=... | // detectPackage adds the correct package creation function to a System struct | [
"detectPackage",
"adds",
"the",
"correct",
"package",
"creation",
"function",
"to",
"a",
"System",
"struct"
] | 9c0d41fbdc8280be6a917e951acaf48f1f5c1f07 | https://github.com/aelsabbahy/goss/blob/9c0d41fbdc8280be6a917e951acaf48f1f5c1f07/system/system.go#L79-L94 | train |
aelsabbahy/goss | system/system.go | detectService | func (sys *System) detectService() {
switch DetectService() {
case "upstart":
sys.NewService = NewServiceUpstart
case "systemd":
sys.NewService = NewServiceSystemd
case "alpineinit":
sys.NewService = NewAlpineServiceInit
default:
sys.NewService = NewServiceInit
}
} | go | func (sys *System) detectService() {
switch DetectService() {
case "upstart":
sys.NewService = NewServiceUpstart
case "systemd":
sys.NewService = NewServiceSystemd
case "alpineinit":
sys.NewService = NewAlpineServiceInit
default:
sys.NewService = NewServiceInit
}
} | [
"func",
"(",
"sys",
"*",
"System",
")",
"detectService",
"(",
")",
"{",
"switch",
"DetectService",
"(",
")",
"{",
"case",
"\"",
"\"",
":",
"sys",
".",
"NewService",
"=",
"NewServiceUpstart",
"\n",
"case",
"\"",
"\"",
":",
"sys",
".",
"NewService",
"=",... | // detectService adds the correct service creation function to a System struct | [
"detectService",
"adds",
"the",
"correct",
"service",
"creation",
"function",
"to",
"a",
"System",
"struct"
] | 9c0d41fbdc8280be6a917e951acaf48f1f5c1f07 | https://github.com/aelsabbahy/goss/blob/9c0d41fbdc8280be6a917e951acaf48f1f5c1f07/system/system.go#L97-L108 | train |
aelsabbahy/goss | system/system.go | HasCommand | func HasCommand(cmd string) bool {
if _, err := exec.LookPath(cmd); err == nil {
return true
}
return false
} | go | func HasCommand(cmd string) bool {
if _, err := exec.LookPath(cmd); err == nil {
return true
}
return false
} | [
"func",
"HasCommand",
"(",
"cmd",
"string",
")",
"bool",
"{",
"if",
"_",
",",
"err",
":=",
"exec",
".",
"LookPath",
"(",
"cmd",
")",
";",
"err",
"==",
"nil",
"{",
"return",
"true",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
] | // HasCommand returns whether or not an executable by this name is on the PATH. | [
"HasCommand",
"returns",
"whether",
"or",
"not",
"an",
"executable",
"by",
"this",
"name",
"is",
"on",
"the",
"PATH",
"."
] | 9c0d41fbdc8280be6a917e951acaf48f1f5c1f07 | https://github.com/aelsabbahy/goss/blob/9c0d41fbdc8280be6a917e951acaf48f1f5c1f07/system/system.go#L174-L179 | train |
aelsabbahy/goss | store.go | ReadJSON | func ReadJSON(filePath string) GossConfig {
file, err := ioutil.ReadFile(filePath)
if err != nil {
fmt.Printf("File error: %v\n", err)
os.Exit(1)
}
return ReadJSONData(file, false)
} | go | func ReadJSON(filePath string) GossConfig {
file, err := ioutil.ReadFile(filePath)
if err != nil {
fmt.Printf("File error: %v\n", err)
os.Exit(1)
}
return ReadJSONData(file, false)
} | [
"func",
"ReadJSON",
"(",
"filePath",
"string",
")",
"GossConfig",
"{",
"file",
",",
"err",
":=",
"ioutil",
".",
"ReadFile",
"(",
"filePath",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"fmt",
".",
"Printf",
"(",
"\"",
"\\n",
"\"",
",",
"err",
")",
"\... | // Reads json file returning GossConfig | [
"Reads",
"json",
"file",
"returning",
"GossConfig"
] | 9c0d41fbdc8280be6a917e951acaf48f1f5c1f07 | https://github.com/aelsabbahy/goss/blob/9c0d41fbdc8280be6a917e951acaf48f1f5c1f07/store.go#L56-L64 | train |
aelsabbahy/goss | store.go | ReadJSONData | func ReadJSONData(data []byte, detectFormat bool) GossConfig {
if TemplateFilter != nil {
data = TemplateFilter(data)
if debug {
fmt.Println("DEBUG: file after text/template render")
fmt.Println(string(data))
}
}
format := OutStoreFormat
if detectFormat == true {
format = getStoreFormatFromData(data)
... | go | func ReadJSONData(data []byte, detectFormat bool) GossConfig {
if TemplateFilter != nil {
data = TemplateFilter(data)
if debug {
fmt.Println("DEBUG: file after text/template render")
fmt.Println(string(data))
}
}
format := OutStoreFormat
if detectFormat == true {
format = getStoreFormatFromData(data)
... | [
"func",
"ReadJSONData",
"(",
"data",
"[",
"]",
"byte",
",",
"detectFormat",
"bool",
")",
"GossConfig",
"{",
"if",
"TemplateFilter",
"!=",
"nil",
"{",
"data",
"=",
"TemplateFilter",
"(",
"data",
")",
"\n",
"if",
"debug",
"{",
"fmt",
".",
"Println",
"(",
... | // Reads json byte array returning GossConfig | [
"Reads",
"json",
"byte",
"array",
"returning",
"GossConfig"
] | 9c0d41fbdc8280be6a917e951acaf48f1f5c1f07 | https://github.com/aelsabbahy/goss/blob/9c0d41fbdc8280be6a917e951acaf48f1f5c1f07/store.go#L96-L116 | train |
aelsabbahy/goss | store.go | RenderJSON | func RenderJSON(c *cli.Context) string {
filePath := c.GlobalString("gossfile")
varsFile := c.GlobalString("vars")
debug = c.Bool("debug")
TemplateFilter = NewTemplateFilter(varsFile)
path := filepath.Dir(filePath)
OutStoreFormat = getStoreFormatFromFileName(filePath)
gossConfig := mergeJSONData(ReadJSON(filePat... | go | func RenderJSON(c *cli.Context) string {
filePath := c.GlobalString("gossfile")
varsFile := c.GlobalString("vars")
debug = c.Bool("debug")
TemplateFilter = NewTemplateFilter(varsFile)
path := filepath.Dir(filePath)
OutStoreFormat = getStoreFormatFromFileName(filePath)
gossConfig := mergeJSONData(ReadJSON(filePat... | [
"func",
"RenderJSON",
"(",
"c",
"*",
"cli",
".",
"Context",
")",
"string",
"{",
"filePath",
":=",
"c",
".",
"GlobalString",
"(",
"\"",
"\"",
")",
"\n",
"varsFile",
":=",
"c",
".",
"GlobalString",
"(",
"\"",
"\"",
")",
"\n",
"debug",
"=",
"c",
".",
... | // Reads json file recursively returning string | [
"Reads",
"json",
"file",
"recursively",
"returning",
"string"
] | 9c0d41fbdc8280be6a917e951acaf48f1f5c1f07 | https://github.com/aelsabbahy/goss/blob/9c0d41fbdc8280be6a917e951acaf48f1f5c1f07/store.go#L119-L133 | train |
aelsabbahy/goss | outputs/outputs.go | Outputers | func Outputers() []string {
outputersMu.Lock()
defer outputersMu.Unlock()
var list []string
for name := range outputers {
list = append(list, name)
}
sort.Strings(list)
return list
} | go | func Outputers() []string {
outputersMu.Lock()
defer outputersMu.Unlock()
var list []string
for name := range outputers {
list = append(list, name)
}
sort.Strings(list)
return list
} | [
"func",
"Outputers",
"(",
")",
"[",
"]",
"string",
"{",
"outputersMu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"outputersMu",
".",
"Unlock",
"(",
")",
"\n",
"var",
"list",
"[",
"]",
"string",
"\n",
"for",
"name",
":=",
"range",
"outputers",
"{",
"list"... | // Outputers returns a sorted list of the names of the registered outputers. | [
"Outputers",
"returns",
"a",
"sorted",
"list",
"of",
"the",
"names",
"of",
"the",
"registered",
"outputers",
"."
] | 9c0d41fbdc8280be6a917e951acaf48f1f5c1f07 | https://github.com/aelsabbahy/goss/blob/9c0d41fbdc8280be6a917e951acaf48f1f5c1f07/outputs/outputs.go#L102-L111 | train |
aelsabbahy/goss | system/dns.go | LookupHost | func LookupHost(host string, server string, c *dns.Client, m *dns.Msg) (addrs []string, err error) {
a, _ := LookupA(host, server, c, m)
aaaa, _ := LookupAAAA(host, server, c, m)
addrs = append(a, aaaa...)
return
} | go | func LookupHost(host string, server string, c *dns.Client, m *dns.Msg) (addrs []string, err error) {
a, _ := LookupA(host, server, c, m)
aaaa, _ := LookupAAAA(host, server, c, m)
addrs = append(a, aaaa...)
return
} | [
"func",
"LookupHost",
"(",
"host",
"string",
",",
"server",
"string",
",",
"c",
"*",
"dns",
".",
"Client",
",",
"m",
"*",
"dns",
".",
"Msg",
")",
"(",
"addrs",
"[",
"]",
"string",
",",
"err",
"error",
")",
"{",
"a",
",",
"_",
":=",
"LookupA",
"... | // A and AAAA record lookup - similar to net.LookupHost | [
"A",
"and",
"AAAA",
"record",
"lookup",
"-",
"similar",
"to",
"net",
".",
"LookupHost"
] | 9c0d41fbdc8280be6a917e951acaf48f1f5c1f07 | https://github.com/aelsabbahy/goss/blob/9c0d41fbdc8280be6a917e951acaf48f1f5c1f07/system/dns.go#L162-L168 | train |
aelsabbahy/goss | system/dns.go | LookupCNAME | func LookupCNAME(host string, server string, c *dns.Client, m *dns.Msg) (addrs []string, err error) {
m.SetQuestion(dns.Fqdn(host), dns.TypeCNAME)
r, _, err := c.Exchange(m, net.JoinHostPort(server, "53"))
if err != nil {
return nil, err
}
for _, ans := range r.Answer {
if t, ok := ans.(*dns.CNAME); ok {
a... | go | func LookupCNAME(host string, server string, c *dns.Client, m *dns.Msg) (addrs []string, err error) {
m.SetQuestion(dns.Fqdn(host), dns.TypeCNAME)
r, _, err := c.Exchange(m, net.JoinHostPort(server, "53"))
if err != nil {
return nil, err
}
for _, ans := range r.Answer {
if t, ok := ans.(*dns.CNAME); ok {
a... | [
"func",
"LookupCNAME",
"(",
"host",
"string",
",",
"server",
"string",
",",
"c",
"*",
"dns",
".",
"Client",
",",
"m",
"*",
"dns",
".",
"Msg",
")",
"(",
"addrs",
"[",
"]",
"string",
",",
"err",
"error",
")",
"{",
"m",
".",
"SetQuestion",
"(",
"dns... | // CNAME record lookup | [
"CNAME",
"record",
"lookup"
] | 9c0d41fbdc8280be6a917e951acaf48f1f5c1f07 | https://github.com/aelsabbahy/goss/blob/9c0d41fbdc8280be6a917e951acaf48f1f5c1f07/system/dns.go#L205-L219 | train |
aelsabbahy/goss | system/dns.go | LookupMX | func LookupMX(host string, server string, c *dns.Client, m *dns.Msg) (addrs []string, err error) {
m.SetQuestion(dns.Fqdn(host), dns.TypeMX)
r, _, err := c.Exchange(m, net.JoinHostPort(server, "53"))
if err != nil {
return nil, err
}
for _, ans := range r.Answer {
if t, ok := ans.(*dns.MX); ok {
mxstring :... | go | func LookupMX(host string, server string, c *dns.Client, m *dns.Msg) (addrs []string, err error) {
m.SetQuestion(dns.Fqdn(host), dns.TypeMX)
r, _, err := c.Exchange(m, net.JoinHostPort(server, "53"))
if err != nil {
return nil, err
}
for _, ans := range r.Answer {
if t, ok := ans.(*dns.MX); ok {
mxstring :... | [
"func",
"LookupMX",
"(",
"host",
"string",
",",
"server",
"string",
",",
"c",
"*",
"dns",
".",
"Client",
",",
"m",
"*",
"dns",
".",
"Msg",
")",
"(",
"addrs",
"[",
"]",
"string",
",",
"err",
"error",
")",
"{",
"m",
".",
"SetQuestion",
"(",
"dns",
... | // MX record lookup | [
"MX",
"record",
"lookup"
] | 9c0d41fbdc8280be6a917e951acaf48f1f5c1f07 | https://github.com/aelsabbahy/goss/blob/9c0d41fbdc8280be6a917e951acaf48f1f5c1f07/system/dns.go#L222-L237 | train |
aelsabbahy/goss | system/dns.go | LookupNS | func LookupNS(host string, server string, c *dns.Client, m *dns.Msg) (addrs []string, err error) {
m.SetQuestion(dns.Fqdn(host), dns.TypeNS)
r, _, err := c.Exchange(m, net.JoinHostPort(server, "53"))
if err != nil {
return nil, err
}
for _, ans := range r.Answer {
if t, ok := ans.(*dns.NS); ok {
addrs = ap... | go | func LookupNS(host string, server string, c *dns.Client, m *dns.Msg) (addrs []string, err error) {
m.SetQuestion(dns.Fqdn(host), dns.TypeNS)
r, _, err := c.Exchange(m, net.JoinHostPort(server, "53"))
if err != nil {
return nil, err
}
for _, ans := range r.Answer {
if t, ok := ans.(*dns.NS); ok {
addrs = ap... | [
"func",
"LookupNS",
"(",
"host",
"string",
",",
"server",
"string",
",",
"c",
"*",
"dns",
".",
"Client",
",",
"m",
"*",
"dns",
".",
"Msg",
")",
"(",
"addrs",
"[",
"]",
"string",
",",
"err",
"error",
")",
"{",
"m",
".",
"SetQuestion",
"(",
"dns",
... | // NS record lookup | [
"NS",
"record",
"lookup"
] | 9c0d41fbdc8280be6a917e951acaf48f1f5c1f07 | https://github.com/aelsabbahy/goss/blob/9c0d41fbdc8280be6a917e951acaf48f1f5c1f07/system/dns.go#L240-L254 | train |
aelsabbahy/goss | system/dns.go | LookupSRV | func LookupSRV(host string, server string, c *dns.Client, m *dns.Msg) (addrs []string, err error) {
m.SetQuestion(dns.Fqdn(host), dns.TypeSRV)
r, _, err := c.Exchange(m, net.JoinHostPort(server, "53"))
if err != nil {
return nil, err
}
for _, ans := range r.Answer {
if t, ok := ans.(*dns.SRV); ok {
prio :=... | go | func LookupSRV(host string, server string, c *dns.Client, m *dns.Msg) (addrs []string, err error) {
m.SetQuestion(dns.Fqdn(host), dns.TypeSRV)
r, _, err := c.Exchange(m, net.JoinHostPort(server, "53"))
if err != nil {
return nil, err
}
for _, ans := range r.Answer {
if t, ok := ans.(*dns.SRV); ok {
prio :=... | [
"func",
"LookupSRV",
"(",
"host",
"string",
",",
"server",
"string",
",",
"c",
"*",
"dns",
".",
"Client",
",",
"m",
"*",
"dns",
".",
"Msg",
")",
"(",
"addrs",
"[",
"]",
"string",
",",
"err",
"error",
")",
"{",
"m",
".",
"SetQuestion",
"(",
"dns",... | // SRV record lookup | [
"SRV",
"record",
"lookup"
] | 9c0d41fbdc8280be6a917e951acaf48f1f5c1f07 | https://github.com/aelsabbahy/goss/blob/9c0d41fbdc8280be6a917e951acaf48f1f5c1f07/system/dns.go#L257-L275 | train |
aelsabbahy/goss | system/dns.go | LookupTXT | func LookupTXT(host string, server string, c *dns.Client, m *dns.Msg) (addrs []string, err error) {
m.SetQuestion(dns.Fqdn(host), dns.TypeTXT)
r, _, err := c.Exchange(m, net.JoinHostPort(server, "53"))
if err != nil {
return nil, err
}
for _, ans := range r.Answer {
if t, ok := ans.(*dns.TXT); ok {
addrs =... | go | func LookupTXT(host string, server string, c *dns.Client, m *dns.Msg) (addrs []string, err error) {
m.SetQuestion(dns.Fqdn(host), dns.TypeTXT)
r, _, err := c.Exchange(m, net.JoinHostPort(server, "53"))
if err != nil {
return nil, err
}
for _, ans := range r.Answer {
if t, ok := ans.(*dns.TXT); ok {
addrs =... | [
"func",
"LookupTXT",
"(",
"host",
"string",
",",
"server",
"string",
",",
"c",
"*",
"dns",
".",
"Client",
",",
"m",
"*",
"dns",
".",
"Msg",
")",
"(",
"addrs",
"[",
"]",
"string",
",",
"err",
"error",
")",
"{",
"m",
".",
"SetQuestion",
"(",
"dns",... | // TXT record lookup | [
"TXT",
"record",
"lookup"
] | 9c0d41fbdc8280be6a917e951acaf48f1f5c1f07 | https://github.com/aelsabbahy/goss/blob/9c0d41fbdc8280be6a917e951acaf48f1f5c1f07/system/dns.go#L278-L292 | train |
aelsabbahy/goss | system/dns.go | LookupPTR | func LookupPTR(addr string, server string, c *dns.Client, m *dns.Msg) (name []string, err error) {
reverse, err := dns.ReverseAddr(addr)
if err != nil {
return nil, err
}
m.SetQuestion(reverse, dns.TypePTR)
r, _, err := c.Exchange(m, net.JoinHostPort(server, "53"))
if err != nil {
return nil, err
}
for ... | go | func LookupPTR(addr string, server string, c *dns.Client, m *dns.Msg) (name []string, err error) {
reverse, err := dns.ReverseAddr(addr)
if err != nil {
return nil, err
}
m.SetQuestion(reverse, dns.TypePTR)
r, _, err := c.Exchange(m, net.JoinHostPort(server, "53"))
if err != nil {
return nil, err
}
for ... | [
"func",
"LookupPTR",
"(",
"addr",
"string",
",",
"server",
"string",
",",
"c",
"*",
"dns",
".",
"Client",
",",
"m",
"*",
"dns",
".",
"Msg",
")",
"(",
"name",
"[",
"]",
"string",
",",
"err",
"error",
")",
"{",
"reverse",
",",
"err",
":=",
"dns",
... | // PTR record lookup | [
"PTR",
"record",
"lookup"
] | 9c0d41fbdc8280be6a917e951acaf48f1f5c1f07 | https://github.com/aelsabbahy/goss/blob/9c0d41fbdc8280be6a917e951acaf48f1f5c1f07/system/dns.go#L295-L314 | train |
aelsabbahy/goss | system/dns.go | LookupCAA | func LookupCAA(host string, server string, c *dns.Client, m *dns.Msg) (addrs []string, err error) {
m.SetQuestion(dns.Fqdn(host), dns.TypeCAA)
r, _, err := c.Exchange(m, net.JoinHostPort(server, "53"))
if err != nil {
return nil, err
}
for _, ans := range r.Answer {
if t, ok := ans.(*dns.CAA); ok {
flag :=... | go | func LookupCAA(host string, server string, c *dns.Client, m *dns.Msg) (addrs []string, err error) {
m.SetQuestion(dns.Fqdn(host), dns.TypeCAA)
r, _, err := c.Exchange(m, net.JoinHostPort(server, "53"))
if err != nil {
return nil, err
}
for _, ans := range r.Answer {
if t, ok := ans.(*dns.CAA); ok {
flag :=... | [
"func",
"LookupCAA",
"(",
"host",
"string",
",",
"server",
"string",
",",
"c",
"*",
"dns",
".",
"Client",
",",
"m",
"*",
"dns",
".",
"Msg",
")",
"(",
"addrs",
"[",
"]",
"string",
",",
"err",
"error",
")",
"{",
"m",
".",
"SetQuestion",
"(",
"dns",... | // CAA record lookup | [
"CAA",
"record",
"lookup"
] | 9c0d41fbdc8280be6a917e951acaf48f1f5c1f07 | https://github.com/aelsabbahy/goss/blob/9c0d41fbdc8280be6a917e951acaf48f1f5c1f07/system/dns.go#L317-L333 | train |
ahmdrz/goinsta | timeline.go | Stories | func (time *Timeline) Stories() (*Tray, error) {
body, err := time.inst.sendSimpleRequest(urlStories)
if err == nil {
tray := &Tray{}
err = json.Unmarshal(body, tray)
if err != nil {
return nil, err
}
tray.set(time.inst, urlStories)
return tray, nil
}
return nil, err
} | go | func (time *Timeline) Stories() (*Tray, error) {
body, err := time.inst.sendSimpleRequest(urlStories)
if err == nil {
tray := &Tray{}
err = json.Unmarshal(body, tray)
if err != nil {
return nil, err
}
tray.set(time.inst, urlStories)
return tray, nil
}
return nil, err
} | [
"func",
"(",
"time",
"*",
"Timeline",
")",
"Stories",
"(",
")",
"(",
"*",
"Tray",
",",
"error",
")",
"{",
"body",
",",
"err",
":=",
"time",
".",
"inst",
".",
"sendSimpleRequest",
"(",
"urlStories",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"tray",
... | // Stories returns slice of StoryMedia | [
"Stories",
"returns",
"slice",
"of",
"StoryMedia"
] | 86d8297fa4152941d864ca6d7d2e1f1f673708aa | https://github.com/ahmdrz/goinsta/blob/86d8297fa4152941d864ca6d7d2e1f1f673708aa/timeline.go#L31-L43 | train |
ahmdrz/goinsta | goinsta.go | New | func New(username, password string) *Instagram {
// this call never returns error
jar, _ := cookiejar.New(nil)
inst := &Instagram{
user: username,
pass: password,
dID: generateDeviceID(
generateMD5Hash(username + password),
),
uuid: generateUUID(), // both uuid must be differents
pid: generateUUID(),... | go | func New(username, password string) *Instagram {
// this call never returns error
jar, _ := cookiejar.New(nil)
inst := &Instagram{
user: username,
pass: password,
dID: generateDeviceID(
generateMD5Hash(username + password),
),
uuid: generateUUID(), // both uuid must be differents
pid: generateUUID(),... | [
"func",
"New",
"(",
"username",
",",
"password",
"string",
")",
"*",
"Instagram",
"{",
"// this call never returns error",
"jar",
",",
"_",
":=",
"cookiejar",
".",
"New",
"(",
"nil",
")",
"\n",
"inst",
":=",
"&",
"Instagram",
"{",
"user",
":",
"username",
... | // New creates Instagram structure | [
"New",
"creates",
"Instagram",
"structure"
] | 86d8297fa4152941d864ca6d7d2e1f1f673708aa | https://github.com/ahmdrz/goinsta/blob/86d8297fa4152941d864ca6d7d2e1f1f673708aa/goinsta.go#L96-L117 | train |
ahmdrz/goinsta | goinsta.go | SetProxy | func (inst *Instagram) SetProxy(url string, insecure bool) error {
uri, err := neturl.Parse(url)
if err == nil {
inst.c.Transport = &http.Transport{
Proxy: http.ProxyURL(uri),
TLSClientConfig: &tls.Config{
InsecureSkipVerify: insecure,
},
}
}
return err
} | go | func (inst *Instagram) SetProxy(url string, insecure bool) error {
uri, err := neturl.Parse(url)
if err == nil {
inst.c.Transport = &http.Transport{
Proxy: http.ProxyURL(uri),
TLSClientConfig: &tls.Config{
InsecureSkipVerify: insecure,
},
}
}
return err
} | [
"func",
"(",
"inst",
"*",
"Instagram",
")",
"SetProxy",
"(",
"url",
"string",
",",
"insecure",
"bool",
")",
"error",
"{",
"uri",
",",
"err",
":=",
"neturl",
".",
"Parse",
"(",
"url",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"inst",
".",
"c",
"."... | // SetProxy sets proxy for connection. | [
"SetProxy",
"sets",
"proxy",
"for",
"connection",
"."
] | 86d8297fa4152941d864ca6d7d2e1f1f673708aa | https://github.com/ahmdrz/goinsta/blob/86d8297fa4152941d864ca6d7d2e1f1f673708aa/goinsta.go#L131-L142 | train |
ahmdrz/goinsta | goinsta.go | ImportReader | func ImportReader(r io.Reader) (*Instagram, error) {
url, err := neturl.Parse(goInstaAPIUrl)
if err != nil {
return nil, err
}
bytes, err := ioutil.ReadAll(r)
if err != nil {
return nil, err
}
config := ConfigFile{}
err = json.Unmarshal(bytes, &config)
if err != nil {
return nil, err
}
inst := &Insta... | go | func ImportReader(r io.Reader) (*Instagram, error) {
url, err := neturl.Parse(goInstaAPIUrl)
if err != nil {
return nil, err
}
bytes, err := ioutil.ReadAll(r)
if err != nil {
return nil, err
}
config := ConfigFile{}
err = json.Unmarshal(bytes, &config)
if err != nil {
return nil, err
}
inst := &Insta... | [
"func",
"ImportReader",
"(",
"r",
"io",
".",
"Reader",
")",
"(",
"*",
"Instagram",
",",
"error",
")",
"{",
"url",
",",
"err",
":=",
"neturl",
".",
"Parse",
"(",
"goInstaAPIUrl",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",... | // ImportReader imports instagram configuration from io.Reader
//
// This function does not set proxy automatically. Use SetProxy after this call. | [
"ImportReader",
"imports",
"instagram",
"configuration",
"from",
"io",
".",
"Reader",
"This",
"function",
"does",
"not",
"set",
"proxy",
"automatically",
".",
"Use",
"SetProxy",
"after",
"this",
"call",
"."
] | 86d8297fa4152941d864ca6d7d2e1f1f673708aa | https://github.com/ahmdrz/goinsta/blob/86d8297fa4152941d864ca6d7d2e1f1f673708aa/goinsta.go#L211-L251 | train |
ahmdrz/goinsta | goinsta.go | Import | func Import(path string) (*Instagram, error) {
f, err := os.Open(path)
if err != nil {
return nil, err
}
defer f.Close()
return ImportReader(f)
} | go | func Import(path string) (*Instagram, error) {
f, err := os.Open(path)
if err != nil {
return nil, err
}
defer f.Close()
return ImportReader(f)
} | [
"func",
"Import",
"(",
"path",
"string",
")",
"(",
"*",
"Instagram",
",",
"error",
")",
"{",
"f",
",",
"err",
":=",
"os",
".",
"Open",
"(",
"path",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"defer",... | // Import imports instagram configuration
//
// This function does not set proxy automatically. Use SetProxy after this call. | [
"Import",
"imports",
"instagram",
"configuration",
"This",
"function",
"does",
"not",
"set",
"proxy",
"automatically",
".",
"Use",
"SetProxy",
"after",
"this",
"call",
"."
] | 86d8297fa4152941d864ca6d7d2e1f1f673708aa | https://github.com/ahmdrz/goinsta/blob/86d8297fa4152941d864ca6d7d2e1f1f673708aa/goinsta.go#L256-L263 | train |
ahmdrz/goinsta | goinsta.go | Login | func (inst *Instagram) Login() error {
err := inst.readMsisdnHeader()
if err != nil {
return err
}
err = inst.syncFeatures()
if err != nil {
return err
}
err = inst.zrToken()
if err != nil {
return err
}
err = inst.sendAdID()
if err != nil {
return err
}
err = inst.contactPrefill()
if err != n... | go | func (inst *Instagram) Login() error {
err := inst.readMsisdnHeader()
if err != nil {
return err
}
err = inst.syncFeatures()
if err != nil {
return err
}
err = inst.zrToken()
if err != nil {
return err
}
err = inst.sendAdID()
if err != nil {
return err
}
err = inst.contactPrefill()
if err != n... | [
"func",
"(",
"inst",
"*",
"Instagram",
")",
"Login",
"(",
")",
"error",
"{",
"err",
":=",
"inst",
".",
"readMsisdnHeader",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"err",
"=",
"inst",
".",
"syncFeatures",
"... | // Login performs instagram login.
//
// Password will be deleted after login | [
"Login",
"performs",
"instagram",
"login",
".",
"Password",
"will",
"be",
"deleted",
"after",
"login"
] | 86d8297fa4152941d864ca6d7d2e1f1f673708aa | https://github.com/ahmdrz/goinsta/blob/86d8297fa4152941d864ca6d7d2e1f1f673708aa/goinsta.go#L347-L415 | train |
ahmdrz/goinsta | goinsta.go | Logout | func (inst *Instagram) Logout() error {
_, err := inst.sendSimpleRequest(urlLogout)
inst.c.Jar = nil
inst.c = nil
return err
} | go | func (inst *Instagram) Logout() error {
_, err := inst.sendSimpleRequest(urlLogout)
inst.c.Jar = nil
inst.c = nil
return err
} | [
"func",
"(",
"inst",
"*",
"Instagram",
")",
"Logout",
"(",
")",
"error",
"{",
"_",
",",
"err",
":=",
"inst",
".",
"sendSimpleRequest",
"(",
"urlLogout",
")",
"\n",
"inst",
".",
"c",
".",
"Jar",
"=",
"nil",
"\n",
"inst",
".",
"c",
"=",
"nil",
"\n"... | // Logout closes current session | [
"Logout",
"closes",
"current",
"session"
] | 86d8297fa4152941d864ca6d7d2e1f1f673708aa | https://github.com/ahmdrz/goinsta/blob/86d8297fa4152941d864ca6d7d2e1f1f673708aa/goinsta.go#L418-L423 | train |
ahmdrz/goinsta | search.go | User | func (search *Search) User(user string) (*SearchResult, error) {
insta := search.inst
body, err := insta.sendRequest(
&reqOptions{
Endpoint: urlSearchUser,
Query: map[string]string{
"ig_sig_key_version": goInstaSigKeyVersion,
"is_typeahead": "true",
"query": user,
"rank_toke... | go | func (search *Search) User(user string) (*SearchResult, error) {
insta := search.inst
body, err := insta.sendRequest(
&reqOptions{
Endpoint: urlSearchUser,
Query: map[string]string{
"ig_sig_key_version": goInstaSigKeyVersion,
"is_typeahead": "true",
"query": user,
"rank_toke... | [
"func",
"(",
"search",
"*",
"Search",
")",
"User",
"(",
"user",
"string",
")",
"(",
"*",
"SearchResult",
",",
"error",
")",
"{",
"insta",
":=",
"search",
".",
"inst",
"\n",
"body",
",",
"err",
":=",
"insta",
".",
"sendRequest",
"(",
"&",
"reqOptions"... | // User search by username | [
"User",
"search",
"by",
"username"
] | 86d8297fa4152941d864ca6d7d2e1f1f673708aa | https://github.com/ahmdrz/goinsta/blob/86d8297fa4152941d864ca6d7d2e1f1f673708aa/search.go#L73-L93 | train |
ahmdrz/goinsta | search.go | Tags | func (search *Search) Tags(tag string) (*SearchResult, error) {
insta := search.inst
body, err := insta.sendRequest(
&reqOptions{
Endpoint: urlSearchTag,
Query: map[string]string{
"is_typeahead": "true",
"rank_token": insta.rankToken,
"q": tag,
},
},
)
if err != nil {
return ... | go | func (search *Search) Tags(tag string) (*SearchResult, error) {
insta := search.inst
body, err := insta.sendRequest(
&reqOptions{
Endpoint: urlSearchTag,
Query: map[string]string{
"is_typeahead": "true",
"rank_token": insta.rankToken,
"q": tag,
},
},
)
if err != nil {
return ... | [
"func",
"(",
"search",
"*",
"Search",
")",
"Tags",
"(",
"tag",
"string",
")",
"(",
"*",
"SearchResult",
",",
"error",
")",
"{",
"insta",
":=",
"search",
".",
"inst",
"\n",
"body",
",",
"err",
":=",
"insta",
".",
"sendRequest",
"(",
"&",
"reqOptions",... | // Tags search by tag | [
"Tags",
"search",
"by",
"tag"
] | 86d8297fa4152941d864ca6d7d2e1f1f673708aa | https://github.com/ahmdrz/goinsta/blob/86d8297fa4152941d864ca6d7d2e1f1f673708aa/search.go#L96-L115 | train |
ahmdrz/goinsta | search.go | Facebook | func (search *Search) Facebook(user string) (*SearchResult, error) {
insta := search.inst
body, err := insta.sendRequest(
&reqOptions{
Endpoint: urlSearchFacebook,
Query: map[string]string{
"query": user,
"rank_token": insta.rankToken,
},
},
)
if err != nil {
return nil, err
}
res := &... | go | func (search *Search) Facebook(user string) (*SearchResult, error) {
insta := search.inst
body, err := insta.sendRequest(
&reqOptions{
Endpoint: urlSearchFacebook,
Query: map[string]string{
"query": user,
"rank_token": insta.rankToken,
},
},
)
if err != nil {
return nil, err
}
res := &... | [
"func",
"(",
"search",
"*",
"Search",
")",
"Facebook",
"(",
"user",
"string",
")",
"(",
"*",
"SearchResult",
",",
"error",
")",
"{",
"insta",
":=",
"search",
".",
"inst",
"\n",
"body",
",",
"err",
":=",
"insta",
".",
"sendRequest",
"(",
"&",
"reqOpti... | // Facebook search by facebook user. | [
"Facebook",
"search",
"by",
"facebook",
"user",
"."
] | 86d8297fa4152941d864ca6d7d2e1f1f673708aa | https://github.com/ahmdrz/goinsta/blob/86d8297fa4152941d864ca6d7d2e1f1f673708aa/search.go#L151-L168 | train |
ahmdrz/goinsta | types.go | GetBest | func (img Images) GetBest() string {
best := ""
var mh, mw int
for _, v := range img.Versions {
if v.Width > mw || v.Height > mh {
best = v.URL
mh, mw = v.Height, v.Width
}
}
return best
} | go | func (img Images) GetBest() string {
best := ""
var mh, mw int
for _, v := range img.Versions {
if v.Width > mw || v.Height > mh {
best = v.URL
mh, mw = v.Height, v.Width
}
}
return best
} | [
"func",
"(",
"img",
"Images",
")",
"GetBest",
"(",
")",
"string",
"{",
"best",
":=",
"\"",
"\"",
"\n",
"var",
"mh",
",",
"mw",
"int",
"\n",
"for",
"_",
",",
"v",
":=",
"range",
"img",
".",
"Versions",
"{",
"if",
"v",
".",
"Width",
">",
"mw",
... | // GetBest returns the URL of the image with the best quality. | [
"GetBest",
"returns",
"the",
"URL",
"of",
"the",
"image",
"with",
"the",
"best",
"quality",
"."
] | 86d8297fa4152941d864ca6d7d2e1f1f673708aa | https://github.com/ahmdrz/goinsta/blob/86d8297fa4152941d864ca6d7d2e1f1f673708aa/types.go#L149-L159 | train |
ahmdrz/goinsta | types.go | Unblock | func (b *BlockedUser) Unblock() error {
u := User{ID: b.UserID}
return u.Unblock()
} | go | func (b *BlockedUser) Unblock() error {
u := User{ID: b.UserID}
return u.Unblock()
} | [
"func",
"(",
"b",
"*",
"BlockedUser",
")",
"Unblock",
"(",
")",
"error",
"{",
"u",
":=",
"User",
"{",
"ID",
":",
"b",
".",
"UserID",
"}",
"\n",
"return",
"u",
".",
"Unblock",
"(",
")",
"\n",
"}"
] | // Unblock unblocks blocked user. | [
"Unblock",
"unblocks",
"blocked",
"user",
"."
] | 86d8297fa4152941d864ca6d7d2e1f1f673708aa | https://github.com/ahmdrz/goinsta/blob/86d8297fa4152941d864ca6d7d2e1f1f673708aa/types.go#L297-L300 | train |
ahmdrz/goinsta | utils.go | getImageDimensionFromReader | func getImageDimensionFromReader(rdr io.Reader) (int, int, error) {
image, _, err := image.DecodeConfig(rdr)
if err != nil {
return 0, 0, err
}
return image.Width, image.Height, nil
} | go | func getImageDimensionFromReader(rdr io.Reader) (int, int, error) {
image, _, err := image.DecodeConfig(rdr)
if err != nil {
return 0, 0, err
}
return image.Width, image.Height, nil
} | [
"func",
"getImageDimensionFromReader",
"(",
"rdr",
"io",
".",
"Reader",
")",
"(",
"int",
",",
"int",
",",
"error",
")",
"{",
"image",
",",
"_",
",",
"err",
":=",
"image",
".",
"DecodeConfig",
"(",
"rdr",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"r... | // getImageDimensionFromReader return image dimension , types is .jpg and .png | [
"getImageDimensionFromReader",
"return",
"image",
"dimension",
"types",
"is",
".",
"jpg",
"and",
".",
"png"
] | 86d8297fa4152941d864ca6d7d2e1f1f673708aa | https://github.com/ahmdrz/goinsta/blob/86d8297fa4152941d864ca6d7d2e1f1f673708aa/utils.go#L75-L81 | train |
ahmdrz/goinsta | account.go | Sync | func (account *Account) Sync() error {
insta := account.inst
data, err := insta.prepareData()
if err != nil {
return err
}
body, err := insta.sendRequest(&reqOptions{
Endpoint: urlCurrentUser,
Query: generateSignature(data),
IsPost: true,
})
if err == nil {
resp := profResp{}
err = json.Unmarsha... | go | func (account *Account) Sync() error {
insta := account.inst
data, err := insta.prepareData()
if err != nil {
return err
}
body, err := insta.sendRequest(&reqOptions{
Endpoint: urlCurrentUser,
Query: generateSignature(data),
IsPost: true,
})
if err == nil {
resp := profResp{}
err = json.Unmarsha... | [
"func",
"(",
"account",
"*",
"Account",
")",
"Sync",
"(",
")",
"error",
"{",
"insta",
":=",
"account",
".",
"inst",
"\n",
"data",
",",
"err",
":=",
"insta",
".",
"prepareData",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
... | // Sync updates account information | [
"Sync",
"updates",
"account",
"information"
] | 86d8297fa4152941d864ca6d7d2e1f1f673708aa | https://github.com/ahmdrz/goinsta/blob/86d8297fa4152941d864ca6d7d2e1f1f673708aa/account.go#L74-L94 | train |
ahmdrz/goinsta | account.go | Saved | func (account *Account) Saved() (*SavedMedia, error) {
body, err := account.inst.sendSimpleRequest(urlUserTags, account.ID)
if err == nil {
media := &SavedMedia{}
err = json.Unmarshal(body, &media)
return media, err
}
return nil, err
} | go | func (account *Account) Saved() (*SavedMedia, error) {
body, err := account.inst.sendSimpleRequest(urlUserTags, account.ID)
if err == nil {
media := &SavedMedia{}
err = json.Unmarshal(body, &media)
return media, err
}
return nil, err
} | [
"func",
"(",
"account",
"*",
"Account",
")",
"Saved",
"(",
")",
"(",
"*",
"SavedMedia",
",",
"error",
")",
"{",
"body",
",",
"err",
":=",
"account",
".",
"inst",
".",
"sendSimpleRequest",
"(",
"urlUserTags",
",",
"account",
".",
"ID",
")",
"\n",
"if"... | // Saved returns saved media. | [
"Saved",
"returns",
"saved",
"media",
"."
] | 86d8297fa4152941d864ca6d7d2e1f1f673708aa | https://github.com/ahmdrz/goinsta/blob/86d8297fa4152941d864ca6d7d2e1f1f673708aa/account.go#L312-L320 | train |
ahmdrz/goinsta | account.go | SetBiography | func (account *Account) SetBiography(bio string) error {
account.edit() // preparing to edit
insta := account.inst
data, err := insta.prepareData(
map[string]interface{}{
"raw_text": bio,
},
)
if err != nil {
return err
}
body, err := insta.sendRequest(
&reqOptions{
Endpoint: urlSetBiography,
Q... | go | func (account *Account) SetBiography(bio string) error {
account.edit() // preparing to edit
insta := account.inst
data, err := insta.prepareData(
map[string]interface{}{
"raw_text": bio,
},
)
if err != nil {
return err
}
body, err := insta.sendRequest(
&reqOptions{
Endpoint: urlSetBiography,
Q... | [
"func",
"(",
"account",
"*",
"Account",
")",
"SetBiography",
"(",
"bio",
"string",
")",
"error",
"{",
"account",
".",
"edit",
"(",
")",
"// preparing to edit",
"\n",
"insta",
":=",
"account",
".",
"inst",
"\n",
"data",
",",
"err",
":=",
"insta",
".",
"... | // SetBiography changes your Instagram's biography.
//
// This function updates current Account information. | [
"SetBiography",
"changes",
"your",
"Instagram",
"s",
"biography",
".",
"This",
"function",
"updates",
"current",
"Account",
"information",
"."
] | 86d8297fa4152941d864ca6d7d2e1f1f673708aa | https://github.com/ahmdrz/goinsta/blob/86d8297fa4152941d864ca6d7d2e1f1f673708aa/account.go#L350-L383 | train |
ahmdrz/goinsta | account.go | Liked | func (account *Account) Liked() *FeedMedia {
insta := account.inst
media := &FeedMedia{}
media.inst = insta
media.endpoint = urlFeedLiked
return media
} | go | func (account *Account) Liked() *FeedMedia {
insta := account.inst
media := &FeedMedia{}
media.inst = insta
media.endpoint = urlFeedLiked
return media
} | [
"func",
"(",
"account",
"*",
"Account",
")",
"Liked",
"(",
")",
"*",
"FeedMedia",
"{",
"insta",
":=",
"account",
".",
"inst",
"\n\n",
"media",
":=",
"&",
"FeedMedia",
"{",
"}",
"\n",
"media",
".",
"inst",
"=",
"insta",
"\n",
"media",
".",
"endpoint",... | // Liked are liked publications | [
"Liked",
"are",
"liked",
"publications"
] | 86d8297fa4152941d864ca6d7d2e1f1f673708aa | https://github.com/ahmdrz/goinsta/blob/86d8297fa4152941d864ca6d7d2e1f1f673708aa/account.go#L386-L393 | train |
ahmdrz/goinsta | account.go | PendingFollowRequests | func (account *Account) PendingFollowRequests() ([]User, error) {
insta := account.inst
resp, err := insta.sendRequest(
&reqOptions{
Endpoint: urlFriendshipPending,
},
)
if err != nil {
return nil, err
}
var result struct {
Users []User `json:"users"`
// TODO: pagination
// TODO: SuggestedUsers
... | go | func (account *Account) PendingFollowRequests() ([]User, error) {
insta := account.inst
resp, err := insta.sendRequest(
&reqOptions{
Endpoint: urlFriendshipPending,
},
)
if err != nil {
return nil, err
}
var result struct {
Users []User `json:"users"`
// TODO: pagination
// TODO: SuggestedUsers
... | [
"func",
"(",
"account",
"*",
"Account",
")",
"PendingFollowRequests",
"(",
")",
"(",
"[",
"]",
"User",
",",
"error",
")",
"{",
"insta",
":=",
"account",
".",
"inst",
"\n",
"resp",
",",
"err",
":=",
"insta",
".",
"sendRequest",
"(",
"&",
"reqOptions",
... | // PendingFollowRequests returns pending follow requests. | [
"PendingFollowRequests",
"returns",
"pending",
"follow",
"requests",
"."
] | 86d8297fa4152941d864ca6d7d2e1f1f673708aa | https://github.com/ahmdrz/goinsta/blob/86d8297fa4152941d864ca6d7d2e1f1f673708aa/account.go#L396-L422 | train |
ahmdrz/goinsta | feeds.go | LocationID | func (feed *Feed) LocationID(locationID int64) (*FeedLocation, error) {
insta := feed.inst
body, err := insta.sendRequest(
&reqOptions{
Endpoint: fmt.Sprintf(urlFeedLocationID, locationID),
Query: map[string]string{
"rank_token": insta.rankToken,
"ranked_content": "true",
},
},
)
if err != ... | go | func (feed *Feed) LocationID(locationID int64) (*FeedLocation, error) {
insta := feed.inst
body, err := insta.sendRequest(
&reqOptions{
Endpoint: fmt.Sprintf(urlFeedLocationID, locationID),
Query: map[string]string{
"rank_token": insta.rankToken,
"ranked_content": "true",
},
},
)
if err != ... | [
"func",
"(",
"feed",
"*",
"Feed",
")",
"LocationID",
"(",
"locationID",
"int64",
")",
"(",
"*",
"FeedLocation",
",",
"error",
")",
"{",
"insta",
":=",
"feed",
".",
"inst",
"\n",
"body",
",",
"err",
":=",
"insta",
".",
"sendRequest",
"(",
"&",
"reqOpt... | // Feed search by locationID | [
"Feed",
"search",
"by",
"locationID"
] | 86d8297fa4152941d864ca6d7d2e1f1f673708aa | https://github.com/ahmdrz/goinsta/blob/86d8297fa4152941d864ca6d7d2e1f1f673708aa/feeds.go#L21-L39 | train |
ahmdrz/goinsta | media.go | SyncLikers | func (item *Item) SyncLikers() error {
resp := respLikers{}
insta := item.media.instagram()
body, err := insta.sendSimpleRequest(urlMediaLikers, item.ID)
if err != nil {
return err
}
err = json.Unmarshal(body, &resp)
if err == nil {
item.Likers = resp.Users
}
return err
} | go | func (item *Item) SyncLikers() error {
resp := respLikers{}
insta := item.media.instagram()
body, err := insta.sendSimpleRequest(urlMediaLikers, item.ID)
if err != nil {
return err
}
err = json.Unmarshal(body, &resp)
if err == nil {
item.Likers = resp.Users
}
return err
} | [
"func",
"(",
"item",
"*",
"Item",
")",
"SyncLikers",
"(",
")",
"error",
"{",
"resp",
":=",
"respLikers",
"{",
"}",
"\n",
"insta",
":=",
"item",
".",
"media",
".",
"instagram",
"(",
")",
"\n",
"body",
",",
"err",
":=",
"insta",
".",
"sendSimpleRequest... | // SyncLikers fetch new likers of a media
//
// This function updates Item.Likers value | [
"SyncLikers",
"fetch",
"new",
"likers",
"of",
"a",
"media",
"This",
"function",
"updates",
"Item",
".",
"Likers",
"value"
] | 86d8297fa4152941d864ca6d7d2e1f1f673708aa | https://github.com/ahmdrz/goinsta/blob/86d8297fa4152941d864ca6d7d2e1f1f673708aa/media.go#L249-L261 | train |
ahmdrz/goinsta | media.go | ID | func (media *StoryMedia) ID() string {
switch id := media.Pk.(type) {
case int64:
return strconv.FormatInt(id, 10)
case string:
return id
}
return ""
} | go | func (media *StoryMedia) ID() string {
switch id := media.Pk.(type) {
case int64:
return strconv.FormatInt(id, 10)
case string:
return id
}
return ""
} | [
"func",
"(",
"media",
"*",
"StoryMedia",
")",
"ID",
"(",
")",
"string",
"{",
"switch",
"id",
":=",
"media",
".",
"Pk",
".",
"(",
"type",
")",
"{",
"case",
"int64",
":",
"return",
"strconv",
".",
"FormatInt",
"(",
"id",
",",
"10",
")",
"\n",
"case... | // ID returns Story id | [
"ID",
"returns",
"Story",
"id"
] | 86d8297fa4152941d864ca6d7d2e1f1f673708aa | https://github.com/ahmdrz/goinsta/blob/86d8297fa4152941d864ca6d7d2e1f1f673708aa/media.go#L524-L532 | train |
ahmdrz/goinsta | media.go | Sync | func (media *StoryMedia) Sync() error {
insta := media.inst
query := []trayRequest{
{"SUPPORTED_SDK_VERSIONS", "9.0,10.0,11.0,12.0,13.0,14.0,15.0,16.0,17.0,18.0,19.0,20.0,21.0,22.0,23.0,24.0"},
{"FACE_TRACKER_VERSION", "10"},
{"segmentation", "segmentation_enabled"},
{"COMPRESSION", "ETC2_COMPRESSION"},
}
q... | go | func (media *StoryMedia) Sync() error {
insta := media.inst
query := []trayRequest{
{"SUPPORTED_SDK_VERSIONS", "9.0,10.0,11.0,12.0,13.0,14.0,15.0,16.0,17.0,18.0,19.0,20.0,21.0,22.0,23.0,24.0"},
{"FACE_TRACKER_VERSION", "10"},
{"segmentation", "segmentation_enabled"},
{"COMPRESSION", "ETC2_COMPRESSION"},
}
q... | [
"func",
"(",
"media",
"*",
"StoryMedia",
")",
"Sync",
"(",
")",
"error",
"{",
"insta",
":=",
"media",
".",
"inst",
"\n",
"query",
":=",
"[",
"]",
"trayRequest",
"{",
"{",
"\"",
"\"",
",",
"\"",
"\"",
"}",
",",
"{",
"\"",
"\"",
",",
"\"",
"\"",
... | // Sync function is used when Highlight must be sync.
// Highlight must be sync when User.Highlights does not return any object inside StoryMedia slice.
//
// This function does NOT update Stories items.
//
// This function updates StoryMedia.Items | [
"Sync",
"function",
"is",
"used",
"when",
"Highlight",
"must",
"be",
"sync",
".",
"Highlight",
"must",
"be",
"sync",
"when",
"User",
".",
"Highlights",
"does",
"not",
"return",
"any",
"object",
"inside",
"StoryMedia",
"slice",
".",
"This",
"function",
"does"... | 86d8297fa4152941d864ca6d7d2e1f1f673708aa | https://github.com/ahmdrz/goinsta/blob/86d8297fa4152941d864ca6d7d2e1f1f673708aa/media.go#L589-L634 | train |
ahmdrz/goinsta | media.go | Sync | func (media *FeedMedia) Sync() error {
id := media.ID()
insta := media.inst
data, err := insta.prepareData(
map[string]interface{}{
"media_id": id,
},
)
if err != nil {
return err
}
body, err := insta.sendRequest(
&reqOptions{
Endpoint: fmt.Sprintf(urlMediaInfo, id),
Query: generateSignatur... | go | func (media *FeedMedia) Sync() error {
id := media.ID()
insta := media.inst
data, err := insta.prepareData(
map[string]interface{}{
"media_id": id,
},
)
if err != nil {
return err
}
body, err := insta.sendRequest(
&reqOptions{
Endpoint: fmt.Sprintf(urlMediaInfo, id),
Query: generateSignatur... | [
"func",
"(",
"media",
"*",
"FeedMedia",
")",
"Sync",
"(",
")",
"error",
"{",
"id",
":=",
"media",
".",
"ID",
"(",
")",
"\n",
"insta",
":=",
"media",
".",
"inst",
"\n\n",
"data",
",",
"err",
":=",
"insta",
".",
"prepareData",
"(",
"map",
"[",
"str... | // Sync updates media values. | [
"Sync",
"updates",
"media",
"values",
"."
] | 86d8297fa4152941d864ca6d7d2e1f1f673708aa | https://github.com/ahmdrz/goinsta/blob/86d8297fa4152941d864ca6d7d2e1f1f673708aa/media.go#L717-L749 | train |
ahmdrz/goinsta | media.go | ID | func (media *FeedMedia) ID() string {
switch s := media.NextID.(type) {
case string:
return s
case int64:
return strconv.FormatInt(s, 10)
case json.Number:
return string(s)
}
return ""
} | go | func (media *FeedMedia) ID() string {
switch s := media.NextID.(type) {
case string:
return s
case int64:
return strconv.FormatInt(s, 10)
case json.Number:
return string(s)
}
return ""
} | [
"func",
"(",
"media",
"*",
"FeedMedia",
")",
"ID",
"(",
")",
"string",
"{",
"switch",
"s",
":=",
"media",
".",
"NextID",
".",
"(",
"type",
")",
"{",
"case",
"string",
":",
"return",
"s",
"\n",
"case",
"int64",
":",
"return",
"strconv",
".",
"Format... | // ID returns media id. | [
"ID",
"returns",
"media",
"id",
"."
] | 86d8297fa4152941d864ca6d7d2e1f1f673708aa | https://github.com/ahmdrz/goinsta/blob/86d8297fa4152941d864ca6d7d2e1f1f673708aa/media.go#L762-L772 | train |
ahmdrz/goinsta | inbox.go | Write | func (c *Conversation) Write(b []byte) (int, error) {
n := len(b)
return n, c.Send(b2s(b))
} | go | func (c *Conversation) Write(b []byte) (int, error) {
n := len(b)
return n, c.Send(b2s(b))
} | [
"func",
"(",
"c",
"*",
"Conversation",
")",
"Write",
"(",
"b",
"[",
"]",
"byte",
")",
"(",
"int",
",",
"error",
")",
"{",
"n",
":=",
"len",
"(",
"b",
")",
"\n",
"return",
"n",
",",
"c",
".",
"Send",
"(",
"b2s",
"(",
"b",
")",
")",
"\n",
"... | // Write is like Send but being compatible with io.Writer. | [
"Write",
"is",
"like",
"Send",
"but",
"being",
"compatible",
"with",
"io",
".",
"Writer",
"."
] | 86d8297fa4152941d864ca6d7d2e1f1f673708aa | https://github.com/ahmdrz/goinsta/blob/86d8297fa4152941d864ca6d7d2e1f1f673708aa/inbox.go#L340-L343 | train |
ahmdrz/goinsta | comments.go | Next | func (comments *Comments) Next() bool {
if comments.err != nil {
return false
}
item := comments.item
insta := item.media.instagram()
endpoint := comments.endpoint
query := map[string]string{
// "can_support_threading": "true",
}
if comments.NextMaxID != nil {
next, _ := strconv.Unquote(string(comments.N... | go | func (comments *Comments) Next() bool {
if comments.err != nil {
return false
}
item := comments.item
insta := item.media.instagram()
endpoint := comments.endpoint
query := map[string]string{
// "can_support_threading": "true",
}
if comments.NextMaxID != nil {
next, _ := strconv.Unquote(string(comments.N... | [
"func",
"(",
"comments",
"*",
"Comments",
")",
"Next",
"(",
")",
"bool",
"{",
"if",
"comments",
".",
"err",
"!=",
"nil",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"item",
":=",
"comments",
".",
"item",
"\n",
"insta",
":=",
"item",
".",
"media",
".... | // Next allows comment pagination.
//
// This function support concurrency methods to get comments using Last and Next ID
//
// New comments are stored in Comments.Items | [
"Next",
"allows",
"comment",
"pagination",
".",
"This",
"function",
"support",
"concurrency",
"methods",
"to",
"get",
"comments",
"using",
"Last",
"and",
"Next",
"ID",
"New",
"comments",
"are",
"stored",
"in",
"Comments",
".",
"Items"
] | 86d8297fa4152941d864ca6d7d2e1f1f673708aa | https://github.com/ahmdrz/goinsta/blob/86d8297fa4152941d864ca6d7d2e1f1f673708aa/comments.go#L117-L160 | train |
ahmdrz/goinsta | comments.go | Del | func (comments *Comments) Del(comment *Comment) error {
insta := comments.item.media.instagram()
data, err := insta.prepareData()
if err != nil {
return err
}
id := comment.getid()
_, err = insta.sendRequest(
&reqOptions{
Endpoint: fmt.Sprintf(urlCommentDelete, comments.item.ID, id),
Query: generat... | go | func (comments *Comments) Del(comment *Comment) error {
insta := comments.item.media.instagram()
data, err := insta.prepareData()
if err != nil {
return err
}
id := comment.getid()
_, err = insta.sendRequest(
&reqOptions{
Endpoint: fmt.Sprintf(urlCommentDelete, comments.item.ID, id),
Query: generat... | [
"func",
"(",
"comments",
"*",
"Comments",
")",
"Del",
"(",
"comment",
"*",
"Comment",
")",
"error",
"{",
"insta",
":=",
"comments",
".",
"item",
".",
"media",
".",
"instagram",
"(",
")",
"\n\n",
"data",
",",
"err",
":=",
"insta",
".",
"prepareData",
... | // Del deletes comment. | [
"Del",
"deletes",
"comment",
"."
] | 86d8297fa4152941d864ca6d7d2e1f1f673708aa | https://github.com/ahmdrz/goinsta/blob/86d8297fa4152941d864ca6d7d2e1f1f673708aa/comments.go#L230-L247 | train |
ahmdrz/goinsta | comments.go | Like | func (c *Comment) Like() error {
data, err := c.inst.prepareData()
if err != nil {
return err
}
_, err = c.inst.sendRequest(
&reqOptions{
Endpoint: fmt.Sprintf(urlCommentLike, c.getid()),
Query: generateSignature(data),
IsPost: true,
},
)
return err
} | go | func (c *Comment) Like() error {
data, err := c.inst.prepareData()
if err != nil {
return err
}
_, err = c.inst.sendRequest(
&reqOptions{
Endpoint: fmt.Sprintf(urlCommentLike, c.getid()),
Query: generateSignature(data),
IsPost: true,
},
)
return err
} | [
"func",
"(",
"c",
"*",
"Comment",
")",
"Like",
"(",
")",
"error",
"{",
"data",
",",
"err",
":=",
"c",
".",
"inst",
".",
"prepareData",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"_",
",",
"err",
"=",
"c... | // Like likes comment. | [
"Like",
"likes",
"comment",
"."
] | 86d8297fa4152941d864ca6d7d2e1f1f673708aa | https://github.com/ahmdrz/goinsta/blob/86d8297fa4152941d864ca6d7d2e1f1f673708aa/comments.go#L339-L353 | train |
ahmdrz/goinsta | hashtags.go | NewHashtag | func (inst *Instagram) NewHashtag(name string) *Hashtag {
return &Hashtag{
inst: inst,
Name: name,
}
} | go | func (inst *Instagram) NewHashtag(name string) *Hashtag {
return &Hashtag{
inst: inst,
Name: name,
}
} | [
"func",
"(",
"inst",
"*",
"Instagram",
")",
"NewHashtag",
"(",
"name",
"string",
")",
"*",
"Hashtag",
"{",
"return",
"&",
"Hashtag",
"{",
"inst",
":",
"inst",
",",
"Name",
":",
"name",
",",
"}",
"\n",
"}"
] | // NewHashtag returns initialised hashtag structure
// Name parameter is hashtag name | [
"NewHashtag",
"returns",
"initialised",
"hashtag",
"structure",
"Name",
"parameter",
"is",
"hashtag",
"name"
] | 86d8297fa4152941d864ca6d7d2e1f1f673708aa | https://github.com/ahmdrz/goinsta/blob/86d8297fa4152941d864ca6d7d2e1f1f673708aa/hashtags.go#L56-L61 | train |
ahmdrz/goinsta | hashtags.go | Sync | func (h *Hashtag) Sync() error {
insta := h.inst
body, err := insta.sendSimpleRequest(urlTagSync, h.Name)
if err == nil {
var resp struct {
Name string `json:"name"`
ID int64 `json:"id"`
MediaCount int `json:"media_count"`
}
err = json.Unmarshal(body, &resp)
if err == nil {
h.N... | go | func (h *Hashtag) Sync() error {
insta := h.inst
body, err := insta.sendSimpleRequest(urlTagSync, h.Name)
if err == nil {
var resp struct {
Name string `json:"name"`
ID int64 `json:"id"`
MediaCount int `json:"media_count"`
}
err = json.Unmarshal(body, &resp)
if err == nil {
h.N... | [
"func",
"(",
"h",
"*",
"Hashtag",
")",
"Sync",
"(",
")",
"error",
"{",
"insta",
":=",
"h",
".",
"inst",
"\n\n",
"body",
",",
"err",
":=",
"insta",
".",
"sendSimpleRequest",
"(",
"urlTagSync",
",",
"h",
".",
"Name",
")",
"\n",
"if",
"err",
"==",
"... | // Sync updates Hashtag information preparing it to Next call. | [
"Sync",
"updates",
"Hashtag",
"information",
"preparing",
"it",
"to",
"Next",
"call",
"."
] | 86d8297fa4152941d864ca6d7d2e1f1f673708aa | https://github.com/ahmdrz/goinsta/blob/86d8297fa4152941d864ca6d7d2e1f1f673708aa/hashtags.go#L64-L83 | train |
ahmdrz/goinsta | hashtags.go | Stories | func (h *Hashtag) Stories() (*StoryMedia, error) {
body, err := h.inst.sendSimpleRequest(
urlTagStories, h.Name,
)
if err == nil {
var resp struct {
Story StoryMedia `json:"story"`
Status string `json:"status"`
}
err = json.Unmarshal(body, &resp)
return &resp.Story, err
}
return nil, err
} | go | func (h *Hashtag) Stories() (*StoryMedia, error) {
body, err := h.inst.sendSimpleRequest(
urlTagStories, h.Name,
)
if err == nil {
var resp struct {
Story StoryMedia `json:"story"`
Status string `json:"status"`
}
err = json.Unmarshal(body, &resp)
return &resp.Story, err
}
return nil, err
} | [
"func",
"(",
"h",
"*",
"Hashtag",
")",
"Stories",
"(",
")",
"(",
"*",
"StoryMedia",
",",
"error",
")",
"{",
"body",
",",
"err",
":=",
"h",
".",
"inst",
".",
"sendSimpleRequest",
"(",
"urlTagStories",
",",
"h",
".",
"Name",
",",
")",
"\n",
"if",
"... | // Stories returns hashtag stories. | [
"Stories",
"returns",
"hashtag",
"stories",
"."
] | 86d8297fa4152941d864ca6d7d2e1f1f673708aa | https://github.com/ahmdrz/goinsta/blob/86d8297fa4152941d864ca6d7d2e1f1f673708aa/hashtags.go#L127-L140 | train |
ahmdrz/goinsta | profiles.go | Blocked | func (prof *Profiles) Blocked() ([]BlockedUser, error) {
body, err := prof.inst.sendSimpleRequest(urlBlockedList)
if err == nil {
resp := blockedListResp{}
err = json.Unmarshal(body, &resp)
return resp.BlockedList, err
}
return nil, err
} | go | func (prof *Profiles) Blocked() ([]BlockedUser, error) {
body, err := prof.inst.sendSimpleRequest(urlBlockedList)
if err == nil {
resp := blockedListResp{}
err = json.Unmarshal(body, &resp)
return resp.BlockedList, err
}
return nil, err
} | [
"func",
"(",
"prof",
"*",
"Profiles",
")",
"Blocked",
"(",
")",
"(",
"[",
"]",
"BlockedUser",
",",
"error",
")",
"{",
"body",
",",
"err",
":=",
"prof",
".",
"inst",
".",
"sendSimpleRequest",
"(",
"urlBlockedList",
")",
"\n",
"if",
"err",
"==",
"nil",... | // Blocked returns a list of blocked profiles. | [
"Blocked",
"returns",
"a",
"list",
"of",
"blocked",
"profiles",
"."
] | 86d8297fa4152941d864ca6d7d2e1f1f673708aa | https://github.com/ahmdrz/goinsta/blob/86d8297fa4152941d864ca6d7d2e1f1f673708aa/profiles.go#L61-L69 | train |
mailru/easyjson | opt/gotemplate_Uint64.go | MarshalJSON | func (v Uint64) MarshalJSON() ([]byte, error) {
w := jwriter.Writer{}
v.MarshalEasyJSON(&w)
return w.Buffer.BuildBytes(), w.Error
} | go | func (v Uint64) MarshalJSON() ([]byte, error) {
w := jwriter.Writer{}
v.MarshalEasyJSON(&w)
return w.Buffer.BuildBytes(), w.Error
} | [
"func",
"(",
"v",
"Uint64",
")",
"MarshalJSON",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"w",
":=",
"jwriter",
".",
"Writer",
"{",
"}",
"\n",
"v",
".",
"MarshalEasyJSON",
"(",
"&",
"w",
")",
"\n",
"return",
"w",
".",
"Buffer",
"... | // MarshalJSON implements a standard json marshaler interface. | [
"MarshalJSON",
"implements",
"a",
"standard",
"json",
"marshaler",
"interface",
"."
] | 1ea4449da9834f4d333f1cc461c374aea217d249 | https://github.com/mailru/easyjson/blob/1ea4449da9834f4d333f1cc461c374aea217d249/opt/gotemplate_Uint64.go#L54-L58 | train |
mailru/easyjson | opt/gotemplate_Uint64.go | UnmarshalJSON | func (v *Uint64) UnmarshalJSON(data []byte) error {
l := jlexer.Lexer{Data: data}
v.UnmarshalEasyJSON(&l)
return l.Error()
} | go | func (v *Uint64) UnmarshalJSON(data []byte) error {
l := jlexer.Lexer{Data: data}
v.UnmarshalEasyJSON(&l)
return l.Error()
} | [
"func",
"(",
"v",
"*",
"Uint64",
")",
"UnmarshalJSON",
"(",
"data",
"[",
"]",
"byte",
")",
"error",
"{",
"l",
":=",
"jlexer",
".",
"Lexer",
"{",
"Data",
":",
"data",
"}",
"\n",
"v",
".",
"UnmarshalEasyJSON",
"(",
"&",
"l",
")",
"\n",
"return",
"l... | // UnmarshalJSON implements a standard json unmarshaler interface. | [
"UnmarshalJSON",
"implements",
"a",
"standard",
"json",
"unmarshaler",
"interface",
"."
] | 1ea4449da9834f4d333f1cc461c374aea217d249 | https://github.com/mailru/easyjson/blob/1ea4449da9834f4d333f1cc461c374aea217d249/opt/gotemplate_Uint64.go#L61-L65 | train |
mailru/easyjson | gen/decoder.go | genTypeDecoder | func (g *Generator) genTypeDecoder(t reflect.Type, out string, tags fieldTags, indent int) error {
ws := strings.Repeat(" ", indent)
unmarshalerIface := reflect.TypeOf((*easyjson.Unmarshaler)(nil)).Elem()
if reflect.PtrTo(t).Implements(unmarshalerIface) {
fmt.Fprintln(g.out, ws+"("+out+").UnmarshalEasyJSON(in)")... | go | func (g *Generator) genTypeDecoder(t reflect.Type, out string, tags fieldTags, indent int) error {
ws := strings.Repeat(" ", indent)
unmarshalerIface := reflect.TypeOf((*easyjson.Unmarshaler)(nil)).Elem()
if reflect.PtrTo(t).Implements(unmarshalerIface) {
fmt.Fprintln(g.out, ws+"("+out+").UnmarshalEasyJSON(in)")... | [
"func",
"(",
"g",
"*",
"Generator",
")",
"genTypeDecoder",
"(",
"t",
"reflect",
".",
"Type",
",",
"out",
"string",
",",
"tags",
"fieldTags",
",",
"indent",
"int",
")",
"error",
"{",
"ws",
":=",
"strings",
".",
"Repeat",
"(",
"\"",
"\"",
",",
"indent"... | // genTypeDecoder generates decoding code for the type t, but uses unmarshaler interface if implemented by t. | [
"genTypeDecoder",
"generates",
"decoding",
"code",
"for",
"the",
"type",
"t",
"but",
"uses",
"unmarshaler",
"interface",
"if",
"implemented",
"by",
"t",
"."
] | 1ea4449da9834f4d333f1cc461c374aea217d249 | https://github.com/mailru/easyjson/blob/1ea4449da9834f4d333f1cc461c374aea217d249/gen/decoder.go#L60-L87 | train |
mailru/easyjson | gen/decoder.go | hasCustomUnmarshaler | func hasCustomUnmarshaler(t reflect.Type) bool {
t = reflect.PtrTo(t)
return t.Implements(reflect.TypeOf((*easyjson.Unmarshaler)(nil)).Elem()) ||
t.Implements(reflect.TypeOf((*json.Unmarshaler)(nil)).Elem()) ||
t.Implements(reflect.TypeOf((*encoding.TextUnmarshaler)(nil)).Elem())
} | go | func hasCustomUnmarshaler(t reflect.Type) bool {
t = reflect.PtrTo(t)
return t.Implements(reflect.TypeOf((*easyjson.Unmarshaler)(nil)).Elem()) ||
t.Implements(reflect.TypeOf((*json.Unmarshaler)(nil)).Elem()) ||
t.Implements(reflect.TypeOf((*encoding.TextUnmarshaler)(nil)).Elem())
} | [
"func",
"hasCustomUnmarshaler",
"(",
"t",
"reflect",
".",
"Type",
")",
"bool",
"{",
"t",
"=",
"reflect",
".",
"PtrTo",
"(",
"t",
")",
"\n",
"return",
"t",
".",
"Implements",
"(",
"reflect",
".",
"TypeOf",
"(",
"(",
"*",
"easyjson",
".",
"Unmarshaler",
... | // returns true of the type t implements one of the custom unmarshaler interfaces | [
"returns",
"true",
"of",
"the",
"type",
"t",
"implements",
"one",
"of",
"the",
"custom",
"unmarshaler",
"interfaces"
] | 1ea4449da9834f4d333f1cc461c374aea217d249 | https://github.com/mailru/easyjson/blob/1ea4449da9834f4d333f1cc461c374aea217d249/gen/decoder.go#L90-L95 | train |
mailru/easyjson | opt/gotemplate_Float32.go | String | func (v Float32) String() string {
if !v.Defined {
return "<undefined>"
}
return fmt.Sprint(v.V)
} | go | func (v Float32) String() string {
if !v.Defined {
return "<undefined>"
}
return fmt.Sprint(v.V)
} | [
"func",
"(",
"v",
"Float32",
")",
"String",
"(",
")",
"string",
"{",
"if",
"!",
"v",
".",
"Defined",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n",
"return",
"fmt",
".",
"Sprint",
"(",
"v",
".",
"V",
")",
"\n",
"}"
] | // String implements a stringer interface using fmt.Sprint for the value. | [
"String",
"implements",
"a",
"stringer",
"interface",
"using",
"fmt",
".",
"Sprint",
"for",
"the",
"value",
"."
] | 1ea4449da9834f4d333f1cc461c374aea217d249 | https://github.com/mailru/easyjson/blob/1ea4449da9834f4d333f1cc461c374aea217d249/opt/gotemplate_Float32.go#L74-L79 | train |
mailru/easyjson | gen/generator.go | NewGenerator | func NewGenerator(filename string) *Generator {
ret := &Generator{
imports: map[string]string{
pkgWriter: "jwriter",
pkgLexer: "jlexer",
pkgEasyJSON: "easyjson",
"encoding/json": "json",
},
fieldNamer: DefaultFieldNamer{},
marshalers: make(map[reflect.Type]bool),
typesSeen:... | go | func NewGenerator(filename string) *Generator {
ret := &Generator{
imports: map[string]string{
pkgWriter: "jwriter",
pkgLexer: "jlexer",
pkgEasyJSON: "easyjson",
"encoding/json": "json",
},
fieldNamer: DefaultFieldNamer{},
marshalers: make(map[reflect.Type]bool),
typesSeen:... | [
"func",
"NewGenerator",
"(",
"filename",
"string",
")",
"*",
"Generator",
"{",
"ret",
":=",
"&",
"Generator",
"{",
"imports",
":",
"map",
"[",
"string",
"]",
"string",
"{",
"pkgWriter",
":",
"\"",
"\"",
",",
"pkgLexer",
":",
"\"",
"\"",
",",
"pkgEasyJS... | // NewGenerator initializes and returns a Generator. | [
"NewGenerator",
"initializes",
"and",
"returns",
"a",
"Generator",
"."
] | 1ea4449da9834f4d333f1cc461c374aea217d249 | https://github.com/mailru/easyjson/blob/1ea4449da9834f4d333f1cc461c374aea217d249/gen/generator.go#L59-L80 | train |
mailru/easyjson | gen/generator.go | SetPkg | func (g *Generator) SetPkg(name, path string) {
g.pkgName = name
g.pkgPath = path
} | go | func (g *Generator) SetPkg(name, path string) {
g.pkgName = name
g.pkgPath = path
} | [
"func",
"(",
"g",
"*",
"Generator",
")",
"SetPkg",
"(",
"name",
",",
"path",
"string",
")",
"{",
"g",
".",
"pkgName",
"=",
"name",
"\n",
"g",
".",
"pkgPath",
"=",
"path",
"\n",
"}"
] | // SetPkg sets the name and path of output package. | [
"SetPkg",
"sets",
"the",
"name",
"and",
"path",
"of",
"output",
"package",
"."
] | 1ea4449da9834f4d333f1cc461c374aea217d249 | https://github.com/mailru/easyjson/blob/1ea4449da9834f4d333f1cc461c374aea217d249/gen/generator.go#L83-L86 | train |
mailru/easyjson | gen/generator.go | printHeader | func (g *Generator) printHeader() {
if g.buildTags != "" {
fmt.Println("// +build ", g.buildTags)
fmt.Println()
}
fmt.Println("// Code generated by easyjson for marshaling/unmarshaling. DO NOT EDIT.")
fmt.Println()
fmt.Println("package ", g.pkgName)
fmt.Println()
byAlias := map[string]string{}
var aliases ... | go | func (g *Generator) printHeader() {
if g.buildTags != "" {
fmt.Println("// +build ", g.buildTags)
fmt.Println()
}
fmt.Println("// Code generated by easyjson for marshaling/unmarshaling. DO NOT EDIT.")
fmt.Println()
fmt.Println("package ", g.pkgName)
fmt.Println()
byAlias := map[string]string{}
var aliases ... | [
"func",
"(",
"g",
"*",
"Generator",
")",
"printHeader",
"(",
")",
"{",
"if",
"g",
".",
"buildTags",
"!=",
"\"",
"\"",
"{",
"fmt",
".",
"Println",
"(",
"\"",
"\"",
",",
"g",
".",
"buildTags",
")",
"\n",
"fmt",
".",
"Println",
"(",
")",
"\n",
"}"... | // printHeader prints package declaration and imports. | [
"printHeader",
"prints",
"package",
"declaration",
"and",
"imports",
"."
] | 1ea4449da9834f4d333f1cc461c374aea217d249 | https://github.com/mailru/easyjson/blob/1ea4449da9834f4d333f1cc461c374aea217d249/gen/generator.go#L149-L183 | train |
mailru/easyjson | gen/generator.go | Run | func (g *Generator) Run(out io.Writer) error {
g.out = &bytes.Buffer{}
for len(g.typesUnseen) > 0 {
t := g.typesUnseen[len(g.typesUnseen)-1]
g.typesUnseen = g.typesUnseen[:len(g.typesUnseen)-1]
g.typesSeen[t] = true
if err := g.genDecoder(t); err != nil {
return err
}
if err := g.genEncoder(t); err !... | go | func (g *Generator) Run(out io.Writer) error {
g.out = &bytes.Buffer{}
for len(g.typesUnseen) > 0 {
t := g.typesUnseen[len(g.typesUnseen)-1]
g.typesUnseen = g.typesUnseen[:len(g.typesUnseen)-1]
g.typesSeen[t] = true
if err := g.genDecoder(t); err != nil {
return err
}
if err := g.genEncoder(t); err !... | [
"func",
"(",
"g",
"*",
"Generator",
")",
"Run",
"(",
"out",
"io",
".",
"Writer",
")",
"error",
"{",
"g",
".",
"out",
"=",
"&",
"bytes",
".",
"Buffer",
"{",
"}",
"\n\n",
"for",
"len",
"(",
"g",
".",
"typesUnseen",
")",
">",
"0",
"{",
"t",
":="... | // Run runs the generator and outputs generated code to out. | [
"Run",
"runs",
"the",
"generator",
"and",
"outputs",
"generated",
"code",
"to",
"out",
"."
] | 1ea4449da9834f4d333f1cc461c374aea217d249 | https://github.com/mailru/easyjson/blob/1ea4449da9834f4d333f1cc461c374aea217d249/gen/generator.go#L186-L215 | train |
mailru/easyjson | gen/generator.go | fixPkgPathVendoring | func fixPkgPathVendoring(pkgPath string) string {
const vendor = "/vendor/"
if i := strings.LastIndex(pkgPath, vendor); i != -1 {
return pkgPath[i+len(vendor):]
}
return pkgPath
} | go | func fixPkgPathVendoring(pkgPath string) string {
const vendor = "/vendor/"
if i := strings.LastIndex(pkgPath, vendor); i != -1 {
return pkgPath[i+len(vendor):]
}
return pkgPath
} | [
"func",
"fixPkgPathVendoring",
"(",
"pkgPath",
"string",
")",
"string",
"{",
"const",
"vendor",
"=",
"\"",
"\"",
"\n",
"if",
"i",
":=",
"strings",
".",
"LastIndex",
"(",
"pkgPath",
",",
"vendor",
")",
";",
"i",
"!=",
"-",
"1",
"{",
"return",
"pkgPath",... | // fixes vendored paths | [
"fixes",
"vendored",
"paths"
] | 1ea4449da9834f4d333f1cc461c374aea217d249 | https://github.com/mailru/easyjson/blob/1ea4449da9834f4d333f1cc461c374aea217d249/gen/generator.go#L218-L224 | train |
mailru/easyjson | gen/generator.go | pkgAlias | func (g *Generator) pkgAlias(pkgPath string) string {
pkgPath = fixPkgPathVendoring(pkgPath)
if alias := g.imports[pkgPath]; alias != "" {
return alias
}
for i := 0; ; i++ {
alias := fixAliasName(path.Base(pkgPath))
if i > 0 {
alias += fmt.Sprint(i)
}
exists := false
for _, v := range g.imports {
... | go | func (g *Generator) pkgAlias(pkgPath string) string {
pkgPath = fixPkgPathVendoring(pkgPath)
if alias := g.imports[pkgPath]; alias != "" {
return alias
}
for i := 0; ; i++ {
alias := fixAliasName(path.Base(pkgPath))
if i > 0 {
alias += fmt.Sprint(i)
}
exists := false
for _, v := range g.imports {
... | [
"func",
"(",
"g",
"*",
"Generator",
")",
"pkgAlias",
"(",
"pkgPath",
"string",
")",
"string",
"{",
"pkgPath",
"=",
"fixPkgPathVendoring",
"(",
"pkgPath",
")",
"\n",
"if",
"alias",
":=",
"g",
".",
"imports",
"[",
"pkgPath",
"]",
";",
"alias",
"!=",
"\""... | // pkgAlias creates and returns and import alias for a given package. | [
"pkgAlias",
"creates",
"and",
"returns",
"and",
"import",
"alias",
"for",
"a",
"given",
"package",
"."
] | 1ea4449da9834f4d333f1cc461c374aea217d249 | https://github.com/mailru/easyjson/blob/1ea4449da9834f4d333f1cc461c374aea217d249/gen/generator.go#L241-L266 | train |
mailru/easyjson | gen/generator.go | getType | func (g *Generator) getType(t reflect.Type) string {
if t.Name() == "" {
switch t.Kind() {
case reflect.Ptr:
return "*" + g.getType(t.Elem())
case reflect.Slice:
return "[]" + g.getType(t.Elem())
case reflect.Array:
return "[" + strconv.Itoa(t.Len()) + "]" + g.getType(t.Elem())
case reflect.Map:
... | go | func (g *Generator) getType(t reflect.Type) string {
if t.Name() == "" {
switch t.Kind() {
case reflect.Ptr:
return "*" + g.getType(t.Elem())
case reflect.Slice:
return "[]" + g.getType(t.Elem())
case reflect.Array:
return "[" + strconv.Itoa(t.Len()) + "]" + g.getType(t.Elem())
case reflect.Map:
... | [
"func",
"(",
"g",
"*",
"Generator",
")",
"getType",
"(",
"t",
"reflect",
".",
"Type",
")",
"string",
"{",
"if",
"t",
".",
"Name",
"(",
")",
"==",
"\"",
"\"",
"{",
"switch",
"t",
".",
"Kind",
"(",
")",
"{",
"case",
"reflect",
".",
"Ptr",
":",
... | // getType return the textual type name of given type that can be used in generated code. | [
"getType",
"return",
"the",
"textual",
"type",
"name",
"of",
"given",
"type",
"that",
"can",
"be",
"used",
"in",
"generated",
"code",
"."
] | 1ea4449da9834f4d333f1cc461c374aea217d249 | https://github.com/mailru/easyjson/blob/1ea4449da9834f4d333f1cc461c374aea217d249/gen/generator.go#L269-L311 | train |
mailru/easyjson | gen/generator.go | escapeTag | func escapeTag(tag reflect.StructTag) string {
t := string(tag)
if strings.ContainsRune(t, '`') {
// there are ` in the string; we can't use ` to enclose the string
return strconv.Quote(t)
}
return "`" + t + "`"
} | go | func escapeTag(tag reflect.StructTag) string {
t := string(tag)
if strings.ContainsRune(t, '`') {
// there are ` in the string; we can't use ` to enclose the string
return strconv.Quote(t)
}
return "`" + t + "`"
} | [
"func",
"escapeTag",
"(",
"tag",
"reflect",
".",
"StructTag",
")",
"string",
"{",
"t",
":=",
"string",
"(",
"tag",
")",
"\n",
"if",
"strings",
".",
"ContainsRune",
"(",
"t",
",",
"'`'",
")",
"{",
"// there are ` in the string; we can't use ` to enclose the strin... | // escape a struct field tag string back to source code | [
"escape",
"a",
"struct",
"field",
"tag",
"string",
"back",
"to",
"source",
"code"
] | 1ea4449da9834f4d333f1cc461c374aea217d249 | https://github.com/mailru/easyjson/blob/1ea4449da9834f4d333f1cc461c374aea217d249/gen/generator.go#L314-L321 | train |
mailru/easyjson | gen/generator.go | uniqueVarName | func (g *Generator) uniqueVarName() string {
g.varCounter++
return fmt.Sprint("v", g.varCounter)
} | go | func (g *Generator) uniqueVarName() string {
g.varCounter++
return fmt.Sprint("v", g.varCounter)
} | [
"func",
"(",
"g",
"*",
"Generator",
")",
"uniqueVarName",
"(",
")",
"string",
"{",
"g",
".",
"varCounter",
"++",
"\n",
"return",
"fmt",
".",
"Sprint",
"(",
"\"",
"\"",
",",
"g",
".",
"varCounter",
")",
"\n",
"}"
] | // uniqueVarName returns a file-unique name that can be used for generated variables. | [
"uniqueVarName",
"returns",
"a",
"file",
"-",
"unique",
"name",
"that",
"can",
"be",
"used",
"for",
"generated",
"variables",
"."
] | 1ea4449da9834f4d333f1cc461c374aea217d249 | https://github.com/mailru/easyjson/blob/1ea4449da9834f4d333f1cc461c374aea217d249/gen/generator.go#L324-L327 | train |
mailru/easyjson | gen/generator.go | lowerFirst | func lowerFirst(s string) string {
if s == "" {
return ""
}
str := ""
strlen := len(s)
/**
Loop each char
If is uppercase:
If is first char, LOWER it
If the following char is lower, LEAVE it
If the following char is upper OR numeric, LOWER it
If is the end of string, LEAVE it
Else ... | go | func lowerFirst(s string) string {
if s == "" {
return ""
}
str := ""
strlen := len(s)
/**
Loop each char
If is uppercase:
If is first char, LOWER it
If the following char is lower, LEAVE it
If the following char is upper OR numeric, LOWER it
If is the end of string, LEAVE it
Else ... | [
"func",
"lowerFirst",
"(",
"s",
"string",
")",
"string",
"{",
"if",
"s",
"==",
"\"",
"\"",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n\n",
"str",
":=",
"\"",
"\"",
"\n",
"strlen",
":=",
"len",
"(",
"s",
")",
"\n\n",
"/**\n\t Loop each char\n\t If is up... | // convert HTTPRestClient to httpRestClient | [
"convert",
"HTTPRestClient",
"to",
"httpRestClient"
] | 1ea4449da9834f4d333f1cc461c374aea217d249 | https://github.com/mailru/easyjson/blob/1ea4449da9834f4d333f1cc461c374aea217d249/gen/generator.go#L408-L451 | train |
mailru/easyjson | gen/encoder.go | parseFieldTags | func parseFieldTags(f reflect.StructField) fieldTags {
var ret fieldTags
for i, s := range strings.Split(f.Tag.Get("json"), ",") {
switch {
case i == 0 && s == "-":
ret.omit = true
case i == 0:
ret.name = s
case s == "omitempty":
ret.omitEmpty = true
case s == "!omitempty":
ret.noOmitEmpty = tr... | go | func parseFieldTags(f reflect.StructField) fieldTags {
var ret fieldTags
for i, s := range strings.Split(f.Tag.Get("json"), ",") {
switch {
case i == 0 && s == "-":
ret.omit = true
case i == 0:
ret.name = s
case s == "omitempty":
ret.omitEmpty = true
case s == "!omitempty":
ret.noOmitEmpty = tr... | [
"func",
"parseFieldTags",
"(",
"f",
"reflect",
".",
"StructField",
")",
"fieldTags",
"{",
"var",
"ret",
"fieldTags",
"\n\n",
"for",
"i",
",",
"s",
":=",
"range",
"strings",
".",
"Split",
"(",
"f",
".",
"Tag",
".",
"Get",
"(",
"\"",
"\"",
")",
",",
... | // parseFieldTags parses the json field tag into a structure. | [
"parseFieldTags",
"parses",
"the",
"json",
"field",
"tag",
"into",
"a",
"structure",
"."
] | 1ea4449da9834f4d333f1cc461c374aea217d249 | https://github.com/mailru/easyjson/blob/1ea4449da9834f4d333f1cc461c374aea217d249/gen/encoder.go#L64-L85 | train |
mailru/easyjson | gen/encoder.go | genTypeEncoder | func (g *Generator) genTypeEncoder(t reflect.Type, in string, tags fieldTags, indent int, assumeNonEmpty bool) error {
ws := strings.Repeat(" ", indent)
marshalerIface := reflect.TypeOf((*easyjson.Marshaler)(nil)).Elem()
if reflect.PtrTo(t).Implements(marshalerIface) {
fmt.Fprintln(g.out, ws+"("+in+").MarshalEas... | go | func (g *Generator) genTypeEncoder(t reflect.Type, in string, tags fieldTags, indent int, assumeNonEmpty bool) error {
ws := strings.Repeat(" ", indent)
marshalerIface := reflect.TypeOf((*easyjson.Marshaler)(nil)).Elem()
if reflect.PtrTo(t).Implements(marshalerIface) {
fmt.Fprintln(g.out, ws+"("+in+").MarshalEas... | [
"func",
"(",
"g",
"*",
"Generator",
")",
"genTypeEncoder",
"(",
"t",
"reflect",
".",
"Type",
",",
"in",
"string",
",",
"tags",
"fieldTags",
",",
"indent",
"int",
",",
"assumeNonEmpty",
"bool",
")",
"error",
"{",
"ws",
":=",
"strings",
".",
"Repeat",
"(... | // genTypeEncoder generates code that encodes in of type t into the writer, but uses marshaler interface if implemented by t. | [
"genTypeEncoder",
"generates",
"code",
"that",
"encodes",
"in",
"of",
"type",
"t",
"into",
"the",
"writer",
"but",
"uses",
"marshaler",
"interface",
"if",
"implemented",
"by",
"t",
"."
] | 1ea4449da9834f4d333f1cc461c374aea217d249 | https://github.com/mailru/easyjson/blob/1ea4449da9834f4d333f1cc461c374aea217d249/gen/encoder.go#L88-L111 | train |
mailru/easyjson | gen/encoder.go | hasCustomMarshaler | func hasCustomMarshaler(t reflect.Type) bool {
t = reflect.PtrTo(t)
return t.Implements(reflect.TypeOf((*easyjson.Marshaler)(nil)).Elem()) ||
t.Implements(reflect.TypeOf((*json.Marshaler)(nil)).Elem()) ||
t.Implements(reflect.TypeOf((*encoding.TextMarshaler)(nil)).Elem())
} | go | func hasCustomMarshaler(t reflect.Type) bool {
t = reflect.PtrTo(t)
return t.Implements(reflect.TypeOf((*easyjson.Marshaler)(nil)).Elem()) ||
t.Implements(reflect.TypeOf((*json.Marshaler)(nil)).Elem()) ||
t.Implements(reflect.TypeOf((*encoding.TextMarshaler)(nil)).Elem())
} | [
"func",
"hasCustomMarshaler",
"(",
"t",
"reflect",
".",
"Type",
")",
"bool",
"{",
"t",
"=",
"reflect",
".",
"PtrTo",
"(",
"t",
")",
"\n",
"return",
"t",
".",
"Implements",
"(",
"reflect",
".",
"TypeOf",
"(",
"(",
"*",
"easyjson",
".",
"Marshaler",
")... | // returns true of the type t implements one of the custom marshaler interfaces | [
"returns",
"true",
"of",
"the",
"type",
"t",
"implements",
"one",
"of",
"the",
"custom",
"marshaler",
"interfaces"
] | 1ea4449da9834f4d333f1cc461c374aea217d249 | https://github.com/mailru/easyjson/blob/1ea4449da9834f4d333f1cc461c374aea217d249/gen/encoder.go#L114-L119 | train |
mailru/easyjson | gen/encoder.go | genTypeEncoderNoCheck | func (g *Generator) genTypeEncoderNoCheck(t reflect.Type, in string, tags fieldTags, indent int, assumeNonEmpty bool) error {
ws := strings.Repeat(" ", indent)
// Check whether type is primitive, needs to be done after interface check.
if enc := primitiveStringEncoders[t.Kind()]; enc != "" && tags.asString {
fmt... | go | func (g *Generator) genTypeEncoderNoCheck(t reflect.Type, in string, tags fieldTags, indent int, assumeNonEmpty bool) error {
ws := strings.Repeat(" ", indent)
// Check whether type is primitive, needs to be done after interface check.
if enc := primitiveStringEncoders[t.Kind()]; enc != "" && tags.asString {
fmt... | [
"func",
"(",
"g",
"*",
"Generator",
")",
"genTypeEncoderNoCheck",
"(",
"t",
"reflect",
".",
"Type",
",",
"in",
"string",
",",
"tags",
"fieldTags",
",",
"indent",
"int",
",",
"assumeNonEmpty",
"bool",
")",
"error",
"{",
"ws",
":=",
"strings",
".",
"Repeat... | // genTypeEncoderNoCheck generates code that encodes in of type t into the writer. | [
"genTypeEncoderNoCheck",
"generates",
"code",
"that",
"encodes",
"in",
"of",
"type",
"t",
"into",
"the",
"writer",
"."
] | 1ea4449da9834f4d333f1cc461c374aea217d249 | https://github.com/mailru/easyjson/blob/1ea4449da9834f4d333f1cc461c374aea217d249/gen/encoder.go#L122-L264 | train |
mailru/easyjson | bootstrap/bootstrap.go | writeMain | func (g *Generator) writeMain() (path string, err error) {
f, err := ioutil.TempFile(filepath.Dir(g.OutName), "easyjson-bootstrap")
if err != nil {
return "", err
}
fmt.Fprintln(f, "// +build ignore")
fmt.Fprintln(f)
fmt.Fprintln(f, "// TEMPORARY AUTOGENERATED FILE: easyjson bootstapping code to launch")
fmt.... | go | func (g *Generator) writeMain() (path string, err error) {
f, err := ioutil.TempFile(filepath.Dir(g.OutName), "easyjson-bootstrap")
if err != nil {
return "", err
}
fmt.Fprintln(f, "// +build ignore")
fmt.Fprintln(f)
fmt.Fprintln(f, "// TEMPORARY AUTOGENERATED FILE: easyjson bootstapping code to launch")
fmt.... | [
"func",
"(",
"g",
"*",
"Generator",
")",
"writeMain",
"(",
")",
"(",
"path",
"string",
",",
"err",
"error",
")",
"{",
"f",
",",
"err",
":=",
"ioutil",
".",
"TempFile",
"(",
"filepath",
".",
"Dir",
"(",
"g",
".",
"OutName",
")",
",",
"\"",
"\"",
... | // writeMain creates a .go file that launches the generator if 'go run'. | [
"writeMain",
"creates",
"a",
".",
"go",
"file",
"that",
"launches",
"the",
"generator",
"if",
"go",
"run",
"."
] | 1ea4449da9834f4d333f1cc461c374aea217d249 | https://github.com/mailru/easyjson/blob/1ea4449da9834f4d333f1cc461c374aea217d249/bootstrap/bootstrap.go#L82-L146 | train |
mailru/easyjson | jwriter/writer.go | DumpTo | func (w *Writer) DumpTo(out io.Writer) (written int, err error) {
return w.Buffer.DumpTo(out)
} | go | func (w *Writer) DumpTo(out io.Writer) (written int, err error) {
return w.Buffer.DumpTo(out)
} | [
"func",
"(",
"w",
"*",
"Writer",
")",
"DumpTo",
"(",
"out",
"io",
".",
"Writer",
")",
"(",
"written",
"int",
",",
"err",
"error",
")",
"{",
"return",
"w",
".",
"Buffer",
".",
"DumpTo",
"(",
"out",
")",
"\n",
"}"
] | // DumpTo outputs the data to given io.Writer, resetting the buffer. | [
"DumpTo",
"outputs",
"the",
"data",
"to",
"given",
"io",
".",
"Writer",
"resetting",
"the",
"buffer",
"."
] | 1ea4449da9834f4d333f1cc461c374aea217d249 | https://github.com/mailru/easyjson/blob/1ea4449da9834f4d333f1cc461c374aea217d249/jwriter/writer.go#L36-L38 | train |
mailru/easyjson | jwriter/writer.go | BuildBytes | func (w *Writer) BuildBytes(reuse ...[]byte) ([]byte, error) {
if w.Error != nil {
return nil, w.Error
}
return w.Buffer.BuildBytes(reuse...), nil
} | go | func (w *Writer) BuildBytes(reuse ...[]byte) ([]byte, error) {
if w.Error != nil {
return nil, w.Error
}
return w.Buffer.BuildBytes(reuse...), nil
} | [
"func",
"(",
"w",
"*",
"Writer",
")",
"BuildBytes",
"(",
"reuse",
"...",
"[",
"]",
"byte",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"if",
"w",
".",
"Error",
"!=",
"nil",
"{",
"return",
"nil",
",",
"w",
".",
"Error",
"\n",
"}",
"\n\... | // BuildBytes returns writer data as a single byte slice. You can optionally provide one byte slice
// as argument that it will try to reuse. | [
"BuildBytes",
"returns",
"writer",
"data",
"as",
"a",
"single",
"byte",
"slice",
".",
"You",
"can",
"optionally",
"provide",
"one",
"byte",
"slice",
"as",
"argument",
"that",
"it",
"will",
"try",
"to",
"reuse",
"."
] | 1ea4449da9834f4d333f1cc461c374aea217d249 | https://github.com/mailru/easyjson/blob/1ea4449da9834f4d333f1cc461c374aea217d249/jwriter/writer.go#L42-L48 | train |
mailru/easyjson | jwriter/writer.go | ReadCloser | func (w *Writer) ReadCloser() (io.ReadCloser, error) {
if w.Error != nil {
return nil, w.Error
}
return w.Buffer.ReadCloser(), nil
} | go | func (w *Writer) ReadCloser() (io.ReadCloser, error) {
if w.Error != nil {
return nil, w.Error
}
return w.Buffer.ReadCloser(), nil
} | [
"func",
"(",
"w",
"*",
"Writer",
")",
"ReadCloser",
"(",
")",
"(",
"io",
".",
"ReadCloser",
",",
"error",
")",
"{",
"if",
"w",
".",
"Error",
"!=",
"nil",
"{",
"return",
"nil",
",",
"w",
".",
"Error",
"\n",
"}",
"\n\n",
"return",
"w",
".",
"Buff... | // ReadCloser returns an io.ReadCloser that can be used to read the data.
// ReadCloser also resets the buffer. | [
"ReadCloser",
"returns",
"an",
"io",
".",
"ReadCloser",
"that",
"can",
"be",
"used",
"to",
"read",
"the",
"data",
".",
"ReadCloser",
"also",
"resets",
"the",
"buffer",
"."
] | 1ea4449da9834f4d333f1cc461c374aea217d249 | https://github.com/mailru/easyjson/blob/1ea4449da9834f4d333f1cc461c374aea217d249/jwriter/writer.go#L52-L58 | train |
mailru/easyjson | jwriter/writer.go | Raw | func (w *Writer) Raw(data []byte, err error) {
switch {
case w.Error != nil:
return
case err != nil:
w.Error = err
case len(data) > 0:
w.Buffer.AppendBytes(data)
default:
w.RawString("null")
}
} | go | func (w *Writer) Raw(data []byte, err error) {
switch {
case w.Error != nil:
return
case err != nil:
w.Error = err
case len(data) > 0:
w.Buffer.AppendBytes(data)
default:
w.RawString("null")
}
} | [
"func",
"(",
"w",
"*",
"Writer",
")",
"Raw",
"(",
"data",
"[",
"]",
"byte",
",",
"err",
"error",
")",
"{",
"switch",
"{",
"case",
"w",
".",
"Error",
"!=",
"nil",
":",
"return",
"\n",
"case",
"err",
"!=",
"nil",
":",
"w",
".",
"Error",
"=",
"e... | // Raw appends raw binary data to the buffer or sets the error if it is given. Useful for
// calling with results of MarshalJSON-like functions. | [
"Raw",
"appends",
"raw",
"binary",
"data",
"to",
"the",
"buffer",
"or",
"sets",
"the",
"error",
"if",
"it",
"is",
"given",
".",
"Useful",
"for",
"calling",
"with",
"results",
"of",
"MarshalJSON",
"-",
"like",
"functions",
"."
] | 1ea4449da9834f4d333f1cc461c374aea217d249 | https://github.com/mailru/easyjson/blob/1ea4449da9834f4d333f1cc461c374aea217d249/jwriter/writer.go#L72-L83 | train |
mailru/easyjson | jwriter/writer.go | RawText | func (w *Writer) RawText(data []byte, err error) {
switch {
case w.Error != nil:
return
case err != nil:
w.Error = err
case len(data) > 0:
w.String(string(data))
default:
w.RawString("null")
}
} | go | func (w *Writer) RawText(data []byte, err error) {
switch {
case w.Error != nil:
return
case err != nil:
w.Error = err
case len(data) > 0:
w.String(string(data))
default:
w.RawString("null")
}
} | [
"func",
"(",
"w",
"*",
"Writer",
")",
"RawText",
"(",
"data",
"[",
"]",
"byte",
",",
"err",
"error",
")",
"{",
"switch",
"{",
"case",
"w",
".",
"Error",
"!=",
"nil",
":",
"return",
"\n",
"case",
"err",
"!=",
"nil",
":",
"w",
".",
"Error",
"=",
... | // RawText encloses raw binary data in quotes and appends in to the buffer.
// Useful for calling with results of MarshalText-like functions. | [
"RawText",
"encloses",
"raw",
"binary",
"data",
"in",
"quotes",
"and",
"appends",
"in",
"to",
"the",
"buffer",
".",
"Useful",
"for",
"calling",
"with",
"results",
"of",
"MarshalText",
"-",
"like",
"functions",
"."
] | 1ea4449da9834f4d333f1cc461c374aea217d249 | https://github.com/mailru/easyjson/blob/1ea4449da9834f4d333f1cc461c374aea217d249/jwriter/writer.go#L87-L98 | train |
mailru/easyjson | jwriter/writer.go | Base64Bytes | func (w *Writer) Base64Bytes(data []byte) {
if data == nil {
w.Buffer.AppendString("null")
return
}
w.Buffer.AppendByte('"')
w.base64(data)
w.Buffer.AppendByte('"')
} | go | func (w *Writer) Base64Bytes(data []byte) {
if data == nil {
w.Buffer.AppendString("null")
return
}
w.Buffer.AppendByte('"')
w.base64(data)
w.Buffer.AppendByte('"')
} | [
"func",
"(",
"w",
"*",
"Writer",
")",
"Base64Bytes",
"(",
"data",
"[",
"]",
"byte",
")",
"{",
"if",
"data",
"==",
"nil",
"{",
"w",
".",
"Buffer",
".",
"AppendString",
"(",
"\"",
"\"",
")",
"\n",
"return",
"\n",
"}",
"\n",
"w",
".",
"Buffer",
".... | // Base64Bytes appends data to the buffer after base64 encoding it | [
"Base64Bytes",
"appends",
"data",
"to",
"the",
"buffer",
"after",
"base64",
"encoding",
"it"
] | 1ea4449da9834f4d333f1cc461c374aea217d249 | https://github.com/mailru/easyjson/blob/1ea4449da9834f4d333f1cc461c374aea217d249/jwriter/writer.go#L101-L109 | train |
mailru/easyjson | parser/pkgpath.go | goModPath | func goModPath(fname string, isDir bool) (string, error) {
root := fname
if !isDir {
root = filepath.Dir(fname)
}
goModPathCache.RLock()
goModPath, ok := goModPathCache.paths[root]
goModPathCache.RUnlock()
if ok {
return goModPath, nil
}
defer func() {
goModPathCache.Lock()
goModPathCache.paths[root]... | go | func goModPath(fname string, isDir bool) (string, error) {
root := fname
if !isDir {
root = filepath.Dir(fname)
}
goModPathCache.RLock()
goModPath, ok := goModPathCache.paths[root]
goModPathCache.RUnlock()
if ok {
return goModPath, nil
}
defer func() {
goModPathCache.Lock()
goModPathCache.paths[root]... | [
"func",
"goModPath",
"(",
"fname",
"string",
",",
"isDir",
"bool",
")",
"(",
"string",
",",
"error",
")",
"{",
"root",
":=",
"fname",
"\n",
"if",
"!",
"isDir",
"{",
"root",
"=",
"filepath",
".",
"Dir",
"(",
"fname",
")",
"\n",
"}",
"\n\n",
"goModPa... | // empty if no go.mod, GO111MODULE=off or go without go modules support | [
"empty",
"if",
"no",
"go",
".",
"mod",
"GO111MODULE",
"=",
"off",
"or",
"go",
"without",
"go",
"modules",
"support"
] | 1ea4449da9834f4d333f1cc461c374aea217d249 | https://github.com/mailru/easyjson/blob/1ea4449da9834f4d333f1cc461c374aea217d249/parser/pkgpath.go#L46-L76 | train |
mailru/easyjson | buffer/pool.go | putBuf | func putBuf(buf []byte) {
size := cap(buf)
if size < config.PooledSize {
return
}
if c := buffers[size]; c != nil {
c.Put(buf[:0])
}
} | go | func putBuf(buf []byte) {
size := cap(buf)
if size < config.PooledSize {
return
}
if c := buffers[size]; c != nil {
c.Put(buf[:0])
}
} | [
"func",
"putBuf",
"(",
"buf",
"[",
"]",
"byte",
")",
"{",
"size",
":=",
"cap",
"(",
"buf",
")",
"\n",
"if",
"size",
"<",
"config",
".",
"PooledSize",
"{",
"return",
"\n",
"}",
"\n",
"if",
"c",
":=",
"buffers",
"[",
"size",
"]",
";",
"c",
"!=",
... | // putBuf puts a chunk to reuse pool if it can be reused. | [
"putBuf",
"puts",
"a",
"chunk",
"to",
"reuse",
"pool",
"if",
"it",
"can",
"be",
"reused",
"."
] | 1ea4449da9834f4d333f1cc461c374aea217d249 | https://github.com/mailru/easyjson/blob/1ea4449da9834f4d333f1cc461c374aea217d249/buffer/pool.go#L43-L51 | train |
mailru/easyjson | buffer/pool.go | getBuf | func getBuf(size int) []byte {
if size < config.PooledSize {
return make([]byte, 0, size)
}
if c := buffers[size]; c != nil {
v := c.Get()
if v != nil {
return v.([]byte)
}
}
return make([]byte, 0, size)
} | go | func getBuf(size int) []byte {
if size < config.PooledSize {
return make([]byte, 0, size)
}
if c := buffers[size]; c != nil {
v := c.Get()
if v != nil {
return v.([]byte)
}
}
return make([]byte, 0, size)
} | [
"func",
"getBuf",
"(",
"size",
"int",
")",
"[",
"]",
"byte",
"{",
"if",
"size",
"<",
"config",
".",
"PooledSize",
"{",
"return",
"make",
"(",
"[",
"]",
"byte",
",",
"0",
",",
"size",
")",
"\n",
"}",
"\n\n",
"if",
"c",
":=",
"buffers",
"[",
"siz... | // getBuf gets a chunk from reuse pool or creates a new one if reuse failed. | [
"getBuf",
"gets",
"a",
"chunk",
"from",
"reuse",
"pool",
"or",
"creates",
"a",
"new",
"one",
"if",
"reuse",
"failed",
"."
] | 1ea4449da9834f4d333f1cc461c374aea217d249 | https://github.com/mailru/easyjson/blob/1ea4449da9834f4d333f1cc461c374aea217d249/buffer/pool.go#L54-L66 | train |
mailru/easyjson | buffer/pool.go | EnsureSpace | func (b *Buffer) EnsureSpace(s int) {
if cap(b.Buf)-len(b.Buf) >= s {
return
}
l := len(b.Buf)
if l > 0 {
if cap(b.toPool) != cap(b.Buf) {
// Chunk was reallocated, toPool can be pooled.
putBuf(b.toPool)
}
if cap(b.bufs) == 0 {
b.bufs = make([][]byte, 0, 8)
}
b.bufs = append(b.bufs, b.Buf)
l ... | go | func (b *Buffer) EnsureSpace(s int) {
if cap(b.Buf)-len(b.Buf) >= s {
return
}
l := len(b.Buf)
if l > 0 {
if cap(b.toPool) != cap(b.Buf) {
// Chunk was reallocated, toPool can be pooled.
putBuf(b.toPool)
}
if cap(b.bufs) == 0 {
b.bufs = make([][]byte, 0, 8)
}
b.bufs = append(b.bufs, b.Buf)
l ... | [
"func",
"(",
"b",
"*",
"Buffer",
")",
"EnsureSpace",
"(",
"s",
"int",
")",
"{",
"if",
"cap",
"(",
"b",
".",
"Buf",
")",
"-",
"len",
"(",
"b",
".",
"Buf",
")",
">=",
"s",
"{",
"return",
"\n",
"}",
"\n",
"l",
":=",
"len",
"(",
"b",
".",
"Bu... | // EnsureSpace makes sure that the current chunk contains at least s free bytes,
// possibly creating a new chunk. | [
"EnsureSpace",
"makes",
"sure",
"that",
"the",
"current",
"chunk",
"contains",
"at",
"least",
"s",
"free",
"bytes",
"possibly",
"creating",
"a",
"new",
"chunk",
"."
] | 1ea4449da9834f4d333f1cc461c374aea217d249 | https://github.com/mailru/easyjson/blob/1ea4449da9834f4d333f1cc461c374aea217d249/buffer/pool.go#L80-L104 | train |
mailru/easyjson | buffer/pool.go | AppendByte | func (b *Buffer) AppendByte(data byte) {
if cap(b.Buf) == len(b.Buf) { // EnsureSpace won't be inlined.
b.EnsureSpace(1)
}
b.Buf = append(b.Buf, data)
} | go | func (b *Buffer) AppendByte(data byte) {
if cap(b.Buf) == len(b.Buf) { // EnsureSpace won't be inlined.
b.EnsureSpace(1)
}
b.Buf = append(b.Buf, data)
} | [
"func",
"(",
"b",
"*",
"Buffer",
")",
"AppendByte",
"(",
"data",
"byte",
")",
"{",
"if",
"cap",
"(",
"b",
".",
"Buf",
")",
"==",
"len",
"(",
"b",
".",
"Buf",
")",
"{",
"// EnsureSpace won't be inlined.",
"b",
".",
"EnsureSpace",
"(",
"1",
")",
"\n"... | // AppendByte appends a single byte to buffer. | [
"AppendByte",
"appends",
"a",
"single",
"byte",
"to",
"buffer",
"."
] | 1ea4449da9834f4d333f1cc461c374aea217d249 | https://github.com/mailru/easyjson/blob/1ea4449da9834f4d333f1cc461c374aea217d249/buffer/pool.go#L107-L112 | train |
mailru/easyjson | buffer/pool.go | AppendBytes | func (b *Buffer) AppendBytes(data []byte) {
for len(data) > 0 {
if cap(b.Buf) == len(b.Buf) { // EnsureSpace won't be inlined.
b.EnsureSpace(1)
}
sz := cap(b.Buf) - len(b.Buf)
if sz > len(data) {
sz = len(data)
}
b.Buf = append(b.Buf, data[:sz]...)
data = data[sz:]
}
} | go | func (b *Buffer) AppendBytes(data []byte) {
for len(data) > 0 {
if cap(b.Buf) == len(b.Buf) { // EnsureSpace won't be inlined.
b.EnsureSpace(1)
}
sz := cap(b.Buf) - len(b.Buf)
if sz > len(data) {
sz = len(data)
}
b.Buf = append(b.Buf, data[:sz]...)
data = data[sz:]
}
} | [
"func",
"(",
"b",
"*",
"Buffer",
")",
"AppendBytes",
"(",
"data",
"[",
"]",
"byte",
")",
"{",
"for",
"len",
"(",
"data",
")",
">",
"0",
"{",
"if",
"cap",
"(",
"b",
".",
"Buf",
")",
"==",
"len",
"(",
"b",
".",
"Buf",
")",
"{",
"// EnsureSpace ... | // AppendBytes appends a byte slice to buffer. | [
"AppendBytes",
"appends",
"a",
"byte",
"slice",
"to",
"buffer",
"."
] | 1ea4449da9834f4d333f1cc461c374aea217d249 | https://github.com/mailru/easyjson/blob/1ea4449da9834f4d333f1cc461c374aea217d249/buffer/pool.go#L115-L129 | train |
mailru/easyjson | buffer/pool.go | AppendString | func (b *Buffer) AppendString(data string) {
for len(data) > 0 {
if cap(b.Buf) == len(b.Buf) { // EnsureSpace won't be inlined.
b.EnsureSpace(1)
}
sz := cap(b.Buf) - len(b.Buf)
if sz > len(data) {
sz = len(data)
}
b.Buf = append(b.Buf, data[:sz]...)
data = data[sz:]
}
} | go | func (b *Buffer) AppendString(data string) {
for len(data) > 0 {
if cap(b.Buf) == len(b.Buf) { // EnsureSpace won't be inlined.
b.EnsureSpace(1)
}
sz := cap(b.Buf) - len(b.Buf)
if sz > len(data) {
sz = len(data)
}
b.Buf = append(b.Buf, data[:sz]...)
data = data[sz:]
}
} | [
"func",
"(",
"b",
"*",
"Buffer",
")",
"AppendString",
"(",
"data",
"string",
")",
"{",
"for",
"len",
"(",
"data",
")",
">",
"0",
"{",
"if",
"cap",
"(",
"b",
".",
"Buf",
")",
"==",
"len",
"(",
"b",
".",
"Buf",
")",
"{",
"// EnsureSpace won't be in... | // AppendBytes appends a string to buffer. | [
"AppendBytes",
"appends",
"a",
"string",
"to",
"buffer",
"."
] | 1ea4449da9834f4d333f1cc461c374aea217d249 | https://github.com/mailru/easyjson/blob/1ea4449da9834f4d333f1cc461c374aea217d249/buffer/pool.go#L132-L146 | train |
mailru/easyjson | buffer/pool.go | Size | func (b *Buffer) Size() int {
size := len(b.Buf)
for _, buf := range b.bufs {
size += len(buf)
}
return size
} | go | func (b *Buffer) Size() int {
size := len(b.Buf)
for _, buf := range b.bufs {
size += len(buf)
}
return size
} | [
"func",
"(",
"b",
"*",
"Buffer",
")",
"Size",
"(",
")",
"int",
"{",
"size",
":=",
"len",
"(",
"b",
".",
"Buf",
")",
"\n",
"for",
"_",
",",
"buf",
":=",
"range",
"b",
".",
"bufs",
"{",
"size",
"+=",
"len",
"(",
"buf",
")",
"\n",
"}",
"\n",
... | // Size computes the size of a buffer by adding sizes of every chunk. | [
"Size",
"computes",
"the",
"size",
"of",
"a",
"buffer",
"by",
"adding",
"sizes",
"of",
"every",
"chunk",
"."
] | 1ea4449da9834f4d333f1cc461c374aea217d249 | https://github.com/mailru/easyjson/blob/1ea4449da9834f4d333f1cc461c374aea217d249/buffer/pool.go#L149-L155 | train |
mailru/easyjson | buffer/pool.go | DumpTo | func (b *Buffer) DumpTo(w io.Writer) (written int, err error) {
var n int
for _, buf := range b.bufs {
if err == nil {
n, err = w.Write(buf)
written += n
}
putBuf(buf)
}
if err == nil {
n, err = w.Write(b.Buf)
written += n
}
putBuf(b.toPool)
b.bufs = nil
b.Buf = nil
b.toPool = nil
return
} | go | func (b *Buffer) DumpTo(w io.Writer) (written int, err error) {
var n int
for _, buf := range b.bufs {
if err == nil {
n, err = w.Write(buf)
written += n
}
putBuf(buf)
}
if err == nil {
n, err = w.Write(b.Buf)
written += n
}
putBuf(b.toPool)
b.bufs = nil
b.Buf = nil
b.toPool = nil
return
} | [
"func",
"(",
"b",
"*",
"Buffer",
")",
"DumpTo",
"(",
"w",
"io",
".",
"Writer",
")",
"(",
"written",
"int",
",",
"err",
"error",
")",
"{",
"var",
"n",
"int",
"\n",
"for",
"_",
",",
"buf",
":=",
"range",
"b",
".",
"bufs",
"{",
"if",
"err",
"=="... | // DumpTo outputs the contents of a buffer to a writer and resets the buffer. | [
"DumpTo",
"outputs",
"the",
"contents",
"of",
"a",
"buffer",
"to",
"a",
"writer",
"and",
"resets",
"the",
"buffer",
"."
] | 1ea4449da9834f4d333f1cc461c374aea217d249 | https://github.com/mailru/easyjson/blob/1ea4449da9834f4d333f1cc461c374aea217d249/buffer/pool.go#L158-L179 | train |
mailru/easyjson | buffer/pool.go | BuildBytes | func (b *Buffer) BuildBytes(reuse ...[]byte) []byte {
if len(b.bufs) == 0 {
ret := b.Buf
b.toPool = nil
b.Buf = nil
return ret
}
var ret []byte
size := b.Size()
// If we got a buffer as argument and it is big enought, reuse it.
if len(reuse) == 1 && cap(reuse[0]) >= size {
ret = reuse[0][:0]
} else {... | go | func (b *Buffer) BuildBytes(reuse ...[]byte) []byte {
if len(b.bufs) == 0 {
ret := b.Buf
b.toPool = nil
b.Buf = nil
return ret
}
var ret []byte
size := b.Size()
// If we got a buffer as argument and it is big enought, reuse it.
if len(reuse) == 1 && cap(reuse[0]) >= size {
ret = reuse[0][:0]
} else {... | [
"func",
"(",
"b",
"*",
"Buffer",
")",
"BuildBytes",
"(",
"reuse",
"...",
"[",
"]",
"byte",
")",
"[",
"]",
"byte",
"{",
"if",
"len",
"(",
"b",
".",
"bufs",
")",
"==",
"0",
"{",
"ret",
":=",
"b",
".",
"Buf",
"\n",
"b",
".",
"toPool",
"=",
"ni... | // BuildBytes creates a single byte slice with all the contents of the buffer. Data is
// copied if it does not fit in a single chunk. You can optionally provide one byte
// slice as argument that it will try to reuse. | [
"BuildBytes",
"creates",
"a",
"single",
"byte",
"slice",
"with",
"all",
"the",
"contents",
"of",
"the",
"buffer",
".",
"Data",
"is",
"copied",
"if",
"it",
"does",
"not",
"fit",
"in",
"a",
"single",
"chunk",
".",
"You",
"can",
"optionally",
"provide",
"on... | 1ea4449da9834f4d333f1cc461c374aea217d249 | https://github.com/mailru/easyjson/blob/1ea4449da9834f4d333f1cc461c374aea217d249/buffer/pool.go#L184-L214 | train |
mailru/easyjson | buffer/pool.go | ReadCloser | func (b *Buffer) ReadCloser() io.ReadCloser {
ret := &readCloser{0, append(b.bufs, b.Buf)}
b.bufs = nil
b.toPool = nil
b.Buf = nil
return ret
} | go | func (b *Buffer) ReadCloser() io.ReadCloser {
ret := &readCloser{0, append(b.bufs, b.Buf)}
b.bufs = nil
b.toPool = nil
b.Buf = nil
return ret
} | [
"func",
"(",
"b",
"*",
"Buffer",
")",
"ReadCloser",
"(",
")",
"io",
".",
"ReadCloser",
"{",
"ret",
":=",
"&",
"readCloser",
"{",
"0",
",",
"append",
"(",
"b",
".",
"bufs",
",",
"b",
".",
"Buf",
")",
"}",
"\n\n",
"b",
".",
"bufs",
"=",
"nil",
... | // ReadCloser creates an io.ReadCloser with all the contents of the buffer. | [
"ReadCloser",
"creates",
"an",
"io",
".",
"ReadCloser",
"with",
"all",
"the",
"contents",
"of",
"the",
"buffer",
"."
] | 1ea4449da9834f4d333f1cc461c374aea217d249 | https://github.com/mailru/easyjson/blob/1ea4449da9834f4d333f1cc461c374aea217d249/buffer/pool.go#L262-L270 | train |
mailru/easyjson | jlexer/lexer.go | FetchToken | func (r *Lexer) FetchToken() {
r.token.kind = tokenUndef
r.start = r.pos
// Check if r.Data has r.pos element
// If it doesn't, it mean corrupted input data
if len(r.Data) < r.pos {
r.errParse("Unexpected end of data")
return
}
// Determine the type of a token by skipping whitespace and reading the
// firs... | go | func (r *Lexer) FetchToken() {
r.token.kind = tokenUndef
r.start = r.pos
// Check if r.Data has r.pos element
// If it doesn't, it mean corrupted input data
if len(r.Data) < r.pos {
r.errParse("Unexpected end of data")
return
}
// Determine the type of a token by skipping whitespace and reading the
// firs... | [
"func",
"(",
"r",
"*",
"Lexer",
")",
"FetchToken",
"(",
")",
"{",
"r",
".",
"token",
".",
"kind",
"=",
"tokenUndef",
"\n",
"r",
".",
"start",
"=",
"r",
".",
"pos",
"\n\n",
"// Check if r.Data has r.pos element",
"// If it doesn't, it mean corrupted input data",
... | // FetchToken scans the input for the next token. | [
"FetchToken",
"scans",
"the",
"input",
"for",
"the",
"next",
"token",
"."
] | 1ea4449da9834f4d333f1cc461c374aea217d249 | https://github.com/mailru/easyjson/blob/1ea4449da9834f4d333f1cc461c374aea217d249/jlexer/lexer.go#L57-L157 | train |
mailru/easyjson | jlexer/lexer.go | isTokenEnd | func isTokenEnd(c byte) bool {
return c == ' ' || c == '\t' || c == '\r' || c == '\n' || c == '[' || c == ']' || c == '{' || c == '}' || c == ',' || c == ':'
} | go | func isTokenEnd(c byte) bool {
return c == ' ' || c == '\t' || c == '\r' || c == '\n' || c == '[' || c == ']' || c == '{' || c == '}' || c == ',' || c == ':'
} | [
"func",
"isTokenEnd",
"(",
"c",
"byte",
")",
"bool",
"{",
"return",
"c",
"==",
"' '",
"||",
"c",
"==",
"'\\t'",
"||",
"c",
"==",
"'\\r'",
"||",
"c",
"==",
"'\\n'",
"||",
"c",
"==",
"'['",
"||",
"c",
"==",
"']'",
"||",
"c",
"==",
"'{'",
"||",
... | // isTokenEnd returns true if the char can follow a non-delimiter token | [
"isTokenEnd",
"returns",
"true",
"if",
"the",
"char",
"can",
"follow",
"a",
"non",
"-",
"delimiter",
"token"
] | 1ea4449da9834f4d333f1cc461c374aea217d249 | https://github.com/mailru/easyjson/blob/1ea4449da9834f4d333f1cc461c374aea217d249/jlexer/lexer.go#L160-L162 | train |
mailru/easyjson | jlexer/lexer.go | fetchNull | func (r *Lexer) fetchNull() {
r.pos += 4
if r.pos > len(r.Data) ||
r.Data[r.pos-3] != 'u' ||
r.Data[r.pos-2] != 'l' ||
r.Data[r.pos-1] != 'l' ||
(r.pos != len(r.Data) && !isTokenEnd(r.Data[r.pos])) {
r.pos -= 4
r.errSyntax()
}
} | go | func (r *Lexer) fetchNull() {
r.pos += 4
if r.pos > len(r.Data) ||
r.Data[r.pos-3] != 'u' ||
r.Data[r.pos-2] != 'l' ||
r.Data[r.pos-1] != 'l' ||
(r.pos != len(r.Data) && !isTokenEnd(r.Data[r.pos])) {
r.pos -= 4
r.errSyntax()
}
} | [
"func",
"(",
"r",
"*",
"Lexer",
")",
"fetchNull",
"(",
")",
"{",
"r",
".",
"pos",
"+=",
"4",
"\n",
"if",
"r",
".",
"pos",
">",
"len",
"(",
"r",
".",
"Data",
")",
"||",
"r",
".",
"Data",
"[",
"r",
".",
"pos",
"-",
"3",
"]",
"!=",
"'u'",
... | // fetchNull fetches and checks remaining bytes of null keyword. | [
"fetchNull",
"fetches",
"and",
"checks",
"remaining",
"bytes",
"of",
"null",
"keyword",
"."
] | 1ea4449da9834f4d333f1cc461c374aea217d249 | https://github.com/mailru/easyjson/blob/1ea4449da9834f4d333f1cc461c374aea217d249/jlexer/lexer.go#L165-L176 | train |
mailru/easyjson | jlexer/lexer.go | fetchTrue | func (r *Lexer) fetchTrue() {
r.pos += 4
if r.pos > len(r.Data) ||
r.Data[r.pos-3] != 'r' ||
r.Data[r.pos-2] != 'u' ||
r.Data[r.pos-1] != 'e' ||
(r.pos != len(r.Data) && !isTokenEnd(r.Data[r.pos])) {
r.pos -= 4
r.errSyntax()
}
} | go | func (r *Lexer) fetchTrue() {
r.pos += 4
if r.pos > len(r.Data) ||
r.Data[r.pos-3] != 'r' ||
r.Data[r.pos-2] != 'u' ||
r.Data[r.pos-1] != 'e' ||
(r.pos != len(r.Data) && !isTokenEnd(r.Data[r.pos])) {
r.pos -= 4
r.errSyntax()
}
} | [
"func",
"(",
"r",
"*",
"Lexer",
")",
"fetchTrue",
"(",
")",
"{",
"r",
".",
"pos",
"+=",
"4",
"\n",
"if",
"r",
".",
"pos",
">",
"len",
"(",
"r",
".",
"Data",
")",
"||",
"r",
".",
"Data",
"[",
"r",
".",
"pos",
"-",
"3",
"]",
"!=",
"'r'",
... | // fetchTrue fetches and checks remaining bytes of true keyword. | [
"fetchTrue",
"fetches",
"and",
"checks",
"remaining",
"bytes",
"of",
"true",
"keyword",
"."
] | 1ea4449da9834f4d333f1cc461c374aea217d249 | https://github.com/mailru/easyjson/blob/1ea4449da9834f4d333f1cc461c374aea217d249/jlexer/lexer.go#L179-L190 | train |
mailru/easyjson | jlexer/lexer.go | fetchFalse | func (r *Lexer) fetchFalse() {
r.pos += 5
if r.pos > len(r.Data) ||
r.Data[r.pos-4] != 'a' ||
r.Data[r.pos-3] != 'l' ||
r.Data[r.pos-2] != 's' ||
r.Data[r.pos-1] != 'e' ||
(r.pos != len(r.Data) && !isTokenEnd(r.Data[r.pos])) {
r.pos -= 5
r.errSyntax()
}
} | go | func (r *Lexer) fetchFalse() {
r.pos += 5
if r.pos > len(r.Data) ||
r.Data[r.pos-4] != 'a' ||
r.Data[r.pos-3] != 'l' ||
r.Data[r.pos-2] != 's' ||
r.Data[r.pos-1] != 'e' ||
(r.pos != len(r.Data) && !isTokenEnd(r.Data[r.pos])) {
r.pos -= 5
r.errSyntax()
}
} | [
"func",
"(",
"r",
"*",
"Lexer",
")",
"fetchFalse",
"(",
")",
"{",
"r",
".",
"pos",
"+=",
"5",
"\n",
"if",
"r",
".",
"pos",
">",
"len",
"(",
"r",
".",
"Data",
")",
"||",
"r",
".",
"Data",
"[",
"r",
".",
"pos",
"-",
"4",
"]",
"!=",
"'a'",
... | // fetchFalse fetches and checks remaining bytes of false keyword. | [
"fetchFalse",
"fetches",
"and",
"checks",
"remaining",
"bytes",
"of",
"false",
"keyword",
"."
] | 1ea4449da9834f4d333f1cc461c374aea217d249 | https://github.com/mailru/easyjson/blob/1ea4449da9834f4d333f1cc461c374aea217d249/jlexer/lexer.go#L193-L205 | train |
mailru/easyjson | jlexer/lexer.go | fetchNumber | func (r *Lexer) fetchNumber() {
hasE := false
afterE := false
hasDot := false
r.pos++
for i, c := range r.Data[r.pos:] {
switch {
case c >= '0' && c <= '9':
afterE = false
case c == '.' && !hasDot:
hasDot = true
case (c == 'e' || c == 'E') && !hasE:
hasE = true
hasDot = true
afterE = true
... | go | func (r *Lexer) fetchNumber() {
hasE := false
afterE := false
hasDot := false
r.pos++
for i, c := range r.Data[r.pos:] {
switch {
case c >= '0' && c <= '9':
afterE = false
case c == '.' && !hasDot:
hasDot = true
case (c == 'e' || c == 'E') && !hasE:
hasE = true
hasDot = true
afterE = true
... | [
"func",
"(",
"r",
"*",
"Lexer",
")",
"fetchNumber",
"(",
")",
"{",
"hasE",
":=",
"false",
"\n",
"afterE",
":=",
"false",
"\n",
"hasDot",
":=",
"false",
"\n\n",
"r",
".",
"pos",
"++",
"\n",
"for",
"i",
",",
"c",
":=",
"range",
"r",
".",
"Data",
... | // fetchNumber scans a number literal token. | [
"fetchNumber",
"scans",
"a",
"number",
"literal",
"token",
"."
] | 1ea4449da9834f4d333f1cc461c374aea217d249 | https://github.com/mailru/easyjson/blob/1ea4449da9834f4d333f1cc461c374aea217d249/jlexer/lexer.go#L208-L239 | train |
mailru/easyjson | jlexer/lexer.go | findStringLen | func findStringLen(data []byte) (isValid, hasEscapes bool, length int) {
delta := 0
for i := 0; i < len(data); i++ {
switch data[i] {
case '\\':
i++
delta++
if i < len(data) && data[i] == 'u' {
delta++
}
case '"':
return true, (delta > 0), (i - delta)
}
}
return false, false, len(data)
... | go | func findStringLen(data []byte) (isValid, hasEscapes bool, length int) {
delta := 0
for i := 0; i < len(data); i++ {
switch data[i] {
case '\\':
i++
delta++
if i < len(data) && data[i] == 'u' {
delta++
}
case '"':
return true, (delta > 0), (i - delta)
}
}
return false, false, len(data)
... | [
"func",
"findStringLen",
"(",
"data",
"[",
"]",
"byte",
")",
"(",
"isValid",
",",
"hasEscapes",
"bool",
",",
"length",
"int",
")",
"{",
"delta",
":=",
"0",
"\n\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"len",
"(",
"data",
")",
";",
"i",
"++",
"... | // findStringLen tries to scan into the string literal for ending quote char to determine required size.
// The size will be exact if no escapes are present and may be inexact if there are escaped chars. | [
"findStringLen",
"tries",
"to",
"scan",
"into",
"the",
"string",
"literal",
"for",
"ending",
"quote",
"char",
"to",
"determine",
"required",
"size",
".",
"The",
"size",
"will",
"be",
"exact",
"if",
"no",
"escapes",
"are",
"present",
"and",
"may",
"be",
"in... | 1ea4449da9834f4d333f1cc461c374aea217d249 | https://github.com/mailru/easyjson/blob/1ea4449da9834f4d333f1cc461c374aea217d249/jlexer/lexer.go#L243-L260 | train |
mailru/easyjson | jlexer/lexer.go | processEscape | func (r *Lexer) processEscape(data []byte) (int, error) {
if len(data) < 2 {
return 0, fmt.Errorf("syntax error at %v", string(data))
}
c := data[1]
switch c {
case '"', '/', '\\':
r.token.byteValue = append(r.token.byteValue, c)
return 2, nil
case 'b':
r.token.byteValue = append(r.token.byteValue, '\b')... | go | func (r *Lexer) processEscape(data []byte) (int, error) {
if len(data) < 2 {
return 0, fmt.Errorf("syntax error at %v", string(data))
}
c := data[1]
switch c {
case '"', '/', '\\':
r.token.byteValue = append(r.token.byteValue, c)
return 2, nil
case 'b':
r.token.byteValue = append(r.token.byteValue, '\b')... | [
"func",
"(",
"r",
"*",
"Lexer",
")",
"processEscape",
"(",
"data",
"[",
"]",
"byte",
")",
"(",
"int",
",",
"error",
")",
"{",
"if",
"len",
"(",
"data",
")",
"<",
"2",
"{",
"return",
"0",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"strin... | // processEscape processes a single escape sequence and returns number of bytes processed. | [
"processEscape",
"processes",
"a",
"single",
"escape",
"sequence",
"and",
"returns",
"number",
"of",
"bytes",
"processed",
"."
] | 1ea4449da9834f4d333f1cc461c374aea217d249 | https://github.com/mailru/easyjson/blob/1ea4449da9834f4d333f1cc461c374aea217d249/jlexer/lexer.go#L290-L338 | train |
mailru/easyjson | jlexer/lexer.go | fetchString | func (r *Lexer) fetchString() {
r.pos++
data := r.Data[r.pos:]
isValid, hasEscapes, length := findStringLen(data)
if !isValid {
r.pos += length
r.errParse("unterminated string literal")
return
}
if !hasEscapes {
r.token.byteValue = data[:length]
r.pos += length + 1
return
}
r.token.byteValue = mak... | go | func (r *Lexer) fetchString() {
r.pos++
data := r.Data[r.pos:]
isValid, hasEscapes, length := findStringLen(data)
if !isValid {
r.pos += length
r.errParse("unterminated string literal")
return
}
if !hasEscapes {
r.token.byteValue = data[:length]
r.pos += length + 1
return
}
r.token.byteValue = mak... | [
"func",
"(",
"r",
"*",
"Lexer",
")",
"fetchString",
"(",
")",
"{",
"r",
".",
"pos",
"++",
"\n",
"data",
":=",
"r",
".",
"Data",
"[",
"r",
".",
"pos",
":",
"]",
"\n\n",
"isValid",
",",
"hasEscapes",
",",
"length",
":=",
"findStringLen",
"(",
"data... | // fetchString scans a string literal token. | [
"fetchString",
"scans",
"a",
"string",
"literal",
"token",
"."
] | 1ea4449da9834f4d333f1cc461c374aea217d249 | https://github.com/mailru/easyjson/blob/1ea4449da9834f4d333f1cc461c374aea217d249/jlexer/lexer.go#L341-L382 | train |
mailru/easyjson | jlexer/lexer.go | scanToken | func (r *Lexer) scanToken() {
if r.token.kind != tokenUndef || r.fatalError != nil {
return
}
r.FetchToken()
} | go | func (r *Lexer) scanToken() {
if r.token.kind != tokenUndef || r.fatalError != nil {
return
}
r.FetchToken()
} | [
"func",
"(",
"r",
"*",
"Lexer",
")",
"scanToken",
"(",
")",
"{",
"if",
"r",
".",
"token",
".",
"kind",
"!=",
"tokenUndef",
"||",
"r",
".",
"fatalError",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"r",
".",
"FetchToken",
"(",
")",
"\n",
"}"
] | // scanToken scans the next token if no token is currently available in the lexer. | [
"scanToken",
"scans",
"the",
"next",
"token",
"if",
"no",
"token",
"is",
"currently",
"available",
"in",
"the",
"lexer",
"."
] | 1ea4449da9834f4d333f1cc461c374aea217d249 | https://github.com/mailru/easyjson/blob/1ea4449da9834f4d333f1cc461c374aea217d249/jlexer/lexer.go#L385-L391 | train |
Subsets and Splits
SQL Console for semeru/code-text-go
Retrieves a limited set of code samples with their languages, with a specific case adjustment for 'Go' language.