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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
144,300 | carlosdp/twiliogo | ip_user.go | FirstPage | func (s *IPUserList) FirstPage() (*IPUserList, error) {
return s.getPage(s.Meta.FirstPageUri)
} | go | func (s *IPUserList) FirstPage() (*IPUserList, error) {
return s.getPage(s.Meta.FirstPageUri)
} | [
"func",
"(",
"s",
"*",
"IPUserList",
")",
"FirstPage",
"(",
")",
"(",
"*",
"IPUserList",
",",
"error",
")",
"{",
"return",
"s",
".",
"getPage",
"(",
"s",
".",
"Meta",
".",
"FirstPageUri",
")",
"\n",
"}"
] | // FirstPage returns the first page of users. | [
"FirstPage",
"returns",
"the",
"first",
"page",
"of",
"users",
"."
] | b26045ebb9d15c9296ba59d94687aaf7d2080905 | https://github.com/carlosdp/twiliogo/blob/b26045ebb9d15c9296ba59d94687aaf7d2080905/ip_user.go#L156-L158 |
144,301 | carlosdp/twiliogo | ip_user.go | LastPage | func (s *IPUserList) LastPage() (*IPUserList, error) {
return s.getPage(s.Meta.LastPageUri)
} | go | func (s *IPUserList) LastPage() (*IPUserList, error) {
return s.getPage(s.Meta.LastPageUri)
} | [
"func",
"(",
"s",
"*",
"IPUserList",
")",
"LastPage",
"(",
")",
"(",
"*",
"IPUserList",
",",
"error",
")",
"{",
"return",
"s",
".",
"getPage",
"(",
"s",
".",
"Meta",
".",
"LastPageUri",
")",
"\n",
"}"
] | // LastPage returns the last page of users. | [
"LastPage",
"returns",
"the",
"last",
"page",
"of",
"users",
"."
] | b26045ebb9d15c9296ba59d94687aaf7d2080905 | https://github.com/carlosdp/twiliogo/blob/b26045ebb9d15c9296ba59d94687aaf7d2080905/ip_user.go#L161-L163 |
144,302 | carlosdp/twiliogo | ip_client.go | NewIPMessagingClient | func NewIPMessagingClient(accountSid, authToken string) *TwilioIPMessagingClient {
rootUrl := IP_MESSAGING_ROOT + "/" + IP_MESSAGING_VERSION
return &TwilioIPMessagingClient{TwilioClient{accountSid, authToken, rootUrl}}
} | go | func NewIPMessagingClient(accountSid, authToken string) *TwilioIPMessagingClient {
rootUrl := IP_MESSAGING_ROOT + "/" + IP_MESSAGING_VERSION
return &TwilioIPMessagingClient{TwilioClient{accountSid, authToken, rootUrl}}
} | [
"func",
"NewIPMessagingClient",
"(",
"accountSid",
",",
"authToken",
"string",
")",
"*",
"TwilioIPMessagingClient",
"{",
"rootUrl",
":=",
"IP_MESSAGING_ROOT",
"+",
"\"",
"\"",
"+",
"IP_MESSAGING_VERSION",
"\n",
"return",
"&",
"TwilioIPMessagingClient",
"{",
"TwilioCli... | // NewIPMessagingClient creates a new Twilio IP Messaging client. | [
"NewIPMessagingClient",
"creates",
"a",
"new",
"Twilio",
"IP",
"Messaging",
"client",
"."
] | b26045ebb9d15c9296ba59d94687aaf7d2080905 | https://github.com/carlosdp/twiliogo/blob/b26045ebb9d15c9296ba59d94687aaf7d2080905/ip_client.go#L18-L21 |
144,303 | carlosdp/twiliogo | ip_member.go | AddIPMemberToChannel | func AddIPMemberToChannel(client *TwilioIPMessagingClient, serviceSid string, channelSid string, identity string, roleSid string) (*IPMember, error) {
var member *IPMember
params := url.Values{}
params.Set("Identity", identity)
if roleSid != "" {
params.Set("RoleSid", roleSid)
}
res, err := client.post(params... | go | func AddIPMemberToChannel(client *TwilioIPMessagingClient, serviceSid string, channelSid string, identity string, roleSid string) (*IPMember, error) {
var member *IPMember
params := url.Values{}
params.Set("Identity", identity)
if roleSid != "" {
params.Set("RoleSid", roleSid)
}
res, err := client.post(params... | [
"func",
"AddIPMemberToChannel",
"(",
"client",
"*",
"TwilioIPMessagingClient",
",",
"serviceSid",
"string",
",",
"channelSid",
"string",
",",
"identity",
"string",
",",
"roleSid",
"string",
")",
"(",
"*",
"IPMember",
",",
"error",
")",
"{",
"var",
"member",
"*... | // AddIPMemberToChannel adds a member to a channel. | [
"AddIPMemberToChannel",
"adds",
"a",
"member",
"to",
"a",
"channel",
"."
] | b26045ebb9d15c9296ba59d94687aaf7d2080905 | https://github.com/carlosdp/twiliogo/blob/b26045ebb9d15c9296ba59d94687aaf7d2080905/ip_member.go#L30-L49 |
144,304 | carlosdp/twiliogo | ip_member.go | GetIPChannelMember | func GetIPChannelMember(client *TwilioIPMessagingClient, serviceSid, channelSid, sid string) (*IPMember, error) {
var member *IPMember
res, err := client.get(url.Values{}, "/Services/"+serviceSid+"/Channels/"+channelSid+"/Members/"+sid+".json")
if err != nil {
return nil, err
}
member = new(IPMember)
err = j... | go | func GetIPChannelMember(client *TwilioIPMessagingClient, serviceSid, channelSid, sid string) (*IPMember, error) {
var member *IPMember
res, err := client.get(url.Values{}, "/Services/"+serviceSid+"/Channels/"+channelSid+"/Members/"+sid+".json")
if err != nil {
return nil, err
}
member = new(IPMember)
err = j... | [
"func",
"GetIPChannelMember",
"(",
"client",
"*",
"TwilioIPMessagingClient",
",",
"serviceSid",
",",
"channelSid",
",",
"sid",
"string",
")",
"(",
"*",
"IPMember",
",",
"error",
")",
"{",
"var",
"member",
"*",
"IPMember",
"\n\n",
"res",
",",
"err",
":=",
"... | // GetIPChannelMember returns the specified IP Member in the channel. | [
"GetIPChannelMember",
"returns",
"the",
"specified",
"IP",
"Member",
"in",
"the",
"channel",
"."
] | b26045ebb9d15c9296ba59d94687aaf7d2080905 | https://github.com/carlosdp/twiliogo/blob/b26045ebb9d15c9296ba59d94687aaf7d2080905/ip_member.go#L52-L65 |
144,305 | carlosdp/twiliogo | ip_member.go | RemoveIPMemberFromChannel | func RemoveIPMemberFromChannel(client *TwilioIPMessagingClient, serviceSid, channelSid, sid string) error {
return client.delete("/Services/" + serviceSid + "/Channels/" + channelSid + "/Members/" + sid)
} | go | func RemoveIPMemberFromChannel(client *TwilioIPMessagingClient, serviceSid, channelSid, sid string) error {
return client.delete("/Services/" + serviceSid + "/Channels/" + channelSid + "/Members/" + sid)
} | [
"func",
"RemoveIPMemberFromChannel",
"(",
"client",
"*",
"TwilioIPMessagingClient",
",",
"serviceSid",
",",
"channelSid",
",",
"sid",
"string",
")",
"error",
"{",
"return",
"client",
".",
"delete",
"(",
"\"",
"\"",
"+",
"serviceSid",
"+",
"\"",
"\"",
"+",
"c... | // RemoveIPMemberFromChannel removes the given member from the channel. | [
"RemoveIPMemberFromChannel",
"removes",
"the",
"given",
"member",
"from",
"the",
"channel",
"."
] | b26045ebb9d15c9296ba59d94687aaf7d2080905 | https://github.com/carlosdp/twiliogo/blob/b26045ebb9d15c9296ba59d94687aaf7d2080905/ip_member.go#L68-L70 |
144,306 | carlosdp/twiliogo | ip_member.go | ListIPMembers | func ListIPMembers(client *TwilioIPMessagingClient, serviceSid, channelSid string) (*IPMemberList, error) {
var memberList *IPMemberList
body, err := client.get(nil, "/Services/"+serviceSid+"/Channels/"+channelSid+"/Members.json")
if err != nil {
return memberList, err
}
memberList = new(IPMemberList)
member... | go | func ListIPMembers(client *TwilioIPMessagingClient, serviceSid, channelSid string) (*IPMemberList, error) {
var memberList *IPMemberList
body, err := client.get(nil, "/Services/"+serviceSid+"/Channels/"+channelSid+"/Members.json")
if err != nil {
return memberList, err
}
memberList = new(IPMemberList)
member... | [
"func",
"ListIPMembers",
"(",
"client",
"*",
"TwilioIPMessagingClient",
",",
"serviceSid",
",",
"channelSid",
"string",
")",
"(",
"*",
"IPMemberList",
",",
"error",
")",
"{",
"var",
"memberList",
"*",
"IPMemberList",
"\n\n",
"body",
",",
"err",
":=",
"client",... | // ListIPMembers returns the first page of members. | [
"ListIPMembers",
"returns",
"the",
"first",
"page",
"of",
"members",
"."
] | b26045ebb9d15c9296ba59d94687aaf7d2080905 | https://github.com/carlosdp/twiliogo/blob/b26045ebb9d15c9296ba59d94687aaf7d2080905/ip_member.go#L73-L87 |
144,307 | carlosdp/twiliogo | ip_member.go | NextPage | func (c *IPMemberList) NextPage() (*IPMemberList, error) {
if !c.HasNextPage() {
return nil, Error{"No next page"}
}
return c.getPage(c.Meta.NextPageUri)
} | go | func (c *IPMemberList) NextPage() (*IPMemberList, error) {
if !c.HasNextPage() {
return nil, Error{"No next page"}
}
return c.getPage(c.Meta.NextPageUri)
} | [
"func",
"(",
"c",
"*",
"IPMemberList",
")",
"NextPage",
"(",
")",
"(",
"*",
"IPMemberList",
",",
"error",
")",
"{",
"if",
"!",
"c",
".",
"HasNextPage",
"(",
")",
"{",
"return",
"nil",
",",
"Error",
"{",
"\"",
"\"",
"}",
"\n",
"}",
"\n\n",
"return... | // NextPage returns the next page of members. | [
"NextPage",
"returns",
"the",
"next",
"page",
"of",
"members",
"."
] | b26045ebb9d15c9296ba59d94687aaf7d2080905 | https://github.com/carlosdp/twiliogo/blob/b26045ebb9d15c9296ba59d94687aaf7d2080905/ip_member.go#L116-L122 |
144,308 | carlosdp/twiliogo | ip_member.go | PreviousPage | func (c *IPMemberList) PreviousPage() (*IPMemberList, error) {
if !c.HasPreviousPage() {
return nil, Error{"No previous page"}
}
return c.getPage(c.Meta.NextPageUri)
} | go | func (c *IPMemberList) PreviousPage() (*IPMemberList, error) {
if !c.HasPreviousPage() {
return nil, Error{"No previous page"}
}
return c.getPage(c.Meta.NextPageUri)
} | [
"func",
"(",
"c",
"*",
"IPMemberList",
")",
"PreviousPage",
"(",
")",
"(",
"*",
"IPMemberList",
",",
"error",
")",
"{",
"if",
"!",
"c",
".",
"HasPreviousPage",
"(",
")",
"{",
"return",
"nil",
",",
"Error",
"{",
"\"",
"\"",
"}",
"\n",
"}",
"\n\n",
... | // PreviousPage returns the previous page of members. | [
"PreviousPage",
"returns",
"the",
"previous",
"page",
"of",
"members",
"."
] | b26045ebb9d15c9296ba59d94687aaf7d2080905 | https://github.com/carlosdp/twiliogo/blob/b26045ebb9d15c9296ba59d94687aaf7d2080905/ip_member.go#L130-L136 |
144,309 | carlosdp/twiliogo | ip_member.go | FirstPage | func (c *IPMemberList) FirstPage() (*IPMemberList, error) {
return c.getPage(c.Meta.FirstPageUri)
} | go | func (c *IPMemberList) FirstPage() (*IPMemberList, error) {
return c.getPage(c.Meta.FirstPageUri)
} | [
"func",
"(",
"c",
"*",
"IPMemberList",
")",
"FirstPage",
"(",
")",
"(",
"*",
"IPMemberList",
",",
"error",
")",
"{",
"return",
"c",
".",
"getPage",
"(",
"c",
".",
"Meta",
".",
"FirstPageUri",
")",
"\n",
"}"
] | // FirstPage returns the first page of members. | [
"FirstPage",
"returns",
"the",
"first",
"page",
"of",
"members",
"."
] | b26045ebb9d15c9296ba59d94687aaf7d2080905 | https://github.com/carlosdp/twiliogo/blob/b26045ebb9d15c9296ba59d94687aaf7d2080905/ip_member.go#L139-L141 |
144,310 | carlosdp/twiliogo | ip_member.go | LastPage | func (c *IPMemberList) LastPage() (*IPMemberList, error) {
return c.getPage(c.Meta.LastPageUri)
} | go | func (c *IPMemberList) LastPage() (*IPMemberList, error) {
return c.getPage(c.Meta.LastPageUri)
} | [
"func",
"(",
"c",
"*",
"IPMemberList",
")",
"LastPage",
"(",
")",
"(",
"*",
"IPMemberList",
",",
"error",
")",
"{",
"return",
"c",
".",
"getPage",
"(",
"c",
".",
"Meta",
".",
"LastPageUri",
")",
"\n",
"}"
] | // LastPage returns the last page of members. | [
"LastPage",
"returns",
"the",
"last",
"page",
"of",
"members",
"."
] | b26045ebb9d15c9296ba59d94687aaf7d2080905 | https://github.com/carlosdp/twiliogo/blob/b26045ebb9d15c9296ba59d94687aaf7d2080905/ip_member.go#L144-L146 |
144,311 | nesv/go-dynect | dynect/client.go | NewClient | func NewClient(customerName string) *Client {
return &Client{
CustomerName: customerName,
Transport: &http.Transport{Proxy: http.ProxyFromEnvironment},
}
} | go | func NewClient(customerName string) *Client {
return &Client{
CustomerName: customerName,
Transport: &http.Transport{Proxy: http.ProxyFromEnvironment},
}
} | [
"func",
"NewClient",
"(",
"customerName",
"string",
")",
"*",
"Client",
"{",
"return",
"&",
"Client",
"{",
"CustomerName",
":",
"customerName",
",",
"Transport",
":",
"&",
"http",
".",
"Transport",
"{",
"Proxy",
":",
"http",
".",
"ProxyFromEnvironment",
"}",... | // Creates a new Httpclient. | [
"Creates",
"a",
"new",
"Httpclient",
"."
] | cdd946344b54bdf7dbeac406c2f1fe93150f08ea | https://github.com/nesv/go-dynect/blob/cdd946344b54bdf7dbeac406c2f1fe93150f08ea/dynect/client.go#L54-L59 |
144,312 | nesv/go-dynect | dynect/client.go | Login | func (c *Client) Login(username, password string) error {
var req = LoginBlock{
Username: username,
Password: password,
CustomerName: c.CustomerName}
var resp LoginResponse
err := c.Do("POST", "Session", req, &resp)
if err != nil {
return err
}
c.Token = resp.Data.Token
return nil
} | go | func (c *Client) Login(username, password string) error {
var req = LoginBlock{
Username: username,
Password: password,
CustomerName: c.CustomerName}
var resp LoginResponse
err := c.Do("POST", "Session", req, &resp)
if err != nil {
return err
}
c.Token = resp.Data.Token
return nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"Login",
"(",
"username",
",",
"password",
"string",
")",
"error",
"{",
"var",
"req",
"=",
"LoginBlock",
"{",
"Username",
":",
"username",
",",
"Password",
":",
"password",
",",
"CustomerName",
":",
"c",
".",
"Cust... | // Establishes a new session with the DynECT API. | [
"Establishes",
"a",
"new",
"session",
"with",
"the",
"DynECT",
"API",
"."
] | cdd946344b54bdf7dbeac406c2f1fe93150f08ea | https://github.com/nesv/go-dynect/blob/cdd946344b54bdf7dbeac406c2f1fe93150f08ea/dynect/client.go#L77-L92 |
144,313 | ffledgling/pdns-go | api_client.go | selectHeaderAccept | func selectHeaderAccept(accepts []string) string {
if len(accepts) == 0 {
return ""
}
if contains(accepts, "application/json") {
return "application/json"
}
return strings.Join(accepts, ",")
} | go | func selectHeaderAccept(accepts []string) string {
if len(accepts) == 0 {
return ""
}
if contains(accepts, "application/json") {
return "application/json"
}
return strings.Join(accepts, ",")
} | [
"func",
"selectHeaderAccept",
"(",
"accepts",
"[",
"]",
"string",
")",
"string",
"{",
"if",
"len",
"(",
"accepts",
")",
"==",
"0",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n\n",
"if",
"contains",
"(",
"accepts",
",",
"\"",
"\"",
")",
"{",
"return",
... | // selectHeaderAccept join all accept types and return | [
"selectHeaderAccept",
"join",
"all",
"accept",
"types",
"and",
"return"
] | 2a3e8964c0f14459cf9ff47cf085c571d4018d20 | https://github.com/ffledgling/pdns-go/blob/2a3e8964c0f14459cf9ff47cf085c571d4018d20/api_client.go#L99-L109 |
144,314 | ffledgling/pdns-go | api_client.go | typeCheckParameter | func typeCheckParameter(obj interface{}, expected string, name string) error {
// Make sure there is an object.
if obj == nil {
return nil
}
// Check the type is as expected.
if reflect.TypeOf(obj).String() != expected {
return fmt.Errorf("Expected %s to be of type %s but received %s.", name, expected, reflec... | go | func typeCheckParameter(obj interface{}, expected string, name string) error {
// Make sure there is an object.
if obj == nil {
return nil
}
// Check the type is as expected.
if reflect.TypeOf(obj).String() != expected {
return fmt.Errorf("Expected %s to be of type %s but received %s.", name, expected, reflec... | [
"func",
"typeCheckParameter",
"(",
"obj",
"interface",
"{",
"}",
",",
"expected",
"string",
",",
"name",
"string",
")",
"error",
"{",
"// Make sure there is an object.",
"if",
"obj",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"// Check the type is as ... | // Verify optional parameters are of the correct type. | [
"Verify",
"optional",
"parameters",
"are",
"of",
"the",
"correct",
"type",
"."
] | 2a3e8964c0f14459cf9ff47cf085c571d4018d20 | https://github.com/ffledgling/pdns-go/blob/2a3e8964c0f14459cf9ff47cf085c571d4018d20/api_client.go#L122-L133 |
144,315 | ffledgling/pdns-go | api_client.go | callAPI | func (c *APIClient) callAPI(request *http.Request) (*http.Response, error) {
return c.cfg.HTTPClient.Do(request)
} | go | func (c *APIClient) callAPI(request *http.Request) (*http.Response, error) {
return c.cfg.HTTPClient.Do(request)
} | [
"func",
"(",
"c",
"*",
"APIClient",
")",
"callAPI",
"(",
"request",
"*",
"http",
".",
"Request",
")",
"(",
"*",
"http",
".",
"Response",
",",
"error",
")",
"{",
"return",
"c",
".",
"cfg",
".",
"HTTPClient",
".",
"Do",
"(",
"request",
")",
"\n",
"... | // callAPI do the request. | [
"callAPI",
"do",
"the",
"request",
"."
] | 2a3e8964c0f14459cf9ff47cf085c571d4018d20 | https://github.com/ffledgling/pdns-go/blob/2a3e8964c0f14459cf9ff47cf085c571d4018d20/api_client.go#L158-L160 |
144,316 | ffledgling/pdns-go | api_client.go | addFile | func addFile(w *multipart.Writer, fieldName, path string) error {
file, err := os.Open(path)
if err != nil {
return err
}
defer file.Close()
part, err := w.CreateFormFile(fieldName, filepath.Base(path))
if err != nil {
return err
}
_, err = io.Copy(part, file)
return err
} | go | func addFile(w *multipart.Writer, fieldName, path string) error {
file, err := os.Open(path)
if err != nil {
return err
}
defer file.Close()
part, err := w.CreateFormFile(fieldName, filepath.Base(path))
if err != nil {
return err
}
_, err = io.Copy(part, file)
return err
} | [
"func",
"addFile",
"(",
"w",
"*",
"multipart",
".",
"Writer",
",",
"fieldName",
",",
"path",
"string",
")",
"error",
"{",
"file",
",",
"err",
":=",
"os",
".",
"Open",
"(",
"path",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"... | // Add a file to the multipart request | [
"Add",
"a",
"file",
"to",
"the",
"multipart",
"request"
] | 2a3e8964c0f14459cf9ff47cf085c571d4018d20 | https://github.com/ffledgling/pdns-go/blob/2a3e8964c0f14459cf9ff47cf085c571d4018d20/api_client.go#L316-L330 |
144,317 | ffledgling/pdns-go | api_client.go | detectContentType | func detectContentType(body interface{}) string {
contentType := "text/plain; charset=utf-8"
kind := reflect.TypeOf(body).Kind()
switch kind {
case reflect.Struct, reflect.Map, reflect.Ptr:
contentType = "application/json; charset=utf-8"
case reflect.String:
contentType = "text/plain; charset=utf-8"
default... | go | func detectContentType(body interface{}) string {
contentType := "text/plain; charset=utf-8"
kind := reflect.TypeOf(body).Kind()
switch kind {
case reflect.Struct, reflect.Map, reflect.Ptr:
contentType = "application/json; charset=utf-8"
case reflect.String:
contentType = "text/plain; charset=utf-8"
default... | [
"func",
"detectContentType",
"(",
"body",
"interface",
"{",
"}",
")",
"string",
"{",
"contentType",
":=",
"\"",
"\"",
"\n",
"kind",
":=",
"reflect",
".",
"TypeOf",
"(",
"body",
")",
".",
"Kind",
"(",
")",
"\n",
"switch",
"kind",
"{",
"case",
"reflect",... | // detectContentType method is used to figure out `Request.Body` content type for request header | [
"detectContentType",
"method",
"is",
"used",
"to",
"figure",
"out",
"Request",
".",
"Body",
"content",
"type",
"for",
"request",
"header"
] | 2a3e8964c0f14459cf9ff47cf085c571d4018d20 | https://github.com/ffledgling/pdns-go/blob/2a3e8964c0f14459cf9ff47cf085c571d4018d20/api_client.go#L367-L385 |
144,318 | ffledgling/pdns-go | api_client.go | CacheExpires | func CacheExpires(r *http.Response) (time.Time) {
// Figure out when the cache expires.
var expires time.Time
now, err := time.Parse(time.RFC1123, r.Header.Get("date"))
if err != nil {
return time.Now()
}
respCacheControl := parseCacheControl(r.Header)
if maxAge, ok := respCacheControl["max-age"]; ok {
lif... | go | func CacheExpires(r *http.Response) (time.Time) {
// Figure out when the cache expires.
var expires time.Time
now, err := time.Parse(time.RFC1123, r.Header.Get("date"))
if err != nil {
return time.Now()
}
respCacheControl := parseCacheControl(r.Header)
if maxAge, ok := respCacheControl["max-age"]; ok {
lif... | [
"func",
"CacheExpires",
"(",
"r",
"*",
"http",
".",
"Response",
")",
"(",
"time",
".",
"Time",
")",
"{",
"// Figure out when the cache expires.",
"var",
"expires",
"time",
".",
"Time",
"\n",
"now",
",",
"err",
":=",
"time",
".",
"Parse",
"(",
"time",
"."... | // CacheExpires helper function to determine remaining time before repeating a request. | [
"CacheExpires",
"helper",
"function",
"to",
"determine",
"remaining",
"time",
"before",
"repeating",
"a",
"request",
"."
] | 2a3e8964c0f14459cf9ff47cf085c571d4018d20 | https://github.com/ffledgling/pdns-go/blob/2a3e8964c0f14459cf9ff47cf085c571d4018d20/api_client.go#L410-L435 |
144,319 | nesv/go-dynect | dynect/convenient_client.go | NewConvenientClient | func NewConvenientClient(customerName string) *ConvenientClient {
return &ConvenientClient{
Client{
CustomerName: customerName,
Transport: &http.Transport{Proxy: http.ProxyFromEnvironment},
}}
} | go | func NewConvenientClient(customerName string) *ConvenientClient {
return &ConvenientClient{
Client{
CustomerName: customerName,
Transport: &http.Transport{Proxy: http.ProxyFromEnvironment},
}}
} | [
"func",
"NewConvenientClient",
"(",
"customerName",
"string",
")",
"*",
"ConvenientClient",
"{",
"return",
"&",
"ConvenientClient",
"{",
"Client",
"{",
"CustomerName",
":",
"customerName",
",",
"Transport",
":",
"&",
"http",
".",
"Transport",
"{",
"Proxy",
":",
... | // NewConvenientClient Creates a new ConvenientClient | [
"NewConvenientClient",
"Creates",
"a",
"new",
"ConvenientClient"
] | cdd946344b54bdf7dbeac406c2f1fe93150f08ea | https://github.com/nesv/go-dynect/blob/cdd946344b54bdf7dbeac406c2f1fe93150f08ea/dynect/convenient_client.go#L17-L23 |
144,320 | nesv/go-dynect | dynect/convenient_client.go | CreateZone | func (c *ConvenientClient) CreateZone(zone, rname, serialStyle, ttl string) error {
url := fmt.Sprintf("Zone/%s/", zone)
data := &CreateZoneBlock{
RName: rname,
SerialStyle: serialStyle,
TTL: ttl,
}
if err := c.Do("POST", url, data, nil); err != nil {
return fmt.Errorf("Failed to create zone:... | go | func (c *ConvenientClient) CreateZone(zone, rname, serialStyle, ttl string) error {
url := fmt.Sprintf("Zone/%s/", zone)
data := &CreateZoneBlock{
RName: rname,
SerialStyle: serialStyle,
TTL: ttl,
}
if err := c.Do("POST", url, data, nil); err != nil {
return fmt.Errorf("Failed to create zone:... | [
"func",
"(",
"c",
"*",
"ConvenientClient",
")",
"CreateZone",
"(",
"zone",
",",
"rname",
",",
"serialStyle",
",",
"ttl",
"string",
")",
"error",
"{",
"url",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"zone",
")",
"\n",
"data",
":=",
"&",
"C... | // CreateZone method to create a zone | [
"CreateZone",
"method",
"to",
"create",
"a",
"zone"
] | cdd946344b54bdf7dbeac406c2f1fe93150f08ea | https://github.com/nesv/go-dynect/blob/cdd946344b54bdf7dbeac406c2f1fe93150f08ea/dynect/convenient_client.go#L26-L39 |
144,321 | nesv/go-dynect | dynect/convenient_client.go | GetZone | func (c *ConvenientClient) GetZone(z *Zone) error {
url := fmt.Sprintf("Zone/%s", z.Zone)
data := &ZoneResponse{}
if err := c.Do("GET", url, nil, data); err != nil {
return fmt.Errorf("Failed to get zone: %s", err)
}
z.Serial = strconv.Itoa(data.Data.Serial)
z.SerialStyle = data.Data.SerialStyle
z.Zone = dat... | go | func (c *ConvenientClient) GetZone(z *Zone) error {
url := fmt.Sprintf("Zone/%s", z.Zone)
data := &ZoneResponse{}
if err := c.Do("GET", url, nil, data); err != nil {
return fmt.Errorf("Failed to get zone: %s", err)
}
z.Serial = strconv.Itoa(data.Data.Serial)
z.SerialStyle = data.Data.SerialStyle
z.Zone = dat... | [
"func",
"(",
"c",
"*",
"ConvenientClient",
")",
"GetZone",
"(",
"z",
"*",
"Zone",
")",
"error",
"{",
"url",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"z",
".",
"Zone",
")",
"\n",
"data",
":=",
"&",
"ZoneResponse",
"{",
"}",
"\n\n",
"if",... | // GetZone method to read a zone | [
"GetZone",
"method",
"to",
"read",
"a",
"zone"
] | cdd946344b54bdf7dbeac406c2f1fe93150f08ea | https://github.com/nesv/go-dynect/blob/cdd946344b54bdf7dbeac406c2f1fe93150f08ea/dynect/convenient_client.go#L42-L56 |
144,322 | nesv/go-dynect | dynect/convenient_client.go | PublishZone | func (c *ConvenientClient) PublishZone(zone string) error {
url := fmt.Sprintf("Zone/%s", zone)
data := &PublishZoneBlock{
Publish: true,
}
if err := c.Do("PUT", url, data, nil); err != nil {
return fmt.Errorf("Failed to publish zone: %s", err)
}
return nil
} | go | func (c *ConvenientClient) PublishZone(zone string) error {
url := fmt.Sprintf("Zone/%s", zone)
data := &PublishZoneBlock{
Publish: true,
}
if err := c.Do("PUT", url, data, nil); err != nil {
return fmt.Errorf("Failed to publish zone: %s", err)
}
return nil
} | [
"func",
"(",
"c",
"*",
"ConvenientClient",
")",
"PublishZone",
"(",
"zone",
"string",
")",
"error",
"{",
"url",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"zone",
")",
"\n",
"data",
":=",
"&",
"PublishZoneBlock",
"{",
"Publish",
":",
"true",
... | // PublishZone Publish a specific zone and the changes for the current session | [
"PublishZone",
"Publish",
"a",
"specific",
"zone",
"and",
"the",
"changes",
"for",
"the",
"current",
"session"
] | cdd946344b54bdf7dbeac406c2f1fe93150f08ea | https://github.com/nesv/go-dynect/blob/cdd946344b54bdf7dbeac406c2f1fe93150f08ea/dynect/convenient_client.go#L59-L70 |
144,323 | nesv/go-dynect | dynect/convenient_client.go | DeleteZoneNode | func (c *ConvenientClient) DeleteZoneNode(zone string) error {
parentZone := strings.Join(strings.Split(zone, ".")[1:], ".")
url := fmt.Sprintf("Node/%s/%s", parentZone, zone)
if err := c.Do("DELETE", url, nil, nil); err != nil {
return fmt.Errorf("Failed to delete zone node: %s", err)
}
return nil
} | go | func (c *ConvenientClient) DeleteZoneNode(zone string) error {
parentZone := strings.Join(strings.Split(zone, ".")[1:], ".")
url := fmt.Sprintf("Node/%s/%s", parentZone, zone)
if err := c.Do("DELETE", url, nil, nil); err != nil {
return fmt.Errorf("Failed to delete zone node: %s", err)
}
return nil
} | [
"func",
"(",
"c",
"*",
"ConvenientClient",
")",
"DeleteZoneNode",
"(",
"zone",
"string",
")",
"error",
"{",
"parentZone",
":=",
"strings",
".",
"Join",
"(",
"strings",
".",
"Split",
"(",
"zone",
",",
"\"",
"\"",
")",
"[",
"1",
":",
"]",
",",
"\"",
... | // DeleteZoneNode method to delete everything in a zone | [
"DeleteZoneNode",
"method",
"to",
"delete",
"everything",
"in",
"a",
"zone"
] | cdd946344b54bdf7dbeac406c2f1fe93150f08ea | https://github.com/nesv/go-dynect/blob/cdd946344b54bdf7dbeac406c2f1fe93150f08ea/dynect/convenient_client.go#L73-L82 |
144,324 | nesv/go-dynect | dynect/convenient_client.go | DeleteZone | func (c *ConvenientClient) DeleteZone(zone string) error {
url := fmt.Sprintf("Zone/%s/", zone)
if err := c.Do("DELETE", url, nil, nil); err != nil {
return fmt.Errorf("Failed to delete zone: %s", err)
}
return nil
} | go | func (c *ConvenientClient) DeleteZone(zone string) error {
url := fmt.Sprintf("Zone/%s/", zone)
if err := c.Do("DELETE", url, nil, nil); err != nil {
return fmt.Errorf("Failed to delete zone: %s", err)
}
return nil
} | [
"func",
"(",
"c",
"*",
"ConvenientClient",
")",
"DeleteZone",
"(",
"zone",
"string",
")",
"error",
"{",
"url",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"zone",
")",
"\n\n",
"if",
"err",
":=",
"c",
".",
"Do",
"(",
"\"",
"\"",
",",
"url",... | // DeleteZone method to delete a zone | [
"DeleteZone",
"method",
"to",
"delete",
"a",
"zone"
] | cdd946344b54bdf7dbeac406c2f1fe93150f08ea | https://github.com/nesv/go-dynect/blob/cdd946344b54bdf7dbeac406c2f1fe93150f08ea/dynect/convenient_client.go#L85-L93 |
144,325 | nesv/go-dynect | dynect/convenient_client.go | GetRecordID | func (c *ConvenientClient) GetRecordID(record *Record) error {
finalID := ""
url := fmt.Sprintf("AllRecord/%s/%s", record.Zone, record.FQDN)
var records AllRecordsResponse
err := c.Do("GET", url, nil, &records)
if err != nil {
return fmt.Errorf("Failed to find Dyn record id: %s", err)
}
for _, recordURL := ran... | go | func (c *ConvenientClient) GetRecordID(record *Record) error {
finalID := ""
url := fmt.Sprintf("AllRecord/%s/%s", record.Zone, record.FQDN)
var records AllRecordsResponse
err := c.Do("GET", url, nil, &records)
if err != nil {
return fmt.Errorf("Failed to find Dyn record id: %s", err)
}
for _, recordURL := ran... | [
"func",
"(",
"c",
"*",
"ConvenientClient",
")",
"GetRecordID",
"(",
"record",
"*",
"Record",
")",
"error",
"{",
"finalID",
":=",
"\"",
"\"",
"\n",
"url",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"record",
".",
"Zone",
",",
"record",
".",
... | // GetRecordID finds the dns record ID by fetching all records for a FQDN | [
"GetRecordID",
"finds",
"the",
"dns",
"record",
"ID",
"by",
"fetching",
"all",
"records",
"for",
"a",
"FQDN"
] | cdd946344b54bdf7dbeac406c2f1fe93150f08ea | https://github.com/nesv/go-dynect/blob/cdd946344b54bdf7dbeac406c2f1fe93150f08ea/dynect/convenient_client.go#L96-L117 |
144,326 | nesv/go-dynect | dynect/convenient_client.go | CreateRecord | func (c *ConvenientClient) CreateRecord(record *Record) error {
if record.FQDN == "" && record.Name == "" {
record.FQDN = record.Zone
} else if record.FQDN == "" {
record.FQDN = fmt.Sprintf("%s.%s", record.Name, record.Zone)
}
rdata, err := buildRData(record)
if err != nil {
return fmt.Errorf("Failed to crea... | go | func (c *ConvenientClient) CreateRecord(record *Record) error {
if record.FQDN == "" && record.Name == "" {
record.FQDN = record.Zone
} else if record.FQDN == "" {
record.FQDN = fmt.Sprintf("%s.%s", record.Name, record.Zone)
}
rdata, err := buildRData(record)
if err != nil {
return fmt.Errorf("Failed to crea... | [
"func",
"(",
"c",
"*",
"ConvenientClient",
")",
"CreateRecord",
"(",
"record",
"*",
"Record",
")",
"error",
"{",
"if",
"record",
".",
"FQDN",
"==",
"\"",
"\"",
"&&",
"record",
".",
"Name",
"==",
"\"",
"\"",
"{",
"record",
".",
"FQDN",
"=",
"record",
... | // CreateRecord Method to create a DNS record | [
"CreateRecord",
"Method",
"to",
"create",
"a",
"DNS",
"record"
] | cdd946344b54bdf7dbeac406c2f1fe93150f08ea | https://github.com/nesv/go-dynect/blob/cdd946344b54bdf7dbeac406c2f1fe93150f08ea/dynect/convenient_client.go#L120-L136 |
144,327 | nesv/go-dynect | dynect/convenient_client.go | DeleteRecord | func (c *ConvenientClient) DeleteRecord(record *Record) error {
if record.FQDN == "" {
record.FQDN = fmt.Sprintf("%s.%s", record.Name, record.Zone)
}
// safety check that we have an ID, otherwise we could accidentally delete everything
if record.ID == "" {
return fmt.Errorf("No ID found! We can't continue!")
}... | go | func (c *ConvenientClient) DeleteRecord(record *Record) error {
if record.FQDN == "" {
record.FQDN = fmt.Sprintf("%s.%s", record.Name, record.Zone)
}
// safety check that we have an ID, otherwise we could accidentally delete everything
if record.ID == "" {
return fmt.Errorf("No ID found! We can't continue!")
}... | [
"func",
"(",
"c",
"*",
"ConvenientClient",
")",
"DeleteRecord",
"(",
"record",
"*",
"Record",
")",
"error",
"{",
"if",
"record",
".",
"FQDN",
"==",
"\"",
"\"",
"{",
"record",
".",
"FQDN",
"=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"record",
... | // DeleteRecord Method to delete a DNS record | [
"DeleteRecord",
"Method",
"to",
"delete",
"a",
"DNS",
"record"
] | cdd946344b54bdf7dbeac406c2f1fe93150f08ea | https://github.com/nesv/go-dynect/blob/cdd946344b54bdf7dbeac406c2f1fe93150f08ea/dynect/convenient_client.go#L156-L166 |
144,328 | nesv/go-dynect | dynect/convenient_client.go | GetRecord | func (c *ConvenientClient) GetRecord(record *Record) error {
url := fmt.Sprintf("%sRecord/%s/%s/%s", record.Type, record.Zone, record.FQDN, record.ID)
var rec RecordResponse
err := c.Do("GET", url, nil, &rec)
if err != nil {
return err
}
record.Zone = rec.Data.Zone
record.FQDN = rec.Data.FQDN
record.Name = s... | go | func (c *ConvenientClient) GetRecord(record *Record) error {
url := fmt.Sprintf("%sRecord/%s/%s/%s", record.Type, record.Zone, record.FQDN, record.ID)
var rec RecordResponse
err := c.Do("GET", url, nil, &rec)
if err != nil {
return err
}
record.Zone = rec.Data.Zone
record.FQDN = rec.Data.FQDN
record.Name = s... | [
"func",
"(",
"c",
"*",
"ConvenientClient",
")",
"GetRecord",
"(",
"record",
"*",
"Record",
")",
"error",
"{",
"url",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"record",
".",
"Type",
",",
"record",
".",
"Zone",
",",
"record",
".",
"FQDN",
"... | // GetRecord Method to get record details | [
"GetRecord",
"Method",
"to",
"get",
"record",
"details"
] | cdd946344b54bdf7dbeac406c2f1fe93150f08ea | https://github.com/nesv/go-dynect/blob/cdd946344b54bdf7dbeac406c2f1fe93150f08ea/dynect/convenient_client.go#L169-L204 |
144,329 | titpetric/factory | resputil/resputil.go | getTrace | func getTrace(errs ...error) string {
for _, err := range errs {
if err != nil {
terr, ok := err.(stackTracer)
if ok {
return fmt.Sprintf("%+v", terr.StackTrace())
}
}
}
return E_EMPTY_TRACE
} | go | func getTrace(errs ...error) string {
for _, err := range errs {
if err != nil {
terr, ok := err.(stackTracer)
if ok {
return fmt.Sprintf("%+v", terr.StackTrace())
}
}
}
return E_EMPTY_TRACE
} | [
"func",
"getTrace",
"(",
"errs",
"...",
"error",
")",
"string",
"{",
"for",
"_",
",",
"err",
":=",
"range",
"errs",
"{",
"if",
"err",
"!=",
"nil",
"{",
"terr",
",",
"ok",
":=",
"err",
".",
"(",
"stackTracer",
")",
"\n",
"if",
"ok",
"{",
"return",... | // getTrace prints the first available stack trace if any | [
"getTrace",
"prints",
"the",
"first",
"available",
"stack",
"trace",
"if",
"any"
] | ce6800c0c52f2c1da3b166b4c26f174dc55c2d02 | https://github.com/titpetric/factory/blob/ce6800c0c52f2c1da3b166b4c26f174dc55c2d02/resputil/resputil.go#L48-L58 |
144,330 | titpetric/factory | resputil/resputil.go | errorResponse | func errorResponse(err ...error) errorMessage {
response := errorMessage{}
// add stack trace to the response if available and enabled
response.Error.Message = "Unknown error"
if len(err) > 0 {
if config.Trace {
response.Error.Trace = getTrace(errors.Cause(err[0]), err[0])
}
response.Error.Message = err[0]... | go | func errorResponse(err ...error) errorMessage {
response := errorMessage{}
// add stack trace to the response if available and enabled
response.Error.Message = "Unknown error"
if len(err) > 0 {
if config.Trace {
response.Error.Trace = getTrace(errors.Cause(err[0]), err[0])
}
response.Error.Message = err[0]... | [
"func",
"errorResponse",
"(",
"err",
"...",
"error",
")",
"errorMessage",
"{",
"response",
":=",
"errorMessage",
"{",
"}",
"\n",
"// add stack trace to the response if available and enabled",
"response",
".",
"Error",
".",
"Message",
"=",
"\"",
"\"",
"\n",
"if",
"... | // error returns a structured error for API responses | [
"error",
"returns",
"a",
"structured",
"error",
"for",
"API",
"responses"
] | ce6800c0c52f2c1da3b166b4c26f174dc55c2d02 | https://github.com/titpetric/factory/blob/ce6800c0c52f2c1da3b166b4c26f174dc55c2d02/resputil/resputil.go#L61-L72 |
144,331 | titpetric/factory | resputil/resputil.go | Success | func Success(success ...string) successMessage {
response := successMessage{}
response.Success.Message = "OK"
if len(success) > 0 {
response.Success.Message = success[0]
}
return response
} | go | func Success(success ...string) successMessage {
response := successMessage{}
response.Success.Message = "OK"
if len(success) > 0 {
response.Success.Message = success[0]
}
return response
} | [
"func",
"Success",
"(",
"success",
"...",
"string",
")",
"successMessage",
"{",
"response",
":=",
"successMessage",
"{",
"}",
"\n",
"response",
".",
"Success",
".",
"Message",
"=",
"\"",
"\"",
"\n",
"if",
"len",
"(",
"success",
")",
">",
"0",
"{",
"res... | // Success returns a structured success message for API responses | [
"Success",
"returns",
"a",
"structured",
"success",
"message",
"for",
"API",
"responses"
] | ce6800c0c52f2c1da3b166b4c26f174dc55c2d02 | https://github.com/titpetric/factory/blob/ce6800c0c52f2c1da3b166b4c26f174dc55c2d02/resputil/resputil.go#L75-L82 |
144,332 | titpetric/factory | resputil/resputil.go | JSON | func JSON(w http.ResponseWriter, responses ...interface{}) {
respond := func(payload interface{}) {
var result []byte
var err error
encode := func(payload interface{}) ([]byte, error) {
if config.Pretty {
return json.MarshalIndent(payload, "", "\t")
}
return json.Marshal(payload)
}
switch value ... | go | func JSON(w http.ResponseWriter, responses ...interface{}) {
respond := func(payload interface{}) {
var result []byte
var err error
encode := func(payload interface{}) ([]byte, error) {
if config.Pretty {
return json.MarshalIndent(payload, "", "\t")
}
return json.Marshal(payload)
}
switch value ... | [
"func",
"JSON",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"responses",
"...",
"interface",
"{",
"}",
")",
"{",
"respond",
":=",
"func",
"(",
"payload",
"interface",
"{",
"}",
")",
"{",
"var",
"result",
"[",
"]",
"byte",
"\n",
"var",
"err",
"error... | // JSON responds with the first non-nil payload, formats error messages | [
"JSON",
"responds",
"with",
"the",
"first",
"non",
"-",
"nil",
"payload",
"formats",
"error",
"messages"
] | ce6800c0c52f2c1da3b166b4c26f174dc55c2d02 | https://github.com/titpetric/factory/blob/ce6800c0c52f2c1da3b166b4c26f174dc55c2d02/resputil/resputil.go#L90-L169 |
144,333 | titpetric/factory | sonyflake.go | NextID | func (s *SonyflakeFactory) NextID() uint64 {
// sonyflake errors out only when the time overflows, that will
// occur in approximately 174 years after the custom epoch.
// If the 10ms keyspace is exhausted, NextID will sleep and return
// an ID from the next interval. It can't fail, because the generator
// is pro... | go | func (s *SonyflakeFactory) NextID() uint64 {
// sonyflake errors out only when the time overflows, that will
// occur in approximately 174 years after the custom epoch.
// If the 10ms keyspace is exhausted, NextID will sleep and return
// an ID from the next interval. It can't fail, because the generator
// is pro... | [
"func",
"(",
"s",
"*",
"SonyflakeFactory",
")",
"NextID",
"(",
")",
"uint64",
"{",
"// sonyflake errors out only when the time overflows, that will",
"// occur in approximately 174 years after the custom epoch.",
"// If the 10ms keyspace is exhausted, NextID will sleep and return",
"// a... | // NextID returns uint64 ID, escalates possible error to a panic | [
"NextID",
"returns",
"uint64",
"ID",
"escalates",
"possible",
"error",
"to",
"a",
"panic"
] | ce6800c0c52f2c1da3b166b4c26f174dc55c2d02 | https://github.com/titpetric/factory/blob/ce6800c0c52f2c1da3b166b4c26f174dc55c2d02/sonyflake.go#L25-L36 |
144,334 | Songmu/go-ltsv | encode.go | OfField | func (m MarshalError) OfField(name string) error {
err := m[name]
if e, ok := err.(*MarshalTypeError); ok {
if e.err != nil {
return e.err
}
}
return m[name]
} | go | func (m MarshalError) OfField(name string) error {
err := m[name]
if e, ok := err.(*MarshalTypeError); ok {
if e.err != nil {
return e.err
}
}
return m[name]
} | [
"func",
"(",
"m",
"MarshalError",
")",
"OfField",
"(",
"name",
"string",
")",
"error",
"{",
"err",
":=",
"m",
"[",
"name",
"]",
"\n",
"if",
"e",
",",
"ok",
":=",
"err",
".",
"(",
"*",
"MarshalTypeError",
")",
";",
"ok",
"{",
"if",
"e",
".",
"er... | // OfField returns the error correspoinding to a given field | [
"OfField",
"returns",
"the",
"error",
"correspoinding",
"to",
"a",
"given",
"field"
] | c30af2b7b171f5896188903b69f8afa4ef3e7daa | https://github.com/Songmu/go-ltsv/blob/c30af2b7b171f5896188903b69f8afa4ef3e7daa/encode.go#L31-L39 |
144,335 | Songmu/go-ltsv | encode.go | MarshalTo | func MarshalTo(w io.Writer, v interface{}) error {
rv := reflect.ValueOf(v)
if rv.Kind() == reflect.Ptr {
rv = rv.Elem()
}
var err error
switch rv.Kind() {
case reflect.Map:
if m, ok := v.(map[string]string); ok {
err = marshalMapTo(w, m)
break
}
err = fmt.Errorf("not a map[string]string")
case re... | go | func MarshalTo(w io.Writer, v interface{}) error {
rv := reflect.ValueOf(v)
if rv.Kind() == reflect.Ptr {
rv = rv.Elem()
}
var err error
switch rv.Kind() {
case reflect.Map:
if m, ok := v.(map[string]string); ok {
err = marshalMapTo(w, m)
break
}
err = fmt.Errorf("not a map[string]string")
case re... | [
"func",
"MarshalTo",
"(",
"w",
"io",
".",
"Writer",
",",
"v",
"interface",
"{",
"}",
")",
"error",
"{",
"rv",
":=",
"reflect",
".",
"ValueOf",
"(",
"v",
")",
"\n",
"if",
"rv",
".",
"Kind",
"(",
")",
"==",
"reflect",
".",
"Ptr",
"{",
"rv",
"=",
... | // MarshalTo writes the LTSV encoding of v into w.
// Be aware that the writing into w is not thread safe. | [
"MarshalTo",
"writes",
"the",
"LTSV",
"encoding",
"of",
"v",
"into",
"w",
".",
"Be",
"aware",
"that",
"the",
"writing",
"into",
"w",
"is",
"not",
"thread",
"safe",
"."
] | c30af2b7b171f5896188903b69f8afa4ef3e7daa | https://github.com/Songmu/go-ltsv/blob/c30af2b7b171f5896188903b69f8afa4ef3e7daa/encode.go#L253-L273 |
144,336 | Songmu/go-ltsv | encode.go | Marshal | func Marshal(v interface{}) ([]byte, error) {
w := bytes.NewBuffer(nil)
err := MarshalTo(w, v)
return w.Bytes(), err
} | go | func Marshal(v interface{}) ([]byte, error) {
w := bytes.NewBuffer(nil)
err := MarshalTo(w, v)
return w.Bytes(), err
} | [
"func",
"Marshal",
"(",
"v",
"interface",
"{",
"}",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"w",
":=",
"bytes",
".",
"NewBuffer",
"(",
"nil",
")",
"\n",
"err",
":=",
"MarshalTo",
"(",
"w",
",",
"v",
")",
"\n",
"return",
"w",
".",
... | // Marshal returns the LTSV encoding of v | [
"Marshal",
"returns",
"the",
"LTSV",
"encoding",
"of",
"v"
] | c30af2b7b171f5896188903b69f8afa4ef3e7daa | https://github.com/Songmu/go-ltsv/blob/c30af2b7b171f5896188903b69f8afa4ef3e7daa/encode.go#L276-L280 |
144,337 | titpetric/factory | database.go | GetDSN | func (r *DatabaseFactory) GetDSN(name string) (string, error) {
addOption := func(s, match, option string) string {
if !strings.Contains(s, match) {
s += option
}
return s
}
if value, ok := r.credentials[name]; ok {
value.DSN = addOption(value.DSN, "?", "?")
value.DSN = addOption(value.DSN, "collation=... | go | func (r *DatabaseFactory) GetDSN(name string) (string, error) {
addOption := func(s, match, option string) string {
if !strings.Contains(s, match) {
s += option
}
return s
}
if value, ok := r.credentials[name]; ok {
value.DSN = addOption(value.DSN, "?", "?")
value.DSN = addOption(value.DSN, "collation=... | [
"func",
"(",
"r",
"*",
"DatabaseFactory",
")",
"GetDSN",
"(",
"name",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"addOption",
":=",
"func",
"(",
"s",
",",
"match",
",",
"option",
"string",
")",
"string",
"{",
"if",
"!",
"strings",
".",
"... | // GetDSN returns the augmented DSN from the named database | [
"GetDSN",
"returns",
"the",
"augmented",
"DSN",
"from",
"the",
"named",
"database"
] | ce6800c0c52f2c1da3b166b4c26f174dc55c2d02 | https://github.com/titpetric/factory/blob/ce6800c0c52f2c1da3b166b4c26f174dc55c2d02/database.go#L78-L95 |
144,338 | titpetric/factory | database.go | MustGet | func (r *DatabaseFactory) MustGet(dbName ...string) *DB {
db, err := r.Get(dbName...)
if err != nil {
panic(err)
}
return db
} | go | func (r *DatabaseFactory) MustGet(dbName ...string) *DB {
db, err := r.Get(dbName...)
if err != nil {
panic(err)
}
return db
} | [
"func",
"(",
"r",
"*",
"DatabaseFactory",
")",
"MustGet",
"(",
"dbName",
"...",
"string",
")",
"*",
"DB",
"{",
"db",
",",
"err",
":=",
"r",
".",
"Get",
"(",
"dbName",
"...",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\... | // MustGet is the same as Get, except it will panic on connection error | [
"MustGet",
"is",
"the",
"same",
"as",
"Get",
"except",
"it",
"will",
"panic",
"on",
"connection",
"error"
] | ce6800c0c52f2c1da3b166b4c26f174dc55c2d02 | https://github.com/titpetric/factory/blob/ce6800c0c52f2c1da3b166b4c26f174dc55c2d02/database.go#L147-L153 |
144,339 | titpetric/factory | database.go | Begin | func (r *DB) Begin() (err error) {
if r.inTx > 0 {
_, err = r.Exec(fmt.Sprintf("SAVEPOINT sp_%d", r.inTx))
}
if r.inTx == 0 {
if r.ctx == nil {
r.Log(func() {
r.Tx, err = r.DB.Beginx()
}, "BEGIN;")
} else {
r.Log(func() {
r.Tx, err = r.DB.BeginTxx(r.ctx, r.TxOpts)
}, "BEGIN; -- with context... | go | func (r *DB) Begin() (err error) {
if r.inTx > 0 {
_, err = r.Exec(fmt.Sprintf("SAVEPOINT sp_%d", r.inTx))
}
if r.inTx == 0 {
if r.ctx == nil {
r.Log(func() {
r.Tx, err = r.DB.Beginx()
}, "BEGIN;")
} else {
r.Log(func() {
r.Tx, err = r.DB.BeginTxx(r.ctx, r.TxOpts)
}, "BEGIN; -- with context... | [
"func",
"(",
"r",
"*",
"DB",
")",
"Begin",
"(",
")",
"(",
"err",
"error",
")",
"{",
"if",
"r",
".",
"inTx",
">",
"0",
"{",
"_",
",",
"err",
"=",
"r",
".",
"Exec",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"r",
".",
"inTx",
")",
... | // Begin will create a transaction in the DB with a context | [
"Begin",
"will",
"create",
"a",
"transaction",
"in",
"the",
"DB",
"with",
"a",
"context"
] | ce6800c0c52f2c1da3b166b4c26f174dc55c2d02 | https://github.com/titpetric/factory/blob/ce6800c0c52f2c1da3b166b4c26f174dc55c2d02/database.go#L193-L214 |
144,340 | titpetric/factory | database.go | Transaction | func (r *DB) Transaction(callback func() error) (err error) {
var tries int
// Perform transaction statements
tries = 0
for {
// Start transaction
if err = r.Begin(); err != nil {
return
}
if err = callback(); err == nil {
break
}
tries++
if tries > 3 {
log.Printf("Retried transaction %d t... | go | func (r *DB) Transaction(callback func() error) (err error) {
var tries int
// Perform transaction statements
tries = 0
for {
// Start transaction
if err = r.Begin(); err != nil {
return
}
if err = callback(); err == nil {
break
}
tries++
if tries > 3 {
log.Printf("Retried transaction %d t... | [
"func",
"(",
"r",
"*",
"DB",
")",
"Transaction",
"(",
"callback",
"func",
"(",
")",
"error",
")",
"(",
"err",
"error",
")",
"{",
"var",
"tries",
"int",
"\n\n",
"// Perform transaction statements",
"tries",
"=",
"0",
"\n",
"for",
"{",
"// Start transaction"... | // Transaction will create a transaction and invoke a callback | [
"Transaction",
"will",
"create",
"a",
"transaction",
"and",
"invoke",
"a",
"callback"
] | ce6800c0c52f2c1da3b166b4c26f174dc55c2d02 | https://github.com/titpetric/factory/blob/ce6800c0c52f2c1da3b166b4c26f174dc55c2d02/database.go#L217-L263 |
144,341 | titpetric/factory | database.go | SetFields | func (r *DB) SetFields(fields []string) string {
idx := 0
sql := ""
for _, field := range fields {
if idx > 0 {
sql = sql + ", "
}
idx++
sql = sql + field + "=:" + field
}
return sql
} | go | func (r *DB) SetFields(fields []string) string {
idx := 0
sql := ""
for _, field := range fields {
if idx > 0 {
sql = sql + ", "
}
idx++
sql = sql + field + "=:" + field
}
return sql
} | [
"func",
"(",
"r",
"*",
"DB",
")",
"SetFields",
"(",
"fields",
"[",
"]",
"string",
")",
"string",
"{",
"idx",
":=",
"0",
"\n",
"sql",
":=",
"\"",
"\"",
"\n",
"for",
"_",
",",
"field",
":=",
"range",
"fields",
"{",
"if",
"idx",
">",
"0",
"{",
"... | // SetFields will provide a string with SQL named bindings from a string slice | [
"SetFields",
"will",
"provide",
"a",
"string",
"with",
"SQL",
"named",
"bindings",
"from",
"a",
"string",
"slice"
] | ce6800c0c52f2c1da3b166b4c26f174dc55c2d02 | https://github.com/titpetric/factory/blob/ce6800c0c52f2c1da3b166b4c26f174dc55c2d02/database.go#L310-L321 |
144,342 | titpetric/factory | database.go | NamedExec | func (r *DB) NamedExec(query string, arg interface{}) (res sql.Result, err error) {
exec := func() (sql.Result, error) {
if r.Tx != nil {
return r.Tx.NamedExecContext(r.ctx, query, arg)
}
return r.DB.NamedExecContext(r.ctx, query, arg)
}
r.Log(func() {
res, err = exec()
}, query, arg)
return res, erro... | go | func (r *DB) NamedExec(query string, arg interface{}) (res sql.Result, err error) {
exec := func() (sql.Result, error) {
if r.Tx != nil {
return r.Tx.NamedExecContext(r.ctx, query, arg)
}
return r.DB.NamedExecContext(r.ctx, query, arg)
}
r.Log(func() {
res, err = exec()
}, query, arg)
return res, erro... | [
"func",
"(",
"r",
"*",
"DB",
")",
"NamedExec",
"(",
"query",
"string",
",",
"arg",
"interface",
"{",
"}",
")",
"(",
"res",
"sql",
".",
"Result",
",",
"err",
"error",
")",
"{",
"exec",
":=",
"func",
"(",
")",
"(",
"sql",
".",
"Result",
",",
"err... | // NamedExec adds profiling on top of the parent DB.NameExec | [
"NamedExec",
"adds",
"profiling",
"on",
"top",
"of",
"the",
"parent",
"DB",
".",
"NameExec"
] | ce6800c0c52f2c1da3b166b4c26f174dc55c2d02 | https://github.com/titpetric/factory/blob/ce6800c0c52f2c1da3b166b4c26f174dc55c2d02/database.go#L324-L337 |
144,343 | titpetric/factory | database.go | Exec | func (r *DB) Exec(query string, args ...interface{}) (res sql.Result, err error) {
exec := func() (sql.Result, error) {
if r.Tx != nil {
return r.Tx.ExecContext(r.ctx, query, args...)
}
return r.DB.ExecContext(r.ctx, query, args...)
}
r.Log(func() {
res, err = exec()
}, query, args...)
return res, err... | go | func (r *DB) Exec(query string, args ...interface{}) (res sql.Result, err error) {
exec := func() (sql.Result, error) {
if r.Tx != nil {
return r.Tx.ExecContext(r.ctx, query, args...)
}
return r.DB.ExecContext(r.ctx, query, args...)
}
r.Log(func() {
res, err = exec()
}, query, args...)
return res, err... | [
"func",
"(",
"r",
"*",
"DB",
")",
"Exec",
"(",
"query",
"string",
",",
"args",
"...",
"interface",
"{",
"}",
")",
"(",
"res",
"sql",
".",
"Result",
",",
"err",
"error",
")",
"{",
"exec",
":=",
"func",
"(",
")",
"(",
"sql",
".",
"Result",
",",
... | // Exec adds profiling on top of the parent DB.Exec | [
"Exec",
"adds",
"profiling",
"on",
"top",
"of",
"the",
"parent",
"DB",
".",
"Exec"
] | ce6800c0c52f2c1da3b166b4c26f174dc55c2d02 | https://github.com/titpetric/factory/blob/ce6800c0c52f2c1da3b166b4c26f174dc55c2d02/database.go#L340-L353 |
144,344 | titpetric/factory | database.go | Select | func (r *DB) Select(dest interface{}, query string, args ...interface{}) error {
var err error
exec := func() error {
if r.Tx != nil {
return r.Tx.SelectContext(r.ctx, dest, query, args...)
}
return r.DB.SelectContext(r.ctx, dest, query, args...)
}
r.Log(func() {
err = exec()
}, query, args...)
// cl... | go | func (r *DB) Select(dest interface{}, query string, args ...interface{}) error {
var err error
exec := func() error {
if r.Tx != nil {
return r.Tx.SelectContext(r.ctx, dest, query, args...)
}
return r.DB.SelectContext(r.ctx, dest, query, args...)
}
r.Log(func() {
err = exec()
}, query, args...)
// cl... | [
"func",
"(",
"r",
"*",
"DB",
")",
"Select",
"(",
"dest",
"interface",
"{",
"}",
",",
"query",
"string",
",",
"args",
"...",
"interface",
"{",
"}",
")",
"error",
"{",
"var",
"err",
"error",
"\n",
"exec",
":=",
"func",
"(",
")",
"error",
"{",
"if",... | // Select is a helper function that will ignore sql.ErrNoRows | [
"Select",
"is",
"a",
"helper",
"function",
"that",
"will",
"ignore",
"sql",
".",
"ErrNoRows"
] | ce6800c0c52f2c1da3b166b4c26f174dc55c2d02 | https://github.com/titpetric/factory/blob/ce6800c0c52f2c1da3b166b4c26f174dc55c2d02/database.go#L356-L375 |
144,345 | titpetric/factory | database.go | set | func (r *DB) set(data interface{}, allowed ...string) string {
set := r.setMap(data, allowed...)
return r.setImplode(", ", set)
} | go | func (r *DB) set(data interface{}, allowed ...string) string {
set := r.setMap(data, allowed...)
return r.setImplode(", ", set)
} | [
"func",
"(",
"r",
"*",
"DB",
")",
"set",
"(",
"data",
"interface",
"{",
"}",
",",
"allowed",
"...",
"string",
")",
"string",
"{",
"set",
":=",
"r",
".",
"setMap",
"(",
"data",
",",
"allowed",
"...",
")",
"\n",
"return",
"r",
".",
"setImplode",
"(... | // set uses reflection to iterate over struct fields tags, producing bindings for struct values | [
"set",
"uses",
"reflection",
"to",
"iterate",
"over",
"struct",
"fields",
"tags",
"producing",
"bindings",
"for",
"struct",
"values"
] | ce6800c0c52f2c1da3b166b4c26f174dc55c2d02 | https://github.com/titpetric/factory/blob/ce6800c0c52f2c1da3b166b4c26f174dc55c2d02/database.go#L400-L403 |
144,346 | titpetric/factory | database.go | UpdatePartial | func (r *DB) UpdatePartial(table string, args interface{}, allowed []string, keys ...string) error {
var err error
if len(keys) == 0 {
return errors.New("Full-table update not supported")
}
set := r.setMap(args, allowed...)
setWhere := make(map[string]string)
for _, key := range keys {
value, ok := set[key]
... | go | func (r *DB) UpdatePartial(table string, args interface{}, allowed []string, keys ...string) error {
var err error
if len(keys) == 0 {
return errors.New("Full-table update not supported")
}
set := r.setMap(args, allowed...)
setWhere := make(map[string]string)
for _, key := range keys {
value, ok := set[key]
... | [
"func",
"(",
"r",
"*",
"DB",
")",
"UpdatePartial",
"(",
"table",
"string",
",",
"args",
"interface",
"{",
"}",
",",
"allowed",
"[",
"]",
"string",
",",
"keys",
"...",
"string",
")",
"error",
"{",
"var",
"err",
"error",
"\n",
"if",
"len",
"(",
"keys... | // UpdatePartial is a helper function which will issue an `update` statement to the db | [
"UpdatePartial",
"is",
"a",
"helper",
"function",
"which",
"will",
"issue",
"an",
"update",
"statement",
"to",
"the",
"db"
] | ce6800c0c52f2c1da3b166b4c26f174dc55c2d02 | https://github.com/titpetric/factory/blob/ce6800c0c52f2c1da3b166b4c26f174dc55c2d02/database.go#L484-L505 |
144,347 | titpetric/factory | database.go | Replace | func (r *DB) Replace(table string, args interface{}) error {
var err error
query := "replace into " + table + " set " + r.set(args)
_, err = r.NamedExec(query, args)
return err
} | go | func (r *DB) Replace(table string, args interface{}) error {
var err error
query := "replace into " + table + " set " + r.set(args)
_, err = r.NamedExec(query, args)
return err
} | [
"func",
"(",
"r",
"*",
"DB",
")",
"Replace",
"(",
"table",
"string",
",",
"args",
"interface",
"{",
"}",
")",
"error",
"{",
"var",
"err",
"error",
"\n",
"query",
":=",
"\"",
"\"",
"+",
"table",
"+",
"\"",
"\"",
"+",
"r",
".",
"set",
"(",
"args"... | // Replace is a helper function which will issue an `replace` statement to the database | [
"Replace",
"is",
"a",
"helper",
"function",
"which",
"will",
"issue",
"an",
"replace",
"statement",
"to",
"the",
"database"
] | ce6800c0c52f2c1da3b166b4c26f174dc55c2d02 | https://github.com/titpetric/factory/blob/ce6800c0c52f2c1da3b166b4c26f174dc55c2d02/database.go#L529-L534 |
144,348 | titpetric/factory | profiler.go | new | func (DatabaseProfilerContext) new(query string, args ...interface{}) *DatabaseProfilerContext {
a := fmt.Sprintf("%#v", args)
return &DatabaseProfilerContext{
Query: query,
Args: a[15 : len(a)-1], // omits `[]interface {...}`
Time: time.Now(),
}
} | go | func (DatabaseProfilerContext) new(query string, args ...interface{}) *DatabaseProfilerContext {
a := fmt.Sprintf("%#v", args)
return &DatabaseProfilerContext{
Query: query,
Args: a[15 : len(a)-1], // omits `[]interface {...}`
Time: time.Now(),
}
} | [
"func",
"(",
"DatabaseProfilerContext",
")",
"new",
"(",
"query",
"string",
",",
"args",
"...",
"interface",
"{",
"}",
")",
"*",
"DatabaseProfilerContext",
"{",
"a",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"args",
")",
"\n",
"return",
"&",
"... | // new is the private constructor for a DatabaseProfilerContext | [
"new",
"is",
"the",
"private",
"constructor",
"for",
"a",
"DatabaseProfilerContext"
] | ce6800c0c52f2c1da3b166b4c26f174dc55c2d02 | https://github.com/titpetric/factory/blob/ce6800c0c52f2c1da3b166b4c26f174dc55c2d02/profiler.go#L23-L30 |
144,349 | titpetric/factory | profiler.go | Post | func (this *DatabaseProfilerMemory) Post(p *DatabaseProfilerContext) {
this.Lock()
this.Log = append(this.Log, p.String())
this.Unlock()
} | go | func (this *DatabaseProfilerMemory) Post(p *DatabaseProfilerContext) {
this.Lock()
this.Log = append(this.Log, p.String())
this.Unlock()
} | [
"func",
"(",
"this",
"*",
"DatabaseProfilerMemory",
")",
"Post",
"(",
"p",
"*",
"DatabaseProfilerContext",
")",
"{",
"this",
".",
"Lock",
"(",
")",
"\n",
"this",
".",
"Log",
"=",
"append",
"(",
"this",
".",
"Log",
",",
"p",
".",
"String",
"(",
")",
... | // Post prints the query statistics | [
"Post",
"prints",
"the",
"query",
"statistics"
] | ce6800c0c52f2c1da3b166b4c26f174dc55c2d02 | https://github.com/titpetric/factory/blob/ce6800c0c52f2c1da3b166b4c26f174dc55c2d02/profiler.go#L63-L67 |
144,350 | titpetric/factory | profiler.go | Flush | func (this *DatabaseProfilerMemory) Flush() {
this.Lock()
count := len(this.Log)
for _, line := range this.Log[:count] {
fmt.Println(line)
}
this.Log = this.Log[count:]
this.Unlock()
} | go | func (this *DatabaseProfilerMemory) Flush() {
this.Lock()
count := len(this.Log)
for _, line := range this.Log[:count] {
fmt.Println(line)
}
this.Log = this.Log[count:]
this.Unlock()
} | [
"func",
"(",
"this",
"*",
"DatabaseProfilerMemory",
")",
"Flush",
"(",
")",
"{",
"this",
".",
"Lock",
"(",
")",
"\n",
"count",
":=",
"len",
"(",
"this",
".",
"Log",
")",
"\n",
"for",
"_",
",",
"line",
":=",
"range",
"this",
".",
"Log",
"[",
":",
... | // Flush log to stdout with fmt.Println | [
"Flush",
"log",
"to",
"stdout",
"with",
"fmt",
".",
"Println"
] | ce6800c0c52f2c1da3b166b4c26f174dc55c2d02 | https://github.com/titpetric/factory/blob/ce6800c0c52f2c1da3b166b4c26f174dc55c2d02/profiler.go#L70-L78 |
144,351 | svent/go-nbreader | nbreader.go | NewNBReader | func NewNBReader(reader io.Reader, blockSize int, options ...Option) *NBReader {
dataChan := make(chan []byte)
r := NBReader{reader: reader, dataChan: dataChan, blockSize: blockSize}
for _, option := range options {
option(&r)
}
go r.readInput()
return &r
} | go | func NewNBReader(reader io.Reader, blockSize int, options ...Option) *NBReader {
dataChan := make(chan []byte)
r := NBReader{reader: reader, dataChan: dataChan, blockSize: blockSize}
for _, option := range options {
option(&r)
}
go r.readInput()
return &r
} | [
"func",
"NewNBReader",
"(",
"reader",
"io",
".",
"Reader",
",",
"blockSize",
"int",
",",
"options",
"...",
"Option",
")",
"*",
"NBReader",
"{",
"dataChan",
":=",
"make",
"(",
"chan",
"[",
"]",
"byte",
")",
"\n",
"r",
":=",
"NBReader",
"{",
"reader",
... | // NewNBReader returns a new NBReader with the given block size. | [
"NewNBReader",
"returns",
"a",
"new",
"NBReader",
"with",
"the",
"given",
"block",
"size",
"."
] | 7cef48da76dca6a496faa7fe63e39ed665cbd219 | https://github.com/svent/go-nbreader/blob/7cef48da76dca6a496faa7fe63e39ed665cbd219/nbreader.go#L64-L72 |
144,352 | svent/go-nbreader | nbreader.go | readInput | func (r *NBReader) readInput() {
for {
tmp := make([]byte, r.blockSize)
length, err := r.reader.Read(tmp)
if err != nil {
break
}
r.dataChan <- tmp[0:length]
}
close(r.dataChan)
} | go | func (r *NBReader) readInput() {
for {
tmp := make([]byte, r.blockSize)
length, err := r.reader.Read(tmp)
if err != nil {
break
}
r.dataChan <- tmp[0:length]
}
close(r.dataChan)
} | [
"func",
"(",
"r",
"*",
"NBReader",
")",
"readInput",
"(",
")",
"{",
"for",
"{",
"tmp",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"r",
".",
"blockSize",
")",
"\n",
"length",
",",
"err",
":=",
"r",
".",
"reader",
".",
"Read",
"(",
"tmp",
")",
"... | // readInput is used by a goroutine to read data from the underlying io.Reader | [
"readInput",
"is",
"used",
"by",
"a",
"goroutine",
"to",
"read",
"data",
"from",
"the",
"underlying",
"io",
".",
"Reader"
] | 7cef48da76dca6a496faa7fe63e39ed665cbd219 | https://github.com/svent/go-nbreader/blob/7cef48da76dca6a496faa7fe63e39ed665cbd219/nbreader.go#L123-L133 |
144,353 | omniscale/magnacarto | builder/builder.go | AddMSS | func (b *Builder) AddMSS(mss string) {
b.mss = append(b.mss, mss)
} | go | func (b *Builder) AddMSS(mss string) {
b.mss = append(b.mss, mss)
} | [
"func",
"(",
"b",
"*",
"Builder",
")",
"AddMSS",
"(",
"mss",
"string",
")",
"{",
"b",
".",
"mss",
"=",
"append",
"(",
"b",
".",
"mss",
",",
"mss",
")",
"\n",
"}"
] | // AddMSS adds another mss file to this builder. | [
"AddMSS",
"adds",
"another",
"mss",
"file",
"to",
"this",
"builder",
"."
] | 70ccb049d7e2d0da1c5a10ef3ea37eac30cd142b | https://github.com/omniscale/magnacarto/blob/70ccb049d7e2d0da1c5a10ef3ea37eac30cd142b/builder/builder.go#L32-L34 |
144,354 | omniscale/magnacarto | builder/builder.go | Build | func (b *Builder) Build() error {
layerIDs := []string{}
layers := []mml.Layer{}
var mmlObj *mml.MML
if b.mml != "" {
r, err := os.Open(b.mml)
if err != nil {
return err
}
defer r.Close()
mmlObj, err = mml.Parse(r)
if err != nil {
return err
}
if len(b.mss) == 0 {
for _, s := range mmlObj.... | go | func (b *Builder) Build() error {
layerIDs := []string{}
layers := []mml.Layer{}
var mmlObj *mml.MML
if b.mml != "" {
r, err := os.Open(b.mml)
if err != nil {
return err
}
defer r.Close()
mmlObj, err = mml.Parse(r)
if err != nil {
return err
}
if len(b.mss) == 0 {
for _, s := range mmlObj.... | [
"func",
"(",
"b",
"*",
"Builder",
")",
"Build",
"(",
")",
"error",
"{",
"layerIDs",
":=",
"[",
"]",
"string",
"{",
"}",
"\n",
"layers",
":=",
"[",
"]",
"mml",
".",
"Layer",
"{",
"}",
"\n\n",
"var",
"mmlObj",
"*",
"mml",
".",
"MML",
"\n",
"if",
... | // Build parses MML, MSS files, builds all rules and adds them to the Map. | [
"Build",
"parses",
"MML",
"MSS",
"files",
"builds",
"all",
"rules",
"and",
"adds",
"them",
"to",
"the",
"Map",
"."
] | 70ccb049d7e2d0da1c5a10ef3ea37eac30cd142b | https://github.com/omniscale/magnacarto/blob/70ccb049d7e2d0da1c5a10ef3ea37eac30cd142b/builder/builder.go#L52-L127 |
144,355 | omniscale/magnacarto | builder/builder.go | BuildMapFromString | func BuildMapFromString(m Map, mml *mml.MML, style string) error {
carto := mss.New()
err := carto.ParseString(style)
if err != nil {
return err
}
if err := carto.Evaluate(); err != nil {
return err
}
if m, ok := m.(MapZoomScaleSetter); ok {
if mml.Map.ZoomScales != nil {
m.SetZoomScales(mml.Map.ZoomS... | go | func BuildMapFromString(m Map, mml *mml.MML, style string) error {
carto := mss.New()
err := carto.ParseString(style)
if err != nil {
return err
}
if err := carto.Evaluate(); err != nil {
return err
}
if m, ok := m.(MapZoomScaleSetter); ok {
if mml.Map.ZoomScales != nil {
m.SetZoomScales(mml.Map.ZoomS... | [
"func",
"BuildMapFromString",
"(",
"m",
"Map",
",",
"mml",
"*",
"mml",
".",
"MML",
",",
"style",
"string",
")",
"error",
"{",
"carto",
":=",
"mss",
".",
"New",
"(",
")",
"\n\n",
"err",
":=",
"carto",
".",
"ParseString",
"(",
"style",
")",
"\n",
"if... | // BuildMapFromString parses the style from a string and adds all
// mml.Layers to the map. | [
"BuildMapFromString",
"parses",
"the",
"style",
"from",
"a",
"string",
"and",
"adds",
"all",
"mml",
".",
"Layers",
"to",
"the",
"map",
"."
] | 70ccb049d7e2d0da1c5a10ef3ea37eac30cd142b | https://github.com/omniscale/magnacarto/blob/70ccb049d7e2d0da1c5a10ef3ea37eac30cd142b/builder/builder.go#L153-L184 |
144,356 | omniscale/magnacarto | builder/mapserver/fmt.go | fmtFloatProp | func fmtFloatProp(p *mss.Properties, name string, scale float64) *string {
v, ok := p.GetFloat(name)
if !ok {
return nil
}
r := strconv.FormatFloat(v*scale, 'f', -1, 64)
return &r
} | go | func fmtFloatProp(p *mss.Properties, name string, scale float64) *string {
v, ok := p.GetFloat(name)
if !ok {
return nil
}
r := strconv.FormatFloat(v*scale, 'f', -1, 64)
return &r
} | [
"func",
"fmtFloatProp",
"(",
"p",
"*",
"mss",
".",
"Properties",
",",
"name",
"string",
",",
"scale",
"float64",
")",
"*",
"string",
"{",
"v",
",",
"ok",
":=",
"p",
".",
"GetFloat",
"(",
"name",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
"... | // fmtFloatProp formats a scaled float property. Returns nil if property is not set or ont a float. | [
"fmtFloatProp",
"formats",
"a",
"scaled",
"float",
"property",
".",
"Returns",
"nil",
"if",
"property",
"is",
"not",
"set",
"or",
"ont",
"a",
"float",
"."
] | 70ccb049d7e2d0da1c5a10ef3ea37eac30cd142b | https://github.com/omniscale/magnacarto/blob/70ccb049d7e2d0da1c5a10ef3ea37eac30cd142b/builder/mapserver/fmt.go#L34-L41 |
144,357 | omniscale/magnacarto | builder/mapserver/fmt.go | indent | func indent(s, prefix string) string {
return string(indentBytes([]byte(s), []byte(prefix)))
} | go | func indent(s, prefix string) string {
return string(indentBytes([]byte(s), []byte(prefix)))
} | [
"func",
"indent",
"(",
"s",
",",
"prefix",
"string",
")",
"string",
"{",
"return",
"string",
"(",
"indentBytes",
"(",
"[",
"]",
"byte",
"(",
"s",
")",
",",
"[",
"]",
"byte",
"(",
"prefix",
")",
")",
")",
"\n",
"}"
] | // indent inserts prefix at the beginning of each non-empty line of s. The
// end-of-line marker is NL. | [
"indent",
"inserts",
"prefix",
"at",
"the",
"beginning",
"of",
"each",
"non",
"-",
"empty",
"line",
"of",
"s",
".",
"The",
"end",
"-",
"of",
"-",
"line",
"marker",
"is",
"NL",
"."
] | 70ccb049d7e2d0da1c5a10ef3ea37eac30cd142b | https://github.com/omniscale/magnacarto/blob/70ccb049d7e2d0da1c5a10ef3ea37eac30cd142b/builder/mapserver/fmt.go#L172-L174 |
144,358 | omniscale/magnacarto | builder/cache.go | ClearTill | func (c *Cache) ClearTill(till time.Time) {
c.mu.Lock()
defer c.mu.Unlock()
if c.destDir != "" {
// all in same dir. also remove files with different suffixes (e.g. foo.map.font.lst)
files, err := filepath.Glob(filepath.Join(c.destDir, stylePrefix+"*"))
if err != nil {
log.Println("cleanup error: ", err)
... | go | func (c *Cache) ClearTill(till time.Time) {
c.mu.Lock()
defer c.mu.Unlock()
if c.destDir != "" {
// all in same dir. also remove files with different suffixes (e.g. foo.map.font.lst)
files, err := filepath.Glob(filepath.Join(c.destDir, stylePrefix+"*"))
if err != nil {
log.Println("cleanup error: ", err)
... | [
"func",
"(",
"c",
"*",
"Cache",
")",
"ClearTill",
"(",
"till",
"time",
".",
"Time",
")",
"{",
"c",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"c",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n\n",
"if",
"c",
".",
"destDir",
"!=",
"\"",
"\"",
... | // ClearTill removes all cached styles that are older then till. | [
"ClearTill",
"removes",
"all",
"cached",
"styles",
"that",
"are",
"older",
"then",
"till",
"."
] | 70ccb049d7e2d0da1c5a10ef3ea37eac30cd142b | https://github.com/omniscale/magnacarto/blob/70ccb049d7e2d0da1c5a10ef3ea37eac30cd142b/builder/cache.go#L108-L140 |
144,359 | omniscale/magnacarto | mss/scanner.go | updatePosition | func (s *scanner) updatePosition(text string) {
width := utf8.RuneCountInString(text)
lines := strings.Count(text, "\n")
s.row += lines
if lines == 0 {
s.col += width
} else {
s.col = utf8.RuneCountInString(text[strings.LastIndex(text, "\n"):])
}
s.pos += len(text)
} | go | func (s *scanner) updatePosition(text string) {
width := utf8.RuneCountInString(text)
lines := strings.Count(text, "\n")
s.row += lines
if lines == 0 {
s.col += width
} else {
s.col = utf8.RuneCountInString(text[strings.LastIndex(text, "\n"):])
}
s.pos += len(text)
} | [
"func",
"(",
"s",
"*",
"scanner",
")",
"updatePosition",
"(",
"text",
"string",
")",
"{",
"width",
":=",
"utf8",
".",
"RuneCountInString",
"(",
"text",
")",
"\n",
"lines",
":=",
"strings",
".",
"Count",
"(",
"text",
",",
"\"",
"\\n",
"\"",
")",
"\n",... | // updatePosition updates input coordinates based on the consumed text. | [
"updatePosition",
"updates",
"input",
"coordinates",
"based",
"on",
"the",
"consumed",
"text",
"."
] | 70ccb049d7e2d0da1c5a10ef3ea37eac30cd142b | https://github.com/omniscale/magnacarto/blob/70ccb049d7e2d0da1c5a10ef3ea37eac30cd142b/mss/scanner.go#L396-L406 |
144,360 | omniscale/magnacarto | mss/scanner.go | emitToken | func (s *scanner) emitToken(t tokenType, v string) *token {
token := &token{t, v, s.row, s.col}
s.updatePosition(v)
return token
} | go | func (s *scanner) emitToken(t tokenType, v string) *token {
token := &token{t, v, s.row, s.col}
s.updatePosition(v)
return token
} | [
"func",
"(",
"s",
"*",
"scanner",
")",
"emitToken",
"(",
"t",
"tokenType",
",",
"v",
"string",
")",
"*",
"token",
"{",
"token",
":=",
"&",
"token",
"{",
"t",
",",
"v",
",",
"s",
".",
"row",
",",
"s",
".",
"col",
"}",
"\n",
"s",
".",
"updatePo... | // emitToken returns a token for the string v and updates the scanner position. | [
"emitToken",
"returns",
"a",
"token",
"for",
"the",
"string",
"v",
"and",
"updates",
"the",
"scanner",
"position",
"."
] | 70ccb049d7e2d0da1c5a10ef3ea37eac30cd142b | https://github.com/omniscale/magnacarto/blob/70ccb049d7e2d0da1c5a10ef3ea37eac30cd142b/mss/scanner.go#L409-L413 |
144,361 | omniscale/magnacarto | mss/scanner.go | emitSimple | func (s *scanner) emitSimple(t tokenType, v string) *token {
token := &token{t, v, s.row, s.col}
s.col += len(v)
s.pos += len(v)
return token
} | go | func (s *scanner) emitSimple(t tokenType, v string) *token {
token := &token{t, v, s.row, s.col}
s.col += len(v)
s.pos += len(v)
return token
} | [
"func",
"(",
"s",
"*",
"scanner",
")",
"emitSimple",
"(",
"t",
"tokenType",
",",
"v",
"string",
")",
"*",
"token",
"{",
"token",
":=",
"&",
"token",
"{",
"t",
",",
"v",
",",
"s",
".",
"row",
",",
"s",
".",
"col",
"}",
"\n",
"s",
".",
"col",
... | // emitSimple returns a token for the string v and updates the scanner
// position in a simplified manner.
//
// The string is known to have only ASCII characters and to not have a newline. | [
"emitSimple",
"returns",
"a",
"token",
"for",
"the",
"string",
"v",
"and",
"updates",
"the",
"scanner",
"position",
"in",
"a",
"simplified",
"manner",
".",
"The",
"string",
"is",
"known",
"to",
"have",
"only",
"ASCII",
"characters",
"and",
"to",
"not",
"ha... | 70ccb049d7e2d0da1c5a10ef3ea37eac30cd142b | https://github.com/omniscale/magnacarto/blob/70ccb049d7e2d0da1c5a10ef3ea37eac30cd142b/mss/scanner.go#L419-L424 |
144,362 | omniscale/magnacarto | mss/properties.go | pos | func (p *Properties) pos(property key) position {
return p.values[property].pos
} | go | func (p *Properties) pos(property key) position {
return p.values[property].pos
} | [
"func",
"(",
"p",
"*",
"Properties",
")",
"pos",
"(",
"property",
"key",
")",
"position",
"{",
"return",
"p",
".",
"values",
"[",
"property",
"]",
".",
"pos",
"\n",
"}"
] | // pos returns position of the property in the .mss file. | [
"pos",
"returns",
"position",
"of",
"the",
"property",
"in",
"the",
".",
"mss",
"file",
"."
] | 70ccb049d7e2d0da1c5a10ef3ea37eac30cd142b | https://github.com/omniscale/magnacarto/blob/70ccb049d7e2d0da1c5a10ef3ea37eac30cd142b/mss/properties.go#L56-L58 |
144,363 | omniscale/magnacarto | mss/properties.go | SortedPrefixes | func SortedPrefixes(p *Properties, prefixes []string) []Prefix {
/*
With properties for:
{
line-width: 2;
top/line-width: 1;
polygon-fill: red;
}
SortedPrefixes(p, []string{"line-", "polygon-"})
will return
[]Prefix{{"line-", ""}, {"line-", "top"}, {"polygon-", ""}}
*/
pp := ... | go | func SortedPrefixes(p *Properties, prefixes []string) []Prefix {
/*
With properties for:
{
line-width: 2;
top/line-width: 1;
polygon-fill: red;
}
SortedPrefixes(p, []string{"line-", "polygon-"})
will return
[]Prefix{{"line-", ""}, {"line-", "top"}, {"polygon-", ""}}
*/
pp := ... | [
"func",
"SortedPrefixes",
"(",
"p",
"*",
"Properties",
",",
"prefixes",
"[",
"]",
"string",
")",
"[",
"]",
"Prefix",
"{",
"/*\n\t With properties for:\n\t {\n\t \tline-width: 2;\n\t \ttop/line-width: 1;\n\t \tpolygon-fill: red;\n\t }\n\n\t SortedPrefixes(p, []string{\"l... | // SortedPrefixes returns a slice of all propertry prefixes, sorted by their first occurence. | [
"SortedPrefixes",
"returns",
"a",
"slice",
"of",
"all",
"propertry",
"prefixes",
"sorted",
"by",
"their",
"first",
"occurence",
"."
] | 70ccb049d7e2d0da1c5a10ef3ea37eac30cd142b | https://github.com/omniscale/magnacarto/blob/70ccb049d7e2d0da1c5a10ef3ea37eac30cd142b/mss/properties.go#L173-L199 |
144,364 | omniscale/magnacarto | mss/properties.go | GetStringList | func (p *Properties) GetStringList(property string) ([]string, bool) {
v, ok := p.get(property)
if !ok {
return nil, false
}
if s, ok := v.(string); ok {
return []string{s}, true
}
l, ok := v.([]Value)
if !ok {
return nil, false
}
strs := make([]string, len(l))
for i := range l {
strs[i], ok = l[i].(s... | go | func (p *Properties) GetStringList(property string) ([]string, bool) {
v, ok := p.get(property)
if !ok {
return nil, false
}
if s, ok := v.(string); ok {
return []string{s}, true
}
l, ok := v.([]Value)
if !ok {
return nil, false
}
strs := make([]string, len(l))
for i := range l {
strs[i], ok = l[i].(s... | [
"func",
"(",
"p",
"*",
"Properties",
")",
"GetStringList",
"(",
"property",
"string",
")",
"(",
"[",
"]",
"string",
",",
"bool",
")",
"{",
"v",
",",
"ok",
":=",
"p",
".",
"get",
"(",
"property",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
... | // GetStringList returns property as a list of strings, single string is converted to a slice. | [
"GetStringList",
"returns",
"property",
"as",
"a",
"list",
"of",
"strings",
"single",
"string",
"is",
"converted",
"to",
"a",
"slice",
"."
] | 70ccb049d7e2d0da1c5a10ef3ea37eac30cd142b | https://github.com/omniscale/magnacarto/blob/70ccb049d7e2d0da1c5a10ef3ea37eac30cd142b/mss/properties.go#L262-L282 |
144,365 | omniscale/magnacarto | mss/properties.go | GetStopList | func (p *Properties) GetStopList(property string) ([]Stop, bool) {
v, ok := p.get(property)
if !ok {
return nil, false
}
l, ok := v.([]Value)
if !ok {
return nil, false
}
stops := make([]Stop, len(l))
for i := range l {
stops[i], ok = l[i].(Stop)
if !ok {
return nil, false
}
}
return stops, true
... | go | func (p *Properties) GetStopList(property string) ([]Stop, bool) {
v, ok := p.get(property)
if !ok {
return nil, false
}
l, ok := v.([]Value)
if !ok {
return nil, false
}
stops := make([]Stop, len(l))
for i := range l {
stops[i], ok = l[i].(Stop)
if !ok {
return nil, false
}
}
return stops, true
... | [
"func",
"(",
"p",
"*",
"Properties",
")",
"GetStopList",
"(",
"property",
"string",
")",
"(",
"[",
"]",
"Stop",
",",
"bool",
")",
"{",
"v",
",",
"ok",
":=",
"p",
".",
"get",
"(",
"property",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
","... | // GetStopList returns property as a list of Stops. | [
"GetStopList",
"returns",
"property",
"as",
"a",
"list",
"of",
"Stops",
"."
] | 70ccb049d7e2d0da1c5a10ef3ea37eac30cd142b | https://github.com/omniscale/magnacarto/blob/70ccb049d7e2d0da1c5a10ef3ea37eac30cd142b/mss/properties.go#L304-L321 |
144,366 | omniscale/magnacarto | mss/properties.go | combineProperties | func combineProperties(a, b *Properties) *Properties {
r := &Properties{values: make(map[key]attr)}
for k, v := range a.values {
r.values[k] = v
}
r.updateMissing(b)
return r
} | go | func combineProperties(a, b *Properties) *Properties {
r := &Properties{values: make(map[key]attr)}
for k, v := range a.values {
r.values[k] = v
}
r.updateMissing(b)
return r
} | [
"func",
"combineProperties",
"(",
"a",
",",
"b",
"*",
"Properties",
")",
"*",
"Properties",
"{",
"r",
":=",
"&",
"Properties",
"{",
"values",
":",
"make",
"(",
"map",
"[",
"key",
"]",
"attr",
")",
"}",
"\n",
"for",
"k",
",",
"v",
":=",
"range",
"... | // combineProperties returns new properties all values from a and b. uses more specific value
// for duplicate keys. | [
"combineProperties",
"returns",
"new",
"properties",
"all",
"values",
"from",
"a",
"and",
"b",
".",
"uses",
"more",
"specific",
"value",
"for",
"duplicate",
"keys",
"."
] | 70ccb049d7e2d0da1c5a10ef3ea37eac30cd142b | https://github.com/omniscale/magnacarto/blob/70ccb049d7e2d0da1c5a10ef3ea37eac30cd142b/mss/properties.go#L325-L332 |
144,367 | omniscale/magnacarto | mss/spec.go | validProperty | func validProperty(property string, value interface{}) (bool, bool) {
checkFunc, ok := attributeTypes[property]
if !ok {
return false, false
}
return true, checkFunc(value)
} | go | func validProperty(property string, value interface{}) (bool, bool) {
checkFunc, ok := attributeTypes[property]
if !ok {
return false, false
}
return true, checkFunc(value)
} | [
"func",
"validProperty",
"(",
"property",
"string",
",",
"value",
"interface",
"{",
"}",
")",
"(",
"bool",
",",
"bool",
")",
"{",
"checkFunc",
",",
"ok",
":=",
"attributeTypes",
"[",
"property",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"false",
",",
... | // validProperty returns whether the property and the value is valid. | [
"validProperty",
"returns",
"whether",
"the",
"property",
"and",
"the",
"value",
"is",
"valid",
"."
] | 70ccb049d7e2d0da1c5a10ef3ea37eac30cd142b | https://github.com/omniscale/magnacarto/blob/70ccb049d7e2d0da1c5a10ef3ea37eac30cd142b/mss/spec.go#L410-L416 |
144,368 | omniscale/magnacarto | cmd/magnaserv/project.go | findProjects | func findProjects(path string) ([]project, error) {
projects := []project{}
var mmls []string
if files, err := filepath.Glob(filepath.Join(path, "*.mml")); err != nil {
return nil, err
} else {
mmls = append(mmls, files...)
}
if files, err := filepath.Glob(filepath.Join(path, "*", "*.mml")); err != nil {
r... | go | func findProjects(path string) ([]project, error) {
projects := []project{}
var mmls []string
if files, err := filepath.Glob(filepath.Join(path, "*.mml")); err != nil {
return nil, err
} else {
mmls = append(mmls, files...)
}
if files, err := filepath.Glob(filepath.Join(path, "*", "*.mml")); err != nil {
r... | [
"func",
"findProjects",
"(",
"path",
"string",
")",
"(",
"[",
"]",
"project",
",",
"error",
")",
"{",
"projects",
":=",
"[",
"]",
"project",
"{",
"}",
"\n",
"var",
"mmls",
"[",
"]",
"string",
"\n",
"if",
"files",
",",
"err",
":=",
"filepath",
".",
... | // findProjects searches for .mml files in path and in all sub-directories of
// path, but not any deeper. | [
"findProjects",
"searches",
"for",
".",
"mml",
"files",
"in",
"path",
"and",
"in",
"all",
"sub",
"-",
"directories",
"of",
"path",
"but",
"not",
"any",
"deeper",
"."
] | 70ccb049d7e2d0da1c5a10ef3ea37eac30cd142b | https://github.com/omniscale/magnacarto/blob/70ccb049d7e2d0da1c5a10ef3ea37eac30cd142b/cmd/magnaserv/project.go#L31-L88 |
144,369 | omniscale/magnacarto | mss/rule.go | filterOverlap | func filterOverlap(a, b []Filter) bool {
for ia := range a {
for ib := range b {
if a[ia].Field != b[ib].Field {
continue
}
if a[ia].CompOp != b[ib].CompOp || a[ia].Value != b[ib].Value {
return false
} else {
break
}
}
}
return true
} | go | func filterOverlap(a, b []Filter) bool {
for ia := range a {
for ib := range b {
if a[ia].Field != b[ib].Field {
continue
}
if a[ia].CompOp != b[ib].CompOp || a[ia].Value != b[ib].Value {
return false
} else {
break
}
}
}
return true
} | [
"func",
"filterOverlap",
"(",
"a",
",",
"b",
"[",
"]",
"Filter",
")",
"bool",
"{",
"for",
"ia",
":=",
"range",
"a",
"{",
"for",
"ib",
":=",
"range",
"b",
"{",
"if",
"a",
"[",
"ia",
"]",
".",
"Field",
"!=",
"b",
"[",
"ib",
"]",
".",
"Field",
... | // filterOverlap returns true if a does not contain any filters that conflicts with filters of b | [
"filterOverlap",
"returns",
"true",
"if",
"a",
"does",
"not",
"contain",
"any",
"filters",
"that",
"conflicts",
"with",
"filters",
"of",
"b"
] | 70ccb049d7e2d0da1c5a10ef3ea37eac30cd142b | https://github.com/omniscale/magnacarto/blob/70ccb049d7e2d0da1c5a10ef3ea37eac30cd142b/mss/rule.go#L218-L232 |
144,370 | omniscale/magnacarto | mss/rule.go | filterEqual | func filterEqual(a, b []Filter) bool {
if len(a) != len(b) {
return false
}
for i := range a {
if a[i].Field != b[i].Field {
return false
}
if a[i].CompOp != b[i].CompOp {
return false
}
if a[i].Value != b[i].Value {
return false
}
}
return true
} | go | func filterEqual(a, b []Filter) bool {
if len(a) != len(b) {
return false
}
for i := range a {
if a[i].Field != b[i].Field {
return false
}
if a[i].CompOp != b[i].CompOp {
return false
}
if a[i].Value != b[i].Value {
return false
}
}
return true
} | [
"func",
"filterEqual",
"(",
"a",
",",
"b",
"[",
"]",
"Filter",
")",
"bool",
"{",
"if",
"len",
"(",
"a",
")",
"!=",
"len",
"(",
"b",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"for",
"i",
":=",
"range",
"a",
"{",
"if",
"a",
"[",
"i",
"]",... | // filterEqual returns true if a and b contain the same filter
// filters need to be sorted alpha-numerical. | [
"filterEqual",
"returns",
"true",
"if",
"a",
"and",
"b",
"contain",
"the",
"same",
"filter",
"filters",
"need",
"to",
"be",
"sorted",
"alpha",
"-",
"numerical",
"."
] | 70ccb049d7e2d0da1c5a10ef3ea37eac30cd142b | https://github.com/omniscale/magnacarto/blob/70ccb049d7e2d0da1c5a10ef3ea37eac30cd142b/mss/rule.go#L236-L252 |
144,371 | omniscale/magnacarto | mss/rule.go | same | func (r Rule) same(o Rule) bool {
if r.Layer != o.Layer {
return false
}
if r.Attachment != o.Attachment {
return false
}
if r.Class != o.Class {
return false
}
if r.Zoom != o.Zoom {
return false
}
if !filterEqual(r.Filters, o.Filters) {
return false
}
return true
} | go | func (r Rule) same(o Rule) bool {
if r.Layer != o.Layer {
return false
}
if r.Attachment != o.Attachment {
return false
}
if r.Class != o.Class {
return false
}
if r.Zoom != o.Zoom {
return false
}
if !filterEqual(r.Filters, o.Filters) {
return false
}
return true
} | [
"func",
"(",
"r",
"Rule",
")",
"same",
"(",
"o",
"Rule",
")",
"bool",
"{",
"if",
"r",
".",
"Layer",
"!=",
"o",
".",
"Layer",
"{",
"return",
"false",
"\n",
"}",
"\n",
"if",
"r",
".",
"Attachment",
"!=",
"o",
".",
"Attachment",
"{",
"return",
"fa... | // same checks whether both rule selectors are the same | [
"same",
"checks",
"whether",
"both",
"rule",
"selectors",
"are",
"the",
"same"
] | 70ccb049d7e2d0da1c5a10ef3ea37eac30cd142b | https://github.com/omniscale/magnacarto/blob/70ccb049d7e2d0da1c5a10ef3ea37eac30cd142b/mss/rule.go#L302-L319 |
144,372 | omniscale/magnacarto | mss/rule.go | sameExceptClass | func (r Rule) sameExceptClass(o Rule) bool {
if r.Layer != o.Layer {
return false
}
if r.Attachment != o.Attachment {
return false
}
if r.Zoom != o.Zoom {
return false
}
if !filterEqual(r.Filters, o.Filters) {
return false
}
return true
} | go | func (r Rule) sameExceptClass(o Rule) bool {
if r.Layer != o.Layer {
return false
}
if r.Attachment != o.Attachment {
return false
}
if r.Zoom != o.Zoom {
return false
}
if !filterEqual(r.Filters, o.Filters) {
return false
}
return true
} | [
"func",
"(",
"r",
"Rule",
")",
"sameExceptClass",
"(",
"o",
"Rule",
")",
"bool",
"{",
"if",
"r",
".",
"Layer",
"!=",
"o",
".",
"Layer",
"{",
"return",
"false",
"\n",
"}",
"\n",
"if",
"r",
".",
"Attachment",
"!=",
"o",
".",
"Attachment",
"{",
"ret... | // sameExceptClass checks whether both rule selectors are the same, ignores different Class value | [
"sameExceptClass",
"checks",
"whether",
"both",
"rule",
"selectors",
"are",
"the",
"same",
"ignores",
"different",
"Class",
"value"
] | 70ccb049d7e2d0da1c5a10ef3ea37eac30cd142b | https://github.com/omniscale/magnacarto/blob/70ccb049d7e2d0da1c5a10ef3ea37eac30cd142b/mss/rule.go#L322-L336 |
144,373 | omniscale/magnacarto | mss/rule.go | Layers | func (m *MSS) Layers() []string {
layerNames := []string{}
layersAdded := map[string]struct{}{}
for _, b := range m.root.blocks {
for _, s := range b.selectors {
if _, ok := layersAdded[s.Layer]; !ok {
layerNames = append(layerNames, s.Layer)
layersAdded[s.Layer] = struct{}{}
}
}
}
return layerNa... | go | func (m *MSS) Layers() []string {
layerNames := []string{}
layersAdded := map[string]struct{}{}
for _, b := range m.root.blocks {
for _, s := range b.selectors {
if _, ok := layersAdded[s.Layer]; !ok {
layerNames = append(layerNames, s.Layer)
layersAdded[s.Layer] = struct{}{}
}
}
}
return layerNa... | [
"func",
"(",
"m",
"*",
"MSS",
")",
"Layers",
"(",
")",
"[",
"]",
"string",
"{",
"layerNames",
":=",
"[",
"]",
"string",
"{",
"}",
"\n",
"layersAdded",
":=",
"map",
"[",
"string",
"]",
"struct",
"{",
"}",
"{",
"}",
"\n",
"for",
"_",
",",
"b",
... | // Layers returns all layer names in order of appearance. | [
"Layers",
"returns",
"all",
"layer",
"names",
"in",
"order",
"of",
"appearance",
"."
] | 70ccb049d7e2d0da1c5a10ef3ea37eac30cd142b | https://github.com/omniscale/magnacarto/blob/70ccb049d7e2d0da1c5a10ef3ea37eac30cd142b/mss/rule.go#L360-L372 |
144,374 | omniscale/magnacarto | mss/rule.go | LayerRules | func (m *MSS) LayerRules(layer string, classes ...string) []Rule {
return m.LayerZoomRules(layer, InvalidZoom, classes...)
} | go | func (m *MSS) LayerRules(layer string, classes ...string) []Rule {
return m.LayerZoomRules(layer, InvalidZoom, classes...)
} | [
"func",
"(",
"m",
"*",
"MSS",
")",
"LayerRules",
"(",
"layer",
"string",
",",
"classes",
"...",
"string",
")",
"[",
"]",
"Rule",
"{",
"return",
"m",
".",
"LayerZoomRules",
"(",
"layer",
",",
"InvalidZoom",
",",
"classes",
"...",
")",
"\n",
"}"
] | // LayerRules returns all Rules for this layer. | [
"LayerRules",
"returns",
"all",
"Rules",
"for",
"this",
"layer",
"."
] | 70ccb049d7e2d0da1c5a10ef3ea37eac30cd142b | https://github.com/omniscale/magnacarto/blob/70ccb049d7e2d0da1c5a10ef3ea37eac30cd142b/mss/rule.go#L375-L377 |
144,375 | omniscale/magnacarto | mss/rule.go | dedup | func dedup(rules []Rule) []Rule {
// record hash of already added rules to detect duplicates
added := make(map[uint64]struct{}, len(rules))
result := []Rule{}
for i := range rules {
// TODO: detect duplicates styles where filters/zoom can be combined
// if i != 0 && filterEqual(rules[i-1].Filters, rules[i].Filt... | go | func dedup(rules []Rule) []Rule {
// record hash of already added rules to detect duplicates
added := make(map[uint64]struct{}, len(rules))
result := []Rule{}
for i := range rules {
// TODO: detect duplicates styles where filters/zoom can be combined
// if i != 0 && filterEqual(rules[i-1].Filters, rules[i].Filt... | [
"func",
"dedup",
"(",
"rules",
"[",
"]",
"Rule",
")",
"[",
"]",
"Rule",
"{",
"// record hash of already added rules to detect duplicates",
"added",
":=",
"make",
"(",
"map",
"[",
"uint64",
"]",
"struct",
"{",
"}",
",",
"len",
"(",
"rules",
")",
")",
"\n",
... | // dedup removes all duplicates | [
"dedup",
"removes",
"all",
"duplicates"
] | 70ccb049d7e2d0da1c5a10ef3ea37eac30cd142b | https://github.com/omniscale/magnacarto/blob/70ccb049d7e2d0da1c5a10ef3ea37eac30cd142b/mss/rule.go#L647-L666 |
144,376 | omniscale/magnacarto | mss/rule.go | dedupMergeClasses | func dedupMergeClasses(rules []Rule, classes []string) []Rule {
classIdx := func(class string) int {
if class == "" {
return math.MaxInt32
}
for i := range classes {
if classes[i] == class {
return i
}
}
return math.MaxInt32
}
result := []Rule{}
for i := range rules {
found := false
for ... | go | func dedupMergeClasses(rules []Rule, classes []string) []Rule {
classIdx := func(class string) int {
if class == "" {
return math.MaxInt32
}
for i := range classes {
if classes[i] == class {
return i
}
}
return math.MaxInt32
}
result := []Rule{}
for i := range rules {
found := false
for ... | [
"func",
"dedupMergeClasses",
"(",
"rules",
"[",
"]",
"Rule",
",",
"classes",
"[",
"]",
"string",
")",
"[",
"]",
"Rule",
"{",
"classIdx",
":=",
"func",
"(",
"class",
"string",
")",
"int",
"{",
"if",
"class",
"==",
"\"",
"\"",
"{",
"return",
"math",
... | // dedup removes all duplicates, merges rules with different classes | [
"dedup",
"removes",
"all",
"duplicates",
"merges",
"rules",
"with",
"different",
"classes"
] | 70ccb049d7e2d0da1c5a10ef3ea37eac30cd142b | https://github.com/omniscale/magnacarto/blob/70ccb049d7e2d0da1c5a10ef3ea37eac30cd142b/mss/rule.go#L669-L705 |
144,377 | omniscale/magnacarto | mss/decode.go | New | func New() *Decoder {
mss := newMSS()
return &Decoder{mss: mss, vars: &Properties{}, expr: &expression{}}
} | go | func New() *Decoder {
mss := newMSS()
return &Decoder{mss: mss, vars: &Properties{}, expr: &expression{}}
} | [
"func",
"New",
"(",
")",
"*",
"Decoder",
"{",
"mss",
":=",
"newMSS",
"(",
")",
"\n",
"return",
"&",
"Decoder",
"{",
"mss",
":",
"mss",
",",
"vars",
":",
"&",
"Properties",
"{",
"}",
",",
"expr",
":",
"&",
"expression",
"{",
"}",
"}",
"\n",
"}"
... | // New will allocate a new MSS Decoder | [
"New",
"will",
"allocate",
"a",
"new",
"MSS",
"Decoder"
] | 70ccb049d7e2d0da1c5a10ef3ea37eac30cd142b | https://github.com/omniscale/magnacarto/blob/70ccb049d7e2d0da1c5a10ef3ea37eac30cd142b/mss/decode.go#L55-L58 |
144,378 | omniscale/magnacarto | mss/decode.go | ParseFile | func (d *Decoder) ParseFile(filename string) error {
d.filename = filename
defer func() { d.filename = "" }()
r, err := os.Open(filename)
if err != nil {
return err
}
defer r.Close()
content, err := ioutil.ReadAll(r)
if err != nil {
return err
}
return d.ParseString(string(content))
} | go | func (d *Decoder) ParseFile(filename string) error {
d.filename = filename
defer func() { d.filename = "" }()
r, err := os.Open(filename)
if err != nil {
return err
}
defer r.Close()
content, err := ioutil.ReadAll(r)
if err != nil {
return err
}
return d.ParseString(string(content))
} | [
"func",
"(",
"d",
"*",
"Decoder",
")",
"ParseFile",
"(",
"filename",
"string",
")",
"error",
"{",
"d",
".",
"filename",
"=",
"filename",
"\n",
"defer",
"func",
"(",
")",
"{",
"d",
".",
"filename",
"=",
"\"",
"\"",
"}",
"(",
")",
"\n\n",
"r",
",",... | // ParseFile parses the given .mss file.
// Can be called multiple times to parse a style split into multiple files. | [
"ParseFile",
"parses",
"the",
"given",
".",
"mss",
"file",
".",
"Can",
"be",
"called",
"multiple",
"times",
"to",
"parse",
"a",
"style",
"split",
"into",
"multiple",
"files",
"."
] | 70ccb049d7e2d0da1c5a10ef3ea37eac30cd142b | https://github.com/omniscale/magnacarto/blob/70ccb049d7e2d0da1c5a10ef3ea37eac30cd142b/mss/decode.go#L99-L113 |
144,379 | omniscale/magnacarto | mss/decode.go | expect | func (d *Decoder) expect(t tokenType) {
if tok := d.next(); tok.t != t {
d.error(d.pos(tok), "expected %v found %v", t, tok)
}
} | go | func (d *Decoder) expect(t tokenType) {
if tok := d.next(); tok.t != t {
d.error(d.pos(tok), "expected %v found %v", t, tok)
}
} | [
"func",
"(",
"d",
"*",
"Decoder",
")",
"expect",
"(",
"t",
"tokenType",
")",
"{",
"if",
"tok",
":=",
"d",
".",
"next",
"(",
")",
";",
"tok",
".",
"t",
"!=",
"t",
"{",
"d",
".",
"error",
"(",
"d",
".",
"pos",
"(",
"tok",
")",
",",
"\"",
"\... | // expect consumes the next token checks that it is of type t | [
"expect",
"consumes",
"the",
"next",
"token",
"checks",
"that",
"it",
"is",
"of",
"type",
"t"
] | 70ccb049d7e2d0da1c5a10ef3ea37eac30cd142b | https://github.com/omniscale/magnacarto/blob/70ccb049d7e2d0da1c5a10ef3ea37eac30cd142b/mss/decode.go#L438-L442 |
144,380 | omniscale/magnacarto | mss/decode.go | expectEndOfStatement | func (d *Decoder) expectEndOfStatement() {
tok := d.next()
if tok.t == tokenRBrace {
d.backup()
return
}
d.backup()
d.expect(tokenSemicolon)
} | go | func (d *Decoder) expectEndOfStatement() {
tok := d.next()
if tok.t == tokenRBrace {
d.backup()
return
}
d.backup()
d.expect(tokenSemicolon)
} | [
"func",
"(",
"d",
"*",
"Decoder",
")",
"expectEndOfStatement",
"(",
")",
"{",
"tok",
":=",
"d",
".",
"next",
"(",
")",
"\n\n",
"if",
"tok",
".",
"t",
"==",
"tokenRBrace",
"{",
"d",
".",
"backup",
"(",
")",
"\n",
"return",
"\n",
"}",
"\n",
"d",
... | // expectEndOfStatement checks for semicolon or closing block `}` | [
"expectEndOfStatement",
"checks",
"for",
"semicolon",
"or",
"closing",
"block",
"}"
] | 70ccb049d7e2d0da1c5a10ef3ea37eac30cd142b | https://github.com/omniscale/magnacarto/blob/70ccb049d7e2d0da1c5a10ef3ea37eac30cd142b/mss/decode.go#L445-L454 |
144,381 | martini-contrib/gzip | gzip.go | All | func All(options ...Options) martini.Handler {
opt := prepareOptions(options)
return func(w http.ResponseWriter, r *http.Request, c martini.Context) {
serveGzip(w, r, c, opt)
}
} | go | func All(options ...Options) martini.Handler {
opt := prepareOptions(options)
return func(w http.ResponseWriter, r *http.Request, c martini.Context) {
serveGzip(w, r, c, opt)
}
} | [
"func",
"All",
"(",
"options",
"...",
"Options",
")",
"martini",
".",
"Handler",
"{",
"opt",
":=",
"prepareOptions",
"(",
"options",
")",
"\n",
"return",
"func",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
",",
"c",
... | // All returns a Handler that adds gzip compression to all requests | [
"All",
"returns",
"a",
"Handler",
"that",
"adds",
"gzip",
"compression",
"to",
"all",
"requests"
] | 6c035326b43f79aa18793d2f1db512d21253ea61 | https://github.com/martini-contrib/gzip/blob/6c035326b43f79aa18793d2f1db512d21253ea61/gzip.go#L53-L58 |
144,382 | getlantern/errors | errors.go | NewOffset | func NewOffset(offset int, desc string, args ...interface{}) Error {
var cause error
for _, arg := range args {
err, isError := arg.(error)
if isError {
cause = err
break
}
}
e := buildError(desc, fmt.Sprintf(desc, args...), nil, Wrap(cause))
e.attachStack(2 + offset)
return e
} | go | func NewOffset(offset int, desc string, args ...interface{}) Error {
var cause error
for _, arg := range args {
err, isError := arg.(error)
if isError {
cause = err
break
}
}
e := buildError(desc, fmt.Sprintf(desc, args...), nil, Wrap(cause))
e.attachStack(2 + offset)
return e
} | [
"func",
"NewOffset",
"(",
"offset",
"int",
",",
"desc",
"string",
",",
"args",
"...",
"interface",
"{",
"}",
")",
"Error",
"{",
"var",
"cause",
"error",
"\n",
"for",
"_",
",",
"arg",
":=",
"range",
"args",
"{",
"err",
",",
"isError",
":=",
"arg",
"... | // NewOffset is like New but offsets the stack by the given offset. This is
// useful for utilities like golog that may create errors on behalf of others. | [
"NewOffset",
"is",
"like",
"New",
"but",
"offsets",
"the",
"stack",
"by",
"the",
"given",
"offset",
".",
"This",
"is",
"useful",
"for",
"utilities",
"like",
"golog",
"that",
"may",
"create",
"errors",
"on",
"behalf",
"of",
"others",
"."
] | abdb3e3e36f7e64b4bfbe96e860db91e7534aa6e | https://github.com/getlantern/errors/blob/abdb3e3e36f7e64b4bfbe96e860db91e7534aa6e/errors.go#L144-L156 |
144,383 | getlantern/errors | errors.go | Fill | func (e *structured) Fill(m context.Map) {
if e != nil {
if e.cause != nil {
// Include data from cause, which supercedes context
e.cause.Fill(m)
}
// Include the context, which supercedes the cause
for key, value := range e.context {
m[key] = value
}
// Now include the error's data, which superce... | go | func (e *structured) Fill(m context.Map) {
if e != nil {
if e.cause != nil {
// Include data from cause, which supercedes context
e.cause.Fill(m)
}
// Include the context, which supercedes the cause
for key, value := range e.context {
m[key] = value
}
// Now include the error's data, which superce... | [
"func",
"(",
"e",
"*",
"structured",
")",
"Fill",
"(",
"m",
"context",
".",
"Map",
")",
"{",
"if",
"e",
"!=",
"nil",
"{",
"if",
"e",
".",
"cause",
"!=",
"nil",
"{",
"// Include data from cause, which supercedes context",
"e",
".",
"cause",
".",
"Fill",
... | // Fill implements the method from the context.Contextual interface. | [
"Fill",
"implements",
"the",
"method",
"from",
"the",
"context",
".",
"Contextual",
"interface",
"."
] | abdb3e3e36f7e64b4bfbe96e860db91e7534aa6e | https://github.com/getlantern/errors/blob/abdb3e3e36f7e64b4bfbe96e860db91e7534aa6e/errors.go#L167-L182 |
144,384 | veqryn/go-email | email/header.go | Get | func (h Header) Get(key string) string {
if h == nil {
return ""
}
v := h[textproto.CanonicalMIMEHeaderKey(key)]
if len(v) == 0 {
return ""
}
return v[0]
} | go | func (h Header) Get(key string) string {
if h == nil {
return ""
}
v := h[textproto.CanonicalMIMEHeaderKey(key)]
if len(v) == 0 {
return ""
}
return v[0]
} | [
"func",
"(",
"h",
"Header",
")",
"Get",
"(",
"key",
"string",
")",
"string",
"{",
"if",
"h",
"==",
"nil",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n",
"v",
":=",
"h",
"[",
"textproto",
".",
"CanonicalMIMEHeaderKey",
"(",
"key",
")",
"]",
"\n",
"if... | // Get gets the first value associated with the given key.
// If there are no values associated with the key, Get returns "".
// Get is a convenience method. For more complex queries,
// access the map directly. | [
"Get",
"gets",
"the",
"first",
"value",
"associated",
"with",
"the",
"given",
"key",
".",
"If",
"there",
"are",
"no",
"values",
"associated",
"with",
"the",
"key",
"Get",
"returns",
".",
"Get",
"is",
"a",
"convenience",
"method",
".",
"For",
"more",
"com... | 388713805b1e28295565f252ab14b53e1267b0bc | https://github.com/veqryn/go-email/blob/388713805b1e28295565f252ab14b53e1267b0bc/email/header.go#L62-L71 |
144,385 | veqryn/go-email | email/header.go | IsSet | func (h Header) IsSet(key string) bool {
if h == nil {
return false
}
_, ok := h[textproto.CanonicalMIMEHeaderKey(key)]
return ok
} | go | func (h Header) IsSet(key string) bool {
if h == nil {
return false
}
_, ok := h[textproto.CanonicalMIMEHeaderKey(key)]
return ok
} | [
"func",
"(",
"h",
"Header",
")",
"IsSet",
"(",
"key",
"string",
")",
"bool",
"{",
"if",
"h",
"==",
"nil",
"{",
"return",
"false",
"\n",
"}",
"\n",
"_",
",",
"ok",
":=",
"h",
"[",
"textproto",
".",
"CanonicalMIMEHeaderKey",
"(",
"key",
")",
"]",
"... | // IsSet tests if a key is present in the Header | [
"IsSet",
"tests",
"if",
"a",
"key",
"is",
"present",
"in",
"the",
"Header"
] | 388713805b1e28295565f252ab14b53e1267b0bc | https://github.com/veqryn/go-email/blob/388713805b1e28295565f252ab14b53e1267b0bc/email/header.go#L74-L80 |
144,386 | veqryn/go-email | email/header.go | AddressList | func (h Header) AddressList(key string) ([]*mail.Address, error) {
return mail.Header(h).AddressList(key)
} | go | func (h Header) AddressList(key string) ([]*mail.Address, error) {
return mail.Header(h).AddressList(key)
} | [
"func",
"(",
"h",
"Header",
")",
"AddressList",
"(",
"key",
"string",
")",
"(",
"[",
"]",
"*",
"mail",
".",
"Address",
",",
"error",
")",
"{",
"return",
"mail",
".",
"Header",
"(",
"h",
")",
".",
"AddressList",
"(",
"key",
")",
"\n",
"}"
] | // AddressList parses the named header field as a list of addresses. | [
"AddressList",
"parses",
"the",
"named",
"header",
"field",
"as",
"a",
"list",
"of",
"addresses",
"."
] | 388713805b1e28295565f252ab14b53e1267b0bc | https://github.com/veqryn/go-email/blob/388713805b1e28295565f252ab14b53e1267b0bc/email/header.go#L95-L97 |
144,387 | veqryn/go-email | email/header.go | Bytes | func (h Header) Bytes() ([]byte, error) {
buffer := &bytes.Buffer{}
_, err := h.WriteTo(buffer)
return buffer.Bytes(), err
} | go | func (h Header) Bytes() ([]byte, error) {
buffer := &bytes.Buffer{}
_, err := h.WriteTo(buffer)
return buffer.Bytes(), err
} | [
"func",
"(",
"h",
"Header",
")",
"Bytes",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"buffer",
":=",
"&",
"bytes",
".",
"Buffer",
"{",
"}",
"\n",
"_",
",",
"err",
":=",
"h",
".",
"WriteTo",
"(",
"buffer",
")",
"\n",
"return",
"b... | // Bytes returns the bytes representing this header. It is a convenience
// method that calls WriteTo on a buffer, returning its bytes. | [
"Bytes",
"returns",
"the",
"bytes",
"representing",
"this",
"header",
".",
"It",
"is",
"a",
"convenience",
"method",
"that",
"calls",
"WriteTo",
"on",
"a",
"buffer",
"returning",
"its",
"bytes",
"."
] | 388713805b1e28295565f252ab14b53e1267b0bc | https://github.com/veqryn/go-email/blob/388713805b1e28295565f252ab14b53e1267b0bc/email/header.go#L120-L124 |
144,388 | veqryn/go-email | email/header.go | WriteTo | func (h Header) WriteTo(w io.Writer) (int64, error) {
// TODO: Change how headerWriter decides where to wrap, then switch to MaxHeaderLineLength
writer := &headerWriter{w: w, maxLineLen: MaxHeaderTotalLength}
var total int64
for _, field := range sortedHeaderFields(h) {
if field == "Bcc" {
continue // skip wri... | go | func (h Header) WriteTo(w io.Writer) (int64, error) {
// TODO: Change how headerWriter decides where to wrap, then switch to MaxHeaderLineLength
writer := &headerWriter{w: w, maxLineLen: MaxHeaderTotalLength}
var total int64
for _, field := range sortedHeaderFields(h) {
if field == "Bcc" {
continue // skip wri... | [
"func",
"(",
"h",
"Header",
")",
"WriteTo",
"(",
"w",
"io",
".",
"Writer",
")",
"(",
"int64",
",",
"error",
")",
"{",
"// TODO: Change how headerWriter decides where to wrap, then switch to MaxHeaderLineLength",
"writer",
":=",
"&",
"headerWriter",
"{",
"w",
":",
... | // WriteTo writes this header out, including every field except for Bcc. | [
"WriteTo",
"writes",
"this",
"header",
"out",
"including",
"every",
"field",
"except",
"for",
"Bcc",
"."
] | 388713805b1e28295565f252ab14b53e1267b0bc | https://github.com/veqryn/go-email/blob/388713805b1e28295565f252ab14b53e1267b0bc/email/header.go#L127-L148 |
144,389 | veqryn/go-email | email/parser.go | readParts | func readParts(bodyReader io.Reader, boundary string) ([]*Message, error) {
parts := make([]*Message, 0, 1)
multipartReader := multipart.NewReader(bodyReader, boundary)
for part, partErr := multipartReader.NextPart(); partErr != io.EOF; part, partErr = multipartReader.NextPart() {
if partErr != nil && partErr !=... | go | func readParts(bodyReader io.Reader, boundary string) ([]*Message, error) {
parts := make([]*Message, 0, 1)
multipartReader := multipart.NewReader(bodyReader, boundary)
for part, partErr := multipartReader.NextPart(); partErr != io.EOF; part, partErr = multipartReader.NextPart() {
if partErr != nil && partErr !=... | [
"func",
"readParts",
"(",
"bodyReader",
"io",
".",
"Reader",
",",
"boundary",
"string",
")",
"(",
"[",
"]",
"*",
"Message",
",",
"error",
")",
"{",
"parts",
":=",
"make",
"(",
"[",
"]",
"*",
"Message",
",",
"0",
",",
"1",
")",
"\n",
"multipartReade... | // readParts parses out the parts of a multipart body, including the preamble and epilogue. | [
"readParts",
"parses",
"out",
"the",
"parts",
"of",
"a",
"multipart",
"body",
"including",
"the",
"preamble",
"and",
"epilogue",
"."
] | 388713805b1e28295565f252ab14b53e1267b0bc | https://github.com/veqryn/go-email/blob/388713805b1e28295565f252ab14b53e1267b0bc/email/parser.go#L97-L114 |
144,390 | veqryn/go-email | email/message_delivery_status.go | DeliveryStatusMessageDNS | func (m *Message) DeliveryStatusMessageDNS() (Header, error) {
if !m.HasDeliveryStatusMessage() {
return Header{}, errors.New("Message does not have media content of type message/delivery-status")
}
return m.SubMessage.Header, nil
} | go | func (m *Message) DeliveryStatusMessageDNS() (Header, error) {
if !m.HasDeliveryStatusMessage() {
return Header{}, errors.New("Message does not have media content of type message/delivery-status")
}
return m.SubMessage.Header, nil
} | [
"func",
"(",
"m",
"*",
"Message",
")",
"DeliveryStatusMessageDNS",
"(",
")",
"(",
"Header",
",",
"error",
")",
"{",
"if",
"!",
"m",
".",
"HasDeliveryStatusMessage",
"(",
")",
"{",
"return",
"Header",
"{",
"}",
",",
"errors",
".",
"New",
"(",
"\"",
"\... | // DeliveryStatusMessageDNS returns the message DNS information,
// or an error if HasDeliveryStatusMessage would return false. | [
"DeliveryStatusMessageDNS",
"returns",
"the",
"message",
"DNS",
"information",
"or",
"an",
"error",
"if",
"HasDeliveryStatusMessage",
"would",
"return",
"false",
"."
] | 388713805b1e28295565f252ab14b53e1267b0bc | https://github.com/veqryn/go-email/blob/388713805b1e28295565f252ab14b53e1267b0bc/email/message_delivery_status.go#L28-L33 |
144,391 | veqryn/go-email | email/message_delivery_status.go | DeliveryStatusRecipientDNS | func (m *Message) DeliveryStatusRecipientDNS() ([]Header, error) {
recipientDNS := make([]Header, 0, 1)
if !m.HasDeliveryStatusMessage() {
return recipientDNS, errors.New("Message does not have media content of type message/delivery-status")
}
var err error
var recipientHeaders textproto.MIMEHeader
tp := textpr... | go | func (m *Message) DeliveryStatusRecipientDNS() ([]Header, error) {
recipientDNS := make([]Header, 0, 1)
if !m.HasDeliveryStatusMessage() {
return recipientDNS, errors.New("Message does not have media content of type message/delivery-status")
}
var err error
var recipientHeaders textproto.MIMEHeader
tp := textpr... | [
"func",
"(",
"m",
"*",
"Message",
")",
"DeliveryStatusRecipientDNS",
"(",
")",
"(",
"[",
"]",
"Header",
",",
"error",
")",
"{",
"recipientDNS",
":=",
"make",
"(",
"[",
"]",
"Header",
",",
"0",
",",
"1",
")",
"\n",
"if",
"!",
"m",
".",
"HasDeliveryS... | // DeliveryStatusRecipientDNS returns the message recipients' DNS information,
// or an error if HasDeliveryStatusMessage would return false. | [
"DeliveryStatusRecipientDNS",
"returns",
"the",
"message",
"recipients",
"DNS",
"information",
"or",
"an",
"error",
"if",
"HasDeliveryStatusMessage",
"would",
"return",
"false",
"."
] | 388713805b1e28295565f252ab14b53e1267b0bc | https://github.com/veqryn/go-email/blob/388713805b1e28295565f252ab14b53e1267b0bc/email/message_delivery_status.go#L37-L53 |
144,392 | veqryn/go-email | email/message.go | HasParts | func (m *Message) HasParts() bool {
mediaType, _, err := m.Header.ContentType()
if err != nil {
return false
}
return strings.HasPrefix(mediaType, "multipart")
} | go | func (m *Message) HasParts() bool {
mediaType, _, err := m.Header.ContentType()
if err != nil {
return false
}
return strings.HasPrefix(mediaType, "multipart")
} | [
"func",
"(",
"m",
"*",
"Message",
")",
"HasParts",
"(",
")",
"bool",
"{",
"mediaType",
",",
"_",
",",
"err",
":=",
"m",
".",
"Header",
".",
"ContentType",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"false",
"\n",
"}",
"\n",
"return"... | // HasParts returns true if the Content-Type is "multipart" | [
"HasParts",
"returns",
"true",
"if",
"the",
"Content",
"-",
"Type",
"is",
"multipart"
] | 388713805b1e28295565f252ab14b53e1267b0bc | https://github.com/veqryn/go-email/blob/388713805b1e28295565f252ab14b53e1267b0bc/email/message.go#L77-L83 |
144,393 | veqryn/go-email | email/message.go | HasBody | func (m *Message) HasBody() bool {
mediaType, _, err := m.Header.ContentType()
if err != nil && err != ErrHeadersMissingField {
return false
}
return !strings.HasPrefix(mediaType, "multipart") && !strings.HasPrefix(mediaType, "message")
} | go | func (m *Message) HasBody() bool {
mediaType, _, err := m.Header.ContentType()
if err != nil && err != ErrHeadersMissingField {
return false
}
return !strings.HasPrefix(mediaType, "multipart") && !strings.HasPrefix(mediaType, "message")
} | [
"func",
"(",
"m",
"*",
"Message",
")",
"HasBody",
"(",
")",
"bool",
"{",
"mediaType",
",",
"_",
",",
"err",
":=",
"m",
".",
"Header",
".",
"ContentType",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"&&",
"err",
"!=",
"ErrHeadersMissingField",
"{",
"r... | // HasBody returns true if the Content-Type is not "multipart" nor "message" | [
"HasBody",
"returns",
"true",
"if",
"the",
"Content",
"-",
"Type",
"is",
"not",
"multipart",
"nor",
"message"
] | 388713805b1e28295565f252ab14b53e1267b0bc | https://github.com/veqryn/go-email/blob/388713805b1e28295565f252ab14b53e1267b0bc/email/message.go#L95-L101 |
144,394 | veqryn/go-email | email/message.go | PartsFilter | func (m *Message) PartsFilter(filter func(*Message) bool) []*Message {
messages := make([]*Message, 0, 1)
if m.HasParts() {
for _, part := range m.Parts {
if filter(part) {
messages = append(messages, part)
}
}
}
return messages
} | go | func (m *Message) PartsFilter(filter func(*Message) bool) []*Message {
messages := make([]*Message, 0, 1)
if m.HasParts() {
for _, part := range m.Parts {
if filter(part) {
messages = append(messages, part)
}
}
}
return messages
} | [
"func",
"(",
"m",
"*",
"Message",
")",
"PartsFilter",
"(",
"filter",
"func",
"(",
"*",
"Message",
")",
"bool",
")",
"[",
"]",
"*",
"Message",
"{",
"messages",
":=",
"make",
"(",
"[",
"]",
"*",
"Message",
",",
"0",
",",
"1",
")",
"\n",
"if",
"m"... | // PartsFilter will return a slice of all parts of this message
// that match this lambda function.
// The slice will be empty if this message is not a multipart message.
// This method does NOT recurse into sub-messages and sub-parts. | [
"PartsFilter",
"will",
"return",
"a",
"slice",
"of",
"all",
"parts",
"of",
"this",
"message",
"that",
"match",
"this",
"lambda",
"function",
".",
"The",
"slice",
"will",
"be",
"empty",
"if",
"this",
"message",
"is",
"not",
"a",
"multipart",
"message",
".",... | 388713805b1e28295565f252ab14b53e1267b0bc | https://github.com/veqryn/go-email/blob/388713805b1e28295565f252ab14b53e1267b0bc/email/message.go#L116-L127 |
144,395 | veqryn/go-email | email/message.go | MessagesAll | func (m *Message) MessagesAll() []*Message {
return m.MessagesFilter(func(tested *Message) bool {
return true
})
} | go | func (m *Message) MessagesAll() []*Message {
return m.MessagesFilter(func(tested *Message) bool {
return true
})
} | [
"func",
"(",
"m",
"*",
"Message",
")",
"MessagesAll",
"(",
")",
"[",
"]",
"*",
"Message",
"{",
"return",
"m",
".",
"MessagesFilter",
"(",
"func",
"(",
"tested",
"*",
"Message",
")",
"bool",
"{",
"return",
"true",
"\n",
"}",
")",
"\n",
"}"
] | // MessagesAll will return a slice of Messages, starting with this message,
// and followed by all messages contained within this message, recursively.
// This method is similar to Python's email message "walk" function.
// This method DOES recurse into sub-messages and sub-parts. | [
"MessagesAll",
"will",
"return",
"a",
"slice",
"of",
"Messages",
"starting",
"with",
"this",
"message",
"and",
"followed",
"by",
"all",
"messages",
"contained",
"within",
"this",
"message",
"recursively",
".",
"This",
"method",
"is",
"similar",
"to",
"Python",
... | 388713805b1e28295565f252ab14b53e1267b0bc | https://github.com/veqryn/go-email/blob/388713805b1e28295565f252ab14b53e1267b0bc/email/message.go#L133-L137 |
144,396 | veqryn/go-email | email/message.go | MessagesFilter | func (m *Message) MessagesFilter(filter func(*Message) bool) []*Message {
messages := make([]*Message, 0, 1)
if filter(m) {
messages = append(messages, m)
}
if m.HasSubMessage() {
return append(messages, m.SubMessage.MessagesFilter(filter)...)
}
if m.HasParts() {
for _, part := range m.Parts {
message... | go | func (m *Message) MessagesFilter(filter func(*Message) bool) []*Message {
messages := make([]*Message, 0, 1)
if filter(m) {
messages = append(messages, m)
}
if m.HasSubMessage() {
return append(messages, m.SubMessage.MessagesFilter(filter)...)
}
if m.HasParts() {
for _, part := range m.Parts {
message... | [
"func",
"(",
"m",
"*",
"Message",
")",
"MessagesFilter",
"(",
"filter",
"func",
"(",
"*",
"Message",
")",
"bool",
")",
"[",
"]",
"*",
"Message",
"{",
"messages",
":=",
"make",
"(",
"[",
"]",
"*",
"Message",
",",
"0",
",",
"1",
")",
"\n",
"if",
... | // MessagesFilter will return a slice of all Messages that match this lambda
// function, potentially including this message and messages contained within
// this message.
// This method DOES recurse into sub-messages and sub-parts. | [
"MessagesFilter",
"will",
"return",
"a",
"slice",
"of",
"all",
"Messages",
"that",
"match",
"this",
"lambda",
"function",
"potentially",
"including",
"this",
"message",
"and",
"messages",
"contained",
"within",
"this",
"message",
".",
"This",
"method",
"DOES",
"... | 388713805b1e28295565f252ab14b53e1267b0bc | https://github.com/veqryn/go-email/blob/388713805b1e28295565f252ab14b53e1267b0bc/email/message.go#L152-L169 |
144,397 | veqryn/go-email | email/message.go | contentTypePrefixFilterClosure | func contentTypePrefixFilterClosure(contentTypePrefix string) func(*Message) bool {
return func(tested *Message) bool {
mediaType, _, err := tested.Header.ContentType()
if err != nil {
return false
}
return strings.HasPrefix(mediaType, contentTypePrefix)
}
} | go | func contentTypePrefixFilterClosure(contentTypePrefix string) func(*Message) bool {
return func(tested *Message) bool {
mediaType, _, err := tested.Header.ContentType()
if err != nil {
return false
}
return strings.HasPrefix(mediaType, contentTypePrefix)
}
} | [
"func",
"contentTypePrefixFilterClosure",
"(",
"contentTypePrefix",
"string",
")",
"func",
"(",
"*",
"Message",
")",
"bool",
"{",
"return",
"func",
"(",
"tested",
"*",
"Message",
")",
"bool",
"{",
"mediaType",
",",
"_",
",",
"err",
":=",
"tested",
".",
"He... | // contentTypePrefixFilterClosure returns a closure that returns true if
// the message has this contentTypePrefix. | [
"contentTypePrefixFilterClosure",
"returns",
"a",
"closure",
"that",
"returns",
"true",
"if",
"the",
"message",
"has",
"this",
"contentTypePrefix",
"."
] | 388713805b1e28295565f252ab14b53e1267b0bc | https://github.com/veqryn/go-email/blob/388713805b1e28295565f252ab14b53e1267b0bc/email/message.go#L173-L181 |
144,398 | veqryn/go-email | email/message.go | Bytes | func (m *Message) Bytes() ([]byte, error) {
buffer := &bytes.Buffer{}
_, err := m.WriteTo(buffer)
return buffer.Bytes(), err
} | go | func (m *Message) Bytes() ([]byte, error) {
buffer := &bytes.Buffer{}
_, err := m.WriteTo(buffer)
return buffer.Bytes(), err
} | [
"func",
"(",
"m",
"*",
"Message",
")",
"Bytes",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"buffer",
":=",
"&",
"bytes",
".",
"Buffer",
"{",
"}",
"\n",
"_",
",",
"err",
":=",
"m",
".",
"WriteTo",
"(",
"buffer",
")",
"\n",
"retur... | // Bytes returns the bytes representing this message. It is a convenience
// method that calls WriteTo on a buffer, returning its bytes. | [
"Bytes",
"returns",
"the",
"bytes",
"representing",
"this",
"message",
".",
"It",
"is",
"a",
"convenience",
"method",
"that",
"calls",
"WriteTo",
"on",
"a",
"buffer",
"returning",
"its",
"bytes",
"."
] | 388713805b1e28295565f252ab14b53e1267b0bc | https://github.com/veqryn/go-email/blob/388713805b1e28295565f252ab14b53e1267b0bc/email/message.go#L193-L197 |
144,399 | veqryn/go-email | email/message.go | WriteTo | func (m *Message) WriteTo(w io.Writer) (int64, error) {
total, err := m.Header.WriteTo(w)
if err != nil {
return total, err
}
mediaType, mediaTypeParams, err := m.Header.ContentType()
if err != nil && err != ErrHeadersMissingField {
return total, err
}
hasParts := strings.HasPrefix(mediaType, "multipart")
... | go | func (m *Message) WriteTo(w io.Writer) (int64, error) {
total, err := m.Header.WriteTo(w)
if err != nil {
return total, err
}
mediaType, mediaTypeParams, err := m.Header.ContentType()
if err != nil && err != ErrHeadersMissingField {
return total, err
}
hasParts := strings.HasPrefix(mediaType, "multipart")
... | [
"func",
"(",
"m",
"*",
"Message",
")",
"WriteTo",
"(",
"w",
"io",
".",
"Writer",
")",
"(",
"int64",
",",
"error",
")",
"{",
"total",
",",
"err",
":=",
"m",
".",
"Header",
".",
"WriteTo",
"(",
"w",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"re... | // WriteTo writes out this Message and its payloads, recursively.
// Any text bodies will be quoted-printable encoded,
// and all other bodies will be base64 encoded. | [
"WriteTo",
"writes",
"out",
"this",
"Message",
"and",
"its",
"payloads",
"recursively",
".",
"Any",
"text",
"bodies",
"will",
"be",
"quoted",
"-",
"printable",
"encoded",
"and",
"all",
"other",
"bodies",
"will",
"be",
"base64",
"encoded",
"."
] | 388713805b1e28295565f252ab14b53e1267b0bc | https://github.com/veqryn/go-email/blob/388713805b1e28295565f252ab14b53e1267b0bc/email/message.go#L202-L233 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.