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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
149,100 | brankas/autocertdns | godop/opts.go | Logf | func Logf(f func(string, ...interface{})) Option {
return func(c *Client) error {
c.logf = f
return nil
}
} | go | func Logf(f func(string, ...interface{})) Option {
return func(c *Client) error {
c.logf = f
return nil
}
} | [
"func",
"Logf",
"(",
"f",
"func",
"(",
"string",
",",
"...",
"interface",
"{",
"}",
")",
")",
"Option",
"{",
"return",
"func",
"(",
"c",
"*",
"Client",
")",
"error",
"{",
"c",
".",
"logf",
"=",
"f",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] | // Logf is a Client option to specify the logging function used. | [
"Logf",
"is",
"a",
"Client",
"option",
"to",
"specify",
"the",
"logging",
"function",
"used",
"."
] | 7ff699412a4deb56c78bf9ddbeb5de6fe3856ed5 | https://github.com/brankas/autocertdns/blob/7ff699412a4deb56c78bf9ddbeb5de6fe3856ed5/godop/opts.go#L60-L65 |
149,101 | brankas/autocertdns | godop/opts.go | Errorf | func Errorf(f func(string, ...interface{})) Option {
return func(c *Client) error {
c.errf = f
return nil
}
} | go | func Errorf(f func(string, ...interface{})) Option {
return func(c *Client) error {
c.errf = f
return nil
}
} | [
"func",
"Errorf",
"(",
"f",
"func",
"(",
"string",
",",
"...",
"interface",
"{",
"}",
")",
")",
"Option",
"{",
"return",
"func",
"(",
"c",
"*",
"Client",
")",
"error",
"{",
"c",
".",
"errf",
"=",
"f",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"... | // Errorf is a Client option to specify the error logging function used. | [
"Errorf",
"is",
"a",
"Client",
"option",
"to",
"specify",
"the",
"error",
"logging",
"function",
"used",
"."
] | 7ff699412a4deb56c78bf9ddbeb5de6fe3856ed5 | https://github.com/brankas/autocertdns/blob/7ff699412a4deb56c78bf9ddbeb5de6fe3856ed5/godop/opts.go#L68-L73 |
149,102 | brankas/autocertdns | gcdnsp/opts.go | ProjectID | func ProjectID(projectID string) Option {
return func(c *Client) error {
c.projectID = projectID
return nil
}
} | go | func ProjectID(projectID string) Option {
return func(c *Client) error {
c.projectID = projectID
return nil
}
} | [
"func",
"ProjectID",
"(",
"projectID",
"string",
")",
"Option",
"{",
"return",
"func",
"(",
"c",
"*",
"Client",
")",
"error",
"{",
"c",
".",
"projectID",
"=",
"projectID",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] | // ProjectID is an option that sets the project ID. | [
"ProjectID",
"is",
"an",
"option",
"that",
"sets",
"the",
"project",
"ID",
"."
] | 7ff699412a4deb56c78bf9ddbeb5de6fe3856ed5 | https://github.com/brankas/autocertdns/blob/7ff699412a4deb56c78bf9ddbeb5de6fe3856ed5/gcdnsp/opts.go#L23-L28 |
149,103 | brankas/autocertdns | gcdnsp/opts.go | ManagedZone | func ManagedZone(managedZone string) Option {
return func(c *Client) error {
c.managedZone = managedZone
return nil
}
} | go | func ManagedZone(managedZone string) Option {
return func(c *Client) error {
c.managedZone = managedZone
return nil
}
} | [
"func",
"ManagedZone",
"(",
"managedZone",
"string",
")",
"Option",
"{",
"return",
"func",
"(",
"c",
"*",
"Client",
")",
"error",
"{",
"c",
".",
"managedZone",
"=",
"managedZone",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] | // ManagedZone is a Client option to set the managed zone. | [
"ManagedZone",
"is",
"a",
"Client",
"option",
"to",
"set",
"the",
"managed",
"zone",
"."
] | 7ff699412a4deb56c78bf9ddbeb5de6fe3856ed5 | https://github.com/brankas/autocertdns/blob/7ff699412a4deb56c78bf9ddbeb5de6fe3856ed5/gcdnsp/opts.go#L31-L36 |
149,104 | brankas/autocertdns | gcdnsp/opts.go | Nameservers | func Nameservers(nameservers ...string) Option {
return func(c *Client) error {
c.nameservers = nameservers
return nil
}
} | go | func Nameservers(nameservers ...string) Option {
return func(c *Client) error {
c.nameservers = nameservers
return nil
}
} | [
"func",
"Nameservers",
"(",
"nameservers",
"...",
"string",
")",
"Option",
"{",
"return",
"func",
"(",
"c",
"*",
"Client",
")",
"error",
"{",
"c",
".",
"nameservers",
"=",
"nameservers",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] | // Nameservers is a Client option to set the nameservers to check. | [
"Nameservers",
"is",
"a",
"Client",
"option",
"to",
"set",
"the",
"nameservers",
"to",
"check",
"."
] | 7ff699412a4deb56c78bf9ddbeb5de6fe3856ed5 | https://github.com/brankas/autocertdns/blob/7ff699412a4deb56c78bf9ddbeb5de6fe3856ed5/gcdnsp/opts.go#L47-L52 |
149,105 | brankas/autocertdns | gcdnsp/opts.go | PropagationWait | func PropagationWait(d time.Duration) Option {
return func(c *Client) error {
c.propagationWait = d
return nil
}
} | go | func PropagationWait(d time.Duration) Option {
return func(c *Client) error {
c.propagationWait = d
return nil
}
} | [
"func",
"PropagationWait",
"(",
"d",
"time",
".",
"Duration",
")",
"Option",
"{",
"return",
"func",
"(",
"c",
"*",
"Client",
")",
"error",
"{",
"c",
".",
"propagationWait",
"=",
"d",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] | // PropagationWait is a Client option to set the propagation wait timeout. | [
"PropagationWait",
"is",
"a",
"Client",
"option",
"to",
"set",
"the",
"propagation",
"wait",
"timeout",
"."
] | 7ff699412a4deb56c78bf9ddbeb5de6fe3856ed5 | https://github.com/brankas/autocertdns/blob/7ff699412a4deb56c78bf9ddbeb5de6fe3856ed5/gcdnsp/opts.go#L55-L60 |
149,106 | brankas/autocertdns | gcdnsp/opts.go | CheckDelay | func CheckDelay(d time.Duration) Option {
return func(c *Client) error {
c.checkDelay = d
return nil
}
} | go | func CheckDelay(d time.Duration) Option {
return func(c *Client) error {
c.checkDelay = d
return nil
}
} | [
"func",
"CheckDelay",
"(",
"d",
"time",
".",
"Duration",
")",
"Option",
"{",
"return",
"func",
"(",
"c",
"*",
"Client",
")",
"error",
"{",
"c",
".",
"checkDelay",
"=",
"d",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] | // CheckDelay is a Client option to set the delay between DNS name propagation
// checks. | [
"CheckDelay",
"is",
"a",
"Client",
"option",
"to",
"set",
"the",
"delay",
"between",
"DNS",
"name",
"propagation",
"checks",
"."
] | 7ff699412a4deb56c78bf9ddbeb5de6fe3856ed5 | https://github.com/brankas/autocertdns/blob/7ff699412a4deb56c78bf9ddbeb5de6fe3856ed5/gcdnsp/opts.go#L64-L69 |
149,107 | brankas/autocertdns | gcdnsp/opts.go | ProvisionDelay | func ProvisionDelay(d time.Duration) Option {
return func(c *Client) error {
c.provisionDelay = d
return nil
}
} | go | func ProvisionDelay(d time.Duration) Option {
return func(c *Client) error {
c.provisionDelay = d
return nil
}
} | [
"func",
"ProvisionDelay",
"(",
"d",
"time",
".",
"Duration",
")",
"Option",
"{",
"return",
"func",
"(",
"c",
"*",
"Client",
")",
"error",
"{",
"c",
".",
"provisionDelay",
"=",
"d",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] | // ProvisionDelay is a Client option to set the delay after a successful
// provision and name propagation. | [
"ProvisionDelay",
"is",
"a",
"Client",
"option",
"to",
"set",
"the",
"delay",
"after",
"a",
"successful",
"provision",
"and",
"name",
"propagation",
"."
] | 7ff699412a4deb56c78bf9ddbeb5de6fe3856ed5 | https://github.com/brankas/autocertdns/blob/7ff699412a4deb56c78bf9ddbeb5de6fe3856ed5/gcdnsp/opts.go#L73-L78 |
149,108 | brankas/autocertdns | gcdnsp/opts.go | DNSService | func DNSService(dnsService *dns.Service) Option {
return func(c *Client) error {
c.dnsService = dnsService
return nil
}
} | go | func DNSService(dnsService *dns.Service) Option {
return func(c *Client) error {
c.dnsService = dnsService
return nil
}
} | [
"func",
"DNSService",
"(",
"dnsService",
"*",
"dns",
".",
"Service",
")",
"Option",
"{",
"return",
"func",
"(",
"c",
"*",
"Client",
")",
"error",
"{",
"c",
".",
"dnsService",
"=",
"dnsService",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] | // DNSService is an option that sets the Google Cloud DNS service to use. | [
"DNSService",
"is",
"an",
"option",
"that",
"sets",
"the",
"Google",
"Cloud",
"DNS",
"service",
"to",
"use",
"."
] | 7ff699412a4deb56c78bf9ddbeb5de6fe3856ed5 | https://github.com/brankas/autocertdns/blob/7ff699412a4deb56c78bf9ddbeb5de6fe3856ed5/gcdnsp/opts.go#L81-L86 |
149,109 | brankas/autocertdns | gcdnsp/opts.go | HTTPClient | func HTTPClient(client *http.Client) Option {
return func(c *Client) error {
// create dns service
l, err := dns.New(client)
if err != nil {
return err
}
return DNSService(l)(c)
}
} | go | func HTTPClient(client *http.Client) Option {
return func(c *Client) error {
// create dns service
l, err := dns.New(client)
if err != nil {
return err
}
return DNSService(l)(c)
}
} | [
"func",
"HTTPClient",
"(",
"client",
"*",
"http",
".",
"Client",
")",
"Option",
"{",
"return",
"func",
"(",
"c",
"*",
"Client",
")",
"error",
"{",
"// create dns service",
"l",
",",
"err",
":=",
"dns",
".",
"New",
"(",
"client",
")",
"\n",
"if",
"err... | // HTTPClient is a Client option that sets the http.Client used. | [
"HTTPClient",
"is",
"a",
"Client",
"option",
"that",
"sets",
"the",
"http",
".",
"Client",
"used",
"."
] | 7ff699412a4deb56c78bf9ddbeb5de6fe3856ed5 | https://github.com/brankas/autocertdns/blob/7ff699412a4deb56c78bf9ddbeb5de6fe3856ed5/gcdnsp/opts.go#L89-L98 |
149,110 | brankas/autocertdns | gcdnsp/gcdnsp.go | buildDeletions | func (c *Client) buildDeletions(ctxt context.Context, typ, name string) ([]*dns.ResourceRecordSet, error) {
// get current records
//c.logf("retrieving records (type: %s, name: %s, token: %s)", typ, name, token)
req := c.dnsService.ResourceRecordSets.List(
c.projectID, c.managedZone,
)
var deletions []*dns.Reso... | go | func (c *Client) buildDeletions(ctxt context.Context, typ, name string) ([]*dns.ResourceRecordSet, error) {
// get current records
//c.logf("retrieving records (type: %s, name: %s, token: %s)", typ, name, token)
req := c.dnsService.ResourceRecordSets.List(
c.projectID, c.managedZone,
)
var deletions []*dns.Reso... | [
"func",
"(",
"c",
"*",
"Client",
")",
"buildDeletions",
"(",
"ctxt",
"context",
".",
"Context",
",",
"typ",
",",
"name",
"string",
")",
"(",
"[",
"]",
"*",
"dns",
".",
"ResourceRecordSet",
",",
"error",
")",
"{",
"// get current records",
"//c.logf(\"retri... | // buildDeletions builds list of record sets to delete. | [
"buildDeletions",
"builds",
"list",
"of",
"record",
"sets",
"to",
"delete",
"."
] | 7ff699412a4deb56c78bf9ddbeb5de6fe3856ed5 | https://github.com/brankas/autocertdns/blob/7ff699412a4deb56c78bf9ddbeb5de6fe3856ed5/gcdnsp/gcdnsp.go#L243-L266 |
149,111 | brankas/autocertdns | gcdnsp/gcdnsp.go | contains | func contains(haystack []string, needle string) bool {
for _, s := range haystack {
if needle == strings.TrimFunc(s, func(r rune) bool { return r == '"' }) {
return true
}
}
return false
} | go | func contains(haystack []string, needle string) bool {
for _, s := range haystack {
if needle == strings.TrimFunc(s, func(r rune) bool { return r == '"' }) {
return true
}
}
return false
} | [
"func",
"contains",
"(",
"haystack",
"[",
"]",
"string",
",",
"needle",
"string",
")",
"bool",
"{",
"for",
"_",
",",
"s",
":=",
"range",
"haystack",
"{",
"if",
"needle",
"==",
"strings",
".",
"TrimFunc",
"(",
"s",
",",
"func",
"(",
"r",
"rune",
")"... | // contains returns true if haystack contains needle. | [
"contains",
"returns",
"true",
"if",
"haystack",
"contains",
"needle",
"."
] | 7ff699412a4deb56c78bf9ddbeb5de6fe3856ed5 | https://github.com/brankas/autocertdns/blob/7ff699412a4deb56c78bf9ddbeb5de6fe3856ed5/gcdnsp/gcdnsp.go#L269-L276 |
149,112 | mozilla-services/go-mozlog | mozlog.go | Write | func (m *MozLogger) Write(l []byte) (int, error) {
log := NewAppLog(m.LoggerName, l)
out, err := log.ToJSON()
if err != nil {
// Need someway to notify that this happened.
fmt.Fprintln(os.Stderr, err)
return 0, err
}
_, err = m.Output.Write(append(out, '\n'))
return len(l), err
} | go | func (m *MozLogger) Write(l []byte) (int, error) {
log := NewAppLog(m.LoggerName, l)
out, err := log.ToJSON()
if err != nil {
// Need someway to notify that this happened.
fmt.Fprintln(os.Stderr, err)
return 0, err
}
_, err = m.Output.Write(append(out, '\n'))
return len(l), err
} | [
"func",
"(",
"m",
"*",
"MozLogger",
")",
"Write",
"(",
"l",
"[",
"]",
"byte",
")",
"(",
"int",
",",
"error",
")",
"{",
"log",
":=",
"NewAppLog",
"(",
"m",
".",
"LoggerName",
",",
"l",
")",
"\n\n",
"out",
",",
"err",
":=",
"log",
".",
"ToJSON",
... | // Write converts the log to AppLog | [
"Write",
"converts",
"the",
"log",
"to",
"AppLog"
] | 4bb13139d40339f59bf140d0f5f28be83b07cc58 | https://github.com/mozilla-services/go-mozlog/blob/4bb13139d40339f59bf140d0f5f28be83b07cc58/mozlog.go#L42-L54 |
149,113 | mozilla-services/go-mozlog | mozlog.go | NewAppLog | func NewAppLog(loggerName string, msg []byte) *AppLog {
now := time.Now().UTC()
return &AppLog{
Timestamp: now.UnixNano(),
Time: now.Format(time.RFC3339),
Type: "app.log",
Logger: loggerName,
Hostname: hostname,
EnvVersion: "2.0",
Pid: os.Getpid(),
Fields: map[string]interfac... | go | func NewAppLog(loggerName string, msg []byte) *AppLog {
now := time.Now().UTC()
return &AppLog{
Timestamp: now.UnixNano(),
Time: now.Format(time.RFC3339),
Type: "app.log",
Logger: loggerName,
Hostname: hostname,
EnvVersion: "2.0",
Pid: os.Getpid(),
Fields: map[string]interfac... | [
"func",
"NewAppLog",
"(",
"loggerName",
"string",
",",
"msg",
"[",
"]",
"byte",
")",
"*",
"AppLog",
"{",
"now",
":=",
"time",
".",
"Now",
"(",
")",
".",
"UTC",
"(",
")",
"\n",
"return",
"&",
"AppLog",
"{",
"Timestamp",
":",
"now",
".",
"UnixNano",
... | // NewAppLog returns a loggable struct | [
"NewAppLog",
"returns",
"a",
"loggable",
"struct"
] | 4bb13139d40339f59bf140d0f5f28be83b07cc58 | https://github.com/mozilla-services/go-mozlog/blob/4bb13139d40339f59bf140d0f5f28be83b07cc58/mozlog.go#L70-L84 |
149,114 | brankas/autocertdns | cmd/autogcdns/main.go | loadZone | func loadZone(ctxt context.Context, gsa *gserviceaccount.GServiceAccount, dnsService *dns.Service) (string, error) {
// list managed zones
res, err := dnsService.ManagedZones.List(*flagProject).Do()
if err != nil {
return "", err
}
if len(res.ManagedZones) == 0 {
return "", fmt.Errorf("no managed zones in pro... | go | func loadZone(ctxt context.Context, gsa *gserviceaccount.GServiceAccount, dnsService *dns.Service) (string, error) {
// list managed zones
res, err := dnsService.ManagedZones.List(*flagProject).Do()
if err != nil {
return "", err
}
if len(res.ManagedZones) == 0 {
return "", fmt.Errorf("no managed zones in pro... | [
"func",
"loadZone",
"(",
"ctxt",
"context",
".",
"Context",
",",
"gsa",
"*",
"gserviceaccount",
".",
"GServiceAccount",
",",
"dnsService",
"*",
"dns",
".",
"Service",
")",
"(",
"string",
",",
"error",
")",
"{",
"// list managed zones",
"res",
",",
"err",
"... | // loadZone determines the managed zone for the provided domain and
// credentials. | [
"loadZone",
"determines",
"the",
"managed",
"zone",
"for",
"the",
"provided",
"domain",
"and",
"credentials",
"."
] | 7ff699412a4deb56c78bf9ddbeb5de6fe3856ed5 | https://github.com/brankas/autocertdns/blob/7ff699412a4deb56c78bf9ddbeb5de6fe3856ed5/cmd/autogcdns/main.go#L145-L168 |
149,115 | brankas/autocertdns | cmd/autogcdns/main.go | transportFromEnv | func transportFromEnv() http.RoundTripper {
for _, v := range []string{"HTTPS_PROXY", "HTTP_PROXY"} {
if proxy := os.Getenv(v); proxy != "" {
if u, err := url.Parse(proxy); err == nil {
return &http.Transport{
Proxy: http.ProxyURL(u),
}
}
}
}
return nil
} | go | func transportFromEnv() http.RoundTripper {
for _, v := range []string{"HTTPS_PROXY", "HTTP_PROXY"} {
if proxy := os.Getenv(v); proxy != "" {
if u, err := url.Parse(proxy); err == nil {
return &http.Transport{
Proxy: http.ProxyURL(u),
}
}
}
}
return nil
} | [
"func",
"transportFromEnv",
"(",
")",
"http",
".",
"RoundTripper",
"{",
"for",
"_",
",",
"v",
":=",
"range",
"[",
"]",
"string",
"{",
"\"",
"\"",
",",
"\"",
"\"",
"}",
"{",
"if",
"proxy",
":=",
"os",
".",
"Getenv",
"(",
"v",
")",
";",
"proxy",
... | // transportFromEnv builds a http transport from environment variables, adding
// a HTTP proxy if HTTP_PROXY or HTTPS_PROXY has been set. | [
"transportFromEnv",
"builds",
"a",
"http",
"transport",
"from",
"environment",
"variables",
"adding",
"a",
"HTTP",
"proxy",
"if",
"HTTP_PROXY",
"or",
"HTTPS_PROXY",
"has",
"been",
"set",
"."
] | 7ff699412a4deb56c78bf9ddbeb5de6fe3856ed5 | https://github.com/brankas/autocertdns/blob/7ff699412a4deb56c78bf9ddbeb5de6fe3856ed5/cmd/autogcdns/main.go#L172-L183 |
149,116 | MariaTerzieva/gotumblr | gotumblr.go | Info | func (trc *TumblrRestClient) Info() UserInfoResponse {
data := trc.request.Get("/v2/user/info", map[string]string{})
var result UserInfoResponse
json.Unmarshal(data.Response, &result)
return result
} | go | func (trc *TumblrRestClient) Info() UserInfoResponse {
data := trc.request.Get("/v2/user/info", map[string]string{})
var result UserInfoResponse
json.Unmarshal(data.Response, &result)
return result
} | [
"func",
"(",
"trc",
"*",
"TumblrRestClient",
")",
"Info",
"(",
")",
"UserInfoResponse",
"{",
"data",
":=",
"trc",
".",
"request",
".",
"Get",
"(",
"\"",
"\"",
",",
"map",
"[",
"string",
"]",
"string",
"{",
"}",
")",
"\n",
"var",
"result",
"UserInfoRe... | //Gets the user information. | [
"Gets",
"the",
"user",
"information",
"."
] | 93ca5e50a3fd2dfb6ed1613853520ba624bbbc64 | https://github.com/MariaTerzieva/gotumblr/blob/93ca5e50a3fd2dfb6ed1613853520ba624bbbc64/gotumblr.go#L29-L34 |
149,117 | YoungPioneers/blog4go | consoleWriter.go | NewConsoleWriter | func NewConsoleWriter(redirected bool) (err error) {
singltonLock.Lock()
defer singltonLock.Unlock()
if nil != blog {
return ErrAlreadyInit
}
consoleWriter, err := newConsoleWriter(redirected)
if nil != err {
return err
}
blog = consoleWriter
go consoleWriter.daemon()
return nil
} | go | func NewConsoleWriter(redirected bool) (err error) {
singltonLock.Lock()
defer singltonLock.Unlock()
if nil != blog {
return ErrAlreadyInit
}
consoleWriter, err := newConsoleWriter(redirected)
if nil != err {
return err
}
blog = consoleWriter
go consoleWriter.daemon()
return nil
} | [
"func",
"NewConsoleWriter",
"(",
"redirected",
"bool",
")",
"(",
"err",
"error",
")",
"{",
"singltonLock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"singltonLock",
".",
"Unlock",
"(",
")",
"\n",
"if",
"nil",
"!=",
"blog",
"{",
"return",
"ErrAlreadyInit",
"\... | // NewConsoleWriter initialize a console writer, singlton | [
"NewConsoleWriter",
"initialize",
"a",
"console",
"writer",
"singlton"
] | 6cabe173eb084d34eac5653a0395f0b21774e748 | https://github.com/YoungPioneers/blog4go/blob/6cabe173eb084d34eac5653a0395f0b21774e748/consoleWriter.go#L33-L48 |
149,118 | YoungPioneers/blog4go | consoleWriter.go | newConsoleWriter | func newConsoleWriter(redirected bool) (consoleWriter *ConsoleWriter, err error) {
consoleWriter = new(ConsoleWriter)
consoleWriter.blog = NewBLog(os.Stdout)
consoleWriter.redirected = redirected
if !redirected {
consoleWriter.errblog = NewBLog(os.Stderr)
}
consoleWriter.closed = false
consoleWriter.colored =... | go | func newConsoleWriter(redirected bool) (consoleWriter *ConsoleWriter, err error) {
consoleWriter = new(ConsoleWriter)
consoleWriter.blog = NewBLog(os.Stdout)
consoleWriter.redirected = redirected
if !redirected {
consoleWriter.errblog = NewBLog(os.Stderr)
}
consoleWriter.closed = false
consoleWriter.colored =... | [
"func",
"newConsoleWriter",
"(",
"redirected",
"bool",
")",
"(",
"consoleWriter",
"*",
"ConsoleWriter",
",",
"err",
"error",
")",
"{",
"consoleWriter",
"=",
"new",
"(",
"ConsoleWriter",
")",
"\n",
"consoleWriter",
".",
"blog",
"=",
"NewBLog",
"(",
"os",
".",... | // newConsoleWriter initialize a console writer, not singlton
// if redirected, stderr will be redirected to stdout | [
"newConsoleWriter",
"initialize",
"a",
"console",
"writer",
"not",
"singlton",
"if",
"redirected",
"stderr",
"will",
"be",
"redirected",
"to",
"stdout"
] | 6cabe173eb084d34eac5653a0395f0b21774e748 | https://github.com/YoungPioneers/blog4go/blob/6cabe173eb084d34eac5653a0395f0b21774e748/consoleWriter.go#L52-L74 |
149,119 | YoungPioneers/blog4go | consoleWriter.go | Level | func (writer *ConsoleWriter) Level() LevelType {
writer.lock.RLock()
defer writer.lock.RUnlock()
return writer.blog.Level()
} | go | func (writer *ConsoleWriter) Level() LevelType {
writer.lock.RLock()
defer writer.lock.RUnlock()
return writer.blog.Level()
} | [
"func",
"(",
"writer",
"*",
"ConsoleWriter",
")",
"Level",
"(",
")",
"LevelType",
"{",
"writer",
".",
"lock",
".",
"RLock",
"(",
")",
"\n",
"defer",
"writer",
".",
"lock",
".",
"RUnlock",
"(",
")",
"\n\n",
"return",
"writer",
".",
"blog",
".",
"Level... | // Level get level | [
"Level",
"get",
"level"
] | 6cabe173eb084d34eac5653a0395f0b21774e748 | https://github.com/YoungPioneers/blog4go/blob/6cabe173eb084d34eac5653a0395f0b21774e748/consoleWriter.go#L148-L153 |
149,120 | YoungPioneers/blog4go | consoleWriter.go | SetLevel | func (writer *ConsoleWriter) SetLevel(level LevelType) {
writer.lock.Lock()
defer writer.lock.Unlock()
writer.blog.SetLevel(level)
} | go | func (writer *ConsoleWriter) SetLevel(level LevelType) {
writer.lock.Lock()
defer writer.lock.Unlock()
writer.blog.SetLevel(level)
} | [
"func",
"(",
"writer",
"*",
"ConsoleWriter",
")",
"SetLevel",
"(",
"level",
"LevelType",
")",
"{",
"writer",
".",
"lock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"writer",
".",
"lock",
".",
"Unlock",
"(",
")",
"\n\n",
"writer",
".",
"blog",
".",
"SetLe... | // SetLevel set logger level | [
"SetLevel",
"set",
"logger",
"level"
] | 6cabe173eb084d34eac5653a0395f0b21774e748 | https://github.com/YoungPioneers/blog4go/blob/6cabe173eb084d34eac5653a0395f0b21774e748/consoleWriter.go#L156-L161 |
149,121 | YoungPioneers/blog4go | consoleWriter.go | Colored | func (writer *ConsoleWriter) Colored() bool {
writer.lock.RLock()
defer writer.lock.RUnlock()
return writer.colored
} | go | func (writer *ConsoleWriter) Colored() bool {
writer.lock.RLock()
defer writer.lock.RUnlock()
return writer.colored
} | [
"func",
"(",
"writer",
"*",
"ConsoleWriter",
")",
"Colored",
"(",
")",
"bool",
"{",
"writer",
".",
"lock",
".",
"RLock",
"(",
")",
"\n",
"defer",
"writer",
".",
"lock",
".",
"RUnlock",
"(",
")",
"\n\n",
"return",
"writer",
".",
"colored",
"\n",
"}"
] | // Colored get Colored | [
"Colored",
"get",
"Colored"
] | 6cabe173eb084d34eac5653a0395f0b21774e748 | https://github.com/YoungPioneers/blog4go/blob/6cabe173eb084d34eac5653a0395f0b21774e748/consoleWriter.go#L180-L185 |
149,122 | YoungPioneers/blog4go | consoleWriter.go | Close | func (writer *ConsoleWriter) Close() {
writer.lock.Lock()
defer writer.lock.Unlock()
if writer.closed {
return
}
writer.blog.flush()
writer.blog = nil
writer.closed = true
} | go | func (writer *ConsoleWriter) Close() {
writer.lock.Lock()
defer writer.lock.Unlock()
if writer.closed {
return
}
writer.blog.flush()
writer.blog = nil
writer.closed = true
} | [
"func",
"(",
"writer",
"*",
"ConsoleWriter",
")",
"Close",
"(",
")",
"{",
"writer",
".",
"lock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"writer",
".",
"lock",
".",
"Unlock",
"(",
")",
"\n\n",
"if",
"writer",
".",
"closed",
"{",
"return",
"\n",
"}",
... | // Close close console writer | [
"Close",
"close",
"console",
"writer"
] | 6cabe173eb084d34eac5653a0395f0b21774e748 | https://github.com/YoungPioneers/blog4go/blob/6cabe173eb084d34eac5653a0395f0b21774e748/consoleWriter.go#L226-L237 |
149,123 | YoungPioneers/blog4go | consoleWriter.go | TimeRotated | func (writer *ConsoleWriter) TimeRotated() bool {
writer.lock.RLock()
defer writer.lock.RUnlock()
return false
} | go | func (writer *ConsoleWriter) TimeRotated() bool {
writer.lock.RLock()
defer writer.lock.RUnlock()
return false
} | [
"func",
"(",
"writer",
"*",
"ConsoleWriter",
")",
"TimeRotated",
"(",
")",
"bool",
"{",
"writer",
".",
"lock",
".",
"RLock",
"(",
")",
"\n",
"defer",
"writer",
".",
"lock",
".",
"RUnlock",
"(",
")",
"\n\n",
"return",
"false",
"\n",
"}"
] | // TimeRotated do nothing | [
"TimeRotated",
"do",
"nothing"
] | 6cabe173eb084d34eac5653a0395f0b21774e748 | https://github.com/YoungPioneers/blog4go/blob/6cabe173eb084d34eac5653a0395f0b21774e748/consoleWriter.go#L240-L245 |
149,124 | YoungPioneers/blog4go | consoleWriter.go | Retentions | func (writer *ConsoleWriter) Retentions() int64 {
writer.lock.RLock()
defer writer.lock.RUnlock()
return 0
} | go | func (writer *ConsoleWriter) Retentions() int64 {
writer.lock.RLock()
defer writer.lock.RUnlock()
return 0
} | [
"func",
"(",
"writer",
"*",
"ConsoleWriter",
")",
"Retentions",
"(",
")",
"int64",
"{",
"writer",
".",
"lock",
".",
"RLock",
"(",
")",
"\n",
"defer",
"writer",
".",
"lock",
".",
"RUnlock",
"(",
")",
"\n\n",
"return",
"0",
"\n",
"}"
] | // Retentions do nothing | [
"Retentions",
"do",
"nothing"
] | 6cabe173eb084d34eac5653a0395f0b21774e748 | https://github.com/YoungPioneers/blog4go/blob/6cabe173eb084d34eac5653a0395f0b21774e748/consoleWriter.go#L253-L258 |
149,125 | YoungPioneers/blog4go | consoleWriter.go | SetRetentions | func (writer *ConsoleWriter) SetRetentions(retentions int64) {
writer.lock.Lock()
defer writer.lock.Unlock()
return
} | go | func (writer *ConsoleWriter) SetRetentions(retentions int64) {
writer.lock.Lock()
defer writer.lock.Unlock()
return
} | [
"func",
"(",
"writer",
"*",
"ConsoleWriter",
")",
"SetRetentions",
"(",
"retentions",
"int64",
")",
"{",
"writer",
".",
"lock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"writer",
".",
"lock",
".",
"Unlock",
"(",
")",
"\n\n",
"return",
"\n",
"}"
] | // SetRetentions do nothing | [
"SetRetentions",
"do",
"nothing"
] | 6cabe173eb084d34eac5653a0395f0b21774e748 | https://github.com/YoungPioneers/blog4go/blob/6cabe173eb084d34eac5653a0395f0b21774e748/consoleWriter.go#L261-L266 |
149,126 | YoungPioneers/blog4go | consoleWriter.go | RotateSize | func (writer *ConsoleWriter) RotateSize() int64 {
writer.lock.RLock()
defer writer.lock.RUnlock()
return 0
} | go | func (writer *ConsoleWriter) RotateSize() int64 {
writer.lock.RLock()
defer writer.lock.RUnlock()
return 0
} | [
"func",
"(",
"writer",
"*",
"ConsoleWriter",
")",
"RotateSize",
"(",
")",
"int64",
"{",
"writer",
".",
"lock",
".",
"RLock",
"(",
")",
"\n",
"defer",
"writer",
".",
"lock",
".",
"RUnlock",
"(",
")",
"\n\n",
"return",
"0",
"\n",
"}"
] | // RotateSize do nothing | [
"RotateSize",
"do",
"nothing"
] | 6cabe173eb084d34eac5653a0395f0b21774e748 | https://github.com/YoungPioneers/blog4go/blob/6cabe173eb084d34eac5653a0395f0b21774e748/consoleWriter.go#L269-L274 |
149,127 | YoungPioneers/blog4go | consoleWriter.go | SetRotateSize | func (writer *ConsoleWriter) SetRotateSize(rotateSize int64) {
writer.lock.Lock()
defer writer.lock.Unlock()
return
} | go | func (writer *ConsoleWriter) SetRotateSize(rotateSize int64) {
writer.lock.Lock()
defer writer.lock.Unlock()
return
} | [
"func",
"(",
"writer",
"*",
"ConsoleWriter",
")",
"SetRotateSize",
"(",
"rotateSize",
"int64",
")",
"{",
"writer",
".",
"lock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"writer",
".",
"lock",
".",
"Unlock",
"(",
")",
"\n\n",
"return",
"\n",
"}"
] | // SetRotateSize do nothing | [
"SetRotateSize",
"do",
"nothing"
] | 6cabe173eb084d34eac5653a0395f0b21774e748 | https://github.com/YoungPioneers/blog4go/blob/6cabe173eb084d34eac5653a0395f0b21774e748/consoleWriter.go#L277-L282 |
149,128 | YoungPioneers/blog4go | consoleWriter.go | RotateLines | func (writer *ConsoleWriter) RotateLines() int {
writer.lock.RLock()
defer writer.lock.RUnlock()
return 0
} | go | func (writer *ConsoleWriter) RotateLines() int {
writer.lock.RLock()
defer writer.lock.RUnlock()
return 0
} | [
"func",
"(",
"writer",
"*",
"ConsoleWriter",
")",
"RotateLines",
"(",
")",
"int",
"{",
"writer",
".",
"lock",
".",
"RLock",
"(",
")",
"\n",
"defer",
"writer",
".",
"lock",
".",
"RUnlock",
"(",
")",
"\n\n",
"return",
"0",
"\n",
"}"
] | // RotateLines do nothing | [
"RotateLines",
"do",
"nothing"
] | 6cabe173eb084d34eac5653a0395f0b21774e748 | https://github.com/YoungPioneers/blog4go/blob/6cabe173eb084d34eac5653a0395f0b21774e748/consoleWriter.go#L285-L290 |
149,129 | YoungPioneers/blog4go | consoleWriter.go | SetRotateLines | func (writer *ConsoleWriter) SetRotateLines(rotateLines int) {
writer.lock.Lock()
defer writer.lock.Unlock()
return
} | go | func (writer *ConsoleWriter) SetRotateLines(rotateLines int) {
writer.lock.Lock()
defer writer.lock.Unlock()
return
} | [
"func",
"(",
"writer",
"*",
"ConsoleWriter",
")",
"SetRotateLines",
"(",
"rotateLines",
"int",
")",
"{",
"writer",
".",
"lock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"writer",
".",
"lock",
".",
"Unlock",
"(",
")",
"\n\n",
"return",
"\n",
"}"
] | // SetRotateLines do nothing | [
"SetRotateLines",
"do",
"nothing"
] | 6cabe173eb084d34eac5653a0395f0b21774e748 | https://github.com/YoungPioneers/blog4go/blob/6cabe173eb084d34eac5653a0395f0b21774e748/consoleWriter.go#L293-L298 |
149,130 | YoungPioneers/blog4go | baseFileWriter.go | NewBaseFileWriter | func NewBaseFileWriter(fileName string, timeRotated bool) (err error) {
singltonLock.Lock()
defer singltonLock.Unlock()
if nil != blog {
return ErrAlreadyInit
}
baseFileWriter, err := newBaseFileWriter(fileName, timeRotated)
if nil != err {
return err
}
blog = baseFileWriter
return err
} | go | func NewBaseFileWriter(fileName string, timeRotated bool) (err error) {
singltonLock.Lock()
defer singltonLock.Unlock()
if nil != blog {
return ErrAlreadyInit
}
baseFileWriter, err := newBaseFileWriter(fileName, timeRotated)
if nil != err {
return err
}
blog = baseFileWriter
return err
} | [
"func",
"NewBaseFileWriter",
"(",
"fileName",
"string",
",",
"timeRotated",
"bool",
")",
"(",
"err",
"error",
")",
"{",
"singltonLock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"singltonLock",
".",
"Unlock",
"(",
")",
"\n\n",
"if",
"nil",
"!=",
"blog",
"{",... | // NewBaseFileWriter initialize a base file writer | [
"NewBaseFileWriter",
"initialize",
"a",
"base",
"file",
"writer"
] | 6cabe173eb084d34eac5653a0395f0b21774e748 | https://github.com/YoungPioneers/blog4go/blob/6cabe173eb084d34eac5653a0395f0b21774e748/baseFileWriter.go#L102-L117 |
149,131 | YoungPioneers/blog4go | baseFileWriter.go | newBaseFileWriter | func newBaseFileWriter(fileName string, timeRotated bool) (fileWriter *baseFileWriter, err error) {
fileWriter = new(baseFileWriter)
fileWriter.fileName = fileName
// open file target file
if timeRotated {
fileName = fmt.Sprintf("%s.%s", fileName, timeCache.Date())
}
file, err := os.OpenFile(fileName, os.O_WRO... | go | func newBaseFileWriter(fileName string, timeRotated bool) (fileWriter *baseFileWriter, err error) {
fileWriter = new(baseFileWriter)
fileWriter.fileName = fileName
// open file target file
if timeRotated {
fileName = fmt.Sprintf("%s.%s", fileName, timeCache.Date())
}
file, err := os.OpenFile(fileName, os.O_WRO... | [
"func",
"newBaseFileWriter",
"(",
"fileName",
"string",
",",
"timeRotated",
"bool",
")",
"(",
"fileWriter",
"*",
"baseFileWriter",
",",
"err",
"error",
")",
"{",
"fileWriter",
"=",
"new",
"(",
"baseFileWriter",
")",
"\n\n",
"fileWriter",
".",
"fileName",
"=",
... | // newbaseFileWriter create a single file writer instance and return the poionter
// of it. When any errors happened during creation, a null writer and appropriate
// will be returned.
// fileName must be an absolute path to the destination log file
// rotate determine if it will logrotate | [
"newbaseFileWriter",
"create",
"a",
"single",
"file",
"writer",
"instance",
"and",
"return",
"the",
"poionter",
"of",
"it",
".",
"When",
"any",
"errors",
"happened",
"during",
"creation",
"a",
"null",
"writer",
"and",
"appropriate",
"will",
"be",
"returned",
"... | 6cabe173eb084d34eac5653a0395f0b21774e748 | https://github.com/YoungPioneers/blog4go/blob/6cabe173eb084d34eac5653a0395f0b21774e748/baseFileWriter.go#L124-L168 |
149,132 | YoungPioneers/blog4go | baseFileWriter.go | daemon | func (writer *baseFileWriter) daemon() {
// tick every seconds
// time base logrotate
t := time.Tick(1 * time.Second)
// tick every second
// auto flush writer buffer
f := time.Tick(1 * time.Second)
DaemonLoop:
for {
select {
case <-f:
if writer.Closed() {
break DaemonLoop
}
writer.Flush()
c... | go | func (writer *baseFileWriter) daemon() {
// tick every seconds
// time base logrotate
t := time.Tick(1 * time.Second)
// tick every second
// auto flush writer buffer
f := time.Tick(1 * time.Second)
DaemonLoop:
for {
select {
case <-f:
if writer.Closed() {
break DaemonLoop
}
writer.Flush()
c... | [
"func",
"(",
"writer",
"*",
"baseFileWriter",
")",
"daemon",
"(",
")",
"{",
"// tick every seconds",
"// time base logrotate",
"t",
":=",
"time",
".",
"Tick",
"(",
"1",
"*",
"time",
".",
"Second",
")",
"\n",
"// tick every second",
"// auto flush writer buffer",
... | // daemon run in background as NewbaseFileWriter called.
// It flushes writer buffer every 1 second.
// It decides whether a time base when logrotate is needed.
// It sums up lines && sizes already written. Also it supports the lines &&
// size base logrotate | [
"daemon",
"run",
"in",
"background",
"as",
"NewbaseFileWriter",
"called",
".",
"It",
"flushes",
"writer",
"buffer",
"every",
"1",
"second",
".",
"It",
"decides",
"whether",
"a",
"time",
"base",
"when",
"logrotate",
"is",
"needed",
".",
"It",
"sums",
"up",
... | 6cabe173eb084d34eac5653a0395f0b21774e748 | https://github.com/YoungPioneers/blog4go/blob/6cabe173eb084d34eac5653a0395f0b21774e748/baseFileWriter.go#L175-L256 |
149,133 | YoungPioneers/blog4go | baseFileWriter.go | resetFile | func (writer *baseFileWriter) resetFile() {
writer.lock.Lock()
defer writer.lock.Unlock()
fileName := writer.fileName
if writer.timeRotated {
fileName = fmt.Sprintf("%s.%s", fileName, timeCache.Date())
}
file, _ := os.OpenFile(fileName, os.O_WRONLY|os.O_APPEND|os.O_CREATE, os.FileMode(0644))
writer.blog.reset... | go | func (writer *baseFileWriter) resetFile() {
writer.lock.Lock()
defer writer.lock.Unlock()
fileName := writer.fileName
if writer.timeRotated {
fileName = fmt.Sprintf("%s.%s", fileName, timeCache.Date())
}
file, _ := os.OpenFile(fileName, os.O_WRONLY|os.O_APPEND|os.O_CREATE, os.FileMode(0644))
writer.blog.reset... | [
"func",
"(",
"writer",
"*",
"baseFileWriter",
")",
"resetFile",
"(",
")",
"{",
"writer",
".",
"lock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"writer",
".",
"lock",
".",
"Unlock",
"(",
")",
"\n\n",
"fileName",
":=",
"writer",
".",
"fileName",
"\n",
"if... | // resetFile reset current writing file | [
"resetFile",
"reset",
"current",
"writing",
"file"
] | 6cabe173eb084d34eac5653a0395f0b21774e748 | https://github.com/YoungPioneers/blog4go/blob/6cabe173eb084d34eac5653a0395f0b21774e748/baseFileWriter.go#L259-L274 |
149,134 | YoungPioneers/blog4go | baseFileWriter.go | TimeRotated | func (writer *baseFileWriter) TimeRotated() bool {
writer.lock.RLock()
defer writer.lock.RUnlock()
return writer.timeRotated
} | go | func (writer *baseFileWriter) TimeRotated() bool {
writer.lock.RLock()
defer writer.lock.RUnlock()
return writer.timeRotated
} | [
"func",
"(",
"writer",
"*",
"baseFileWriter",
")",
"TimeRotated",
"(",
")",
"bool",
"{",
"writer",
".",
"lock",
".",
"RLock",
"(",
")",
"\n",
"defer",
"writer",
".",
"lock",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"writer",
".",
"timeRotated",
"\n",
... | // TimeRotated get timeRotated | [
"TimeRotated",
"get",
"timeRotated"
] | 6cabe173eb084d34eac5653a0395f0b21774e748 | https://github.com/YoungPioneers/blog4go/blob/6cabe173eb084d34eac5653a0395f0b21774e748/baseFileWriter.go#L361-L365 |
149,135 | YoungPioneers/blog4go | baseFileWriter.go | Retentions | func (writer *baseFileWriter) Retentions() int64 {
writer.lock.RLock()
defer writer.lock.RUnlock()
return writer.retentions
} | go | func (writer *baseFileWriter) Retentions() int64 {
writer.lock.RLock()
defer writer.lock.RUnlock()
return writer.retentions
} | [
"func",
"(",
"writer",
"*",
"baseFileWriter",
")",
"Retentions",
"(",
")",
"int64",
"{",
"writer",
".",
"lock",
".",
"RLock",
"(",
")",
"\n",
"defer",
"writer",
".",
"lock",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"writer",
".",
"retentions",
"\n",
... | // Retentions get log retention days | [
"Retentions",
"get",
"log",
"retention",
"days"
] | 6cabe173eb084d34eac5653a0395f0b21774e748 | https://github.com/YoungPioneers/blog4go/blob/6cabe173eb084d34eac5653a0395f0b21774e748/baseFileWriter.go#L375-L379 |
149,136 | YoungPioneers/blog4go | baseFileWriter.go | SetRetentions | func (writer *baseFileWriter) SetRetentions(retentions int64) {
writer.lock.Lock()
defer writer.lock.Unlock()
if retentions < 1 {
return
}
writer.retentions = retentions
} | go | func (writer *baseFileWriter) SetRetentions(retentions int64) {
writer.lock.Lock()
defer writer.lock.Unlock()
if retentions < 1 {
return
}
writer.retentions = retentions
} | [
"func",
"(",
"writer",
"*",
"baseFileWriter",
")",
"SetRetentions",
"(",
"retentions",
"int64",
")",
"{",
"writer",
".",
"lock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"writer",
".",
"lock",
".",
"Unlock",
"(",
")",
"\n",
"if",
"retentions",
"<",
"1",
... | // SetExpiredDays set how many days of logs will keep | [
"SetExpiredDays",
"set",
"how",
"many",
"days",
"of",
"logs",
"will",
"keep"
] | 6cabe173eb084d34eac5653a0395f0b21774e748 | https://github.com/YoungPioneers/blog4go/blob/6cabe173eb084d34eac5653a0395f0b21774e748/baseFileWriter.go#L382-L389 |
149,137 | YoungPioneers/blog4go | baseFileWriter.go | RotateSize | func (writer *baseFileWriter) RotateSize() int64 {
writer.lock.RLock()
defer writer.lock.RUnlock()
return writer.rotateSize
} | go | func (writer *baseFileWriter) RotateSize() int64 {
writer.lock.RLock()
defer writer.lock.RUnlock()
return writer.rotateSize
} | [
"func",
"(",
"writer",
"*",
"baseFileWriter",
")",
"RotateSize",
"(",
")",
"int64",
"{",
"writer",
".",
"lock",
".",
"RLock",
"(",
")",
"\n",
"defer",
"writer",
".",
"lock",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"writer",
".",
"rotateSize",
"\n",
... | // RotateSize get log rotate size | [
"RotateSize",
"get",
"log",
"rotate",
"size"
] | 6cabe173eb084d34eac5653a0395f0b21774e748 | https://github.com/YoungPioneers/blog4go/blob/6cabe173eb084d34eac5653a0395f0b21774e748/baseFileWriter.go#L392-L396 |
149,138 | YoungPioneers/blog4go | baseFileWriter.go | RotateLines | func (writer *baseFileWriter) RotateLines() int {
writer.lock.RLock()
defer writer.lock.RUnlock()
return writer.rotateLines
} | go | func (writer *baseFileWriter) RotateLines() int {
writer.lock.RLock()
defer writer.lock.RUnlock()
return writer.rotateLines
} | [
"func",
"(",
"writer",
"*",
"baseFileWriter",
")",
"RotateLines",
"(",
")",
"int",
"{",
"writer",
".",
"lock",
".",
"RLock",
"(",
")",
"\n",
"defer",
"writer",
".",
"lock",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"writer",
".",
"rotateLines",
"\n",
... | // RotateLines get log rotate lines | [
"RotateLines",
"get",
"log",
"rotate",
"lines"
] | 6cabe173eb084d34eac5653a0395f0b21774e748 | https://github.com/YoungPioneers/blog4go/blob/6cabe173eb084d34eac5653a0395f0b21774e748/baseFileWriter.go#L411-L415 |
149,139 | YoungPioneers/blog4go | baseFileWriter.go | Colored | func (writer *baseFileWriter) Colored() bool {
writer.lock.RLock()
defer writer.lock.RUnlock()
return writer.colored
} | go | func (writer *baseFileWriter) Colored() bool {
writer.lock.RLock()
defer writer.lock.RUnlock()
return writer.colored
} | [
"func",
"(",
"writer",
"*",
"baseFileWriter",
")",
"Colored",
"(",
")",
"bool",
"{",
"writer",
".",
"lock",
".",
"RLock",
"(",
")",
"\n",
"defer",
"writer",
".",
"lock",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"writer",
".",
"colored",
"\n",
"}"
] | // Colored get whether it is log with colored | [
"Colored",
"get",
"whether",
"it",
"is",
"log",
"with",
"colored"
] | 6cabe173eb084d34eac5653a0395f0b21774e748 | https://github.com/YoungPioneers/blog4go/blob/6cabe173eb084d34eac5653a0395f0b21774e748/baseFileWriter.go#L430-L434 |
149,140 | YoungPioneers/blog4go | baseFileWriter.go | Level | func (writer *baseFileWriter) Level() LevelType {
writer.lock.RLock()
defer writer.lock.RUnlock()
return writer.blog.Level()
} | go | func (writer *baseFileWriter) Level() LevelType {
writer.lock.RLock()
defer writer.lock.RUnlock()
return writer.blog.Level()
} | [
"func",
"(",
"writer",
"*",
"baseFileWriter",
")",
"Level",
"(",
")",
"LevelType",
"{",
"writer",
".",
"lock",
".",
"RLock",
"(",
")",
"\n",
"defer",
"writer",
".",
"lock",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"writer",
".",
"blog",
".",
"Level"... | // Level get log level | [
"Level",
"get",
"log",
"level"
] | 6cabe173eb084d34eac5653a0395f0b21774e748 | https://github.com/YoungPioneers/blog4go/blob/6cabe173eb084d34eac5653a0395f0b21774e748/baseFileWriter.go#L449-L453 |
149,141 | YoungPioneers/blog4go | baseFileWriter.go | SetHook | func (writer *baseFileWriter) SetHook(hook Hook) {
writer.lock.Lock()
defer writer.lock.Unlock()
writer.hook = hook
} | go | func (writer *baseFileWriter) SetHook(hook Hook) {
writer.lock.Lock()
defer writer.lock.Unlock()
writer.hook = hook
} | [
"func",
"(",
"writer",
"*",
"baseFileWriter",
")",
"SetHook",
"(",
"hook",
"Hook",
")",
"{",
"writer",
".",
"lock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"writer",
".",
"lock",
".",
"Unlock",
"(",
")",
"\n",
"writer",
".",
"hook",
"=",
"hook",
"\n"... | // SetHook set hook for the base file writer | [
"SetHook",
"set",
"hook",
"for",
"the",
"base",
"file",
"writer"
] | 6cabe173eb084d34eac5653a0395f0b21774e748 | https://github.com/YoungPioneers/blog4go/blob/6cabe173eb084d34eac5653a0395f0b21774e748/baseFileWriter.go#L463-L467 |
149,142 | YoungPioneers/blog4go | baseFileWriter.go | SetHookAsync | func (writer *baseFileWriter) SetHookAsync(async bool) {
writer.lock.Lock()
defer writer.lock.Unlock()
writer.hookAsync = async
} | go | func (writer *baseFileWriter) SetHookAsync(async bool) {
writer.lock.Lock()
defer writer.lock.Unlock()
writer.hookAsync = async
} | [
"func",
"(",
"writer",
"*",
"baseFileWriter",
")",
"SetHookAsync",
"(",
"async",
"bool",
")",
"{",
"writer",
".",
"lock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"writer",
".",
"lock",
".",
"Unlock",
"(",
")",
"\n",
"writer",
".",
"hookAsync",
"=",
"as... | // SetHookAsync set hook async for base file writer | [
"SetHookAsync",
"set",
"hook",
"async",
"for",
"base",
"file",
"writer"
] | 6cabe173eb084d34eac5653a0395f0b21774e748 | https://github.com/YoungPioneers/blog4go/blob/6cabe173eb084d34eac5653a0395f0b21774e748/baseFileWriter.go#L484-L488 |
149,143 | YoungPioneers/blog4go | baseFileWriter.go | Flush | func (writer *baseFileWriter) Flush() {
writer.lock.RLock()
defer writer.lock.RUnlock()
writer.flush()
} | go | func (writer *baseFileWriter) Flush() {
writer.lock.RLock()
defer writer.lock.RUnlock()
writer.flush()
} | [
"func",
"(",
"writer",
"*",
"baseFileWriter",
")",
"Flush",
"(",
")",
"{",
"writer",
".",
"lock",
".",
"RLock",
"(",
")",
"\n",
"defer",
"writer",
".",
"lock",
".",
"RUnlock",
"(",
")",
"\n\n",
"writer",
".",
"flush",
"(",
")",
"\n",
"}"
] | // Flush flush logs to disk | [
"Flush",
"flush",
"logs",
"to",
"disk"
] | 6cabe173eb084d34eac5653a0395f0b21774e748 | https://github.com/YoungPioneers/blog4go/blob/6cabe173eb084d34eac5653a0395f0b21774e748/baseFileWriter.go#L498-L503 |
149,144 | YoungPioneers/blog4go | fileWriter.go | NewFileWriter | func NewFileWriter(baseDir string, rotate bool) (err error) {
singltonLock.Lock()
defer singltonLock.Unlock()
if nil != blog {
return ErrAlreadyInit
}
fileWriter := new(MultiWriter)
fileWriter.lock = new(sync.RWMutex)
fileWriter.level = DEBUG
fileWriter.closed = false
fileWriter.writers = make(map[LevelTyp... | go | func NewFileWriter(baseDir string, rotate bool) (err error) {
singltonLock.Lock()
defer singltonLock.Unlock()
if nil != blog {
return ErrAlreadyInit
}
fileWriter := new(MultiWriter)
fileWriter.lock = new(sync.RWMutex)
fileWriter.level = DEBUG
fileWriter.closed = false
fileWriter.writers = make(map[LevelTyp... | [
"func",
"NewFileWriter",
"(",
"baseDir",
"string",
",",
"rotate",
"bool",
")",
"(",
"err",
"error",
")",
"{",
"singltonLock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"singltonLock",
".",
"Unlock",
"(",
")",
"\n",
"if",
"nil",
"!=",
"blog",
"{",
"return",... | // NewFileWriter initialize a file writer
// baseDir must be base directory of log files
// rotate determine if it will logrotate | [
"NewFileWriter",
"initialize",
"a",
"file",
"writer",
"baseDir",
"must",
"be",
"base",
"directory",
"of",
"log",
"files",
"rotate",
"determine",
"if",
"it",
"will",
"logrotate"
] | 6cabe173eb084d34eac5653a0395f0b21774e748 | https://github.com/YoungPioneers/blog4go/blob/6cabe173eb084d34eac5653a0395f0b21774e748/fileWriter.go#L15-L44 |
149,145 | YoungPioneers/blog4go | blog4go.go | NewBLog | func NewBLog(in io.Writer) (blog *BLog) {
blog = new(BLog)
blog.in = in
blog.level = TRACE
blog.lock = new(sync.RWMutex)
blog.closed = false
blog.writer = bufio.NewWriterSize(in, DefaultBufferSize)
return
} | go | func NewBLog(in io.Writer) (blog *BLog) {
blog = new(BLog)
blog.in = in
blog.level = TRACE
blog.lock = new(sync.RWMutex)
blog.closed = false
blog.writer = bufio.NewWriterSize(in, DefaultBufferSize)
return
} | [
"func",
"NewBLog",
"(",
"in",
"io",
".",
"Writer",
")",
"(",
"blog",
"*",
"BLog",
")",
"{",
"blog",
"=",
"new",
"(",
"BLog",
")",
"\n",
"blog",
".",
"in",
"=",
"in",
"\n",
"blog",
".",
"level",
"=",
"TRACE",
"\n",
"blog",
".",
"lock",
"=",
"n... | // NewBLog create a BLog instance and return the pointer of it.
// fileName must be an absolute path to the destination log file | [
"NewBLog",
"create",
"a",
"BLog",
"instance",
"and",
"return",
"the",
"pointer",
"of",
"it",
".",
"fileName",
"must",
"be",
"an",
"absolute",
"path",
"to",
"the",
"destination",
"log",
"file"
] | 6cabe173eb084d34eac5653a0395f0b21774e748 | https://github.com/YoungPioneers/blog4go/blob/6cabe173eb084d34eac5653a0395f0b21774e748/blog4go.go#L249-L258 |
149,146 | YoungPioneers/blog4go | blog4go.go | flush | func (blog *BLog) flush() {
blog.lock.Lock()
defer blog.lock.Unlock()
if blog.closed {
return
}
blog.writer.Flush()
} | go | func (blog *BLog) flush() {
blog.lock.Lock()
defer blog.lock.Unlock()
if blog.closed {
return
}
blog.writer.Flush()
} | [
"func",
"(",
"blog",
"*",
"BLog",
")",
"flush",
"(",
")",
"{",
"blog",
".",
"lock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"blog",
".",
"lock",
".",
"Unlock",
"(",
")",
"\n\n",
"if",
"blog",
".",
"closed",
"{",
"return",
"\n",
"}",
"\n\n",
"blog... | // Flush flush buffer to disk | [
"Flush",
"flush",
"buffer",
"to",
"disk"
] | 6cabe173eb084d34eac5653a0395f0b21774e748 | https://github.com/YoungPioneers/blog4go/blob/6cabe173eb084d34eac5653a0395f0b21774e748/blog4go.go#L355-L364 |
149,147 | YoungPioneers/blog4go | blog4go.go | resetFile | func (blog *BLog) resetFile(in io.Writer) (err error) {
blog.lock.Lock()
defer blog.lock.Unlock()
blog.writer.Flush()
blog.in = in
blog.writer.Reset(in)
return
} | go | func (blog *BLog) resetFile(in io.Writer) (err error) {
blog.lock.Lock()
defer blog.lock.Unlock()
blog.writer.Flush()
blog.in = in
blog.writer.Reset(in)
return
} | [
"func",
"(",
"blog",
"*",
"BLog",
")",
"resetFile",
"(",
"in",
"io",
".",
"Writer",
")",
"(",
"err",
"error",
")",
"{",
"blog",
".",
"lock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"blog",
".",
"lock",
".",
"Unlock",
"(",
")",
"\n\n",
"blog",
"."... | // resetFile resets file descriptor of the writer with specific file name | [
"resetFile",
"resets",
"file",
"descriptor",
"of",
"the",
"writer",
"with",
"specific",
"file",
"name"
] | 6cabe173eb084d34eac5653a0395f0b21774e748 | https://github.com/YoungPioneers/blog4go/blob/6cabe173eb084d34eac5653a0395f0b21774e748/blog4go.go#L419-L429 |
149,148 | YoungPioneers/blog4go | blog4go.go | SetLevel | func SetLevel(level LevelType) {
singltonLock.RLock()
defer singltonLock.RUnlock()
blog.SetLevel(level)
} | go | func SetLevel(level LevelType) {
singltonLock.RLock()
defer singltonLock.RUnlock()
blog.SetLevel(level)
} | [
"func",
"SetLevel",
"(",
"level",
"LevelType",
")",
"{",
"singltonLock",
".",
"RLock",
"(",
")",
"\n",
"defer",
"singltonLock",
".",
"RUnlock",
"(",
")",
"\n\n",
"blog",
".",
"SetLevel",
"(",
"level",
")",
"\n",
"}"
] | // SetLevel set level for logging action | [
"SetLevel",
"set",
"level",
"for",
"logging",
"action"
] | 6cabe173eb084d34eac5653a0395f0b21774e748 | https://github.com/YoungPioneers/blog4go/blob/6cabe173eb084d34eac5653a0395f0b21774e748/blog4go.go#L448-L453 |
149,149 | YoungPioneers/blog4go | blog4go.go | SetHookAsync | func SetHookAsync(async bool) {
singltonLock.RLock()
defer singltonLock.RUnlock()
blog.SetHookAsync(async)
} | go | func SetHookAsync(async bool) {
singltonLock.RLock()
defer singltonLock.RUnlock()
blog.SetHookAsync(async)
} | [
"func",
"SetHookAsync",
"(",
"async",
"bool",
")",
"{",
"singltonLock",
".",
"RLock",
"(",
")",
"\n",
"defer",
"singltonLock",
".",
"RUnlock",
"(",
")",
"\n\n",
"blog",
".",
"SetHookAsync",
"(",
"async",
")",
"\n",
"}"
] | // SetHookAsync set whether hook is called async | [
"SetHookAsync",
"set",
"whether",
"hook",
"is",
"called",
"async"
] | 6cabe173eb084d34eac5653a0395f0b21774e748 | https://github.com/YoungPioneers/blog4go/blob/6cabe173eb084d34eac5653a0395f0b21774e748/blog4go.go#L488-L493 |
149,150 | YoungPioneers/blog4go | blog4go.go | Tracef | func Tracef(format string, args ...interface{}) {
singltonLock.RLock()
defer singltonLock.RUnlock()
blog.Tracef(format, args...)
} | go | func Tracef(format string, args ...interface{}) {
singltonLock.RLock()
defer singltonLock.RUnlock()
blog.Tracef(format, args...)
} | [
"func",
"Tracef",
"(",
"format",
"string",
",",
"args",
"...",
"interface",
"{",
"}",
")",
"{",
"singltonLock",
".",
"RLock",
"(",
")",
"\n",
"defer",
"singltonLock",
".",
"RUnlock",
"(",
")",
"\n\n",
"blog",
".",
"Tracef",
"(",
"format",
",",
"args",
... | // Tracef static function for Tracef | [
"Tracef",
"static",
"function",
"for",
"Tracef"
] | 6cabe173eb084d34eac5653a0395f0b21774e748 | https://github.com/YoungPioneers/blog4go/blob/6cabe173eb084d34eac5653a0395f0b21774e748/blog4go.go#L592-L597 |
149,151 | YoungPioneers/blog4go | blog4go.go | Debugf | func Debugf(format string, args ...interface{}) {
singltonLock.RLock()
defer singltonLock.RUnlock()
blog.Debugf(format, args...)
} | go | func Debugf(format string, args ...interface{}) {
singltonLock.RLock()
defer singltonLock.RUnlock()
blog.Debugf(format, args...)
} | [
"func",
"Debugf",
"(",
"format",
"string",
",",
"args",
"...",
"interface",
"{",
"}",
")",
"{",
"singltonLock",
".",
"RLock",
"(",
")",
"\n",
"defer",
"singltonLock",
".",
"RUnlock",
"(",
")",
"\n\n",
"blog",
".",
"Debugf",
"(",
"format",
",",
"args",
... | // Debugf static function for Debugf | [
"Debugf",
"static",
"function",
"for",
"Debugf"
] | 6cabe173eb084d34eac5653a0395f0b21774e748 | https://github.com/YoungPioneers/blog4go/blob/6cabe173eb084d34eac5653a0395f0b21774e748/blog4go.go#L608-L613 |
149,152 | YoungPioneers/blog4go | blog4go.go | Infof | func Infof(format string, args ...interface{}) {
singltonLock.RLock()
defer singltonLock.RUnlock()
blog.Infof(format, args...)
} | go | func Infof(format string, args ...interface{}) {
singltonLock.RLock()
defer singltonLock.RUnlock()
blog.Infof(format, args...)
} | [
"func",
"Infof",
"(",
"format",
"string",
",",
"args",
"...",
"interface",
"{",
"}",
")",
"{",
"singltonLock",
".",
"RLock",
"(",
")",
"\n",
"defer",
"singltonLock",
".",
"RUnlock",
"(",
")",
"\n\n",
"blog",
".",
"Infof",
"(",
"format",
",",
"args",
... | // Infof static function for Infof | [
"Infof",
"static",
"function",
"for",
"Infof"
] | 6cabe173eb084d34eac5653a0395f0b21774e748 | https://github.com/YoungPioneers/blog4go/blob/6cabe173eb084d34eac5653a0395f0b21774e748/blog4go.go#L624-L629 |
149,153 | YoungPioneers/blog4go | blog4go.go | Warnf | func Warnf(format string, args ...interface{}) {
singltonLock.RLock()
defer singltonLock.RUnlock()
blog.Warnf(format, args...)
} | go | func Warnf(format string, args ...interface{}) {
singltonLock.RLock()
defer singltonLock.RUnlock()
blog.Warnf(format, args...)
} | [
"func",
"Warnf",
"(",
"format",
"string",
",",
"args",
"...",
"interface",
"{",
"}",
")",
"{",
"singltonLock",
".",
"RLock",
"(",
")",
"\n",
"defer",
"singltonLock",
".",
"RUnlock",
"(",
")",
"\n\n",
"blog",
".",
"Warnf",
"(",
"format",
",",
"args",
... | // Warnf static function for Warnf | [
"Warnf",
"static",
"function",
"for",
"Warnf"
] | 6cabe173eb084d34eac5653a0395f0b21774e748 | https://github.com/YoungPioneers/blog4go/blob/6cabe173eb084d34eac5653a0395f0b21774e748/blog4go.go#L640-L645 |
149,154 | YoungPioneers/blog4go | blog4go.go | Errorf | func Errorf(format string, args ...interface{}) {
singltonLock.RLock()
defer singltonLock.RUnlock()
blog.Errorf(format, args...)
} | go | func Errorf(format string, args ...interface{}) {
singltonLock.RLock()
defer singltonLock.RUnlock()
blog.Errorf(format, args...)
} | [
"func",
"Errorf",
"(",
"format",
"string",
",",
"args",
"...",
"interface",
"{",
"}",
")",
"{",
"singltonLock",
".",
"RLock",
"(",
")",
"\n",
"defer",
"singltonLock",
".",
"RUnlock",
"(",
")",
"\n\n",
"blog",
".",
"Errorf",
"(",
"format",
",",
"args",
... | // Errorf static function for Errorf | [
"Errorf",
"static",
"function",
"for",
"Errorf"
] | 6cabe173eb084d34eac5653a0395f0b21774e748 | https://github.com/YoungPioneers/blog4go/blob/6cabe173eb084d34eac5653a0395f0b21774e748/blog4go.go#L656-L661 |
149,155 | YoungPioneers/blog4go | blog4go.go | Criticalf | func Criticalf(format string, args ...interface{}) {
singltonLock.RLock()
defer singltonLock.RUnlock()
blog.Criticalf(format, args...)
} | go | func Criticalf(format string, args ...interface{}) {
singltonLock.RLock()
defer singltonLock.RUnlock()
blog.Criticalf(format, args...)
} | [
"func",
"Criticalf",
"(",
"format",
"string",
",",
"args",
"...",
"interface",
"{",
"}",
")",
"{",
"singltonLock",
".",
"RLock",
"(",
")",
"\n",
"defer",
"singltonLock",
".",
"RUnlock",
"(",
")",
"\n\n",
"blog",
".",
"Criticalf",
"(",
"format",
",",
"a... | // Criticalf static function for Criticalf | [
"Criticalf",
"static",
"function",
"for",
"Criticalf"
] | 6cabe173eb084d34eac5653a0395f0b21774e748 | https://github.com/YoungPioneers/blog4go/blob/6cabe173eb084d34eac5653a0395f0b21774e748/blog4go.go#L672-L677 |
149,156 | YoungPioneers/blog4go | blog4go.go | Close | func Close() {
singltonLock.Lock()
defer singltonLock.Unlock()
if nil == blog {
return
}
blog.Close()
blog = nil
} | go | func Close() {
singltonLock.Lock()
defer singltonLock.Unlock()
if nil == blog {
return
}
blog.Close()
blog = nil
} | [
"func",
"Close",
"(",
")",
"{",
"singltonLock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"singltonLock",
".",
"Unlock",
"(",
")",
"\n\n",
"if",
"nil",
"==",
"blog",
"{",
"return",
"\n",
"}",
"\n\n",
"blog",
".",
"Close",
"(",
")",
"\n",
"blog",
"=",
... | // Close close the logger | [
"Close",
"close",
"the",
"logger"
] | 6cabe173eb084d34eac5653a0395f0b21774e748 | https://github.com/YoungPioneers/blog4go/blob/6cabe173eb084d34eac5653a0395f0b21774e748/blog4go.go#L680-L690 |
149,157 | YoungPioneers/blog4go | config.go | valid | func (config *Config) valid() error {
// check minlevel validation
if "" != config.MinLevel && !LevelFromString(config.MinLevel).valid() {
return ErrConfigBadAttributes
}
// check filters len
if len(config.Filters) < 1 {
return ErrConfigFiltersNotFound
}
// check filter one by one
for _, filter := range c... | go | func (config *Config) valid() error {
// check minlevel validation
if "" != config.MinLevel && !LevelFromString(config.MinLevel).valid() {
return ErrConfigBadAttributes
}
// check filters len
if len(config.Filters) < 1 {
return ErrConfigFiltersNotFound
}
// check filter one by one
for _, filter := range c... | [
"func",
"(",
"config",
"*",
"Config",
")",
"valid",
"(",
")",
"error",
"{",
"// check minlevel validation",
"if",
"\"",
"\"",
"!=",
"config",
".",
"MinLevel",
"&&",
"!",
"LevelFromString",
"(",
"config",
".",
"MinLevel",
")",
".",
"valid",
"(",
")",
"{",... | // check if config is valid | [
"check",
"if",
"config",
"is",
"valid"
] | 6cabe173eb084d34eac5653a0395f0b21774e748 | https://github.com/YoungPioneers/blog4go/blob/6cabe173eb084d34eac5653a0395f0b21774e748/config.go#L75-L117 |
149,158 | YoungPioneers/blog4go | config.go | readConfig | func readConfig(fileName string) (*Config, error) {
file, err := os.Open(fileName)
if nil != err {
return nil, err
}
defer file.Close()
in, err := ioutil.ReadAll(file)
if nil != err {
return nil, err
}
config := new(Config)
err = xml.Unmarshal(in, config)
if nil != err {
return nil, err
}
return co... | go | func readConfig(fileName string) (*Config, error) {
file, err := os.Open(fileName)
if nil != err {
return nil, err
}
defer file.Close()
in, err := ioutil.ReadAll(file)
if nil != err {
return nil, err
}
config := new(Config)
err = xml.Unmarshal(in, config)
if nil != err {
return nil, err
}
return co... | [
"func",
"readConfig",
"(",
"fileName",
"string",
")",
"(",
"*",
"Config",
",",
"error",
")",
"{",
"file",
",",
"err",
":=",
"os",
".",
"Open",
"(",
"fileName",
")",
"\n",
"if",
"nil",
"!=",
"err",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n"... | // read config from a xml file | [
"read",
"config",
"from",
"a",
"xml",
"file"
] | 6cabe173eb084d34eac5653a0395f0b21774e748 | https://github.com/YoungPioneers/blog4go/blob/6cabe173eb084d34eac5653a0395f0b21774e748/config.go#L120-L139 |
149,159 | YoungPioneers/blog4go | level.go | initPrefix | func initPrefix(colored bool) {
if colored {
Prefix[TRACE] = fmt.Sprintf(ColoredPrefixFormat, GRAY, TRACE.String())
Prefix[DEBUG] = fmt.Sprintf(ColoredPrefixFormat, GREEN, DEBUG.String())
Prefix[INFO] = fmt.Sprintf(ColoredPrefixFormat, BLUE, INFO.String())
Prefix[WARNING] = fmt.Sprintf(ColoredPrefixFormat, YEL... | go | func initPrefix(colored bool) {
if colored {
Prefix[TRACE] = fmt.Sprintf(ColoredPrefixFormat, GRAY, TRACE.String())
Prefix[DEBUG] = fmt.Sprintf(ColoredPrefixFormat, GREEN, DEBUG.String())
Prefix[INFO] = fmt.Sprintf(ColoredPrefixFormat, BLUE, INFO.String())
Prefix[WARNING] = fmt.Sprintf(ColoredPrefixFormat, YEL... | [
"func",
"initPrefix",
"(",
"colored",
"bool",
")",
"{",
"if",
"colored",
"{",
"Prefix",
"[",
"TRACE",
"]",
"=",
"fmt",
".",
"Sprintf",
"(",
"ColoredPrefixFormat",
",",
"GRAY",
",",
"TRACE",
".",
"String",
"(",
")",
")",
"\n",
"Prefix",
"[",
"DEBUG",
... | // initPrefix is designed to preformat level prefix string for each level.
// colored decide whether preformat in colored format or not.
// if colored is true, preformat level prefix string in colored format | [
"initPrefix",
"is",
"designed",
"to",
"preformat",
"level",
"prefix",
"string",
"for",
"each",
"level",
".",
"colored",
"decide",
"whether",
"preformat",
"in",
"colored",
"format",
"or",
"not",
".",
"if",
"colored",
"is",
"true",
"preformat",
"level",
"prefix"... | 6cabe173eb084d34eac5653a0395f0b21774e748 | https://github.com/YoungPioneers/blog4go/blob/6cabe173eb084d34eac5653a0395f0b21774e748/level.go#L78-L94 |
149,160 | YoungPioneers/blog4go | level.go | valid | func (level LevelType) valid() bool {
if TRACE > level || CRITICAL < level {
return false
}
return true
} | go | func (level LevelType) valid() bool {
if TRACE > level || CRITICAL < level {
return false
}
return true
} | [
"func",
"(",
"level",
"LevelType",
")",
"valid",
"(",
")",
"bool",
"{",
"if",
"TRACE",
">",
"level",
"||",
"CRITICAL",
"<",
"level",
"{",
"return",
"false",
"\n",
"}",
"\n",
"return",
"true",
"\n",
"}"
] | // valid determines whether a Level instance is valid or not | [
"valid",
"determines",
"whether",
"a",
"Level",
"instance",
"is",
"valid",
"or",
"not"
] | 6cabe173eb084d34eac5653a0395f0b21774e748 | https://github.com/YoungPioneers/blog4go/blob/6cabe173eb084d34eac5653a0395f0b21774e748/level.go#L97-L102 |
149,161 | YoungPioneers/blog4go | level.go | LevelFromString | func LevelFromString(str string) LevelType {
level, ok := StringLevels[strings.ToUpper(str)]
if !ok {
return LevelType(-1)
}
return level
} | go | func LevelFromString(str string) LevelType {
level, ok := StringLevels[strings.ToUpper(str)]
if !ok {
return LevelType(-1)
}
return level
} | [
"func",
"LevelFromString",
"(",
"str",
"string",
")",
"LevelType",
"{",
"level",
",",
"ok",
":=",
"StringLevels",
"[",
"strings",
".",
"ToUpper",
"(",
"str",
")",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"LevelType",
"(",
"-",
"1",
")",
"\n",
"}",
... | // LevelFromString return Level according to given string | [
"LevelFromString",
"return",
"Level",
"according",
"to",
"given",
"string"
] | 6cabe173eb084d34eac5653a0395f0b21774e748 | https://github.com/YoungPioneers/blog4go/blob/6cabe173eb084d34eac5653a0395f0b21774e748/level.go#L118-L124 |
149,162 | YoungPioneers/blog4go | socketWriter.go | NewSocketWriter | func NewSocketWriter(network string, address string) (err error) {
singltonLock.Lock()
defer singltonLock.Unlock()
if nil != blog {
return ErrAlreadyInit
}
socketWriter, err := newSocketWriter(network, address)
if nil != err {
return err
}
blog = socketWriter
return nil
} | go | func NewSocketWriter(network string, address string) (err error) {
singltonLock.Lock()
defer singltonLock.Unlock()
if nil != blog {
return ErrAlreadyInit
}
socketWriter, err := newSocketWriter(network, address)
if nil != err {
return err
}
blog = socketWriter
return nil
} | [
"func",
"NewSocketWriter",
"(",
"network",
"string",
",",
"address",
"string",
")",
"(",
"err",
"error",
")",
"{",
"singltonLock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"singltonLock",
".",
"Unlock",
"(",
")",
"\n",
"if",
"nil",
"!=",
"blog",
"{",
"ret... | // NewSocketWriter creates a socket writer, singlton | [
"NewSocketWriter",
"creates",
"a",
"socket",
"writer",
"singlton"
] | 6cabe173eb084d34eac5653a0395f0b21774e748 | https://github.com/YoungPioneers/blog4go/blob/6cabe173eb084d34eac5653a0395f0b21774e748/socketWriter.go#L34-L48 |
149,163 | YoungPioneers/blog4go | socketWriter.go | newSocketWriter | func newSocketWriter(network string, address string) (socketWriter *SocketWriter, err error) {
socketWriter = new(SocketWriter)
socketWriter.level = DEBUG
socketWriter.closed = false
socketWriter.lock = new(sync.RWMutex)
// log hook
socketWriter.hook = nil
socketWriter.hookLevel = DEBUG
conn, err := net.Dial(... | go | func newSocketWriter(network string, address string) (socketWriter *SocketWriter, err error) {
socketWriter = new(SocketWriter)
socketWriter.level = DEBUG
socketWriter.closed = false
socketWriter.lock = new(sync.RWMutex)
// log hook
socketWriter.hook = nil
socketWriter.hookLevel = DEBUG
conn, err := net.Dial(... | [
"func",
"newSocketWriter",
"(",
"network",
"string",
",",
"address",
"string",
")",
"(",
"socketWriter",
"*",
"SocketWriter",
",",
"err",
"error",
")",
"{",
"socketWriter",
"=",
"new",
"(",
"SocketWriter",
")",
"\n",
"socketWriter",
".",
"level",
"=",
"DEBUG... | // newSocketWriter creates a socket writer, not singlton | [
"newSocketWriter",
"creates",
"a",
"socket",
"writer",
"not",
"singlton"
] | 6cabe173eb084d34eac5653a0395f0b21774e748 | https://github.com/YoungPioneers/blog4go/blob/6cabe173eb084d34eac5653a0395f0b21774e748/socketWriter.go#L51-L69 |
149,164 | YoungPioneers/blog4go | socketWriter.go | Close | func (writer *SocketWriter) Close() {
writer.lock.Lock()
defer writer.lock.Unlock()
if writer.closed {
return
}
writer.writer.Close()
writer.writer = nil
writer.closed = true
} | go | func (writer *SocketWriter) Close() {
writer.lock.Lock()
defer writer.lock.Unlock()
if writer.closed {
return
}
writer.writer.Close()
writer.writer = nil
writer.closed = true
} | [
"func",
"(",
"writer",
"*",
"SocketWriter",
")",
"Close",
"(",
")",
"{",
"writer",
".",
"lock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"writer",
".",
"lock",
".",
"Unlock",
"(",
")",
"\n",
"if",
"writer",
".",
"closed",
"{",
"return",
"\n",
"}",
"... | // Close will close the writer | [
"Close",
"will",
"close",
"the",
"writer"
] | 6cabe173eb084d34eac5653a0395f0b21774e748 | https://github.com/YoungPioneers/blog4go/blob/6cabe173eb084d34eac5653a0395f0b21774e748/socketWriter.go#L218-L228 |
149,165 | YoungPioneers/blog4go | multiWriter.go | SetTimeRotated | func (writer *MultiWriter) SetTimeRotated(timeRotated bool) {
writer.timeRotated = timeRotated
for _, fileWriter := range writer.writers {
fileWriter.SetTimeRotated(timeRotated)
}
} | go | func (writer *MultiWriter) SetTimeRotated(timeRotated bool) {
writer.timeRotated = timeRotated
for _, fileWriter := range writer.writers {
fileWriter.SetTimeRotated(timeRotated)
}
} | [
"func",
"(",
"writer",
"*",
"MultiWriter",
")",
"SetTimeRotated",
"(",
"timeRotated",
"bool",
")",
"{",
"writer",
".",
"timeRotated",
"=",
"timeRotated",
"\n",
"for",
"_",
",",
"fileWriter",
":=",
"range",
"writer",
".",
"writers",
"{",
"fileWriter",
".",
... | // SetTimeRotated toggle time base logrotate | [
"SetTimeRotated",
"toggle",
"time",
"base",
"logrotate"
] | 6cabe173eb084d34eac5653a0395f0b21774e748 | https://github.com/YoungPioneers/blog4go/blob/6cabe173eb084d34eac5653a0395f0b21774e748/multiWriter.go#L58-L63 |
149,166 | YoungPioneers/blog4go | timeCache.go | fresh | func (timeCache *timeFormatCacheType) fresh() {
timeCache.lock.Lock()
defer timeCache.lock.Unlock()
// get current time and update timeCache
now := time.Now()
timeCache.now = now
timeCache.format = []byte(now.Format(PrefixTimeFormat))
date := now.Format(DateFormat)
if date != timeCache.date {
timeCache.dateY... | go | func (timeCache *timeFormatCacheType) fresh() {
timeCache.lock.Lock()
defer timeCache.lock.Unlock()
// get current time and update timeCache
now := time.Now()
timeCache.now = now
timeCache.format = []byte(now.Format(PrefixTimeFormat))
date := now.Format(DateFormat)
if date != timeCache.date {
timeCache.dateY... | [
"func",
"(",
"timeCache",
"*",
"timeFormatCacheType",
")",
"fresh",
"(",
")",
"{",
"timeCache",
".",
"lock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"timeCache",
".",
"lock",
".",
"Unlock",
"(",
")",
"\n\n",
"// get current time and update timeCache",
"now",
"... | // fresh data in timeCache | [
"fresh",
"data",
"in",
"timeCache"
] | 6cabe173eb084d34eac5653a0395f0b21774e748 | https://github.com/YoungPioneers/blog4go/blob/6cabe173eb084d34eac5653a0395f0b21774e748/timeCache.go#L89-L102 |
149,167 | mrmorphic/hwio | servo/servo.go | New | func New(pwm hwio.PWMModule, pin interface{}) (*Servo, error) {
var p hwio.Pin
var e error
switch pt := pin.(type) {
case hwio.Pin:
p = pt
case string:
p, e = hwio.GetPin(pt)
if e != nil {
return nil, e
}
}
result := &Servo{PWM: pwm, Pin: p}
// enable the servo
e = pwm.EnablePin(p, true)
if e !=... | go | func New(pwm hwio.PWMModule, pin interface{}) (*Servo, error) {
var p hwio.Pin
var e error
switch pt := pin.(type) {
case hwio.Pin:
p = pt
case string:
p, e = hwio.GetPin(pt)
if e != nil {
return nil, e
}
}
result := &Servo{PWM: pwm, Pin: p}
// enable the servo
e = pwm.EnablePin(p, true)
if e !=... | [
"func",
"New",
"(",
"pwm",
"hwio",
".",
"PWMModule",
",",
"pin",
"interface",
"{",
"}",
")",
"(",
"*",
"Servo",
",",
"error",
")",
"{",
"var",
"p",
"hwio",
".",
"Pin",
"\n",
"var",
"e",
"error",
"\n\n",
"switch",
"pt",
":=",
"pin",
".",
"(",
"t... | // Create a new servo and initialise it. | [
"Create",
"a",
"new",
"servo",
"and",
"initialise",
"it",
"."
] | 11ea3f481a1404aa1de932554dd25858ee509163 | https://github.com/mrmorphic/hwio/blob/11ea3f481a1404aa1de932554dd25858ee509163/servo/servo.go#L24-L54 |
149,168 | mrmorphic/hwio | servo/servo.go | SetPeriod | func (servo *Servo) SetPeriod(milliseconds int) error {
return servo.PWM.SetPeriod(servo.Pin, int64(milliseconds*1000000))
} | go | func (servo *Servo) SetPeriod(milliseconds int) error {
return servo.PWM.SetPeriod(servo.Pin, int64(milliseconds*1000000))
} | [
"func",
"(",
"servo",
"*",
"Servo",
")",
"SetPeriod",
"(",
"milliseconds",
"int",
")",
"error",
"{",
"return",
"servo",
".",
"PWM",
".",
"SetPeriod",
"(",
"servo",
".",
"Pin",
",",
"int64",
"(",
"milliseconds",
"*",
"1000000",
")",
")",
"\n",
"}"
] | // helper function to set the period of each cycle. Servos generally want this to be fixed, typically at 20ms.
// This just sets the underling PWM period, so if you need less than 1 ms you can set that directly on the PWM. | [
"helper",
"function",
"to",
"set",
"the",
"period",
"of",
"each",
"cycle",
".",
"Servos",
"generally",
"want",
"this",
"to",
"be",
"fixed",
"typically",
"at",
"20ms",
".",
"This",
"just",
"sets",
"the",
"underling",
"PWM",
"period",
"so",
"if",
"you",
"n... | 11ea3f481a1404aa1de932554dd25858ee509163 | https://github.com/mrmorphic/hwio/blob/11ea3f481a1404aa1de932554dd25858ee509163/servo/servo.go#L58-L60 |
149,169 | mrmorphic/hwio | servo/servo.go | Write | func (servo *Servo) Write(angle int) {
servo.WriteMicroseconds(hwio.Map(angle, 0, 180, servo.minDuty, servo.maxDuty))
} | go | func (servo *Servo) Write(angle int) {
servo.WriteMicroseconds(hwio.Map(angle, 0, 180, servo.minDuty, servo.maxDuty))
} | [
"func",
"(",
"servo",
"*",
"Servo",
")",
"Write",
"(",
"angle",
"int",
")",
"{",
"servo",
".",
"WriteMicroseconds",
"(",
"hwio",
".",
"Map",
"(",
"angle",
",",
"0",
",",
"180",
",",
"servo",
".",
"minDuty",
",",
"servo",
".",
"maxDuty",
")",
")",
... | // Set the servo to the specified angle, typically 0-180. This sets the duty cycle proportionally between min and max,
// which are defaulted to 1000-2000 microseconds range. | [
"Set",
"the",
"servo",
"to",
"the",
"specified",
"angle",
"typically",
"0",
"-",
"180",
".",
"This",
"sets",
"the",
"duty",
"cycle",
"proportionally",
"between",
"min",
"and",
"max",
"which",
"are",
"defaulted",
"to",
"1000",
"-",
"2000",
"microseconds",
"... | 11ea3f481a1404aa1de932554dd25858ee509163 | https://github.com/mrmorphic/hwio/blob/11ea3f481a1404aa1de932554dd25858ee509163/servo/servo.go#L64-L66 |
149,170 | mrmorphic/hwio | servo/servo.go | WriteMicroseconds | func (servo *Servo) WriteMicroseconds(ms int) {
// just pass to the underlying PWM pin.
servo.PWM.SetDuty(servo.Pin, int64(ms*1000))
} | go | func (servo *Servo) WriteMicroseconds(ms int) {
// just pass to the underlying PWM pin.
servo.PWM.SetDuty(servo.Pin, int64(ms*1000))
} | [
"func",
"(",
"servo",
"*",
"Servo",
")",
"WriteMicroseconds",
"(",
"ms",
"int",
")",
"{",
"// just pass to the underlying PWM pin.",
"servo",
".",
"PWM",
".",
"SetDuty",
"(",
"servo",
".",
"Pin",
",",
"int64",
"(",
"ms",
"*",
"1000",
")",
")",
"\n",
"}"
... | // Like the Arduino Servo.writeMicroseconds function. This is really setting the PWM duty directly, so it is possible
// to write values too small or too large for the servo to track. | [
"Like",
"the",
"Arduino",
"Servo",
".",
"writeMicroseconds",
"function",
".",
"This",
"is",
"really",
"setting",
"the",
"PWM",
"duty",
"directly",
"so",
"it",
"is",
"possible",
"to",
"write",
"values",
"too",
"small",
"or",
"too",
"large",
"for",
"the",
"s... | 11ea3f481a1404aa1de932554dd25858ee509163 | https://github.com/mrmorphic/hwio/blob/11ea3f481a1404aa1de932554dd25858ee509163/servo/servo.go#L70-L73 |
149,171 | mrmorphic/hwio | servo/servo.go | SetRange | func (servo *Servo) SetRange(min int, max int) {
servo.minDuty = min
servo.maxDuty = max
} | go | func (servo *Servo) SetRange(min int, max int) {
servo.minDuty = min
servo.maxDuty = max
} | [
"func",
"(",
"servo",
"*",
"Servo",
")",
"SetRange",
"(",
"min",
"int",
",",
"max",
"int",
")",
"{",
"servo",
".",
"minDuty",
"=",
"min",
"\n",
"servo",
".",
"maxDuty",
"=",
"max",
"\n",
"}"
] | // Set the minimum and maximum number of microseconds for the servo. Write maps 0-180 to these values. | [
"Set",
"the",
"minimum",
"and",
"maximum",
"number",
"of",
"microseconds",
"for",
"the",
"servo",
".",
"Write",
"maps",
"0",
"-",
"180",
"to",
"these",
"values",
"."
] | 11ea3f481a1404aa1de932554dd25858ee509163 | https://github.com/mrmorphic/hwio/blob/11ea3f481a1404aa1de932554dd25858ee509163/servo/servo.go#L76-L79 |
149,172 | mrmorphic/hwio | devices/bh1750fvi/bh1750fvi.go | NewBH1750FVIAddr | func NewBH1750FVIAddr(module hwio.I2CModule, address int) *BH1750FVI {
device := module.GetDevice(address)
result := &BH1750FVI{device: device}
return result
} | go | func NewBH1750FVIAddr(module hwio.I2CModule, address int) *BH1750FVI {
device := module.GetDevice(address)
result := &BH1750FVI{device: device}
return result
} | [
"func",
"NewBH1750FVIAddr",
"(",
"module",
"hwio",
".",
"I2CModule",
",",
"address",
"int",
")",
"*",
"BH1750FVI",
"{",
"device",
":=",
"module",
".",
"GetDevice",
"(",
"address",
")",
"\n",
"result",
":=",
"&",
"BH1750FVI",
"{",
"device",
":",
"device",
... | // Create a new device, with i2c address specified. This can be used to access the device
// on a non-standard address, since it has an address bit. | [
"Create",
"a",
"new",
"device",
"with",
"i2c",
"address",
"specified",
".",
"This",
"can",
"be",
"used",
"to",
"access",
"the",
"device",
"on",
"a",
"non",
"-",
"standard",
"address",
"since",
"it",
"has",
"an",
"address",
"bit",
"."
] | 11ea3f481a1404aa1de932554dd25858ee509163 | https://github.com/mrmorphic/hwio/blob/11ea3f481a1404aa1de932554dd25858ee509163/devices/bh1750fvi/bh1750fvi.go#L51-L56 |
149,173 | mrmorphic/hwio | devices/bh1750fvi/bh1750fvi.go | ReadLightLevel | func (t *BH1750FVI) ReadLightLevel(mode ReadMode) (float32, error) {
// Get the settings
m := modes[mode]
// send a command to initiate low resolution read. The empty slice indicates there are no additional bytes,
// just the command
t.device.Write(m.deviceMode, []byte{})
// wait for the sampling to be complete... | go | func (t *BH1750FVI) ReadLightLevel(mode ReadMode) (float32, error) {
// Get the settings
m := modes[mode]
// send a command to initiate low resolution read. The empty slice indicates there are no additional bytes,
// just the command
t.device.Write(m.deviceMode, []byte{})
// wait for the sampling to be complete... | [
"func",
"(",
"t",
"*",
"BH1750FVI",
")",
"ReadLightLevel",
"(",
"mode",
"ReadMode",
")",
"(",
"float32",
",",
"error",
")",
"{",
"// Get the settings",
"m",
":=",
"modes",
"[",
"mode",
"]",
"\n\n",
"// send a command to initiate low resolution read. The empty slice ... | // Read the light level in low resolution mode, which is to a 4 lux precision. | [
"Read",
"the",
"light",
"level",
"in",
"low",
"resolution",
"mode",
"which",
"is",
"to",
"a",
"4",
"lux",
"precision",
"."
] | 11ea3f481a1404aa1de932554dd25858ee509163 | https://github.com/mrmorphic/hwio/blob/11ea3f481a1404aa1de932554dd25858ee509163/devices/bh1750fvi/bh1750fvi.go#L64-L91 |
149,174 | mrmorphic/hwio | hwio.go | determineDriver | func determineDriver() {
drivers := [...]HardwareDriver{NewBeagleboneBlackDTDriver(), NewRaspPiDTDriver(), NewOdroidC1Driver()}
for _, d := range drivers {
if d.MatchesHardwareConfig() {
SetDriver(d)
return
}
}
fmt.Printf("Unable to select a suitable driver for this board.\n")
} | go | func determineDriver() {
drivers := [...]HardwareDriver{NewBeagleboneBlackDTDriver(), NewRaspPiDTDriver(), NewOdroidC1Driver()}
for _, d := range drivers {
if d.MatchesHardwareConfig() {
SetDriver(d)
return
}
}
fmt.Printf("Unable to select a suitable driver for this board.\n")
} | [
"func",
"determineDriver",
"(",
")",
"{",
"drivers",
":=",
"[",
"...",
"]",
"HardwareDriver",
"{",
"NewBeagleboneBlackDTDriver",
"(",
")",
",",
"NewRaspPiDTDriver",
"(",
")",
",",
"NewOdroidC1Driver",
"(",
")",
"}",
"\n",
"for",
"_",
",",
"d",
":=",
"range... | // Work out the driver from environment if we can. If we have any problems,
// don't generate an error, just return with the driver not set. | [
"Work",
"out",
"the",
"driver",
"from",
"environment",
"if",
"we",
"can",
".",
"If",
"we",
"have",
"any",
"problems",
"don",
"t",
"generate",
"an",
"error",
"just",
"return",
"with",
"the",
"driver",
"not",
"set",
"."
] | 11ea3f481a1404aa1de932554dd25858ee509163 | https://github.com/mrmorphic/hwio/blob/11ea3f481a1404aa1de932554dd25858ee509163/hwio.go#L69-L79 |
149,175 | mrmorphic/hwio | hwio.go | SetDriver | func SetDriver(d HardwareDriver) {
driver = d
e := driver.Init()
if e != nil {
fmt.Printf("Could not initialise driver: %s", e)
}
definedPins = driver.PinMap()
} | go | func SetDriver(d HardwareDriver) {
driver = d
e := driver.Init()
if e != nil {
fmt.Printf("Could not initialise driver: %s", e)
}
definedPins = driver.PinMap()
} | [
"func",
"SetDriver",
"(",
"d",
"HardwareDriver",
")",
"{",
"driver",
"=",
"d",
"\n",
"e",
":=",
"driver",
".",
"Init",
"(",
")",
"\n",
"if",
"e",
"!=",
"nil",
"{",
"fmt",
".",
"Printf",
"(",
"\"",
"\"",
",",
"e",
")",
"\n",
"}",
"\n",
"definedP... | // Set the driver. Also calls Init on the driver, and loads the capabilities
// of the device. | [
"Set",
"the",
"driver",
".",
"Also",
"calls",
"Init",
"on",
"the",
"driver",
"and",
"loads",
"the",
"capabilities",
"of",
"the",
"device",
"."
] | 11ea3f481a1404aa1de932554dd25858ee509163 | https://github.com/mrmorphic/hwio/blob/11ea3f481a1404aa1de932554dd25858ee509163/hwio.go#L92-L99 |
149,176 | mrmorphic/hwio | hwio.go | GetPinWithMode | func GetPinWithMode(cname string, mode PinIOMode) (pin Pin, e error) {
p, e := GetPin(cname)
if e != nil {
return
}
e = PinMode(p, mode)
return p, e
} | go | func GetPinWithMode(cname string, mode PinIOMode) (pin Pin, e error) {
p, e := GetPin(cname)
if e != nil {
return
}
e = PinMode(p, mode)
return p, e
} | [
"func",
"GetPinWithMode",
"(",
"cname",
"string",
",",
"mode",
"PinIOMode",
")",
"(",
"pin",
"Pin",
",",
"e",
"error",
")",
"{",
"p",
",",
"e",
":=",
"GetPin",
"(",
"cname",
")",
"\n",
"if",
"e",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"e"... | // Shortcut for calling GetPin and then PinMode. | [
"Shortcut",
"for",
"calling",
"GetPin",
"and",
"then",
"PinMode",
"."
] | 11ea3f481a1404aa1de932554dd25858ee509163 | https://github.com/mrmorphic/hwio/blob/11ea3f481a1404aa1de932554dd25858ee509163/hwio.go#L144-L152 |
149,177 | mrmorphic/hwio | hwio.go | PinName | func PinName(pin Pin) string {
p := definedPins[pin]
if p == nil {
return ""
}
return p.names[0]
} | go | func PinName(pin Pin) string {
p := definedPins[pin]
if p == nil {
return ""
}
return p.names[0]
} | [
"func",
"PinName",
"(",
"pin",
"Pin",
")",
"string",
"{",
"p",
":=",
"definedPins",
"[",
"pin",
"]",
"\n",
"if",
"p",
"==",
"nil",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n",
"return",
"p",
".",
"names",
"[",
"0",
"]",
"\n",
"}"
] | // Given an internal pin number, return the canonical name for the pin, as defined by the driver. If the pin
// is not to the driver, return "". | [
"Given",
"an",
"internal",
"pin",
"number",
"return",
"the",
"canonical",
"name",
"for",
"the",
"pin",
"as",
"defined",
"by",
"the",
"driver",
".",
"If",
"the",
"pin",
"is",
"not",
"to",
"the",
"driver",
"return",
"."
] | 11ea3f481a1404aa1de932554dd25858ee509163 | https://github.com/mrmorphic/hwio/blob/11ea3f481a1404aa1de932554dd25858ee509163/hwio.go#L175-L181 |
149,178 | mrmorphic/hwio | hwio.go | PinMode | func PinMode(pin Pin, mode PinIOMode) error {
gpio, e := GetGPIOModule()
if e != nil {
return e
}
return gpio.PinMode(pin, mode)
} | go | func PinMode(pin Pin, mode PinIOMode) error {
gpio, e := GetGPIOModule()
if e != nil {
return e
}
return gpio.PinMode(pin, mode)
} | [
"func",
"PinMode",
"(",
"pin",
"Pin",
",",
"mode",
"PinIOMode",
")",
"error",
"{",
"gpio",
",",
"e",
":=",
"GetGPIOModule",
"(",
")",
"\n",
"if",
"e",
"!=",
"nil",
"{",
"return",
"e",
"\n",
"}",
"\n\n",
"return",
"gpio",
".",
"PinMode",
"(",
"pin",... | // Set the mode of a pin. Analogous to Arduino pin mode. | [
"Set",
"the",
"mode",
"of",
"a",
"pin",
".",
"Analogous",
"to",
"Arduino",
"pin",
"mode",
"."
] | 11ea3f481a1404aa1de932554dd25858ee509163 | https://github.com/mrmorphic/hwio/blob/11ea3f481a1404aa1de932554dd25858ee509163/hwio.go#L184-L191 |
149,179 | mrmorphic/hwio | hwio.go | ClosePin | func ClosePin(pin Pin) error {
gpio, e := GetGPIOModule()
if e != nil {
return e
}
return gpio.ClosePin(pin)
} | go | func ClosePin(pin Pin) error {
gpio, e := GetGPIOModule()
if e != nil {
return e
}
return gpio.ClosePin(pin)
} | [
"func",
"ClosePin",
"(",
"pin",
"Pin",
")",
"error",
"{",
"gpio",
",",
"e",
":=",
"GetGPIOModule",
"(",
")",
"\n",
"if",
"e",
"!=",
"nil",
"{",
"return",
"e",
"\n",
"}",
"\n\n",
"return",
"gpio",
".",
"ClosePin",
"(",
"pin",
")",
"\n",
"}"
] | // Close a specific pin that has been assigned as GPIO by PinMode | [
"Close",
"a",
"specific",
"pin",
"that",
"has",
"been",
"assigned",
"as",
"GPIO",
"by",
"PinMode"
] | 11ea3f481a1404aa1de932554dd25858ee509163 | https://github.com/mrmorphic/hwio/blob/11ea3f481a1404aa1de932554dd25858ee509163/hwio.go#L194-L201 |
149,180 | mrmorphic/hwio | hwio.go | AssignPin | func AssignPin(pin Pin, module Module) error {
if a := assignedPins[pin]; a != nil {
return fmt.Errorf("Pin %d is already assigned to module %s", pin, a.module.GetName())
}
assignedPins[pin] = &assignedPin{pin, module}
return nil
} | go | func AssignPin(pin Pin, module Module) error {
if a := assignedPins[pin]; a != nil {
return fmt.Errorf("Pin %d is already assigned to module %s", pin, a.module.GetName())
}
assignedPins[pin] = &assignedPin{pin, module}
return nil
} | [
"func",
"AssignPin",
"(",
"pin",
"Pin",
",",
"module",
"Module",
")",
"error",
"{",
"if",
"a",
":=",
"assignedPins",
"[",
"pin",
"]",
";",
"a",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"pin",
",",
"a",
".",
"module"... | // Assign a pin to a module. This is typically called by modules when they allocate pins. If the pin is already assigned,
// an error is generated. ethod is public in case it is needed to hack around default driver settings. | [
"Assign",
"a",
"pin",
"to",
"a",
"module",
".",
"This",
"is",
"typically",
"called",
"by",
"modules",
"when",
"they",
"allocate",
"pins",
".",
"If",
"the",
"pin",
"is",
"already",
"assigned",
"an",
"error",
"is",
"generated",
".",
"ethod",
"is",
"public"... | 11ea3f481a1404aa1de932554dd25858ee509163 | https://github.com/mrmorphic/hwio/blob/11ea3f481a1404aa1de932554dd25858ee509163/hwio.go#L205-L211 |
149,181 | mrmorphic/hwio | hwio.go | AssignPins | func AssignPins(pins PinList, module Module) error {
for _, pin := range pins {
e := AssignPin(pin, module)
if e != nil {
return e
}
}
return nil
} | go | func AssignPins(pins PinList, module Module) error {
for _, pin := range pins {
e := AssignPin(pin, module)
if e != nil {
return e
}
}
return nil
} | [
"func",
"AssignPins",
"(",
"pins",
"PinList",
",",
"module",
"Module",
")",
"error",
"{",
"for",
"_",
",",
"pin",
":=",
"range",
"pins",
"{",
"e",
":=",
"AssignPin",
"(",
"pin",
",",
"module",
")",
"\n",
"if",
"e",
"!=",
"nil",
"{",
"return",
"e",
... | // Assign a set of pins. Method is public in case it is needed to hack around default driver settings. | [
"Assign",
"a",
"set",
"of",
"pins",
".",
"Method",
"is",
"public",
"in",
"case",
"it",
"is",
"needed",
"to",
"hack",
"around",
"default",
"driver",
"settings",
"."
] | 11ea3f481a1404aa1de932554dd25858ee509163 | https://github.com/mrmorphic/hwio/blob/11ea3f481a1404aa1de932554dd25858ee509163/hwio.go#L214-L222 |
149,182 | mrmorphic/hwio | hwio.go | UnassignPins | func UnassignPins(pins PinList) (er error) {
er = nil
for _, pin := range pins {
e := UnassignPin(pin)
if e != nil {
er = e
}
}
return
} | go | func UnassignPins(pins PinList) (er error) {
er = nil
for _, pin := range pins {
e := UnassignPin(pin)
if e != nil {
er = e
}
}
return
} | [
"func",
"UnassignPins",
"(",
"pins",
"PinList",
")",
"(",
"er",
"error",
")",
"{",
"er",
"=",
"nil",
"\n\n",
"for",
"_",
",",
"pin",
":=",
"range",
"pins",
"{",
"e",
":=",
"UnassignPin",
"(",
"pin",
")",
"\n",
"if",
"e",
"!=",
"nil",
"{",
"er",
... | // Unassign a set of pins. Method is public in case it is needed to hack around default driver settings. | [
"Unassign",
"a",
"set",
"of",
"pins",
".",
"Method",
"is",
"public",
"in",
"case",
"it",
"is",
"needed",
"to",
"hack",
"around",
"default",
"driver",
"settings",
"."
] | 11ea3f481a1404aa1de932554dd25858ee509163 | https://github.com/mrmorphic/hwio/blob/11ea3f481a1404aa1de932554dd25858ee509163/hwio.go#L231-L242 |
149,183 | mrmorphic/hwio | hwio.go | DigitalWrite | func DigitalWrite(pin Pin, value int) (e error) {
gpio, e := GetGPIOModule()
if e != nil {
return e
}
return gpio.DigitalWrite(pin, value)
} | go | func DigitalWrite(pin Pin, value int) (e error) {
gpio, e := GetGPIOModule()
if e != nil {
return e
}
return gpio.DigitalWrite(pin, value)
} | [
"func",
"DigitalWrite",
"(",
"pin",
"Pin",
",",
"value",
"int",
")",
"(",
"e",
"error",
")",
"{",
"gpio",
",",
"e",
":=",
"GetGPIOModule",
"(",
")",
"\n",
"if",
"e",
"!=",
"nil",
"{",
"return",
"e",
"\n",
"}",
"\n\n",
"return",
"gpio",
".",
"Digi... | // Write a value to a digital pin | [
"Write",
"a",
"value",
"to",
"a",
"digital",
"pin"
] | 11ea3f481a1404aa1de932554dd25858ee509163 | https://github.com/mrmorphic/hwio/blob/11ea3f481a1404aa1de932554dd25858ee509163/hwio.go#L245-L252 |
149,184 | mrmorphic/hwio | hwio.go | DigitalRead | func DigitalRead(pin Pin) (result int, e error) {
// @todo consider memoizing
gpio, e := GetGPIOModule()
if e != nil {
return 0, e
}
return gpio.DigitalRead(pin)
} | go | func DigitalRead(pin Pin) (result int, e error) {
// @todo consider memoizing
gpio, e := GetGPIOModule()
if e != nil {
return 0, e
}
return gpio.DigitalRead(pin)
} | [
"func",
"DigitalRead",
"(",
"pin",
"Pin",
")",
"(",
"result",
"int",
",",
"e",
"error",
")",
"{",
"// @todo consider memoizing",
"gpio",
",",
"e",
":=",
"GetGPIOModule",
"(",
")",
"\n",
"if",
"e",
"!=",
"nil",
"{",
"return",
"0",
",",
"e",
"\n",
"}",... | // Read a value from a digital pin | [
"Read",
"a",
"value",
"from",
"a",
"digital",
"pin"
] | 11ea3f481a1404aa1de932554dd25858ee509163 | https://github.com/mrmorphic/hwio/blob/11ea3f481a1404aa1de932554dd25858ee509163/hwio.go#L255-L263 |
149,185 | mrmorphic/hwio | hwio.go | Pulse | func Pulse(pin Pin, active int, durationMicroseconds int) error {
// set to inactive state, in case it wasn't already
e := DigitalWrite(pin, Negate(active))
if e != nil {
return e
}
// set to active state
e = DigitalWrite(pin, active)
if e != nil {
return e
}
DelayMicroseconds(durationMicroseconds)
// ... | go | func Pulse(pin Pin, active int, durationMicroseconds int) error {
// set to inactive state, in case it wasn't already
e := DigitalWrite(pin, Negate(active))
if e != nil {
return e
}
// set to active state
e = DigitalWrite(pin, active)
if e != nil {
return e
}
DelayMicroseconds(durationMicroseconds)
// ... | [
"func",
"Pulse",
"(",
"pin",
"Pin",
",",
"active",
"int",
",",
"durationMicroseconds",
"int",
")",
"error",
"{",
"// set to inactive state, in case it wasn't already",
"e",
":=",
"DigitalWrite",
"(",
"pin",
",",
"Negate",
"(",
"active",
")",
")",
"\n",
"if",
"... | // Helper function to pulse a pin, which must have been set as GPIO.
// 'active' is LOW or HIGH. Pulse sets pin to inactive, then active for
// 'durationMicroseconds' and the back to inactive. | [
"Helper",
"function",
"to",
"pulse",
"a",
"pin",
"which",
"must",
"have",
"been",
"set",
"as",
"GPIO",
".",
"active",
"is",
"LOW",
"or",
"HIGH",
".",
"Pulse",
"sets",
"pin",
"to",
"inactive",
"then",
"active",
"for",
"durationMicroseconds",
"and",
"the",
... | 11ea3f481a1404aa1de932554dd25858ee509163 | https://github.com/mrmorphic/hwio/blob/11ea3f481a1404aa1de932554dd25858ee509163/hwio.go#L276-L293 |
149,186 | mrmorphic/hwio | hwio.go | AnalogRead | func AnalogRead(pin Pin) (int, error) {
analog, e := GetAnalogModule()
if e != nil {
return 0, e
}
return analog.AnalogRead(pin)
} | go | func AnalogRead(pin Pin) (int, error) {
analog, e := GetAnalogModule()
if e != nil {
return 0, e
}
return analog.AnalogRead(pin)
} | [
"func",
"AnalogRead",
"(",
"pin",
"Pin",
")",
"(",
"int",
",",
"error",
")",
"{",
"analog",
",",
"e",
":=",
"GetAnalogModule",
"(",
")",
"\n",
"if",
"e",
"!=",
"nil",
"{",
"return",
"0",
",",
"e",
"\n",
"}",
"\n\n",
"return",
"analog",
".",
"Anal... | // Read an analog value from a pin. The range of values is hardware driver dependent. | [
"Read",
"an",
"analog",
"value",
"from",
"a",
"pin",
".",
"The",
"range",
"of",
"values",
"is",
"hardware",
"driver",
"dependent",
"."
] | 11ea3f481a1404aa1de932554dd25858ee509163 | https://github.com/mrmorphic/hwio/blob/11ea3f481a1404aa1de932554dd25858ee509163/hwio.go#L310-L317 |
149,187 | mrmorphic/hwio | hwio.go | Led | func Led(name string, on bool) error {
m, e := GetModule("leds")
if e != nil {
return e
}
leds := m.(LEDModule)
led, e := leds.GetLED(name)
if e != nil {
return e
}
e = led.SetTrigger("none")
if e != nil {
return e
}
return led.SetOn(on)
} | go | func Led(name string, on bool) error {
m, e := GetModule("leds")
if e != nil {
return e
}
leds := m.(LEDModule)
led, e := leds.GetLED(name)
if e != nil {
return e
}
e = led.SetTrigger("none")
if e != nil {
return e
}
return led.SetOn(on)
} | [
"func",
"Led",
"(",
"name",
"string",
",",
"on",
"bool",
")",
"error",
"{",
"m",
",",
"e",
":=",
"GetModule",
"(",
"\"",
"\"",
")",
"\n",
"if",
"e",
"!=",
"nil",
"{",
"return",
"e",
"\n",
"}",
"\n\n",
"leds",
":=",
"m",
".",
"(",
"LEDModule",
... | // Helper to turn an on-board LED on or off. Uses LED module | [
"Helper",
"to",
"turn",
"an",
"on",
"-",
"board",
"LED",
"on",
"or",
"off",
".",
"Uses",
"LED",
"module"
] | 11ea3f481a1404aa1de932554dd25858ee509163 | https://github.com/mrmorphic/hwio/blob/11ea3f481a1404aa1de932554dd25858ee509163/hwio.go#L320-L338 |
149,188 | mrmorphic/hwio | hwio.go | Delay | func Delay(duration int) {
time.Sleep(time.Duration(duration) * time.Millisecond)
} | go | func Delay(duration int) {
time.Sleep(time.Duration(duration) * time.Millisecond)
} | [
"func",
"Delay",
"(",
"duration",
"int",
")",
"{",
"time",
".",
"Sleep",
"(",
"time",
".",
"Duration",
"(",
"duration",
")",
"*",
"time",
".",
"Millisecond",
")",
"\n",
"}"
] | // Delay execution by the specified number of milliseconds. This is a helper
// function for similarity with Arduino. It is implemented using standard go
// time package. | [
"Delay",
"execution",
"by",
"the",
"specified",
"number",
"of",
"milliseconds",
".",
"This",
"is",
"a",
"helper",
"function",
"for",
"similarity",
"with",
"Arduino",
".",
"It",
"is",
"implemented",
"using",
"standard",
"go",
"time",
"package",
"."
] | 11ea3f481a1404aa1de932554dd25858ee509163 | https://github.com/mrmorphic/hwio/blob/11ea3f481a1404aa1de932554dd25858ee509163/hwio.go#L343-L345 |
149,189 | mrmorphic/hwio | hwio.go | DelayMicroseconds | func DelayMicroseconds(duration int) {
time.Sleep(time.Duration(duration) * time.Microsecond)
} | go | func DelayMicroseconds(duration int) {
time.Sleep(time.Duration(duration) * time.Microsecond)
} | [
"func",
"DelayMicroseconds",
"(",
"duration",
"int",
")",
"{",
"time",
".",
"Sleep",
"(",
"time",
".",
"Duration",
"(",
"duration",
")",
"*",
"time",
".",
"Microsecond",
")",
"\n",
"}"
] | // Delay execution by the specified number of microseconds. This is a helper
// function for similarity with Arduino. It is implemented using standard go
// time package | [
"Delay",
"execution",
"by",
"the",
"specified",
"number",
"of",
"microseconds",
".",
"This",
"is",
"a",
"helper",
"function",
"for",
"similarity",
"with",
"Arduino",
".",
"It",
"is",
"implemented",
"using",
"standard",
"go",
"time",
"package"
] | 11ea3f481a1404aa1de932554dd25858ee509163 | https://github.com/mrmorphic/hwio/blob/11ea3f481a1404aa1de932554dd25858ee509163/hwio.go#L350-L352 |
149,190 | mrmorphic/hwio | hwio.go | ShiftOut | func ShiftOut(dataPin Pin, clockPin Pin, value uint, order BitShiftOrder) error {
return ShiftOutSize(dataPin, clockPin, value, order, 8)
} | go | func ShiftOut(dataPin Pin, clockPin Pin, value uint, order BitShiftOrder) error {
return ShiftOutSize(dataPin, clockPin, value, order, 8)
} | [
"func",
"ShiftOut",
"(",
"dataPin",
"Pin",
",",
"clockPin",
"Pin",
",",
"value",
"uint",
",",
"order",
"BitShiftOrder",
")",
"error",
"{",
"return",
"ShiftOutSize",
"(",
"dataPin",
",",
"clockPin",
",",
"value",
",",
"order",
",",
"8",
")",
"\n",
"}"
] | // The approximate mapping of Arduino shiftOut, this shifts a byte out on the
// data pin, pulsing the clock pin high and then low. | [
"The",
"approximate",
"mapping",
"of",
"Arduino",
"shiftOut",
"this",
"shifts",
"a",
"byte",
"out",
"on",
"the",
"data",
"pin",
"pulsing",
"the",
"clock",
"pin",
"high",
"and",
"then",
"low",
"."
] | 11ea3f481a1404aa1de932554dd25858ee509163 | https://github.com/mrmorphic/hwio/blob/11ea3f481a1404aa1de932554dd25858ee509163/hwio.go#L365-L367 |
149,191 | mrmorphic/hwio | hwio.go | ShiftOutSize | func ShiftOutSize(dataPin Pin, clockPin Pin, value uint, order BitShiftOrder, n uint) error {
bit := uint(0)
v := value
mask := uint(1) << (n - 1)
for i := uint(0); i < n; i++ {
// get the next bit
if order == LSBFIRST {
bit = v & 1
v = v >> 1
} else {
bit = v & mask
if bit != 0 {
bit = 1
}... | go | func ShiftOutSize(dataPin Pin, clockPin Pin, value uint, order BitShiftOrder, n uint) error {
bit := uint(0)
v := value
mask := uint(1) << (n - 1)
for i := uint(0); i < n; i++ {
// get the next bit
if order == LSBFIRST {
bit = v & 1
v = v >> 1
} else {
bit = v & mask
if bit != 0 {
bit = 1
}... | [
"func",
"ShiftOutSize",
"(",
"dataPin",
"Pin",
",",
"clockPin",
"Pin",
",",
"value",
"uint",
",",
"order",
"BitShiftOrder",
",",
"n",
"uint",
")",
"error",
"{",
"bit",
":=",
"uint",
"(",
"0",
")",
"\n",
"v",
":=",
"value",
"\n",
"mask",
":=",
"uint",... | // More generic version of ShiftOut which shifts out n of data from value. The
// value shifted out is always the lowest n bits of the value, but 'order'
// determines whether the msb or lsb from that value are shifted first | [
"More",
"generic",
"version",
"of",
"ShiftOut",
"which",
"shifts",
"out",
"n",
"of",
"data",
"from",
"value",
".",
"The",
"value",
"shifted",
"out",
"is",
"always",
"the",
"lowest",
"n",
"bits",
"of",
"the",
"value",
"but",
"order",
"determines",
"whether"... | 11ea3f481a1404aa1de932554dd25858ee509163 | https://github.com/mrmorphic/hwio/blob/11ea3f481a1404aa1de932554dd25858ee509163/hwio.go#L372-L401 |
149,192 | mrmorphic/hwio | hwio.go | WriteStringToFile | func WriteStringToFile(filename string, value string) error {
// fmt.Printf("writing %s to file %s\n", value, filename)
f, e := os.OpenFile(filename, os.O_WRONLY|os.O_TRUNC, 0666)
if e != nil {
return e
}
defer f.Close()
_, e = f.WriteString(value)
return e
} | go | func WriteStringToFile(filename string, value string) error {
// fmt.Printf("writing %s to file %s\n", value, filename)
f, e := os.OpenFile(filename, os.O_WRONLY|os.O_TRUNC, 0666)
if e != nil {
return e
}
defer f.Close()
_, e = f.WriteString(value)
return e
} | [
"func",
"WriteStringToFile",
"(",
"filename",
"string",
",",
"value",
"string",
")",
"error",
"{",
"//\tfmt.Printf(\"writing %s to file %s\\n\", value, filename)",
"f",
",",
"e",
":=",
"os",
".",
"OpenFile",
"(",
"filename",
",",
"os",
".",
"O_WRONLY",
"|",
"os",
... | // Write a string to a file and close it again. | [
"Write",
"a",
"string",
"to",
"a",
"file",
"and",
"close",
"it",
"again",
"."
] | 11ea3f481a1404aa1de932554dd25858ee509163 | https://github.com/mrmorphic/hwio/blob/11ea3f481a1404aa1de932554dd25858ee509163/hwio.go#L434-L444 |
149,193 | mrmorphic/hwio | hwio.go | findFirstMatchingFile | func findFirstMatchingFile(glob string) (string, error) {
matches, e := filepath.Glob(glob)
if e != nil {
return "", e
}
if len(matches) >= 1 {
return matches[0], nil
}
return "", nil
} | go | func findFirstMatchingFile(glob string) (string, error) {
matches, e := filepath.Glob(glob)
if e != nil {
return "", e
}
if len(matches) >= 1 {
return matches[0], nil
}
return "", nil
} | [
"func",
"findFirstMatchingFile",
"(",
"glob",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"matches",
",",
"e",
":=",
"filepath",
".",
"Glob",
"(",
"glob",
")",
"\n",
"if",
"e",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"e",
"\n",
"}",
... | // Given a glob pattern, return the full path of the first matching file | [
"Given",
"a",
"glob",
"pattern",
"return",
"the",
"full",
"path",
"of",
"the",
"first",
"matching",
"file"
] | 11ea3f481a1404aa1de932554dd25858ee509163 | https://github.com/mrmorphic/hwio/blob/11ea3f481a1404aa1de932554dd25858ee509163/hwio.go#L447-L457 |
149,194 | mrmorphic/hwio | hwio.go | UInt16FromUInt8 | func UInt16FromUInt8(highByte byte, lowByte byte) uint16 {
return uint16(uint16(highByte)<<8) | uint16(lowByte)
} | go | func UInt16FromUInt8(highByte byte, lowByte byte) uint16 {
return uint16(uint16(highByte)<<8) | uint16(lowByte)
} | [
"func",
"UInt16FromUInt8",
"(",
"highByte",
"byte",
",",
"lowByte",
"byte",
")",
"uint16",
"{",
"return",
"uint16",
"(",
"uint16",
"(",
"highByte",
")",
"<<",
"8",
")",
"|",
"uint16",
"(",
"lowByte",
")",
"\n",
"}"
] | // Given a high and low byte, combine to form a single 16-bit value | [
"Given",
"a",
"high",
"and",
"low",
"byte",
"combine",
"to",
"form",
"a",
"single",
"16",
"-",
"bit",
"value"
] | 11ea3f481a1404aa1de932554dd25858ee509163 | https://github.com/mrmorphic/hwio/blob/11ea3f481a1404aa1de932554dd25858ee509163/hwio.go#L464-L466 |
149,195 | mrmorphic/hwio | hwio.go | GetModule | func GetModule(name string) (Module, error) {
driver := GetDriver()
if driver == nil {
return nil, errors.New("GetModule: Driver is not set")
}
modules := driver.GetModules()
return modules[name], nil
} | go | func GetModule(name string) (Module, error) {
driver := GetDriver()
if driver == nil {
return nil, errors.New("GetModule: Driver is not set")
}
modules := driver.GetModules()
return modules[name], nil
} | [
"func",
"GetModule",
"(",
"name",
"string",
")",
"(",
"Module",
",",
"error",
")",
"{",
"driver",
":=",
"GetDriver",
"(",
")",
"\n",
"if",
"driver",
"==",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\... | // Get a module by name. If driver is not set, it will return an error. If the driver does not support that module,
// | [
"Get",
"a",
"module",
"by",
"name",
".",
"If",
"driver",
"is",
"not",
"set",
"it",
"will",
"return",
"an",
"error",
".",
"If",
"the",
"driver",
"does",
"not",
"support",
"that",
"module"
] | 11ea3f481a1404aa1de932554dd25858ee509163 | https://github.com/mrmorphic/hwio/blob/11ea3f481a1404aa1de932554dd25858ee509163/hwio.go#L480-L488 |
149,196 | mrmorphic/hwio | module_dti2c.go | Enable | func (module *DTI2CModule) Enable() error {
// Assign the pins so nothing else can allocate them.
for _, pin := range module.definedPins {
// fmt.Printf("assigning pin %d\n", pin)
AssignPin(pin, module)
}
// @todo consider lazily opening the file. Since Enable is called automatically by BBB driver, this
// @t... | go | func (module *DTI2CModule) Enable() error {
// Assign the pins so nothing else can allocate them.
for _, pin := range module.definedPins {
// fmt.Printf("assigning pin %d\n", pin)
AssignPin(pin, module)
}
// @todo consider lazily opening the file. Since Enable is called automatically by BBB driver, this
// @t... | [
"func",
"(",
"module",
"*",
"DTI2CModule",
")",
"Enable",
"(",
")",
"error",
"{",
"// Assign the pins so nothing else can allocate them.",
"for",
"_",
",",
"pin",
":=",
"range",
"module",
".",
"definedPins",
"{",
"// fmt.Printf(\"assigning pin %d\\n\", pin)",
"AssignPin... | // enable this I2C module | [
"enable",
"this",
"I2C",
"module"
] | 11ea3f481a1404aa1de932554dd25858ee509163 | https://github.com/mrmorphic/hwio/blob/11ea3f481a1404aa1de932554dd25858ee509163/module_dti2c.go#L89-L105 |
149,197 | mrmorphic/hwio | module_dti2c.go | ReadByte | func (device *DTI2CDevice) ReadByte(command byte) (byte, error) {
device.module.Lock()
defer device.module.Unlock()
e := device.sendSlaveAddress()
if e != nil {
return 0, e
}
data := uint8(0)
busData := i2c_smbus_ioctl_data{
read_write: I2C_SMBUS_READ,
command: command,
size: I2C_SMBUS_BYTE_D... | go | func (device *DTI2CDevice) ReadByte(command byte) (byte, error) {
device.module.Lock()
defer device.module.Unlock()
e := device.sendSlaveAddress()
if e != nil {
return 0, e
}
data := uint8(0)
busData := i2c_smbus_ioctl_data{
read_write: I2C_SMBUS_READ,
command: command,
size: I2C_SMBUS_BYTE_D... | [
"func",
"(",
"device",
"*",
"DTI2CDevice",
")",
"ReadByte",
"(",
"command",
"byte",
")",
"(",
"byte",
",",
"error",
")",
"{",
"device",
".",
"module",
".",
"Lock",
"(",
")",
"\n",
"defer",
"device",
".",
"module",
".",
"Unlock",
"(",
")",
"\n\n",
"... | // Read 1 byte from the bus | [
"Read",
"1",
"byte",
"from",
"the",
"bus"
] | 11ea3f481a1404aa1de932554dd25858ee509163 | https://github.com/mrmorphic/hwio/blob/11ea3f481a1404aa1de932554dd25858ee509163/module_dti2c.go#L194-L218 |
149,198 | mrmorphic/hwio | examples/tlc5940.go | writeData | func writeData(val uint, sinPin hwio.Pin, sclkPin hwio.Pin, xlatPin hwio.Pin) {
fmt.Printf("writing data %d\n", val)
bits := 0
mask := uint(1) << 11
for i := 0; i < 16; i++ {
v := val
for j := 0; j < 12; j++ {
if (v & mask) != 0 {
hwio.DigitalWrite(sinPin, hwio.HIGH)
} else {
hwio.DigitalWrite(sin... | go | func writeData(val uint, sinPin hwio.Pin, sclkPin hwio.Pin, xlatPin hwio.Pin) {
fmt.Printf("writing data %d\n", val)
bits := 0
mask := uint(1) << 11
for i := 0; i < 16; i++ {
v := val
for j := 0; j < 12; j++ {
if (v & mask) != 0 {
hwio.DigitalWrite(sinPin, hwio.HIGH)
} else {
hwio.DigitalWrite(sin... | [
"func",
"writeData",
"(",
"val",
"uint",
",",
"sinPin",
"hwio",
".",
"Pin",
",",
"sclkPin",
"hwio",
".",
"Pin",
",",
"xlatPin",
"hwio",
".",
"Pin",
")",
"{",
"fmt",
".",
"Printf",
"(",
"\"",
"\\n",
"\"",
",",
"val",
")",
"\n",
"bits",
":=",
"0",
... | // val is a 12-bit int | [
"val",
"is",
"a",
"12",
"-",
"bit",
"int"
] | 11ea3f481a1404aa1de932554dd25858ee509163 | https://github.com/mrmorphic/hwio/blob/11ea3f481a1404aa1de932554dd25858ee509163/examples/tlc5940.go#L66-L89 |
149,199 | mrmorphic/hwio | module_bb_pwm.go | EnablePin | func (module *BBPWMModule) EnablePin(pin Pin, enabled bool) error {
if module.definedPins[pin] == nil {
return fmt.Errorf("Pin %d is not known as a PWM pin on module %s", pin, module.GetName())
}
openPin := module.openPins[pin]
if enabled {
// ensure pin is enabled by creating an open pin
if openPin == nil {... | go | func (module *BBPWMModule) EnablePin(pin Pin, enabled bool) error {
if module.definedPins[pin] == nil {
return fmt.Errorf("Pin %d is not known as a PWM pin on module %s", pin, module.GetName())
}
openPin := module.openPins[pin]
if enabled {
// ensure pin is enabled by creating an open pin
if openPin == nil {... | [
"func",
"(",
"module",
"*",
"BBPWMModule",
")",
"EnablePin",
"(",
"pin",
"Pin",
",",
"enabled",
"bool",
")",
"error",
"{",
"if",
"module",
".",
"definedPins",
"[",
"pin",
"]",
"==",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
... | // Enable a specific PWM pin. You need to call this explicitly after enabling the module, as the
// module will not by default allocate all pins, since there are a few. | [
"Enable",
"a",
"specific",
"PWM",
"pin",
".",
"You",
"need",
"to",
"call",
"this",
"explicitly",
"after",
"enabling",
"the",
"module",
"as",
"the",
"module",
"will",
"not",
"by",
"default",
"allocate",
"all",
"pins",
"since",
"there",
"are",
"a",
"few",
... | 11ea3f481a1404aa1de932554dd25858ee509163 | https://github.com/mrmorphic/hwio/blob/11ea3f481a1404aa1de932554dd25858ee509163/module_bb_pwm.go#L96-L119 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.