id int32 0 167k | repo stringlengths 5 54 | path stringlengths 4 155 | func_name stringlengths 1 118 | original_string stringlengths 52 85.5k | language stringclasses 1
value | code stringlengths 52 85.5k | code_tokens list | docstring stringlengths 6 2.61k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 85 252 |
|---|---|---|---|---|---|---|---|---|---|---|---|
142,900 | btcsuite/winsvc | mgr/service.go | Start | func (s *Service) Start(args []string) error {
var p **uint16
if len(args) > 0 {
vs := make([]*uint16, len(args))
for i, _ := range vs {
vs[i] = syscall.StringToUTF16Ptr(args[i])
}
p = &vs[0]
}
return winapi.StartService(s.Handle, uint32(len(args)), p)
} | go | func (s *Service) Start(args []string) error {
var p **uint16
if len(args) > 0 {
vs := make([]*uint16, len(args))
for i, _ := range vs {
vs[i] = syscall.StringToUTF16Ptr(args[i])
}
p = &vs[0]
}
return winapi.StartService(s.Handle, uint32(len(args)), p)
} | [
"func",
"(",
"s",
"*",
"Service",
")",
"Start",
"(",
"args",
"[",
"]",
"string",
")",
"error",
"{",
"var",
"p",
"*",
"*",
"uint16",
"\n",
"if",
"len",
"(",
"args",
")",
">",
"0",
"{",
"vs",
":=",
"make",
"(",
"[",
"]",
"*",
"uint16",
",",
"... | // Start starts service s. | [
"Start",
"starts",
"service",
"s",
"."
] | f8fb11f83f7e860e3769a08e6811d1b399a43722 | https://github.com/btcsuite/winsvc/blob/f8fb11f83f7e860e3769a08e6811d1b399a43722/mgr/service.go#L38-L48 |
142,901 | btcsuite/winsvc | mgr/service.go | Control | func (s *Service) Control(c svc.Cmd) (svc.Status, error) {
var t winapi.SERVICE_STATUS
err := winapi.ControlService(s.Handle, uint32(c), &t)
if err != nil {
return svc.Status{}, err
}
return svc.Status{
State: svc.State(t.CurrentState),
Accepts: svc.Accepted(t.ControlsAccepted),
}, nil
} | go | func (s *Service) Control(c svc.Cmd) (svc.Status, error) {
var t winapi.SERVICE_STATUS
err := winapi.ControlService(s.Handle, uint32(c), &t)
if err != nil {
return svc.Status{}, err
}
return svc.Status{
State: svc.State(t.CurrentState),
Accepts: svc.Accepted(t.ControlsAccepted),
}, nil
} | [
"func",
"(",
"s",
"*",
"Service",
")",
"Control",
"(",
"c",
"svc",
".",
"Cmd",
")",
"(",
"svc",
".",
"Status",
",",
"error",
")",
"{",
"var",
"t",
"winapi",
".",
"SERVICE_STATUS",
"\n",
"err",
":=",
"winapi",
".",
"ControlService",
"(",
"s",
".",
... | // Control sends state change request c to servce s. | [
"Control",
"sends",
"state",
"change",
"request",
"c",
"to",
"servce",
"s",
"."
] | f8fb11f83f7e860e3769a08e6811d1b399a43722 | https://github.com/btcsuite/winsvc/blob/f8fb11f83f7e860e3769a08e6811d1b399a43722/mgr/service.go#L51-L61 |
142,902 | btcsuite/winsvc | mgr/service.go | Query | func (s *Service) Query() (svc.Status, error) {
var t winapi.SERVICE_STATUS
err := winapi.QueryServiceStatus(s.Handle, &t)
if err != nil {
return svc.Status{}, err
}
return svc.Status{
State: svc.State(t.CurrentState),
Accepts: svc.Accepted(t.ControlsAccepted),
}, nil
} | go | func (s *Service) Query() (svc.Status, error) {
var t winapi.SERVICE_STATUS
err := winapi.QueryServiceStatus(s.Handle, &t)
if err != nil {
return svc.Status{}, err
}
return svc.Status{
State: svc.State(t.CurrentState),
Accepts: svc.Accepted(t.ControlsAccepted),
}, nil
} | [
"func",
"(",
"s",
"*",
"Service",
")",
"Query",
"(",
")",
"(",
"svc",
".",
"Status",
",",
"error",
")",
"{",
"var",
"t",
"winapi",
".",
"SERVICE_STATUS",
"\n",
"err",
":=",
"winapi",
".",
"QueryServiceStatus",
"(",
"s",
".",
"Handle",
",",
"&",
"t"... | // Query returns current status of service s. | [
"Query",
"returns",
"current",
"status",
"of",
"service",
"s",
"."
] | f8fb11f83f7e860e3769a08e6811d1b399a43722 | https://github.com/btcsuite/winsvc/blob/f8fb11f83f7e860e3769a08e6811d1b399a43722/mgr/service.go#L64-L74 |
142,903 | btcsuite/winsvc | debug/log.go | Info | func (l *ConsoleLog) Info(eid uint32, msg string) error {
return l.report("info", eid, msg)
} | go | func (l *ConsoleLog) Info(eid uint32, msg string) error {
return l.report("info", eid, msg)
} | [
"func",
"(",
"l",
"*",
"ConsoleLog",
")",
"Info",
"(",
"eid",
"uint32",
",",
"msg",
"string",
")",
"error",
"{",
"return",
"l",
".",
"report",
"(",
"\"",
"\"",
",",
"eid",
",",
"msg",
")",
"\n",
"}"
] | // Info writes an information event msg with event id eid to the console l. | [
"Info",
"writes",
"an",
"information",
"event",
"msg",
"with",
"event",
"id",
"eid",
"to",
"the",
"console",
"l",
"."
] | f8fb11f83f7e860e3769a08e6811d1b399a43722 | https://github.com/btcsuite/winsvc/blob/f8fb11f83f7e860e3769a08e6811d1b399a43722/debug/log.go#L44-L46 |
142,904 | btcsuite/winsvc | eventlog/install.go | Remove | func Remove(src string) error {
appkey, err := registry.OpenKey(syscall.HKEY_LOCAL_MACHINE, addKeyName)
if err != nil {
return err
}
defer appkey.Close()
return appkey.DeleteSubKey(src)
} | go | func Remove(src string) error {
appkey, err := registry.OpenKey(syscall.HKEY_LOCAL_MACHINE, addKeyName)
if err != nil {
return err
}
defer appkey.Close()
return appkey.DeleteSubKey(src)
} | [
"func",
"Remove",
"(",
"src",
"string",
")",
"error",
"{",
"appkey",
",",
"err",
":=",
"registry",
".",
"OpenKey",
"(",
"syscall",
".",
"HKEY_LOCAL_MACHINE",
",",
"addKeyName",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",... | // Remove deletes all registry elements installed by correspondent Install. | [
"Remove",
"deletes",
"all",
"registry",
"elements",
"installed",
"by",
"correspondent",
"Install",
"."
] | f8fb11f83f7e860e3769a08e6811d1b399a43722 | https://github.com/btcsuite/winsvc/blob/f8fb11f83f7e860e3769a08e6811d1b399a43722/eventlog/install.go#L66-L73 |
142,905 | btcsuite/winsvc | eventlog/log.go | OpenRemote | func OpenRemote(host, source string) (*Log, error) {
if source == "" {
return nil, errors.New("Specify event log source")
}
var s *uint16
if host != "" {
s = syscall.StringToUTF16Ptr(host)
}
h, err := winapi.RegisterEventSource(s, syscall.StringToUTF16Ptr(source))
if err != nil {
return nil, err
}
return... | go | func OpenRemote(host, source string) (*Log, error) {
if source == "" {
return nil, errors.New("Specify event log source")
}
var s *uint16
if host != "" {
s = syscall.StringToUTF16Ptr(host)
}
h, err := winapi.RegisterEventSource(s, syscall.StringToUTF16Ptr(source))
if err != nil {
return nil, err
}
return... | [
"func",
"OpenRemote",
"(",
"host",
",",
"source",
"string",
")",
"(",
"*",
"Log",
",",
"error",
")",
"{",
"if",
"source",
"==",
"\"",
"\"",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"var",
"s",
"*",... | // OpenRemote does the same as Open, but on different computer host. | [
"OpenRemote",
"does",
"the",
"same",
"as",
"Open",
"but",
"on",
"different",
"computer",
"host",
"."
] | f8fb11f83f7e860e3769a08e6811d1b399a43722 | https://github.com/btcsuite/winsvc/blob/f8fb11f83f7e860e3769a08e6811d1b399a43722/eventlog/log.go#L29-L42 |
142,906 | btcsuite/winsvc | eventlog/log.go | Info | func (l *Log) Info(eid uint32, msg string) error {
return l.report(winapi.EVENTLOG_INFORMATION_TYPE, eid, msg)
} | go | func (l *Log) Info(eid uint32, msg string) error {
return l.report(winapi.EVENTLOG_INFORMATION_TYPE, eid, msg)
} | [
"func",
"(",
"l",
"*",
"Log",
")",
"Info",
"(",
"eid",
"uint32",
",",
"msg",
"string",
")",
"error",
"{",
"return",
"l",
".",
"report",
"(",
"winapi",
".",
"EVENTLOG_INFORMATION_TYPE",
",",
"eid",
",",
"msg",
")",
"\n",
"}"
] | // Info writes an information event msg with event id eid to the end of event log l.
// eid must be between 1 and 1000 if using EventCreate.exe as event message file. | [
"Info",
"writes",
"an",
"information",
"event",
"msg",
"with",
"event",
"id",
"eid",
"to",
"the",
"end",
"of",
"event",
"log",
"l",
".",
"eid",
"must",
"be",
"between",
"1",
"and",
"1000",
"if",
"using",
"EventCreate",
".",
"exe",
"as",
"event",
"messa... | f8fb11f83f7e860e3769a08e6811d1b399a43722 | https://github.com/btcsuite/winsvc/blob/f8fb11f83f7e860e3769a08e6811d1b399a43722/eventlog/log.go#L56-L58 |
142,907 | btcsuite/winsvc | eventlog/log.go | Warning | func (l *Log) Warning(eid uint32, msg string) error {
return l.report(winapi.EVENTLOG_WARNING_TYPE, eid, msg)
} | go | func (l *Log) Warning(eid uint32, msg string) error {
return l.report(winapi.EVENTLOG_WARNING_TYPE, eid, msg)
} | [
"func",
"(",
"l",
"*",
"Log",
")",
"Warning",
"(",
"eid",
"uint32",
",",
"msg",
"string",
")",
"error",
"{",
"return",
"l",
".",
"report",
"(",
"winapi",
".",
"EVENTLOG_WARNING_TYPE",
",",
"eid",
",",
"msg",
")",
"\n",
"}"
] | // Warning writes an warning event msg with event id eid to the end of event log l.
// eid must be between 1 and 1000 if using EventCreate.exe as event message file. | [
"Warning",
"writes",
"an",
"warning",
"event",
"msg",
"with",
"event",
"id",
"eid",
"to",
"the",
"end",
"of",
"event",
"log",
"l",
".",
"eid",
"must",
"be",
"between",
"1",
"and",
"1000",
"if",
"using",
"EventCreate",
".",
"exe",
"as",
"event",
"messag... | f8fb11f83f7e860e3769a08e6811d1b399a43722 | https://github.com/btcsuite/winsvc/blob/f8fb11f83f7e860e3769a08e6811d1b399a43722/eventlog/log.go#L62-L64 |
142,908 | btcsuite/winsvc | eventlog/log.go | Error | func (l *Log) Error(eid uint32, msg string) error {
return l.report(winapi.EVENTLOG_ERROR_TYPE, eid, msg)
} | go | func (l *Log) Error(eid uint32, msg string) error {
return l.report(winapi.EVENTLOG_ERROR_TYPE, eid, msg)
} | [
"func",
"(",
"l",
"*",
"Log",
")",
"Error",
"(",
"eid",
"uint32",
",",
"msg",
"string",
")",
"error",
"{",
"return",
"l",
".",
"report",
"(",
"winapi",
".",
"EVENTLOG_ERROR_TYPE",
",",
"eid",
",",
"msg",
")",
"\n",
"}"
] | // Error writes an error event msg with event id eid to the end of event log l.
// eid must be between 1 and 1000 if using EventCreate.exe as event message file. | [
"Error",
"writes",
"an",
"error",
"event",
"msg",
"with",
"event",
"id",
"eid",
"to",
"the",
"end",
"of",
"event",
"log",
"l",
".",
"eid",
"must",
"be",
"between",
"1",
"and",
"1000",
"if",
"using",
"EventCreate",
".",
"exe",
"as",
"event",
"message",
... | f8fb11f83f7e860e3769a08e6811d1b399a43722 | https://github.com/btcsuite/winsvc/blob/f8fb11f83f7e860e3769a08e6811d1b399a43722/eventlog/log.go#L68-L70 |
142,909 | btcsuite/winsvc | mgr/mgr.go | ConnectRemote | func ConnectRemote(host string) (*Mgr, error) {
var s *uint16
if host != "" {
s = syscall.StringToUTF16Ptr(host)
}
h, err := winapi.OpenSCManager(s, nil, winapi.SC_MANAGER_ALL_ACCESS)
if err != nil {
return nil, err
}
return &Mgr{Handle: h}, nil
} | go | func ConnectRemote(host string) (*Mgr, error) {
var s *uint16
if host != "" {
s = syscall.StringToUTF16Ptr(host)
}
h, err := winapi.OpenSCManager(s, nil, winapi.SC_MANAGER_ALL_ACCESS)
if err != nil {
return nil, err
}
return &Mgr{Handle: h}, nil
} | [
"func",
"ConnectRemote",
"(",
"host",
"string",
")",
"(",
"*",
"Mgr",
",",
"error",
")",
"{",
"var",
"s",
"*",
"uint16",
"\n",
"if",
"host",
"!=",
"\"",
"\"",
"{",
"s",
"=",
"syscall",
".",
"StringToUTF16Ptr",
"(",
"host",
")",
"\n",
"}",
"\n",
"... | // ConnectRemote establishes a connection to the
// service control manager on computer named host. | [
"ConnectRemote",
"establishes",
"a",
"connection",
"to",
"the",
"service",
"control",
"manager",
"on",
"computer",
"named",
"host",
"."
] | f8fb11f83f7e860e3769a08e6811d1b399a43722 | https://github.com/btcsuite/winsvc/blob/f8fb11f83f7e860e3769a08e6811d1b399a43722/mgr/mgr.go#L32-L42 |
142,910 | btcsuite/winsvc | mgr/mgr.go | CreateService | func (m *Mgr) CreateService(name, exepath string, c Config) (*Service, error) {
if c.StartType == 0 {
c.StartType = StartManual
}
if c.ErrorControl == 0 {
c.ErrorControl = ErrorNormal
}
c.BinaryPathName = exepath // execpath is important, do not rely on BinaryPathName field to be set
h, err := winapi.CreateSe... | go | func (m *Mgr) CreateService(name, exepath string, c Config) (*Service, error) {
if c.StartType == 0 {
c.StartType = StartManual
}
if c.ErrorControl == 0 {
c.ErrorControl = ErrorNormal
}
c.BinaryPathName = exepath // execpath is important, do not rely on BinaryPathName field to be set
h, err := winapi.CreateSe... | [
"func",
"(",
"m",
"*",
"Mgr",
")",
"CreateService",
"(",
"name",
",",
"exepath",
"string",
",",
"c",
"Config",
")",
"(",
"*",
"Service",
",",
"error",
")",
"{",
"if",
"c",
".",
"StartType",
"==",
"0",
"{",
"c",
".",
"StartType",
"=",
"StartManual",... | // CreateService installs new service name on the system.
// The service will be executed by running exepath binary,
// while service settings are specified in config c. | [
"CreateService",
"installs",
"new",
"service",
"name",
"on",
"the",
"system",
".",
"The",
"service",
"will",
"be",
"executed",
"by",
"running",
"exepath",
"binary",
"while",
"service",
"settings",
"are",
"specified",
"in",
"config",
"c",
"."
] | f8fb11f83f7e860e3769a08e6811d1b399a43722 | https://github.com/btcsuite/winsvc/blob/f8fb11f83f7e860e3769a08e6811d1b399a43722/mgr/mgr.go#L59-L81 |
142,911 | btcsuite/winsvc | mgr/mgr.go | OpenService | func (m *Mgr) OpenService(name string) (*Service, error) {
h, err := winapi.OpenService(m.Handle, syscall.StringToUTF16Ptr(name), winapi.SERVICE_ALL_ACCESS)
if err != nil {
return nil, err
}
return &Service{Name: name, Handle: h}, nil
} | go | func (m *Mgr) OpenService(name string) (*Service, error) {
h, err := winapi.OpenService(m.Handle, syscall.StringToUTF16Ptr(name), winapi.SERVICE_ALL_ACCESS)
if err != nil {
return nil, err
}
return &Service{Name: name, Handle: h}, nil
} | [
"func",
"(",
"m",
"*",
"Mgr",
")",
"OpenService",
"(",
"name",
"string",
")",
"(",
"*",
"Service",
",",
"error",
")",
"{",
"h",
",",
"err",
":=",
"winapi",
".",
"OpenService",
"(",
"m",
".",
"Handle",
",",
"syscall",
".",
"StringToUTF16Ptr",
"(",
"... | // OpenService retrievs access to service name, so it can
// be interrogated and controlled. | [
"OpenService",
"retrievs",
"access",
"to",
"service",
"name",
"so",
"it",
"can",
"be",
"interrogated",
"and",
"controlled",
"."
] | f8fb11f83f7e860e3769a08e6811d1b399a43722 | https://github.com/btcsuite/winsvc/blob/f8fb11f83f7e860e3769a08e6811d1b399a43722/mgr/mgr.go#L85-L91 |
142,912 | btcsuite/winsvc | svc/security.go | getTokenGroups | func getTokenGroups(t syscall.Token) (*winapi.Tokengroups, error) {
i, e := getInfo(t, syscall.TokenGroups, 50)
if e != nil {
return nil, e
}
return (*winapi.Tokengroups)(i), nil
} | go | func getTokenGroups(t syscall.Token) (*winapi.Tokengroups, error) {
i, e := getInfo(t, syscall.TokenGroups, 50)
if e != nil {
return nil, e
}
return (*winapi.Tokengroups)(i), nil
} | [
"func",
"getTokenGroups",
"(",
"t",
"syscall",
".",
"Token",
")",
"(",
"*",
"winapi",
".",
"Tokengroups",
",",
"error",
")",
"{",
"i",
",",
"e",
":=",
"getInfo",
"(",
"t",
",",
"syscall",
".",
"TokenGroups",
",",
"50",
")",
"\n",
"if",
"e",
"!=",
... | // getTokenUser retrieves access token t user account information. | [
"getTokenUser",
"retrieves",
"access",
"token",
"t",
"user",
"account",
"information",
"."
] | f8fb11f83f7e860e3769a08e6811d1b399a43722 | https://github.com/btcsuite/winsvc/blob/f8fb11f83f7e860e3769a08e6811d1b399a43722/svc/security.go#L38-L44 |
142,913 | btcsuite/winsvc | svc/go13.go | add | func add(p unsafe.Pointer, x uintptr) unsafe.Pointer {
return unsafe.Pointer(uintptr(p) + x)
} | go | func add(p unsafe.Pointer, x uintptr) unsafe.Pointer {
return unsafe.Pointer(uintptr(p) + x)
} | [
"func",
"add",
"(",
"p",
"unsafe",
".",
"Pointer",
",",
"x",
"uintptr",
")",
"unsafe",
".",
"Pointer",
"{",
"return",
"unsafe",
".",
"Pointer",
"(",
"uintptr",
"(",
"p",
")",
"+",
"x",
")",
"\n",
"}"
] | // Should be a built-in for unsafe.Pointer? | [
"Should",
"be",
"a",
"built",
"-",
"in",
"for",
"unsafe",
".",
"Pointer?"
] | f8fb11f83f7e860e3769a08e6811d1b399a43722 | https://github.com/btcsuite/winsvc/blob/f8fb11f83f7e860e3769a08e6811d1b399a43722/svc/go13.go#L15-L17 |
142,914 | btcsuite/winsvc | debug/service.go | Run | func Run(name string, handler svc.Handler) error {
cmds := make(chan svc.ChangeRequest)
changes := make(chan svc.Status)
sig := make(chan os.Signal)
signal.Notify(sig)
go func() {
status := svc.Status{State: svc.Stopped}
for {
select {
case <-sig:
cmds <- svc.ChangeRequest{svc.Stop, status}
case... | go | func Run(name string, handler svc.Handler) error {
cmds := make(chan svc.ChangeRequest)
changes := make(chan svc.Status)
sig := make(chan os.Signal)
signal.Notify(sig)
go func() {
status := svc.Status{State: svc.Stopped}
for {
select {
case <-sig:
cmds <- svc.ChangeRequest{svc.Stop, status}
case... | [
"func",
"Run",
"(",
"name",
"string",
",",
"handler",
"svc",
".",
"Handler",
")",
"error",
"{",
"cmds",
":=",
"make",
"(",
"chan",
"svc",
".",
"ChangeRequest",
")",
"\n",
"changes",
":=",
"make",
"(",
"chan",
"svc",
".",
"Status",
")",
"\n\n",
"sig",... | // Run executes service named name by calling appropriate handler function.
// The process is running on console, unlike real service. Use Ctrl+C to
// send "Stop" command to your service. | [
"Run",
"executes",
"service",
"named",
"name",
"by",
"calling",
"appropriate",
"handler",
"function",
".",
"The",
"process",
"is",
"running",
"on",
"console",
"unlike",
"real",
"service",
".",
"Use",
"Ctrl",
"+",
"C",
"to",
"send",
"Stop",
"command",
"to",
... | f8fb11f83f7e860e3769a08e6811d1b399a43722 | https://github.com/btcsuite/winsvc/blob/f8fb11f83f7e860e3769a08e6811d1b399a43722/debug/service.go#L22-L45 |
142,915 | markbates/going | wait/wait.go | Wait | func Wait(length int, block func(index int)) {
var w sync.WaitGroup
w.Add(length)
for i := 0; i < length; i++ {
go func(w *sync.WaitGroup, index int) {
block(index)
w.Done()
}(&w, i)
}
w.Wait()
} | go | func Wait(length int, block func(index int)) {
var w sync.WaitGroup
w.Add(length)
for i := 0; i < length; i++ {
go func(w *sync.WaitGroup, index int) {
block(index)
w.Done()
}(&w, i)
}
w.Wait()
} | [
"func",
"Wait",
"(",
"length",
"int",
",",
"block",
"func",
"(",
"index",
"int",
")",
")",
"{",
"var",
"w",
"sync",
".",
"WaitGroup",
"\n",
"w",
".",
"Add",
"(",
"length",
")",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"length",
";",
"i",
"... | // Wait cleans up the pattern around using sync.WaitGroup | [
"Wait",
"cleans",
"up",
"the",
"pattern",
"around",
"using",
"sync",
".",
"WaitGroup"
] | 27d69239d99b49436b4b00d9605923b07fd863ad | https://github.com/markbates/going/blob/27d69239d99b49436b4b00d9605923b07fd863ad/wait/wait.go#L6-L16 |
142,916 | ancientlore/go-avltree | treeprint.go | Print | func (t *Tree) Print(w io.Writer, f IterateFunc, itemSiz int) {
fmt.Fprintf(w, "treeNode-+-Left \t / Left High\n")
fmt.Fprintf(w, " | \t = Equal\n")
fmt.Fprintf(w, " +-Right\t \\ Right High\n\n")
maxHeight := t.Height()
if f != nil && t.root != nil {
d := &printData{0, itemSiz, make([]byte, maxHe... | go | func (t *Tree) Print(w io.Writer, f IterateFunc, itemSiz int) {
fmt.Fprintf(w, "treeNode-+-Left \t / Left High\n")
fmt.Fprintf(w, " | \t = Equal\n")
fmt.Fprintf(w, " +-Right\t \\ Right High\n\n")
maxHeight := t.Height()
if f != nil && t.root != nil {
d := &printData{0, itemSiz, make([]byte, maxHe... | [
"func",
"(",
"t",
"*",
"Tree",
")",
"Print",
"(",
"w",
"io",
".",
"Writer",
",",
"f",
"IterateFunc",
",",
"itemSiz",
"int",
")",
"{",
"fmt",
".",
"Fprintf",
"(",
"w",
",",
"\"",
"\\t",
"\\n",
"\"",
")",
"\n",
"fmt",
".",
"Fprintf",
"(",
"w",
... | // Print prints the values of the Tree to the given writer. | [
"Print",
"prints",
"the",
"values",
"of",
"the",
"Tree",
"to",
"the",
"given",
"writer",
"."
] | da83409fdfb761103cef93a2e2e71f97349d42d6 | https://github.com/ancientlore/go-avltree/blob/da83409fdfb761103cef93a2e2e71f97349d42d6/treeprint.go#L73-L85 |
142,917 | ancientlore/go-avltree | node.go | init | func (n *treeNode) init(val interface{}) *treeNode {
n.left = nil
n.right = nil
n.bal = equal
n.size = 1
n.value = val
return n
} | go | func (n *treeNode) init(val interface{}) *treeNode {
n.left = nil
n.right = nil
n.bal = equal
n.size = 1
n.value = val
return n
} | [
"func",
"(",
"n",
"*",
"treeNode",
")",
"init",
"(",
"val",
"interface",
"{",
"}",
")",
"*",
"treeNode",
"{",
"n",
".",
"left",
"=",
"nil",
"\n",
"n",
".",
"right",
"=",
"nil",
"\n",
"n",
".",
"bal",
"=",
"equal",
"\n",
"n",
".",
"size",
"=",... | // Init initializes a node with the given value | [
"Init",
"initializes",
"a",
"node",
"with",
"the",
"given",
"value"
] | da83409fdfb761103cef93a2e2e71f97349d42d6 | https://github.com/ancientlore/go-avltree/blob/da83409fdfb761103cef93a2e2e71f97349d42d6/node.go#L26-L33 |
142,918 | ancientlore/go-avltree | node.go | leftSize | func (n *treeNode) leftSize() int {
if n.left != nil {
return n.left.size
}
return 0
} | go | func (n *treeNode) leftSize() int {
if n.left != nil {
return n.left.size
}
return 0
} | [
"func",
"(",
"n",
"*",
"treeNode",
")",
"leftSize",
"(",
")",
"int",
"{",
"if",
"n",
".",
"left",
"!=",
"nil",
"{",
"return",
"n",
".",
"left",
".",
"size",
"\n",
"}",
"\n",
"return",
"0",
"\n",
"}"
] | // leftSize returns the size of the left subtree
// of the node | [
"leftSize",
"returns",
"the",
"size",
"of",
"the",
"left",
"subtree",
"of",
"the",
"node"
] | da83409fdfb761103cef93a2e2e71f97349d42d6 | https://github.com/ancientlore/go-avltree/blob/da83409fdfb761103cef93a2e2e71f97349d42d6/node.go#L40-L45 |
142,919 | ancientlore/go-avltree | node.go | rightSize | func (n treeNode) rightSize() int {
if n.right != nil {
return n.right.size
}
return 0
} | go | func (n treeNode) rightSize() int {
if n.right != nil {
return n.right.size
}
return 0
} | [
"func",
"(",
"n",
"treeNode",
")",
"rightSize",
"(",
")",
"int",
"{",
"if",
"n",
".",
"right",
"!=",
"nil",
"{",
"return",
"n",
".",
"right",
".",
"size",
"\n",
"}",
"\n",
"return",
"0",
"\n",
"}"
] | // rightSize returns the size of the right subtree
// of the node | [
"rightSize",
"returns",
"the",
"size",
"of",
"the",
"right",
"subtree",
"of",
"the",
"node"
] | da83409fdfb761103cef93a2e2e71f97349d42d6 | https://github.com/ancientlore/go-avltree/blob/da83409fdfb761103cef93a2e2e71f97349d42d6/node.go#L49-L54 |
142,920 | ancientlore/go-avltree | tree.go | Init | func (t *Tree) Init(c CompareFunc, flags byte) *Tree {
t.compare = c
t.root = nil
t.treeFlags = flags
return t
} | go | func (t *Tree) Init(c CompareFunc, flags byte) *Tree {
t.compare = c
t.root = nil
t.treeFlags = flags
return t
} | [
"func",
"(",
"t",
"*",
"Tree",
")",
"Init",
"(",
"c",
"CompareFunc",
",",
"flags",
"byte",
")",
"*",
"Tree",
"{",
"t",
".",
"compare",
"=",
"c",
"\n",
"t",
".",
"root",
"=",
"nil",
"\n",
"t",
".",
"treeFlags",
"=",
"flags",
"\n",
"return",
"t",... | // Init initializes or resets a Tree. | [
"Init",
"initializes",
"or",
"resets",
"a",
"Tree",
"."
] | da83409fdfb761103cef93a2e2e71f97349d42d6 | https://github.com/ancientlore/go-avltree/blob/da83409fdfb761103cef93a2e2e71f97349d42d6/tree.go#L59-L64 |
142,921 | ancientlore/go-avltree | tree.go | Height | func (t *Tree) Height() int {
d := &calcHeightData{0, 0}
if t.root != nil {
d.calcHeight(t.root)
}
return d.maxHeight
} | go | func (t *Tree) Height() int {
d := &calcHeightData{0, 0}
if t.root != nil {
d.calcHeight(t.root)
}
return d.maxHeight
} | [
"func",
"(",
"t",
"*",
"Tree",
")",
"Height",
"(",
")",
"int",
"{",
"d",
":=",
"&",
"calcHeightData",
"{",
"0",
",",
"0",
"}",
"\n\n",
"if",
"t",
".",
"root",
"!=",
"nil",
"{",
"d",
".",
"calcHeight",
"(",
"t",
".",
"root",
")",
"\n",
"}",
... | // Height returns the "height" of the tree, meaning the
// number of levels. | [
"Height",
"returns",
"the",
"height",
"of",
"the",
"tree",
"meaning",
"the",
"number",
"of",
"levels",
"."
] | da83409fdfb761103cef93a2e2e71f97349d42d6 | https://github.com/ancientlore/go-avltree/blob/da83409fdfb761103cef93a2e2e71f97349d42d6/tree.go#L101-L109 |
142,922 | ancientlore/go-avltree | tree.go | Len | func (t *Tree) Len() int {
if t.root != nil {
return t.root.size
}
return 0
} | go | func (t *Tree) Len() int {
if t.root != nil {
return t.root.size
}
return 0
} | [
"func",
"(",
"t",
"*",
"Tree",
")",
"Len",
"(",
")",
"int",
"{",
"if",
"t",
".",
"root",
"!=",
"nil",
"{",
"return",
"t",
".",
"root",
".",
"size",
"\n",
"}",
"\n",
"return",
"0",
"\n",
"}"
] | // Len returns the number of elements in the tree. | [
"Len",
"returns",
"the",
"number",
"of",
"elements",
"in",
"the",
"tree",
"."
] | da83409fdfb761103cef93a2e2e71f97349d42d6 | https://github.com/ancientlore/go-avltree/blob/da83409fdfb761103cef93a2e2e71f97349d42d6/tree.go#L112-L117 |
142,923 | ancientlore/go-avltree | tree.go | Cap | func (t *Tree) Cap() int {
var count, i int
count = 0
maxHeight := t.Height()
for i = 0; i < maxHeight; i++ {
count += int(math.Pow(2, float64(i)))
}
return count
} | go | func (t *Tree) Cap() int {
var count, i int
count = 0
maxHeight := t.Height()
for i = 0; i < maxHeight; i++ {
count += int(math.Pow(2, float64(i)))
}
return count
} | [
"func",
"(",
"t",
"*",
"Tree",
")",
"Cap",
"(",
")",
"int",
"{",
"var",
"count",
",",
"i",
"int",
"\n",
"count",
"=",
"0",
"\n\n",
"maxHeight",
":=",
"t",
".",
"Height",
"(",
")",
"\n\n",
"for",
"i",
"=",
"0",
";",
"i",
"<",
"maxHeight",
";",... | // Cap returns the capacity of the tree; that is, the
// maximum elements the tree can hold with at the
// current height. This is only useful as a measure
// of how skewed the tree is. | [
"Cap",
"returns",
"the",
"capacity",
"of",
"the",
"tree",
";",
"that",
"is",
"the",
"maximum",
"elements",
"the",
"tree",
"can",
"hold",
"with",
"at",
"the",
"current",
"height",
".",
"This",
"is",
"only",
"useful",
"as",
"a",
"measure",
"of",
"how",
"... | da83409fdfb761103cef93a2e2e71f97349d42d6 | https://github.com/ancientlore/go-avltree/blob/da83409fdfb761103cef93a2e2e71f97349d42d6/tree.go#L123-L135 |
142,924 | ancientlore/go-avltree | tree.go | indexer | func indexer(node *treeNode, index int) *treeNode {
if index < node.leftSize() {
return indexer(node.left, index)
} else if index == node.leftSize() {
return node
} else if node.right != nil {
return indexer(node.right, index-(node.leftSize()+1))
}
return nil
} | go | func indexer(node *treeNode, index int) *treeNode {
if index < node.leftSize() {
return indexer(node.left, index)
} else if index == node.leftSize() {
return node
} else if node.right != nil {
return indexer(node.right, index-(node.leftSize()+1))
}
return nil
} | [
"func",
"indexer",
"(",
"node",
"*",
"treeNode",
",",
"index",
"int",
")",
"*",
"treeNode",
"{",
"if",
"index",
"<",
"node",
".",
"leftSize",
"(",
")",
"{",
"return",
"indexer",
"(",
"node",
".",
"left",
",",
"index",
")",
"\n",
"}",
"else",
"if",
... | // indexer recursively scans the tree to find the node
// at the given position. | [
"indexer",
"recursively",
"scans",
"the",
"tree",
"to",
"find",
"the",
"node",
"at",
"the",
"given",
"position",
"."
] | da83409fdfb761103cef93a2e2e71f97349d42d6 | https://github.com/ancientlore/go-avltree/blob/da83409fdfb761103cef93a2e2e71f97349d42d6/tree.go#L139-L149 |
142,925 | ancientlore/go-avltree | tree.go | finder | func (d *findData) finder(node *treeNode) *treeNode {
if node != nil {
code := d.compare(d.lookingFor, node.value)
if code < 0 {
return d.finder(node.left)
} else if code > 0 {
return d.finder(node.right)
}
return node
}
return nil
} | go | func (d *findData) finder(node *treeNode) *treeNode {
if node != nil {
code := d.compare(d.lookingFor, node.value)
if code < 0 {
return d.finder(node.left)
} else if code > 0 {
return d.finder(node.right)
}
return node
}
return nil
} | [
"func",
"(",
"d",
"*",
"findData",
")",
"finder",
"(",
"node",
"*",
"treeNode",
")",
"*",
"treeNode",
"{",
"if",
"node",
"!=",
"nil",
"{",
"code",
":=",
"d",
".",
"compare",
"(",
"d",
".",
"lookingFor",
",",
"node",
".",
"value",
")",
"\n",
"if",... | // finder recursively scans the tree to find the node with the
// value we're looking for. | [
"finder",
"recursively",
"scans",
"the",
"tree",
"to",
"find",
"the",
"node",
"with",
"the",
"value",
"we",
"re",
"looking",
"for",
"."
] | da83409fdfb761103cef93a2e2e71f97349d42d6 | https://github.com/ancientlore/go-avltree/blob/da83409fdfb761103cef93a2e2e71f97349d42d6/tree.go#L172-L184 |
142,926 | ancientlore/go-avltree | tree.go | iterate | func (d *iterData) iterate(node *treeNode) bool {
var proceed bool
if node.left != nil {
proceed = d.iterate(node.left)
if !proceed {
return false
}
}
proceed = d.iter(node.value)
if !proceed {
return false
}
if node.right != nil {
proceed = d.iterate(node.right)
if !proceed {
return false
... | go | func (d *iterData) iterate(node *treeNode) bool {
var proceed bool
if node.left != nil {
proceed = d.iterate(node.left)
if !proceed {
return false
}
}
proceed = d.iter(node.value)
if !proceed {
return false
}
if node.right != nil {
proceed = d.iterate(node.right)
if !proceed {
return false
... | [
"func",
"(",
"d",
"*",
"iterData",
")",
"iterate",
"(",
"node",
"*",
"treeNode",
")",
"bool",
"{",
"var",
"proceed",
"bool",
"\n\n",
"if",
"node",
".",
"left",
"!=",
"nil",
"{",
"proceed",
"=",
"d",
".",
"iterate",
"(",
"node",
".",
"left",
")",
... | // iterate recursively traverses the tree and executes
// the iteration function. | [
"iterate",
"recursively",
"traverses",
"the",
"tree",
"and",
"executes",
"the",
"iteration",
"function",
"."
] | da83409fdfb761103cef93a2e2e71f97349d42d6 | https://github.com/ancientlore/go-avltree/blob/da83409fdfb761103cef93a2e2e71f97349d42d6/tree.go#L207-L230 |
142,927 | ancientlore/go-avltree | pairtree.go | Compare | func (a Pair) Compare(b Interface) int {
if a.Key < b.(Pair).Key {
return -1
} else if a.Key > b.(Pair).Key {
return 1
}
return 0
} | go | func (a Pair) Compare(b Interface) int {
if a.Key < b.(Pair).Key {
return -1
} else if a.Key > b.(Pair).Key {
return 1
}
return 0
} | [
"func",
"(",
"a",
"Pair",
")",
"Compare",
"(",
"b",
"Interface",
")",
"int",
"{",
"if",
"a",
".",
"Key",
"<",
"b",
".",
"(",
"Pair",
")",
".",
"Key",
"{",
"return",
"-",
"1",
"\n",
"}",
"else",
"if",
"a",
".",
"Key",
">",
"b",
".",
"(",
"... | // Compare is the compare function for Pairs, based on Key. | [
"Compare",
"is",
"the",
"compare",
"function",
"for",
"Pairs",
"based",
"on",
"Key",
"."
] | da83409fdfb761103cef93a2e2e71f97349d42d6 | https://github.com/ancientlore/go-avltree/blob/da83409fdfb761103cef93a2e2e71f97349d42d6/pairtree.go#L19-L26 |
142,928 | ancientlore/go-avltree | pairtree.go | Init | func (t *PairTree) Init(flags byte) *PairTree {
t.ObjectTree.Init(flags)
return t
} | go | func (t *PairTree) Init(flags byte) *PairTree {
t.ObjectTree.Init(flags)
return t
} | [
"func",
"(",
"t",
"*",
"PairTree",
")",
"Init",
"(",
"flags",
"byte",
")",
"*",
"PairTree",
"{",
"t",
".",
"ObjectTree",
".",
"Init",
"(",
"flags",
")",
"\n",
"return",
"t",
"\n",
"}"
] | // Init will initialize or reset a PairTree. | [
"Init",
"will",
"initialize",
"or",
"reset",
"a",
"PairTree",
"."
] | da83409fdfb761103cef93a2e2e71f97349d42d6 | https://github.com/ancientlore/go-avltree/blob/da83409fdfb761103cef93a2e2e71f97349d42d6/pairtree.go#L32-L35 |
142,929 | ancientlore/go-avltree | pairtree.go | Print | func (t *PairTree) Print(w io.Writer, f PairIterateFunc, itemSiz int) {
t.ObjectTree.Print(w, func(v interface{}) bool { return f(v.(Pair)) }, itemSiz)
} | go | func (t *PairTree) Print(w io.Writer, f PairIterateFunc, itemSiz int) {
t.ObjectTree.Print(w, func(v interface{}) bool { return f(v.(Pair)) }, itemSiz)
} | [
"func",
"(",
"t",
"*",
"PairTree",
")",
"Print",
"(",
"w",
"io",
".",
"Writer",
",",
"f",
"PairIterateFunc",
",",
"itemSiz",
"int",
")",
"{",
"t",
".",
"ObjectTree",
".",
"Print",
"(",
"w",
",",
"func",
"(",
"v",
"interface",
"{",
"}",
")",
"bool... | // Print prints the values in the tree to the writer. | [
"Print",
"prints",
"the",
"values",
"in",
"the",
"tree",
"to",
"the",
"writer",
"."
] | da83409fdfb761103cef93a2e2e71f97349d42d6 | https://github.com/ancientlore/go-avltree/blob/da83409fdfb761103cef93a2e2e71f97349d42d6/pairtree.go#L128-L130 |
142,930 | ancientlore/go-avltree | stringtree.go | Init | func (t *StringTree) Init(flags byte) *StringTree {
t.Tree.Init(stringCompare, flags)
return t
} | go | func (t *StringTree) Init(flags byte) *StringTree {
t.Tree.Init(stringCompare, flags)
return t
} | [
"func",
"(",
"t",
"*",
"StringTree",
")",
"Init",
"(",
"flags",
"byte",
")",
"*",
"StringTree",
"{",
"t",
".",
"Tree",
".",
"Init",
"(",
"stringCompare",
",",
"flags",
")",
"\n",
"return",
"t",
"\n",
"}"
] | // Init will initialize or reset a StringTree. | [
"Init",
"will",
"initialize",
"or",
"reset",
"a",
"StringTree",
"."
] | da83409fdfb761103cef93a2e2e71f97349d42d6 | https://github.com/ancientlore/go-avltree/blob/da83409fdfb761103cef93a2e2e71f97349d42d6/stringtree.go#L25-L28 |
142,931 | ancientlore/go-avltree | stringtree.go | Print | func (t *StringTree) Print(w io.Writer, f StringIterateFunc, itemSiz int) {
t.Tree.Print(w, func(v interface{}) bool { return f(v.(string)) }, itemSiz)
} | go | func (t *StringTree) Print(w io.Writer, f StringIterateFunc, itemSiz int) {
t.Tree.Print(w, func(v interface{}) bool { return f(v.(string)) }, itemSiz)
} | [
"func",
"(",
"t",
"*",
"StringTree",
")",
"Print",
"(",
"w",
"io",
".",
"Writer",
",",
"f",
"StringIterateFunc",
",",
"itemSiz",
"int",
")",
"{",
"t",
".",
"Tree",
".",
"Print",
"(",
"w",
",",
"func",
"(",
"v",
"interface",
"{",
"}",
")",
"bool",... | // Print prints the values of the StringTree to the given writer. | [
"Print",
"prints",
"the",
"values",
"of",
"the",
"StringTree",
"to",
"the",
"given",
"writer",
"."
] | da83409fdfb761103cef93a2e2e71f97349d42d6 | https://github.com/ancientlore/go-avltree/blob/da83409fdfb761103cef93a2e2e71f97349d42d6/stringtree.go#L116-L118 |
142,932 | ancientlore/go-avltree | objecttree.go | Init | func (t *ObjectTree) Init(flags byte) *ObjectTree {
t.Tree.Init(objectCompare, flags)
return t
} | go | func (t *ObjectTree) Init(flags byte) *ObjectTree {
t.Tree.Init(objectCompare, flags)
return t
} | [
"func",
"(",
"t",
"*",
"ObjectTree",
")",
"Init",
"(",
"flags",
"byte",
")",
"*",
"ObjectTree",
"{",
"t",
".",
"Tree",
".",
"Init",
"(",
"objectCompare",
",",
"flags",
")",
"\n",
"return",
"t",
"\n",
"}"
] | // Init will initialize or reset an ObjectTree. | [
"Init",
"will",
"initialize",
"or",
"reset",
"an",
"ObjectTree",
"."
] | da83409fdfb761103cef93a2e2e71f97349d42d6 | https://github.com/ancientlore/go-avltree/blob/da83409fdfb761103cef93a2e2e71f97349d42d6/objecttree.go#L20-L23 |
142,933 | iris-contrib/formBinder | binder.go | find | func (ma pathMaps) find(id reflect.Value, key string) *pathMap {
for _, v := range ma {
if v.ma == id && v.key == key {
return v
}
}
return nil
} | go | func (ma pathMaps) find(id reflect.Value, key string) *pathMap {
for _, v := range ma {
if v.ma == id && v.key == key {
return v
}
}
return nil
} | [
"func",
"(",
"ma",
"pathMaps",
")",
"find",
"(",
"id",
"reflect",
".",
"Value",
",",
"key",
"string",
")",
"*",
"pathMap",
"{",
"for",
"_",
",",
"v",
":=",
"range",
"ma",
"{",
"if",
"v",
".",
"ma",
"==",
"id",
"&&",
"v",
".",
"key",
"==",
"ke... | // find find and get the value by the given key | [
"find",
"find",
"and",
"get",
"the",
"value",
"by",
"the",
"given",
"key"
] | fbd5963f41e18ae1f1423ba046235094b0721ea1 | https://github.com/iris-contrib/formBinder/blob/fbd5963f41e18ae1f1423ba046235094b0721ea1/binder.go#L45-L52 |
142,934 | iris-contrib/formBinder | binder.go | RegisterCustomType | func (dec *Decoder) RegisterCustomType(fn DecodeCustomTypeFunc, types []interface{}, fields []interface{}) *Decoder {
if dec.customTypes == nil {
dec.customTypes = make(map[reflect.Type]*DecodeCustomType)
}
for i := range types {
typ := reflect.TypeOf(types[i])
if dec.customTypes[typ] == nil {
dec.customTyp... | go | func (dec *Decoder) RegisterCustomType(fn DecodeCustomTypeFunc, types []interface{}, fields []interface{}) *Decoder {
if dec.customTypes == nil {
dec.customTypes = make(map[reflect.Type]*DecodeCustomType)
}
for i := range types {
typ := reflect.TypeOf(types[i])
if dec.customTypes[typ] == nil {
dec.customTyp... | [
"func",
"(",
"dec",
"*",
"Decoder",
")",
"RegisterCustomType",
"(",
"fn",
"DecodeCustomTypeFunc",
",",
"types",
"[",
"]",
"interface",
"{",
"}",
",",
"fields",
"[",
"]",
"interface",
"{",
"}",
")",
"*",
"Decoder",
"{",
"if",
"dec",
".",
"customTypes",
... | // RegisterCustomType It is the method responsible for register functions for decoding custom types | [
"RegisterCustomType",
"It",
"is",
"the",
"method",
"responsible",
"for",
"register",
"functions",
"for",
"decoding",
"custom",
"types"
] | fbd5963f41e18ae1f1423ba046235094b0721ea1 | https://github.com/iris-contrib/formBinder/blob/fbd5963f41e18ae1f1423ba046235094b0721ea1/binder.go#L95-L115 |
142,935 | iris-contrib/formBinder | binder.go | Decode | func (dec *Decoder) Decode(vs url.Values, dst interface{}) error {
main := reflect.ValueOf(dst)
if main.Kind() != reflect.Ptr {
return newError(fmt.Errorf("form: the value passed for decode is not a pointer but a %v", main.Kind()))
}
dec.main = main.Elem()
dec.formValues = vs
return dec.prepare()
} | go | func (dec *Decoder) Decode(vs url.Values, dst interface{}) error {
main := reflect.ValueOf(dst)
if main.Kind() != reflect.Ptr {
return newError(fmt.Errorf("form: the value passed for decode is not a pointer but a %v", main.Kind()))
}
dec.main = main.Elem()
dec.formValues = vs
return dec.prepare()
} | [
"func",
"(",
"dec",
"*",
"Decoder",
")",
"Decode",
"(",
"vs",
"url",
".",
"Values",
",",
"dst",
"interface",
"{",
"}",
")",
"error",
"{",
"main",
":=",
"reflect",
".",
"ValueOf",
"(",
"dst",
")",
"\n",
"if",
"main",
".",
"Kind",
"(",
")",
"!=",
... | // Decode decodes the url.Values into a element that must be a pointer to a type provided by argument | [
"Decode",
"decodes",
"the",
"url",
".",
"Values",
"into",
"a",
"element",
"that",
"must",
"be",
"a",
"pointer",
"to",
"a",
"type",
"provided",
"by",
"argument"
] | fbd5963f41e18ae1f1423ba046235094b0721ea1 | https://github.com/iris-contrib/formBinder/blob/fbd5963f41e18ae1f1423ba046235094b0721ea1/binder.go#L130-L138 |
142,936 | iris-contrib/formBinder | binder.go | begin | func (dec *Decoder) begin() (err error) {
inBracket := false
valBracket := ""
bracketClosed := false
lastPos := 0
tmp := dec.field
// parse path
for i, char := range tmp {
if char == '[' && inBracket == false {
// found an opening bracket
bracketClosed = false
inBracket = true
dec.field = tmp[last... | go | func (dec *Decoder) begin() (err error) {
inBracket := false
valBracket := ""
bracketClosed := false
lastPos := 0
tmp := dec.field
// parse path
for i, char := range tmp {
if char == '[' && inBracket == false {
// found an opening bracket
bracketClosed = false
inBracket = true
dec.field = tmp[last... | [
"func",
"(",
"dec",
"*",
"Decoder",
")",
"begin",
"(",
")",
"(",
"err",
"error",
")",
"{",
"inBracket",
":=",
"false",
"\n",
"valBracket",
":=",
"\"",
"\"",
"\n",
"bracketClosed",
":=",
"false",
"\n",
"lastPos",
":=",
"0",
"\n",
"tmp",
":=",
"dec",
... | // begin analyzes the current path to walk through it | [
"begin",
"analyzes",
"the",
"current",
"path",
"to",
"walk",
"through",
"it"
] | fbd5963f41e18ae1f1423ba046235094b0721ea1 | https://github.com/iris-contrib/formBinder/blob/fbd5963f41e18ae1f1423ba046235094b0721ea1/binder.go#L198-L272 |
142,937 | iris-contrib/formBinder | binder.go | IsErrPath | func IsErrPath(err error) bool {
if err == nil {
return false
}
_, ok := err.(ErrPath)
return ok
} | go | func IsErrPath(err error) bool {
if err == nil {
return false
}
_, ok := err.(ErrPath)
return ok
} | [
"func",
"IsErrPath",
"(",
"err",
"error",
")",
"bool",
"{",
"if",
"err",
"==",
"nil",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"_",
",",
"ok",
":=",
"err",
".",
"(",
"ErrPath",
")",
"\n",
"return",
"ok",
"\n",
"}"
] | // IsErrPath reports whether the incoming error is type of `ErrPath`, which can be ignored
// when server allows unknown post values to be sent by the client. | [
"IsErrPath",
"reports",
"whether",
"the",
"incoming",
"error",
"is",
"type",
"of",
"ErrPath",
"which",
"can",
"be",
"ignored",
"when",
"server",
"allows",
"unknown",
"post",
"values",
"to",
"be",
"sent",
"by",
"the",
"client",
"."
] | fbd5963f41e18ae1f1423ba046235094b0721ea1 | https://github.com/iris-contrib/formBinder/blob/fbd5963f41e18ae1f1423ba046235094b0721ea1/binder.go#L499-L506 |
142,938 | iris-contrib/formBinder | binder.go | findStructField | func (dec *Decoder) findStructField() error {
var anon reflect.Value
num := dec.curr.NumField()
for i := 0; i < num; i++ {
field := dec.curr.Type().Field(i)
if field.Name == dec.field {
// check if the field's name is equal
dec.curr = dec.curr.Field(i)
return nil
} else if field.Anonymous {
// if ... | go | func (dec *Decoder) findStructField() error {
var anon reflect.Value
num := dec.curr.NumField()
for i := 0; i < num; i++ {
field := dec.curr.Type().Field(i)
if field.Name == dec.field {
// check if the field's name is equal
dec.curr = dec.curr.Field(i)
return nil
} else if field.Anonymous {
// if ... | [
"func",
"(",
"dec",
"*",
"Decoder",
")",
"findStructField",
"(",
")",
"error",
"{",
"var",
"anon",
"reflect",
".",
"Value",
"\n\n",
"num",
":=",
"dec",
".",
"curr",
".",
"NumField",
"(",
")",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"num",
";"... | // findField finds a field by its name, if it is not found,
// then retry the search examining the tag "form" of every field of struct | [
"findField",
"finds",
"a",
"field",
"by",
"its",
"name",
"if",
"it",
"is",
"not",
"found",
"then",
"retry",
"the",
"search",
"examining",
"the",
"tag",
"form",
"of",
"every",
"field",
"of",
"struct"
] | fbd5963f41e18ae1f1423ba046235094b0721ea1 | https://github.com/iris-contrib/formBinder/blob/fbd5963f41e18ae1f1423ba046235094b0721ea1/binder.go#L524-L559 |
142,939 | iris-contrib/formBinder | utils.go | checkUnmarshalText | func checkUnmarshalText(v reflect.Value, val string) (bool, error) {
// check if implements the interface
m, ok := v.Interface().(encoding.TextUnmarshaler)
addr := v.CanAddr()
if !ok && !addr {
return false, nil
} else if addr {
return checkUnmarshalText(v.Addr(), val)
}
// skip if the type is time.Time
n :... | go | func checkUnmarshalText(v reflect.Value, val string) (bool, error) {
// check if implements the interface
m, ok := v.Interface().(encoding.TextUnmarshaler)
addr := v.CanAddr()
if !ok && !addr {
return false, nil
} else if addr {
return checkUnmarshalText(v.Addr(), val)
}
// skip if the type is time.Time
n :... | [
"func",
"checkUnmarshalText",
"(",
"v",
"reflect",
".",
"Value",
",",
"val",
"string",
")",
"(",
"bool",
",",
"error",
")",
"{",
"// check if implements the interface",
"m",
",",
"ok",
":=",
"v",
".",
"Interface",
"(",
")",
".",
"(",
"encoding",
".",
"Te... | // unmarshalText returns a boolean and error. The boolean is true if the
// value implements TextUnmarshaler, and false if not. | [
"unmarshalText",
"returns",
"a",
"boolean",
"and",
"error",
".",
"The",
"boolean",
"is",
"true",
"if",
"the",
"value",
"implements",
"TextUnmarshaler",
"and",
"false",
"if",
"not",
"."
] | fbd5963f41e18ae1f1423ba046235094b0721ea1 | https://github.com/iris-contrib/formBinder/blob/fbd5963f41e18ae1f1423ba046235094b0721ea1/utils.go#L16-L32 |
142,940 | GoIncremental/negroni-sessions | redisstore/main.go | New | func New(size int, network, address, password string, keyPairs ...[]byte) (nSessions.Store, error) {
store, err := redistore.NewRediStore(size, network, address, password, keyPairs...)
if err != nil {
return nil, err
}
return &rediStore{store}, nil
} | go | func New(size int, network, address, password string, keyPairs ...[]byte) (nSessions.Store, error) {
store, err := redistore.NewRediStore(size, network, address, password, keyPairs...)
if err != nil {
return nil, err
}
return &rediStore{store}, nil
} | [
"func",
"New",
"(",
"size",
"int",
",",
"network",
",",
"address",
",",
"password",
"string",
",",
"keyPairs",
"...",
"[",
"]",
"byte",
")",
"(",
"nSessions",
".",
"Store",
",",
"error",
")",
"{",
"store",
",",
"err",
":=",
"redistore",
".",
"NewRedi... | //New returns a new Redis store | [
"New",
"returns",
"a",
"new",
"Redis",
"store"
] | 40b49004abeec57f602bad8509521a865b2be95e | https://github.com/GoIncremental/negroni-sessions/blob/40b49004abeec57f602bad8509521a865b2be95e/redisstore/main.go#L10-L16 |
142,941 | GoIncremental/negroni-sessions | dalstore/main.go | New | func New(connection dal.Connection, database string, collection string, maxAge int,
ensureTTL bool, keyPairs ...[]byte) nSessions.Store {
if ensureTTL {
conn := connection.Clone()
defer conn.Close()
db := conn.DB(database)
c := db.C(collection)
c.EnsureIndex(dal.Index{
Key: []string{"modified"},
... | go | func New(connection dal.Connection, database string, collection string, maxAge int,
ensureTTL bool, keyPairs ...[]byte) nSessions.Store {
if ensureTTL {
conn := connection.Clone()
defer conn.Close()
db := conn.DB(database)
c := db.C(collection)
c.EnsureIndex(dal.Index{
Key: []string{"modified"},
... | [
"func",
"New",
"(",
"connection",
"dal",
".",
"Connection",
",",
"database",
"string",
",",
"collection",
"string",
",",
"maxAge",
"int",
",",
"ensureTTL",
"bool",
",",
"keyPairs",
"...",
"[",
"]",
"byte",
")",
"nSessions",
".",
"Store",
"{",
"if",
"ensu... | // New is returns a store object using the provided dal.Connection | [
"New",
"is",
"returns",
"a",
"store",
"object",
"using",
"the",
"provided",
"dal",
".",
"Connection"
] | 40b49004abeec57f602bad8509521a865b2be95e | https://github.com/GoIncremental/negroni-sessions/blob/40b49004abeec57f602bad8509521a865b2be95e/dalstore/main.go#L14-L38 |
142,942 | GoIncremental/negroni-sessions | sessions.go | Sessions | func Sessions(name string, store Store) negroni.HandlerFunc {
return func(res http.ResponseWriter, r *http.Request, next http.HandlerFunc) {
// Map to the Session interface
s := &session{name, r, store, nil, false}
// Add our session to the context we got from our request
ctx := context.WithValue(r.Context(),... | go | func Sessions(name string, store Store) negroni.HandlerFunc {
return func(res http.ResponseWriter, r *http.Request, next http.HandlerFunc) {
// Map to the Session interface
s := &session{name, r, store, nil, false}
// Add our session to the context we got from our request
ctx := context.WithValue(r.Context(),... | [
"func",
"Sessions",
"(",
"name",
"string",
",",
"store",
"Store",
")",
"negroni",
".",
"HandlerFunc",
"{",
"return",
"func",
"(",
"res",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
",",
"next",
"http",
".",
"HandlerFunc",
")",
... | // Sessions is a Middleware that maps a session.Session service into the negroni handler chain.
// Sessions can use a number of storage solutions with the given store. | [
"Sessions",
"is",
"a",
"Middleware",
"that",
"maps",
"a",
"session",
".",
"Session",
"service",
"into",
"the",
"negroni",
"handler",
"chain",
".",
"Sessions",
"can",
"use",
"a",
"number",
"of",
"storage",
"solutions",
"with",
"the",
"given",
"store",
"."
] | 40b49004abeec57f602bad8509521a865b2be95e | https://github.com/GoIncremental/negroni-sessions/blob/40b49004abeec57f602bad8509521a865b2be95e/sessions.go#L87-L108 |
142,943 | GoIncremental/negroni-sessions | sessions.go | GetSession | func GetSession(req *http.Request) Session {
if s, ok := req.Context().Value(sessionKey).(*session); ok {
return s
}
return nil
} | go | func GetSession(req *http.Request) Session {
if s, ok := req.Context().Value(sessionKey).(*session); ok {
return s
}
return nil
} | [
"func",
"GetSession",
"(",
"req",
"*",
"http",
".",
"Request",
")",
"Session",
"{",
"if",
"s",
",",
"ok",
":=",
"req",
".",
"Context",
"(",
")",
".",
"Value",
"(",
"sessionKey",
")",
".",
"(",
"*",
"session",
")",
";",
"ok",
"{",
"return",
"s",
... | // GetSession returns the session stored in the request context | [
"GetSession",
"returns",
"the",
"session",
"stored",
"in",
"the",
"request",
"context"
] | 40b49004abeec57f602bad8509521a865b2be95e | https://github.com/GoIncremental/negroni-sessions/blob/40b49004abeec57f602bad8509521a865b2be95e/sessions.go#L119-L124 |
142,944 | GoIncremental/negroni-sessions | dynamostore/main.go | New | func New(accessKey string, secretKey string, tableName string, region string, keyPairs ...[]byte) (nSessions.Store, error) {
store, err := dynstore.NewDynamoStore(accessKey, secretKey, tableName, region, keyPairs...)
if err != nil {
return nil, err
}
return &dynamoStore{store}, nil
} | go | func New(accessKey string, secretKey string, tableName string, region string, keyPairs ...[]byte) (nSessions.Store, error) {
store, err := dynstore.NewDynamoStore(accessKey, secretKey, tableName, region, keyPairs...)
if err != nil {
return nil, err
}
return &dynamoStore{store}, nil
} | [
"func",
"New",
"(",
"accessKey",
"string",
",",
"secretKey",
"string",
",",
"tableName",
"string",
",",
"region",
"string",
",",
"keyPairs",
"...",
"[",
"]",
"byte",
")",
"(",
"nSessions",
".",
"Store",
",",
"error",
")",
"{",
"store",
",",
"err",
":="... | //New returns a new Dynamodb store | [
"New",
"returns",
"a",
"new",
"Dynamodb",
"store"
] | 40b49004abeec57f602bad8509521a865b2be95e | https://github.com/GoIncremental/negroni-sessions/blob/40b49004abeec57f602bad8509521a865b2be95e/dynamostore/main.go#L10-L17 |
142,945 | NebulousLabs/merkletree | tree.go | sum | func sum(h hash.Hash, data ...[]byte) []byte {
h.Reset()
for _, d := range data {
// the Hash interface specifies that Write never returns an error
_, _ = h.Write(d)
}
return h.Sum(nil)
} | go | func sum(h hash.Hash, data ...[]byte) []byte {
h.Reset()
for _, d := range data {
// the Hash interface specifies that Write never returns an error
_, _ = h.Write(d)
}
return h.Sum(nil)
} | [
"func",
"sum",
"(",
"h",
"hash",
".",
"Hash",
",",
"data",
"...",
"[",
"]",
"byte",
")",
"[",
"]",
"byte",
"{",
"h",
".",
"Reset",
"(",
")",
"\n",
"for",
"_",
",",
"d",
":=",
"range",
"data",
"{",
"// the Hash interface specifies that Write never retur... | // sum returns the hash of the input data using the specified algorithm. | [
"sum",
"returns",
"the",
"hash",
"of",
"the",
"input",
"data",
"using",
"the",
"specified",
"algorithm",
"."
] | 08d5d54b07f5e86a27f2d7431d0bc0300f5a9328 | https://github.com/NebulousLabs/merkletree/blob/08d5d54b07f5e86a27f2d7431d0bc0300f5a9328/tree.go#L51-L58 |
142,946 | NebulousLabs/merkletree | tree.go | joinSubTrees | func joinSubTrees(h hash.Hash, a, b *subTree) *subTree {
if DEBUG {
if b.next != a {
panic("invalid subtree join - 'a' is not paired with 'b'")
}
if a.height < b.height {
panic("invalid subtree presented - height mismatch")
}
}
return &subTree{
next: a.next,
height: a.height + 1,
sum: nodeS... | go | func joinSubTrees(h hash.Hash, a, b *subTree) *subTree {
if DEBUG {
if b.next != a {
panic("invalid subtree join - 'a' is not paired with 'b'")
}
if a.height < b.height {
panic("invalid subtree presented - height mismatch")
}
}
return &subTree{
next: a.next,
height: a.height + 1,
sum: nodeS... | [
"func",
"joinSubTrees",
"(",
"h",
"hash",
".",
"Hash",
",",
"a",
",",
"b",
"*",
"subTree",
")",
"*",
"subTree",
"{",
"if",
"DEBUG",
"{",
"if",
"b",
".",
"next",
"!=",
"a",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"a",
".",
... | // joinSubTrees combines two equal sized subTrees into a larger subTree. | [
"joinSubTrees",
"combines",
"two",
"equal",
"sized",
"subTrees",
"into",
"a",
"larger",
"subTree",
"."
] | 08d5d54b07f5e86a27f2d7431d0bc0300f5a9328 | https://github.com/NebulousLabs/merkletree/blob/08d5d54b07f5e86a27f2d7431d0bc0300f5a9328/tree.go#L75-L90 |
142,947 | NebulousLabs/merkletree | tree.go | PushSubTree | func (t *Tree) PushSubTree(height int, sum []byte) error {
// Check if the cached tree that is pushed contains the element at
// proofIndex. This is not allowed.
newIndex := t.currentIndex + 1<<uint64(height)
if t.proofTree && (t.currentIndex == t.proofIndex ||
(t.currentIndex < t.proofIndex && t.proofIndex < new... | go | func (t *Tree) PushSubTree(height int, sum []byte) error {
// Check if the cached tree that is pushed contains the element at
// proofIndex. This is not allowed.
newIndex := t.currentIndex + 1<<uint64(height)
if t.proofTree && (t.currentIndex == t.proofIndex ||
(t.currentIndex < t.proofIndex && t.proofIndex < new... | [
"func",
"(",
"t",
"*",
"Tree",
")",
"PushSubTree",
"(",
"height",
"int",
",",
"sum",
"[",
"]",
"byte",
")",
"error",
"{",
"// Check if the cached tree that is pushed contains the element at",
"// proofIndex. This is not allowed.",
"newIndex",
":=",
"t",
".",
"currentI... | // PushSubTree pushes a cached subtree into the merkle tree. The subtree has to
// be smaller than the smallest subtree in the merkle tree, it has to be
// balanced and it can't contain the element that needs to be proven. Since we
// can't tell if a subTree is balanced, we can't sanity check for unbalanced
// trees. ... | [
"PushSubTree",
"pushes",
"a",
"cached",
"subtree",
"into",
"the",
"merkle",
"tree",
".",
"The",
"subtree",
"has",
"to",
"be",
"smaller",
"than",
"the",
"smallest",
"subtree",
"in",
"the",
"merkle",
"tree",
"it",
"has",
"to",
"be",
"balanced",
"and",
"it",
... | 08d5d54b07f5e86a27f2d7431d0bc0300f5a9328 | https://github.com/NebulousLabs/merkletree/blob/08d5d54b07f5e86a27f2d7431d0bc0300f5a9328/tree.go#L221-L263 |
142,948 | NebulousLabs/merkletree | tree.go | Root | func (t *Tree) Root() []byte {
// If the Tree is empty, return nil.
if t.head == nil {
return nil
}
// The root is formed by hashing together subTrees in order from least in
// height to greatest in height. The taller subtree is the first subtree in
// the join.
current := t.head
for current.next != nil {
... | go | func (t *Tree) Root() []byte {
// If the Tree is empty, return nil.
if t.head == nil {
return nil
}
// The root is formed by hashing together subTrees in order from least in
// height to greatest in height. The taller subtree is the first subtree in
// the join.
current := t.head
for current.next != nil {
... | [
"func",
"(",
"t",
"*",
"Tree",
")",
"Root",
"(",
")",
"[",
"]",
"byte",
"{",
"// If the Tree is empty, return nil.",
"if",
"t",
".",
"head",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"// The root is formed by hashing together subTrees in order from lea... | // Root returns the Merkle root of the data that has been pushed. | [
"Root",
"returns",
"the",
"Merkle",
"root",
"of",
"the",
"data",
"that",
"has",
"been",
"pushed",
"."
] | 08d5d54b07f5e86a27f2d7431d0bc0300f5a9328 | https://github.com/NebulousLabs/merkletree/blob/08d5d54b07f5e86a27f2d7431d0bc0300f5a9328/tree.go#L266-L280 |
142,949 | NebulousLabs/merkletree | tree.go | SetIndex | func (t *Tree) SetIndex(i uint64) error {
if t.head != nil {
return errors.New("cannot call SetIndex on Tree if Tree has not been reset")
}
t.proofTree = true
t.proofIndex = i
return nil
} | go | func (t *Tree) SetIndex(i uint64) error {
if t.head != nil {
return errors.New("cannot call SetIndex on Tree if Tree has not been reset")
}
t.proofTree = true
t.proofIndex = i
return nil
} | [
"func",
"(",
"t",
"*",
"Tree",
")",
"SetIndex",
"(",
"i",
"uint64",
")",
"error",
"{",
"if",
"t",
".",
"head",
"!=",
"nil",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"t",
".",
"proofTree",
"=",
"true",
"\n",
... | // SetIndex will tell the Tree to create a storage proof for the leaf at the
// input index. SetIndex must be called on an empty tree. | [
"SetIndex",
"will",
"tell",
"the",
"Tree",
"to",
"create",
"a",
"storage",
"proof",
"for",
"the",
"leaf",
"at",
"the",
"input",
"index",
".",
"SetIndex",
"must",
"be",
"called",
"on",
"an",
"empty",
"tree",
"."
] | 08d5d54b07f5e86a27f2d7431d0bc0300f5a9328 | https://github.com/NebulousLabs/merkletree/blob/08d5d54b07f5e86a27f2d7431d0bc0300f5a9328/tree.go#L284-L291 |
142,950 | NebulousLabs/merkletree | tree.go | joinAllSubTrees | func (t *Tree) joinAllSubTrees() {
for t.head.next != nil && t.head.height == t.head.next.height {
// Before combining subtrees, check whether one of the subtree hashes
// needs to be added to the proof set. This is going to be true IFF the
// subtrees being combined are one height higher than the previous
// ... | go | func (t *Tree) joinAllSubTrees() {
for t.head.next != nil && t.head.height == t.head.next.height {
// Before combining subtrees, check whether one of the subtree hashes
// needs to be added to the proof set. This is going to be true IFF the
// subtrees being combined are one height higher than the previous
// ... | [
"func",
"(",
"t",
"*",
"Tree",
")",
"joinAllSubTrees",
"(",
")",
"{",
"for",
"t",
".",
"head",
".",
"next",
"!=",
"nil",
"&&",
"t",
".",
"head",
".",
"height",
"==",
"t",
".",
"head",
".",
"next",
".",
"height",
"{",
"// Before combining subtrees, ch... | // joinAllSubTrees inserts the subTree at t.head into the Tree. As long as the
// height of the next subTree is the same as the height of the current subTree,
// the two will be combined into a single subTree of height n+1. | [
"joinAllSubTrees",
"inserts",
"the",
"subTree",
"at",
"t",
".",
"head",
"into",
"the",
"Tree",
".",
"As",
"long",
"as",
"the",
"height",
"of",
"the",
"next",
"subTree",
"is",
"the",
"same",
"as",
"the",
"height",
"of",
"the",
"current",
"subTree",
"the",... | 08d5d54b07f5e86a27f2d7431d0bc0300f5a9328 | https://github.com/NebulousLabs/merkletree/blob/08d5d54b07f5e86a27f2d7431d0bc0300f5a9328/tree.go#L296-L331 |
142,951 | NebulousLabs/merkletree | verify.go | VerifyProof | func VerifyProof(h hash.Hash, merkleRoot []byte, proofSet [][]byte, proofIndex uint64, numLeaves uint64) bool {
// Return false for nonsense input. A switch statement is used so that the
// cover tool will reveal if a case is not covered by the test suite. This
// would not be possible using a single if statement du... | go | func VerifyProof(h hash.Hash, merkleRoot []byte, proofSet [][]byte, proofIndex uint64, numLeaves uint64) bool {
// Return false for nonsense input. A switch statement is used so that the
// cover tool will reveal if a case is not covered by the test suite. This
// would not be possible using a single if statement du... | [
"func",
"VerifyProof",
"(",
"h",
"hash",
".",
"Hash",
",",
"merkleRoot",
"[",
"]",
"byte",
",",
"proofSet",
"[",
"]",
"[",
"]",
"byte",
",",
"proofIndex",
"uint64",
",",
"numLeaves",
"uint64",
")",
"bool",
"{",
"// Return false for nonsense input. A switch sta... | // VerifyProof takes a Merkle root, a proofSet, and a proofIndex and returns
// true if the first element of the proof set is a leaf of data in the Merkle
// root. False is returned if the proof set or Merkle root is nil, and if
// 'numLeaves' equals 0. | [
"VerifyProof",
"takes",
"a",
"Merkle",
"root",
"a",
"proofSet",
"and",
"a",
"proofIndex",
"and",
"returns",
"true",
"if",
"the",
"first",
"element",
"of",
"the",
"proof",
"set",
"is",
"a",
"leaf",
"of",
"data",
"in",
"the",
"Merkle",
"root",
".",
"False"... | 08d5d54b07f5e86a27f2d7431d0bc0300f5a9328 | https://github.com/NebulousLabs/merkletree/blob/08d5d54b07f5e86a27f2d7431d0bc0300f5a9328/verify.go#L12-L120 |
142,952 | NebulousLabs/merkletree | readers.go | ReadAll | func (t *Tree) ReadAll(r io.Reader, segmentSize int) error {
for {
segment := make([]byte, segmentSize)
n, readErr := io.ReadFull(r, segment)
if readErr == io.EOF {
// All data has been read.
break
} else if readErr == io.ErrUnexpectedEOF {
// This is the last segment, and there aren't enough bytes to... | go | func (t *Tree) ReadAll(r io.Reader, segmentSize int) error {
for {
segment := make([]byte, segmentSize)
n, readErr := io.ReadFull(r, segment)
if readErr == io.EOF {
// All data has been read.
break
} else if readErr == io.ErrUnexpectedEOF {
// This is the last segment, and there aren't enough bytes to... | [
"func",
"(",
"t",
"*",
"Tree",
")",
"ReadAll",
"(",
"r",
"io",
".",
"Reader",
",",
"segmentSize",
"int",
")",
"error",
"{",
"for",
"{",
"segment",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"segmentSize",
")",
"\n",
"n",
",",
"readErr",
":=",
"io"... | // ReadAll will read segments of size 'segmentSize' and push them into the tree
// until EOF is reached. Success will return 'err == nil', not 'err == EOF'. No
// padding is added to the data, so the last element may be smaller than
// 'segmentSize'. | [
"ReadAll",
"will",
"read",
"segments",
"of",
"size",
"segmentSize",
"and",
"push",
"them",
"into",
"the",
"tree",
"until",
"EOF",
"is",
"reached",
".",
"Success",
"will",
"return",
"err",
"==",
"nil",
"not",
"err",
"==",
"EOF",
".",
"No",
"padding",
"is"... | 08d5d54b07f5e86a27f2d7431d0bc0300f5a9328 | https://github.com/NebulousLabs/merkletree/blob/08d5d54b07f5e86a27f2d7431d0bc0300f5a9328/readers.go#L13-L30 |
142,953 | NebulousLabs/merkletree | readers.go | ReaderRoot | func ReaderRoot(r io.Reader, h hash.Hash, segmentSize int) (root []byte, err error) {
tree := New(h)
err = tree.ReadAll(r, segmentSize)
if err != nil {
return
}
root = tree.Root()
return
} | go | func ReaderRoot(r io.Reader, h hash.Hash, segmentSize int) (root []byte, err error) {
tree := New(h)
err = tree.ReadAll(r, segmentSize)
if err != nil {
return
}
root = tree.Root()
return
} | [
"func",
"ReaderRoot",
"(",
"r",
"io",
".",
"Reader",
",",
"h",
"hash",
".",
"Hash",
",",
"segmentSize",
"int",
")",
"(",
"root",
"[",
"]",
"byte",
",",
"err",
"error",
")",
"{",
"tree",
":=",
"New",
"(",
"h",
")",
"\n",
"err",
"=",
"tree",
".",... | // ReaderRoot returns the Merkle root of the data read from the reader, where
// each leaf is 'segmentSize' long and 'h' is used as the hashing function. All
// leaves will be 'segmentSize' bytes except the last leaf, which will not be
// padded out if there are not enough bytes remaining in the reader. | [
"ReaderRoot",
"returns",
"the",
"Merkle",
"root",
"of",
"the",
"data",
"read",
"from",
"the",
"reader",
"where",
"each",
"leaf",
"is",
"segmentSize",
"long",
"and",
"h",
"is",
"used",
"as",
"the",
"hashing",
"function",
".",
"All",
"leaves",
"will",
"be",
... | 08d5d54b07f5e86a27f2d7431d0bc0300f5a9328 | https://github.com/NebulousLabs/merkletree/blob/08d5d54b07f5e86a27f2d7431d0bc0300f5a9328/readers.go#L36-L44 |
142,954 | NebulousLabs/merkletree | readers.go | BuildReaderProof | func BuildReaderProof(r io.Reader, h hash.Hash, segmentSize int, index uint64) (root []byte, proofSet [][]byte, numLeaves uint64, err error) {
tree := New(h)
err = tree.SetIndex(index)
if err != nil {
// This code should be unreachable - SetIndex will only return an error
// if the tree is not empty, and yet the... | go | func BuildReaderProof(r io.Reader, h hash.Hash, segmentSize int, index uint64) (root []byte, proofSet [][]byte, numLeaves uint64, err error) {
tree := New(h)
err = tree.SetIndex(index)
if err != nil {
// This code should be unreachable - SetIndex will only return an error
// if the tree is not empty, and yet the... | [
"func",
"BuildReaderProof",
"(",
"r",
"io",
".",
"Reader",
",",
"h",
"hash",
".",
"Hash",
",",
"segmentSize",
"int",
",",
"index",
"uint64",
")",
"(",
"root",
"[",
"]",
"byte",
",",
"proofSet",
"[",
"]",
"[",
"]",
"byte",
",",
"numLeaves",
"uint64",
... | // BuildReaderProof returns a proof that certain data is in the merkle tree
// created by the data in the reader. The merkle root, set of proofs, and the
// number of leaves in the Merkle tree are all returned. All leaves will we
// 'segmentSize' bytes except the last leaf, which will not be padded out if
// there are ... | [
"BuildReaderProof",
"returns",
"a",
"proof",
"that",
"certain",
"data",
"is",
"in",
"the",
"merkle",
"tree",
"created",
"by",
"the",
"data",
"in",
"the",
"reader",
".",
"The",
"merkle",
"root",
"set",
"of",
"proofs",
"and",
"the",
"number",
"of",
"leaves",... | 08d5d54b07f5e86a27f2d7431d0bc0300f5a9328 | https://github.com/NebulousLabs/merkletree/blob/08d5d54b07f5e86a27f2d7431d0bc0300f5a9328/readers.go#L51-L70 |
142,955 | NebulousLabs/merkletree | cachedtree.go | NewCachedTree | func NewCachedTree(h hash.Hash, cachedNodeHeight uint64) *CachedTree {
return &CachedTree{
cachedNodeHeight: cachedNodeHeight,
Tree: Tree{
hash: h,
cachedTree: true,
},
}
} | go | func NewCachedTree(h hash.Hash, cachedNodeHeight uint64) *CachedTree {
return &CachedTree{
cachedNodeHeight: cachedNodeHeight,
Tree: Tree{
hash: h,
cachedTree: true,
},
}
} | [
"func",
"NewCachedTree",
"(",
"h",
"hash",
".",
"Hash",
",",
"cachedNodeHeight",
"uint64",
")",
"*",
"CachedTree",
"{",
"return",
"&",
"CachedTree",
"{",
"cachedNodeHeight",
":",
"cachedNodeHeight",
",",
"Tree",
":",
"Tree",
"{",
"hash",
":",
"h",
",",
"ca... | // NewCachedTree initializes a CachedTree with a hash object, which will be
// used when hashing the input. | [
"NewCachedTree",
"initializes",
"a",
"CachedTree",
"with",
"a",
"hash",
"object",
"which",
"will",
"be",
"used",
"when",
"hashing",
"the",
"input",
"."
] | 08d5d54b07f5e86a27f2d7431d0bc0300f5a9328 | https://github.com/NebulousLabs/merkletree/blob/08d5d54b07f5e86a27f2d7431d0bc0300f5a9328/cachedtree.go#L20-L30 |
142,956 | NebulousLabs/merkletree | cachedtree.go | Prove | func (ct *CachedTree) Prove(cachedProofSet [][]byte) (merkleRoot []byte, proofSet [][]byte, proofIndex uint64, numLeaves uint64) {
// Determine the proof index within the full tree, and the number of leaves
// within the full tree.
leavesPerCachedNode := uint64(1) << ct.cachedNodeHeight
numLeaves = leavesPerCachedN... | go | func (ct *CachedTree) Prove(cachedProofSet [][]byte) (merkleRoot []byte, proofSet [][]byte, proofIndex uint64, numLeaves uint64) {
// Determine the proof index within the full tree, and the number of leaves
// within the full tree.
leavesPerCachedNode := uint64(1) << ct.cachedNodeHeight
numLeaves = leavesPerCachedN... | [
"func",
"(",
"ct",
"*",
"CachedTree",
")",
"Prove",
"(",
"cachedProofSet",
"[",
"]",
"[",
"]",
"byte",
")",
"(",
"merkleRoot",
"[",
"]",
"byte",
",",
"proofSet",
"[",
"]",
"[",
"]",
"byte",
",",
"proofIndex",
"uint64",
",",
"numLeaves",
"uint64",
")"... | // Prove will create a proof that the leaf at the indicated index is a part of
// the data represented by the Merkle root of the Cached Tree. The CachedTree
// needs the proof set proving that the index is an element of the cached
// element in order to create a correct proof. After proof is called, the
// CachedTree i... | [
"Prove",
"will",
"create",
"a",
"proof",
"that",
"the",
"leaf",
"at",
"the",
"indicated",
"index",
"is",
"a",
"part",
"of",
"the",
"data",
"represented",
"by",
"the",
"Merkle",
"root",
"of",
"the",
"Cached",
"Tree",
".",
"The",
"CachedTree",
"needs",
"th... | 08d5d54b07f5e86a27f2d7431d0bc0300f5a9328 | https://github.com/NebulousLabs/merkletree/blob/08d5d54b07f5e86a27f2d7431d0bc0300f5a9328/cachedtree.go#L37-L59 |
142,957 | NebulousLabs/merkletree | cachedtree.go | SetIndex | func (ct *CachedTree) SetIndex(i uint64) error {
if ct.head != nil {
return errors.New("cannot call SetIndex on Tree if Tree has not been reset")
}
ct.trueProofIndex = i
return ct.Tree.SetIndex(i / (1 << ct.cachedNodeHeight))
} | go | func (ct *CachedTree) SetIndex(i uint64) error {
if ct.head != nil {
return errors.New("cannot call SetIndex on Tree if Tree has not been reset")
}
ct.trueProofIndex = i
return ct.Tree.SetIndex(i / (1 << ct.cachedNodeHeight))
} | [
"func",
"(",
"ct",
"*",
"CachedTree",
")",
"SetIndex",
"(",
"i",
"uint64",
")",
"error",
"{",
"if",
"ct",
".",
"head",
"!=",
"nil",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"ct",
".",
"trueProofIndex",
"=",
"i",... | // SetIndex will inform the CachedTree of the index of the leaf for which a
// storage proof is being created. The index should be the index of the actual
// leaf, and not the index of the cached element containing the leaf. SetIndex
// must be called on empty CachedTree. | [
"SetIndex",
"will",
"inform",
"the",
"CachedTree",
"of",
"the",
"index",
"of",
"the",
"leaf",
"for",
"which",
"a",
"storage",
"proof",
"is",
"being",
"created",
".",
"The",
"index",
"should",
"be",
"the",
"index",
"of",
"the",
"actual",
"leaf",
"and",
"n... | 08d5d54b07f5e86a27f2d7431d0bc0300f5a9328 | https://github.com/NebulousLabs/merkletree/blob/08d5d54b07f5e86a27f2d7431d0bc0300f5a9328/cachedtree.go#L65-L71 |
142,958 | NebulousLabs/merkletree | fuzz.go | Fuzz | func Fuzz(data []byte) int {
// Use the first two bytes to determine the proof index.
if len(data) < 2 {
return -1
}
index := 256*uint64(data[0]) + uint64(data[1])
data = data[2:]
// Build a reader proof for index 'index' using the remaining data as input
// to the reader. '64' is chosen as the only input siz... | go | func Fuzz(data []byte) int {
// Use the first two bytes to determine the proof index.
if len(data) < 2 {
return -1
}
index := 256*uint64(data[0]) + uint64(data[1])
data = data[2:]
// Build a reader proof for index 'index' using the remaining data as input
// to the reader. '64' is chosen as the only input siz... | [
"func",
"Fuzz",
"(",
"data",
"[",
"]",
"byte",
")",
"int",
"{",
"// Use the first two bytes to determine the proof index.",
"if",
"len",
"(",
"data",
")",
"<",
"2",
"{",
"return",
"-",
"1",
"\n",
"}",
"\n",
"index",
":=",
"256",
"*",
"uint64",
"(",
"data... | // Fuzz is called by go-fuzz to look for inputs to BuildReaderProof that will
// not verify correctly. | [
"Fuzz",
"is",
"called",
"by",
"go",
"-",
"fuzz",
"to",
"look",
"for",
"inputs",
"to",
"BuildReaderProof",
"that",
"will",
"not",
"verify",
"correctly",
"."
] | 08d5d54b07f5e86a27f2d7431d0bc0300f5a9328 | https://github.com/NebulousLabs/merkletree/blob/08d5d54b07f5e86a27f2d7431d0bc0300f5a9328/fuzz.go#L13-L38 |
142,959 | NebulousLabs/merkletree | fuzz.go | FuzzReadSubTreesNoProof | func FuzzReadSubTreesNoProof(data []byte) int {
buildAndCompareTreesFromFuzz(data, math.MaxUint64)
if len(data) > 2 {
return 1
}
return 0
} | go | func FuzzReadSubTreesNoProof(data []byte) int {
buildAndCompareTreesFromFuzz(data, math.MaxUint64)
if len(data) > 2 {
return 1
}
return 0
} | [
"func",
"FuzzReadSubTreesNoProof",
"(",
"data",
"[",
"]",
"byte",
")",
"int",
"{",
"buildAndCompareTreesFromFuzz",
"(",
"data",
",",
"math",
".",
"MaxUint64",
")",
"\n",
"if",
"len",
"(",
"data",
")",
">",
"2",
"{",
"return",
"1",
"\n",
"}",
"\n",
"ret... | // FuzzReadSubTreesNoProof can be used by go-fuzz to test creating a merkle
// tree from cached subTrees. | [
"FuzzReadSubTreesNoProof",
"can",
"be",
"used",
"by",
"go",
"-",
"fuzz",
"to",
"test",
"creating",
"a",
"merkle",
"tree",
"from",
"cached",
"subTrees",
"."
] | 08d5d54b07f5e86a27f2d7431d0bc0300f5a9328 | https://github.com/NebulousLabs/merkletree/blob/08d5d54b07f5e86a27f2d7431d0bc0300f5a9328/fuzz.go#L70-L76 |
142,960 | NebulousLabs/merkletree | fuzz.go | buildAndCompareTreesFromFuzz | func buildAndCompareTreesFromFuzz(data []byte, proofIndex uint64) (cachedTree *Tree, numLeaves uint64) {
hash := sha256.New()
tree := New(hash)
cachedTree = New(hash)
if proofIndex != math.MaxUint64 {
if err := cachedTree.SetIndex(proofIndex); err != nil {
panic(err)
}
}
for _, b := range data {
b = b %... | go | func buildAndCompareTreesFromFuzz(data []byte, proofIndex uint64) (cachedTree *Tree, numLeaves uint64) {
hash := sha256.New()
tree := New(hash)
cachedTree = New(hash)
if proofIndex != math.MaxUint64 {
if err := cachedTree.SetIndex(proofIndex); err != nil {
panic(err)
}
}
for _, b := range data {
b = b %... | [
"func",
"buildAndCompareTreesFromFuzz",
"(",
"data",
"[",
"]",
"byte",
",",
"proofIndex",
"uint64",
")",
"(",
"cachedTree",
"*",
"Tree",
",",
"numLeaves",
"uint64",
")",
"{",
"hash",
":=",
"sha256",
".",
"New",
"(",
")",
"\n",
"tree",
":=",
"New",
"(",
... | // buildAndCompareTreesFromFuzz will read the input data and create a subTree
// or leaf for each byte of the input data. It returns the cached tree. | [
"buildAndCompareTreesFromFuzz",
"will",
"read",
"the",
"input",
"data",
"and",
"create",
"a",
"subTree",
"or",
"leaf",
"for",
"each",
"byte",
"of",
"the",
"input",
"data",
".",
"It",
"returns",
"the",
"cached",
"tree",
"."
] | 08d5d54b07f5e86a27f2d7431d0bc0300f5a9328 | https://github.com/NebulousLabs/merkletree/blob/08d5d54b07f5e86a27f2d7431d0bc0300f5a9328/fuzz.go#L80-L118 |
142,961 | mackerelio/go-mackerel-plugin | mackerel-plugin.go | OutputDefinitions | func (mp *MackerelPlugin) OutputDefinitions() {
fmt.Fprintln(mp.getWriter(), "# mackerel-agent-plugin")
graphs := make(map[string]Graphs)
for key, graph := range mp.GraphDefinition() {
g := graph
k := key
if p, ok := mp.Plugin.(PluginWithPrefix); ok {
prefix := p.MetricKeyPrefix()
if k == "" {
k = pr... | go | func (mp *MackerelPlugin) OutputDefinitions() {
fmt.Fprintln(mp.getWriter(), "# mackerel-agent-plugin")
graphs := make(map[string]Graphs)
for key, graph := range mp.GraphDefinition() {
g := graph
k := key
if p, ok := mp.Plugin.(PluginWithPrefix); ok {
prefix := p.MetricKeyPrefix()
if k == "" {
k = pr... | [
"func",
"(",
"mp",
"*",
"MackerelPlugin",
")",
"OutputDefinitions",
"(",
")",
"{",
"fmt",
".",
"Fprintln",
"(",
"mp",
".",
"getWriter",
"(",
")",
",",
"\"",
"\"",
")",
"\n",
"graphs",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"Graphs",
")",
"\n... | // OutputDefinitions outputs graph definitions | [
"OutputDefinitions",
"outputs",
"graph",
"definitions"
] | d8f0ff0871b9e0f85db920041749fa052f42521d | https://github.com/mackerelio/go-mackerel-plugin/blob/d8f0ff0871b9e0f85db920041749fa052f42521d/mackerel-plugin.go#L290-L324 |
142,962 | stephanos/clock | mock.go | NewMock | func NewMock() Mock {
return &mock{
base: time.Now(),
setAt: time.Now(),
sleep: -1,
}
} | go | func NewMock() Mock {
return &mock{
base: time.Now(),
setAt: time.Now(),
sleep: -1,
}
} | [
"func",
"NewMock",
"(",
")",
"Mock",
"{",
"return",
"&",
"mock",
"{",
"base",
":",
"time",
".",
"Now",
"(",
")",
",",
"setAt",
":",
"time",
".",
"Now",
"(",
")",
",",
"sleep",
":",
"-",
"1",
",",
"}",
"\n",
"}"
] | // NewMock returns a new manipulable Clock. | [
"NewMock",
"returns",
"a",
"new",
"manipulable",
"Clock",
"."
] | e4ec0ab5053ee441dab6c55d0c3633f275269f72 | https://github.com/stephanos/clock/blob/e4ec0ab5053ee441dab6c55d0c3633f275269f72/mock.go#L19-L25 |
142,963 | stephanos/clock | mock.go | elapsed | func (c *mock) elapsed() time.Duration {
return time.Now().Sub(c.setAt)
} | go | func (c *mock) elapsed() time.Duration {
return time.Now().Sub(c.setAt)
} | [
"func",
"(",
"c",
"*",
"mock",
")",
"elapsed",
"(",
")",
"time",
".",
"Duration",
"{",
"return",
"time",
".",
"Now",
"(",
")",
".",
"Sub",
"(",
"c",
".",
"setAt",
")",
"\n",
"}"
] | // elapsed returns the Duration between the date the time was set and now. | [
"elapsed",
"returns",
"the",
"Duration",
"between",
"the",
"date",
"the",
"time",
"was",
"set",
"and",
"now",
"."
] | e4ec0ab5053ee441dab6c55d0c3633f275269f72 | https://github.com/stephanos/clock/blob/e4ec0ab5053ee441dab6c55d0c3633f275269f72/mock.go#L120-L122 |
142,964 | bjarneh/latinx | reader.go | Read | func (r *LatinReader) Read(p []byte) (n int, err error) {
var p2, utf8bytes []byte
var n2 int
var e2, e3 error
p2 = make([]byte, len(p))
n2, e2 = r.reader.Read(p2)
if e2 == nil || e2 == io.EOF {
utf8bytes, e3 = r.converter.Decode(p2[:n2])
if e3 != nil {
return 0, e3
}
r.buf.Write(utf8bytes) // n ... | go | func (r *LatinReader) Read(p []byte) (n int, err error) {
var p2, utf8bytes []byte
var n2 int
var e2, e3 error
p2 = make([]byte, len(p))
n2, e2 = r.reader.Read(p2)
if e2 == nil || e2 == io.EOF {
utf8bytes, e3 = r.converter.Decode(p2[:n2])
if e3 != nil {
return 0, e3
}
r.buf.Write(utf8bytes) // n ... | [
"func",
"(",
"r",
"*",
"LatinReader",
")",
"Read",
"(",
"p",
"[",
"]",
"byte",
")",
"(",
"n",
"int",
",",
"err",
"error",
")",
"{",
"var",
"p2",
",",
"utf8bytes",
"[",
"]",
"byte",
"\n",
"var",
"n2",
"int",
"\n",
"var",
"e2",
",",
"e3",
"erro... | // Read from underlying io.Reader and decode to UTF-8 and return result. | [
"Read",
"from",
"underlying",
"io",
".",
"Reader",
"and",
"decode",
"to",
"UTF",
"-",
"8",
"and",
"return",
"result",
"."
] | 4dfe9ba2a293f28a5e06fc7ffe56b1d71a47b8c8 | https://github.com/bjarneh/latinx/blob/4dfe9ba2a293f28a5e06fc7ffe56b1d71a47b8c8/reader.go#L36-L64 |
142,965 | bjarneh/latinx | latinx.go | Available | func Available() (all []string) {
for _, v := range converters {
all = append(all, v.String())
}
return
} | go | func Available() (all []string) {
for _, v := range converters {
all = append(all, v.String())
}
return
} | [
"func",
"Available",
"(",
")",
"(",
"all",
"[",
"]",
"string",
")",
"{",
"for",
"_",
",",
"v",
":=",
"range",
"converters",
"{",
"all",
"=",
"append",
"(",
"all",
",",
"v",
".",
"String",
"(",
")",
")",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] | // Return the String representation of all available encodings | [
"Return",
"the",
"String",
"representation",
"of",
"all",
"available",
"encodings"
] | 4dfe9ba2a293f28a5e06fc7ffe56b1d71a47b8c8 | https://github.com/bjarneh/latinx/blob/4dfe9ba2a293f28a5e06fc7ffe56b1d71a47b8c8/latinx.go#L124-L129 |
142,966 | bjarneh/latinx | latinx.go | Decode | func (c *Converter) Decode(latin []byte) (utf_8 []byte, err error) {
var offset, i int
var ok bool
var utf8symbol []byte
var errmsg string
var buf *bytes.Buffer
buf = bytes.NewBuffer(make([]byte, len(latin)*2))
buf.Reset()
for offset < len(latin) {
if latin[offset] < utf8.RuneSelf {
buf.WriteByte(latin... | go | func (c *Converter) Decode(latin []byte) (utf_8 []byte, err error) {
var offset, i int
var ok bool
var utf8symbol []byte
var errmsg string
var buf *bytes.Buffer
buf = bytes.NewBuffer(make([]byte, len(latin)*2))
buf.Reset()
for offset < len(latin) {
if latin[offset] < utf8.RuneSelf {
buf.WriteByte(latin... | [
"func",
"(",
"c",
"*",
"Converter",
")",
"Decode",
"(",
"latin",
"[",
"]",
"byte",
")",
"(",
"utf_8",
"[",
"]",
"byte",
",",
"err",
"error",
")",
"{",
"var",
"offset",
",",
"i",
"int",
"\n",
"var",
"ok",
"bool",
"\n",
"var",
"utf8symbol",
"[",
... | // Convert a ISO 8859 byte sequence into a UTF-8 byte sequence.
// If this function returns a UnknownByteError, the charset of the
// Converter does not have a unicode mapping for a byte found in latin. | [
"Convert",
"a",
"ISO",
"8859",
"byte",
"sequence",
"into",
"a",
"UTF",
"-",
"8",
"byte",
"sequence",
".",
"If",
"this",
"function",
"returns",
"a",
"UnknownByteError",
"the",
"charset",
"of",
"the",
"Converter",
"does",
"not",
"have",
"a",
"unicode",
"mapp... | 4dfe9ba2a293f28a5e06fc7ffe56b1d71a47b8c8 | https://github.com/bjarneh/latinx/blob/4dfe9ba2a293f28a5e06fc7ffe56b1d71a47b8c8/latinx.go#L180-L210 |
142,967 | bjarneh/latinx | latinx.go | Decode | func Decode(charset int, latin []byte) (utf_8 []byte, err error) {
return converters[charset].Decode(latin)
} | go | func Decode(charset int, latin []byte) (utf_8 []byte, err error) {
return converters[charset].Decode(latin)
} | [
"func",
"Decode",
"(",
"charset",
"int",
",",
"latin",
"[",
"]",
"byte",
")",
"(",
"utf_8",
"[",
"]",
"byte",
",",
"err",
"error",
")",
"{",
"return",
"converters",
"[",
"charset",
"]",
".",
"Decode",
"(",
"latin",
")",
"\n",
"}"
] | // Convert a ISO-8859 encoded slice to a UTF-8 encoded slice | [
"Convert",
"a",
"ISO",
"-",
"8859",
"encoded",
"slice",
"to",
"a",
"UTF",
"-",
"8",
"encoded",
"slice"
] | 4dfe9ba2a293f28a5e06fc7ffe56b1d71a47b8c8 | https://github.com/bjarneh/latinx/blob/4dfe9ba2a293f28a5e06fc7ffe56b1d71a47b8c8/latinx.go#L220-L222 |
142,968 | bjarneh/latinx | example/giconv/main.go | main | func main() {
var inputbytes, utf8bytes, outputbytes []byte
flag.Parse()
// print help/version/list/usage...
someSortOfHelp()
// read input from stdin or file
inputbytes = getInputBytes()
// convert inputformat to UTF-8 (decode)
utf8bytes = getUtf8FromInput(inputbytes)
// convert UTF-8 to output format (... | go | func main() {
var inputbytes, utf8bytes, outputbytes []byte
flag.Parse()
// print help/version/list/usage...
someSortOfHelp()
// read input from stdin or file
inputbytes = getInputBytes()
// convert inputformat to UTF-8 (decode)
utf8bytes = getUtf8FromInput(inputbytes)
// convert UTF-8 to output format (... | [
"func",
"main",
"(",
")",
"{",
"var",
"inputbytes",
",",
"utf8bytes",
",",
"outputbytes",
"[",
"]",
"byte",
"\n\n",
"flag",
".",
"Parse",
"(",
")",
"\n\n",
"// print help/version/list/usage...",
"someSortOfHelp",
"(",
")",
"\n\n",
"// read input from stdin or file... | // this is where the interesting stuff happens.. | [
"this",
"is",
"where",
"the",
"interesting",
"stuff",
"happens",
".."
] | 4dfe9ba2a293f28a5e06fc7ffe56b1d71a47b8c8 | https://github.com/bjarneh/latinx/blob/4dfe9ba2a293f28a5e06fc7ffe56b1d71a47b8c8/example/giconv/main.go#L105-L126 |
142,969 | dcu/go-authy | api.go | NewAuthyAPI | func NewAuthyAPI(apiKey string) *Authy {
apiURL := "https://api.authy.com"
initalTimeout := 2 * time.Millisecond
maxTimeout := 1000 * time.Millisecond
exponentFactor := 2.0
maximumJitterInterval := 2 * time.Millisecond
backoff := heimdall.NewExponentialBackoff(initalTimeout, maxTimeout, exponentFactor, maximumJi... | go | func NewAuthyAPI(apiKey string) *Authy {
apiURL := "https://api.authy.com"
initalTimeout := 2 * time.Millisecond
maxTimeout := 1000 * time.Millisecond
exponentFactor := 2.0
maximumJitterInterval := 2 * time.Millisecond
backoff := heimdall.NewExponentialBackoff(initalTimeout, maxTimeout, exponentFactor, maximumJi... | [
"func",
"NewAuthyAPI",
"(",
"apiKey",
"string",
")",
"*",
"Authy",
"{",
"apiURL",
":=",
"\"",
"\"",
"\n\n",
"initalTimeout",
":=",
"2",
"*",
"time",
".",
"Millisecond",
"\n",
"maxTimeout",
":=",
"1000",
"*",
"time",
".",
"Millisecond",
"\n",
"exponentFacto... | // NewAuthyAPI returns an instance of Authy pointing to production. | [
"NewAuthyAPI",
"returns",
"an",
"instance",
"of",
"Authy",
"pointing",
"to",
"production",
"."
] | 0c8491e20fe9225f4902f789480d7166eab098f7 | https://github.com/dcu/go-authy/blob/0c8491e20fe9225f4902f789480d7166eab098f7/api.go#L62-L85 |
142,970 | dcu/go-authy | api.go | RegisterUser | func (authy *Authy) RegisterUser(email string, countryCode int, phoneNumber string, params url.Values) (*User, error) {
Logger.Println("Creating Authy user with", email, ",", phoneNumber, "and", countryCode)
path := "/protected/json/users/new"
params.Set("user[cellphone]", phoneNumber)
params.Set("user[country_co... | go | func (authy *Authy) RegisterUser(email string, countryCode int, phoneNumber string, params url.Values) (*User, error) {
Logger.Println("Creating Authy user with", email, ",", phoneNumber, "and", countryCode)
path := "/protected/json/users/new"
params.Set("user[cellphone]", phoneNumber)
params.Set("user[country_co... | [
"func",
"(",
"authy",
"*",
"Authy",
")",
"RegisterUser",
"(",
"email",
"string",
",",
"countryCode",
"int",
",",
"phoneNumber",
"string",
",",
"params",
"url",
".",
"Values",
")",
"(",
"*",
"User",
",",
"error",
")",
"{",
"Logger",
".",
"Println",
"(",... | // RegisterUser register a new user given an email and phone number. | [
"RegisterUser",
"register",
"a",
"new",
"user",
"given",
"an",
"email",
"and",
"phone",
"number",
"."
] | 0c8491e20fe9225f4902f789480d7166eab098f7 | https://github.com/dcu/go-authy/blob/0c8491e20fe9225f4902f789480d7166eab098f7/api.go#L88-L105 |
142,971 | dcu/go-authy | api.go | UserStatus | func (authy *Authy) UserStatus(id string, params url.Values) (*UserStatus, error) {
Logger.Println("Finding Authy user with id", id)
path := fmt.Sprintf("/protected/json/users/%s/status", id)
response, err := authy.DoRequest("GET", path, params)
if err != nil {
return nil, err
}
statusResponse, err := NewUse... | go | func (authy *Authy) UserStatus(id string, params url.Values) (*UserStatus, error) {
Logger.Println("Finding Authy user with id", id)
path := fmt.Sprintf("/protected/json/users/%s/status", id)
response, err := authy.DoRequest("GET", path, params)
if err != nil {
return nil, err
}
statusResponse, err := NewUse... | [
"func",
"(",
"authy",
"*",
"Authy",
")",
"UserStatus",
"(",
"id",
"string",
",",
"params",
"url",
".",
"Values",
")",
"(",
"*",
"UserStatus",
",",
"error",
")",
"{",
"Logger",
".",
"Println",
"(",
"\"",
"\"",
",",
"id",
")",
"\n\n",
"path",
":=",
... | // UserStatus returns a set of data about a user. | [
"UserStatus",
"returns",
"a",
"set",
"of",
"data",
"about",
"a",
"user",
"."
] | 0c8491e20fe9225f4902f789480d7166eab098f7 | https://github.com/dcu/go-authy/blob/0c8491e20fe9225f4902f789480d7166eab098f7/api.go#L108-L120 |
142,972 | dcu/go-authy | api.go | VerifyToken | func (authy *Authy) VerifyToken(userID string, token string, params url.Values) (*TokenVerification, error) {
path := "/protected/json/verify/" + url.QueryEscape(token) + "/" + url.QueryEscape(userID)
response, err := authy.DoRequest("GET", path, params)
if err != nil {
Logger.Println("Error while contacting the... | go | func (authy *Authy) VerifyToken(userID string, token string, params url.Values) (*TokenVerification, error) {
path := "/protected/json/verify/" + url.QueryEscape(token) + "/" + url.QueryEscape(userID)
response, err := authy.DoRequest("GET", path, params)
if err != nil {
Logger.Println("Error while contacting the... | [
"func",
"(",
"authy",
"*",
"Authy",
")",
"VerifyToken",
"(",
"userID",
"string",
",",
"token",
"string",
",",
"params",
"url",
".",
"Values",
")",
"(",
"*",
"TokenVerification",
",",
"error",
")",
"{",
"path",
":=",
"\"",
"\"",
"+",
"url",
".",
"Quer... | // VerifyToken verifies the given token | [
"VerifyToken",
"verifies",
"the",
"given",
"token"
] | 0c8491e20fe9225f4902f789480d7166eab098f7 | https://github.com/dcu/go-authy/blob/0c8491e20fe9225f4902f789480d7166eab098f7/api.go#L123-L137 |
142,973 | dcu/go-authy | api.go | RequestSMS | func (authy *Authy) RequestSMS(userID string, params url.Values) (*SMSRequest, error) {
path := "/protected/json/sms/" + url.QueryEscape(userID)
response, err := authy.DoRequest("GET", path, params)
if err != nil {
return nil, err
}
defer closeResponseBody(response)
smsVerification, err := NewSMSRequest(respon... | go | func (authy *Authy) RequestSMS(userID string, params url.Values) (*SMSRequest, error) {
path := "/protected/json/sms/" + url.QueryEscape(userID)
response, err := authy.DoRequest("GET", path, params)
if err != nil {
return nil, err
}
defer closeResponseBody(response)
smsVerification, err := NewSMSRequest(respon... | [
"func",
"(",
"authy",
"*",
"Authy",
")",
"RequestSMS",
"(",
"userID",
"string",
",",
"params",
"url",
".",
"Values",
")",
"(",
"*",
"SMSRequest",
",",
"error",
")",
"{",
"path",
":=",
"\"",
"\"",
"+",
"url",
".",
"QueryEscape",
"(",
"userID",
")",
... | // RequestSMS requests a SMS for the given userID | [
"RequestSMS",
"requests",
"a",
"SMS",
"for",
"the",
"given",
"userID"
] | 0c8491e20fe9225f4902f789480d7166eab098f7 | https://github.com/dcu/go-authy/blob/0c8491e20fe9225f4902f789480d7166eab098f7/api.go#L140-L150 |
142,974 | dcu/go-authy | api.go | RequestPhoneCall | func (authy *Authy) RequestPhoneCall(userID string, params url.Values) (*PhoneCallRequest, error) {
path := "/protected/json/call/" + url.QueryEscape(userID)
response, err := authy.DoRequest("GET", path, params)
if err != nil {
return nil, err
}
defer closeResponseBody(response)
smsVerification, err := NewPho... | go | func (authy *Authy) RequestPhoneCall(userID string, params url.Values) (*PhoneCallRequest, error) {
path := "/protected/json/call/" + url.QueryEscape(userID)
response, err := authy.DoRequest("GET", path, params)
if err != nil {
return nil, err
}
defer closeResponseBody(response)
smsVerification, err := NewPho... | [
"func",
"(",
"authy",
"*",
"Authy",
")",
"RequestPhoneCall",
"(",
"userID",
"string",
",",
"params",
"url",
".",
"Values",
")",
"(",
"*",
"PhoneCallRequest",
",",
"error",
")",
"{",
"path",
":=",
"\"",
"\"",
"+",
"url",
".",
"QueryEscape",
"(",
"userID... | // RequestPhoneCall requests a phone call for the given user | [
"RequestPhoneCall",
"requests",
"a",
"phone",
"call",
"for",
"the",
"given",
"user"
] | 0c8491e20fe9225f4902f789480d7166eab098f7 | https://github.com/dcu/go-authy/blob/0c8491e20fe9225f4902f789480d7166eab098f7/api.go#L153-L164 |
142,975 | dcu/go-authy | api.go | SendApprovalRequest | func (authy *Authy) SendApprovalRequest(userID string, message string, details Details, params url.Values) (*ApprovalRequest, error) {
addParamsForOneTouch(params, message, details)
path := fmt.Sprintf(`/onetouch/json/users/%s/approval_requests`, url.QueryEscape(userID))
response, err := authy.DoRequest("POST", pat... | go | func (authy *Authy) SendApprovalRequest(userID string, message string, details Details, params url.Values) (*ApprovalRequest, error) {
addParamsForOneTouch(params, message, details)
path := fmt.Sprintf(`/onetouch/json/users/%s/approval_requests`, url.QueryEscape(userID))
response, err := authy.DoRequest("POST", pat... | [
"func",
"(",
"authy",
"*",
"Authy",
")",
"SendApprovalRequest",
"(",
"userID",
"string",
",",
"message",
"string",
",",
"details",
"Details",
",",
"params",
"url",
".",
"Values",
")",
"(",
"*",
"ApprovalRequest",
",",
"error",
")",
"{",
"addParamsForOneTouch... | // SendApprovalRequest sends a OneTouch's approval request to the given user. | [
"SendApprovalRequest",
"sends",
"a",
"OneTouch",
"s",
"approval",
"request",
"to",
"the",
"given",
"user",
"."
] | 0c8491e20fe9225f4902f789480d7166eab098f7 | https://github.com/dcu/go-authy/blob/0c8491e20fe9225f4902f789480d7166eab098f7/api.go#L167-L178 |
142,976 | dcu/go-authy | api.go | FindApprovalRequest | func (authy *Authy) FindApprovalRequest(uuid string, params url.Values) (*ApprovalRequest, error) {
path := fmt.Sprintf("/onetouch/json/approval_requests/%s", uuid)
response, err := authy.DoRequest("GET", path, params)
if err != nil {
return nil, err
}
defer closeResponseBody(response)
approvalRequest, err := ... | go | func (authy *Authy) FindApprovalRequest(uuid string, params url.Values) (*ApprovalRequest, error) {
path := fmt.Sprintf("/onetouch/json/approval_requests/%s", uuid)
response, err := authy.DoRequest("GET", path, params)
if err != nil {
return nil, err
}
defer closeResponseBody(response)
approvalRequest, err := ... | [
"func",
"(",
"authy",
"*",
"Authy",
")",
"FindApprovalRequest",
"(",
"uuid",
"string",
",",
"params",
"url",
".",
"Values",
")",
"(",
"*",
"ApprovalRequest",
",",
"error",
")",
"{",
"path",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"uuid",
"... | // FindApprovalRequest finds an approval request given its uuid. | [
"FindApprovalRequest",
"finds",
"an",
"approval",
"request",
"given",
"its",
"uuid",
"."
] | 0c8491e20fe9225f4902f789480d7166eab098f7 | https://github.com/dcu/go-authy/blob/0c8491e20fe9225f4902f789480d7166eab098f7/api.go#L181-L196 |
142,977 | dcu/go-authy | api.go | WaitForApprovalRequest | func (authy *Authy) WaitForApprovalRequest(uuid string, maxDuration time.Duration, params url.Values) (OneTouchStatus, error) {
for maxDuration > 0 {
request, err := authy.FindApprovalRequest(uuid, url.Values{})
if err != nil {
return OneTouchStatusPending, err
}
if request.Status != OneTouchStatusPending ... | go | func (authy *Authy) WaitForApprovalRequest(uuid string, maxDuration time.Duration, params url.Values) (OneTouchStatus, error) {
for maxDuration > 0 {
request, err := authy.FindApprovalRequest(uuid, url.Values{})
if err != nil {
return OneTouchStatusPending, err
}
if request.Status != OneTouchStatusPending ... | [
"func",
"(",
"authy",
"*",
"Authy",
")",
"WaitForApprovalRequest",
"(",
"uuid",
"string",
",",
"maxDuration",
"time",
".",
"Duration",
",",
"params",
"url",
".",
"Values",
")",
"(",
"OneTouchStatus",
",",
"error",
")",
"{",
"for",
"maxDuration",
">",
"0",
... | // WaitForApprovalRequest waits until the status of an approval request has changed or times out. | [
"WaitForApprovalRequest",
"waits",
"until",
"the",
"status",
"of",
"an",
"approval",
"request",
"has",
"changed",
"or",
"times",
"out",
"."
] | 0c8491e20fe9225f4902f789480d7166eab098f7 | https://github.com/dcu/go-authy/blob/0c8491e20fe9225f4902f789480d7166eab098f7/api.go#L199-L215 |
142,978 | dcu/go-authy | api.go | StartPhoneVerification | func (authy *Authy) StartPhoneVerification(countryCode int, phoneNumber string, via string, params url.Values) (*PhoneVerificationStart, error) {
params.Set("country_code", strconv.Itoa(countryCode))
params.Set("phone_number", phoneNumber)
params.Set("via", via)
path := fmt.Sprintf("/protected/json/phones/verifica... | go | func (authy *Authy) StartPhoneVerification(countryCode int, phoneNumber string, via string, params url.Values) (*PhoneVerificationStart, error) {
params.Set("country_code", strconv.Itoa(countryCode))
params.Set("phone_number", phoneNumber)
params.Set("via", via)
path := fmt.Sprintf("/protected/json/phones/verifica... | [
"func",
"(",
"authy",
"*",
"Authy",
")",
"StartPhoneVerification",
"(",
"countryCode",
"int",
",",
"phoneNumber",
"string",
",",
"via",
"string",
",",
"params",
"url",
".",
"Values",
")",
"(",
"*",
"PhoneVerificationStart",
",",
"error",
")",
"{",
"params",
... | // StartPhoneVerification starts the phone verification process. | [
"StartPhoneVerification",
"starts",
"the",
"phone",
"verification",
"process",
"."
] | 0c8491e20fe9225f4902f789480d7166eab098f7 | https://github.com/dcu/go-authy/blob/0c8491e20fe9225f4902f789480d7166eab098f7/api.go#L218-L231 |
142,979 | dcu/go-authy | api.go | CheckPhoneVerification | func (authy *Authy) CheckPhoneVerification(countryCode int, phoneNumber string, verificationCode string, params url.Values) (*PhoneVerificationCheck, error) {
params.Set("country_code", strconv.Itoa(countryCode))
params.Set("phone_number", phoneNumber)
params.Set("verification_code", verificationCode)
path := fmt.... | go | func (authy *Authy) CheckPhoneVerification(countryCode int, phoneNumber string, verificationCode string, params url.Values) (*PhoneVerificationCheck, error) {
params.Set("country_code", strconv.Itoa(countryCode))
params.Set("phone_number", phoneNumber)
params.Set("verification_code", verificationCode)
path := fmt.... | [
"func",
"(",
"authy",
"*",
"Authy",
")",
"CheckPhoneVerification",
"(",
"countryCode",
"int",
",",
"phoneNumber",
"string",
",",
"verificationCode",
"string",
",",
"params",
"url",
".",
"Values",
")",
"(",
"*",
"PhoneVerificationCheck",
",",
"error",
")",
"{",... | // CheckPhoneVerification checks the given verification code. | [
"CheckPhoneVerification",
"checks",
"the",
"given",
"verification",
"code",
"."
] | 0c8491e20fe9225f4902f789480d7166eab098f7 | https://github.com/dcu/go-authy/blob/0c8491e20fe9225f4902f789480d7166eab098f7/api.go#L234-L247 |
142,980 | dcu/go-authy | api.go | DoRequest | func (authy *Authy) DoRequest(method string, path string, params url.Values) (*http.Response, error) {
apiURL := authy.buildURL(path)
// Set api_key to all requests.
params.Set("api_key", authy.APIKey)
var bodyReader io.Reader
switch method {
case "POST":
{
encodedParams := params.Encode()
bodyReader = ... | go | func (authy *Authy) DoRequest(method string, path string, params url.Values) (*http.Response, error) {
apiURL := authy.buildURL(path)
// Set api_key to all requests.
params.Set("api_key", authy.APIKey)
var bodyReader io.Reader
switch method {
case "POST":
{
encodedParams := params.Encode()
bodyReader = ... | [
"func",
"(",
"authy",
"*",
"Authy",
")",
"DoRequest",
"(",
"method",
"string",
",",
"path",
"string",
",",
"params",
"url",
".",
"Values",
")",
"(",
"*",
"http",
".",
"Response",
",",
"error",
")",
"{",
"apiURL",
":=",
"authy",
".",
"buildURL",
"(",
... | // DoRequest performs a HTTP request to the Authy API | [
"DoRequest",
"performs",
"a",
"HTTP",
"request",
"to",
"the",
"Authy",
"API"
] | 0c8491e20fe9225f4902f789480d7166eab098f7 | https://github.com/dcu/go-authy/blob/0c8491e20fe9225f4902f789480d7166eab098f7/api.go#L250-L281 |
142,981 | dcu/go-authy | user.go | NewUser | func NewUser(httpResponse *http.Response) (*User, error) {
userResponse := &User{HTTPResponse: httpResponse}
defer closeResponseBody(httpResponse)
body, err := ioutil.ReadAll(httpResponse.Body)
if err != nil {
Logger.Println("Error reading from API:", err)
return userResponse, err
}
err = json.Unmarshal(bo... | go | func NewUser(httpResponse *http.Response) (*User, error) {
userResponse := &User{HTTPResponse: httpResponse}
defer closeResponseBody(httpResponse)
body, err := ioutil.ReadAll(httpResponse.Body)
if err != nil {
Logger.Println("Error reading from API:", err)
return userResponse, err
}
err = json.Unmarshal(bo... | [
"func",
"NewUser",
"(",
"httpResponse",
"*",
"http",
".",
"Response",
")",
"(",
"*",
"User",
",",
"error",
")",
"{",
"userResponse",
":=",
"&",
"User",
"{",
"HTTPResponse",
":",
"httpResponse",
"}",
"\n\n",
"defer",
"closeResponseBody",
"(",
"httpResponse",
... | // NewUser returns an instance of User | [
"NewUser",
"returns",
"an",
"instance",
"of",
"User"
] | 0c8491e20fe9225f4902f789480d7166eab098f7 | https://github.com/dcu/go-authy/blob/0c8491e20fe9225f4902f789480d7166eab098f7/user.go#L38-L57 |
142,982 | dcu/go-authy | user.go | NewUserStatus | func NewUserStatus(httpResponse *http.Response) (*UserStatus, error) {
statusResponse := &UserStatus{HTTPResponse: httpResponse}
defer closeResponseBody(httpResponse)
body, err := ioutil.ReadAll(httpResponse.Body)
if err != nil {
Logger.Println("Error reading from API:", err)
return statusResponse, err
}
e... | go | func NewUserStatus(httpResponse *http.Response) (*UserStatus, error) {
statusResponse := &UserStatus{HTTPResponse: httpResponse}
defer closeResponseBody(httpResponse)
body, err := ioutil.ReadAll(httpResponse.Body)
if err != nil {
Logger.Println("Error reading from API:", err)
return statusResponse, err
}
e... | [
"func",
"NewUserStatus",
"(",
"httpResponse",
"*",
"http",
".",
"Response",
")",
"(",
"*",
"UserStatus",
",",
"error",
")",
"{",
"statusResponse",
":=",
"&",
"UserStatus",
"{",
"HTTPResponse",
":",
"httpResponse",
"}",
"\n\n",
"defer",
"closeResponseBody",
"("... | // NewUserStatus returns an instance of UserStatus | [
"NewUserStatus",
"returns",
"an",
"instance",
"of",
"UserStatus"
] | 0c8491e20fe9225f4902f789480d7166eab098f7 | https://github.com/dcu/go-authy/blob/0c8491e20fe9225f4902f789480d7166eab098f7/user.go#L60-L79 |
142,983 | dcu/go-authy | token_verification.go | NewTokenVerification | func NewTokenVerification(response *http.Response) (*TokenVerification, error) {
tokenVerification := &TokenVerification{HTTPResponse: response}
body, err := ioutil.ReadAll(response.Body)
if err != nil {
Logger.Println("Error reading from API:", err)
return tokenVerification, err
}
err = json.Unmarshal(body,... | go | func NewTokenVerification(response *http.Response) (*TokenVerification, error) {
tokenVerification := &TokenVerification{HTTPResponse: response}
body, err := ioutil.ReadAll(response.Body)
if err != nil {
Logger.Println("Error reading from API:", err)
return tokenVerification, err
}
err = json.Unmarshal(body,... | [
"func",
"NewTokenVerification",
"(",
"response",
"*",
"http",
".",
"Response",
")",
"(",
"*",
"TokenVerification",
",",
"error",
")",
"{",
"tokenVerification",
":=",
"&",
"TokenVerification",
"{",
"HTTPResponse",
":",
"response",
"}",
"\n",
"body",
",",
"err",... | // NewTokenVerification creates an instance of a TokenVerification | [
"NewTokenVerification",
"creates",
"an",
"instance",
"of",
"a",
"TokenVerification"
] | 0c8491e20fe9225f4902f789480d7166eab098f7 | https://github.com/dcu/go-authy/blob/0c8491e20fe9225f4902f789480d7166eab098f7/token_verification.go#L18-L34 |
142,984 | dcu/go-authy | token_verification.go | Valid | func (verification *TokenVerification) Valid() bool {
if verification.HTTPResponse.StatusCode == 200 && verification.Token == "is valid" {
return true
}
return false
} | go | func (verification *TokenVerification) Valid() bool {
if verification.HTTPResponse.StatusCode == 200 && verification.Token == "is valid" {
return true
}
return false
} | [
"func",
"(",
"verification",
"*",
"TokenVerification",
")",
"Valid",
"(",
")",
"bool",
"{",
"if",
"verification",
".",
"HTTPResponse",
".",
"StatusCode",
"==",
"200",
"&&",
"verification",
".",
"Token",
"==",
"\"",
"\"",
"{",
"return",
"true",
"\n",
"}",
... | // Valid returns true if the verification was valid. | [
"Valid",
"returns",
"true",
"if",
"the",
"verification",
"was",
"valid",
"."
] | 0c8491e20fe9225f4902f789480d7166eab098f7 | https://github.com/dcu/go-authy/blob/0c8491e20fe9225f4902f789480d7166eab098f7/token_verification.go#L37-L43 |
142,985 | dcu/go-authy | sms_request.go | NewSMSRequest | func NewSMSRequest(response *http.Response) (*SMSRequest, error) {
request := &SMSRequest{HTTPResponse: response}
body, err := ioutil.ReadAll(response.Body)
if err != nil {
Logger.Println("Error reading from API:", err)
return request, err
}
err = json.Unmarshal(body, &request)
if err != nil {
Logger.Prin... | go | func NewSMSRequest(response *http.Response) (*SMSRequest, error) {
request := &SMSRequest{HTTPResponse: response}
body, err := ioutil.ReadAll(response.Body)
if err != nil {
Logger.Println("Error reading from API:", err)
return request, err
}
err = json.Unmarshal(body, &request)
if err != nil {
Logger.Prin... | [
"func",
"NewSMSRequest",
"(",
"response",
"*",
"http",
".",
"Response",
")",
"(",
"*",
"SMSRequest",
",",
"error",
")",
"{",
"request",
":=",
"&",
"SMSRequest",
"{",
"HTTPResponse",
":",
"response",
"}",
"\n",
"body",
",",
"err",
":=",
"ioutil",
".",
"... | // NewSMSRequest returns an instance of SMSRequest | [
"NewSMSRequest",
"returns",
"an",
"instance",
"of",
"SMSRequest"
] | 0c8491e20fe9225f4902f789480d7166eab098f7 | https://github.com/dcu/go-authy/blob/0c8491e20fe9225f4902f789480d7166eab098f7/sms_request.go#L16-L32 |
142,986 | dcu/go-authy | approval_request.go | NewApprovalRequest | func NewApprovalRequest(response *http.Response) (*ApprovalRequest, error) {
body, err := ioutil.ReadAll(response.Body)
if err != nil {
return nil, err
}
jsonResponse := struct {
Success bool `json:"success"`
ApprovalRequest *ApprovalRequest `json:"approval_request"`
Message str... | go | func NewApprovalRequest(response *http.Response) (*ApprovalRequest, error) {
body, err := ioutil.ReadAll(response.Body)
if err != nil {
return nil, err
}
jsonResponse := struct {
Success bool `json:"success"`
ApprovalRequest *ApprovalRequest `json:"approval_request"`
Message str... | [
"func",
"NewApprovalRequest",
"(",
"response",
"*",
"http",
".",
"Response",
")",
"(",
"*",
"ApprovalRequest",
",",
"error",
")",
"{",
"body",
",",
"err",
":=",
"ioutil",
".",
"ReadAll",
"(",
"response",
".",
"Body",
")",
"\n",
"if",
"err",
"!=",
"nil"... | // NewApprovalRequest returns an instance of ApprovalRequest. | [
"NewApprovalRequest",
"returns",
"an",
"instance",
"of",
"ApprovalRequest",
"."
] | 0c8491e20fe9225f4902f789480d7166eab098f7 | https://github.com/dcu/go-authy/blob/0c8491e20fe9225f4902f789480d7166eab098f7/approval_request.go#L37-L61 |
142,987 | dcu/go-authy | phone_verification.go | NewPhoneVerificationStart | func NewPhoneVerificationStart(response *http.Response) (*PhoneVerificationStart, error) {
phoneVerification := &PhoneVerificationStart{HTTPResponse: response}
body, err := ioutil.ReadAll(response.Body)
if err != nil {
return phoneVerification, err
}
err = json.Unmarshal(body, &phoneVerification)
if err != ni... | go | func NewPhoneVerificationStart(response *http.Response) (*PhoneVerificationStart, error) {
phoneVerification := &PhoneVerificationStart{HTTPResponse: response}
body, err := ioutil.ReadAll(response.Body)
if err != nil {
return phoneVerification, err
}
err = json.Unmarshal(body, &phoneVerification)
if err != ni... | [
"func",
"NewPhoneVerificationStart",
"(",
"response",
"*",
"http",
".",
"Response",
")",
"(",
"*",
"PhoneVerificationStart",
",",
"error",
")",
"{",
"phoneVerification",
":=",
"&",
"PhoneVerificationStart",
"{",
"HTTPResponse",
":",
"response",
"}",
"\n",
"body",
... | // NewPhoneVerificationStart receives a http request, parses the body and return an instance of PhoneVerification | [
"NewPhoneVerificationStart",
"receives",
"a",
"http",
"request",
"parses",
"the",
"body",
"and",
"return",
"an",
"instance",
"of",
"PhoneVerification"
] | 0c8491e20fe9225f4902f789480d7166eab098f7 | https://github.com/dcu/go-authy/blob/0c8491e20fe9225f4902f789480d7166eab098f7/phone_verification.go#L19-L33 |
142,988 | dcu/go-authy | phone_verification.go | NewPhoneVerificationCheck | func NewPhoneVerificationCheck(response *http.Response) (*PhoneVerificationCheck, error) {
phoneVerification := &PhoneVerificationCheck{HTTPResponse: response}
body, err := ioutil.ReadAll(response.Body)
if err != nil {
return phoneVerification, err
}
err = json.Unmarshal(body, &phoneVerification)
if err != ni... | go | func NewPhoneVerificationCheck(response *http.Response) (*PhoneVerificationCheck, error) {
phoneVerification := &PhoneVerificationCheck{HTTPResponse: response}
body, err := ioutil.ReadAll(response.Body)
if err != nil {
return phoneVerification, err
}
err = json.Unmarshal(body, &phoneVerification)
if err != ni... | [
"func",
"NewPhoneVerificationCheck",
"(",
"response",
"*",
"http",
".",
"Response",
")",
"(",
"*",
"PhoneVerificationCheck",
",",
"error",
")",
"{",
"phoneVerification",
":=",
"&",
"PhoneVerificationCheck",
"{",
"HTTPResponse",
":",
"response",
"}",
"\n",
"body",
... | // NewPhoneVerificationCheck receives a http request, parses the body and return an instance of PhoneVerification | [
"NewPhoneVerificationCheck",
"receives",
"a",
"http",
"request",
"parses",
"the",
"body",
"and",
"return",
"an",
"instance",
"of",
"PhoneVerification"
] | 0c8491e20fe9225f4902f789480d7166eab098f7 | https://github.com/dcu/go-authy/blob/0c8491e20fe9225f4902f789480d7166eab098f7/phone_verification.go#L43-L57 |
142,989 | Ableton/go-travis | jobs.go | IsValid | func (jfo *JobFindOptions) IsValid() bool {
s := structs.New(jfo)
f := s.Fields()
nonZeroValues := 0
for _, field := range f {
if !field.IsZero() {
nonZeroValues += 1
}
}
return nonZeroValues == 0 || nonZeroValues == 1
} | go | func (jfo *JobFindOptions) IsValid() bool {
s := structs.New(jfo)
f := s.Fields()
nonZeroValues := 0
for _, field := range f {
if !field.IsZero() {
nonZeroValues += 1
}
}
return nonZeroValues == 0 || nonZeroValues == 1
} | [
"func",
"(",
"jfo",
"*",
"JobFindOptions",
")",
"IsValid",
"(",
")",
"bool",
"{",
"s",
":=",
"structs",
".",
"New",
"(",
"jfo",
")",
"\n",
"f",
":=",
"s",
".",
"Fields",
"(",
")",
"\n\n",
"nonZeroValues",
":=",
"0",
"\n\n",
"for",
"_",
",",
"fiel... | // IsValid asserts the JobFindOptions instance has one
// and only one value set to a non-zero value.
//
// This method is particularly useful to check a JobFindOptions
// instance before passing it to JobsService.Find method. | [
"IsValid",
"asserts",
"the",
"JobFindOptions",
"instance",
"has",
"one",
"and",
"only",
"one",
"value",
"set",
"to",
"a",
"non",
"-",
"zero",
"value",
".",
"This",
"method",
"is",
"particularly",
"useful",
"to",
"check",
"a",
"JobFindOptions",
"instance",
"b... | 1d2b2c3b9155adcd5c02bc677fdbfa91713a7019 | https://github.com/Ableton/go-travis/blob/1d2b2c3b9155adcd5c02bc677fdbfa91713a7019/jobs.go#L75-L88 |
142,990 | ivpusic/golog | golog.go | GetLogger | func GetLogger(name string) *Logger {
logger, ok := loggers[name]
if !ok {
logger = &Logger{
Name: name,
Level: DEBUG,
ctx: Ctx{},
}
logger.Enable(StdoutAppender())
logger.normalizeName()
// recalculate names
curnamelen = len(logger.Name)
for _, _logger := range loggers {
_logger.normal... | go | func GetLogger(name string) *Logger {
logger, ok := loggers[name]
if !ok {
logger = &Logger{
Name: name,
Level: DEBUG,
ctx: Ctx{},
}
logger.Enable(StdoutAppender())
logger.normalizeName()
// recalculate names
curnamelen = len(logger.Name)
for _, _logger := range loggers {
_logger.normal... | [
"func",
"GetLogger",
"(",
"name",
"string",
")",
"*",
"Logger",
"{",
"logger",
",",
"ok",
":=",
"loggers",
"[",
"name",
"]",
"\n",
"if",
"!",
"ok",
"{",
"logger",
"=",
"&",
"Logger",
"{",
"Name",
":",
"name",
",",
"Level",
":",
"DEBUG",
",",
"ctx... | // Function for getting logger instance.
// Method returns singleton logger instance. | [
"Function",
"for",
"getting",
"logger",
"instance",
".",
"Method",
"returns",
"singleton",
"logger",
"instance",
"."
] | 28640bee649fa9f065ca537ae68d244fd79845d4 | https://github.com/ivpusic/golog/blob/28640bee649fa9f065ca537ae68d244fd79845d4/golog.go#L19-L41 |
142,991 | ivpusic/golog | golog.go | Disable | func Disable(name string) {
logger := loggers[name]
if logger == nil {
Default.Warn("cannot find logger " + name)
return
}
logger.disabled = true
} | go | func Disable(name string) {
logger := loggers[name]
if logger == nil {
Default.Warn("cannot find logger " + name)
return
}
logger.disabled = true
} | [
"func",
"Disable",
"(",
"name",
"string",
")",
"{",
"logger",
":=",
"loggers",
"[",
"name",
"]",
"\n",
"if",
"logger",
"==",
"nil",
"{",
"Default",
".",
"Warn",
"(",
"\"",
"\"",
"+",
"name",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"logger",
".",
... | // Will disable all logs comming from logger with provided name | [
"Will",
"disable",
"all",
"logs",
"comming",
"from",
"logger",
"with",
"provided",
"name"
] | 28640bee649fa9f065ca537ae68d244fd79845d4 | https://github.com/ivpusic/golog/blob/28640bee649fa9f065ca537ae68d244fd79845d4/golog.go#L44-L52 |
142,992 | ivpusic/golog | golog.go | Enable | func Enable(name string) {
logger := loggers[name]
if logger == nil {
Default.Warn("cannot find logger " + name)
return
}
logger.disabled = false
} | go | func Enable(name string) {
logger := loggers[name]
if logger == nil {
Default.Warn("cannot find logger " + name)
return
}
logger.disabled = false
} | [
"func",
"Enable",
"(",
"name",
"string",
")",
"{",
"logger",
":=",
"loggers",
"[",
"name",
"]",
"\n",
"if",
"logger",
"==",
"nil",
"{",
"Default",
".",
"Warn",
"(",
"\"",
"\"",
"+",
"name",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"logger",
".",
"... | // Will enable all logs comming to logger with provided name | [
"Will",
"enable",
"all",
"logs",
"comming",
"to",
"logger",
"with",
"provided",
"name"
] | 28640bee649fa9f065ca537ae68d244fd79845d4 | https://github.com/ivpusic/golog/blob/28640bee649fa9f065ca537ae68d244fd79845d4/golog.go#L55-L63 |
142,993 | ivpusic/golog | appender.go | Append | func (s *Stdout) Append(log Log) {
msg := fmt.Sprintf(" {cyan}%s {default}%s {%s}%s[%s] ▶ %s",
log.Logger.Name,
log.Time.Format(s.DateFormat),
log.Level.color,
log.Level.icon,
log.Level.Name[:4],
log.Message)
color.Print(msg).InFormat()
} | go | func (s *Stdout) Append(log Log) {
msg := fmt.Sprintf(" {cyan}%s {default}%s {%s}%s[%s] ▶ %s",
log.Logger.Name,
log.Time.Format(s.DateFormat),
log.Level.color,
log.Level.icon,
log.Level.Name[:4],
log.Message)
color.Print(msg).InFormat()
} | [
"func",
"(",
"s",
"*",
"Stdout",
")",
"Append",
"(",
"log",
"Log",
")",
"{",
"msg",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"",
"",
"log",
".",
"Logger",
".",
"Name",
",",
"log",
".",
"Time",
".",
"Format",
"(",
"s",
".",
"DateFormat",
")",
"... | // Appending logs to stdout. | [
"Appending",
"logs",
"to",
"stdout",
"."
] | 28640bee649fa9f065ca537ae68d244fd79845d4 | https://github.com/ivpusic/golog/blob/28640bee649fa9f065ca537ae68d244fd79845d4/appender.go#L31-L41 |
142,994 | Ableton/go-travis | travis.go | NewClient | func NewClient(baseUrl string, travisToken string) *Client {
bu, _ := url.Parse(baseUrl)
bh := map[string]string{
"Content-Type": TRAVIS_REQUEST_CONTENT_TYPE,
"User-Agent": TRAVIS_USER_AGENT,
"Accept": TRAVIS_REQUEST_ACCEPT_HEADER,
"Host": bu.Host,
}
c := &Client{
client: http.DefaultC... | go | func NewClient(baseUrl string, travisToken string) *Client {
bu, _ := url.Parse(baseUrl)
bh := map[string]string{
"Content-Type": TRAVIS_REQUEST_CONTENT_TYPE,
"User-Agent": TRAVIS_USER_AGENT,
"Accept": TRAVIS_REQUEST_ACCEPT_HEADER,
"Host": bu.Host,
}
c := &Client{
client: http.DefaultC... | [
"func",
"NewClient",
"(",
"baseUrl",
"string",
",",
"travisToken",
"string",
")",
"*",
"Client",
"{",
"bu",
",",
"_",
":=",
"url",
".",
"Parse",
"(",
"baseUrl",
")",
"\n",
"bh",
":=",
"map",
"[",
"string",
"]",
"string",
"{",
"\"",
"\"",
":",
"TRAV... | // NewClient returns a new Travis API client.
// If travisToken is not provided, the client can be authenticated at any time,
// using it's Authentication exposed service. | [
"NewClient",
"returns",
"a",
"new",
"Travis",
"API",
"client",
".",
"If",
"travisToken",
"is",
"not",
"provided",
"the",
"client",
"can",
"be",
"authenticated",
"at",
"any",
"time",
"using",
"it",
"s",
"Authentication",
"exposed",
"service",
"."
] | 1d2b2c3b9155adcd5c02bc677fdbfa91713a7019 | https://github.com/Ableton/go-travis/blob/1d2b2c3b9155adcd5c02bc677fdbfa91713a7019/travis.go#L74-L105 |
142,995 | Ableton/go-travis | travis.go | NewRequest | func (c *Client) NewRequest(method, urlStr string, body interface{}, headers map[string]string) (*http.Request, error) {
rel, err := url.Parse(urlStr)
if err != nil {
return nil, err
}
u := c.BaseURL.ResolveReference(rel)
var buf io.ReadWriter
if body != nil {
buf = new(bytes.Buffer)
err := json.NewEncode... | go | func (c *Client) NewRequest(method, urlStr string, body interface{}, headers map[string]string) (*http.Request, error) {
rel, err := url.Parse(urlStr)
if err != nil {
return nil, err
}
u := c.BaseURL.ResolveReference(rel)
var buf io.ReadWriter
if body != nil {
buf = new(bytes.Buffer)
err := json.NewEncode... | [
"func",
"(",
"c",
"*",
"Client",
")",
"NewRequest",
"(",
"method",
",",
"urlStr",
"string",
",",
"body",
"interface",
"{",
"}",
",",
"headers",
"map",
"[",
"string",
"]",
"string",
")",
"(",
"*",
"http",
".",
"Request",
",",
"error",
")",
"{",
"rel... | // NewRequest creates an API request. A relative URL can be provided in urlStr,
// in which case it is resolved relative to the BaseURL of the Client.
// Relative URLs should always be specified without a preceding slash. If
// specified, the value pointed to by body is JSON encoded and included as the
// request body.... | [
"NewRequest",
"creates",
"an",
"API",
"request",
".",
"A",
"relative",
"URL",
"can",
"be",
"provided",
"in",
"urlStr",
"in",
"which",
"case",
"it",
"is",
"resolved",
"relative",
"to",
"the",
"BaseURL",
"of",
"the",
"Client",
".",
"Relative",
"URLs",
"shoul... | 1d2b2c3b9155adcd5c02bc677fdbfa91713a7019 | https://github.com/Ableton/go-travis/blob/1d2b2c3b9155adcd5c02bc677fdbfa91713a7019/travis.go#L120-L154 |
142,996 | Ableton/go-travis | travis.go | IsAuthenticated | func (c *Client) IsAuthenticated() bool {
authHeader, ok := c.Headers["Authorization"]
if !ok || (ok && authHeader == "token ") {
return false
}
return true
} | go | func (c *Client) IsAuthenticated() bool {
authHeader, ok := c.Headers["Authorization"]
if !ok || (ok && authHeader == "token ") {
return false
}
return true
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"IsAuthenticated",
"(",
")",
"bool",
"{",
"authHeader",
",",
"ok",
":=",
"c",
".",
"Headers",
"[",
"\"",
"\"",
"]",
"\n\n",
"if",
"!",
"ok",
"||",
"(",
"ok",
"&&",
"authHeader",
"==",
"\"",
"\"",
")",
"{",
... | // IsAuthenticated indicates if Authorization headers were
// found in Client.Headers mapping. | [
"IsAuthenticated",
"indicates",
"if",
"Authorization",
"headers",
"were",
"found",
"in",
"Client",
".",
"Headers",
"mapping",
"."
] | 1d2b2c3b9155adcd5c02bc677fdbfa91713a7019 | https://github.com/Ableton/go-travis/blob/1d2b2c3b9155adcd5c02bc677fdbfa91713a7019/travis.go#L186-L194 |
142,997 | Ableton/go-travis | authentication.go | UsingGithubToken | func (as *AuthenticationService) UsingGithubToken(githubToken string) (AccessToken, *http.Response, error) {
if githubToken == "" {
return "", nil, fmt.Errorf("unable to authenticate client; empty github token provided")
}
var u string = "/auth/github"
var b map[string]string = map[string]string{"github_token": g... | go | func (as *AuthenticationService) UsingGithubToken(githubToken string) (AccessToken, *http.Response, error) {
if githubToken == "" {
return "", nil, fmt.Errorf("unable to authenticate client; empty github token provided")
}
var u string = "/auth/github"
var b map[string]string = map[string]string{"github_token": g... | [
"func",
"(",
"as",
"*",
"AuthenticationService",
")",
"UsingGithubToken",
"(",
"githubToken",
"string",
")",
"(",
"AccessToken",
",",
"*",
"http",
".",
"Response",
",",
"error",
")",
"{",
"if",
"githubToken",
"==",
"\"",
"\"",
"{",
"return",
"\"",
"\"",
... | // UsingGithubToken will generate a Travis CI API authentication
// token and call the UsingTravisToken method with it, leaving your
// client authenticated and ready to use. | [
"UsingGithubToken",
"will",
"generate",
"a",
"Travis",
"CI",
"API",
"authentication",
"token",
"and",
"call",
"the",
"UsingTravisToken",
"method",
"with",
"it",
"leaving",
"your",
"client",
"authenticated",
"and",
"ready",
"to",
"use",
"."
] | 1d2b2c3b9155adcd5c02bc677fdbfa91713a7019 | https://github.com/Ableton/go-travis/blob/1d2b2c3b9155adcd5c02bc677fdbfa91713a7019/authentication.go#L27-L48 |
142,998 | Ableton/go-travis | authentication.go | UsingTravisToken | func (as *AuthenticationService) UsingTravisToken(travisToken string) error {
if travisToken == "" {
return fmt.Errorf("unable to authenticate client; empty travis token provided")
}
as.client.Headers["Authorization"] = "token " + travisToken
return nil
} | go | func (as *AuthenticationService) UsingTravisToken(travisToken string) error {
if travisToken == "" {
return fmt.Errorf("unable to authenticate client; empty travis token provided")
}
as.client.Headers["Authorization"] = "token " + travisToken
return nil
} | [
"func",
"(",
"as",
"*",
"AuthenticationService",
")",
"UsingTravisToken",
"(",
"travisToken",
"string",
")",
"error",
"{",
"if",
"travisToken",
"==",
"\"",
"\"",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"as",
".",
"... | // UsingTravisToken will format and write provided
// travisToken in the AuthenticationService client's headers. | [
"UsingTravisToken",
"will",
"format",
"and",
"write",
"provided",
"travisToken",
"in",
"the",
"AuthenticationService",
"client",
"s",
"headers",
"."
] | 1d2b2c3b9155adcd5c02bc677fdbfa91713a7019 | https://github.com/Ableton/go-travis/blob/1d2b2c3b9155adcd5c02bc677fdbfa91713a7019/authentication.go#L52-L60 |
142,999 | ivpusic/golog | logger.go | makeLog | func (l *Logger) makeLog(msg interface{}, lvl Level, data []interface{}) {
log := Log{
Time: time.Now().UTC(),
Message: l.toString(msg),
Level: lvl,
Data: data,
Logger: l,
Pid: os.Getpid(),
Ctx: l.ctx,
}
for _, appender := range l.appenders {
appender.Append(log)
}
} | go | func (l *Logger) makeLog(msg interface{}, lvl Level, data []interface{}) {
log := Log{
Time: time.Now().UTC(),
Message: l.toString(msg),
Level: lvl,
Data: data,
Logger: l,
Pid: os.Getpid(),
Ctx: l.ctx,
}
for _, appender := range l.appenders {
appender.Append(log)
}
} | [
"func",
"(",
"l",
"*",
"Logger",
")",
"makeLog",
"(",
"msg",
"interface",
"{",
"}",
",",
"lvl",
"Level",
",",
"data",
"[",
"]",
"interface",
"{",
"}",
")",
"{",
"log",
":=",
"Log",
"{",
"Time",
":",
"time",
".",
"Now",
"(",
")",
".",
"UTC",
"... | // Making and sending log entry to appenders if log level is appropriate. | [
"Making",
"and",
"sending",
"log",
"entry",
"to",
"appenders",
"if",
"log",
"level",
"is",
"appropriate",
"."
] | 28640bee649fa9f065ca537ae68d244fd79845d4 | https://github.com/ivpusic/golog/blob/28640bee649fa9f065ca537ae68d244fd79845d4/logger.go#L136-L150 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.