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
listlengths 21
1.41k
| docstring
stringlengths 6
2.61k
| docstring_tokens
listlengths 3
215
| sha
stringlengths 40
40
| url
stringlengths 85
252
|
---|---|---|---|---|---|---|---|---|---|---|---|
144,500 |
NaySoftware/go-fcm
|
fcm.go
|
SetDryRun
|
func (this *FcmClient) SetDryRun(drun bool) *FcmClient {
this.Message.DryRun = drun
return this
}
|
go
|
func (this *FcmClient) SetDryRun(drun bool) *FcmClient {
this.Message.DryRun = drun
return this
}
|
[
"func",
"(",
"this",
"*",
"FcmClient",
")",
"SetDryRun",
"(",
"drun",
"bool",
")",
"*",
"FcmClient",
"{",
"this",
".",
"Message",
".",
"DryRun",
"=",
"drun",
"\n\n",
"return",
"this",
"\n",
"}"
] |
// SetDryRun This parameter, when set to true, allows developers to test
// a request without actually sending a message.
// The default value is false
|
[
"SetDryRun",
"This",
"parameter",
"when",
"set",
"to",
"true",
"allows",
"developers",
"to",
"test",
"a",
"request",
"without",
"actually",
"sending",
"a",
"message",
".",
"The",
"default",
"value",
"is",
"false"
] |
28fff9381d17f35619309c7a5ada41d26030d976
|
https://github.com/NaySoftware/go-fcm/blob/28fff9381d17f35619309c7a5ada41d26030d976/fcm.go#L310-L315
|
144,501 |
NaySoftware/go-fcm
|
fcm.go
|
SetMutableContent
|
func (this *FcmClient) SetMutableContent(mc bool) *FcmClient {
this.Message.MutableContent = mc
return this
}
|
go
|
func (this *FcmClient) SetMutableContent(mc bool) *FcmClient {
this.Message.MutableContent = mc
return this
}
|
[
"func",
"(",
"this",
"*",
"FcmClient",
")",
"SetMutableContent",
"(",
"mc",
"bool",
")",
"*",
"FcmClient",
"{",
"this",
".",
"Message",
".",
"MutableContent",
"=",
"mc",
"\n\n",
"return",
"this",
"\n",
"}"
] |
// SetMutableContent Currently for iOS 10+ devices only. On iOS,
// use this field to represent mutable-content in the APNs payload.
// When a notification is sent and this is set to true, the content
// of the notification can be modified before it is displayed,
// using a Notification Service app extension.
// This parameter will be ignored for Android and web.
|
[
"SetMutableContent",
"Currently",
"for",
"iOS",
"10",
"+",
"devices",
"only",
".",
"On",
"iOS",
"use",
"this",
"field",
"to",
"represent",
"mutable",
"-",
"content",
"in",
"the",
"APNs",
"payload",
".",
"When",
"a",
"notification",
"is",
"sent",
"and",
"this",
"is",
"set",
"to",
"true",
"the",
"content",
"of",
"the",
"notification",
"can",
"be",
"modified",
"before",
"it",
"is",
"displayed",
"using",
"a",
"Notification",
"Service",
"app",
"extension",
".",
"This",
"parameter",
"will",
"be",
"ignored",
"for",
"Android",
"and",
"web",
"."
] |
28fff9381d17f35619309c7a5ada41d26030d976
|
https://github.com/NaySoftware/go-fcm/blob/28fff9381d17f35619309c7a5ada41d26030d976/fcm.go#L323-L328
|
144,502 |
NaySoftware/go-fcm
|
fcm.go
|
PrintResults
|
func (this *FcmResponseStatus) PrintResults() {
fmt.Println("Status Code :", this.StatusCode)
fmt.Println("Success :", this.Success)
fmt.Println("Fail :", this.Fail)
fmt.Println("Canonical_ids :", this.Canonical_ids)
fmt.Println("Topic MsgId :", this.MsgId)
fmt.Println("Topic Err :", this.Err)
for i, val := range this.Results {
fmt.Printf("Result(%d)> \n", i)
for k, v := range val {
fmt.Println("\t", k, " : ", v)
}
}
}
|
go
|
func (this *FcmResponseStatus) PrintResults() {
fmt.Println("Status Code :", this.StatusCode)
fmt.Println("Success :", this.Success)
fmt.Println("Fail :", this.Fail)
fmt.Println("Canonical_ids :", this.Canonical_ids)
fmt.Println("Topic MsgId :", this.MsgId)
fmt.Println("Topic Err :", this.Err)
for i, val := range this.Results {
fmt.Printf("Result(%d)> \n", i)
for k, v := range val {
fmt.Println("\t", k, " : ", v)
}
}
}
|
[
"func",
"(",
"this",
"*",
"FcmResponseStatus",
")",
"PrintResults",
"(",
")",
"{",
"fmt",
".",
"Println",
"(",
"\"",
"\"",
",",
"this",
".",
"StatusCode",
")",
"\n",
"fmt",
".",
"Println",
"(",
"\"",
"\"",
",",
"this",
".",
"Success",
")",
"\n",
"fmt",
".",
"Println",
"(",
"\"",
"\"",
",",
"this",
".",
"Fail",
")",
"\n",
"fmt",
".",
"Println",
"(",
"\"",
"\"",
",",
"this",
".",
"Canonical_ids",
")",
"\n",
"fmt",
".",
"Println",
"(",
"\"",
"\"",
",",
"this",
".",
"MsgId",
")",
"\n",
"fmt",
".",
"Println",
"(",
"\"",
"\"",
",",
"this",
".",
"Err",
")",
"\n",
"for",
"i",
",",
"val",
":=",
"range",
"this",
".",
"Results",
"{",
"fmt",
".",
"Printf",
"(",
"\"",
"\\n",
"\"",
",",
"i",
")",
"\n",
"for",
"k",
",",
"v",
":=",
"range",
"val",
"{",
"fmt",
".",
"Println",
"(",
"\"",
"\\t",
"\"",
",",
"k",
",",
"\"",
"\"",
",",
"v",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] |
// PrintResults prints the FcmResponseStatus results for fast using and debugging
|
[
"PrintResults",
"prints",
"the",
"FcmResponseStatus",
"results",
"for",
"fast",
"using",
"and",
"debugging"
] |
28fff9381d17f35619309c7a5ada41d26030d976
|
https://github.com/NaySoftware/go-fcm/blob/28fff9381d17f35619309c7a5ada41d26030d976/fcm.go#L331-L344
|
144,503 |
NaySoftware/go-fcm
|
fcm.go
|
IsTimeout
|
func (this *FcmResponseStatus) IsTimeout() bool {
if this.StatusCode >= 500 {
return true
} else if this.StatusCode == 200 {
for _, val := range this.Results {
for k, v := range val {
if k == error_key && retreyableErrors[v] == true {
return true
}
}
}
}
return false
}
|
go
|
func (this *FcmResponseStatus) IsTimeout() bool {
if this.StatusCode >= 500 {
return true
} else if this.StatusCode == 200 {
for _, val := range this.Results {
for k, v := range val {
if k == error_key && retreyableErrors[v] == true {
return true
}
}
}
}
return false
}
|
[
"func",
"(",
"this",
"*",
"FcmResponseStatus",
")",
"IsTimeout",
"(",
")",
"bool",
"{",
"if",
"this",
".",
"StatusCode",
">=",
"500",
"{",
"return",
"true",
"\n",
"}",
"else",
"if",
"this",
".",
"StatusCode",
"==",
"200",
"{",
"for",
"_",
",",
"val",
":=",
"range",
"this",
".",
"Results",
"{",
"for",
"k",
",",
"v",
":=",
"range",
"val",
"{",
"if",
"k",
"==",
"error_key",
"&&",
"retreyableErrors",
"[",
"v",
"]",
"==",
"true",
"{",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"false",
"\n",
"}"
] |
// IsTimeout check whether the response timeout based on http response status
// code and if any error is retryable
|
[
"IsTimeout",
"check",
"whether",
"the",
"response",
"timeout",
"based",
"on",
"http",
"response",
"status",
"code",
"and",
"if",
"any",
"error",
"is",
"retryable"
] |
28fff9381d17f35619309c7a5ada41d26030d976
|
https://github.com/NaySoftware/go-fcm/blob/28fff9381d17f35619309c7a5ada41d26030d976/fcm.go#L348-L362
|
144,504 |
NaySoftware/go-fcm
|
fcm.go
|
GetRetryAfterTime
|
func (this *FcmResponseStatus) GetRetryAfterTime() (t time.Duration, e error) {
t, e = time.ParseDuration(this.RetryAfter)
return
}
|
go
|
func (this *FcmResponseStatus) GetRetryAfterTime() (t time.Duration, e error) {
t, e = time.ParseDuration(this.RetryAfter)
return
}
|
[
"func",
"(",
"this",
"*",
"FcmResponseStatus",
")",
"GetRetryAfterTime",
"(",
")",
"(",
"t",
"time",
".",
"Duration",
",",
"e",
"error",
")",
"{",
"t",
",",
"e",
"=",
"time",
".",
"ParseDuration",
"(",
"this",
".",
"RetryAfter",
")",
"\n",
"return",
"\n",
"}"
] |
// GetRetryAfterTime converts the retrey after response header
// to a time.Duration
|
[
"GetRetryAfterTime",
"converts",
"the",
"retrey",
"after",
"response",
"header",
"to",
"a",
"time",
".",
"Duration"
] |
28fff9381d17f35619309c7a5ada41d26030d976
|
https://github.com/NaySoftware/go-fcm/blob/28fff9381d17f35619309c7a5ada41d26030d976/fcm.go#L366-L369
|
144,505 |
NaySoftware/go-fcm
|
fcm.go
|
SetCondition
|
func (this *FcmClient) SetCondition(condition string) *FcmClient {
this.Message.Condition = condition
return this
}
|
go
|
func (this *FcmClient) SetCondition(condition string) *FcmClient {
this.Message.Condition = condition
return this
}
|
[
"func",
"(",
"this",
"*",
"FcmClient",
")",
"SetCondition",
"(",
"condition",
"string",
")",
"*",
"FcmClient",
"{",
"this",
".",
"Message",
".",
"Condition",
"=",
"condition",
"\n",
"return",
"this",
"\n",
"}"
] |
// SetCondition to set a logical expression of conditions that determine the message target
|
[
"SetCondition",
"to",
"set",
"a",
"logical",
"expression",
"of",
"conditions",
"that",
"determine",
"the",
"message",
"target"
] |
28fff9381d17f35619309c7a5ada41d26030d976
|
https://github.com/NaySoftware/go-fcm/blob/28fff9381d17f35619309c7a5ada41d26030d976/fcm.go#L372-L375
|
144,506 |
NaySoftware/go-fcm
|
instanceid.go
|
GetInfo
|
func (this *FcmClient) GetInfo(withDetails bool, instanceIdToken string) (*InstanceIdInfoResponse, error) {
var request_url string = generateGetInfoUrl(instance_id_info_no_details_srv_url, instanceIdToken)
if withDetails == true {
request_url = generateGetInfoUrl(instance_id_info_with_details_srv_url, instanceIdToken)
}
request, err := http.NewRequest("GET", request_url, nil)
request.Header.Set("Authorization", this.apiKeyHeader())
request.Header.Set("Content-Type", "application/json")
if err != nil {
return nil, err
}
client := &http.Client{}
response, err := client.Do(request)
if err != nil {
return nil, err
}
defer response.Body.Close()
body, err := ioutil.ReadAll(response.Body)
if err != nil {
return nil, err
}
infoResponse, err := parseGetInfo(body)
if err != nil {
return nil, err
}
return infoResponse, nil
}
|
go
|
func (this *FcmClient) GetInfo(withDetails bool, instanceIdToken string) (*InstanceIdInfoResponse, error) {
var request_url string = generateGetInfoUrl(instance_id_info_no_details_srv_url, instanceIdToken)
if withDetails == true {
request_url = generateGetInfoUrl(instance_id_info_with_details_srv_url, instanceIdToken)
}
request, err := http.NewRequest("GET", request_url, nil)
request.Header.Set("Authorization", this.apiKeyHeader())
request.Header.Set("Content-Type", "application/json")
if err != nil {
return nil, err
}
client := &http.Client{}
response, err := client.Do(request)
if err != nil {
return nil, err
}
defer response.Body.Close()
body, err := ioutil.ReadAll(response.Body)
if err != nil {
return nil, err
}
infoResponse, err := parseGetInfo(body)
if err != nil {
return nil, err
}
return infoResponse, nil
}
|
[
"func",
"(",
"this",
"*",
"FcmClient",
")",
"GetInfo",
"(",
"withDetails",
"bool",
",",
"instanceIdToken",
"string",
")",
"(",
"*",
"InstanceIdInfoResponse",
",",
"error",
")",
"{",
"var",
"request_url",
"string",
"=",
"generateGetInfoUrl",
"(",
"instance_id_info_no_details_srv_url",
",",
"instanceIdToken",
")",
"\n\n",
"if",
"withDetails",
"==",
"true",
"{",
"request_url",
"=",
"generateGetInfoUrl",
"(",
"instance_id_info_with_details_srv_url",
",",
"instanceIdToken",
")",
"\n",
"}",
"\n\n",
"request",
",",
"err",
":=",
"http",
".",
"NewRequest",
"(",
"\"",
"\"",
",",
"request_url",
",",
"nil",
")",
"\n",
"request",
".",
"Header",
".",
"Set",
"(",
"\"",
"\"",
",",
"this",
".",
"apiKeyHeader",
"(",
")",
")",
"\n",
"request",
".",
"Header",
".",
"Set",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"client",
":=",
"&",
"http",
".",
"Client",
"{",
"}",
"\n",
"response",
",",
"err",
":=",
"client",
".",
"Do",
"(",
"request",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"defer",
"response",
".",
"Body",
".",
"Close",
"(",
")",
"\n\n",
"body",
",",
"err",
":=",
"ioutil",
".",
"ReadAll",
"(",
"response",
".",
"Body",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"infoResponse",
",",
"err",
":=",
"parseGetInfo",
"(",
"body",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"infoResponse",
",",
"nil",
"\n",
"}"
] |
// GetInfo gets the instance id info
|
[
"GetInfo",
"gets",
"the",
"instance",
"id",
"info"
] |
28fff9381d17f35619309c7a5ada41d26030d976
|
https://github.com/NaySoftware/go-fcm/blob/28fff9381d17f35619309c7a5ada41d26030d976/instanceid.go#L104-L139
|
144,507 |
NaySoftware/go-fcm
|
instanceid.go
|
parseGetInfo
|
func parseGetInfo(body []byte) (*InstanceIdInfoResponse, error) {
info := new(InstanceIdInfoResponse)
if err := json.Unmarshal([]byte(body), &info); err != nil {
return nil, err
}
return info, nil
}
|
go
|
func parseGetInfo(body []byte) (*InstanceIdInfoResponse, error) {
info := new(InstanceIdInfoResponse)
if err := json.Unmarshal([]byte(body), &info); err != nil {
return nil, err
}
return info, nil
}
|
[
"func",
"parseGetInfo",
"(",
"body",
"[",
"]",
"byte",
")",
"(",
"*",
"InstanceIdInfoResponse",
",",
"error",
")",
"{",
"info",
":=",
"new",
"(",
"InstanceIdInfoResponse",
")",
"\n\n",
"if",
"err",
":=",
"json",
".",
"Unmarshal",
"(",
"[",
"]",
"byte",
"(",
"body",
")",
",",
"&",
"info",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"info",
",",
"nil",
"\n\n",
"}"
] |
// parseGetInfo parses response to InstanceIdInfoResponse
|
[
"parseGetInfo",
"parses",
"response",
"to",
"InstanceIdInfoResponse"
] |
28fff9381d17f35619309c7a5ada41d26030d976
|
https://github.com/NaySoftware/go-fcm/blob/28fff9381d17f35619309c7a5ada41d26030d976/instanceid.go#L142-L152
|
144,508 |
NaySoftware/go-fcm
|
instanceid.go
|
PrintResults
|
func (this *InstanceIdInfoResponse) PrintResults() {
fmt.Println("Error : ", this.Error)
fmt.Println("App : ", this.Application)
fmt.Println("Auth : ", this.AuthorizedEntity)
fmt.Println("Ver : ", this.ApplicationVersion)
fmt.Println("Sig : ", this.AppSigner)
fmt.Println("Att : ", this.AttestStatus)
fmt.Println("Platform : ", this.Platform)
fmt.Println("Connection: ", this.ConnectionType)
fmt.Println("ConnDate : ", this.ConnectDate)
fmt.Println("Rel : ")
for k, v := range this.Rel {
fmt.Println(k, " --> ")
for k2, v2 := range v {
fmt.Println("\t", k2, "\t|")
fmt.Println("\t\t", "addDate", " : ", v2["addDate"])
}
}
}
|
go
|
func (this *InstanceIdInfoResponse) PrintResults() {
fmt.Println("Error : ", this.Error)
fmt.Println("App : ", this.Application)
fmt.Println("Auth : ", this.AuthorizedEntity)
fmt.Println("Ver : ", this.ApplicationVersion)
fmt.Println("Sig : ", this.AppSigner)
fmt.Println("Att : ", this.AttestStatus)
fmt.Println("Platform : ", this.Platform)
fmt.Println("Connection: ", this.ConnectionType)
fmt.Println("ConnDate : ", this.ConnectDate)
fmt.Println("Rel : ")
for k, v := range this.Rel {
fmt.Println(k, " --> ")
for k2, v2 := range v {
fmt.Println("\t", k2, "\t|")
fmt.Println("\t\t", "addDate", " : ", v2["addDate"])
}
}
}
|
[
"func",
"(",
"this",
"*",
"InstanceIdInfoResponse",
")",
"PrintResults",
"(",
")",
"{",
"fmt",
".",
"Println",
"(",
"\"",
"\"",
",",
"this",
".",
"Error",
")",
"\n",
"fmt",
".",
"Println",
"(",
"\"",
"\"",
",",
"this",
".",
"Application",
")",
"\n",
"fmt",
".",
"Println",
"(",
"\"",
"\"",
",",
"this",
".",
"AuthorizedEntity",
")",
"\n",
"fmt",
".",
"Println",
"(",
"\"",
"\"",
",",
"this",
".",
"ApplicationVersion",
")",
"\n",
"fmt",
".",
"Println",
"(",
"\"",
"\"",
",",
"this",
".",
"AppSigner",
")",
"\n",
"fmt",
".",
"Println",
"(",
"\"",
"\"",
",",
"this",
".",
"AttestStatus",
")",
"\n",
"fmt",
".",
"Println",
"(",
"\"",
"\"",
",",
"this",
".",
"Platform",
")",
"\n",
"fmt",
".",
"Println",
"(",
"\"",
"\"",
",",
"this",
".",
"ConnectionType",
")",
"\n",
"fmt",
".",
"Println",
"(",
"\"",
"\"",
",",
"this",
".",
"ConnectDate",
")",
"\n",
"fmt",
".",
"Println",
"(",
"\"",
"\"",
")",
"\n",
"for",
"k",
",",
"v",
":=",
"range",
"this",
".",
"Rel",
"{",
"fmt",
".",
"Println",
"(",
"k",
",",
"\"",
"\"",
")",
"\n",
"for",
"k2",
",",
"v2",
":=",
"range",
"v",
"{",
"fmt",
".",
"Println",
"(",
"\"",
"\\t",
"\"",
",",
"k2",
",",
"\"",
"\\t",
"\"",
")",
"\n",
"fmt",
".",
"Println",
"(",
"\"",
"\\t",
"\\t",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"v2",
"[",
"\"",
"\"",
"]",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] |
// PrintResults prints InstanceIdInfoResponse, for faster debugging
|
[
"PrintResults",
"prints",
"InstanceIdInfoResponse",
"for",
"faster",
"debugging"
] |
28fff9381d17f35619309c7a5ada41d26030d976
|
https://github.com/NaySoftware/go-fcm/blob/28fff9381d17f35619309c7a5ada41d26030d976/instanceid.go#L155-L173
|
144,509 |
NaySoftware/go-fcm
|
instanceid.go
|
generateGetInfoUrl
|
func generateGetInfoUrl(srv string, instanceIdToken string) string {
return fmt.Sprintf(srv, instanceIdToken)
}
|
go
|
func generateGetInfoUrl(srv string, instanceIdToken string) string {
return fmt.Sprintf(srv, instanceIdToken)
}
|
[
"func",
"generateGetInfoUrl",
"(",
"srv",
"string",
",",
"instanceIdToken",
"string",
")",
"string",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"srv",
",",
"instanceIdToken",
")",
"\n",
"}"
] |
// generateGetInfoUrl generate based on with details and the instance token
|
[
"generateGetInfoUrl",
"generate",
"based",
"on",
"with",
"details",
"and",
"the",
"instance",
"token"
] |
28fff9381d17f35619309c7a5ada41d26030d976
|
https://github.com/NaySoftware/go-fcm/blob/28fff9381d17f35619309c7a5ada41d26030d976/instanceid.go#L176-L178
|
144,510 |
NaySoftware/go-fcm
|
instanceid.go
|
parseSubscribeResponse
|
func parseSubscribeResponse(body []byte, resp *http.Response) (*SubscribeResponse, error) {
subResp := new(SubscribeResponse)
subResp.Status = resp.Status
subResp.StatusCode = resp.StatusCode
if err := json.Unmarshal(body, &subResp); err != nil {
return nil, err
}
return subResp, nil
}
|
go
|
func parseSubscribeResponse(body []byte, resp *http.Response) (*SubscribeResponse, error) {
subResp := new(SubscribeResponse)
subResp.Status = resp.Status
subResp.StatusCode = resp.StatusCode
if err := json.Unmarshal(body, &subResp); err != nil {
return nil, err
}
return subResp, nil
}
|
[
"func",
"parseSubscribeResponse",
"(",
"body",
"[",
"]",
"byte",
",",
"resp",
"*",
"http",
".",
"Response",
")",
"(",
"*",
"SubscribeResponse",
",",
"error",
")",
"{",
"subResp",
":=",
"new",
"(",
"SubscribeResponse",
")",
"\n\n",
"subResp",
".",
"Status",
"=",
"resp",
".",
"Status",
"\n",
"subResp",
".",
"StatusCode",
"=",
"resp",
".",
"StatusCode",
"\n\n",
"if",
"err",
":=",
"json",
".",
"Unmarshal",
"(",
"body",
",",
"&",
"subResp",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"subResp",
",",
"nil",
"\n",
"}"
] |
// parseSubscribeResponse converts a byte response to a SubscribeResponse
|
[
"parseSubscribeResponse",
"converts",
"a",
"byte",
"response",
"to",
"a",
"SubscribeResponse"
] |
28fff9381d17f35619309c7a5ada41d26030d976
|
https://github.com/NaySoftware/go-fcm/blob/28fff9381d17f35619309c7a5ada41d26030d976/instanceid.go#L213-L224
|
144,511 |
NaySoftware/go-fcm
|
instanceid.go
|
PrintResults
|
func (this *SubscribeResponse) PrintResults() {
fmt.Println("Response Status: ", this.Status)
fmt.Println("Response Code : ", this.StatusCode)
if this.StatusCode != 200 {
fmt.Println("Error : ", this.Error)
}
}
|
go
|
func (this *SubscribeResponse) PrintResults() {
fmt.Println("Response Status: ", this.Status)
fmt.Println("Response Code : ", this.StatusCode)
if this.StatusCode != 200 {
fmt.Println("Error : ", this.Error)
}
}
|
[
"func",
"(",
"this",
"*",
"SubscribeResponse",
")",
"PrintResults",
"(",
")",
"{",
"fmt",
".",
"Println",
"(",
"\"",
"\"",
",",
"this",
".",
"Status",
")",
"\n",
"fmt",
".",
"Println",
"(",
"\"",
"\"",
",",
"this",
".",
"StatusCode",
")",
"\n",
"if",
"this",
".",
"StatusCode",
"!=",
"200",
"{",
"fmt",
".",
"Println",
"(",
"\"",
"\"",
",",
"this",
".",
"Error",
")",
"\n",
"}",
"\n\n",
"}"
] |
// PrintResults prints SubscribeResponse, for faster debugging
|
[
"PrintResults",
"prints",
"SubscribeResponse",
"for",
"faster",
"debugging"
] |
28fff9381d17f35619309c7a5ada41d26030d976
|
https://github.com/NaySoftware/go-fcm/blob/28fff9381d17f35619309c7a5ada41d26030d976/instanceid.go#L227-L235
|
144,512 |
NaySoftware/go-fcm
|
instanceid.go
|
generateSubToTopicUrl
|
func generateSubToTopicUrl(instaceId string, topic string) string {
Tmptopic := strings.ToLower(topic)
if strings.Contains(Tmptopic, "/topics/") {
tmp := strings.Split(topic, "/")
topic = tmp[len(tmp)-1]
}
return fmt.Sprintf(subscribe_instanceid_to_topic_srv_url, instaceId, topic)
}
|
go
|
func generateSubToTopicUrl(instaceId string, topic string) string {
Tmptopic := strings.ToLower(topic)
if strings.Contains(Tmptopic, "/topics/") {
tmp := strings.Split(topic, "/")
topic = tmp[len(tmp)-1]
}
return fmt.Sprintf(subscribe_instanceid_to_topic_srv_url, instaceId, topic)
}
|
[
"func",
"generateSubToTopicUrl",
"(",
"instaceId",
"string",
",",
"topic",
"string",
")",
"string",
"{",
"Tmptopic",
":=",
"strings",
".",
"ToLower",
"(",
"topic",
")",
"\n",
"if",
"strings",
".",
"Contains",
"(",
"Tmptopic",
",",
"\"",
"\"",
")",
"{",
"tmp",
":=",
"strings",
".",
"Split",
"(",
"topic",
",",
"\"",
"\"",
")",
"\n",
"topic",
"=",
"tmp",
"[",
"len",
"(",
"tmp",
")",
"-",
"1",
"]",
"\n",
"}",
"\n",
"return",
"fmt",
".",
"Sprintf",
"(",
"subscribe_instanceid_to_topic_srv_url",
",",
"instaceId",
",",
"topic",
")",
"\n",
"}"
] |
// generateSubToTopicUrl generates a url based on the instnace id and topic name
|
[
"generateSubToTopicUrl",
"generates",
"a",
"url",
"based",
"on",
"the",
"instnace",
"id",
"and",
"topic",
"name"
] |
28fff9381d17f35619309c7a5ada41d26030d976
|
https://github.com/NaySoftware/go-fcm/blob/28fff9381d17f35619309c7a5ada41d26030d976/instanceid.go#L238-L245
|
144,513 |
NaySoftware/go-fcm
|
instanceid.go
|
PrintResults
|
func (this *BatchResponse) PrintResults() {
fmt.Println("Error : ", this.Error)
fmt.Println("Status : ", this.Status)
fmt.Println("Status Code : ", this.StatusCode)
for i, val := range this.Results {
if batchErrors[val["error"]] == true {
fmt.Println("ID: ", i, " | ", val["error"])
}
}
}
|
go
|
func (this *BatchResponse) PrintResults() {
fmt.Println("Error : ", this.Error)
fmt.Println("Status : ", this.Status)
fmt.Println("Status Code : ", this.StatusCode)
for i, val := range this.Results {
if batchErrors[val["error"]] == true {
fmt.Println("ID: ", i, " | ", val["error"])
}
}
}
|
[
"func",
"(",
"this",
"*",
"BatchResponse",
")",
"PrintResults",
"(",
")",
"{",
"fmt",
".",
"Println",
"(",
"\"",
"\"",
",",
"this",
".",
"Error",
")",
"\n",
"fmt",
".",
"Println",
"(",
"\"",
"\"",
",",
"this",
".",
"Status",
")",
"\n",
"fmt",
".",
"Println",
"(",
"\"",
"\"",
",",
"this",
".",
"StatusCode",
")",
"\n",
"for",
"i",
",",
"val",
":=",
"range",
"this",
".",
"Results",
"{",
"if",
"batchErrors",
"[",
"val",
"[",
"\"",
"\"",
"]",
"]",
"==",
"true",
"{",
"fmt",
".",
"Println",
"(",
"\"",
"\"",
",",
"i",
",",
"\"",
"\"",
",",
"val",
"[",
"\"",
"\"",
"]",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] |
// PrintResults prints BatchResponse, for faster debugging
|
[
"PrintResults",
"prints",
"BatchResponse",
"for",
"faster",
"debugging"
] |
28fff9381d17f35619309c7a5ada41d26030d976
|
https://github.com/NaySoftware/go-fcm/blob/28fff9381d17f35619309c7a5ada41d26030d976/instanceid.go#L331-L340
|
144,514 |
NaySoftware/go-fcm
|
instanceid.go
|
generateBatchRequest
|
func generateBatchRequest(tokens []string, topic string) ([]byte, error) {
envelope := new(BatchRequest)
envelope.To = topics + extractTopicName(topic)
envelope.RegTokens = make([]string, len(tokens))
copy(envelope.RegTokens, tokens)
return json.Marshal(envelope)
}
|
go
|
func generateBatchRequest(tokens []string, topic string) ([]byte, error) {
envelope := new(BatchRequest)
envelope.To = topics + extractTopicName(topic)
envelope.RegTokens = make([]string, len(tokens))
copy(envelope.RegTokens, tokens)
return json.Marshal(envelope)
}
|
[
"func",
"generateBatchRequest",
"(",
"tokens",
"[",
"]",
"string",
",",
"topic",
"string",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"envelope",
":=",
"new",
"(",
"BatchRequest",
")",
"\n",
"envelope",
".",
"To",
"=",
"topics",
"+",
"extractTopicName",
"(",
"topic",
")",
"\n",
"envelope",
".",
"RegTokens",
"=",
"make",
"(",
"[",
"]",
"string",
",",
"len",
"(",
"tokens",
")",
")",
"\n",
"copy",
"(",
"envelope",
".",
"RegTokens",
",",
"tokens",
")",
"\n\n",
"return",
"json",
".",
"Marshal",
"(",
"envelope",
")",
"\n\n",
"}"
] |
// generateBatchRequest based on tokens and topic
|
[
"generateBatchRequest",
"based",
"on",
"tokens",
"and",
"topic"
] |
28fff9381d17f35619309c7a5ada41d26030d976
|
https://github.com/NaySoftware/go-fcm/blob/28fff9381d17f35619309c7a5ada41d26030d976/instanceid.go#L343-L351
|
144,515 |
NaySoftware/go-fcm
|
instanceid.go
|
extractTopicName
|
func extractTopicName(inTopic string) (result string) {
Tmptopic := strings.ToLower(inTopic)
if strings.Contains(Tmptopic, "/topics/") {
tmp := strings.Split(inTopic, "/")
result = tmp[len(tmp)-1]
return
}
result = inTopic
return
}
|
go
|
func extractTopicName(inTopic string) (result string) {
Tmptopic := strings.ToLower(inTopic)
if strings.Contains(Tmptopic, "/topics/") {
tmp := strings.Split(inTopic, "/")
result = tmp[len(tmp)-1]
return
}
result = inTopic
return
}
|
[
"func",
"extractTopicName",
"(",
"inTopic",
"string",
")",
"(",
"result",
"string",
")",
"{",
"Tmptopic",
":=",
"strings",
".",
"ToLower",
"(",
"inTopic",
")",
"\n",
"if",
"strings",
".",
"Contains",
"(",
"Tmptopic",
",",
"\"",
"\"",
")",
"{",
"tmp",
":=",
"strings",
".",
"Split",
"(",
"inTopic",
",",
"\"",
"\"",
")",
"\n",
"result",
"=",
"tmp",
"[",
"len",
"(",
"tmp",
")",
"-",
"1",
"]",
"\n",
"return",
"\n",
"}",
"\n\n",
"result",
"=",
"inTopic",
"\n",
"return",
"\n",
"}"
] |
// extractTopicName extract topic name for valid topic name input
|
[
"extractTopicName",
"extract",
"topic",
"name",
"for",
"valid",
"topic",
"name",
"input"
] |
28fff9381d17f35619309c7a5ada41d26030d976
|
https://github.com/NaySoftware/go-fcm/blob/28fff9381d17f35619309c7a5ada41d26030d976/instanceid.go#L354-L364
|
144,516 |
NaySoftware/go-fcm
|
instanceid.go
|
generateBatchResponse
|
func generateBatchResponse(resp []byte) (*BatchResponse, error) {
result := new(BatchResponse)
if err := json.Unmarshal(resp, &result); err != nil {
return nil, err
}
return result, nil
}
|
go
|
func generateBatchResponse(resp []byte) (*BatchResponse, error) {
result := new(BatchResponse)
if err := json.Unmarshal(resp, &result); err != nil {
return nil, err
}
return result, nil
}
|
[
"func",
"generateBatchResponse",
"(",
"resp",
"[",
"]",
"byte",
")",
"(",
"*",
"BatchResponse",
",",
"error",
")",
"{",
"result",
":=",
"new",
"(",
"BatchResponse",
")",
"\n\n",
"if",
"err",
":=",
"json",
".",
"Unmarshal",
"(",
"resp",
",",
"&",
"result",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"result",
",",
"nil",
"\n\n",
"}"
] |
// generateBatchResponse converts a byte response to BatchResponse
|
[
"generateBatchResponse",
"converts",
"a",
"byte",
"response",
"to",
"BatchResponse"
] |
28fff9381d17f35619309c7a5ada41d26030d976
|
https://github.com/NaySoftware/go-fcm/blob/28fff9381d17f35619309c7a5ada41d26030d976/instanceid.go#L367-L376
|
144,517 |
NaySoftware/go-fcm
|
instanceid.go
|
ApnsBatchImportRequest
|
func (this *FcmClient) ApnsBatchImportRequest(apnsReq *ApnsBatchRequest) (*ApnsBatchResponse, error) {
jsonByte, err := apnsReq.ToByte()
if err != nil {
return nil, err
}
request, err := http.NewRequest("POST", apns_batch_import_srv_url, bytes.NewBuffer(jsonByte))
request.Header.Set("Authorization", this.apiKeyHeader())
request.Header.Set("Content-Type", "application/json")
if err != nil {
return nil, err
}
client := &http.Client{}
response, err := client.Do(request)
if err != nil {
return nil, err
}
defer response.Body.Close()
body, err := ioutil.ReadAll(response.Body)
if err != nil {
return nil, err
}
result, err := parseApnsBatchResponse(body)
if err != nil {
return nil, err
}
if result == nil {
return nil, errors.New("Parsing Request error")
}
result.Status = response.Status
result.StatusCode = response.StatusCode
return result, nil
}
|
go
|
func (this *FcmClient) ApnsBatchImportRequest(apnsReq *ApnsBatchRequest) (*ApnsBatchResponse, error) {
jsonByte, err := apnsReq.ToByte()
if err != nil {
return nil, err
}
request, err := http.NewRequest("POST", apns_batch_import_srv_url, bytes.NewBuffer(jsonByte))
request.Header.Set("Authorization", this.apiKeyHeader())
request.Header.Set("Content-Type", "application/json")
if err != nil {
return nil, err
}
client := &http.Client{}
response, err := client.Do(request)
if err != nil {
return nil, err
}
defer response.Body.Close()
body, err := ioutil.ReadAll(response.Body)
if err != nil {
return nil, err
}
result, err := parseApnsBatchResponse(body)
if err != nil {
return nil, err
}
if result == nil {
return nil, errors.New("Parsing Request error")
}
result.Status = response.Status
result.StatusCode = response.StatusCode
return result, nil
}
|
[
"func",
"(",
"this",
"*",
"FcmClient",
")",
"ApnsBatchImportRequest",
"(",
"apnsReq",
"*",
"ApnsBatchRequest",
")",
"(",
"*",
"ApnsBatchResponse",
",",
"error",
")",
"{",
"jsonByte",
",",
"err",
":=",
"apnsReq",
".",
"ToByte",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"request",
",",
"err",
":=",
"http",
".",
"NewRequest",
"(",
"\"",
"\"",
",",
"apns_batch_import_srv_url",
",",
"bytes",
".",
"NewBuffer",
"(",
"jsonByte",
")",
")",
"\n",
"request",
".",
"Header",
".",
"Set",
"(",
"\"",
"\"",
",",
"this",
".",
"apiKeyHeader",
"(",
")",
")",
"\n",
"request",
".",
"Header",
".",
"Set",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"client",
":=",
"&",
"http",
".",
"Client",
"{",
"}",
"\n",
"response",
",",
"err",
":=",
"client",
".",
"Do",
"(",
"request",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"defer",
"response",
".",
"Body",
".",
"Close",
"(",
")",
"\n\n",
"body",
",",
"err",
":=",
"ioutil",
".",
"ReadAll",
"(",
"response",
".",
"Body",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"result",
",",
"err",
":=",
"parseApnsBatchResponse",
"(",
"body",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"result",
"==",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"result",
".",
"Status",
"=",
"response",
".",
"Status",
"\n",
"result",
".",
"StatusCode",
"=",
"response",
".",
"StatusCode",
"\n\n",
"return",
"result",
",",
"nil",
"\n",
"}"
] |
// ApnsBatchImportRequest apns import requst
|
[
"ApnsBatchImportRequest",
"apns",
"import",
"requst"
] |
28fff9381d17f35619309c7a5ada41d26030d976
|
https://github.com/NaySoftware/go-fcm/blob/28fff9381d17f35619309c7a5ada41d26030d976/instanceid.go#L379-L420
|
144,518 |
NaySoftware/go-fcm
|
instanceid.go
|
ToByte
|
func (this *ApnsBatchRequest) ToByte() ([]byte, error) {
data, err := json.Marshal(this)
if err != nil {
return nil, err
}
return data, nil
}
|
go
|
func (this *ApnsBatchRequest) ToByte() ([]byte, error) {
data, err := json.Marshal(this)
if err != nil {
return nil, err
}
return data, nil
}
|
[
"func",
"(",
"this",
"*",
"ApnsBatchRequest",
")",
"ToByte",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"data",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"this",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"data",
",",
"nil",
"\n",
"}"
] |
// ToByte converts ApnsBatchRequest to a byte
|
[
"ToByte",
"converts",
"ApnsBatchRequest",
"to",
"a",
"byte"
] |
28fff9381d17f35619309c7a5ada41d26030d976
|
https://github.com/NaySoftware/go-fcm/blob/28fff9381d17f35619309c7a5ada41d26030d976/instanceid.go#L423-L430
|
144,519 |
NaySoftware/go-fcm
|
instanceid.go
|
parseApnsBatchResponse
|
func parseApnsBatchResponse(resp []byte) (*ApnsBatchResponse, error) {
result := new(ApnsBatchResponse)
if err := json.Unmarshal(resp, &result); err != nil {
return nil, err
}
return result, nil
}
|
go
|
func parseApnsBatchResponse(resp []byte) (*ApnsBatchResponse, error) {
result := new(ApnsBatchResponse)
if err := json.Unmarshal(resp, &result); err != nil {
return nil, err
}
return result, nil
}
|
[
"func",
"parseApnsBatchResponse",
"(",
"resp",
"[",
"]",
"byte",
")",
"(",
"*",
"ApnsBatchResponse",
",",
"error",
")",
"{",
"result",
":=",
"new",
"(",
"ApnsBatchResponse",
")",
"\n",
"if",
"err",
":=",
"json",
".",
"Unmarshal",
"(",
"resp",
",",
"&",
"result",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"result",
",",
"nil",
"\n\n",
"}"
] |
// parseApnsBatchResponse converts apns byte response to ApnsBatchResponse
|
[
"parseApnsBatchResponse",
"converts",
"apns",
"byte",
"response",
"to",
"ApnsBatchResponse"
] |
28fff9381d17f35619309c7a5ada41d26030d976
|
https://github.com/NaySoftware/go-fcm/blob/28fff9381d17f35619309c7a5ada41d26030d976/instanceid.go#L433-L442
|
144,520 |
NaySoftware/go-fcm
|
instanceid.go
|
PrintResults
|
func (this *ApnsBatchResponse) PrintResults() {
fmt.Println("Status : ", this.Status)
fmt.Println("StatusCode : ", this.StatusCode)
fmt.Println("Error : ", this.Error)
for i, val := range this.Results {
fmt.Println(i, ":")
fmt.Println("\tAPNS Token", val[apns_token_key])
fmt.Println("\tStatus ", val[status_key])
fmt.Println("\tReg Token ", val[reg_token_key])
}
}
|
go
|
func (this *ApnsBatchResponse) PrintResults() {
fmt.Println("Status : ", this.Status)
fmt.Println("StatusCode : ", this.StatusCode)
fmt.Println("Error : ", this.Error)
for i, val := range this.Results {
fmt.Println(i, ":")
fmt.Println("\tAPNS Token", val[apns_token_key])
fmt.Println("\tStatus ", val[status_key])
fmt.Println("\tReg Token ", val[reg_token_key])
}
}
|
[
"func",
"(",
"this",
"*",
"ApnsBatchResponse",
")",
"PrintResults",
"(",
")",
"{",
"fmt",
".",
"Println",
"(",
"\"",
"\"",
",",
"this",
".",
"Status",
")",
"\n",
"fmt",
".",
"Println",
"(",
"\"",
"\"",
",",
"this",
".",
"StatusCode",
")",
"\n",
"fmt",
".",
"Println",
"(",
"\"",
"\"",
",",
"this",
".",
"Error",
")",
"\n",
"for",
"i",
",",
"val",
":=",
"range",
"this",
".",
"Results",
"{",
"fmt",
".",
"Println",
"(",
"i",
",",
"\"",
"\"",
")",
"\n",
"fmt",
".",
"Println",
"(",
"\"",
"\\t",
"\"",
",",
"val",
"[",
"apns_token_key",
"]",
")",
"\n",
"fmt",
".",
"Println",
"(",
"\"",
"\\t",
"\"",
",",
"val",
"[",
"status_key",
"]",
")",
"\n",
"fmt",
".",
"Println",
"(",
"\"",
"\\t",
"\"",
",",
"val",
"[",
"reg_token_key",
"]",
")",
"\n",
"}",
"\n",
"}"
] |
// PrintResults prints ApnsBatchResponse, for faster debugging
|
[
"PrintResults",
"prints",
"ApnsBatchResponse",
"for",
"faster",
"debugging"
] |
28fff9381d17f35619309c7a5ada41d26030d976
|
https://github.com/NaySoftware/go-fcm/blob/28fff9381d17f35619309c7a5ada41d26030d976/instanceid.go#L445-L455
|
144,521 |
kavu/go_reuseport
|
reuseport.go
|
Listen
|
func Listen(proto, addr string) (l net.Listener, err error) {
return NewReusablePortListener(proto, addr)
}
|
go
|
func Listen(proto, addr string) (l net.Listener, err error) {
return NewReusablePortListener(proto, addr)
}
|
[
"func",
"Listen",
"(",
"proto",
",",
"addr",
"string",
")",
"(",
"l",
"net",
".",
"Listener",
",",
"err",
"error",
")",
"{",
"return",
"NewReusablePortListener",
"(",
"proto",
",",
"addr",
")",
"\n",
"}"
] |
// Listen function is an alias for NewReusablePortListener.
|
[
"Listen",
"function",
"is",
"an",
"alias",
"for",
"NewReusablePortListener",
"."
] |
1f6171f327ed3893406d2a802c563390993c4bb5
|
https://github.com/kavu/go_reuseport/blob/1f6171f327ed3893406d2a802c563390993c4bb5/reuseport.go#L43-L45
|
144,522 |
kavu/go_reuseport
|
reuseport.go
|
ListenPacket
|
func ListenPacket(proto, addr string) (l net.PacketConn, err error) {
return NewReusablePortPacketConn(proto, addr)
}
|
go
|
func ListenPacket(proto, addr string) (l net.PacketConn, err error) {
return NewReusablePortPacketConn(proto, addr)
}
|
[
"func",
"ListenPacket",
"(",
"proto",
",",
"addr",
"string",
")",
"(",
"l",
"net",
".",
"PacketConn",
",",
"err",
"error",
")",
"{",
"return",
"NewReusablePortPacketConn",
"(",
"proto",
",",
"addr",
")",
"\n",
"}"
] |
// ListenPacket is an alias for NewReusablePortPacketConn.
|
[
"ListenPacket",
"is",
"an",
"alias",
"for",
"NewReusablePortPacketConn",
"."
] |
1f6171f327ed3893406d2a802c563390993c4bb5
|
https://github.com/kavu/go_reuseport/blob/1f6171f327ed3893406d2a802c563390993c4bb5/reuseport.go#L48-L50
|
144,523 |
kavu/go_reuseport
|
udp.go
|
NewReusablePortPacketConn
|
func NewReusablePortPacketConn(proto, addr string) (l net.PacketConn, err error) {
var (
soType, fd int
file *os.File
sockaddr syscall.Sockaddr
)
if sockaddr, soType, err = getSockaddr(proto, addr); err != nil {
return nil, err
}
syscall.ForkLock.RLock()
fd, err = syscall.Socket(soType, syscall.SOCK_DGRAM, syscall.IPPROTO_UDP)
if err == nil {
syscall.CloseOnExec(fd)
}
syscall.ForkLock.RUnlock()
if err != nil {
syscall.Close(fd)
return nil, err
}
defer func() {
if err != nil {
syscall.Close(fd)
}
}()
if err = syscall.SetsockoptInt(fd, syscall.SOL_SOCKET, syscall.SO_REUSEADDR, 1); err != nil {
return nil, err
}
if err = syscall.SetsockoptInt(fd, syscall.SOL_SOCKET, reusePort, 1); err != nil {
return nil, err
}
if err = syscall.SetsockoptInt(fd, syscall.SOL_SOCKET, syscall.SO_BROADCAST, 1); err != nil {
return nil, err
}
if err = syscall.Bind(fd, sockaddr); err != nil {
return nil, err
}
file = os.NewFile(uintptr(fd), getSocketFileName(proto, addr))
if l, err = net.FilePacketConn(file); err != nil {
return nil, err
}
if err = file.Close(); err != nil {
return nil, err
}
return l, err
}
|
go
|
func NewReusablePortPacketConn(proto, addr string) (l net.PacketConn, err error) {
var (
soType, fd int
file *os.File
sockaddr syscall.Sockaddr
)
if sockaddr, soType, err = getSockaddr(proto, addr); err != nil {
return nil, err
}
syscall.ForkLock.RLock()
fd, err = syscall.Socket(soType, syscall.SOCK_DGRAM, syscall.IPPROTO_UDP)
if err == nil {
syscall.CloseOnExec(fd)
}
syscall.ForkLock.RUnlock()
if err != nil {
syscall.Close(fd)
return nil, err
}
defer func() {
if err != nil {
syscall.Close(fd)
}
}()
if err = syscall.SetsockoptInt(fd, syscall.SOL_SOCKET, syscall.SO_REUSEADDR, 1); err != nil {
return nil, err
}
if err = syscall.SetsockoptInt(fd, syscall.SOL_SOCKET, reusePort, 1); err != nil {
return nil, err
}
if err = syscall.SetsockoptInt(fd, syscall.SOL_SOCKET, syscall.SO_BROADCAST, 1); err != nil {
return nil, err
}
if err = syscall.Bind(fd, sockaddr); err != nil {
return nil, err
}
file = os.NewFile(uintptr(fd), getSocketFileName(proto, addr))
if l, err = net.FilePacketConn(file); err != nil {
return nil, err
}
if err = file.Close(); err != nil {
return nil, err
}
return l, err
}
|
[
"func",
"NewReusablePortPacketConn",
"(",
"proto",
",",
"addr",
"string",
")",
"(",
"l",
"net",
".",
"PacketConn",
",",
"err",
"error",
")",
"{",
"var",
"(",
"soType",
",",
"fd",
"int",
"\n",
"file",
"*",
"os",
".",
"File",
"\n",
"sockaddr",
"syscall",
".",
"Sockaddr",
"\n",
")",
"\n\n",
"if",
"sockaddr",
",",
"soType",
",",
"err",
"=",
"getSockaddr",
"(",
"proto",
",",
"addr",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"syscall",
".",
"ForkLock",
".",
"RLock",
"(",
")",
"\n",
"fd",
",",
"err",
"=",
"syscall",
".",
"Socket",
"(",
"soType",
",",
"syscall",
".",
"SOCK_DGRAM",
",",
"syscall",
".",
"IPPROTO_UDP",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"syscall",
".",
"CloseOnExec",
"(",
"fd",
")",
"\n",
"}",
"\n",
"syscall",
".",
"ForkLock",
".",
"RUnlock",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"syscall",
".",
"Close",
"(",
"fd",
")",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"defer",
"func",
"(",
")",
"{",
"if",
"err",
"!=",
"nil",
"{",
"syscall",
".",
"Close",
"(",
"fd",
")",
"\n",
"}",
"\n",
"}",
"(",
")",
"\n\n",
"if",
"err",
"=",
"syscall",
".",
"SetsockoptInt",
"(",
"fd",
",",
"syscall",
".",
"SOL_SOCKET",
",",
"syscall",
".",
"SO_REUSEADDR",
",",
"1",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"err",
"=",
"syscall",
".",
"SetsockoptInt",
"(",
"fd",
",",
"syscall",
".",
"SOL_SOCKET",
",",
"reusePort",
",",
"1",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"err",
"=",
"syscall",
".",
"SetsockoptInt",
"(",
"fd",
",",
"syscall",
".",
"SOL_SOCKET",
",",
"syscall",
".",
"SO_BROADCAST",
",",
"1",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"err",
"=",
"syscall",
".",
"Bind",
"(",
"fd",
",",
"sockaddr",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"file",
"=",
"os",
".",
"NewFile",
"(",
"uintptr",
"(",
"fd",
")",
",",
"getSocketFileName",
"(",
"proto",
",",
"addr",
")",
")",
"\n",
"if",
"l",
",",
"err",
"=",
"net",
".",
"FilePacketConn",
"(",
"file",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"err",
"=",
"file",
".",
"Close",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"l",
",",
"err",
"\n",
"}"
] |
// NewReusablePortPacketConn returns net.FilePacketConn that created from
// a file discriptor for a socket with SO_REUSEPORT option.
|
[
"NewReusablePortPacketConn",
"returns",
"net",
".",
"FilePacketConn",
"that",
"created",
"from",
"a",
"file",
"discriptor",
"for",
"a",
"socket",
"with",
"SO_REUSEPORT",
"option",
"."
] |
1f6171f327ed3893406d2a802c563390993c4bb5
|
https://github.com/kavu/go_reuseport/blob/1f6171f327ed3893406d2a802c563390993c4bb5/udp.go#L93-L147
|
144,524 |
kavu/go_reuseport
|
tcp.go
|
NewReusablePortListener
|
func NewReusablePortListener(proto, addr string) (l net.Listener, err error) {
var (
soType, fd int
file *os.File
sockaddr syscall.Sockaddr
)
if sockaddr, soType, err = getSockaddr(proto, addr); err != nil {
return nil, err
}
syscall.ForkLock.RLock()
if fd, err = syscall.Socket(soType, syscall.SOCK_STREAM, syscall.IPPROTO_TCP); err != nil {
syscall.ForkLock.RUnlock()
return nil, err
}
syscall.ForkLock.RUnlock()
if err = syscall.SetsockoptInt(fd, syscall.SOL_SOCKET, syscall.SO_REUSEADDR, 1); err != nil {
syscall.Close(fd)
return nil, err
}
if err = syscall.SetsockoptInt(fd, syscall.SOL_SOCKET, reusePort, 1); err != nil {
syscall.Close(fd)
return nil, err
}
if err = syscall.Bind(fd, sockaddr); err != nil {
syscall.Close(fd)
return nil, err
}
// Set backlog size to the maximum
if err = syscall.Listen(fd, listenerBacklogMaxSize); err != nil {
syscall.Close(fd)
return nil, err
}
file = os.NewFile(uintptr(fd), getSocketFileName(proto, addr))
if l, err = net.FileListener(file); err != nil {
file.Close()
return nil, err
}
if err = file.Close(); err != nil {
return nil, err
}
return l, err
}
|
go
|
func NewReusablePortListener(proto, addr string) (l net.Listener, err error) {
var (
soType, fd int
file *os.File
sockaddr syscall.Sockaddr
)
if sockaddr, soType, err = getSockaddr(proto, addr); err != nil {
return nil, err
}
syscall.ForkLock.RLock()
if fd, err = syscall.Socket(soType, syscall.SOCK_STREAM, syscall.IPPROTO_TCP); err != nil {
syscall.ForkLock.RUnlock()
return nil, err
}
syscall.ForkLock.RUnlock()
if err = syscall.SetsockoptInt(fd, syscall.SOL_SOCKET, syscall.SO_REUSEADDR, 1); err != nil {
syscall.Close(fd)
return nil, err
}
if err = syscall.SetsockoptInt(fd, syscall.SOL_SOCKET, reusePort, 1); err != nil {
syscall.Close(fd)
return nil, err
}
if err = syscall.Bind(fd, sockaddr); err != nil {
syscall.Close(fd)
return nil, err
}
// Set backlog size to the maximum
if err = syscall.Listen(fd, listenerBacklogMaxSize); err != nil {
syscall.Close(fd)
return nil, err
}
file = os.NewFile(uintptr(fd), getSocketFileName(proto, addr))
if l, err = net.FileListener(file); err != nil {
file.Close()
return nil, err
}
if err = file.Close(); err != nil {
return nil, err
}
return l, err
}
|
[
"func",
"NewReusablePortListener",
"(",
"proto",
",",
"addr",
"string",
")",
"(",
"l",
"net",
".",
"Listener",
",",
"err",
"error",
")",
"{",
"var",
"(",
"soType",
",",
"fd",
"int",
"\n",
"file",
"*",
"os",
".",
"File",
"\n",
"sockaddr",
"syscall",
".",
"Sockaddr",
"\n",
")",
"\n\n",
"if",
"sockaddr",
",",
"soType",
",",
"err",
"=",
"getSockaddr",
"(",
"proto",
",",
"addr",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"syscall",
".",
"ForkLock",
".",
"RLock",
"(",
")",
"\n",
"if",
"fd",
",",
"err",
"=",
"syscall",
".",
"Socket",
"(",
"soType",
",",
"syscall",
".",
"SOCK_STREAM",
",",
"syscall",
".",
"IPPROTO_TCP",
")",
";",
"err",
"!=",
"nil",
"{",
"syscall",
".",
"ForkLock",
".",
"RUnlock",
"(",
")",
"\n\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"syscall",
".",
"ForkLock",
".",
"RUnlock",
"(",
")",
"\n\n",
"if",
"err",
"=",
"syscall",
".",
"SetsockoptInt",
"(",
"fd",
",",
"syscall",
".",
"SOL_SOCKET",
",",
"syscall",
".",
"SO_REUSEADDR",
",",
"1",
")",
";",
"err",
"!=",
"nil",
"{",
"syscall",
".",
"Close",
"(",
"fd",
")",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"err",
"=",
"syscall",
".",
"SetsockoptInt",
"(",
"fd",
",",
"syscall",
".",
"SOL_SOCKET",
",",
"reusePort",
",",
"1",
")",
";",
"err",
"!=",
"nil",
"{",
"syscall",
".",
"Close",
"(",
"fd",
")",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"err",
"=",
"syscall",
".",
"Bind",
"(",
"fd",
",",
"sockaddr",
")",
";",
"err",
"!=",
"nil",
"{",
"syscall",
".",
"Close",
"(",
"fd",
")",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"// Set backlog size to the maximum",
"if",
"err",
"=",
"syscall",
".",
"Listen",
"(",
"fd",
",",
"listenerBacklogMaxSize",
")",
";",
"err",
"!=",
"nil",
"{",
"syscall",
".",
"Close",
"(",
"fd",
")",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"file",
"=",
"os",
".",
"NewFile",
"(",
"uintptr",
"(",
"fd",
")",
",",
"getSocketFileName",
"(",
"proto",
",",
"addr",
")",
")",
"\n",
"if",
"l",
",",
"err",
"=",
"net",
".",
"FileListener",
"(",
"file",
")",
";",
"err",
"!=",
"nil",
"{",
"file",
".",
"Close",
"(",
")",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"err",
"=",
"file",
".",
"Close",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"l",
",",
"err",
"\n",
"}"
] |
// NewReusablePortListener returns net.FileListener that created from
// a file discriptor for a socket with SO_REUSEPORT option.
|
[
"NewReusablePortListener",
"returns",
"net",
".",
"FileListener",
"that",
"created",
"from",
"a",
"file",
"discriptor",
"for",
"a",
"socket",
"with",
"SO_REUSEPORT",
"option",
"."
] |
1f6171f327ed3893406d2a802c563390993c4bb5
|
https://github.com/kavu/go_reuseport/blob/1f6171f327ed3893406d2a802c563390993c4bb5/tcp.go#L96-L147
|
144,525 |
sohlich/elogrus
|
hook.go
|
Fire
|
func (hook *ElasticHook) Fire(entry *logrus.Entry) error {
return hook.fireFunc(entry, hook, hook.index())
}
|
go
|
func (hook *ElasticHook) Fire(entry *logrus.Entry) error {
return hook.fireFunc(entry, hook, hook.index())
}
|
[
"func",
"(",
"hook",
"*",
"ElasticHook",
")",
"Fire",
"(",
"entry",
"*",
"logrus",
".",
"Entry",
")",
"error",
"{",
"return",
"hook",
".",
"fireFunc",
"(",
"entry",
",",
"hook",
",",
"hook",
".",
"index",
"(",
")",
")",
"\n",
"}"
] |
// Fire is required to implement
// Logrus hook
|
[
"Fire",
"is",
"required",
"to",
"implement",
"Logrus",
"hook"
] |
1fa29e2f2009c129693c7079e5f6361bfbd34080
|
https://github.com/sohlich/elogrus/blob/1fa29e2f2009c129693c7079e5f6361bfbd34080/hook.go#L125-L127
|
144,526 |
adrianmo/go-nmea
|
parser.go
|
AssertType
|
func (p *parser) AssertType(typ string) {
if p.Type != typ {
p.SetErr("type", p.Type)
}
}
|
go
|
func (p *parser) AssertType(typ string) {
if p.Type != typ {
p.SetErr("type", p.Type)
}
}
|
[
"func",
"(",
"p",
"*",
"parser",
")",
"AssertType",
"(",
"typ",
"string",
")",
"{",
"if",
"p",
".",
"Type",
"!=",
"typ",
"{",
"p",
".",
"SetErr",
"(",
"\"",
"\"",
",",
"p",
".",
"Type",
")",
"\n",
"}",
"\n",
"}"
] |
// AssertType makes sure the sentence's type matches the provided one.
|
[
"AssertType",
"makes",
"sure",
"the",
"sentence",
"s",
"type",
"matches",
"the",
"provided",
"one",
"."
] |
7572fbeb90aaa0bd3d1dcb674938ffbc0a943123
|
https://github.com/adrianmo/go-nmea/blob/7572fbeb90aaa0bd3d1dcb674938ffbc0a943123/parser.go#L21-L25
|
144,527 |
adrianmo/go-nmea
|
parser.go
|
SetErr
|
func (p *parser) SetErr(context, value string) {
if p.err == nil {
p.err = fmt.Errorf("nmea: %s invalid %s: %s", p.Prefix(), context, value)
}
}
|
go
|
func (p *parser) SetErr(context, value string) {
if p.err == nil {
p.err = fmt.Errorf("nmea: %s invalid %s: %s", p.Prefix(), context, value)
}
}
|
[
"func",
"(",
"p",
"*",
"parser",
")",
"SetErr",
"(",
"context",
",",
"value",
"string",
")",
"{",
"if",
"p",
".",
"err",
"==",
"nil",
"{",
"p",
".",
"err",
"=",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"p",
".",
"Prefix",
"(",
")",
",",
"context",
",",
"value",
")",
"\n",
"}",
"\n",
"}"
] |
// SetErr assigns an error. Calling this method has no
// effect if there is already an error.
|
[
"SetErr",
"assigns",
"an",
"error",
".",
"Calling",
"this",
"method",
"has",
"no",
"effect",
"if",
"there",
"is",
"already",
"an",
"error",
"."
] |
7572fbeb90aaa0bd3d1dcb674938ffbc0a943123
|
https://github.com/adrianmo/go-nmea/blob/7572fbeb90aaa0bd3d1dcb674938ffbc0a943123/parser.go#L34-L38
|
144,528 |
adrianmo/go-nmea
|
parser.go
|
String
|
func (p *parser) String(i int, context string) string {
if p.err != nil {
return ""
}
if i < 0 || i >= len(p.Fields) {
p.SetErr(context, "index out of range")
return ""
}
return p.Fields[i]
}
|
go
|
func (p *parser) String(i int, context string) string {
if p.err != nil {
return ""
}
if i < 0 || i >= len(p.Fields) {
p.SetErr(context, "index out of range")
return ""
}
return p.Fields[i]
}
|
[
"func",
"(",
"p",
"*",
"parser",
")",
"String",
"(",
"i",
"int",
",",
"context",
"string",
")",
"string",
"{",
"if",
"p",
".",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n",
"if",
"i",
"<",
"0",
"||",
"i",
">=",
"len",
"(",
"p",
".",
"Fields",
")",
"{",
"p",
".",
"SetErr",
"(",
"context",
",",
"\"",
"\"",
")",
"\n",
"return",
"\"",
"\"",
"\n",
"}",
"\n",
"return",
"p",
".",
"Fields",
"[",
"i",
"]",
"\n",
"}"
] |
// String returns the field value at the specified index.
|
[
"String",
"returns",
"the",
"field",
"value",
"at",
"the",
"specified",
"index",
"."
] |
7572fbeb90aaa0bd3d1dcb674938ffbc0a943123
|
https://github.com/adrianmo/go-nmea/blob/7572fbeb90aaa0bd3d1dcb674938ffbc0a943123/parser.go#L41-L50
|
144,529 |
adrianmo/go-nmea
|
parser.go
|
EnumString
|
func (p *parser) EnumString(i int, context string, options ...string) string {
s := p.String(i, context)
if p.err != nil || s == "" {
return ""
}
for _, o := range options {
if o == s {
return s
}
}
p.SetErr(context, s)
return ""
}
|
go
|
func (p *parser) EnumString(i int, context string, options ...string) string {
s := p.String(i, context)
if p.err != nil || s == "" {
return ""
}
for _, o := range options {
if o == s {
return s
}
}
p.SetErr(context, s)
return ""
}
|
[
"func",
"(",
"p",
"*",
"parser",
")",
"EnumString",
"(",
"i",
"int",
",",
"context",
"string",
",",
"options",
"...",
"string",
")",
"string",
"{",
"s",
":=",
"p",
".",
"String",
"(",
"i",
",",
"context",
")",
"\n",
"if",
"p",
".",
"err",
"!=",
"nil",
"||",
"s",
"==",
"\"",
"\"",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n",
"for",
"_",
",",
"o",
":=",
"range",
"options",
"{",
"if",
"o",
"==",
"s",
"{",
"return",
"s",
"\n",
"}",
"\n",
"}",
"\n",
"p",
".",
"SetErr",
"(",
"context",
",",
"s",
")",
"\n",
"return",
"\"",
"\"",
"\n",
"}"
] |
// EnumString returns the field value at the specified index.
// An error occurs if the value is not one of the options and not empty.
|
[
"EnumString",
"returns",
"the",
"field",
"value",
"at",
"the",
"specified",
"index",
".",
"An",
"error",
"occurs",
"if",
"the",
"value",
"is",
"not",
"one",
"of",
"the",
"options",
"and",
"not",
"empty",
"."
] |
7572fbeb90aaa0bd3d1dcb674938ffbc0a943123
|
https://github.com/adrianmo/go-nmea/blob/7572fbeb90aaa0bd3d1dcb674938ffbc0a943123/parser.go#L54-L66
|
144,530 |
adrianmo/go-nmea
|
parser.go
|
EnumChars
|
func (p *parser) EnumChars(i int, context string, options ...string) []string {
s := p.String(i, context)
if p.err != nil || s == "" {
return []string{}
}
strs := []string{}
for _, r := range s {
rs := string(r)
for _, o := range options {
if o == rs {
strs = append(strs, o)
break
}
}
}
if len(strs) != len(s) {
p.SetErr(context, s)
return []string{}
}
return strs
}
|
go
|
func (p *parser) EnumChars(i int, context string, options ...string) []string {
s := p.String(i, context)
if p.err != nil || s == "" {
return []string{}
}
strs := []string{}
for _, r := range s {
rs := string(r)
for _, o := range options {
if o == rs {
strs = append(strs, o)
break
}
}
}
if len(strs) != len(s) {
p.SetErr(context, s)
return []string{}
}
return strs
}
|
[
"func",
"(",
"p",
"*",
"parser",
")",
"EnumChars",
"(",
"i",
"int",
",",
"context",
"string",
",",
"options",
"...",
"string",
")",
"[",
"]",
"string",
"{",
"s",
":=",
"p",
".",
"String",
"(",
"i",
",",
"context",
")",
"\n",
"if",
"p",
".",
"err",
"!=",
"nil",
"||",
"s",
"==",
"\"",
"\"",
"{",
"return",
"[",
"]",
"string",
"{",
"}",
"\n",
"}",
"\n",
"strs",
":=",
"[",
"]",
"string",
"{",
"}",
"\n",
"for",
"_",
",",
"r",
":=",
"range",
"s",
"{",
"rs",
":=",
"string",
"(",
"r",
")",
"\n",
"for",
"_",
",",
"o",
":=",
"range",
"options",
"{",
"if",
"o",
"==",
"rs",
"{",
"strs",
"=",
"append",
"(",
"strs",
",",
"o",
")",
"\n",
"break",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"len",
"(",
"strs",
")",
"!=",
"len",
"(",
"s",
")",
"{",
"p",
".",
"SetErr",
"(",
"context",
",",
"s",
")",
"\n",
"return",
"[",
"]",
"string",
"{",
"}",
"\n",
"}",
"\n",
"return",
"strs",
"\n",
"}"
] |
// EnumChars returns an array of strings that are matched in the Mode field.
// It will only match the number of characters that are in the Mode field.
// If the value is empty, it will return an empty array
|
[
"EnumChars",
"returns",
"an",
"array",
"of",
"strings",
"that",
"are",
"matched",
"in",
"the",
"Mode",
"field",
".",
"It",
"will",
"only",
"match",
"the",
"number",
"of",
"characters",
"that",
"are",
"in",
"the",
"Mode",
"field",
".",
"If",
"the",
"value",
"is",
"empty",
"it",
"will",
"return",
"an",
"empty",
"array"
] |
7572fbeb90aaa0bd3d1dcb674938ffbc0a943123
|
https://github.com/adrianmo/go-nmea/blob/7572fbeb90aaa0bd3d1dcb674938ffbc0a943123/parser.go#L71-L92
|
144,531 |
adrianmo/go-nmea
|
parser.go
|
Int64
|
func (p *parser) Int64(i int, context string) int64 {
s := p.String(i, context)
if p.err != nil {
return 0
}
if s == "" {
return 0
}
v, err := strconv.ParseInt(s, 10, 64)
if err != nil {
p.SetErr(context, s)
}
return v
}
|
go
|
func (p *parser) Int64(i int, context string) int64 {
s := p.String(i, context)
if p.err != nil {
return 0
}
if s == "" {
return 0
}
v, err := strconv.ParseInt(s, 10, 64)
if err != nil {
p.SetErr(context, s)
}
return v
}
|
[
"func",
"(",
"p",
"*",
"parser",
")",
"Int64",
"(",
"i",
"int",
",",
"context",
"string",
")",
"int64",
"{",
"s",
":=",
"p",
".",
"String",
"(",
"i",
",",
"context",
")",
"\n",
"if",
"p",
".",
"err",
"!=",
"nil",
"{",
"return",
"0",
"\n",
"}",
"\n",
"if",
"s",
"==",
"\"",
"\"",
"{",
"return",
"0",
"\n",
"}",
"\n",
"v",
",",
"err",
":=",
"strconv",
".",
"ParseInt",
"(",
"s",
",",
"10",
",",
"64",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"p",
".",
"SetErr",
"(",
"context",
",",
"s",
")",
"\n",
"}",
"\n",
"return",
"v",
"\n",
"}"
] |
// Int64 returns the int64 value at the specified index.
// If the value is an empty string, 0 is returned.
|
[
"Int64",
"returns",
"the",
"int64",
"value",
"at",
"the",
"specified",
"index",
".",
"If",
"the",
"value",
"is",
"an",
"empty",
"string",
"0",
"is",
"returned",
"."
] |
7572fbeb90aaa0bd3d1dcb674938ffbc0a943123
|
https://github.com/adrianmo/go-nmea/blob/7572fbeb90aaa0bd3d1dcb674938ffbc0a943123/parser.go#L96-L109
|
144,532 |
adrianmo/go-nmea
|
parser.go
|
Float64
|
func (p *parser) Float64(i int, context string) float64 {
s := p.String(i, context)
if p.err != nil {
return 0
}
if s == "" {
return 0
}
v, err := strconv.ParseFloat(s, 64)
if err != nil {
p.SetErr(context, s)
}
return v
}
|
go
|
func (p *parser) Float64(i int, context string) float64 {
s := p.String(i, context)
if p.err != nil {
return 0
}
if s == "" {
return 0
}
v, err := strconv.ParseFloat(s, 64)
if err != nil {
p.SetErr(context, s)
}
return v
}
|
[
"func",
"(",
"p",
"*",
"parser",
")",
"Float64",
"(",
"i",
"int",
",",
"context",
"string",
")",
"float64",
"{",
"s",
":=",
"p",
".",
"String",
"(",
"i",
",",
"context",
")",
"\n",
"if",
"p",
".",
"err",
"!=",
"nil",
"{",
"return",
"0",
"\n",
"}",
"\n",
"if",
"s",
"==",
"\"",
"\"",
"{",
"return",
"0",
"\n",
"}",
"\n",
"v",
",",
"err",
":=",
"strconv",
".",
"ParseFloat",
"(",
"s",
",",
"64",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"p",
".",
"SetErr",
"(",
"context",
",",
"s",
")",
"\n",
"}",
"\n",
"return",
"v",
"\n",
"}"
] |
// Float64 returns the float64 value at the specified index.
// If the value is an empty string, 0 is returned.
|
[
"Float64",
"returns",
"the",
"float64",
"value",
"at",
"the",
"specified",
"index",
".",
"If",
"the",
"value",
"is",
"an",
"empty",
"string",
"0",
"is",
"returned",
"."
] |
7572fbeb90aaa0bd3d1dcb674938ffbc0a943123
|
https://github.com/adrianmo/go-nmea/blob/7572fbeb90aaa0bd3d1dcb674938ffbc0a943123/parser.go#L113-L126
|
144,533 |
adrianmo/go-nmea
|
parser.go
|
Time
|
func (p *parser) Time(i int, context string) Time {
s := p.String(i, context)
if p.err != nil {
return Time{}
}
v, err := ParseTime(s)
if err != nil {
p.SetErr(context, s)
}
return v
}
|
go
|
func (p *parser) Time(i int, context string) Time {
s := p.String(i, context)
if p.err != nil {
return Time{}
}
v, err := ParseTime(s)
if err != nil {
p.SetErr(context, s)
}
return v
}
|
[
"func",
"(",
"p",
"*",
"parser",
")",
"Time",
"(",
"i",
"int",
",",
"context",
"string",
")",
"Time",
"{",
"s",
":=",
"p",
".",
"String",
"(",
"i",
",",
"context",
")",
"\n",
"if",
"p",
".",
"err",
"!=",
"nil",
"{",
"return",
"Time",
"{",
"}",
"\n",
"}",
"\n",
"v",
",",
"err",
":=",
"ParseTime",
"(",
"s",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"p",
".",
"SetErr",
"(",
"context",
",",
"s",
")",
"\n",
"}",
"\n",
"return",
"v",
"\n",
"}"
] |
// Time returns the Time value at the specified index.
// If the value is empty, the Time is marked as invalid.
|
[
"Time",
"returns",
"the",
"Time",
"value",
"at",
"the",
"specified",
"index",
".",
"If",
"the",
"value",
"is",
"empty",
"the",
"Time",
"is",
"marked",
"as",
"invalid",
"."
] |
7572fbeb90aaa0bd3d1dcb674938ffbc0a943123
|
https://github.com/adrianmo/go-nmea/blob/7572fbeb90aaa0bd3d1dcb674938ffbc0a943123/parser.go#L130-L140
|
144,534 |
adrianmo/go-nmea
|
parser.go
|
Date
|
func (p *parser) Date(i int, context string) Date {
s := p.String(i, context)
if p.err != nil {
return Date{}
}
v, err := ParseDate(s)
if err != nil {
p.SetErr(context, s)
}
return v
}
|
go
|
func (p *parser) Date(i int, context string) Date {
s := p.String(i, context)
if p.err != nil {
return Date{}
}
v, err := ParseDate(s)
if err != nil {
p.SetErr(context, s)
}
return v
}
|
[
"func",
"(",
"p",
"*",
"parser",
")",
"Date",
"(",
"i",
"int",
",",
"context",
"string",
")",
"Date",
"{",
"s",
":=",
"p",
".",
"String",
"(",
"i",
",",
"context",
")",
"\n",
"if",
"p",
".",
"err",
"!=",
"nil",
"{",
"return",
"Date",
"{",
"}",
"\n",
"}",
"\n",
"v",
",",
"err",
":=",
"ParseDate",
"(",
"s",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"p",
".",
"SetErr",
"(",
"context",
",",
"s",
")",
"\n",
"}",
"\n",
"return",
"v",
"\n",
"}"
] |
// Date returns the Date value at the specified index.
// If the value is empty, the Date is marked as invalid.
|
[
"Date",
"returns",
"the",
"Date",
"value",
"at",
"the",
"specified",
"index",
".",
"If",
"the",
"value",
"is",
"empty",
"the",
"Date",
"is",
"marked",
"as",
"invalid",
"."
] |
7572fbeb90aaa0bd3d1dcb674938ffbc0a943123
|
https://github.com/adrianmo/go-nmea/blob/7572fbeb90aaa0bd3d1dcb674938ffbc0a943123/parser.go#L144-L154
|
144,535 |
adrianmo/go-nmea
|
parser.go
|
LatLong
|
func (p *parser) LatLong(i, j int, context string) float64 {
a := p.String(i, context)
b := p.String(j, context)
if p.err != nil {
return 0
}
s := fmt.Sprintf("%s %s", a, b)
v, err := ParseLatLong(s)
if err != nil {
p.SetErr(context, err.Error())
}
return v
}
|
go
|
func (p *parser) LatLong(i, j int, context string) float64 {
a := p.String(i, context)
b := p.String(j, context)
if p.err != nil {
return 0
}
s := fmt.Sprintf("%s %s", a, b)
v, err := ParseLatLong(s)
if err != nil {
p.SetErr(context, err.Error())
}
return v
}
|
[
"func",
"(",
"p",
"*",
"parser",
")",
"LatLong",
"(",
"i",
",",
"j",
"int",
",",
"context",
"string",
")",
"float64",
"{",
"a",
":=",
"p",
".",
"String",
"(",
"i",
",",
"context",
")",
"\n",
"b",
":=",
"p",
".",
"String",
"(",
"j",
",",
"context",
")",
"\n",
"if",
"p",
".",
"err",
"!=",
"nil",
"{",
"return",
"0",
"\n",
"}",
"\n",
"s",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"a",
",",
"b",
")",
"\n",
"v",
",",
"err",
":=",
"ParseLatLong",
"(",
"s",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"p",
".",
"SetErr",
"(",
"context",
",",
"err",
".",
"Error",
"(",
")",
")",
"\n",
"}",
"\n",
"return",
"v",
"\n",
"}"
] |
// LatLong returns the coordinate value of the specified fields.
|
[
"LatLong",
"returns",
"the",
"coordinate",
"value",
"of",
"the",
"specified",
"fields",
"."
] |
7572fbeb90aaa0bd3d1dcb674938ffbc0a943123
|
https://github.com/adrianmo/go-nmea/blob/7572fbeb90aaa0bd3d1dcb674938ffbc0a943123/parser.go#L157-L169
|
144,536 |
adrianmo/go-nmea
|
parser.go
|
SixBitASCIIArmour
|
func (p *parser) SixBitASCIIArmour(i int, fillBits int, context string) []byte {
if p.err != nil {
return nil
}
if fillBits < 0 || fillBits >= 6 {
p.SetErr(context, "fill bits")
return nil
}
payload := []byte(p.String(i, "encoded payload"))
numBits := len(payload)*6 - fillBits
if numBits < 0 {
p.SetErr(context, "num bits")
return nil
}
result := make([]byte, numBits)
resultIndex := 0
for _, v := range payload {
if v < 48 || v >= 120 {
p.SetErr(context, "data byte")
return nil
}
d := v - 48
if d > 40 {
d -= 8
}
for i := 5; i >= 0 && resultIndex < len(result); i-- {
result[resultIndex] = (d >> uint(i)) & 1
resultIndex++
}
}
return result
}
|
go
|
func (p *parser) SixBitASCIIArmour(i int, fillBits int, context string) []byte {
if p.err != nil {
return nil
}
if fillBits < 0 || fillBits >= 6 {
p.SetErr(context, "fill bits")
return nil
}
payload := []byte(p.String(i, "encoded payload"))
numBits := len(payload)*6 - fillBits
if numBits < 0 {
p.SetErr(context, "num bits")
return nil
}
result := make([]byte, numBits)
resultIndex := 0
for _, v := range payload {
if v < 48 || v >= 120 {
p.SetErr(context, "data byte")
return nil
}
d := v - 48
if d > 40 {
d -= 8
}
for i := 5; i >= 0 && resultIndex < len(result); i-- {
result[resultIndex] = (d >> uint(i)) & 1
resultIndex++
}
}
return result
}
|
[
"func",
"(",
"p",
"*",
"parser",
")",
"SixBitASCIIArmour",
"(",
"i",
"int",
",",
"fillBits",
"int",
",",
"context",
"string",
")",
"[",
"]",
"byte",
"{",
"if",
"p",
".",
"err",
"!=",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"if",
"fillBits",
"<",
"0",
"||",
"fillBits",
">=",
"6",
"{",
"p",
".",
"SetErr",
"(",
"context",
",",
"\"",
"\"",
")",
"\n",
"return",
"nil",
"\n",
"}",
"\n\n",
"payload",
":=",
"[",
"]",
"byte",
"(",
"p",
".",
"String",
"(",
"i",
",",
"\"",
"\"",
")",
")",
"\n",
"numBits",
":=",
"len",
"(",
"payload",
")",
"*",
"6",
"-",
"fillBits",
"\n\n",
"if",
"numBits",
"<",
"0",
"{",
"p",
".",
"SetErr",
"(",
"context",
",",
"\"",
"\"",
")",
"\n",
"return",
"nil",
"\n",
"}",
"\n\n",
"result",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"numBits",
")",
"\n",
"resultIndex",
":=",
"0",
"\n\n",
"for",
"_",
",",
"v",
":=",
"range",
"payload",
"{",
"if",
"v",
"<",
"48",
"||",
"v",
">=",
"120",
"{",
"p",
".",
"SetErr",
"(",
"context",
",",
"\"",
"\"",
")",
"\n",
"return",
"nil",
"\n",
"}",
"\n\n",
"d",
":=",
"v",
"-",
"48",
"\n",
"if",
"d",
">",
"40",
"{",
"d",
"-=",
"8",
"\n",
"}",
"\n\n",
"for",
"i",
":=",
"5",
";",
"i",
">=",
"0",
"&&",
"resultIndex",
"<",
"len",
"(",
"result",
")",
";",
"i",
"--",
"{",
"result",
"[",
"resultIndex",
"]",
"=",
"(",
"d",
">>",
"uint",
"(",
"i",
")",
")",
"&",
"1",
"\n",
"resultIndex",
"++",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"result",
"\n",
"}"
] |
// SixBitASCIIArmour decodes the 6-bit ascii armor used for VDM and VDO messages
|
[
"SixBitASCIIArmour",
"decodes",
"the",
"6",
"-",
"bit",
"ascii",
"armor",
"used",
"for",
"VDM",
"and",
"VDO",
"messages"
] |
7572fbeb90aaa0bd3d1dcb674938ffbc0a943123
|
https://github.com/adrianmo/go-nmea/blob/7572fbeb90aaa0bd3d1dcb674938ffbc0a943123/parser.go#L172-L210
|
144,537 |
adrianmo/go-nmea
|
gsa.go
|
newGSA
|
func newGSA(s BaseSentence) (GSA, error) {
p := newParser(s)
p.AssertType(TypeGSA)
m := GSA{
BaseSentence: s,
Mode: p.EnumString(0, "selection mode", Auto, Manual),
FixType: p.EnumString(1, "fix type", FixNone, Fix2D, Fix3D),
}
// Satellites in view.
for i := 2; i < 14; i++ {
if v := p.String(i, "satellite in view"); v != "" {
m.SV = append(m.SV, v)
}
}
// Dilution of precision.
m.PDOP = p.Float64(14, "pdop")
m.HDOP = p.Float64(15, "hdop")
m.VDOP = p.Float64(16, "vdop")
return m, p.Err()
}
|
go
|
func newGSA(s BaseSentence) (GSA, error) {
p := newParser(s)
p.AssertType(TypeGSA)
m := GSA{
BaseSentence: s,
Mode: p.EnumString(0, "selection mode", Auto, Manual),
FixType: p.EnumString(1, "fix type", FixNone, Fix2D, Fix3D),
}
// Satellites in view.
for i := 2; i < 14; i++ {
if v := p.String(i, "satellite in view"); v != "" {
m.SV = append(m.SV, v)
}
}
// Dilution of precision.
m.PDOP = p.Float64(14, "pdop")
m.HDOP = p.Float64(15, "hdop")
m.VDOP = p.Float64(16, "vdop")
return m, p.Err()
}
|
[
"func",
"newGSA",
"(",
"s",
"BaseSentence",
")",
"(",
"GSA",
",",
"error",
")",
"{",
"p",
":=",
"newParser",
"(",
"s",
")",
"\n",
"p",
".",
"AssertType",
"(",
"TypeGSA",
")",
"\n",
"m",
":=",
"GSA",
"{",
"BaseSentence",
":",
"s",
",",
"Mode",
":",
"p",
".",
"EnumString",
"(",
"0",
",",
"\"",
"\"",
",",
"Auto",
",",
"Manual",
")",
",",
"FixType",
":",
"p",
".",
"EnumString",
"(",
"1",
",",
"\"",
"\"",
",",
"FixNone",
",",
"Fix2D",
",",
"Fix3D",
")",
",",
"}",
"\n",
"// Satellites in view.",
"for",
"i",
":=",
"2",
";",
"i",
"<",
"14",
";",
"i",
"++",
"{",
"if",
"v",
":=",
"p",
".",
"String",
"(",
"i",
",",
"\"",
"\"",
")",
";",
"v",
"!=",
"\"",
"\"",
"{",
"m",
".",
"SV",
"=",
"append",
"(",
"m",
".",
"SV",
",",
"v",
")",
"\n",
"}",
"\n",
"}",
"\n",
"// Dilution of precision.",
"m",
".",
"PDOP",
"=",
"p",
".",
"Float64",
"(",
"14",
",",
"\"",
"\"",
")",
"\n",
"m",
".",
"HDOP",
"=",
"p",
".",
"Float64",
"(",
"15",
",",
"\"",
"\"",
")",
"\n",
"m",
".",
"VDOP",
"=",
"p",
".",
"Float64",
"(",
"16",
",",
"\"",
"\"",
")",
"\n",
"return",
"m",
",",
"p",
".",
"Err",
"(",
")",
"\n",
"}"
] |
// newGSA parses the GSA sentence into this struct.
|
[
"newGSA",
"parses",
"the",
"GSA",
"sentence",
"into",
"this",
"struct",
"."
] |
7572fbeb90aaa0bd3d1dcb674938ffbc0a943123
|
https://github.com/adrianmo/go-nmea/blob/7572fbeb90aaa0bd3d1dcb674938ffbc0a943123/gsa.go#L31-L50
|
144,538 |
adrianmo/go-nmea
|
sentence.go
|
parseSentence
|
func parseSentence(raw string) (BaseSentence, error) {
startIndex := strings.IndexAny(raw, SentenceStart+SentenceStartEncapsulated)
if startIndex != 0 {
return BaseSentence{}, fmt.Errorf("nmea: sentence does not start with a '$' or '!'")
}
sumSepIndex := strings.Index(raw, ChecksumSep)
if sumSepIndex == -1 {
return BaseSentence{}, fmt.Errorf("nmea: sentence does not contain checksum separator")
}
var (
fieldsRaw = raw[startIndex+1 : sumSepIndex]
fields = strings.Split(fieldsRaw, FieldSep)
checksumRaw = strings.ToUpper(raw[sumSepIndex+1:])
checksum = xorChecksum(fieldsRaw)
)
// Validate the checksum
if checksum != checksumRaw {
return BaseSentence{}, fmt.Errorf(
"nmea: sentence checksum mismatch [%s != %s]", checksum, checksumRaw)
}
talker, typ := parsePrefix(fields[0])
return BaseSentence{
Talker: talker,
Type: typ,
Fields: fields[1:],
Checksum: checksumRaw,
Raw: raw,
}, nil
}
|
go
|
func parseSentence(raw string) (BaseSentence, error) {
startIndex := strings.IndexAny(raw, SentenceStart+SentenceStartEncapsulated)
if startIndex != 0 {
return BaseSentence{}, fmt.Errorf("nmea: sentence does not start with a '$' or '!'")
}
sumSepIndex := strings.Index(raw, ChecksumSep)
if sumSepIndex == -1 {
return BaseSentence{}, fmt.Errorf("nmea: sentence does not contain checksum separator")
}
var (
fieldsRaw = raw[startIndex+1 : sumSepIndex]
fields = strings.Split(fieldsRaw, FieldSep)
checksumRaw = strings.ToUpper(raw[sumSepIndex+1:])
checksum = xorChecksum(fieldsRaw)
)
// Validate the checksum
if checksum != checksumRaw {
return BaseSentence{}, fmt.Errorf(
"nmea: sentence checksum mismatch [%s != %s]", checksum, checksumRaw)
}
talker, typ := parsePrefix(fields[0])
return BaseSentence{
Talker: talker,
Type: typ,
Fields: fields[1:],
Checksum: checksumRaw,
Raw: raw,
}, nil
}
|
[
"func",
"parseSentence",
"(",
"raw",
"string",
")",
"(",
"BaseSentence",
",",
"error",
")",
"{",
"startIndex",
":=",
"strings",
".",
"IndexAny",
"(",
"raw",
",",
"SentenceStart",
"+",
"SentenceStartEncapsulated",
")",
"\n",
"if",
"startIndex",
"!=",
"0",
"{",
"return",
"BaseSentence",
"{",
"}",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"sumSepIndex",
":=",
"strings",
".",
"Index",
"(",
"raw",
",",
"ChecksumSep",
")",
"\n",
"if",
"sumSepIndex",
"==",
"-",
"1",
"{",
"return",
"BaseSentence",
"{",
"}",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"var",
"(",
"fieldsRaw",
"=",
"raw",
"[",
"startIndex",
"+",
"1",
":",
"sumSepIndex",
"]",
"\n",
"fields",
"=",
"strings",
".",
"Split",
"(",
"fieldsRaw",
",",
"FieldSep",
")",
"\n",
"checksumRaw",
"=",
"strings",
".",
"ToUpper",
"(",
"raw",
"[",
"sumSepIndex",
"+",
"1",
":",
"]",
")",
"\n",
"checksum",
"=",
"xorChecksum",
"(",
"fieldsRaw",
")",
"\n",
")",
"\n",
"// Validate the checksum",
"if",
"checksum",
"!=",
"checksumRaw",
"{",
"return",
"BaseSentence",
"{",
"}",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"checksum",
",",
"checksumRaw",
")",
"\n",
"}",
"\n",
"talker",
",",
"typ",
":=",
"parsePrefix",
"(",
"fields",
"[",
"0",
"]",
")",
"\n",
"return",
"BaseSentence",
"{",
"Talker",
":",
"talker",
",",
"Type",
":",
"typ",
",",
"Fields",
":",
"fields",
"[",
"1",
":",
"]",
",",
"Checksum",
":",
"checksumRaw",
",",
"Raw",
":",
"raw",
",",
"}",
",",
"nil",
"\n",
"}"
] |
// parseSentence parses a raw message into it's fields
|
[
"parseSentence",
"parses",
"a",
"raw",
"message",
"into",
"it",
"s",
"fields"
] |
7572fbeb90aaa0bd3d1dcb674938ffbc0a943123
|
https://github.com/adrianmo/go-nmea/blob/7572fbeb90aaa0bd3d1dcb674938ffbc0a943123/sentence.go#L58-L86
|
144,539 |
adrianmo/go-nmea
|
sentence.go
|
parsePrefix
|
func parsePrefix(s string) (string, string) {
if strings.HasPrefix(s, "P") {
return "P", s[1:]
}
if len(s) < 2 {
return s, ""
}
return s[:2], s[2:]
}
|
go
|
func parsePrefix(s string) (string, string) {
if strings.HasPrefix(s, "P") {
return "P", s[1:]
}
if len(s) < 2 {
return s, ""
}
return s[:2], s[2:]
}
|
[
"func",
"parsePrefix",
"(",
"s",
"string",
")",
"(",
"string",
",",
"string",
")",
"{",
"if",
"strings",
".",
"HasPrefix",
"(",
"s",
",",
"\"",
"\"",
")",
"{",
"return",
"\"",
"\"",
",",
"s",
"[",
"1",
":",
"]",
"\n",
"}",
"\n",
"if",
"len",
"(",
"s",
")",
"<",
"2",
"{",
"return",
"s",
",",
"\"",
"\"",
"\n",
"}",
"\n",
"return",
"s",
"[",
":",
"2",
"]",
",",
"s",
"[",
"2",
":",
"]",
"\n",
"}"
] |
// parsePrefix takes the first field and splits it into a talker id and data type.
|
[
"parsePrefix",
"takes",
"the",
"first",
"field",
"and",
"splits",
"it",
"into",
"a",
"talker",
"id",
"and",
"data",
"type",
"."
] |
7572fbeb90aaa0bd3d1dcb674938ffbc0a943123
|
https://github.com/adrianmo/go-nmea/blob/7572fbeb90aaa0bd3d1dcb674938ffbc0a943123/sentence.go#L89-L97
|
144,540 |
adrianmo/go-nmea
|
sentence.go
|
xorChecksum
|
func xorChecksum(s string) string {
var checksum uint8
for i := 0; i < len(s); i++ {
checksum ^= s[i]
}
return fmt.Sprintf("%02X", checksum)
}
|
go
|
func xorChecksum(s string) string {
var checksum uint8
for i := 0; i < len(s); i++ {
checksum ^= s[i]
}
return fmt.Sprintf("%02X", checksum)
}
|
[
"func",
"xorChecksum",
"(",
"s",
"string",
")",
"string",
"{",
"var",
"checksum",
"uint8",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"len",
"(",
"s",
")",
";",
"i",
"++",
"{",
"checksum",
"^=",
"s",
"[",
"i",
"]",
"\n",
"}",
"\n",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"checksum",
")",
"\n",
"}"
] |
// xor all the bytes in a string an return it
// as an uppercase hex string
|
[
"xor",
"all",
"the",
"bytes",
"in",
"a",
"string",
"an",
"return",
"it",
"as",
"an",
"uppercase",
"hex",
"string"
] |
7572fbeb90aaa0bd3d1dcb674938ffbc0a943123
|
https://github.com/adrianmo/go-nmea/blob/7572fbeb90aaa0bd3d1dcb674938ffbc0a943123/sentence.go#L101-L107
|
144,541 |
adrianmo/go-nmea
|
sentence.go
|
Parse
|
func Parse(raw string) (Sentence, error) {
s, err := parseSentence(raw)
if err != nil {
return nil, err
}
if strings.HasPrefix(s.Raw, SentenceStart) {
switch s.Type {
case TypeRMC:
return newRMC(s)
case TypeGGA:
return newGGA(s)
case TypeGSA:
return newGSA(s)
case TypeGLL:
return newGLL(s)
case TypeVTG:
return newVTG(s)
case TypeZDA:
return newZDA(s)
case TypePGRME:
return newPGRME(s)
case TypeGSV:
return newGSV(s)
case TypeHDT:
return newHDT(s)
case TypeGNS:
return newGNS(s)
case TypeTHS:
return newTHS(s)
}
}
if strings.HasPrefix(s.Raw, SentenceStartEncapsulated) {
switch s.Type {
case TypeVDM, TypeVDO:
return newVDMVDO(s)
}
}
return nil, fmt.Errorf("nmea: sentence prefix '%s' not supported", s.Prefix())
}
|
go
|
func Parse(raw string) (Sentence, error) {
s, err := parseSentence(raw)
if err != nil {
return nil, err
}
if strings.HasPrefix(s.Raw, SentenceStart) {
switch s.Type {
case TypeRMC:
return newRMC(s)
case TypeGGA:
return newGGA(s)
case TypeGSA:
return newGSA(s)
case TypeGLL:
return newGLL(s)
case TypeVTG:
return newVTG(s)
case TypeZDA:
return newZDA(s)
case TypePGRME:
return newPGRME(s)
case TypeGSV:
return newGSV(s)
case TypeHDT:
return newHDT(s)
case TypeGNS:
return newGNS(s)
case TypeTHS:
return newTHS(s)
}
}
if strings.HasPrefix(s.Raw, SentenceStartEncapsulated) {
switch s.Type {
case TypeVDM, TypeVDO:
return newVDMVDO(s)
}
}
return nil, fmt.Errorf("nmea: sentence prefix '%s' not supported", s.Prefix())
}
|
[
"func",
"Parse",
"(",
"raw",
"string",
")",
"(",
"Sentence",
",",
"error",
")",
"{",
"s",
",",
"err",
":=",
"parseSentence",
"(",
"raw",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"strings",
".",
"HasPrefix",
"(",
"s",
".",
"Raw",
",",
"SentenceStart",
")",
"{",
"switch",
"s",
".",
"Type",
"{",
"case",
"TypeRMC",
":",
"return",
"newRMC",
"(",
"s",
")",
"\n",
"case",
"TypeGGA",
":",
"return",
"newGGA",
"(",
"s",
")",
"\n",
"case",
"TypeGSA",
":",
"return",
"newGSA",
"(",
"s",
")",
"\n",
"case",
"TypeGLL",
":",
"return",
"newGLL",
"(",
"s",
")",
"\n",
"case",
"TypeVTG",
":",
"return",
"newVTG",
"(",
"s",
")",
"\n",
"case",
"TypeZDA",
":",
"return",
"newZDA",
"(",
"s",
")",
"\n",
"case",
"TypePGRME",
":",
"return",
"newPGRME",
"(",
"s",
")",
"\n",
"case",
"TypeGSV",
":",
"return",
"newGSV",
"(",
"s",
")",
"\n",
"case",
"TypeHDT",
":",
"return",
"newHDT",
"(",
"s",
")",
"\n",
"case",
"TypeGNS",
":",
"return",
"newGNS",
"(",
"s",
")",
"\n",
"case",
"TypeTHS",
":",
"return",
"newTHS",
"(",
"s",
")",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"strings",
".",
"HasPrefix",
"(",
"s",
".",
"Raw",
",",
"SentenceStartEncapsulated",
")",
"{",
"switch",
"s",
".",
"Type",
"{",
"case",
"TypeVDM",
",",
"TypeVDO",
":",
"return",
"newVDMVDO",
"(",
"s",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"s",
".",
"Prefix",
"(",
")",
")",
"\n",
"}"
] |
// Parse parses the given string into the correct sentence type.
|
[
"Parse",
"parses",
"the",
"given",
"string",
"into",
"the",
"correct",
"sentence",
"type",
"."
] |
7572fbeb90aaa0bd3d1dcb674938ffbc0a943123
|
https://github.com/adrianmo/go-nmea/blob/7572fbeb90aaa0bd3d1dcb674938ffbc0a943123/sentence.go#L110-L148
|
144,542 |
adrianmo/go-nmea
|
types.go
|
FormatDMS
|
func FormatDMS(l float64) string {
val := math.Abs(l)
degrees := int(math.Floor(val))
minutes := int(math.Floor(60 * (val - float64(degrees))))
seconds := 3600 * (val - float64(degrees) - (float64(minutes) / 60))
return fmt.Sprintf("%d\u00B0 %d' %f\"", degrees, minutes, seconds)
}
|
go
|
func FormatDMS(l float64) string {
val := math.Abs(l)
degrees := int(math.Floor(val))
minutes := int(math.Floor(60 * (val - float64(degrees))))
seconds := 3600 * (val - float64(degrees) - (float64(minutes) / 60))
return fmt.Sprintf("%d\u00B0 %d' %f\"", degrees, minutes, seconds)
}
|
[
"func",
"FormatDMS",
"(",
"l",
"float64",
")",
"string",
"{",
"val",
":=",
"math",
".",
"Abs",
"(",
"l",
")",
"\n",
"degrees",
":=",
"int",
"(",
"math",
".",
"Floor",
"(",
"val",
")",
")",
"\n",
"minutes",
":=",
"int",
"(",
"math",
".",
"Floor",
"(",
"60",
"*",
"(",
"val",
"-",
"float64",
"(",
"degrees",
")",
")",
")",
")",
"\n",
"seconds",
":=",
"3600",
"*",
"(",
"val",
"-",
"float64",
"(",
"degrees",
")",
"-",
"(",
"float64",
"(",
"minutes",
")",
"/",
"60",
")",
")",
"\n",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\\u00B0",
"\\\"",
"\"",
",",
"degrees",
",",
"minutes",
",",
"seconds",
")",
"\n",
"}"
] |
// FormatDMS returns the degrees, minutes, seconds format for the given LatLong.
|
[
"FormatDMS",
"returns",
"the",
"degrees",
"minutes",
"seconds",
"format",
"for",
"the",
"given",
"LatLong",
"."
] |
7572fbeb90aaa0bd3d1dcb674938ffbc0a943123
|
https://github.com/adrianmo/go-nmea/blob/7572fbeb90aaa0bd3d1dcb674938ffbc0a943123/types.go#L160-L166
|
144,543 |
adrianmo/go-nmea
|
types.go
|
String
|
func (t Time) String() string {
seconds := float64(t.Second) + float64(t.Millisecond)/1000
return fmt.Sprintf("%02d:%02d:%07.4f", t.Hour, t.Minute, seconds)
}
|
go
|
func (t Time) String() string {
seconds := float64(t.Second) + float64(t.Millisecond)/1000
return fmt.Sprintf("%02d:%02d:%07.4f", t.Hour, t.Minute, seconds)
}
|
[
"func",
"(",
"t",
"Time",
")",
"String",
"(",
")",
"string",
"{",
"seconds",
":=",
"float64",
"(",
"t",
".",
"Second",
")",
"+",
"float64",
"(",
"t",
".",
"Millisecond",
")",
"/",
"1000",
"\n",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"t",
".",
"Hour",
",",
"t",
".",
"Minute",
",",
"seconds",
")",
"\n",
"}"
] |
// String representation of Time
|
[
"String",
"representation",
"of",
"Time"
] |
7572fbeb90aaa0bd3d1dcb674938ffbc0a943123
|
https://github.com/adrianmo/go-nmea/blob/7572fbeb90aaa0bd3d1dcb674938ffbc0a943123/types.go#L178-L181
|
144,544 |
adrianmo/go-nmea
|
types.go
|
String
|
func (d Date) String() string {
return fmt.Sprintf("%02d/%02d/%02d", d.DD, d.MM, d.YY)
}
|
go
|
func (d Date) String() string {
return fmt.Sprintf("%02d/%02d/%02d", d.DD, d.MM, d.YY)
}
|
[
"func",
"(",
"d",
"Date",
")",
"String",
"(",
")",
"string",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"d",
".",
"DD",
",",
"d",
".",
"MM",
",",
"d",
".",
"YY",
")",
"\n",
"}"
] |
// String representation of date
|
[
"String",
"representation",
"of",
"date"
] |
7572fbeb90aaa0bd3d1dcb674938ffbc0a943123
|
https://github.com/adrianmo/go-nmea/blob/7572fbeb90aaa0bd3d1dcb674938ffbc0a943123/types.go#L223-L225
|
144,545 |
adrianmo/go-nmea
|
types.go
|
ParseDate
|
func ParseDate(ddmmyy string) (Date, error) {
if ddmmyy == "" {
return Date{}, nil
}
if len(ddmmyy) != 6 {
return Date{}, fmt.Errorf("parse date: exptected ddmmyy format, got '%s'", ddmmyy)
}
dd, err := strconv.Atoi(ddmmyy[0:2])
if err != nil {
return Date{}, errors.New(ddmmyy)
}
mm, err := strconv.Atoi(ddmmyy[2:4])
if err != nil {
return Date{}, errors.New(ddmmyy)
}
yy, err := strconv.Atoi(ddmmyy[4:6])
if err != nil {
return Date{}, errors.New(ddmmyy)
}
return Date{true, dd, mm, yy}, nil
}
|
go
|
func ParseDate(ddmmyy string) (Date, error) {
if ddmmyy == "" {
return Date{}, nil
}
if len(ddmmyy) != 6 {
return Date{}, fmt.Errorf("parse date: exptected ddmmyy format, got '%s'", ddmmyy)
}
dd, err := strconv.Atoi(ddmmyy[0:2])
if err != nil {
return Date{}, errors.New(ddmmyy)
}
mm, err := strconv.Atoi(ddmmyy[2:4])
if err != nil {
return Date{}, errors.New(ddmmyy)
}
yy, err := strconv.Atoi(ddmmyy[4:6])
if err != nil {
return Date{}, errors.New(ddmmyy)
}
return Date{true, dd, mm, yy}, nil
}
|
[
"func",
"ParseDate",
"(",
"ddmmyy",
"string",
")",
"(",
"Date",
",",
"error",
")",
"{",
"if",
"ddmmyy",
"==",
"\"",
"\"",
"{",
"return",
"Date",
"{",
"}",
",",
"nil",
"\n",
"}",
"\n",
"if",
"len",
"(",
"ddmmyy",
")",
"!=",
"6",
"{",
"return",
"Date",
"{",
"}",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"ddmmyy",
")",
"\n",
"}",
"\n",
"dd",
",",
"err",
":=",
"strconv",
".",
"Atoi",
"(",
"ddmmyy",
"[",
"0",
":",
"2",
"]",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"Date",
"{",
"}",
",",
"errors",
".",
"New",
"(",
"ddmmyy",
")",
"\n",
"}",
"\n",
"mm",
",",
"err",
":=",
"strconv",
".",
"Atoi",
"(",
"ddmmyy",
"[",
"2",
":",
"4",
"]",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"Date",
"{",
"}",
",",
"errors",
".",
"New",
"(",
"ddmmyy",
")",
"\n",
"}",
"\n",
"yy",
",",
"err",
":=",
"strconv",
".",
"Atoi",
"(",
"ddmmyy",
"[",
"4",
":",
"6",
"]",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"Date",
"{",
"}",
",",
"errors",
".",
"New",
"(",
"ddmmyy",
")",
"\n",
"}",
"\n",
"return",
"Date",
"{",
"true",
",",
"dd",
",",
"mm",
",",
"yy",
"}",
",",
"nil",
"\n",
"}"
] |
// ParseDate field ddmmyy format
|
[
"ParseDate",
"field",
"ddmmyy",
"format"
] |
7572fbeb90aaa0bd3d1dcb674938ffbc0a943123
|
https://github.com/adrianmo/go-nmea/blob/7572fbeb90aaa0bd3d1dcb674938ffbc0a943123/types.go#L228-L248
|
144,546 |
jessevdk/go-flags
|
group.go
|
Find
|
func (g *Group) Find(shortDescription string) *Group {
lshortDescription := strings.ToLower(shortDescription)
var ret *Group
g.eachGroup(func(gg *Group) {
if gg != g && strings.ToLower(gg.ShortDescription) == lshortDescription {
ret = gg
}
})
return ret
}
|
go
|
func (g *Group) Find(shortDescription string) *Group {
lshortDescription := strings.ToLower(shortDescription)
var ret *Group
g.eachGroup(func(gg *Group) {
if gg != g && strings.ToLower(gg.ShortDescription) == lshortDescription {
ret = gg
}
})
return ret
}
|
[
"func",
"(",
"g",
"*",
"Group",
")",
"Find",
"(",
"shortDescription",
"string",
")",
"*",
"Group",
"{",
"lshortDescription",
":=",
"strings",
".",
"ToLower",
"(",
"shortDescription",
")",
"\n\n",
"var",
"ret",
"*",
"Group",
"\n\n",
"g",
".",
"eachGroup",
"(",
"func",
"(",
"gg",
"*",
"Group",
")",
"{",
"if",
"gg",
"!=",
"g",
"&&",
"strings",
".",
"ToLower",
"(",
"gg",
".",
"ShortDescription",
")",
"==",
"lshortDescription",
"{",
"ret",
"=",
"gg",
"\n",
"}",
"\n",
"}",
")",
"\n\n",
"return",
"ret",
"\n",
"}"
] |
// Find locates the subgroup with the given short description and returns it.
// If no such group can be found Find will return nil. Note that the description
// is matched case insensitively.
|
[
"Find",
"locates",
"the",
"subgroup",
"with",
"the",
"given",
"short",
"description",
"and",
"returns",
"it",
".",
"If",
"no",
"such",
"group",
"can",
"be",
"found",
"Find",
"will",
"return",
"nil",
".",
"Note",
"that",
"the",
"description",
"is",
"matched",
"case",
"insensitively",
"."
] |
c0795c8afcf41dd1d786bebce68636c199b3bb45
|
https://github.com/jessevdk/go-flags/blob/c0795c8afcf41dd1d786bebce68636c199b3bb45/group.go#L89-L101
|
144,547 |
jessevdk/go-flags
|
group.go
|
FindOptionByShortName
|
func (g *Group) FindOptionByShortName(shortName rune) *Option {
return g.findOption(func(option *Option) bool {
return option.ShortName == shortName
})
}
|
go
|
func (g *Group) FindOptionByShortName(shortName rune) *Option {
return g.findOption(func(option *Option) bool {
return option.ShortName == shortName
})
}
|
[
"func",
"(",
"g",
"*",
"Group",
")",
"FindOptionByShortName",
"(",
"shortName",
"rune",
")",
"*",
"Option",
"{",
"return",
"g",
".",
"findOption",
"(",
"func",
"(",
"option",
"*",
"Option",
")",
"bool",
"{",
"return",
"option",
".",
"ShortName",
"==",
"shortName",
"\n",
"}",
")",
"\n",
"}"
] |
// FindOptionByShortName finds an option that is part of the group, or any of
// its subgroups, by matching its short name.
|
[
"FindOptionByShortName",
"finds",
"an",
"option",
"that",
"is",
"part",
"of",
"the",
"group",
"or",
"any",
"of",
"its",
"subgroups",
"by",
"matching",
"its",
"short",
"name",
"."
] |
c0795c8afcf41dd1d786bebce68636c199b3bb45
|
https://github.com/jessevdk/go-flags/blob/c0795c8afcf41dd1d786bebce68636c199b3bb45/group.go#L125-L129
|
144,548 |
jessevdk/go-flags
|
man.go
|
WriteManPage
|
func (p *Parser) WriteManPage(wr io.Writer) {
t := time.Now()
source_date_epoch := os.Getenv("SOURCE_DATE_EPOCH")
if source_date_epoch != "" {
sde, err := strconv.ParseInt(source_date_epoch, 10, 64)
if err != nil {
panic(fmt.Sprintf("Invalid SOURCE_DATE_EPOCH: %s", err))
}
t = time.Unix(sde, 0)
}
fmt.Fprintf(wr, ".TH %s 1 \"%s\"\n", manQuote(p.Name), t.Format("2 January 2006"))
fmt.Fprintln(wr, ".SH NAME")
fmt.Fprintf(wr, "%s \\- %s\n", manQuote(p.Name), manQuote(p.ShortDescription))
fmt.Fprintln(wr, ".SH SYNOPSIS")
usage := p.Usage
if len(usage) == 0 {
usage = "[OPTIONS]"
}
fmt.Fprintf(wr, "\\fB%s\\fP %s\n", manQuote(p.Name), manQuote(usage))
fmt.Fprintln(wr, ".SH DESCRIPTION")
formatForMan(wr, p.LongDescription)
fmt.Fprintln(wr, "")
fmt.Fprintln(wr, ".SH OPTIONS")
writeManPageOptions(wr, p.Command.Group)
if len(p.visibleCommands()) > 0 {
fmt.Fprintln(wr, ".SH COMMANDS")
writeManPageSubcommands(wr, "", p.Command)
}
}
|
go
|
func (p *Parser) WriteManPage(wr io.Writer) {
t := time.Now()
source_date_epoch := os.Getenv("SOURCE_DATE_EPOCH")
if source_date_epoch != "" {
sde, err := strconv.ParseInt(source_date_epoch, 10, 64)
if err != nil {
panic(fmt.Sprintf("Invalid SOURCE_DATE_EPOCH: %s", err))
}
t = time.Unix(sde, 0)
}
fmt.Fprintf(wr, ".TH %s 1 \"%s\"\n", manQuote(p.Name), t.Format("2 January 2006"))
fmt.Fprintln(wr, ".SH NAME")
fmt.Fprintf(wr, "%s \\- %s\n", manQuote(p.Name), manQuote(p.ShortDescription))
fmt.Fprintln(wr, ".SH SYNOPSIS")
usage := p.Usage
if len(usage) == 0 {
usage = "[OPTIONS]"
}
fmt.Fprintf(wr, "\\fB%s\\fP %s\n", manQuote(p.Name), manQuote(usage))
fmt.Fprintln(wr, ".SH DESCRIPTION")
formatForMan(wr, p.LongDescription)
fmt.Fprintln(wr, "")
fmt.Fprintln(wr, ".SH OPTIONS")
writeManPageOptions(wr, p.Command.Group)
if len(p.visibleCommands()) > 0 {
fmt.Fprintln(wr, ".SH COMMANDS")
writeManPageSubcommands(wr, "", p.Command)
}
}
|
[
"func",
"(",
"p",
"*",
"Parser",
")",
"WriteManPage",
"(",
"wr",
"io",
".",
"Writer",
")",
"{",
"t",
":=",
"time",
".",
"Now",
"(",
")",
"\n",
"source_date_epoch",
":=",
"os",
".",
"Getenv",
"(",
"\"",
"\"",
")",
"\n",
"if",
"source_date_epoch",
"!=",
"\"",
"\"",
"{",
"sde",
",",
"err",
":=",
"strconv",
".",
"ParseInt",
"(",
"source_date_epoch",
",",
"10",
",",
"64",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"err",
")",
")",
"\n",
"}",
"\n",
"t",
"=",
"time",
".",
"Unix",
"(",
"sde",
",",
"0",
")",
"\n",
"}",
"\n\n",
"fmt",
".",
"Fprintf",
"(",
"wr",
",",
"\"",
"\\\"",
"\\\"",
"\\n",
"\"",
",",
"manQuote",
"(",
"p",
".",
"Name",
")",
",",
"t",
".",
"Format",
"(",
"\"",
"\"",
")",
")",
"\n",
"fmt",
".",
"Fprintln",
"(",
"wr",
",",
"\"",
"\"",
")",
"\n",
"fmt",
".",
"Fprintf",
"(",
"wr",
",",
"\"",
"\\\\",
"\\n",
"\"",
",",
"manQuote",
"(",
"p",
".",
"Name",
")",
",",
"manQuote",
"(",
"p",
".",
"ShortDescription",
")",
")",
"\n",
"fmt",
".",
"Fprintln",
"(",
"wr",
",",
"\"",
"\"",
")",
"\n\n",
"usage",
":=",
"p",
".",
"Usage",
"\n\n",
"if",
"len",
"(",
"usage",
")",
"==",
"0",
"{",
"usage",
"=",
"\"",
"\"",
"\n",
"}",
"\n\n",
"fmt",
".",
"Fprintf",
"(",
"wr",
",",
"\"",
"\\\\",
"\\\\",
"\\n",
"\"",
",",
"manQuote",
"(",
"p",
".",
"Name",
")",
",",
"manQuote",
"(",
"usage",
")",
")",
"\n",
"fmt",
".",
"Fprintln",
"(",
"wr",
",",
"\"",
"\"",
")",
"\n\n",
"formatForMan",
"(",
"wr",
",",
"p",
".",
"LongDescription",
")",
"\n",
"fmt",
".",
"Fprintln",
"(",
"wr",
",",
"\"",
"\"",
")",
"\n\n",
"fmt",
".",
"Fprintln",
"(",
"wr",
",",
"\"",
"\"",
")",
"\n\n",
"writeManPageOptions",
"(",
"wr",
",",
"p",
".",
"Command",
".",
"Group",
")",
"\n\n",
"if",
"len",
"(",
"p",
".",
"visibleCommands",
"(",
")",
")",
">",
"0",
"{",
"fmt",
".",
"Fprintln",
"(",
"wr",
",",
"\"",
"\"",
")",
"\n\n",
"writeManPageSubcommands",
"(",
"wr",
",",
"\"",
"\"",
",",
"p",
".",
"Command",
")",
"\n",
"}",
"\n",
"}"
] |
// WriteManPage writes a basic man page in groff format to the specified
// writer.
|
[
"WriteManPage",
"writes",
"a",
"basic",
"man",
"page",
"in",
"groff",
"format",
"to",
"the",
"specified",
"writer",
"."
] |
c0795c8afcf41dd1d786bebce68636c199b3bb45
|
https://github.com/jessevdk/go-flags/blob/c0795c8afcf41dd1d786bebce68636c199b3bb45/man.go#L178-L215
|
144,549 |
jessevdk/go-flags
|
parser.go
|
NewNamedParser
|
func NewNamedParser(appname string, options Options) *Parser {
p := &Parser{
Command: newCommand(appname, "", "", nil),
Options: options,
NamespaceDelimiter: ".",
EnvNamespaceDelimiter: "_",
}
p.Command.parent = p
return p
}
|
go
|
func NewNamedParser(appname string, options Options) *Parser {
p := &Parser{
Command: newCommand(appname, "", "", nil),
Options: options,
NamespaceDelimiter: ".",
EnvNamespaceDelimiter: "_",
}
p.Command.parent = p
return p
}
|
[
"func",
"NewNamedParser",
"(",
"appname",
"string",
",",
"options",
"Options",
")",
"*",
"Parser",
"{",
"p",
":=",
"&",
"Parser",
"{",
"Command",
":",
"newCommand",
"(",
"appname",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"nil",
")",
",",
"Options",
":",
"options",
",",
"NamespaceDelimiter",
":",
"\"",
"\"",
",",
"EnvNamespaceDelimiter",
":",
"\"",
"\"",
",",
"}",
"\n\n",
"p",
".",
"Command",
".",
"parent",
"=",
"p",
"\n\n",
"return",
"p",
"\n",
"}"
] |
// NewNamedParser creates a new parser. The appname is used to display the
// executable name in the built-in help message. Option groups and commands can
// be added to this parser by using AddGroup and AddCommand.
|
[
"NewNamedParser",
"creates",
"a",
"new",
"parser",
".",
"The",
"appname",
"is",
"used",
"to",
"display",
"the",
"executable",
"name",
"in",
"the",
"built",
"-",
"in",
"help",
"message",
".",
"Option",
"groups",
"and",
"commands",
"can",
"be",
"added",
"to",
"this",
"parser",
"by",
"using",
"AddGroup",
"and",
"AddCommand",
"."
] |
c0795c8afcf41dd1d786bebce68636c199b3bb45
|
https://github.com/jessevdk/go-flags/blob/c0795c8afcf41dd1d786bebce68636c199b3bb45/parser.go#L174-L185
|
144,550 |
jessevdk/go-flags
|
ini.go
|
ParseFile
|
func (i *IniParser) ParseFile(filename string) error {
ini, err := readIniFromFile(filename)
if err != nil {
return err
}
return i.parse(ini)
}
|
go
|
func (i *IniParser) ParseFile(filename string) error {
ini, err := readIniFromFile(filename)
if err != nil {
return err
}
return i.parse(ini)
}
|
[
"func",
"(",
"i",
"*",
"IniParser",
")",
"ParseFile",
"(",
"filename",
"string",
")",
"error",
"{",
"ini",
",",
"err",
":=",
"readIniFromFile",
"(",
"filename",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"return",
"i",
".",
"parse",
"(",
"ini",
")",
"\n",
"}"
] |
// ParseFile parses flags from an ini formatted file. See Parse for more
// information on the ini file format. The returned errors can be of the type
// flags.Error or flags.IniError.
|
[
"ParseFile",
"parses",
"flags",
"from",
"an",
"ini",
"formatted",
"file",
".",
"See",
"Parse",
"for",
"more",
"information",
"on",
"the",
"ini",
"file",
"format",
".",
"The",
"returned",
"errors",
"can",
"be",
"of",
"the",
"type",
"flags",
".",
"Error",
"or",
"flags",
".",
"IniError",
"."
] |
c0795c8afcf41dd1d786bebce68636c199b3bb45
|
https://github.com/jessevdk/go-flags/blob/c0795c8afcf41dd1d786bebce68636c199b3bb45/ini.go#L100-L108
|
144,551 |
jessevdk/go-flags
|
ini.go
|
WriteFile
|
func (i *IniParser) WriteFile(filename string, options IniOptions) error {
return writeIniToFile(i, filename, options)
}
|
go
|
func (i *IniParser) WriteFile(filename string, options IniOptions) error {
return writeIniToFile(i, filename, options)
}
|
[
"func",
"(",
"i",
"*",
"IniParser",
")",
"WriteFile",
"(",
"filename",
"string",
",",
"options",
"IniOptions",
")",
"error",
"{",
"return",
"writeIniToFile",
"(",
"i",
",",
"filename",
",",
"options",
")",
"\n",
"}"
] |
// WriteFile writes the flags as ini format into a file. See Write
// for more information. The returned error occurs when the specified file
// could not be opened for writing.
|
[
"WriteFile",
"writes",
"the",
"flags",
"as",
"ini",
"format",
"into",
"a",
"file",
".",
"See",
"Write",
"for",
"more",
"information",
".",
"The",
"returned",
"error",
"occurs",
"when",
"the",
"specified",
"file",
"could",
"not",
"be",
"opened",
"for",
"writing",
"."
] |
c0795c8afcf41dd1d786bebce68636c199b3bb45
|
https://github.com/jessevdk/go-flags/blob/c0795c8afcf41dd1d786bebce68636c199b3bb45/ini.go#L147-L149
|
144,552 |
jessevdk/go-flags
|
completion.go
|
Complete
|
func (f *Filename) Complete(match string) []Completion {
ret, _ := filepath.Glob(match + "*")
if len(ret) == 1 {
if info, err := os.Stat(ret[0]); err == nil && info.IsDir() {
ret[0] = ret[0] + "/"
}
}
return completionsWithoutDescriptions(ret)
}
|
go
|
func (f *Filename) Complete(match string) []Completion {
ret, _ := filepath.Glob(match + "*")
if len(ret) == 1 {
if info, err := os.Stat(ret[0]); err == nil && info.IsDir() {
ret[0] = ret[0] + "/"
}
}
return completionsWithoutDescriptions(ret)
}
|
[
"func",
"(",
"f",
"*",
"Filename",
")",
"Complete",
"(",
"match",
"string",
")",
"[",
"]",
"Completion",
"{",
"ret",
",",
"_",
":=",
"filepath",
".",
"Glob",
"(",
"match",
"+",
"\"",
"\"",
")",
"\n",
"if",
"len",
"(",
"ret",
")",
"==",
"1",
"{",
"if",
"info",
",",
"err",
":=",
"os",
".",
"Stat",
"(",
"ret",
"[",
"0",
"]",
")",
";",
"err",
"==",
"nil",
"&&",
"info",
".",
"IsDir",
"(",
")",
"{",
"ret",
"[",
"0",
"]",
"=",
"ret",
"[",
"0",
"]",
"+",
"\"",
"\"",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"completionsWithoutDescriptions",
"(",
"ret",
")",
"\n",
"}"
] |
// Complete returns a list of existing files with the given
// prefix.
|
[
"Complete",
"returns",
"a",
"list",
"of",
"existing",
"files",
"with",
"the",
"given",
"prefix",
"."
] |
c0795c8afcf41dd1d786bebce68636c199b3bb45
|
https://github.com/jessevdk/go-flags/blob/c0795c8afcf41dd1d786bebce68636c199b3bb45/completion.go#L64-L72
|
144,553 |
jessevdk/go-flags
|
option.go
|
LongNameWithNamespace
|
func (option *Option) LongNameWithNamespace() string {
if len(option.LongName) == 0 {
return ""
}
// fetch the namespace delimiter from the parser which is always at the
// end of the group hierarchy
namespaceDelimiter := ""
g := option.group
for {
if p, ok := g.parent.(*Parser); ok {
namespaceDelimiter = p.NamespaceDelimiter
break
}
switch i := g.parent.(type) {
case *Command:
g = i.Group
case *Group:
g = i
}
}
// concatenate long name with namespace
longName := option.LongName
g = option.group
for g != nil {
if g.Namespace != "" {
longName = g.Namespace + namespaceDelimiter + longName
}
switch i := g.parent.(type) {
case *Command:
g = i.Group
case *Group:
g = i
case *Parser:
g = nil
}
}
return longName
}
|
go
|
func (option *Option) LongNameWithNamespace() string {
if len(option.LongName) == 0 {
return ""
}
// fetch the namespace delimiter from the parser which is always at the
// end of the group hierarchy
namespaceDelimiter := ""
g := option.group
for {
if p, ok := g.parent.(*Parser); ok {
namespaceDelimiter = p.NamespaceDelimiter
break
}
switch i := g.parent.(type) {
case *Command:
g = i.Group
case *Group:
g = i
}
}
// concatenate long name with namespace
longName := option.LongName
g = option.group
for g != nil {
if g.Namespace != "" {
longName = g.Namespace + namespaceDelimiter + longName
}
switch i := g.parent.(type) {
case *Command:
g = i.Group
case *Group:
g = i
case *Parser:
g = nil
}
}
return longName
}
|
[
"func",
"(",
"option",
"*",
"Option",
")",
"LongNameWithNamespace",
"(",
")",
"string",
"{",
"if",
"len",
"(",
"option",
".",
"LongName",
")",
"==",
"0",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n\n",
"// fetch the namespace delimiter from the parser which is always at the",
"// end of the group hierarchy",
"namespaceDelimiter",
":=",
"\"",
"\"",
"\n",
"g",
":=",
"option",
".",
"group",
"\n\n",
"for",
"{",
"if",
"p",
",",
"ok",
":=",
"g",
".",
"parent",
".",
"(",
"*",
"Parser",
")",
";",
"ok",
"{",
"namespaceDelimiter",
"=",
"p",
".",
"NamespaceDelimiter",
"\n\n",
"break",
"\n",
"}",
"\n\n",
"switch",
"i",
":=",
"g",
".",
"parent",
".",
"(",
"type",
")",
"{",
"case",
"*",
"Command",
":",
"g",
"=",
"i",
".",
"Group",
"\n",
"case",
"*",
"Group",
":",
"g",
"=",
"i",
"\n",
"}",
"\n",
"}",
"\n\n",
"// concatenate long name with namespace",
"longName",
":=",
"option",
".",
"LongName",
"\n",
"g",
"=",
"option",
".",
"group",
"\n\n",
"for",
"g",
"!=",
"nil",
"{",
"if",
"g",
".",
"Namespace",
"!=",
"\"",
"\"",
"{",
"longName",
"=",
"g",
".",
"Namespace",
"+",
"namespaceDelimiter",
"+",
"longName",
"\n",
"}",
"\n\n",
"switch",
"i",
":=",
"g",
".",
"parent",
".",
"(",
"type",
")",
"{",
"case",
"*",
"Command",
":",
"g",
"=",
"i",
".",
"Group",
"\n",
"case",
"*",
"Group",
":",
"g",
"=",
"i",
"\n",
"case",
"*",
"Parser",
":",
"g",
"=",
"nil",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"longName",
"\n",
"}"
] |
// LongNameWithNamespace returns the option's long name with the group namespaces
// prepended by walking up the option's group tree. Namespaces and the long name
// itself are separated by the parser's namespace delimiter. If the long name is
// empty an empty string is returned.
|
[
"LongNameWithNamespace",
"returns",
"the",
"option",
"s",
"long",
"name",
"with",
"the",
"group",
"namespaces",
"prepended",
"by",
"walking",
"up",
"the",
"option",
"s",
"group",
"tree",
".",
"Namespaces",
"and",
"the",
"long",
"name",
"itself",
"are",
"separated",
"by",
"the",
"parser",
"s",
"namespace",
"delimiter",
".",
"If",
"the",
"long",
"name",
"is",
"empty",
"an",
"empty",
"string",
"is",
"returned",
"."
] |
c0795c8afcf41dd1d786bebce68636c199b3bb45
|
https://github.com/jessevdk/go-flags/blob/c0795c8afcf41dd1d786bebce68636c199b3bb45/option.go#L95-L140
|
144,554 |
jessevdk/go-flags
|
option.go
|
EnvKeyWithNamespace
|
func (option *Option) EnvKeyWithNamespace() string {
if len(option.EnvDefaultKey) == 0 {
return ""
}
// fetch the namespace delimiter from the parser which is always at the
// end of the group hierarchy
namespaceDelimiter := ""
g := option.group
for {
if p, ok := g.parent.(*Parser); ok {
namespaceDelimiter = p.EnvNamespaceDelimiter
break
}
switch i := g.parent.(type) {
case *Command:
g = i.Group
case *Group:
g = i
}
}
// concatenate long name with namespace
key := option.EnvDefaultKey
g = option.group
for g != nil {
if g.EnvNamespace != "" {
key = g.EnvNamespace + namespaceDelimiter + key
}
switch i := g.parent.(type) {
case *Command:
g = i.Group
case *Group:
g = i
case *Parser:
g = nil
}
}
return key
}
|
go
|
func (option *Option) EnvKeyWithNamespace() string {
if len(option.EnvDefaultKey) == 0 {
return ""
}
// fetch the namespace delimiter from the parser which is always at the
// end of the group hierarchy
namespaceDelimiter := ""
g := option.group
for {
if p, ok := g.parent.(*Parser); ok {
namespaceDelimiter = p.EnvNamespaceDelimiter
break
}
switch i := g.parent.(type) {
case *Command:
g = i.Group
case *Group:
g = i
}
}
// concatenate long name with namespace
key := option.EnvDefaultKey
g = option.group
for g != nil {
if g.EnvNamespace != "" {
key = g.EnvNamespace + namespaceDelimiter + key
}
switch i := g.parent.(type) {
case *Command:
g = i.Group
case *Group:
g = i
case *Parser:
g = nil
}
}
return key
}
|
[
"func",
"(",
"option",
"*",
"Option",
")",
"EnvKeyWithNamespace",
"(",
")",
"string",
"{",
"if",
"len",
"(",
"option",
".",
"EnvDefaultKey",
")",
"==",
"0",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n\n",
"// fetch the namespace delimiter from the parser which is always at the",
"// end of the group hierarchy",
"namespaceDelimiter",
":=",
"\"",
"\"",
"\n",
"g",
":=",
"option",
".",
"group",
"\n\n",
"for",
"{",
"if",
"p",
",",
"ok",
":=",
"g",
".",
"parent",
".",
"(",
"*",
"Parser",
")",
";",
"ok",
"{",
"namespaceDelimiter",
"=",
"p",
".",
"EnvNamespaceDelimiter",
"\n\n",
"break",
"\n",
"}",
"\n\n",
"switch",
"i",
":=",
"g",
".",
"parent",
".",
"(",
"type",
")",
"{",
"case",
"*",
"Command",
":",
"g",
"=",
"i",
".",
"Group",
"\n",
"case",
"*",
"Group",
":",
"g",
"=",
"i",
"\n",
"}",
"\n",
"}",
"\n\n",
"// concatenate long name with namespace",
"key",
":=",
"option",
".",
"EnvDefaultKey",
"\n",
"g",
"=",
"option",
".",
"group",
"\n\n",
"for",
"g",
"!=",
"nil",
"{",
"if",
"g",
".",
"EnvNamespace",
"!=",
"\"",
"\"",
"{",
"key",
"=",
"g",
".",
"EnvNamespace",
"+",
"namespaceDelimiter",
"+",
"key",
"\n",
"}",
"\n\n",
"switch",
"i",
":=",
"g",
".",
"parent",
".",
"(",
"type",
")",
"{",
"case",
"*",
"Command",
":",
"g",
"=",
"i",
".",
"Group",
"\n",
"case",
"*",
"Group",
":",
"g",
"=",
"i",
"\n",
"case",
"*",
"Parser",
":",
"g",
"=",
"nil",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"key",
"\n",
"}"
] |
// EnvKeyWithNamespace returns the option's env key with the group namespaces
// prepended by walking up the option's group tree. Namespaces and the env key
// itself are separated by the parser's namespace delimiter. If the env key is
// empty an empty string is returned.
|
[
"EnvKeyWithNamespace",
"returns",
"the",
"option",
"s",
"env",
"key",
"with",
"the",
"group",
"namespaces",
"prepended",
"by",
"walking",
"up",
"the",
"option",
"s",
"group",
"tree",
".",
"Namespaces",
"and",
"the",
"env",
"key",
"itself",
"are",
"separated",
"by",
"the",
"parser",
"s",
"namespace",
"delimiter",
".",
"If",
"the",
"env",
"key",
"is",
"empty",
"an",
"empty",
"string",
"is",
"returned",
"."
] |
c0795c8afcf41dd1d786bebce68636c199b3bb45
|
https://github.com/jessevdk/go-flags/blob/c0795c8afcf41dd1d786bebce68636c199b3bb45/option.go#L146-L191
|
144,555 |
jessevdk/go-flags
|
option.go
|
String
|
func (option *Option) String() string {
var s string
var short string
if option.ShortName != 0 {
data := make([]byte, utf8.RuneLen(option.ShortName))
utf8.EncodeRune(data, option.ShortName)
short = string(data)
if len(option.LongName) != 0 {
s = fmt.Sprintf("%s%s, %s%s",
string(defaultShortOptDelimiter), short,
defaultLongOptDelimiter, option.LongNameWithNamespace())
} else {
s = fmt.Sprintf("%s%s", string(defaultShortOptDelimiter), short)
}
} else if len(option.LongName) != 0 {
s = fmt.Sprintf("%s%s", defaultLongOptDelimiter, option.LongNameWithNamespace())
}
return s
}
|
go
|
func (option *Option) String() string {
var s string
var short string
if option.ShortName != 0 {
data := make([]byte, utf8.RuneLen(option.ShortName))
utf8.EncodeRune(data, option.ShortName)
short = string(data)
if len(option.LongName) != 0 {
s = fmt.Sprintf("%s%s, %s%s",
string(defaultShortOptDelimiter), short,
defaultLongOptDelimiter, option.LongNameWithNamespace())
} else {
s = fmt.Sprintf("%s%s", string(defaultShortOptDelimiter), short)
}
} else if len(option.LongName) != 0 {
s = fmt.Sprintf("%s%s", defaultLongOptDelimiter, option.LongNameWithNamespace())
}
return s
}
|
[
"func",
"(",
"option",
"*",
"Option",
")",
"String",
"(",
")",
"string",
"{",
"var",
"s",
"string",
"\n",
"var",
"short",
"string",
"\n\n",
"if",
"option",
".",
"ShortName",
"!=",
"0",
"{",
"data",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"utf8",
".",
"RuneLen",
"(",
"option",
".",
"ShortName",
")",
")",
"\n",
"utf8",
".",
"EncodeRune",
"(",
"data",
",",
"option",
".",
"ShortName",
")",
"\n",
"short",
"=",
"string",
"(",
"data",
")",
"\n\n",
"if",
"len",
"(",
"option",
".",
"LongName",
")",
"!=",
"0",
"{",
"s",
"=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"string",
"(",
"defaultShortOptDelimiter",
")",
",",
"short",
",",
"defaultLongOptDelimiter",
",",
"option",
".",
"LongNameWithNamespace",
"(",
")",
")",
"\n",
"}",
"else",
"{",
"s",
"=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"string",
"(",
"defaultShortOptDelimiter",
")",
",",
"short",
")",
"\n",
"}",
"\n",
"}",
"else",
"if",
"len",
"(",
"option",
".",
"LongName",
")",
"!=",
"0",
"{",
"s",
"=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"defaultLongOptDelimiter",
",",
"option",
".",
"LongNameWithNamespace",
"(",
")",
")",
"\n",
"}",
"\n\n",
"return",
"s",
"\n",
"}"
] |
// String converts an option to a human friendly readable string describing the
// option.
|
[
"String",
"converts",
"an",
"option",
"to",
"a",
"human",
"friendly",
"readable",
"string",
"describing",
"the",
"option",
"."
] |
c0795c8afcf41dd1d786bebce68636c199b3bb45
|
https://github.com/jessevdk/go-flags/blob/c0795c8afcf41dd1d786bebce68636c199b3bb45/option.go#L195-L216
|
144,556 |
jessevdk/go-flags
|
option.go
|
set
|
func (option *Option) set(value *string) error {
kind := option.value.Type().Kind()
if (kind == reflect.Map || kind == reflect.Slice) && !option.isSet {
option.empty()
}
option.isSet = true
option.preventDefault = true
if len(option.Choices) != 0 {
found := false
for _, choice := range option.Choices {
if choice == *value {
found = true
break
}
}
if !found {
allowed := strings.Join(option.Choices[0:len(option.Choices)-1], ", ")
if len(option.Choices) > 1 {
allowed += " or " + option.Choices[len(option.Choices)-1]
}
return newErrorf(ErrInvalidChoice,
"Invalid value `%s' for option `%s'. Allowed values are: %s",
*value, option, allowed)
}
}
if option.isFunc() {
return option.call(value)
} else if value != nil {
return convert(*value, option.value, option.tag)
}
return convert("", option.value, option.tag)
}
|
go
|
func (option *Option) set(value *string) error {
kind := option.value.Type().Kind()
if (kind == reflect.Map || kind == reflect.Slice) && !option.isSet {
option.empty()
}
option.isSet = true
option.preventDefault = true
if len(option.Choices) != 0 {
found := false
for _, choice := range option.Choices {
if choice == *value {
found = true
break
}
}
if !found {
allowed := strings.Join(option.Choices[0:len(option.Choices)-1], ", ")
if len(option.Choices) > 1 {
allowed += " or " + option.Choices[len(option.Choices)-1]
}
return newErrorf(ErrInvalidChoice,
"Invalid value `%s' for option `%s'. Allowed values are: %s",
*value, option, allowed)
}
}
if option.isFunc() {
return option.call(value)
} else if value != nil {
return convert(*value, option.value, option.tag)
}
return convert("", option.value, option.tag)
}
|
[
"func",
"(",
"option",
"*",
"Option",
")",
"set",
"(",
"value",
"*",
"string",
")",
"error",
"{",
"kind",
":=",
"option",
".",
"value",
".",
"Type",
"(",
")",
".",
"Kind",
"(",
")",
"\n\n",
"if",
"(",
"kind",
"==",
"reflect",
".",
"Map",
"||",
"kind",
"==",
"reflect",
".",
"Slice",
")",
"&&",
"!",
"option",
".",
"isSet",
"{",
"option",
".",
"empty",
"(",
")",
"\n",
"}",
"\n\n",
"option",
".",
"isSet",
"=",
"true",
"\n",
"option",
".",
"preventDefault",
"=",
"true",
"\n\n",
"if",
"len",
"(",
"option",
".",
"Choices",
")",
"!=",
"0",
"{",
"found",
":=",
"false",
"\n\n",
"for",
"_",
",",
"choice",
":=",
"range",
"option",
".",
"Choices",
"{",
"if",
"choice",
"==",
"*",
"value",
"{",
"found",
"=",
"true",
"\n",
"break",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"!",
"found",
"{",
"allowed",
":=",
"strings",
".",
"Join",
"(",
"option",
".",
"Choices",
"[",
"0",
":",
"len",
"(",
"option",
".",
"Choices",
")",
"-",
"1",
"]",
",",
"\"",
"\"",
")",
"\n\n",
"if",
"len",
"(",
"option",
".",
"Choices",
")",
">",
"1",
"{",
"allowed",
"+=",
"\"",
"\"",
"+",
"option",
".",
"Choices",
"[",
"len",
"(",
"option",
".",
"Choices",
")",
"-",
"1",
"]",
"\n",
"}",
"\n\n",
"return",
"newErrorf",
"(",
"ErrInvalidChoice",
",",
"\"",
"\"",
",",
"*",
"value",
",",
"option",
",",
"allowed",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"option",
".",
"isFunc",
"(",
")",
"{",
"return",
"option",
".",
"call",
"(",
"value",
")",
"\n",
"}",
"else",
"if",
"value",
"!=",
"nil",
"{",
"return",
"convert",
"(",
"*",
"value",
",",
"option",
".",
"value",
",",
"option",
".",
"tag",
")",
"\n",
"}",
"\n\n",
"return",
"convert",
"(",
"\"",
"\"",
",",
"option",
".",
"value",
",",
"option",
".",
"tag",
")",
"\n",
"}"
] |
// Set the value of an option to the specified value. An error will be returned
// if the specified value could not be converted to the corresponding option
// value type.
|
[
"Set",
"the",
"value",
"of",
"an",
"option",
"to",
"the",
"specified",
"value",
".",
"An",
"error",
"will",
"be",
"returned",
"if",
"the",
"specified",
"value",
"could",
"not",
"be",
"converted",
"to",
"the",
"corresponding",
"option",
"value",
"type",
"."
] |
c0795c8afcf41dd1d786bebce68636c199b3bb45
|
https://github.com/jessevdk/go-flags/blob/c0795c8afcf41dd1d786bebce68636c199b3bb45/option.go#L241-L281
|
144,557 |
jessevdk/go-flags
|
command.go
|
AddCommand
|
func (c *Command) AddCommand(command string, shortDescription string, longDescription string, data interface{}) (*Command, error) {
cmd := newCommand(command, shortDescription, longDescription, data)
cmd.parent = c
if err := cmd.scan(); err != nil {
return nil, err
}
c.commands = append(c.commands, cmd)
return cmd, nil
}
|
go
|
func (c *Command) AddCommand(command string, shortDescription string, longDescription string, data interface{}) (*Command, error) {
cmd := newCommand(command, shortDescription, longDescription, data)
cmd.parent = c
if err := cmd.scan(); err != nil {
return nil, err
}
c.commands = append(c.commands, cmd)
return cmd, nil
}
|
[
"func",
"(",
"c",
"*",
"Command",
")",
"AddCommand",
"(",
"command",
"string",
",",
"shortDescription",
"string",
",",
"longDescription",
"string",
",",
"data",
"interface",
"{",
"}",
")",
"(",
"*",
"Command",
",",
"error",
")",
"{",
"cmd",
":=",
"newCommand",
"(",
"command",
",",
"shortDescription",
",",
"longDescription",
",",
"data",
")",
"\n\n",
"cmd",
".",
"parent",
"=",
"c",
"\n\n",
"if",
"err",
":=",
"cmd",
".",
"scan",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"c",
".",
"commands",
"=",
"append",
"(",
"c",
".",
"commands",
",",
"cmd",
")",
"\n",
"return",
"cmd",
",",
"nil",
"\n",
"}"
] |
// AddCommand adds a new command to the parser with the given name and data. The
// data needs to be a pointer to a struct from which the fields indicate which
// options are in the command. The provided data can implement the Command and
// Usage interfaces.
|
[
"AddCommand",
"adds",
"a",
"new",
"command",
"to",
"the",
"parser",
"with",
"the",
"given",
"name",
"and",
"data",
".",
"The",
"data",
"needs",
"to",
"be",
"a",
"pointer",
"to",
"a",
"struct",
"from",
"which",
"the",
"fields",
"indicate",
"which",
"options",
"are",
"in",
"the",
"command",
".",
"The",
"provided",
"data",
"can",
"implement",
"the",
"Command",
"and",
"Usage",
"interfaces",
"."
] |
c0795c8afcf41dd1d786bebce68636c199b3bb45
|
https://github.com/jessevdk/go-flags/blob/c0795c8afcf41dd1d786bebce68636c199b3bb45/command.go#L68-L79
|
144,558 |
jessevdk/go-flags
|
command.go
|
Find
|
func (c *Command) Find(name string) *Command {
for _, cc := range c.commands {
if cc.match(name) {
return cc
}
}
return nil
}
|
go
|
func (c *Command) Find(name string) *Command {
for _, cc := range c.commands {
if cc.match(name) {
return cc
}
}
return nil
}
|
[
"func",
"(",
"c",
"*",
"Command",
")",
"Find",
"(",
"name",
"string",
")",
"*",
"Command",
"{",
"for",
"_",
",",
"cc",
":=",
"range",
"c",
".",
"commands",
"{",
"if",
"cc",
".",
"match",
"(",
"name",
")",
"{",
"return",
"cc",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// Find locates the subcommand with the given name and returns it. If no such
// command can be found Find will return nil.
|
[
"Find",
"locates",
"the",
"subcommand",
"with",
"the",
"given",
"name",
"and",
"returns",
"it",
".",
"If",
"no",
"such",
"command",
"can",
"be",
"found",
"Find",
"will",
"return",
"nil",
"."
] |
c0795c8afcf41dd1d786bebce68636c199b3bb45
|
https://github.com/jessevdk/go-flags/blob/c0795c8afcf41dd1d786bebce68636c199b3bb45/command.go#L104-L112
|
144,559 |
jessevdk/go-flags
|
command.go
|
Args
|
func (c *Command) Args() []*Arg {
ret := make([]*Arg, len(c.args))
copy(ret, c.args)
return ret
}
|
go
|
func (c *Command) Args() []*Arg {
ret := make([]*Arg, len(c.args))
copy(ret, c.args)
return ret
}
|
[
"func",
"(",
"c",
"*",
"Command",
")",
"Args",
"(",
")",
"[",
"]",
"*",
"Arg",
"{",
"ret",
":=",
"make",
"(",
"[",
"]",
"*",
"Arg",
",",
"len",
"(",
"c",
".",
"args",
")",
")",
"\n",
"copy",
"(",
"ret",
",",
"c",
".",
"args",
")",
"\n\n",
"return",
"ret",
"\n",
"}"
] |
// Args returns a list of positional arguments associated with this command.
|
[
"Args",
"returns",
"a",
"list",
"of",
"positional",
"arguments",
"associated",
"with",
"this",
"command",
"."
] |
c0795c8afcf41dd1d786bebce68636c199b3bb45
|
https://github.com/jessevdk/go-flags/blob/c0795c8afcf41dd1d786bebce68636c199b3bb45/command.go#L141-L146
|
144,560 |
motemen/ghq
|
commands.go
|
mkCommandsTemplate
|
func mkCommandsTemplate(genTemplate func(commandDoc) string) string {
template := "{{if false}}"
for _, command := range append(commands) {
template = template + fmt.Sprintf("{{else if (eq .Name %q)}}%s", command.Name, genTemplate(commandDocs[command.Name]))
}
return template + "{{end}}"
}
|
go
|
func mkCommandsTemplate(genTemplate func(commandDoc) string) string {
template := "{{if false}}"
for _, command := range append(commands) {
template = template + fmt.Sprintf("{{else if (eq .Name %q)}}%s", command.Name, genTemplate(commandDocs[command.Name]))
}
return template + "{{end}}"
}
|
[
"func",
"mkCommandsTemplate",
"(",
"genTemplate",
"func",
"(",
"commandDoc",
")",
"string",
")",
"string",
"{",
"template",
":=",
"\"",
"\"",
"\n",
"for",
"_",
",",
"command",
":=",
"range",
"append",
"(",
"commands",
")",
"{",
"template",
"=",
"template",
"+",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"command",
".",
"Name",
",",
"genTemplate",
"(",
"commandDocs",
"[",
"command",
".",
"Name",
"]",
")",
")",
"\n",
"}",
"\n",
"return",
"template",
"+",
"\"",
"\"",
"\n",
"}"
] |
// Makes template conditionals to generate per-command documents.
|
[
"Makes",
"template",
"conditionals",
"to",
"generate",
"per",
"-",
"command",
"documents",
"."
] |
f311c7108b66c3c94d7730882fdf53a170fd6722
|
https://github.com/motemen/ghq/blob/f311c7108b66c3c94d7730882fdf53a170fd6722/commands.go#L105-L111
|
144,561 |
motemen/ghq
|
git.go
|
GitConfigAll
|
func GitConfigAll(key string) ([]string, error) {
value, err := GitConfig("--get-all", key)
if err != nil {
return nil, err
}
// No results found, return an empty slice
if value == "" {
return nil, nil
}
return strings.Split(value, "\000"), nil
}
|
go
|
func GitConfigAll(key string) ([]string, error) {
value, err := GitConfig("--get-all", key)
if err != nil {
return nil, err
}
// No results found, return an empty slice
if value == "" {
return nil, nil
}
return strings.Split(value, "\000"), nil
}
|
[
"func",
"GitConfigAll",
"(",
"key",
"string",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"value",
",",
"err",
":=",
"GitConfig",
"(",
"\"",
"\"",
",",
"key",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"// No results found, return an empty slice",
"if",
"value",
"==",
"\"",
"\"",
"{",
"return",
"nil",
",",
"nil",
"\n",
"}",
"\n\n",
"return",
"strings",
".",
"Split",
"(",
"value",
",",
"\"",
"\\000",
"\"",
")",
",",
"nil",
"\n",
"}"
] |
// GitConfigAll fetches git-config variable of multiple values.
|
[
"GitConfigAll",
"fetches",
"git",
"-",
"config",
"variable",
"of",
"multiple",
"values",
"."
] |
f311c7108b66c3c94d7730882fdf53a170fd6722
|
https://github.com/motemen/ghq/blob/f311c7108b66c3c94d7730882fdf53a170fd6722/git.go#L21-L33
|
144,562 |
motemen/ghq
|
git.go
|
GitConfig
|
func GitConfig(args ...string) (string, error) {
gitArgs := append([]string{"config", "--path", "--null"}, args...)
cmd := exec.Command("git", gitArgs...)
cmd.Stderr = os.Stderr
buf, err := cmd.Output()
if exitError, ok := err.(*exec.ExitError); ok {
if waitStatus, ok := exitError.Sys().(syscall.WaitStatus); ok {
if waitStatus.ExitStatus() == 1 {
// The key was not found, do not treat as an error
return "", nil
}
}
return "", err
}
return strings.TrimRight(string(buf), "\000"), nil
}
|
go
|
func GitConfig(args ...string) (string, error) {
gitArgs := append([]string{"config", "--path", "--null"}, args...)
cmd := exec.Command("git", gitArgs...)
cmd.Stderr = os.Stderr
buf, err := cmd.Output()
if exitError, ok := err.(*exec.ExitError); ok {
if waitStatus, ok := exitError.Sys().(syscall.WaitStatus); ok {
if waitStatus.ExitStatus() == 1 {
// The key was not found, do not treat as an error
return "", nil
}
}
return "", err
}
return strings.TrimRight(string(buf), "\000"), nil
}
|
[
"func",
"GitConfig",
"(",
"args",
"...",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"gitArgs",
":=",
"append",
"(",
"[",
"]",
"string",
"{",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
"}",
",",
"args",
"...",
")",
"\n",
"cmd",
":=",
"exec",
".",
"Command",
"(",
"\"",
"\"",
",",
"gitArgs",
"...",
")",
"\n",
"cmd",
".",
"Stderr",
"=",
"os",
".",
"Stderr",
"\n\n",
"buf",
",",
"err",
":=",
"cmd",
".",
"Output",
"(",
")",
"\n\n",
"if",
"exitError",
",",
"ok",
":=",
"err",
".",
"(",
"*",
"exec",
".",
"ExitError",
")",
";",
"ok",
"{",
"if",
"waitStatus",
",",
"ok",
":=",
"exitError",
".",
"Sys",
"(",
")",
".",
"(",
"syscall",
".",
"WaitStatus",
")",
";",
"ok",
"{",
"if",
"waitStatus",
".",
"ExitStatus",
"(",
")",
"==",
"1",
"{",
"// The key was not found, do not treat as an error",
"return",
"\"",
"\"",
",",
"nil",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"strings",
".",
"TrimRight",
"(",
"string",
"(",
"buf",
")",
",",
"\"",
"\\000",
"\"",
")",
",",
"nil",
"\n",
"}"
] |
// GitConfig invokes 'git config' and handles some errors properly.
|
[
"GitConfig",
"invokes",
"git",
"config",
"and",
"handles",
"some",
"errors",
"properly",
"."
] |
f311c7108b66c3c94d7730882fdf53a170fd6722
|
https://github.com/motemen/ghq/blob/f311c7108b66c3c94d7730882fdf53a170fd6722/git.go#L36-L55
|
144,563 |
motemen/ghq
|
cmdutil/run.go
|
Run
|
func Run(command string, args ...string) error {
cmd := exec.Command(command, args...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
return RunCommand(cmd, false)
}
|
go
|
func Run(command string, args ...string) error {
cmd := exec.Command(command, args...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
return RunCommand(cmd, false)
}
|
[
"func",
"Run",
"(",
"command",
"string",
",",
"args",
"...",
"string",
")",
"error",
"{",
"cmd",
":=",
"exec",
".",
"Command",
"(",
"command",
",",
"args",
"...",
")",
"\n",
"cmd",
".",
"Stdout",
"=",
"os",
".",
"Stdout",
"\n",
"cmd",
".",
"Stderr",
"=",
"os",
".",
"Stderr",
"\n\n",
"return",
"RunCommand",
"(",
"cmd",
",",
"false",
")",
"\n",
"}"
] |
// Run the command
|
[
"Run",
"the",
"command"
] |
f311c7108b66c3c94d7730882fdf53a170fd6722
|
https://github.com/motemen/ghq/blob/f311c7108b66c3c94d7730882fdf53a170fd6722/cmdutil/run.go#L14-L20
|
144,564 |
motemen/ghq
|
cmdutil/run.go
|
RunSilently
|
func RunSilently(command string, args ...string) error {
cmd := exec.Command(command, args...)
cmd.Stdout = ioutil.Discard
cmd.Stderr = ioutil.Discard
return RunCommand(cmd, true)
}
|
go
|
func RunSilently(command string, args ...string) error {
cmd := exec.Command(command, args...)
cmd.Stdout = ioutil.Discard
cmd.Stderr = ioutil.Discard
return RunCommand(cmd, true)
}
|
[
"func",
"RunSilently",
"(",
"command",
"string",
",",
"args",
"...",
"string",
")",
"error",
"{",
"cmd",
":=",
"exec",
".",
"Command",
"(",
"command",
",",
"args",
"...",
")",
"\n",
"cmd",
".",
"Stdout",
"=",
"ioutil",
".",
"Discard",
"\n",
"cmd",
".",
"Stderr",
"=",
"ioutil",
".",
"Discard",
"\n\n",
"return",
"RunCommand",
"(",
"cmd",
",",
"true",
")",
"\n",
"}"
] |
// RunSilently runs the command silently
|
[
"RunSilently",
"runs",
"the",
"command",
"silently"
] |
f311c7108b66c3c94d7730882fdf53a170fd6722
|
https://github.com/motemen/ghq/blob/f311c7108b66c3c94d7730882fdf53a170fd6722/cmdutil/run.go#L23-L29
|
144,565 |
motemen/ghq
|
cmdutil/run.go
|
RunInDir
|
func RunInDir(dir, command string, args ...string) error {
cmd := exec.Command(command, args...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Dir = dir
return RunCommand(cmd, false)
}
|
go
|
func RunInDir(dir, command string, args ...string) error {
cmd := exec.Command(command, args...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Dir = dir
return RunCommand(cmd, false)
}
|
[
"func",
"RunInDir",
"(",
"dir",
",",
"command",
"string",
",",
"args",
"...",
"string",
")",
"error",
"{",
"cmd",
":=",
"exec",
".",
"Command",
"(",
"command",
",",
"args",
"...",
")",
"\n",
"cmd",
".",
"Stdout",
"=",
"os",
".",
"Stdout",
"\n",
"cmd",
".",
"Stderr",
"=",
"os",
".",
"Stderr",
"\n",
"cmd",
".",
"Dir",
"=",
"dir",
"\n\n",
"return",
"RunCommand",
"(",
"cmd",
",",
"false",
")",
"\n",
"}"
] |
// RunInDir runs the command in the specified directory
|
[
"RunInDir",
"runs",
"the",
"command",
"in",
"the",
"specified",
"directory"
] |
f311c7108b66c3c94d7730882fdf53a170fd6722
|
https://github.com/motemen/ghq/blob/f311c7108b66c3c94d7730882fdf53a170fd6722/cmdutil/run.go#L32-L39
|
144,566 |
motemen/ghq
|
cmdutil/run.go
|
RunInDirSilently
|
func RunInDirSilently(dir, command string, args ...string) error {
cmd := exec.Command(command, args...)
cmd.Stdout = ioutil.Discard
cmd.Stderr = ioutil.Discard
cmd.Dir = dir
return RunCommand(cmd, true)
}
|
go
|
func RunInDirSilently(dir, command string, args ...string) error {
cmd := exec.Command(command, args...)
cmd.Stdout = ioutil.Discard
cmd.Stderr = ioutil.Discard
cmd.Dir = dir
return RunCommand(cmd, true)
}
|
[
"func",
"RunInDirSilently",
"(",
"dir",
",",
"command",
"string",
",",
"args",
"...",
"string",
")",
"error",
"{",
"cmd",
":=",
"exec",
".",
"Command",
"(",
"command",
",",
"args",
"...",
")",
"\n",
"cmd",
".",
"Stdout",
"=",
"ioutil",
".",
"Discard",
"\n",
"cmd",
".",
"Stderr",
"=",
"ioutil",
".",
"Discard",
"\n",
"cmd",
".",
"Dir",
"=",
"dir",
"\n\n",
"return",
"RunCommand",
"(",
"cmd",
",",
"true",
")",
"\n",
"}"
] |
// RunInDirSilently run the command in the specified directory silently
|
[
"RunInDirSilently",
"run",
"the",
"command",
"in",
"the",
"specified",
"directory",
"silently"
] |
f311c7108b66c3c94d7730882fdf53a170fd6722
|
https://github.com/motemen/ghq/blob/f311c7108b66c3c94d7730882fdf53a170fd6722/cmdutil/run.go#L42-L49
|
144,567 |
motemen/ghq
|
cmdutil/run.go
|
RunCommand
|
func RunCommand(cmd *exec.Cmd, silent bool) error {
if !silent {
logger.Log(cmd.Args[0], strings.Join(cmd.Args[1:], " "))
}
err := CommandRunner(cmd)
if err != nil {
if execErr, ok := err.(*exec.Error); ok {
logger.Log("warning", fmt.Sprintf("%q: %s", execErr.Name, execErr.Err))
}
return &RunError{cmd, err}
}
return nil
}
|
go
|
func RunCommand(cmd *exec.Cmd, silent bool) error {
if !silent {
logger.Log(cmd.Args[0], strings.Join(cmd.Args[1:], " "))
}
err := CommandRunner(cmd)
if err != nil {
if execErr, ok := err.(*exec.Error); ok {
logger.Log("warning", fmt.Sprintf("%q: %s", execErr.Name, execErr.Err))
}
return &RunError{cmd, err}
}
return nil
}
|
[
"func",
"RunCommand",
"(",
"cmd",
"*",
"exec",
".",
"Cmd",
",",
"silent",
"bool",
")",
"error",
"{",
"if",
"!",
"silent",
"{",
"logger",
".",
"Log",
"(",
"cmd",
".",
"Args",
"[",
"0",
"]",
",",
"strings",
".",
"Join",
"(",
"cmd",
".",
"Args",
"[",
"1",
":",
"]",
",",
"\"",
"\"",
")",
")",
"\n",
"}",
"\n",
"err",
":=",
"CommandRunner",
"(",
"cmd",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"if",
"execErr",
",",
"ok",
":=",
"err",
".",
"(",
"*",
"exec",
".",
"Error",
")",
";",
"ok",
"{",
"logger",
".",
"Log",
"(",
"\"",
"\"",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"execErr",
".",
"Name",
",",
"execErr",
".",
"Err",
")",
")",
"\n",
"}",
"\n",
"return",
"&",
"RunError",
"{",
"cmd",
",",
"err",
"}",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// RunCommand run the command
|
[
"RunCommand",
"run",
"the",
"command"
] |
f311c7108b66c3c94d7730882fdf53a170fd6722
|
https://github.com/motemen/ghq/blob/f311c7108b66c3c94d7730882fdf53a170fd6722/cmdutil/run.go#L60-L73
|
144,568 |
motemen/ghq
|
cmdutil/run.go
|
Error
|
func (e *RunError) Error() string {
return fmt.Sprintf("%s: %s", e.Command.Path, e.ExecError)
}
|
go
|
func (e *RunError) Error() string {
return fmt.Sprintf("%s: %s", e.Command.Path, e.ExecError)
}
|
[
"func",
"(",
"e",
"*",
"RunError",
")",
"Error",
"(",
")",
"string",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"e",
".",
"Command",
".",
"Path",
",",
"e",
".",
"ExecError",
")",
"\n",
"}"
] |
// Error to implement error interface
|
[
"Error",
"to",
"implement",
"error",
"interface"
] |
f311c7108b66c3c94d7730882fdf53a170fd6722
|
https://github.com/motemen/ghq/blob/f311c7108b66c3c94d7730882fdf53a170fd6722/cmdutil/run.go#L82-L84
|
144,569 |
motemen/ghq
|
local_repository.go
|
Matches
|
func (repo *LocalRepository) Matches(pathQuery string) bool {
for _, p := range repo.Subpaths() {
if p == pathQuery {
return true
}
}
return false
}
|
go
|
func (repo *LocalRepository) Matches(pathQuery string) bool {
for _, p := range repo.Subpaths() {
if p == pathQuery {
return true
}
}
return false
}
|
[
"func",
"(",
"repo",
"*",
"LocalRepository",
")",
"Matches",
"(",
"pathQuery",
"string",
")",
"bool",
"{",
"for",
"_",
",",
"p",
":=",
"range",
"repo",
".",
"Subpaths",
"(",
")",
"{",
"if",
"p",
"==",
"pathQuery",
"{",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"false",
"\n",
"}"
] |
// Matches checks if any subpath of the local repository equals the query.
|
[
"Matches",
"checks",
"if",
"any",
"subpath",
"of",
"the",
"local",
"repository",
"equals",
"the",
"query",
"."
] |
f311c7108b66c3c94d7730882fdf53a170fd6722
|
https://github.com/motemen/ghq/blob/f311c7108b66c3c94d7730882fdf53a170fd6722/local_repository.go#L112-L120
|
144,570 |
openzipkin-contrib/zipkin-go-opentracing
|
zipkin-recorder.go
|
annotate
|
func annotate(span *zipkincore.Span, timestamp time.Time, value string, host *zipkincore.Endpoint) {
if timestamp.IsZero() {
timestamp = time.Now()
}
span.Annotations = append(span.Annotations, &zipkincore.Annotation{
Timestamp: timestamp.UnixNano() / 1e3,
Value: value,
Host: host,
})
}
|
go
|
func annotate(span *zipkincore.Span, timestamp time.Time, value string, host *zipkincore.Endpoint) {
if timestamp.IsZero() {
timestamp = time.Now()
}
span.Annotations = append(span.Annotations, &zipkincore.Annotation{
Timestamp: timestamp.UnixNano() / 1e3,
Value: value,
Host: host,
})
}
|
[
"func",
"annotate",
"(",
"span",
"*",
"zipkincore",
".",
"Span",
",",
"timestamp",
"time",
".",
"Time",
",",
"value",
"string",
",",
"host",
"*",
"zipkincore",
".",
"Endpoint",
")",
"{",
"if",
"timestamp",
".",
"IsZero",
"(",
")",
"{",
"timestamp",
"=",
"time",
".",
"Now",
"(",
")",
"\n",
"}",
"\n",
"span",
".",
"Annotations",
"=",
"append",
"(",
"span",
".",
"Annotations",
",",
"&",
"zipkincore",
".",
"Annotation",
"{",
"Timestamp",
":",
"timestamp",
".",
"UnixNano",
"(",
")",
"/",
"1e3",
",",
"Value",
":",
"value",
",",
"Host",
":",
"host",
",",
"}",
")",
"\n",
"}"
] |
// annotate annotates the span with the given value.
|
[
"annotate",
"annotates",
"the",
"span",
"with",
"the",
"given",
"value",
"."
] |
f0f479ad013a498e4cbfb369414e5d3880903779
|
https://github.com/openzipkin-contrib/zipkin-go-opentracing/blob/f0f479ad013a498e4cbfb369414e5d3880903779/zipkin-recorder.go#L191-L200
|
144,571 |
openzipkin-contrib/zipkin-go-opentracing
|
examples/cli_with_2_services/svc2/httpclient.go
|
NewHTTPClient
|
func NewHTTPClient(tracer opentracing.Tracer, baseURL string) Service {
return &client{
baseURL: baseURL,
httpClient: &http.Client{},
tracer: tracer,
traceRequest: middleware.ToHTTPRequest(tracer),
}
}
|
go
|
func NewHTTPClient(tracer opentracing.Tracer, baseURL string) Service {
return &client{
baseURL: baseURL,
httpClient: &http.Client{},
tracer: tracer,
traceRequest: middleware.ToHTTPRequest(tracer),
}
}
|
[
"func",
"NewHTTPClient",
"(",
"tracer",
"opentracing",
".",
"Tracer",
",",
"baseURL",
"string",
")",
"Service",
"{",
"return",
"&",
"client",
"{",
"baseURL",
":",
"baseURL",
",",
"httpClient",
":",
"&",
"http",
".",
"Client",
"{",
"}",
",",
"tracer",
":",
"tracer",
",",
"traceRequest",
":",
"middleware",
".",
"ToHTTPRequest",
"(",
"tracer",
")",
",",
"}",
"\n",
"}"
] |
// NewHTTPClient returns a new client instance to our svc2 using the HTTP
// transport.
|
[
"NewHTTPClient",
"returns",
"a",
"new",
"client",
"instance",
"to",
"our",
"svc2",
"using",
"the",
"HTTP",
"transport",
"."
] |
f0f479ad013a498e4cbfb369414e5d3880903779
|
https://github.com/openzipkin-contrib/zipkin-go-opentracing/blob/f0f479ad013a498e4cbfb369414e5d3880903779/examples/cli_with_2_services/svc2/httpclient.go#L75-L82
|
144,572 |
openzipkin-contrib/zipkin-go-opentracing
|
logger.go
|
Log
|
func (l *wrappedLogger) Log(k ...interface{}) error {
if len(k)%2 == 1 {
k = append(k, ErrMissingValue)
}
o := make([]string, len(k)/2)
for i := 0; i < len(k); i += 2 {
o[i/2] = fmt.Sprintf("%s=%q", k[i], k[i+1])
}
l.l.Println(strings.Join(o, " "))
return nil
}
|
go
|
func (l *wrappedLogger) Log(k ...interface{}) error {
if len(k)%2 == 1 {
k = append(k, ErrMissingValue)
}
o := make([]string, len(k)/2)
for i := 0; i < len(k); i += 2 {
o[i/2] = fmt.Sprintf("%s=%q", k[i], k[i+1])
}
l.l.Println(strings.Join(o, " "))
return nil
}
|
[
"func",
"(",
"l",
"*",
"wrappedLogger",
")",
"Log",
"(",
"k",
"...",
"interface",
"{",
"}",
")",
"error",
"{",
"if",
"len",
"(",
"k",
")",
"%",
"2",
"==",
"1",
"{",
"k",
"=",
"append",
"(",
"k",
",",
"ErrMissingValue",
")",
"\n",
"}",
"\n",
"o",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"len",
"(",
"k",
")",
"/",
"2",
")",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"len",
"(",
"k",
")",
";",
"i",
"+=",
"2",
"{",
"o",
"[",
"i",
"/",
"2",
"]",
"=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"k",
"[",
"i",
"]",
",",
"k",
"[",
"i",
"+",
"1",
"]",
")",
"\n",
"}",
"\n",
"l",
".",
"l",
".",
"Println",
"(",
"strings",
".",
"Join",
"(",
"o",
",",
"\"",
"\"",
")",
")",
"\n",
"return",
"nil",
"\n",
"}"
] |
// Log implements Logger
|
[
"Log",
"implements",
"Logger"
] |
f0f479ad013a498e4cbfb369414e5d3880903779
|
https://github.com/openzipkin-contrib/zipkin-go-opentracing/blob/f0f479ad013a498e4cbfb369414e5d3880903779/logger.go#L38-L48
|
144,573 |
openzipkin-contrib/zipkin-go-opentracing
|
examples/cli_with_2_services/svc1/httpserver.go
|
concatHandler
|
func (s *httpService) concatHandler(w http.ResponseWriter, req *http.Request) {
// parse query parameters
v := req.URL.Query()
result, err := s.service.Concat(req.Context(), v.Get("a"), v.Get("b"))
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
// return the result
w.Write([]byte(result))
}
|
go
|
func (s *httpService) concatHandler(w http.ResponseWriter, req *http.Request) {
// parse query parameters
v := req.URL.Query()
result, err := s.service.Concat(req.Context(), v.Get("a"), v.Get("b"))
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
// return the result
w.Write([]byte(result))
}
|
[
"func",
"(",
"s",
"*",
"httpService",
")",
"concatHandler",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"req",
"*",
"http",
".",
"Request",
")",
"{",
"// parse query parameters",
"v",
":=",
"req",
".",
"URL",
".",
"Query",
"(",
")",
"\n",
"result",
",",
"err",
":=",
"s",
".",
"service",
".",
"Concat",
"(",
"req",
".",
"Context",
"(",
")",
",",
"v",
".",
"Get",
"(",
"\"",
"\"",
")",
",",
"v",
".",
"Get",
"(",
"\"",
"\"",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"http",
".",
"Error",
"(",
"w",
",",
"err",
".",
"Error",
"(",
")",
",",
"http",
".",
"StatusBadRequest",
")",
"\n",
"return",
"\n",
"}",
"\n",
"// return the result",
"w",
".",
"Write",
"(",
"[",
"]",
"byte",
"(",
"result",
")",
")",
"\n",
"}"
] |
// concatHandler is our HTTP HandlerFunc for a Concat request.
|
[
"concatHandler",
"is",
"our",
"HTTP",
"HandlerFunc",
"for",
"a",
"Concat",
"request",
"."
] |
f0f479ad013a498e4cbfb369414e5d3880903779
|
https://github.com/openzipkin-contrib/zipkin-go-opentracing/blob/f0f479ad013a498e4cbfb369414e5d3880903779/examples/cli_with_2_services/svc1/httpserver.go#L20-L30
|
144,574 |
openzipkin-contrib/zipkin-go-opentracing
|
examples/cli_with_2_services/svc1/httpserver.go
|
sumHandler
|
func (s *httpService) sumHandler(w http.ResponseWriter, req *http.Request) {
// parse query parameters
v := req.URL.Query()
a, err := strconv.ParseInt(v.Get("a"), 10, 64)
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
b, err := strconv.ParseInt(v.Get("b"), 10, 64)
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
// call our Sum binding
result, err := s.service.Sum(req.Context(), a, b)
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
// return the result
w.Write([]byte(fmt.Sprintf("%d", result)))
}
|
go
|
func (s *httpService) sumHandler(w http.ResponseWriter, req *http.Request) {
// parse query parameters
v := req.URL.Query()
a, err := strconv.ParseInt(v.Get("a"), 10, 64)
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
b, err := strconv.ParseInt(v.Get("b"), 10, 64)
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
// call our Sum binding
result, err := s.service.Sum(req.Context(), a, b)
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
// return the result
w.Write([]byte(fmt.Sprintf("%d", result)))
}
|
[
"func",
"(",
"s",
"*",
"httpService",
")",
"sumHandler",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"req",
"*",
"http",
".",
"Request",
")",
"{",
"// parse query parameters",
"v",
":=",
"req",
".",
"URL",
".",
"Query",
"(",
")",
"\n",
"a",
",",
"err",
":=",
"strconv",
".",
"ParseInt",
"(",
"v",
".",
"Get",
"(",
"\"",
"\"",
")",
",",
"10",
",",
"64",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"http",
".",
"Error",
"(",
"w",
",",
"err",
".",
"Error",
"(",
")",
",",
"http",
".",
"StatusBadRequest",
")",
"\n",
"return",
"\n",
"}",
"\n",
"b",
",",
"err",
":=",
"strconv",
".",
"ParseInt",
"(",
"v",
".",
"Get",
"(",
"\"",
"\"",
")",
",",
"10",
",",
"64",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"http",
".",
"Error",
"(",
"w",
",",
"err",
".",
"Error",
"(",
")",
",",
"http",
".",
"StatusBadRequest",
")",
"\n",
"return",
"\n",
"}",
"\n",
"// call our Sum binding",
"result",
",",
"err",
":=",
"s",
".",
"service",
".",
"Sum",
"(",
"req",
".",
"Context",
"(",
")",
",",
"a",
",",
"b",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"http",
".",
"Error",
"(",
"w",
",",
"err",
".",
"Error",
"(",
")",
",",
"http",
".",
"StatusBadRequest",
")",
"\n",
"return",
"\n",
"}",
"\n",
"// return the result",
"w",
".",
"Write",
"(",
"[",
"]",
"byte",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"result",
")",
")",
")",
"\n",
"}"
] |
// sumHandler is our HTTP Handlerfunc for a Sum request.
|
[
"sumHandler",
"is",
"our",
"HTTP",
"Handlerfunc",
"for",
"a",
"Sum",
"request",
"."
] |
f0f479ad013a498e4cbfb369414e5d3880903779
|
https://github.com/openzipkin-contrib/zipkin-go-opentracing/blob/f0f479ad013a498e4cbfb369414e5d3880903779/examples/cli_with_2_services/svc1/httpserver.go#L33-L54
|
144,575 |
openzipkin-contrib/zipkin-go-opentracing
|
examples/cli_with_2_services/svc1/httpserver.go
|
NewHTTPHandler
|
func NewHTTPHandler(tracer opentracing.Tracer, service Service) http.Handler {
// Create our HTTP Service.
svc := &httpService{service: service}
// Create the mux.
mux := http.NewServeMux()
// Create the Concat handler.
var concatHandler http.Handler
concatHandler = http.HandlerFunc(svc.concatHandler)
// Wrap the Concat handler with our tracing middleware.
concatHandler = middleware.FromHTTPRequest(tracer, "Concat")(concatHandler)
// Create the Sum handler.
var sumHandler http.Handler
sumHandler = http.HandlerFunc(svc.sumHandler)
// Wrap the Sum handler with our tracing middleware.
sumHandler = middleware.FromHTTPRequest(tracer, "Sum")(sumHandler)
// Wire up the mux.
mux.Handle("/concat/", concatHandler)
mux.Handle("/sum/", sumHandler)
// Return the mux.
return mux
}
|
go
|
func NewHTTPHandler(tracer opentracing.Tracer, service Service) http.Handler {
// Create our HTTP Service.
svc := &httpService{service: service}
// Create the mux.
mux := http.NewServeMux()
// Create the Concat handler.
var concatHandler http.Handler
concatHandler = http.HandlerFunc(svc.concatHandler)
// Wrap the Concat handler with our tracing middleware.
concatHandler = middleware.FromHTTPRequest(tracer, "Concat")(concatHandler)
// Create the Sum handler.
var sumHandler http.Handler
sumHandler = http.HandlerFunc(svc.sumHandler)
// Wrap the Sum handler with our tracing middleware.
sumHandler = middleware.FromHTTPRequest(tracer, "Sum")(sumHandler)
// Wire up the mux.
mux.Handle("/concat/", concatHandler)
mux.Handle("/sum/", sumHandler)
// Return the mux.
return mux
}
|
[
"func",
"NewHTTPHandler",
"(",
"tracer",
"opentracing",
".",
"Tracer",
",",
"service",
"Service",
")",
"http",
".",
"Handler",
"{",
"// Create our HTTP Service.",
"svc",
":=",
"&",
"httpService",
"{",
"service",
":",
"service",
"}",
"\n\n",
"// Create the mux.",
"mux",
":=",
"http",
".",
"NewServeMux",
"(",
")",
"\n\n",
"// Create the Concat handler.",
"var",
"concatHandler",
"http",
".",
"Handler",
"\n",
"concatHandler",
"=",
"http",
".",
"HandlerFunc",
"(",
"svc",
".",
"concatHandler",
")",
"\n\n",
"// Wrap the Concat handler with our tracing middleware.",
"concatHandler",
"=",
"middleware",
".",
"FromHTTPRequest",
"(",
"tracer",
",",
"\"",
"\"",
")",
"(",
"concatHandler",
")",
"\n\n",
"// Create the Sum handler.",
"var",
"sumHandler",
"http",
".",
"Handler",
"\n",
"sumHandler",
"=",
"http",
".",
"HandlerFunc",
"(",
"svc",
".",
"sumHandler",
")",
"\n\n",
"// Wrap the Sum handler with our tracing middleware.",
"sumHandler",
"=",
"middleware",
".",
"FromHTTPRequest",
"(",
"tracer",
",",
"\"",
"\"",
")",
"(",
"sumHandler",
")",
"\n\n",
"// Wire up the mux.",
"mux",
".",
"Handle",
"(",
"\"",
"\"",
",",
"concatHandler",
")",
"\n",
"mux",
".",
"Handle",
"(",
"\"",
"\"",
",",
"sumHandler",
")",
"\n\n",
"// Return the mux.",
"return",
"mux",
"\n",
"}"
] |
// NewHTTPHandler returns a new HTTP handler our svc1.
|
[
"NewHTTPHandler",
"returns",
"a",
"new",
"HTTP",
"handler",
"our",
"svc1",
"."
] |
f0f479ad013a498e4cbfb369414e5d3880903779
|
https://github.com/openzipkin-contrib/zipkin-go-opentracing/blob/f0f479ad013a498e4cbfb369414e5d3880903779/examples/cli_with_2_services/svc1/httpserver.go#L57-L84
|
144,576 |
openzipkin-contrib/zipkin-go-opentracing
|
collector-kafka.go
|
KafkaProducer
|
func KafkaProducer(p sarama.AsyncProducer) KafkaOption {
return func(c *KafkaCollector) { c.producer = p }
}
|
go
|
func KafkaProducer(p sarama.AsyncProducer) KafkaOption {
return func(c *KafkaCollector) { c.producer = p }
}
|
[
"func",
"KafkaProducer",
"(",
"p",
"sarama",
".",
"AsyncProducer",
")",
"KafkaOption",
"{",
"return",
"func",
"(",
"c",
"*",
"KafkaCollector",
")",
"{",
"c",
".",
"producer",
"=",
"p",
"}",
"\n",
"}"
] |
// KafkaProducer sets the producer used to produce to Kafka.
|
[
"KafkaProducer",
"sets",
"the",
"producer",
"used",
"to",
"produce",
"to",
"Kafka",
"."
] |
f0f479ad013a498e4cbfb369414e5d3880903779
|
https://github.com/openzipkin-contrib/zipkin-go-opentracing/blob/f0f479ad013a498e4cbfb369414e5d3880903779/collector-kafka.go#L34-L36
|
144,577 |
openzipkin-contrib/zipkin-go-opentracing
|
collector-scribe.go
|
ScribeBatchInterval
|
func ScribeBatchInterval(d time.Duration) ScribeOption {
return func(s *ScribeCollector) { s.batchInterval = d }
}
|
go
|
func ScribeBatchInterval(d time.Duration) ScribeOption {
return func(s *ScribeCollector) { s.batchInterval = d }
}
|
[
"func",
"ScribeBatchInterval",
"(",
"d",
"time",
".",
"Duration",
")",
"ScribeOption",
"{",
"return",
"func",
"(",
"s",
"*",
"ScribeCollector",
")",
"{",
"s",
".",
"batchInterval",
"=",
"d",
"}",
"\n",
"}"
] |
// ScribeBatchInterval sets the maximum duration we will buffer traces before
// emitting them to the collector. The default batch interval is 1 second.
|
[
"ScribeBatchInterval",
"sets",
"the",
"maximum",
"duration",
"we",
"will",
"buffer",
"traces",
"before",
"emitting",
"them",
"to",
"the",
"collector",
".",
"The",
"default",
"batch",
"interval",
"is",
"1",
"second",
"."
] |
f0f479ad013a498e4cbfb369414e5d3880903779
|
https://github.com/openzipkin-contrib/zipkin-go-opentracing/blob/f0f479ad013a498e4cbfb369414e5d3880903779/collector-scribe.go#L69-L71
|
144,578 |
openzipkin-contrib/zipkin-go-opentracing
|
tracer.go
|
WithSampler
|
func WithSampler(sampler Sampler) TracerOption {
return func(opts *TracerOptions) error {
opts.shouldSample = sampler
return nil
}
}
|
go
|
func WithSampler(sampler Sampler) TracerOption {
return func(opts *TracerOptions) error {
opts.shouldSample = sampler
return nil
}
}
|
[
"func",
"WithSampler",
"(",
"sampler",
"Sampler",
")",
"TracerOption",
"{",
"return",
"func",
"(",
"opts",
"*",
"TracerOptions",
")",
"error",
"{",
"opts",
".",
"shouldSample",
"=",
"sampler",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] |
// WithSampler allows one to add a Sampler function
|
[
"WithSampler",
"allows",
"one",
"to",
"add",
"a",
"Sampler",
"function"
] |
f0f479ad013a498e4cbfb369414e5d3880903779
|
https://github.com/openzipkin-contrib/zipkin-go-opentracing/blob/f0f479ad013a498e4cbfb369414e5d3880903779/tracer.go#L120-L125
|
144,579 |
openzipkin-contrib/zipkin-go-opentracing
|
tracer.go
|
DebugMode
|
func DebugMode(val bool) TracerOption {
return func(opts *TracerOptions) error {
opts.debugMode = val
return nil
}
}
|
go
|
func DebugMode(val bool) TracerOption {
return func(opts *TracerOptions) error {
opts.debugMode = val
return nil
}
}
|
[
"func",
"DebugMode",
"(",
"val",
"bool",
")",
"TracerOption",
"{",
"return",
"func",
"(",
"opts",
"*",
"TracerOptions",
")",
"error",
"{",
"opts",
".",
"debugMode",
"=",
"val",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] |
// DebugMode allows to set the tracer to Zipkin debug mode
|
[
"DebugMode",
"allows",
"to",
"set",
"the",
"tracer",
"to",
"Zipkin",
"debug",
"mode"
] |
f0f479ad013a498e4cbfb369414e5d3880903779
|
https://github.com/openzipkin-contrib/zipkin-go-opentracing/blob/f0f479ad013a498e4cbfb369414e5d3880903779/tracer.go#L189-L194
|
144,580 |
openzipkin-contrib/zipkin-go-opentracing
|
tracer.go
|
NewTracer
|
func NewTracer(recorder SpanRecorder, options ...TracerOption) (opentracing.Tracer, error) {
opts := &TracerOptions{
recorder: recorder,
shouldSample: alwaysSample,
trimUnsampledSpans: false,
newSpanEventListener: func() func(SpanEvent) { return nil },
logger: &nopLogger{},
debugAssertSingleGoroutine: false,
debugAssertUseAfterFinish: false,
clientServerSameSpan: true,
debugMode: false,
traceID128Bit: false,
maxLogsPerSpan: 10000,
observer: nil,
}
for _, o := range options {
err := o(opts)
if err != nil {
return nil, err
}
}
rval := &tracerImpl{options: *opts}
rval.textPropagator = &textMapPropagator{rval}
rval.binaryPropagator = &binaryPropagator{rval}
rval.accessorPropagator = &accessorPropagator{rval}
return rval, nil
}
|
go
|
func NewTracer(recorder SpanRecorder, options ...TracerOption) (opentracing.Tracer, error) {
opts := &TracerOptions{
recorder: recorder,
shouldSample: alwaysSample,
trimUnsampledSpans: false,
newSpanEventListener: func() func(SpanEvent) { return nil },
logger: &nopLogger{},
debugAssertSingleGoroutine: false,
debugAssertUseAfterFinish: false,
clientServerSameSpan: true,
debugMode: false,
traceID128Bit: false,
maxLogsPerSpan: 10000,
observer: nil,
}
for _, o := range options {
err := o(opts)
if err != nil {
return nil, err
}
}
rval := &tracerImpl{options: *opts}
rval.textPropagator = &textMapPropagator{rval}
rval.binaryPropagator = &binaryPropagator{rval}
rval.accessorPropagator = &accessorPropagator{rval}
return rval, nil
}
|
[
"func",
"NewTracer",
"(",
"recorder",
"SpanRecorder",
",",
"options",
"...",
"TracerOption",
")",
"(",
"opentracing",
".",
"Tracer",
",",
"error",
")",
"{",
"opts",
":=",
"&",
"TracerOptions",
"{",
"recorder",
":",
"recorder",
",",
"shouldSample",
":",
"alwaysSample",
",",
"trimUnsampledSpans",
":",
"false",
",",
"newSpanEventListener",
":",
"func",
"(",
")",
"func",
"(",
"SpanEvent",
")",
"{",
"return",
"nil",
"}",
",",
"logger",
":",
"&",
"nopLogger",
"{",
"}",
",",
"debugAssertSingleGoroutine",
":",
"false",
",",
"debugAssertUseAfterFinish",
":",
"false",
",",
"clientServerSameSpan",
":",
"true",
",",
"debugMode",
":",
"false",
",",
"traceID128Bit",
":",
"false",
",",
"maxLogsPerSpan",
":",
"10000",
",",
"observer",
":",
"nil",
",",
"}",
"\n",
"for",
"_",
",",
"o",
":=",
"range",
"options",
"{",
"err",
":=",
"o",
"(",
"opts",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"rval",
":=",
"&",
"tracerImpl",
"{",
"options",
":",
"*",
"opts",
"}",
"\n",
"rval",
".",
"textPropagator",
"=",
"&",
"textMapPropagator",
"{",
"rval",
"}",
"\n",
"rval",
".",
"binaryPropagator",
"=",
"&",
"binaryPropagator",
"{",
"rval",
"}",
"\n",
"rval",
".",
"accessorPropagator",
"=",
"&",
"accessorPropagator",
"{",
"rval",
"}",
"\n",
"return",
"rval",
",",
"nil",
"\n",
"}"
] |
// NewTracer creates a new OpenTracing compatible Zipkin Tracer.
|
[
"NewTracer",
"creates",
"a",
"new",
"OpenTracing",
"compatible",
"Zipkin",
"Tracer",
"."
] |
f0f479ad013a498e4cbfb369414e5d3880903779
|
https://github.com/openzipkin-contrib/zipkin-go-opentracing/blob/f0f479ad013a498e4cbfb369414e5d3880903779/tracer.go#L224-L250
|
144,581 |
openzipkin-contrib/zipkin-go-opentracing
|
tracer.go
|
WithObserver
|
func WithObserver(observer otobserver.Observer) TracerOption {
return func(opts *TracerOptions) error {
opts.observer = observer
return nil
}
}
|
go
|
func WithObserver(observer otobserver.Observer) TracerOption {
return func(opts *TracerOptions) error {
opts.observer = observer
return nil
}
}
|
[
"func",
"WithObserver",
"(",
"observer",
"otobserver",
".",
"Observer",
")",
"TracerOption",
"{",
"return",
"func",
"(",
"opts",
"*",
"TracerOptions",
")",
"error",
"{",
"opts",
".",
"observer",
"=",
"observer",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] |
// WithObserver assigns an initialized observer to opts.observer
|
[
"WithObserver",
"assigns",
"an",
"initialized",
"observer",
"to",
"opts",
".",
"observer"
] |
f0f479ad013a498e4cbfb369414e5d3880903779
|
https://github.com/openzipkin-contrib/zipkin-go-opentracing/blob/f0f479ad013a498e4cbfb369414e5d3880903779/tracer.go#L435-L440
|
144,582 |
openzipkin-contrib/zipkin-go-opentracing
|
collector-http.go
|
HTTPTimeout
|
func HTTPTimeout(duration time.Duration) HTTPOption {
return func(c *HTTPCollector) { c.client.Timeout = duration }
}
|
go
|
func HTTPTimeout(duration time.Duration) HTTPOption {
return func(c *HTTPCollector) { c.client.Timeout = duration }
}
|
[
"func",
"HTTPTimeout",
"(",
"duration",
"time",
".",
"Duration",
")",
"HTTPOption",
"{",
"return",
"func",
"(",
"c",
"*",
"HTTPCollector",
")",
"{",
"c",
".",
"client",
".",
"Timeout",
"=",
"duration",
"}",
"\n",
"}"
] |
// HTTPTimeout sets maximum timeout for http request.
|
[
"HTTPTimeout",
"sets",
"maximum",
"timeout",
"for",
"http",
"request",
"."
] |
f0f479ad013a498e4cbfb369414e5d3880903779
|
https://github.com/openzipkin-contrib/zipkin-go-opentracing/blob/f0f479ad013a498e4cbfb369414e5d3880903779/collector-http.go#L53-L55
|
144,583 |
openzipkin-contrib/zipkin-go-opentracing
|
collector-http.go
|
HTTPBatchInterval
|
func HTTPBatchInterval(d time.Duration) HTTPOption {
return func(c *HTTPCollector) { c.batchInterval = d }
}
|
go
|
func HTTPBatchInterval(d time.Duration) HTTPOption {
return func(c *HTTPCollector) { c.batchInterval = d }
}
|
[
"func",
"HTTPBatchInterval",
"(",
"d",
"time",
".",
"Duration",
")",
"HTTPOption",
"{",
"return",
"func",
"(",
"c",
"*",
"HTTPCollector",
")",
"{",
"c",
".",
"batchInterval",
"=",
"d",
"}",
"\n",
"}"
] |
// HTTPBatchInterval sets the maximum duration we will buffer traces before
// emitting them to the collector. The default batch interval is 1 second.
|
[
"HTTPBatchInterval",
"sets",
"the",
"maximum",
"duration",
"we",
"will",
"buffer",
"traces",
"before",
"emitting",
"them",
"to",
"the",
"collector",
".",
"The",
"default",
"batch",
"interval",
"is",
"1",
"second",
"."
] |
f0f479ad013a498e4cbfb369414e5d3880903779
|
https://github.com/openzipkin-contrib/zipkin-go-opentracing/blob/f0f479ad013a498e4cbfb369414e5d3880903779/collector-http.go#L72-L74
|
144,584 |
openzipkin-contrib/zipkin-go-opentracing
|
collector-http.go
|
HTTPClient
|
func HTTPClient(client *http.Client) HTTPOption {
return func(c *HTTPCollector) { c.client = client }
}
|
go
|
func HTTPClient(client *http.Client) HTTPOption {
return func(c *HTTPCollector) { c.client = client }
}
|
[
"func",
"HTTPClient",
"(",
"client",
"*",
"http",
".",
"Client",
")",
"HTTPOption",
"{",
"return",
"func",
"(",
"c",
"*",
"HTTPCollector",
")",
"{",
"c",
".",
"client",
"=",
"client",
"}",
"\n",
"}"
] |
// HTTPClient sets a custom http client to use.
|
[
"HTTPClient",
"sets",
"a",
"custom",
"http",
"client",
"to",
"use",
"."
] |
f0f479ad013a498e4cbfb369414e5d3880903779
|
https://github.com/openzipkin-contrib/zipkin-go-opentracing/blob/f0f479ad013a498e4cbfb369414e5d3880903779/collector-http.go#L77-L79
|
144,585 |
openzipkin-contrib/zipkin-go-opentracing
|
collector-http.go
|
NewHTTPCollector
|
func NewHTTPCollector(url string, options ...HTTPOption) (Collector, error) {
c := &HTTPCollector{
logger: NewNopLogger(),
url: url,
client: &http.Client{Timeout: defaultHTTPTimeout},
batchInterval: defaultHTTPBatchInterval * time.Second,
batchSize: defaultHTTPBatchSize,
maxBacklog: defaultHTTPMaxBacklog,
quit: make(chan struct{}, 1),
shutdown: make(chan error, 1),
}
for _, option := range options {
option(c)
}
// spanc can immediately accept maxBacklog spans and everything else is dropped.
c.spanc = make(chan *zipkincore.Span, c.maxBacklog)
go c.loop()
return c, nil
}
|
go
|
func NewHTTPCollector(url string, options ...HTTPOption) (Collector, error) {
c := &HTTPCollector{
logger: NewNopLogger(),
url: url,
client: &http.Client{Timeout: defaultHTTPTimeout},
batchInterval: defaultHTTPBatchInterval * time.Second,
batchSize: defaultHTTPBatchSize,
maxBacklog: defaultHTTPMaxBacklog,
quit: make(chan struct{}, 1),
shutdown: make(chan error, 1),
}
for _, option := range options {
option(c)
}
// spanc can immediately accept maxBacklog spans and everything else is dropped.
c.spanc = make(chan *zipkincore.Span, c.maxBacklog)
go c.loop()
return c, nil
}
|
[
"func",
"NewHTTPCollector",
"(",
"url",
"string",
",",
"options",
"...",
"HTTPOption",
")",
"(",
"Collector",
",",
"error",
")",
"{",
"c",
":=",
"&",
"HTTPCollector",
"{",
"logger",
":",
"NewNopLogger",
"(",
")",
",",
"url",
":",
"url",
",",
"client",
":",
"&",
"http",
".",
"Client",
"{",
"Timeout",
":",
"defaultHTTPTimeout",
"}",
",",
"batchInterval",
":",
"defaultHTTPBatchInterval",
"*",
"time",
".",
"Second",
",",
"batchSize",
":",
"defaultHTTPBatchSize",
",",
"maxBacklog",
":",
"defaultHTTPMaxBacklog",
",",
"quit",
":",
"make",
"(",
"chan",
"struct",
"{",
"}",
",",
"1",
")",
",",
"shutdown",
":",
"make",
"(",
"chan",
"error",
",",
"1",
")",
",",
"}",
"\n\n",
"for",
"_",
",",
"option",
":=",
"range",
"options",
"{",
"option",
"(",
"c",
")",
"\n",
"}",
"\n\n",
"// spanc can immediately accept maxBacklog spans and everything else is dropped.",
"c",
".",
"spanc",
"=",
"make",
"(",
"chan",
"*",
"zipkincore",
".",
"Span",
",",
"c",
".",
"maxBacklog",
")",
"\n\n",
"go",
"c",
".",
"loop",
"(",
")",
"\n",
"return",
"c",
",",
"nil",
"\n",
"}"
] |
// NewHTTPCollector returns a new HTTP-backend Collector. url should be a http
// url for handle post request. timeout is passed to http client. queueSize control
// the maximum size of buffer of async queue. The logger is used to log errors,
// such as send failures;
|
[
"NewHTTPCollector",
"returns",
"a",
"new",
"HTTP",
"-",
"backend",
"Collector",
".",
"url",
"should",
"be",
"a",
"http",
"url",
"for",
"handle",
"post",
"request",
".",
"timeout",
"is",
"passed",
"to",
"http",
"client",
".",
"queueSize",
"control",
"the",
"maximum",
"size",
"of",
"buffer",
"of",
"async",
"queue",
".",
"The",
"logger",
"is",
"used",
"to",
"log",
"errors",
"such",
"as",
"send",
"failures",
";"
] |
f0f479ad013a498e4cbfb369414e5d3880903779
|
https://github.com/openzipkin-contrib/zipkin-go-opentracing/blob/f0f479ad013a498e4cbfb369414e5d3880903779/collector-http.go#L91-L112
|
144,586 |
openzipkin-contrib/zipkin-go-opentracing
|
collector-http.go
|
Collect
|
func (c *HTTPCollector) Collect(s *zipkincore.Span) error {
select {
case c.spanc <- s:
// Accepted.
case <-c.quit:
// Collector concurrently closed.
default:
c.logger.Log("msg", "queue full, disposing spans.", "size", len(c.spanc))
}
return nil
}
|
go
|
func (c *HTTPCollector) Collect(s *zipkincore.Span) error {
select {
case c.spanc <- s:
// Accepted.
case <-c.quit:
// Collector concurrently closed.
default:
c.logger.Log("msg", "queue full, disposing spans.", "size", len(c.spanc))
}
return nil
}
|
[
"func",
"(",
"c",
"*",
"HTTPCollector",
")",
"Collect",
"(",
"s",
"*",
"zipkincore",
".",
"Span",
")",
"error",
"{",
"select",
"{",
"case",
"c",
".",
"spanc",
"<-",
"s",
":",
"// Accepted.",
"case",
"<-",
"c",
".",
"quit",
":",
"// Collector concurrently closed.",
"default",
":",
"c",
".",
"logger",
".",
"Log",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"len",
"(",
"c",
".",
"spanc",
")",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// Collect implements Collector.
// attempts a non blocking send on the channel.
|
[
"Collect",
"implements",
"Collector",
".",
"attempts",
"a",
"non",
"blocking",
"send",
"on",
"the",
"channel",
"."
] |
f0f479ad013a498e4cbfb369414e5d3880903779
|
https://github.com/openzipkin-contrib/zipkin-go-opentracing/blob/f0f479ad013a498e4cbfb369414e5d3880903779/collector-http.go#L116-L126
|
144,587 |
openzipkin-contrib/zipkin-go-opentracing
|
wire/carrier.go
|
State
|
func (p *ProtobufCarrier) State() (traceID types.TraceID, spanID uint64, parentSpanID *uint64, sampled bool, flags flag.Flags) {
traceID.Low = p.TraceId
traceID.High = p.TraceIdHigh
spanID = p.SpanId
sampled = p.Sampled
flags = flag.Flags(p.Flags)
if flags&flag.IsRoot == 0 {
parentSpanID = &p.ParentSpanId
}
return traceID, spanID, parentSpanID, sampled, flags
}
|
go
|
func (p *ProtobufCarrier) State() (traceID types.TraceID, spanID uint64, parentSpanID *uint64, sampled bool, flags flag.Flags) {
traceID.Low = p.TraceId
traceID.High = p.TraceIdHigh
spanID = p.SpanId
sampled = p.Sampled
flags = flag.Flags(p.Flags)
if flags&flag.IsRoot == 0 {
parentSpanID = &p.ParentSpanId
}
return traceID, spanID, parentSpanID, sampled, flags
}
|
[
"func",
"(",
"p",
"*",
"ProtobufCarrier",
")",
"State",
"(",
")",
"(",
"traceID",
"types",
".",
"TraceID",
",",
"spanID",
"uint64",
",",
"parentSpanID",
"*",
"uint64",
",",
"sampled",
"bool",
",",
"flags",
"flag",
".",
"Flags",
")",
"{",
"traceID",
".",
"Low",
"=",
"p",
".",
"TraceId",
"\n",
"traceID",
".",
"High",
"=",
"p",
".",
"TraceIdHigh",
"\n",
"spanID",
"=",
"p",
".",
"SpanId",
"\n",
"sampled",
"=",
"p",
".",
"Sampled",
"\n",
"flags",
"=",
"flag",
".",
"Flags",
"(",
"p",
".",
"Flags",
")",
"\n",
"if",
"flags",
"&",
"flag",
".",
"IsRoot",
"==",
"0",
"{",
"parentSpanID",
"=",
"&",
"p",
".",
"ParentSpanId",
"\n",
"}",
"\n",
"return",
"traceID",
",",
"spanID",
",",
"parentSpanID",
",",
"sampled",
",",
"flags",
"\n",
"}"
] |
// State returns the tracer state.
|
[
"State",
"returns",
"the",
"tracer",
"state",
"."
] |
f0f479ad013a498e4cbfb369414e5d3880903779
|
https://github.com/openzipkin-contrib/zipkin-go-opentracing/blob/f0f479ad013a498e4cbfb369414e5d3880903779/wire/carrier.go#L37-L47
|
144,588 |
openzipkin-contrib/zipkin-go-opentracing
|
wire/carrier.go
|
SetBaggageItem
|
func (p *ProtobufCarrier) SetBaggageItem(key, value string) {
if p.BaggageItems == nil {
p.BaggageItems = map[string]string{key: value}
return
}
p.BaggageItems[key] = value
}
|
go
|
func (p *ProtobufCarrier) SetBaggageItem(key, value string) {
if p.BaggageItems == nil {
p.BaggageItems = map[string]string{key: value}
return
}
p.BaggageItems[key] = value
}
|
[
"func",
"(",
"p",
"*",
"ProtobufCarrier",
")",
"SetBaggageItem",
"(",
"key",
",",
"value",
"string",
")",
"{",
"if",
"p",
".",
"BaggageItems",
"==",
"nil",
"{",
"p",
".",
"BaggageItems",
"=",
"map",
"[",
"string",
"]",
"string",
"{",
"key",
":",
"value",
"}",
"\n",
"return",
"\n",
"}",
"\n\n",
"p",
".",
"BaggageItems",
"[",
"key",
"]",
"=",
"value",
"\n",
"}"
] |
// SetBaggageItem sets a baggage item.
|
[
"SetBaggageItem",
"sets",
"a",
"baggage",
"item",
"."
] |
f0f479ad013a498e4cbfb369414e5d3880903779
|
https://github.com/openzipkin-contrib/zipkin-go-opentracing/blob/f0f479ad013a498e4cbfb369414e5d3880903779/wire/carrier.go#L50-L57
|
144,589 |
openzipkin-contrib/zipkin-go-opentracing
|
examples/middleware/http.go
|
ToHTTPRequest
|
func ToHTTPRequest(tracer opentracing.Tracer) RequestFunc {
return func(req *http.Request) *http.Request {
// Retrieve the Span from context.
if span := opentracing.SpanFromContext(req.Context()); span != nil {
// We are going to use this span in a client request, so mark as such.
ext.SpanKindRPCClient.Set(span)
// Add some standard OpenTracing tags, useful in an HTTP request.
ext.HTTPMethod.Set(span, req.Method)
span.SetTag(zipkincore.HTTP_HOST, req.URL.Host)
span.SetTag(zipkincore.HTTP_PATH, req.URL.Path)
ext.HTTPUrl.Set(
span,
fmt.Sprintf("%s://%s%s", req.URL.Scheme, req.URL.Host, req.URL.Path),
)
// Add information on the peer service we're about to contact.
if host, portString, err := net.SplitHostPort(req.URL.Host); err == nil {
ext.PeerHostname.Set(span, host)
if port, err := strconv.Atoi(portString); err != nil {
ext.PeerPort.Set(span, uint16(port))
}
} else {
ext.PeerHostname.Set(span, req.URL.Host)
}
// Inject the Span context into the outgoing HTTP Request.
if err := tracer.Inject(
span.Context(),
opentracing.TextMap,
opentracing.HTTPHeadersCarrier(req.Header),
); err != nil {
fmt.Printf("error encountered while trying to inject span: %+v\n", err)
}
}
return req
}
}
|
go
|
func ToHTTPRequest(tracer opentracing.Tracer) RequestFunc {
return func(req *http.Request) *http.Request {
// Retrieve the Span from context.
if span := opentracing.SpanFromContext(req.Context()); span != nil {
// We are going to use this span in a client request, so mark as such.
ext.SpanKindRPCClient.Set(span)
// Add some standard OpenTracing tags, useful in an HTTP request.
ext.HTTPMethod.Set(span, req.Method)
span.SetTag(zipkincore.HTTP_HOST, req.URL.Host)
span.SetTag(zipkincore.HTTP_PATH, req.URL.Path)
ext.HTTPUrl.Set(
span,
fmt.Sprintf("%s://%s%s", req.URL.Scheme, req.URL.Host, req.URL.Path),
)
// Add information on the peer service we're about to contact.
if host, portString, err := net.SplitHostPort(req.URL.Host); err == nil {
ext.PeerHostname.Set(span, host)
if port, err := strconv.Atoi(portString); err != nil {
ext.PeerPort.Set(span, uint16(port))
}
} else {
ext.PeerHostname.Set(span, req.URL.Host)
}
// Inject the Span context into the outgoing HTTP Request.
if err := tracer.Inject(
span.Context(),
opentracing.TextMap,
opentracing.HTTPHeadersCarrier(req.Header),
); err != nil {
fmt.Printf("error encountered while trying to inject span: %+v\n", err)
}
}
return req
}
}
|
[
"func",
"ToHTTPRequest",
"(",
"tracer",
"opentracing",
".",
"Tracer",
")",
"RequestFunc",
"{",
"return",
"func",
"(",
"req",
"*",
"http",
".",
"Request",
")",
"*",
"http",
".",
"Request",
"{",
"// Retrieve the Span from context.",
"if",
"span",
":=",
"opentracing",
".",
"SpanFromContext",
"(",
"req",
".",
"Context",
"(",
")",
")",
";",
"span",
"!=",
"nil",
"{",
"// We are going to use this span in a client request, so mark as such.",
"ext",
".",
"SpanKindRPCClient",
".",
"Set",
"(",
"span",
")",
"\n\n",
"// Add some standard OpenTracing tags, useful in an HTTP request.",
"ext",
".",
"HTTPMethod",
".",
"Set",
"(",
"span",
",",
"req",
".",
"Method",
")",
"\n",
"span",
".",
"SetTag",
"(",
"zipkincore",
".",
"HTTP_HOST",
",",
"req",
".",
"URL",
".",
"Host",
")",
"\n",
"span",
".",
"SetTag",
"(",
"zipkincore",
".",
"HTTP_PATH",
",",
"req",
".",
"URL",
".",
"Path",
")",
"\n",
"ext",
".",
"HTTPUrl",
".",
"Set",
"(",
"span",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"req",
".",
"URL",
".",
"Scheme",
",",
"req",
".",
"URL",
".",
"Host",
",",
"req",
".",
"URL",
".",
"Path",
")",
",",
")",
"\n\n",
"// Add information on the peer service we're about to contact.",
"if",
"host",
",",
"portString",
",",
"err",
":=",
"net",
".",
"SplitHostPort",
"(",
"req",
".",
"URL",
".",
"Host",
")",
";",
"err",
"==",
"nil",
"{",
"ext",
".",
"PeerHostname",
".",
"Set",
"(",
"span",
",",
"host",
")",
"\n",
"if",
"port",
",",
"err",
":=",
"strconv",
".",
"Atoi",
"(",
"portString",
")",
";",
"err",
"!=",
"nil",
"{",
"ext",
".",
"PeerPort",
".",
"Set",
"(",
"span",
",",
"uint16",
"(",
"port",
")",
")",
"\n",
"}",
"\n",
"}",
"else",
"{",
"ext",
".",
"PeerHostname",
".",
"Set",
"(",
"span",
",",
"req",
".",
"URL",
".",
"Host",
")",
"\n",
"}",
"\n\n",
"// Inject the Span context into the outgoing HTTP Request.",
"if",
"err",
":=",
"tracer",
".",
"Inject",
"(",
"span",
".",
"Context",
"(",
")",
",",
"opentracing",
".",
"TextMap",
",",
"opentracing",
".",
"HTTPHeadersCarrier",
"(",
"req",
".",
"Header",
")",
",",
")",
";",
"err",
"!=",
"nil",
"{",
"fmt",
".",
"Printf",
"(",
"\"",
"\\n",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"req",
"\n",
"}",
"\n",
"}"
] |
// ToHTTPRequest returns a RequestFunc that injects an OpenTracing Span found in
// context into the HTTP Headers. If no such Span can be found, the RequestFunc
// is a noop.
|
[
"ToHTTPRequest",
"returns",
"a",
"RequestFunc",
"that",
"injects",
"an",
"OpenTracing",
"Span",
"found",
"in",
"context",
"into",
"the",
"HTTP",
"Headers",
".",
"If",
"no",
"such",
"Span",
"can",
"be",
"found",
"the",
"RequestFunc",
"is",
"a",
"noop",
"."
] |
f0f479ad013a498e4cbfb369414e5d3880903779
|
https://github.com/openzipkin-contrib/zipkin-go-opentracing/blob/f0f479ad013a498e4cbfb369414e5d3880903779/examples/middleware/http.go#L25-L63
|
144,590 |
openzipkin-contrib/zipkin-go-opentracing
|
log-materializers.go
|
MaterializeWithLogFmt
|
func MaterializeWithLogFmt(logFields []log.Field) ([]byte, error) {
var (
buffer = bytes.NewBuffer(nil)
encoder = logfmt.NewEncoder(buffer)
)
for _, field := range logFields {
if err := encoder.EncodeKeyval(field.Key(), field.Value()); err != nil {
encoder.EncodeKeyval(field.Key(), err.Error())
}
}
return buffer.Bytes(), nil
}
|
go
|
func MaterializeWithLogFmt(logFields []log.Field) ([]byte, error) {
var (
buffer = bytes.NewBuffer(nil)
encoder = logfmt.NewEncoder(buffer)
)
for _, field := range logFields {
if err := encoder.EncodeKeyval(field.Key(), field.Value()); err != nil {
encoder.EncodeKeyval(field.Key(), err.Error())
}
}
return buffer.Bytes(), nil
}
|
[
"func",
"MaterializeWithLogFmt",
"(",
"logFields",
"[",
"]",
"log",
".",
"Field",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"var",
"(",
"buffer",
"=",
"bytes",
".",
"NewBuffer",
"(",
"nil",
")",
"\n",
"encoder",
"=",
"logfmt",
".",
"NewEncoder",
"(",
"buffer",
")",
"\n",
")",
"\n",
"for",
"_",
",",
"field",
":=",
"range",
"logFields",
"{",
"if",
"err",
":=",
"encoder",
".",
"EncodeKeyval",
"(",
"field",
".",
"Key",
"(",
")",
",",
"field",
".",
"Value",
"(",
")",
")",
";",
"err",
"!=",
"nil",
"{",
"encoder",
".",
"EncodeKeyval",
"(",
"field",
".",
"Key",
"(",
")",
",",
"err",
".",
"Error",
"(",
")",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"buffer",
".",
"Bytes",
"(",
")",
",",
"nil",
"\n",
"}"
] |
// MaterializeWithLogFmt converts log Fields into LogFmt string
|
[
"MaterializeWithLogFmt",
"converts",
"log",
"Fields",
"into",
"LogFmt",
"string"
] |
f0f479ad013a498e4cbfb369414e5d3880903779
|
https://github.com/openzipkin-contrib/zipkin-go-opentracing/blob/f0f479ad013a498e4cbfb369414e5d3880903779/log-materializers.go#L48-L59
|
144,591 |
openzipkin-contrib/zipkin-go-opentracing
|
log-materializers.go
|
StrictZipkinMaterializer
|
func StrictZipkinMaterializer(logFields []log.Field) ([]byte, error) {
for _, field := range logFields {
if field.Key() == "event" {
return []byte(fmt.Sprintf("%+v", field.Value())), nil
}
}
return nil, errEventLogNotFound
}
|
go
|
func StrictZipkinMaterializer(logFields []log.Field) ([]byte, error) {
for _, field := range logFields {
if field.Key() == "event" {
return []byte(fmt.Sprintf("%+v", field.Value())), nil
}
}
return nil, errEventLogNotFound
}
|
[
"func",
"StrictZipkinMaterializer",
"(",
"logFields",
"[",
"]",
"log",
".",
"Field",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"for",
"_",
",",
"field",
":=",
"range",
"logFields",
"{",
"if",
"field",
".",
"Key",
"(",
")",
"==",
"\"",
"\"",
"{",
"return",
"[",
"]",
"byte",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"field",
".",
"Value",
"(",
")",
")",
")",
",",
"nil",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
",",
"errEventLogNotFound",
"\n",
"}"
] |
// StrictZipkinMaterializer will only record a log.Field of type "event".
|
[
"StrictZipkinMaterializer",
"will",
"only",
"record",
"a",
"log",
".",
"Field",
"of",
"type",
"event",
"."
] |
f0f479ad013a498e4cbfb369414e5d3880903779
|
https://github.com/openzipkin-contrib/zipkin-go-opentracing/blob/f0f479ad013a498e4cbfb369414e5d3880903779/log-materializers.go#L62-L69
|
144,592 |
openzipkin-contrib/zipkin-go-opentracing
|
recorder.go
|
GetSpans
|
func (r *InMemorySpanRecorder) GetSpans() []RawSpan {
r.RLock()
defer r.RUnlock()
spans := make([]RawSpan, len(r.spans))
copy(spans, r.spans)
return spans
}
|
go
|
func (r *InMemorySpanRecorder) GetSpans() []RawSpan {
r.RLock()
defer r.RUnlock()
spans := make([]RawSpan, len(r.spans))
copy(spans, r.spans)
return spans
}
|
[
"func",
"(",
"r",
"*",
"InMemorySpanRecorder",
")",
"GetSpans",
"(",
")",
"[",
"]",
"RawSpan",
"{",
"r",
".",
"RLock",
"(",
")",
"\n",
"defer",
"r",
".",
"RUnlock",
"(",
")",
"\n",
"spans",
":=",
"make",
"(",
"[",
"]",
"RawSpan",
",",
"len",
"(",
"r",
".",
"spans",
")",
")",
"\n",
"copy",
"(",
"spans",
",",
"r",
".",
"spans",
")",
"\n",
"return",
"spans",
"\n",
"}"
] |
// GetSpans returns a copy of the array of spans accumulated so far.
|
[
"GetSpans",
"returns",
"a",
"copy",
"of",
"the",
"array",
"of",
"spans",
"accumulated",
"so",
"far",
"."
] |
f0f479ad013a498e4cbfb369414e5d3880903779
|
https://github.com/openzipkin-contrib/zipkin-go-opentracing/blob/f0f479ad013a498e4cbfb369414e5d3880903779/recorder.go#L34-L40
|
144,593 |
openzipkin-contrib/zipkin-go-opentracing
|
recorder.go
|
GetSampledSpans
|
func (r *InMemorySpanRecorder) GetSampledSpans() []RawSpan {
r.RLock()
defer r.RUnlock()
spans := make([]RawSpan, 0, len(r.spans))
for _, span := range r.spans {
if span.Context.Sampled {
spans = append(spans, span)
}
}
return spans
}
|
go
|
func (r *InMemorySpanRecorder) GetSampledSpans() []RawSpan {
r.RLock()
defer r.RUnlock()
spans := make([]RawSpan, 0, len(r.spans))
for _, span := range r.spans {
if span.Context.Sampled {
spans = append(spans, span)
}
}
return spans
}
|
[
"func",
"(",
"r",
"*",
"InMemorySpanRecorder",
")",
"GetSampledSpans",
"(",
")",
"[",
"]",
"RawSpan",
"{",
"r",
".",
"RLock",
"(",
")",
"\n",
"defer",
"r",
".",
"RUnlock",
"(",
")",
"\n",
"spans",
":=",
"make",
"(",
"[",
"]",
"RawSpan",
",",
"0",
",",
"len",
"(",
"r",
".",
"spans",
")",
")",
"\n",
"for",
"_",
",",
"span",
":=",
"range",
"r",
".",
"spans",
"{",
"if",
"span",
".",
"Context",
".",
"Sampled",
"{",
"spans",
"=",
"append",
"(",
"spans",
",",
"span",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"spans",
"\n",
"}"
] |
// GetSampledSpans returns a slice of spans accumulated so far which were sampled.
|
[
"GetSampledSpans",
"returns",
"a",
"slice",
"of",
"spans",
"accumulated",
"so",
"far",
"which",
"were",
"sampled",
"."
] |
f0f479ad013a498e4cbfb369414e5d3880903779
|
https://github.com/openzipkin-contrib/zipkin-go-opentracing/blob/f0f479ad013a498e4cbfb369414e5d3880903779/recorder.go#L43-L53
|
144,594 |
openzipkin-contrib/zipkin-go-opentracing
|
recorder.go
|
Reset
|
func (r *InMemorySpanRecorder) Reset() {
r.Lock()
defer r.Unlock()
r.spans = nil
}
|
go
|
func (r *InMemorySpanRecorder) Reset() {
r.Lock()
defer r.Unlock()
r.spans = nil
}
|
[
"func",
"(",
"r",
"*",
"InMemorySpanRecorder",
")",
"Reset",
"(",
")",
"{",
"r",
".",
"Lock",
"(",
")",
"\n",
"defer",
"r",
".",
"Unlock",
"(",
")",
"\n",
"r",
".",
"spans",
"=",
"nil",
"\n",
"}"
] |
// Reset clears the internal array of spans.
|
[
"Reset",
"clears",
"the",
"internal",
"array",
"of",
"spans",
"."
] |
f0f479ad013a498e4cbfb369414e5d3880903779
|
https://github.com/openzipkin-contrib/zipkin-go-opentracing/blob/f0f479ad013a498e4cbfb369414e5d3880903779/recorder.go#L56-L60
|
144,595 |
openzipkin-contrib/zipkin-go-opentracing
|
collector.go
|
Close
|
func (c MultiCollector) Close() error {
return c.aggregateErrors(func(coll Collector) error { return coll.Close() })
}
|
go
|
func (c MultiCollector) Close() error {
return c.aggregateErrors(func(coll Collector) error { return coll.Close() })
}
|
[
"func",
"(",
"c",
"MultiCollector",
")",
"Close",
"(",
")",
"error",
"{",
"return",
"c",
".",
"aggregateErrors",
"(",
"func",
"(",
"coll",
"Collector",
")",
"error",
"{",
"return",
"coll",
".",
"Close",
"(",
")",
"}",
")",
"\n",
"}"
] |
// Close implements Collector.
|
[
"Close",
"implements",
"Collector",
"."
] |
f0f479ad013a498e4cbfb369414e5d3880903779
|
https://github.com/openzipkin-contrib/zipkin-go-opentracing/blob/f0f479ad013a498e4cbfb369414e5d3880903779/collector.go#L34-L36
|
144,596 |
openzipkin-contrib/zipkin-go-opentracing
|
sample.go
|
ModuloSampler
|
func ModuloSampler(mod uint64) Sampler {
if mod < 2 {
return alwaysSample
}
return func(id uint64) bool {
return (id % mod) == 0
}
}
|
go
|
func ModuloSampler(mod uint64) Sampler {
if mod < 2 {
return alwaysSample
}
return func(id uint64) bool {
return (id % mod) == 0
}
}
|
[
"func",
"ModuloSampler",
"(",
"mod",
"uint64",
")",
"Sampler",
"{",
"if",
"mod",
"<",
"2",
"{",
"return",
"alwaysSample",
"\n",
"}",
"\n",
"return",
"func",
"(",
"id",
"uint64",
")",
"bool",
"{",
"return",
"(",
"id",
"%",
"mod",
")",
"==",
"0",
"\n",
"}",
"\n",
"}"
] |
// ModuloSampler provides a typical OpenTracing type Sampler.
|
[
"ModuloSampler",
"provides",
"a",
"typical",
"OpenTracing",
"type",
"Sampler",
"."
] |
f0f479ad013a498e4cbfb369414e5d3880903779
|
https://github.com/openzipkin-contrib/zipkin-go-opentracing/blob/f0f479ad013a498e4cbfb369414e5d3880903779/sample.go#L19-L26
|
144,597 |
openzipkin-contrib/zipkin-go-opentracing
|
zipkin-endpoint.go
|
makeEndpoint
|
func makeEndpoint(hostport, serviceName string) (ep *zipkincore.Endpoint) {
ep = zipkincore.NewEndpoint()
// Set the ServiceName
ep.ServiceName = serviceName
if strings.IndexByte(hostport, ':') < 0 {
// "<host>" becomes "<host>:0"
hostport = hostport + ":0"
}
// try to parse provided "<host>:<port>"
host, port, err := net.SplitHostPort(hostport)
if err != nil {
// if unparsable, return as "undefined:0"
return
}
// try to set port number
p, _ := strconv.ParseUint(port, 10, 16)
ep.Port = int16(p)
// if <host> is a domain name, look it up
addrs, err := net.LookupIP(host)
if err != nil {
// return as "undefined:<port>"
return
}
var addr4, addr16 net.IP
for i := range addrs {
addr := addrs[i].To4()
if addr == nil {
// IPv6
if addr16 == nil {
addr16 = addrs[i].To16() // IPv6 - 16 bytes
}
} else {
// IPv4
if addr4 == nil {
addr4 = addr // IPv4 - 4 bytes
}
}
if addr16 != nil && addr4 != nil {
// IPv4 & IPv6 have been set, we can stop looking further
break
}
}
// default to 0 filled 4 byte array for IPv4 if IPv6 only host was found
if addr4 == nil {
addr4 = make([]byte, 4)
}
// set IPv4 and IPv6 addresses
ep.Ipv4 = (int32)(binary.BigEndian.Uint32(addr4))
ep.Ipv6 = []byte(addr16)
return
}
|
go
|
func makeEndpoint(hostport, serviceName string) (ep *zipkincore.Endpoint) {
ep = zipkincore.NewEndpoint()
// Set the ServiceName
ep.ServiceName = serviceName
if strings.IndexByte(hostport, ':') < 0 {
// "<host>" becomes "<host>:0"
hostport = hostport + ":0"
}
// try to parse provided "<host>:<port>"
host, port, err := net.SplitHostPort(hostport)
if err != nil {
// if unparsable, return as "undefined:0"
return
}
// try to set port number
p, _ := strconv.ParseUint(port, 10, 16)
ep.Port = int16(p)
// if <host> is a domain name, look it up
addrs, err := net.LookupIP(host)
if err != nil {
// return as "undefined:<port>"
return
}
var addr4, addr16 net.IP
for i := range addrs {
addr := addrs[i].To4()
if addr == nil {
// IPv6
if addr16 == nil {
addr16 = addrs[i].To16() // IPv6 - 16 bytes
}
} else {
// IPv4
if addr4 == nil {
addr4 = addr // IPv4 - 4 bytes
}
}
if addr16 != nil && addr4 != nil {
// IPv4 & IPv6 have been set, we can stop looking further
break
}
}
// default to 0 filled 4 byte array for IPv4 if IPv6 only host was found
if addr4 == nil {
addr4 = make([]byte, 4)
}
// set IPv4 and IPv6 addresses
ep.Ipv4 = (int32)(binary.BigEndian.Uint32(addr4))
ep.Ipv6 = []byte(addr16)
return
}
|
[
"func",
"makeEndpoint",
"(",
"hostport",
",",
"serviceName",
"string",
")",
"(",
"ep",
"*",
"zipkincore",
".",
"Endpoint",
")",
"{",
"ep",
"=",
"zipkincore",
".",
"NewEndpoint",
"(",
")",
"\n\n",
"// Set the ServiceName",
"ep",
".",
"ServiceName",
"=",
"serviceName",
"\n\n",
"if",
"strings",
".",
"IndexByte",
"(",
"hostport",
",",
"':'",
")",
"<",
"0",
"{",
"// \"<host>\" becomes \"<host>:0\"",
"hostport",
"=",
"hostport",
"+",
"\"",
"\"",
"\n",
"}",
"\n\n",
"// try to parse provided \"<host>:<port>\"",
"host",
",",
"port",
",",
"err",
":=",
"net",
".",
"SplitHostPort",
"(",
"hostport",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"// if unparsable, return as \"undefined:0\"",
"return",
"\n",
"}",
"\n\n",
"// try to set port number",
"p",
",",
"_",
":=",
"strconv",
".",
"ParseUint",
"(",
"port",
",",
"10",
",",
"16",
")",
"\n",
"ep",
".",
"Port",
"=",
"int16",
"(",
"p",
")",
"\n\n",
"// if <host> is a domain name, look it up",
"addrs",
",",
"err",
":=",
"net",
".",
"LookupIP",
"(",
"host",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"// return as \"undefined:<port>\"",
"return",
"\n",
"}",
"\n\n",
"var",
"addr4",
",",
"addr16",
"net",
".",
"IP",
"\n",
"for",
"i",
":=",
"range",
"addrs",
"{",
"addr",
":=",
"addrs",
"[",
"i",
"]",
".",
"To4",
"(",
")",
"\n",
"if",
"addr",
"==",
"nil",
"{",
"// IPv6",
"if",
"addr16",
"==",
"nil",
"{",
"addr16",
"=",
"addrs",
"[",
"i",
"]",
".",
"To16",
"(",
")",
"// IPv6 - 16 bytes",
"\n",
"}",
"\n",
"}",
"else",
"{",
"// IPv4",
"if",
"addr4",
"==",
"nil",
"{",
"addr4",
"=",
"addr",
"// IPv4 - 4 bytes",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"addr16",
"!=",
"nil",
"&&",
"addr4",
"!=",
"nil",
"{",
"// IPv4 & IPv6 have been set, we can stop looking further",
"break",
"\n",
"}",
"\n",
"}",
"\n",
"// default to 0 filled 4 byte array for IPv4 if IPv6 only host was found",
"if",
"addr4",
"==",
"nil",
"{",
"addr4",
"=",
"make",
"(",
"[",
"]",
"byte",
",",
"4",
")",
"\n",
"}",
"\n\n",
"// set IPv4 and IPv6 addresses",
"ep",
".",
"Ipv4",
"=",
"(",
"int32",
")",
"(",
"binary",
".",
"BigEndian",
".",
"Uint32",
"(",
"addr4",
")",
")",
"\n",
"ep",
".",
"Ipv6",
"=",
"[",
"]",
"byte",
"(",
"addr16",
")",
"\n",
"return",
"\n",
"}"
] |
// makeEndpoint takes the hostport and service name that represent this Zipkin
// service, and returns an endpoint that's embedded into the Zipkin core Span
// type. It will return a nil endpoint if the input parameters are malformed.
|
[
"makeEndpoint",
"takes",
"the",
"hostport",
"and",
"service",
"name",
"that",
"represent",
"this",
"Zipkin",
"service",
"and",
"returns",
"an",
"endpoint",
"that",
"s",
"embedded",
"into",
"the",
"Zipkin",
"core",
"Span",
"type",
".",
"It",
"will",
"return",
"a",
"nil",
"endpoint",
"if",
"the",
"input",
"parameters",
"are",
"malformed",
"."
] |
f0f479ad013a498e4cbfb369414e5d3880903779
|
https://github.com/openzipkin-contrib/zipkin-go-opentracing/blob/f0f479ad013a498e4cbfb369414e5d3880903779/zipkin-endpoint.go#L15-L72
|
144,598 |
openzipkin-contrib/zipkin-go-opentracing
|
examples/cli_with_2_services/svc2/httpserver.go
|
NewHTTPHandler
|
func NewHTTPHandler(tracer opentracing.Tracer, service Service) http.Handler {
// Create our HTTP Service.
svc := &httpService{service: service}
// Create the mux.
mux := http.NewServeMux()
// Create the Sum handler.
var sumHandler http.Handler
sumHandler = http.HandlerFunc(svc.sumHandler)
// Wrap the Sum handler with our tracing middleware.
sumHandler = middleware.FromHTTPRequest(tracer, "Sum")(sumHandler)
// Wire up the mux.
mux.Handle("/sum/", sumHandler)
// Return the mux.
return mux
}
|
go
|
func NewHTTPHandler(tracer opentracing.Tracer, service Service) http.Handler {
// Create our HTTP Service.
svc := &httpService{service: service}
// Create the mux.
mux := http.NewServeMux()
// Create the Sum handler.
var sumHandler http.Handler
sumHandler = http.HandlerFunc(svc.sumHandler)
// Wrap the Sum handler with our tracing middleware.
sumHandler = middleware.FromHTTPRequest(tracer, "Sum")(sumHandler)
// Wire up the mux.
mux.Handle("/sum/", sumHandler)
// Return the mux.
return mux
}
|
[
"func",
"NewHTTPHandler",
"(",
"tracer",
"opentracing",
".",
"Tracer",
",",
"service",
"Service",
")",
"http",
".",
"Handler",
"{",
"// Create our HTTP Service.",
"svc",
":=",
"&",
"httpService",
"{",
"service",
":",
"service",
"}",
"\n\n",
"// Create the mux.",
"mux",
":=",
"http",
".",
"NewServeMux",
"(",
")",
"\n\n",
"// Create the Sum handler.",
"var",
"sumHandler",
"http",
".",
"Handler",
"\n",
"sumHandler",
"=",
"http",
".",
"HandlerFunc",
"(",
"svc",
".",
"sumHandler",
")",
"\n\n",
"// Wrap the Sum handler with our tracing middleware.",
"sumHandler",
"=",
"middleware",
".",
"FromHTTPRequest",
"(",
"tracer",
",",
"\"",
"\"",
")",
"(",
"sumHandler",
")",
"\n\n",
"// Wire up the mux.",
"mux",
".",
"Handle",
"(",
"\"",
"\"",
",",
"sumHandler",
")",
"\n\n",
"// Return the mux.",
"return",
"mux",
"\n",
"}"
] |
// NewHTTPHandler returns a new HTTP handler our svc2.
|
[
"NewHTTPHandler",
"returns",
"a",
"new",
"HTTP",
"handler",
"our",
"svc2",
"."
] |
f0f479ad013a498e4cbfb369414e5d3880903779
|
https://github.com/openzipkin-contrib/zipkin-go-opentracing/blob/f0f479ad013a498e4cbfb369414e5d3880903779/examples/cli_with_2_services/svc2/httpserver.go#L44-L63
|
144,599 |
openzipkin-contrib/zipkin-go-opentracing
|
types/traceid.go
|
ToHex
|
func (t TraceID) ToHex() string {
if t.High == 0 {
return fmt.Sprintf("%016x", t.Low)
}
return fmt.Sprintf("%016x%016x", t.High, t.Low)
}
|
go
|
func (t TraceID) ToHex() string {
if t.High == 0 {
return fmt.Sprintf("%016x", t.Low)
}
return fmt.Sprintf("%016x%016x", t.High, t.Low)
}
|
[
"func",
"(",
"t",
"TraceID",
")",
"ToHex",
"(",
")",
"string",
"{",
"if",
"t",
".",
"High",
"==",
"0",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"t",
".",
"Low",
")",
"\n",
"}",
"\n",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"t",
".",
"High",
",",
"t",
".",
"Low",
")",
"\n",
"}"
] |
// ToHex outputs the 128-bit traceID as hex string.
|
[
"ToHex",
"outputs",
"the",
"128",
"-",
"bit",
"traceID",
"as",
"hex",
"string",
"."
] |
f0f479ad013a498e4cbfb369414e5d3880903779
|
https://github.com/openzipkin-contrib/zipkin-go-opentracing/blob/f0f479ad013a498e4cbfb369414e5d3880903779/types/traceid.go#L28-L33
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.