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
sequence | docstring
stringlengths 6
2.61k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 85
252
|
---|---|---|---|---|---|---|---|---|---|---|---|
11,600 | quipo/statsd | bufferedclient.go | FGauge | func (sb *StatsdBuffer) FGauge(stat string, value float64) error {
sb.eventChannel <- &event.FGauge{Name: stat, Value: value}
return nil
} | go | func (sb *StatsdBuffer) FGauge(stat string, value float64) error {
sb.eventChannel <- &event.FGauge{Name: stat, Value: value}
return nil
} | [
"func",
"(",
"sb",
"*",
"StatsdBuffer",
")",
"FGauge",
"(",
"stat",
"string",
",",
"value",
"float64",
")",
"error",
"{",
"sb",
".",
"eventChannel",
"<-",
"&",
"event",
".",
"FGauge",
"{",
"Name",
":",
"stat",
",",
"Value",
":",
"value",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // FGauge is a Gauge working with float64 values | [
"FGauge",
"is",
"a",
"Gauge",
"working",
"with",
"float64",
"values"
] | 3d6a5565f3141ac42f8353d97b2c016da2752006 | https://github.com/quipo/statsd/blob/3d6a5565f3141ac42f8353d97b2c016da2752006/bufferedclient.go#L98-L101 |
11,601 | quipo/statsd | bufferedclient.go | SendEvents | func (sb *StatsdBuffer) SendEvents(events map[string]event.Event) error {
for _, e := range events {
sb.eventChannel <- e
}
return nil
} | go | func (sb *StatsdBuffer) SendEvents(events map[string]event.Event) error {
for _, e := range events {
sb.eventChannel <- e
}
return nil
} | [
"func",
"(",
"sb",
"*",
"StatsdBuffer",
")",
"SendEvents",
"(",
"events",
"map",
"[",
"string",
"]",
"event",
".",
"Event",
")",
"error",
"{",
"for",
"_",
",",
"e",
":=",
"range",
"events",
"{",
"sb",
".",
"eventChannel",
"<-",
"e",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // SendEvents - Sends stats from all the event objects. | [
"SendEvents",
"-",
"Sends",
"stats",
"from",
"all",
"the",
"event",
"objects",
"."
] | 3d6a5565f3141ac42f8353d97b2c016da2752006 | https://github.com/quipo/statsd/blob/3d6a5565f3141ac42f8353d97b2c016da2752006/bufferedclient.go#L128-L133 |
11,602 | quipo/statsd | bufferedclient.go | initMemoisedKeyMap | func initMemoisedKeyMap() func(typ string, key string) string {
m := make(map[string]map[string]string)
return func(typ string, key string) string {
if _, ok := m[typ]; !ok {
m[typ] = make(map[string]string)
}
k, ok := m[typ][key]
if !ok {
m[typ][key] = typ + "|" + key
return m[typ][key]
}
return k // memoized value
}
} | go | func initMemoisedKeyMap() func(typ string, key string) string {
m := make(map[string]map[string]string)
return func(typ string, key string) string {
if _, ok := m[typ]; !ok {
m[typ] = make(map[string]string)
}
k, ok := m[typ][key]
if !ok {
m[typ][key] = typ + "|" + key
return m[typ][key]
}
return k // memoized value
}
} | [
"func",
"initMemoisedKeyMap",
"(",
")",
"func",
"(",
"typ",
"string",
",",
"key",
"string",
")",
"string",
"{",
"m",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"map",
"[",
"string",
"]",
"string",
")",
"\n",
"return",
"func",
"(",
"typ",
"string",
",",
"key",
"string",
")",
"string",
"{",
"if",
"_",
",",
"ok",
":=",
"m",
"[",
"typ",
"]",
";",
"!",
"ok",
"{",
"m",
"[",
"typ",
"]",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"string",
")",
"\n",
"}",
"\n",
"k",
",",
"ok",
":=",
"m",
"[",
"typ",
"]",
"[",
"key",
"]",
"\n",
"if",
"!",
"ok",
"{",
"m",
"[",
"typ",
"]",
"[",
"key",
"]",
"=",
"typ",
"+",
"\"",
"\"",
"+",
"key",
"\n",
"return",
"m",
"[",
"typ",
"]",
"[",
"key",
"]",
"\n",
"}",
"\n",
"return",
"k",
"// memoized value",
"\n",
"}",
"\n",
"}"
] | // avoid too many allocations by memoizing the "type|key" pair for an event
// @see https://gobyexample.com/closures | [
"avoid",
"too",
"many",
"allocations",
"by",
"memoizing",
"the",
"type|key",
"pair",
"for",
"an",
"event"
] | 3d6a5565f3141ac42f8353d97b2c016da2752006 | https://github.com/quipo/statsd/blob/3d6a5565f3141ac42f8353d97b2c016da2752006/bufferedclient.go#L137-L150 |
11,603 | quipo/statsd | bufferedclient.go | Close | func (sb *StatsdBuffer) Close() (err error) {
// 1. send a close event to the collector
req := closeRequest{reply: make(chan error)}
sb.closeChannel <- req
// 2. wait for the collector to drain the queue and respond
err = <-req.reply
// 3. close the statsd client
err2 := sb.statsd.Close()
if err != nil {
return err
}
return err2
} | go | func (sb *StatsdBuffer) Close() (err error) {
// 1. send a close event to the collector
req := closeRequest{reply: make(chan error)}
sb.closeChannel <- req
// 2. wait for the collector to drain the queue and respond
err = <-req.reply
// 3. close the statsd client
err2 := sb.statsd.Close()
if err != nil {
return err
}
return err2
} | [
"func",
"(",
"sb",
"*",
"StatsdBuffer",
")",
"Close",
"(",
")",
"(",
"err",
"error",
")",
"{",
"// 1. send a close event to the collector",
"req",
":=",
"closeRequest",
"{",
"reply",
":",
"make",
"(",
"chan",
"error",
")",
"}",
"\n",
"sb",
".",
"closeChannel",
"<-",
"req",
"\n",
"// 2. wait for the collector to drain the queue and respond",
"err",
"=",
"<-",
"req",
".",
"reply",
"\n",
"// 3. close the statsd client",
"err2",
":=",
"sb",
".",
"statsd",
".",
"Close",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"err2",
"\n",
"}"
] | // Close sends a close event to the collector asking to stop & flush pending stats
// and closes the statsd client | [
"Close",
"sends",
"a",
"close",
"event",
"to",
"the",
"collector",
"asking",
"to",
"stop",
"&",
"flush",
"pending",
"stats",
"and",
"closes",
"the",
"statsd",
"client"
] | 3d6a5565f3141ac42f8353d97b2c016da2752006 | https://github.com/quipo/statsd/blob/3d6a5565f3141ac42f8353d97b2c016da2752006/bufferedclient.go#L205-L217 |
11,604 | quipo/statsd | event/precisiontiming.go | NewPrecisionTiming | func NewPrecisionTiming(k string, delta time.Duration) *PrecisionTiming {
return &PrecisionTiming{Name: k, Min: delta, Max: delta, Value: delta, Count: 1}
} | go | func NewPrecisionTiming(k string, delta time.Duration) *PrecisionTiming {
return &PrecisionTiming{Name: k, Min: delta, Max: delta, Value: delta, Count: 1}
} | [
"func",
"NewPrecisionTiming",
"(",
"k",
"string",
",",
"delta",
"time",
".",
"Duration",
")",
"*",
"PrecisionTiming",
"{",
"return",
"&",
"PrecisionTiming",
"{",
"Name",
":",
"k",
",",
"Min",
":",
"delta",
",",
"Max",
":",
"delta",
",",
"Value",
":",
"delta",
",",
"Count",
":",
"1",
"}",
"\n",
"}"
] | // NewPrecisionTiming is a factory for a Timing event, setting the Count to 1 to prevent div_by_0 errors | [
"NewPrecisionTiming",
"is",
"a",
"factory",
"for",
"a",
"Timing",
"event",
"setting",
"the",
"Count",
"to",
"1",
"to",
"prevent",
"div_by_0",
"errors"
] | 3d6a5565f3141ac42f8353d97b2c016da2752006 | https://github.com/quipo/statsd/blob/3d6a5565f3141ac42f8353d97b2c016da2752006/event/precisiontiming.go#L18-L20 |
11,605 | quipo/statsd | event/precisiontiming.go | durationToMs | func (e PrecisionTiming) durationToMs(x time.Duration) float64 {
return float64(x) / float64(time.Millisecond)
} | go | func (e PrecisionTiming) durationToMs(x time.Duration) float64 {
return float64(x) / float64(time.Millisecond)
} | [
"func",
"(",
"e",
"PrecisionTiming",
")",
"durationToMs",
"(",
"x",
"time",
".",
"Duration",
")",
"float64",
"{",
"return",
"float64",
"(",
"x",
")",
"/",
"float64",
"(",
"time",
".",
"Millisecond",
")",
"\n",
"}"
] | // durationToMs converts time.Duration into the corresponding value in milliseconds | [
"durationToMs",
"converts",
"time",
".",
"Duration",
"into",
"the",
"corresponding",
"value",
"in",
"milliseconds"
] | 3d6a5565f3141ac42f8353d97b2c016da2752006 | https://github.com/quipo/statsd/blob/3d6a5565f3141ac42f8353d97b2c016da2752006/event/precisiontiming.go#L51-L53 |
11,606 | quipo/statsd | event/timing.go | NewTiming | func NewTiming(k string, delta int64) *Timing {
return &Timing{Name: k, Min: delta, Max: delta, Value: delta, Count: 1}
} | go | func NewTiming(k string, delta int64) *Timing {
return &Timing{Name: k, Min: delta, Max: delta, Value: delta, Count: 1}
} | [
"func",
"NewTiming",
"(",
"k",
"string",
",",
"delta",
"int64",
")",
"*",
"Timing",
"{",
"return",
"&",
"Timing",
"{",
"Name",
":",
"k",
",",
"Min",
":",
"delta",
",",
"Max",
":",
"delta",
",",
"Value",
":",
"delta",
",",
"Count",
":",
"1",
"}",
"\n",
"}"
] | // NewTiming is a factory for a Timing event, setting the Count to 1 to prevent div_by_0 errors | [
"NewTiming",
"is",
"a",
"factory",
"for",
"a",
"Timing",
"event",
"setting",
"the",
"Count",
"to",
"1",
"to",
"prevent",
"div_by_0",
"errors"
] | 3d6a5565f3141ac42f8353d97b2c016da2752006 | https://github.com/quipo/statsd/blob/3d6a5565f3141ac42f8353d97b2c016da2752006/event/timing.go#L15-L17 |
11,607 | quipo/statsd | event/timing.go | Payload | func (e Timing) Payload() interface{} {
return map[string]int64{
"min": e.Min,
"max": e.Max,
"val": e.Value,
"cnt": e.Count,
}
} | go | func (e Timing) Payload() interface{} {
return map[string]int64{
"min": e.Min,
"max": e.Max,
"val": e.Value,
"cnt": e.Count,
}
} | [
"func",
"(",
"e",
"Timing",
")",
"Payload",
"(",
")",
"interface",
"{",
"}",
"{",
"return",
"map",
"[",
"string",
"]",
"int64",
"{",
"\"",
"\"",
":",
"e",
".",
"Min",
",",
"\"",
"\"",
":",
"e",
".",
"Max",
",",
"\"",
"\"",
":",
"e",
".",
"Value",
",",
"\"",
"\"",
":",
"e",
".",
"Count",
",",
"}",
"\n",
"}"
] | // Payload returns the aggregated value for this event | [
"Payload",
"returns",
"the",
"aggregated",
"value",
"for",
"this",
"event"
] | 3d6a5565f3141ac42f8353d97b2c016da2752006 | https://github.com/quipo/statsd/blob/3d6a5565f3141ac42f8353d97b2c016da2752006/event/timing.go#L33-L40 |
11,608 | quipo/statsd | event/interface.go | _ | func _() {
var _ Event = (*Absolute)(nil) // assert *Absolute implements Event
var _ Event = (*FAbsolute)(nil) // assert *FAbsolute implements Event
var _ Event = (*Gauge)(nil) // assert *Gauge implements Event
var _ Event = (*FGauge)(nil) // assert *FGauge implements Event
var _ Event = (*GaugeDelta)(nil) // assert *GaugeDelta implements Event
var _ Event = (*FGaugeDelta)(nil) // assert *FGaugeDelta implements Event
var _ Event = (*Increment)(nil) // assert *Increment implements Event
var _ Event = (*PrecisionTiming)(nil) // assert *PrecisionTiming implements Event
var _ Event = (*Timing)(nil) // assert *Timing implements Event
var _ Event = (*Total)(nil) // assert *Total implements Event
} | go | func _() {
var _ Event = (*Absolute)(nil) // assert *Absolute implements Event
var _ Event = (*FAbsolute)(nil) // assert *FAbsolute implements Event
var _ Event = (*Gauge)(nil) // assert *Gauge implements Event
var _ Event = (*FGauge)(nil) // assert *FGauge implements Event
var _ Event = (*GaugeDelta)(nil) // assert *GaugeDelta implements Event
var _ Event = (*FGaugeDelta)(nil) // assert *FGaugeDelta implements Event
var _ Event = (*Increment)(nil) // assert *Increment implements Event
var _ Event = (*PrecisionTiming)(nil) // assert *PrecisionTiming implements Event
var _ Event = (*Timing)(nil) // assert *Timing implements Event
var _ Event = (*Total)(nil) // assert *Total implements Event
} | [
"func",
"_",
"(",
")",
"{",
"var",
"_",
"Event",
"=",
"(",
"*",
"Absolute",
")",
"(",
"nil",
")",
"// assert *Absolute implements Event",
"\n",
"var",
"_",
"Event",
"=",
"(",
"*",
"FAbsolute",
")",
"(",
"nil",
")",
"// assert *FAbsolute implements Event",
"\n",
"var",
"_",
"Event",
"=",
"(",
"*",
"Gauge",
")",
"(",
"nil",
")",
"// assert *Gauge implements Event",
"\n",
"var",
"_",
"Event",
"=",
"(",
"*",
"FGauge",
")",
"(",
"nil",
")",
"// assert *FGauge implements Event",
"\n",
"var",
"_",
"Event",
"=",
"(",
"*",
"GaugeDelta",
")",
"(",
"nil",
")",
"// assert *GaugeDelta implements Event",
"\n",
"var",
"_",
"Event",
"=",
"(",
"*",
"FGaugeDelta",
")",
"(",
"nil",
")",
"// assert *FGaugeDelta implements Event",
"\n",
"var",
"_",
"Event",
"=",
"(",
"*",
"Increment",
")",
"(",
"nil",
")",
"// assert *Increment implements Event",
"\n",
"var",
"_",
"Event",
"=",
"(",
"*",
"PrecisionTiming",
")",
"(",
"nil",
")",
"// assert *PrecisionTiming implements Event",
"\n",
"var",
"_",
"Event",
"=",
"(",
"*",
"Timing",
")",
"(",
"nil",
")",
"// assert *Timing implements Event",
"\n",
"var",
"_",
"Event",
"=",
"(",
"*",
"Total",
")",
"(",
"nil",
")",
"// assert *Total implements Event",
"\n",
"}"
] | // compile-time assertion to verify default events implement the Event interface | [
"compile",
"-",
"time",
"assertion",
"to",
"verify",
"default",
"events",
"implement",
"the",
"Event",
"interface"
] | 3d6a5565f3141ac42f8353d97b2c016da2752006 | https://github.com/quipo/statsd/blob/3d6a5565f3141ac42f8353d97b2c016da2752006/event/interface.go#L30-L41 |
11,609 | quipo/statsd | mock/mockableclient.go | CreateSocket | func (msc *MockStatsdClient) CreateSocket() error {
if msc.CreateSocketFn == nil {
return nil
}
return msc.CreateSocketFn()
} | go | func (msc *MockStatsdClient) CreateSocket() error {
if msc.CreateSocketFn == nil {
return nil
}
return msc.CreateSocketFn()
} | [
"func",
"(",
"msc",
"*",
"MockStatsdClient",
")",
"CreateSocket",
"(",
")",
"error",
"{",
"if",
"msc",
".",
"CreateSocketFn",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"msc",
".",
"CreateSocketFn",
"(",
")",
"\n",
"}"
] | // Implement statsd interface | [
"Implement",
"statsd",
"interface"
] | 3d6a5565f3141ac42f8353d97b2c016da2752006 | https://github.com/quipo/statsd/blob/3d6a5565f3141ac42f8353d97b2c016da2752006/mock/mockableclient.go#L62-L67 |
11,610 | quipo/statsd | noopclient.go | PrecisionTiming | func (s NoopClient) PrecisionTiming(stat string, delta time.Duration) error {
return nil
} | go | func (s NoopClient) PrecisionTiming(stat string, delta time.Duration) error {
return nil
} | [
"func",
"(",
"s",
"NoopClient",
")",
"PrecisionTiming",
"(",
"stat",
"string",
",",
"delta",
"time",
".",
"Duration",
")",
"error",
"{",
"return",
"nil",
"\n",
"}"
] | // PrecisionTiming does nothing | [
"PrecisionTiming",
"does",
"nothing"
] | 3d6a5565f3141ac42f8353d97b2c016da2752006 | https://github.com/quipo/statsd/blob/3d6a5565f3141ac42f8353d97b2c016da2752006/noopclient.go#L45-L47 |
11,611 | quipo/statsd | stdoutclient.go | NewStdoutClient | func NewStdoutClient(filename string, prefix string) *StdoutClient {
var err error
// allow %HOST% in the prefix string
prefix = strings.Replace(prefix, "%HOST%", Hostname, 1)
var fh *os.File
if filename == "" {
fh = os.Stdout
} else {
fh, err = os.OpenFile(filename, os.O_WRONLY, 0644)
if nil != err {
fmt.Printf("Cannot open file '%s' for stats output: %s\n", filename, err.Error())
}
}
return &StdoutClient{
FD: fh,
prefix: prefix,
Logger: log.New(os.Stdout, "[StdoutClient] ", log.Ldate|log.Ltime),
}
} | go | func NewStdoutClient(filename string, prefix string) *StdoutClient {
var err error
// allow %HOST% in the prefix string
prefix = strings.Replace(prefix, "%HOST%", Hostname, 1)
var fh *os.File
if filename == "" {
fh = os.Stdout
} else {
fh, err = os.OpenFile(filename, os.O_WRONLY, 0644)
if nil != err {
fmt.Printf("Cannot open file '%s' for stats output: %s\n", filename, err.Error())
}
}
return &StdoutClient{
FD: fh,
prefix: prefix,
Logger: log.New(os.Stdout, "[StdoutClient] ", log.Ldate|log.Ltime),
}
} | [
"func",
"NewStdoutClient",
"(",
"filename",
"string",
",",
"prefix",
"string",
")",
"*",
"StdoutClient",
"{",
"var",
"err",
"error",
"\n",
"// allow %HOST% in the prefix string",
"prefix",
"=",
"strings",
".",
"Replace",
"(",
"prefix",
",",
"\"",
"\"",
",",
"Hostname",
",",
"1",
")",
"\n",
"var",
"fh",
"*",
"os",
".",
"File",
"\n",
"if",
"filename",
"==",
"\"",
"\"",
"{",
"fh",
"=",
"os",
".",
"Stdout",
"\n",
"}",
"else",
"{",
"fh",
",",
"err",
"=",
"os",
".",
"OpenFile",
"(",
"filename",
",",
"os",
".",
"O_WRONLY",
",",
"0644",
")",
"\n",
"if",
"nil",
"!=",
"err",
"{",
"fmt",
".",
"Printf",
"(",
"\"",
"\\n",
"\"",
",",
"filename",
",",
"err",
".",
"Error",
"(",
")",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"&",
"StdoutClient",
"{",
"FD",
":",
"fh",
",",
"prefix",
":",
"prefix",
",",
"Logger",
":",
"log",
".",
"New",
"(",
"os",
".",
"Stdout",
",",
"\"",
"\"",
",",
"log",
".",
"Ldate",
"|",
"log",
".",
"Ltime",
")",
",",
"}",
"\n",
"}"
] | // NewStdoutClient - Factory | [
"NewStdoutClient",
"-",
"Factory"
] | 3d6a5565f3141ac42f8353d97b2c016da2752006 | https://github.com/quipo/statsd/blob/3d6a5565f3141ac42f8353d97b2c016da2752006/stdoutclient.go#L21-L39 |
11,612 | quipo/statsd | stdoutclient.go | CreateSocket | func (s *StdoutClient) CreateSocket() error {
if s.FD == nil {
s.FD = os.Stdout
}
return nil
} | go | func (s *StdoutClient) CreateSocket() error {
if s.FD == nil {
s.FD = os.Stdout
}
return nil
} | [
"func",
"(",
"s",
"*",
"StdoutClient",
")",
"CreateSocket",
"(",
")",
"error",
"{",
"if",
"s",
".",
"FD",
"==",
"nil",
"{",
"s",
".",
"FD",
"=",
"os",
".",
"Stdout",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // CreateSocket does nothing | [
"CreateSocket",
"does",
"nothing"
] | 3d6a5565f3141ac42f8353d97b2c016da2752006 | https://github.com/quipo/statsd/blob/3d6a5565f3141ac42f8353d97b2c016da2752006/stdoutclient.go#L42-L47 |
11,613 | quipo/statsd | stdoutclient.go | CreateTCPSocket | func (s *StdoutClient) CreateTCPSocket() error {
if s.FD == nil {
s.FD = os.Stdout
}
return nil
} | go | func (s *StdoutClient) CreateTCPSocket() error {
if s.FD == nil {
s.FD = os.Stdout
}
return nil
} | [
"func",
"(",
"s",
"*",
"StdoutClient",
")",
"CreateTCPSocket",
"(",
")",
"error",
"{",
"if",
"s",
".",
"FD",
"==",
"nil",
"{",
"s",
".",
"FD",
"=",
"os",
".",
"Stdout",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // CreateTCPSocket does nothing | [
"CreateTCPSocket",
"does",
"nothing"
] | 3d6a5565f3141ac42f8353d97b2c016da2752006 | https://github.com/quipo/statsd/blob/3d6a5565f3141ac42f8353d97b2c016da2752006/stdoutclient.go#L50-L55 |
11,614 | rs/xlog | util.go | writeValue | func writeValue(w io.Writer, v interface{}) (err error) {
switch v := v.(type) {
case nil:
_, err = w.Write([]byte("null"))
case string:
if strings.IndexFunc(v, needsQuotedValueRune) != -1 {
var b []byte
b, err = json.Marshal(v)
if err == nil {
w.Write(b)
}
} else {
_, err = w.Write([]byte(v))
}
case error:
s := v.Error()
err = writeValue(w, s)
default:
s := fmt.Sprint(v)
err = writeValue(w, s)
}
return
} | go | func writeValue(w io.Writer, v interface{}) (err error) {
switch v := v.(type) {
case nil:
_, err = w.Write([]byte("null"))
case string:
if strings.IndexFunc(v, needsQuotedValueRune) != -1 {
var b []byte
b, err = json.Marshal(v)
if err == nil {
w.Write(b)
}
} else {
_, err = w.Write([]byte(v))
}
case error:
s := v.Error()
err = writeValue(w, s)
default:
s := fmt.Sprint(v)
err = writeValue(w, s)
}
return
} | [
"func",
"writeValue",
"(",
"w",
"io",
".",
"Writer",
",",
"v",
"interface",
"{",
"}",
")",
"(",
"err",
"error",
")",
"{",
"switch",
"v",
":=",
"v",
".",
"(",
"type",
")",
"{",
"case",
"nil",
":",
"_",
",",
"err",
"=",
"w",
".",
"Write",
"(",
"[",
"]",
"byte",
"(",
"\"",
"\"",
")",
")",
"\n",
"case",
"string",
":",
"if",
"strings",
".",
"IndexFunc",
"(",
"v",
",",
"needsQuotedValueRune",
")",
"!=",
"-",
"1",
"{",
"var",
"b",
"[",
"]",
"byte",
"\n",
"b",
",",
"err",
"=",
"json",
".",
"Marshal",
"(",
"v",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"w",
".",
"Write",
"(",
"b",
")",
"\n",
"}",
"\n",
"}",
"else",
"{",
"_",
",",
"err",
"=",
"w",
".",
"Write",
"(",
"[",
"]",
"byte",
"(",
"v",
")",
")",
"\n",
"}",
"\n",
"case",
"error",
":",
"s",
":=",
"v",
".",
"Error",
"(",
")",
"\n",
"err",
"=",
"writeValue",
"(",
"w",
",",
"s",
")",
"\n",
"default",
":",
"s",
":=",
"fmt",
".",
"Sprint",
"(",
"v",
")",
"\n",
"err",
"=",
"writeValue",
"(",
"w",
",",
"s",
")",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] | // writeValue writes a value on the writer in a logfmt compatible way | [
"writeValue",
"writes",
"a",
"value",
"on",
"the",
"writer",
"in",
"a",
"logfmt",
"compatible",
"way"
] | 131980fab91b04c953b9dcb438298a7f06cf76cb | https://github.com/rs/xlog/blob/131980fab91b04c953b9dcb438298a7f06cf76cb/util.go#L31-L53 |
11,615 | rs/xlog | handler_pre17.go | IDFromContext | func IDFromContext(ctx context.Context) (xid.ID, bool) {
id, ok := ctx.Value(idKey).(xid.ID)
return id, ok
} | go | func IDFromContext(ctx context.Context) (xid.ID, bool) {
id, ok := ctx.Value(idKey).(xid.ID)
return id, ok
} | [
"func",
"IDFromContext",
"(",
"ctx",
"context",
".",
"Context",
")",
"(",
"xid",
".",
"ID",
",",
"bool",
")",
"{",
"id",
",",
"ok",
":=",
"ctx",
".",
"Value",
"(",
"idKey",
")",
".",
"(",
"xid",
".",
"ID",
")",
"\n",
"return",
"id",
",",
"ok",
"\n",
"}"
] | // IDFromContext returns the unique id associated to the request if any. | [
"IDFromContext",
"returns",
"the",
"unique",
"id",
"associated",
"to",
"the",
"request",
"if",
"any",
"."
] | 131980fab91b04c953b9dcb438298a7f06cf76cb | https://github.com/rs/xlog/blob/131980fab91b04c953b9dcb438298a7f06cf76cb/handler_pre17.go#L22-L25 |
11,616 | rs/xlog | handler_pre17.go | FromContext | func FromContext(ctx context.Context) Logger {
if ctx == nil {
return NopLogger
}
l, ok := ctx.Value(logKey).(Logger)
if !ok {
return NopLogger
}
return l
} | go | func FromContext(ctx context.Context) Logger {
if ctx == nil {
return NopLogger
}
l, ok := ctx.Value(logKey).(Logger)
if !ok {
return NopLogger
}
return l
} | [
"func",
"FromContext",
"(",
"ctx",
"context",
".",
"Context",
")",
"Logger",
"{",
"if",
"ctx",
"==",
"nil",
"{",
"return",
"NopLogger",
"\n",
"}",
"\n",
"l",
",",
"ok",
":=",
"ctx",
".",
"Value",
"(",
"logKey",
")",
".",
"(",
"Logger",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"NopLogger",
"\n",
"}",
"\n",
"return",
"l",
"\n",
"}"
] | // FromContext gets the logger out of the context.
// If not logger is stored in the context, a NopLogger is returned. | [
"FromContext",
"gets",
"the",
"logger",
"out",
"of",
"the",
"context",
".",
"If",
"not",
"logger",
"is",
"stored",
"in",
"the",
"context",
"a",
"NopLogger",
"is",
"returned",
"."
] | 131980fab91b04c953b9dcb438298a7f06cf76cb | https://github.com/rs/xlog/blob/131980fab91b04c953b9dcb438298a7f06cf76cb/handler_pre17.go#L29-L38 |
11,617 | rs/xlog | handler_pre17.go | NewContext | func NewContext(ctx context.Context, l Logger) context.Context {
return context.WithValue(ctx, logKey, l)
} | go | func NewContext(ctx context.Context, l Logger) context.Context {
return context.WithValue(ctx, logKey, l)
} | [
"func",
"NewContext",
"(",
"ctx",
"context",
".",
"Context",
",",
"l",
"Logger",
")",
"context",
".",
"Context",
"{",
"return",
"context",
".",
"WithValue",
"(",
"ctx",
",",
"logKey",
",",
"l",
")",
"\n",
"}"
] | // NewContext returns a copy of the parent context and associates it with the provided logger. | [
"NewContext",
"returns",
"a",
"copy",
"of",
"the",
"parent",
"context",
"and",
"associates",
"it",
"with",
"the",
"provided",
"logger",
"."
] | 131980fab91b04c953b9dcb438298a7f06cf76cb | https://github.com/rs/xlog/blob/131980fab91b04c953b9dcb438298a7f06cf76cb/handler_pre17.go#L41-L43 |
11,618 | rs/xlog | handler_pre17.go | RequestHandler | func RequestHandler(name string) func(next xhandler.HandlerC) xhandler.HandlerC {
return func(next xhandler.HandlerC) xhandler.HandlerC {
return xhandler.HandlerFuncC(func(ctx context.Context, w http.ResponseWriter, r *http.Request) {
FromContext(ctx).SetField(name, r.Method+" "+r.URL.String())
next.ServeHTTPC(ctx, w, r)
})
}
} | go | func RequestHandler(name string) func(next xhandler.HandlerC) xhandler.HandlerC {
return func(next xhandler.HandlerC) xhandler.HandlerC {
return xhandler.HandlerFuncC(func(ctx context.Context, w http.ResponseWriter, r *http.Request) {
FromContext(ctx).SetField(name, r.Method+" "+r.URL.String())
next.ServeHTTPC(ctx, w, r)
})
}
} | [
"func",
"RequestHandler",
"(",
"name",
"string",
")",
"func",
"(",
"next",
"xhandler",
".",
"HandlerC",
")",
"xhandler",
".",
"HandlerC",
"{",
"return",
"func",
"(",
"next",
"xhandler",
".",
"HandlerC",
")",
"xhandler",
".",
"HandlerC",
"{",
"return",
"xhandler",
".",
"HandlerFuncC",
"(",
"func",
"(",
"ctx",
"context",
".",
"Context",
",",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"FromContext",
"(",
"ctx",
")",
".",
"SetField",
"(",
"name",
",",
"r",
".",
"Method",
"+",
"\"",
"\"",
"+",
"r",
".",
"URL",
".",
"String",
"(",
")",
")",
"\n",
"next",
".",
"ServeHTTPC",
"(",
"ctx",
",",
"w",
",",
"r",
")",
"\n",
"}",
")",
"\n",
"}",
"\n",
"}"
] | // RequestHandler returns a handler setting the request's method and URL as a field
// to the current context's logger using the passed name as field name. | [
"RequestHandler",
"returns",
"a",
"handler",
"setting",
"the",
"request",
"s",
"method",
"and",
"URL",
"as",
"a",
"field",
"to",
"the",
"current",
"context",
"s",
"logger",
"using",
"the",
"passed",
"name",
"as",
"field",
"name",
"."
] | 131980fab91b04c953b9dcb438298a7f06cf76cb | https://github.com/rs/xlog/blob/131980fab91b04c953b9dcb438298a7f06cf76cb/handler_pre17.go#L88-L95 |
11,619 | rs/xlog | xlog.go | New | func New(c Config) Logger {
var l *logger
if c.DisablePooling {
l = &logger{}
} else {
l = loggerPool.Get().(*logger)
}
l.level = c.Level
l.output = c.Output
if l.output == nil {
l.output = NewOutputChannel(NewConsoleOutput())
}
for k, v := range c.Fields {
l.SetField(k, v)
}
l.disablePooling = c.DisablePooling
return l
} | go | func New(c Config) Logger {
var l *logger
if c.DisablePooling {
l = &logger{}
} else {
l = loggerPool.Get().(*logger)
}
l.level = c.Level
l.output = c.Output
if l.output == nil {
l.output = NewOutputChannel(NewConsoleOutput())
}
for k, v := range c.Fields {
l.SetField(k, v)
}
l.disablePooling = c.DisablePooling
return l
} | [
"func",
"New",
"(",
"c",
"Config",
")",
"Logger",
"{",
"var",
"l",
"*",
"logger",
"\n",
"if",
"c",
".",
"DisablePooling",
"{",
"l",
"=",
"&",
"logger",
"{",
"}",
"\n",
"}",
"else",
"{",
"l",
"=",
"loggerPool",
".",
"Get",
"(",
")",
".",
"(",
"*",
"logger",
")",
"\n",
"}",
"\n",
"l",
".",
"level",
"=",
"c",
".",
"Level",
"\n",
"l",
".",
"output",
"=",
"c",
".",
"Output",
"\n",
"if",
"l",
".",
"output",
"==",
"nil",
"{",
"l",
".",
"output",
"=",
"NewOutputChannel",
"(",
"NewConsoleOutput",
"(",
")",
")",
"\n",
"}",
"\n",
"for",
"k",
",",
"v",
":=",
"range",
"c",
".",
"Fields",
"{",
"l",
".",
"SetField",
"(",
"k",
",",
"v",
")",
"\n",
"}",
"\n",
"l",
".",
"disablePooling",
"=",
"c",
".",
"DisablePooling",
"\n",
"return",
"l",
"\n",
"}"
] | // New manually creates a logger.
//
// This function should only be used out of a request. Use FromContext in request. | [
"New",
"manually",
"creates",
"a",
"logger",
".",
"This",
"function",
"should",
"only",
"be",
"used",
"out",
"of",
"a",
"request",
".",
"Use",
"FromContext",
"in",
"request",
"."
] | 131980fab91b04c953b9dcb438298a7f06cf76cb | https://github.com/rs/xlog/blob/131980fab91b04c953b9dcb438298a7f06cf76cb/xlog.go#L139-L156 |
11,620 | rs/xlog | xlog.go | Copy | func Copy(l Logger) Logger {
if l, ok := l.(LoggerCopier); ok {
return l.Copy()
}
return NopLogger
} | go | func Copy(l Logger) Logger {
if l, ok := l.(LoggerCopier); ok {
return l.Copy()
}
return NopLogger
} | [
"func",
"Copy",
"(",
"l",
"Logger",
")",
"Logger",
"{",
"if",
"l",
",",
"ok",
":=",
"l",
".",
"(",
"LoggerCopier",
")",
";",
"ok",
"{",
"return",
"l",
".",
"Copy",
"(",
")",
"\n",
"}",
"\n",
"return",
"NopLogger",
"\n",
"}"
] | // Copy returns a copy of the passed logger if the logger implements
// LoggerCopier or the NopLogger otherwise. | [
"Copy",
"returns",
"a",
"copy",
"of",
"the",
"passed",
"logger",
"if",
"the",
"logger",
"implements",
"LoggerCopier",
"or",
"the",
"NopLogger",
"otherwise",
"."
] | 131980fab91b04c953b9dcb438298a7f06cf76cb | https://github.com/rs/xlog/blob/131980fab91b04c953b9dcb438298a7f06cf76cb/xlog.go#L160-L165 |
11,621 | rs/xlog | xlog.go | Copy | func (l *logger) Copy() Logger {
l2 := &logger{
level: l.level,
output: l.output,
fields: map[string]interface{}{},
disablePooling: l.disablePooling,
}
for k, v := range l.fields {
l2.fields[k] = v
}
return l2
} | go | func (l *logger) Copy() Logger {
l2 := &logger{
level: l.level,
output: l.output,
fields: map[string]interface{}{},
disablePooling: l.disablePooling,
}
for k, v := range l.fields {
l2.fields[k] = v
}
return l2
} | [
"func",
"(",
"l",
"*",
"logger",
")",
"Copy",
"(",
")",
"Logger",
"{",
"l2",
":=",
"&",
"logger",
"{",
"level",
":",
"l",
".",
"level",
",",
"output",
":",
"l",
".",
"output",
",",
"fields",
":",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"}",
",",
"disablePooling",
":",
"l",
".",
"disablePooling",
",",
"}",
"\n",
"for",
"k",
",",
"v",
":=",
"range",
"l",
".",
"fields",
"{",
"l2",
".",
"fields",
"[",
"k",
"]",
"=",
"v",
"\n",
"}",
"\n",
"return",
"l2",
"\n",
"}"
] | // Copy returns a copy of the logger | [
"Copy",
"returns",
"a",
"copy",
"of",
"the",
"logger"
] | 131980fab91b04c953b9dcb438298a7f06cf76cb | https://github.com/rs/xlog/blob/131980fab91b04c953b9dcb438298a7f06cf76cb/xlog.go#L168-L179 |
11,622 | rs/xlog | xlog.go | close | func (l *logger) close() {
if !l.disablePooling {
l.level = 0
l.output = nil
l.fields = nil
loggerPool.Put(l)
}
} | go | func (l *logger) close() {
if !l.disablePooling {
l.level = 0
l.output = nil
l.fields = nil
loggerPool.Put(l)
}
} | [
"func",
"(",
"l",
"*",
"logger",
")",
"close",
"(",
")",
"{",
"if",
"!",
"l",
".",
"disablePooling",
"{",
"l",
".",
"level",
"=",
"0",
"\n",
"l",
".",
"output",
"=",
"nil",
"\n",
"l",
".",
"fields",
"=",
"nil",
"\n",
"loggerPool",
".",
"Put",
"(",
"l",
")",
"\n",
"}",
"\n",
"}"
] | // close returns the logger to the pool for reuse | [
"close",
"returns",
"the",
"logger",
"to",
"the",
"pool",
"for",
"reuse"
] | 131980fab91b04c953b9dcb438298a7f06cf76cb | https://github.com/rs/xlog/blob/131980fab91b04c953b9dcb438298a7f06cf76cb/xlog.go#L182-L189 |
11,623 | rs/xlog | xlog.go | SetField | func (l *logger) SetField(name string, value interface{}) {
if l.fields == nil {
l.fields = map[string]interface{}{}
}
l.fields[name] = value
} | go | func (l *logger) SetField(name string, value interface{}) {
if l.fields == nil {
l.fields = map[string]interface{}{}
}
l.fields[name] = value
} | [
"func",
"(",
"l",
"*",
"logger",
")",
"SetField",
"(",
"name",
"string",
",",
"value",
"interface",
"{",
"}",
")",
"{",
"if",
"l",
".",
"fields",
"==",
"nil",
"{",
"l",
".",
"fields",
"=",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"}",
"\n",
"}",
"\n",
"l",
".",
"fields",
"[",
"name",
"]",
"=",
"value",
"\n",
"}"
] | // SetField implements Logger interface | [
"SetField",
"implements",
"Logger",
"interface"
] | 131980fab91b04c953b9dcb438298a7f06cf76cb | https://github.com/rs/xlog/blob/131980fab91b04c953b9dcb438298a7f06cf76cb/xlog.go#L230-L235 |
11,624 | rs/xlog | xlog.go | OutputF | func (l *logger) OutputF(level Level, calldepth int, msg string, fields map[string]interface{}) {
l.send(level, calldepth+1, msg, fields)
} | go | func (l *logger) OutputF(level Level, calldepth int, msg string, fields map[string]interface{}) {
l.send(level, calldepth+1, msg, fields)
} | [
"func",
"(",
"l",
"*",
"logger",
")",
"OutputF",
"(",
"level",
"Level",
",",
"calldepth",
"int",
",",
"msg",
"string",
",",
"fields",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"{",
"l",
".",
"send",
"(",
"level",
",",
"calldepth",
"+",
"1",
",",
"msg",
",",
"fields",
")",
"\n",
"}"
] | // Output implements Logger interface | [
"Output",
"implements",
"Logger",
"interface"
] | 131980fab91b04c953b9dcb438298a7f06cf76cb | https://github.com/rs/xlog/blob/131980fab91b04c953b9dcb438298a7f06cf76cb/xlog.go#L243-L245 |
11,625 | rs/xlog | xlog.go | Debug | func (l *logger) Debug(v ...interface{}) {
f := extractFields(&v)
l.send(LevelDebug, 2, fmt.Sprint(v...), f)
} | go | func (l *logger) Debug(v ...interface{}) {
f := extractFields(&v)
l.send(LevelDebug, 2, fmt.Sprint(v...), f)
} | [
"func",
"(",
"l",
"*",
"logger",
")",
"Debug",
"(",
"v",
"...",
"interface",
"{",
"}",
")",
"{",
"f",
":=",
"extractFields",
"(",
"&",
"v",
")",
"\n",
"l",
".",
"send",
"(",
"LevelDebug",
",",
"2",
",",
"fmt",
".",
"Sprint",
"(",
"v",
"...",
")",
",",
"f",
")",
"\n",
"}"
] | // Debug implements Logger interface | [
"Debug",
"implements",
"Logger",
"interface"
] | 131980fab91b04c953b9dcb438298a7f06cf76cb | https://github.com/rs/xlog/blob/131980fab91b04c953b9dcb438298a7f06cf76cb/xlog.go#L248-L251 |
11,626 | rs/xlog | xlog.go | Debugf | func (l *logger) Debugf(format string, v ...interface{}) {
f := extractFields(&v)
l.send(LevelDebug, 2, fmt.Sprintf(format, v...), f)
} | go | func (l *logger) Debugf(format string, v ...interface{}) {
f := extractFields(&v)
l.send(LevelDebug, 2, fmt.Sprintf(format, v...), f)
} | [
"func",
"(",
"l",
"*",
"logger",
")",
"Debugf",
"(",
"format",
"string",
",",
"v",
"...",
"interface",
"{",
"}",
")",
"{",
"f",
":=",
"extractFields",
"(",
"&",
"v",
")",
"\n",
"l",
".",
"send",
"(",
"LevelDebug",
",",
"2",
",",
"fmt",
".",
"Sprintf",
"(",
"format",
",",
"v",
"...",
")",
",",
"f",
")",
"\n",
"}"
] | // Debugf implements Logger interface | [
"Debugf",
"implements",
"Logger",
"interface"
] | 131980fab91b04c953b9dcb438298a7f06cf76cb | https://github.com/rs/xlog/blob/131980fab91b04c953b9dcb438298a7f06cf76cb/xlog.go#L254-L257 |
11,627 | rs/xlog | xlog.go | Info | func (l *logger) Info(v ...interface{}) {
f := extractFields(&v)
l.send(LevelInfo, 2, fmt.Sprint(v...), f)
} | go | func (l *logger) Info(v ...interface{}) {
f := extractFields(&v)
l.send(LevelInfo, 2, fmt.Sprint(v...), f)
} | [
"func",
"(",
"l",
"*",
"logger",
")",
"Info",
"(",
"v",
"...",
"interface",
"{",
"}",
")",
"{",
"f",
":=",
"extractFields",
"(",
"&",
"v",
")",
"\n",
"l",
".",
"send",
"(",
"LevelInfo",
",",
"2",
",",
"fmt",
".",
"Sprint",
"(",
"v",
"...",
")",
",",
"f",
")",
"\n",
"}"
] | // Info implements Logger interface | [
"Info",
"implements",
"Logger",
"interface"
] | 131980fab91b04c953b9dcb438298a7f06cf76cb | https://github.com/rs/xlog/blob/131980fab91b04c953b9dcb438298a7f06cf76cb/xlog.go#L260-L263 |
11,628 | rs/xlog | xlog.go | Infof | func (l *logger) Infof(format string, v ...interface{}) {
f := extractFields(&v)
l.send(LevelInfo, 2, fmt.Sprintf(format, v...), f)
} | go | func (l *logger) Infof(format string, v ...interface{}) {
f := extractFields(&v)
l.send(LevelInfo, 2, fmt.Sprintf(format, v...), f)
} | [
"func",
"(",
"l",
"*",
"logger",
")",
"Infof",
"(",
"format",
"string",
",",
"v",
"...",
"interface",
"{",
"}",
")",
"{",
"f",
":=",
"extractFields",
"(",
"&",
"v",
")",
"\n",
"l",
".",
"send",
"(",
"LevelInfo",
",",
"2",
",",
"fmt",
".",
"Sprintf",
"(",
"format",
",",
"v",
"...",
")",
",",
"f",
")",
"\n",
"}"
] | // Infof implements Logger interface | [
"Infof",
"implements",
"Logger",
"interface"
] | 131980fab91b04c953b9dcb438298a7f06cf76cb | https://github.com/rs/xlog/blob/131980fab91b04c953b9dcb438298a7f06cf76cb/xlog.go#L266-L269 |
11,629 | rs/xlog | xlog.go | Warn | func (l *logger) Warn(v ...interface{}) {
f := extractFields(&v)
l.send(LevelWarn, 2, fmt.Sprint(v...), f)
} | go | func (l *logger) Warn(v ...interface{}) {
f := extractFields(&v)
l.send(LevelWarn, 2, fmt.Sprint(v...), f)
} | [
"func",
"(",
"l",
"*",
"logger",
")",
"Warn",
"(",
"v",
"...",
"interface",
"{",
"}",
")",
"{",
"f",
":=",
"extractFields",
"(",
"&",
"v",
")",
"\n",
"l",
".",
"send",
"(",
"LevelWarn",
",",
"2",
",",
"fmt",
".",
"Sprint",
"(",
"v",
"...",
")",
",",
"f",
")",
"\n",
"}"
] | // Warn implements Logger interface | [
"Warn",
"implements",
"Logger",
"interface"
] | 131980fab91b04c953b9dcb438298a7f06cf76cb | https://github.com/rs/xlog/blob/131980fab91b04c953b9dcb438298a7f06cf76cb/xlog.go#L272-L275 |
11,630 | rs/xlog | xlog.go | Warnf | func (l *logger) Warnf(format string, v ...interface{}) {
f := extractFields(&v)
l.send(LevelWarn, 2, fmt.Sprintf(format, v...), f)
} | go | func (l *logger) Warnf(format string, v ...interface{}) {
f := extractFields(&v)
l.send(LevelWarn, 2, fmt.Sprintf(format, v...), f)
} | [
"func",
"(",
"l",
"*",
"logger",
")",
"Warnf",
"(",
"format",
"string",
",",
"v",
"...",
"interface",
"{",
"}",
")",
"{",
"f",
":=",
"extractFields",
"(",
"&",
"v",
")",
"\n",
"l",
".",
"send",
"(",
"LevelWarn",
",",
"2",
",",
"fmt",
".",
"Sprintf",
"(",
"format",
",",
"v",
"...",
")",
",",
"f",
")",
"\n",
"}"
] | // Warnf implements Logger interface | [
"Warnf",
"implements",
"Logger",
"interface"
] | 131980fab91b04c953b9dcb438298a7f06cf76cb | https://github.com/rs/xlog/blob/131980fab91b04c953b9dcb438298a7f06cf76cb/xlog.go#L278-L281 |
11,631 | rs/xlog | xlog.go | Error | func (l *logger) Error(v ...interface{}) {
f := extractFields(&v)
l.send(LevelError, 2, fmt.Sprint(v...), f)
} | go | func (l *logger) Error(v ...interface{}) {
f := extractFields(&v)
l.send(LevelError, 2, fmt.Sprint(v...), f)
} | [
"func",
"(",
"l",
"*",
"logger",
")",
"Error",
"(",
"v",
"...",
"interface",
"{",
"}",
")",
"{",
"f",
":=",
"extractFields",
"(",
"&",
"v",
")",
"\n",
"l",
".",
"send",
"(",
"LevelError",
",",
"2",
",",
"fmt",
".",
"Sprint",
"(",
"v",
"...",
")",
",",
"f",
")",
"\n",
"}"
] | // Error implements Logger interface | [
"Error",
"implements",
"Logger",
"interface"
] | 131980fab91b04c953b9dcb438298a7f06cf76cb | https://github.com/rs/xlog/blob/131980fab91b04c953b9dcb438298a7f06cf76cb/xlog.go#L284-L287 |
11,632 | rs/xlog | xlog.go | Write | func (l *logger) Write(p []byte) (int, error) {
msg := strings.TrimRight(string(p), "\n")
l.send(LevelInfo, 4, msg, nil)
if o, ok := l.output.(*OutputChannel); ok {
o.Flush()
}
return len(p), nil
} | go | func (l *logger) Write(p []byte) (int, error) {
msg := strings.TrimRight(string(p), "\n")
l.send(LevelInfo, 4, msg, nil)
if o, ok := l.output.(*OutputChannel); ok {
o.Flush()
}
return len(p), nil
} | [
"func",
"(",
"l",
"*",
"logger",
")",
"Write",
"(",
"p",
"[",
"]",
"byte",
")",
"(",
"int",
",",
"error",
")",
"{",
"msg",
":=",
"strings",
".",
"TrimRight",
"(",
"string",
"(",
"p",
")",
",",
"\"",
"\\n",
"\"",
")",
"\n",
"l",
".",
"send",
"(",
"LevelInfo",
",",
"4",
",",
"msg",
",",
"nil",
")",
"\n",
"if",
"o",
",",
"ok",
":=",
"l",
".",
"output",
".",
"(",
"*",
"OutputChannel",
")",
";",
"ok",
"{",
"o",
".",
"Flush",
"(",
")",
"\n",
"}",
"\n",
"return",
"len",
"(",
"p",
")",
",",
"nil",
"\n",
"}"
] | // Write implements io.Writer interface | [
"Write",
"implements",
"io",
".",
"Writer",
"interface"
] | 131980fab91b04c953b9dcb438298a7f06cf76cb | https://github.com/rs/xlog/blob/131980fab91b04c953b9dcb438298a7f06cf76cb/xlog.go#L336-L343 |
11,633 | rs/xlog | xlog.go | Output | func (l *logger) Output(calldepth int, s string) error {
l.send(LevelInfo, 2, s, nil)
return nil
} | go | func (l *logger) Output(calldepth int, s string) error {
l.send(LevelInfo, 2, s, nil)
return nil
} | [
"func",
"(",
"l",
"*",
"logger",
")",
"Output",
"(",
"calldepth",
"int",
",",
"s",
"string",
")",
"error",
"{",
"l",
".",
"send",
"(",
"LevelInfo",
",",
"2",
",",
"s",
",",
"nil",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | // Output implements common logger interface | [
"Output",
"implements",
"common",
"logger",
"interface"
] | 131980fab91b04c953b9dcb438298a7f06cf76cb | https://github.com/rs/xlog/blob/131980fab91b04c953b9dcb438298a7f06cf76cb/xlog.go#L346-L349 |
11,634 | rs/xlog | output_syslog.go | NewSyslogOutput | func NewSyslogOutput(network, address, tag string) Output {
return NewSyslogOutputFacility(network, address, tag, syslog.LOG_USER)
} | go | func NewSyslogOutput(network, address, tag string) Output {
return NewSyslogOutputFacility(network, address, tag, syslog.LOG_USER)
} | [
"func",
"NewSyslogOutput",
"(",
"network",
",",
"address",
",",
"tag",
"string",
")",
"Output",
"{",
"return",
"NewSyslogOutputFacility",
"(",
"network",
",",
"address",
",",
"tag",
",",
"syslog",
".",
"LOG_USER",
")",
"\n",
"}"
] | // NewSyslogOutput returns JSONOutputs in a LevelOutput with writers set to syslog
// with the proper priority added to a LOG_USER facility.
// If network and address are empty, Dial will connect to the local syslog server. | [
"NewSyslogOutput",
"returns",
"JSONOutputs",
"in",
"a",
"LevelOutput",
"with",
"writers",
"set",
"to",
"syslog",
"with",
"the",
"proper",
"priority",
"added",
"to",
"a",
"LOG_USER",
"facility",
".",
"If",
"network",
"and",
"address",
"are",
"empty",
"Dial",
"will",
"connect",
"to",
"the",
"local",
"syslog",
"server",
"."
] | 131980fab91b04c953b9dcb438298a7f06cf76cb | https://github.com/rs/xlog/blob/131980fab91b04c953b9dcb438298a7f06cf76cb/output_syslog.go#L13-L15 |
11,635 | rs/xlog | output_syslog.go | NewSyslogOutputFacility | func NewSyslogOutputFacility(network, address, tag string, facility syslog.Priority) Output {
o := LevelOutput{
Debug: NewJSONOutput(NewSyslogWriter(network, address, facility|syslog.LOG_DEBUG, tag)),
Info: NewJSONOutput(NewSyslogWriter(network, address, facility|syslog.LOG_INFO, tag)),
Warn: NewJSONOutput(NewSyslogWriter(network, address, facility|syslog.LOG_WARNING, tag)),
Error: NewJSONOutput(NewSyslogWriter(network, address, facility|syslog.LOG_ERR, tag)),
}
return o
} | go | func NewSyslogOutputFacility(network, address, tag string, facility syslog.Priority) Output {
o := LevelOutput{
Debug: NewJSONOutput(NewSyslogWriter(network, address, facility|syslog.LOG_DEBUG, tag)),
Info: NewJSONOutput(NewSyslogWriter(network, address, facility|syslog.LOG_INFO, tag)),
Warn: NewJSONOutput(NewSyslogWriter(network, address, facility|syslog.LOG_WARNING, tag)),
Error: NewJSONOutput(NewSyslogWriter(network, address, facility|syslog.LOG_ERR, tag)),
}
return o
} | [
"func",
"NewSyslogOutputFacility",
"(",
"network",
",",
"address",
",",
"tag",
"string",
",",
"facility",
"syslog",
".",
"Priority",
")",
"Output",
"{",
"o",
":=",
"LevelOutput",
"{",
"Debug",
":",
"NewJSONOutput",
"(",
"NewSyslogWriter",
"(",
"network",
",",
"address",
",",
"facility",
"|",
"syslog",
".",
"LOG_DEBUG",
",",
"tag",
")",
")",
",",
"Info",
":",
"NewJSONOutput",
"(",
"NewSyslogWriter",
"(",
"network",
",",
"address",
",",
"facility",
"|",
"syslog",
".",
"LOG_INFO",
",",
"tag",
")",
")",
",",
"Warn",
":",
"NewJSONOutput",
"(",
"NewSyslogWriter",
"(",
"network",
",",
"address",
",",
"facility",
"|",
"syslog",
".",
"LOG_WARNING",
",",
"tag",
")",
")",
",",
"Error",
":",
"NewJSONOutput",
"(",
"NewSyslogWriter",
"(",
"network",
",",
"address",
",",
"facility",
"|",
"syslog",
".",
"LOG_ERR",
",",
"tag",
")",
")",
",",
"}",
"\n",
"return",
"o",
"\n",
"}"
] | // NewSyslogOutputFacility returns JSONOutputs in a LevelOutput with writers set to syslog
// with the proper priority added to the passed facility.
// If network and address are empty, Dial will connect to the local syslog server. | [
"NewSyslogOutputFacility",
"returns",
"JSONOutputs",
"in",
"a",
"LevelOutput",
"with",
"writers",
"set",
"to",
"syslog",
"with",
"the",
"proper",
"priority",
"added",
"to",
"the",
"passed",
"facility",
".",
"If",
"network",
"and",
"address",
"are",
"empty",
"Dial",
"will",
"connect",
"to",
"the",
"local",
"syslog",
"server",
"."
] | 131980fab91b04c953b9dcb438298a7f06cf76cb | https://github.com/rs/xlog/blob/131980fab91b04c953b9dcb438298a7f06cf76cb/output_syslog.go#L20-L28 |
11,636 | rs/xlog | output_syslog.go | NewSyslogWriter | func NewSyslogWriter(network, address string, prio syslog.Priority, tag string) io.Writer {
s, err := syslog.Dial(network, address, prio, tag)
if err != nil {
m := "syslog dial error: " + err.Error()
critialLogger.Print(m)
panic(m)
}
return s
} | go | func NewSyslogWriter(network, address string, prio syslog.Priority, tag string) io.Writer {
s, err := syslog.Dial(network, address, prio, tag)
if err != nil {
m := "syslog dial error: " + err.Error()
critialLogger.Print(m)
panic(m)
}
return s
} | [
"func",
"NewSyslogWriter",
"(",
"network",
",",
"address",
"string",
",",
"prio",
"syslog",
".",
"Priority",
",",
"tag",
"string",
")",
"io",
".",
"Writer",
"{",
"s",
",",
"err",
":=",
"syslog",
".",
"Dial",
"(",
"network",
",",
"address",
",",
"prio",
",",
"tag",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"m",
":=",
"\"",
"\"",
"+",
"err",
".",
"Error",
"(",
")",
"\n",
"critialLogger",
".",
"Print",
"(",
"m",
")",
"\n",
"panic",
"(",
"m",
")",
"\n",
"}",
"\n",
"return",
"s",
"\n",
"}"
] | // NewSyslogWriter returns a writer ready to be used with output modules.
// If network and address are empty, Dial will connect to the local syslog server. | [
"NewSyslogWriter",
"returns",
"a",
"writer",
"ready",
"to",
"be",
"used",
"with",
"output",
"modules",
".",
"If",
"network",
"and",
"address",
"are",
"empty",
"Dial",
"will",
"connect",
"to",
"the",
"local",
"syslog",
"server",
"."
] | 131980fab91b04c953b9dcb438298a7f06cf76cb | https://github.com/rs/xlog/blob/131980fab91b04c953b9dcb438298a7f06cf76cb/output_syslog.go#L32-L40 |
11,637 | rs/xlog | output.go | NewOutputChannelBuffer | func NewOutputChannelBuffer(o Output, bufSize int) *OutputChannel {
oc := &OutputChannel{
input: make(chan map[string]interface{}, bufSize),
output: o,
stop: make(chan struct{}),
}
go func() {
for {
select {
case msg := <-oc.input:
if err := o.Write(msg); err != nil {
critialLogger.Print("cannot write log message: ", err.Error())
}
case <-oc.stop:
close(oc.stop)
return
}
}
}()
return oc
} | go | func NewOutputChannelBuffer(o Output, bufSize int) *OutputChannel {
oc := &OutputChannel{
input: make(chan map[string]interface{}, bufSize),
output: o,
stop: make(chan struct{}),
}
go func() {
for {
select {
case msg := <-oc.input:
if err := o.Write(msg); err != nil {
critialLogger.Print("cannot write log message: ", err.Error())
}
case <-oc.stop:
close(oc.stop)
return
}
}
}()
return oc
} | [
"func",
"NewOutputChannelBuffer",
"(",
"o",
"Output",
",",
"bufSize",
"int",
")",
"*",
"OutputChannel",
"{",
"oc",
":=",
"&",
"OutputChannel",
"{",
"input",
":",
"make",
"(",
"chan",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
",",
"bufSize",
")",
",",
"output",
":",
"o",
",",
"stop",
":",
"make",
"(",
"chan",
"struct",
"{",
"}",
")",
",",
"}",
"\n\n",
"go",
"func",
"(",
")",
"{",
"for",
"{",
"select",
"{",
"case",
"msg",
":=",
"<-",
"oc",
".",
"input",
":",
"if",
"err",
":=",
"o",
".",
"Write",
"(",
"msg",
")",
";",
"err",
"!=",
"nil",
"{",
"critialLogger",
".",
"Print",
"(",
"\"",
"\"",
",",
"err",
".",
"Error",
"(",
")",
")",
"\n",
"}",
"\n",
"case",
"<-",
"oc",
".",
"stop",
":",
"close",
"(",
"oc",
".",
"stop",
")",
"\n",
"return",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"(",
")",
"\n\n",
"return",
"oc",
"\n",
"}"
] | // NewOutputChannelBuffer creates a consumer buffered channel for the given output
// with a customizable buffer size. | [
"NewOutputChannelBuffer",
"creates",
"a",
"consumer",
"buffered",
"channel",
"for",
"the",
"given",
"output",
"with",
"a",
"customizable",
"buffer",
"size",
"."
] | 131980fab91b04c953b9dcb438298a7f06cf76cb | https://github.com/rs/xlog/blob/131980fab91b04c953b9dcb438298a7f06cf76cb/output.go#L51-L73 |
11,638 | rs/xlog | output.go | Write | func (oc *OutputChannel) Write(fields map[string]interface{}) (err error) {
select {
case oc.input <- fields:
// Sent with success
default:
// Channel is full, message dropped
err = ErrBufferFull
}
return err
} | go | func (oc *OutputChannel) Write(fields map[string]interface{}) (err error) {
select {
case oc.input <- fields:
// Sent with success
default:
// Channel is full, message dropped
err = ErrBufferFull
}
return err
} | [
"func",
"(",
"oc",
"*",
"OutputChannel",
")",
"Write",
"(",
"fields",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"(",
"err",
"error",
")",
"{",
"select",
"{",
"case",
"oc",
".",
"input",
"<-",
"fields",
":",
"// Sent with success",
"default",
":",
"// Channel is full, message dropped",
"err",
"=",
"ErrBufferFull",
"\n",
"}",
"\n",
"return",
"err",
"\n",
"}"
] | // Write implements the Output interface | [
"Write",
"implements",
"the",
"Output",
"interface"
] | 131980fab91b04c953b9dcb438298a7f06cf76cb | https://github.com/rs/xlog/blob/131980fab91b04c953b9dcb438298a7f06cf76cb/output.go#L76-L85 |
11,639 | rs/xlog | output.go | Flush | func (oc *OutputChannel) Flush() {
for {
select {
case msg := <-oc.input:
if err := oc.output.Write(msg); err != nil {
critialLogger.Print("cannot write log message: ", err.Error())
}
default:
return
}
}
} | go | func (oc *OutputChannel) Flush() {
for {
select {
case msg := <-oc.input:
if err := oc.output.Write(msg); err != nil {
critialLogger.Print("cannot write log message: ", err.Error())
}
default:
return
}
}
} | [
"func",
"(",
"oc",
"*",
"OutputChannel",
")",
"Flush",
"(",
")",
"{",
"for",
"{",
"select",
"{",
"case",
"msg",
":=",
"<-",
"oc",
".",
"input",
":",
"if",
"err",
":=",
"oc",
".",
"output",
".",
"Write",
"(",
"msg",
")",
";",
"err",
"!=",
"nil",
"{",
"critialLogger",
".",
"Print",
"(",
"\"",
"\"",
",",
"err",
".",
"Error",
"(",
")",
")",
"\n",
"}",
"\n",
"default",
":",
"return",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // Flush flushes all the buffered message to the output | [
"Flush",
"flushes",
"all",
"the",
"buffered",
"message",
"to",
"the",
"output"
] | 131980fab91b04c953b9dcb438298a7f06cf76cb | https://github.com/rs/xlog/blob/131980fab91b04c953b9dcb438298a7f06cf76cb/output.go#L88-L99 |
11,640 | rs/xlog | output.go | Close | func (oc *OutputChannel) Close() {
if oc.stop == nil {
return
}
oc.stop <- struct{}{}
<-oc.stop
oc.stop = nil
oc.Flush()
} | go | func (oc *OutputChannel) Close() {
if oc.stop == nil {
return
}
oc.stop <- struct{}{}
<-oc.stop
oc.stop = nil
oc.Flush()
} | [
"func",
"(",
"oc",
"*",
"OutputChannel",
")",
"Close",
"(",
")",
"{",
"if",
"oc",
".",
"stop",
"==",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"oc",
".",
"stop",
"<-",
"struct",
"{",
"}",
"{",
"}",
"\n",
"<-",
"oc",
".",
"stop",
"\n",
"oc",
".",
"stop",
"=",
"nil",
"\n",
"oc",
".",
"Flush",
"(",
")",
"\n",
"}"
] | // Close closes the output channel and release the consumer's go routine. | [
"Close",
"closes",
"the",
"output",
"channel",
"and",
"release",
"the",
"consumer",
"s",
"go",
"routine",
"."
] | 131980fab91b04c953b9dcb438298a7f06cf76cb | https://github.com/rs/xlog/blob/131980fab91b04c953b9dcb438298a7f06cf76cb/output.go#L102-L110 |
11,641 | rs/xlog | output.go | NewConsoleOutputW | func NewConsoleOutputW(w io.Writer, noTerm Output) Output {
if isTerminal(w) {
return consoleOutput{w: w}
}
return noTerm
} | go | func NewConsoleOutputW(w io.Writer, noTerm Output) Output {
if isTerminal(w) {
return consoleOutput{w: w}
}
return noTerm
} | [
"func",
"NewConsoleOutputW",
"(",
"w",
"io",
".",
"Writer",
",",
"noTerm",
"Output",
")",
"Output",
"{",
"if",
"isTerminal",
"(",
"w",
")",
"{",
"return",
"consoleOutput",
"{",
"w",
":",
"w",
"}",
"\n",
"}",
"\n",
"return",
"noTerm",
"\n",
"}"
] | // NewConsoleOutputW returns a Output printing message in a colored human readable form with
// the provided writer. If the writer is not on a terminal, the noTerm output is returned. | [
"NewConsoleOutputW",
"returns",
"a",
"Output",
"printing",
"message",
"in",
"a",
"colored",
"human",
"readable",
"form",
"with",
"the",
"provided",
"writer",
".",
"If",
"the",
"writer",
"is",
"not",
"on",
"a",
"terminal",
"the",
"noTerm",
"output",
"is",
"returned",
"."
] | 131980fab91b04c953b9dcb438298a7f06cf76cb | https://github.com/rs/xlog/blob/131980fab91b04c953b9dcb438298a7f06cf76cb/output.go#L216-L221 |
11,642 | rs/xlog | output.go | NewJSONOutput | func NewJSONOutput(w io.Writer) Output {
enc := json.NewEncoder(w)
return OutputFunc(func(fields map[string]interface{}) error {
return enc.Encode(fields)
})
} | go | func NewJSONOutput(w io.Writer) Output {
enc := json.NewEncoder(w)
return OutputFunc(func(fields map[string]interface{}) error {
return enc.Encode(fields)
})
} | [
"func",
"NewJSONOutput",
"(",
"w",
"io",
".",
"Writer",
")",
"Output",
"{",
"enc",
":=",
"json",
".",
"NewEncoder",
"(",
"w",
")",
"\n",
"return",
"OutputFunc",
"(",
"func",
"(",
"fields",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"error",
"{",
"return",
"enc",
".",
"Encode",
"(",
"fields",
")",
"\n",
"}",
")",
"\n",
"}"
] | // NewJSONOutput returns a new JSON output with the given writer. | [
"NewJSONOutput",
"returns",
"a",
"new",
"JSON",
"output",
"with",
"the",
"given",
"writer",
"."
] | 131980fab91b04c953b9dcb438298a7f06cf76cb | https://github.com/rs/xlog/blob/131980fab91b04c953b9dcb438298a7f06cf76cb/output.go#L320-L325 |
11,643 | rs/xlog | output.go | NewLogstashOutput | func NewLogstashOutput(w io.Writer) Output {
return OutputFunc(func(fields map[string]interface{}) error {
lsf := map[string]interface{}{
"@version": 1,
}
for k, v := range fields {
switch k {
case KeyTime:
k = "@timestamp"
case KeyLevel:
if s, ok := v.(string); ok {
v = strings.ToUpper(s)
}
}
if t, ok := v.(time.Time); ok {
lsf[k] = t.Format(time.RFC3339)
} else {
lsf[k] = v
}
}
b, err := json.Marshal(lsf)
if err != nil {
return err
}
_, err = w.Write(b)
return err
})
} | go | func NewLogstashOutput(w io.Writer) Output {
return OutputFunc(func(fields map[string]interface{}) error {
lsf := map[string]interface{}{
"@version": 1,
}
for k, v := range fields {
switch k {
case KeyTime:
k = "@timestamp"
case KeyLevel:
if s, ok := v.(string); ok {
v = strings.ToUpper(s)
}
}
if t, ok := v.(time.Time); ok {
lsf[k] = t.Format(time.RFC3339)
} else {
lsf[k] = v
}
}
b, err := json.Marshal(lsf)
if err != nil {
return err
}
_, err = w.Write(b)
return err
})
} | [
"func",
"NewLogstashOutput",
"(",
"w",
"io",
".",
"Writer",
")",
"Output",
"{",
"return",
"OutputFunc",
"(",
"func",
"(",
"fields",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"error",
"{",
"lsf",
":=",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"\"",
"\"",
":",
"1",
",",
"}",
"\n",
"for",
"k",
",",
"v",
":=",
"range",
"fields",
"{",
"switch",
"k",
"{",
"case",
"KeyTime",
":",
"k",
"=",
"\"",
"\"",
"\n",
"case",
"KeyLevel",
":",
"if",
"s",
",",
"ok",
":=",
"v",
".",
"(",
"string",
")",
";",
"ok",
"{",
"v",
"=",
"strings",
".",
"ToUpper",
"(",
"s",
")",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"t",
",",
"ok",
":=",
"v",
".",
"(",
"time",
".",
"Time",
")",
";",
"ok",
"{",
"lsf",
"[",
"k",
"]",
"=",
"t",
".",
"Format",
"(",
"time",
".",
"RFC3339",
")",
"\n",
"}",
"else",
"{",
"lsf",
"[",
"k",
"]",
"=",
"v",
"\n",
"}",
"\n",
"}",
"\n",
"b",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"lsf",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"_",
",",
"err",
"=",
"w",
".",
"Write",
"(",
"b",
")",
"\n",
"return",
"err",
"\n",
"}",
")",
"\n",
"}"
] | // NewLogstashOutput returns an output to generate logstash friendly JSON format. | [
"NewLogstashOutput",
"returns",
"an",
"output",
"to",
"generate",
"logstash",
"friendly",
"JSON",
"format",
"."
] | 131980fab91b04c953b9dcb438298a7f06cf76cb | https://github.com/rs/xlog/blob/131980fab91b04c953b9dcb438298a7f06cf76cb/output.go#L328-L355 |
11,644 | rs/xlog | output.go | NewTrimOutput | func NewTrimOutput(maxLen int, o Output) Output {
return OutputFunc(func(fields map[string]interface{}) error {
for k, v := range fields {
if s, ok := v.(string); ok && len(s) > maxLen {
fields[k] = s[:maxLen]
}
}
return o.Write(fields)
})
} | go | func NewTrimOutput(maxLen int, o Output) Output {
return OutputFunc(func(fields map[string]interface{}) error {
for k, v := range fields {
if s, ok := v.(string); ok && len(s) > maxLen {
fields[k] = s[:maxLen]
}
}
return o.Write(fields)
})
} | [
"func",
"NewTrimOutput",
"(",
"maxLen",
"int",
",",
"o",
"Output",
")",
"Output",
"{",
"return",
"OutputFunc",
"(",
"func",
"(",
"fields",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"error",
"{",
"for",
"k",
",",
"v",
":=",
"range",
"fields",
"{",
"if",
"s",
",",
"ok",
":=",
"v",
".",
"(",
"string",
")",
";",
"ok",
"&&",
"len",
"(",
"s",
")",
">",
"maxLen",
"{",
"fields",
"[",
"k",
"]",
"=",
"s",
"[",
":",
"maxLen",
"]",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"o",
".",
"Write",
"(",
"fields",
")",
"\n",
"}",
")",
"\n",
"}"
] | // NewTrimOutput trims any field of type string with a value length greater than maxLen
// to maxLen. | [
"NewTrimOutput",
"trims",
"any",
"field",
"of",
"type",
"string",
"with",
"a",
"value",
"length",
"greater",
"than",
"maxLen",
"to",
"maxLen",
"."
] | 131980fab91b04c953b9dcb438298a7f06cf76cb | https://github.com/rs/xlog/blob/131980fab91b04c953b9dcb438298a7f06cf76cb/output.go#L369-L378 |
11,645 | rs/xlog | output.go | NewTrimFieldsOutput | func NewTrimFieldsOutput(trimFields []string, maxLen int, o Output) Output {
return OutputFunc(func(fields map[string]interface{}) error {
for _, f := range trimFields {
if s, ok := fields[f].(string); ok && len(s) > maxLen {
fields[f] = s[:maxLen]
}
}
return o.Write(fields)
})
} | go | func NewTrimFieldsOutput(trimFields []string, maxLen int, o Output) Output {
return OutputFunc(func(fields map[string]interface{}) error {
for _, f := range trimFields {
if s, ok := fields[f].(string); ok && len(s) > maxLen {
fields[f] = s[:maxLen]
}
}
return o.Write(fields)
})
} | [
"func",
"NewTrimFieldsOutput",
"(",
"trimFields",
"[",
"]",
"string",
",",
"maxLen",
"int",
",",
"o",
"Output",
")",
"Output",
"{",
"return",
"OutputFunc",
"(",
"func",
"(",
"fields",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"error",
"{",
"for",
"_",
",",
"f",
":=",
"range",
"trimFields",
"{",
"if",
"s",
",",
"ok",
":=",
"fields",
"[",
"f",
"]",
".",
"(",
"string",
")",
";",
"ok",
"&&",
"len",
"(",
"s",
")",
">",
"maxLen",
"{",
"fields",
"[",
"f",
"]",
"=",
"s",
"[",
":",
"maxLen",
"]",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"o",
".",
"Write",
"(",
"fields",
")",
"\n",
"}",
")",
"\n",
"}"
] | // NewTrimFieldsOutput trims listed field fields of type string with a value length greater than maxLen
// to maxLen. | [
"NewTrimFieldsOutput",
"trims",
"listed",
"field",
"fields",
"of",
"type",
"string",
"with",
"a",
"value",
"length",
"greater",
"than",
"maxLen",
"to",
"maxLen",
"."
] | 131980fab91b04c953b9dcb438298a7f06cf76cb | https://github.com/rs/xlog/blob/131980fab91b04c953b9dcb438298a7f06cf76cb/output.go#L382-L391 |
11,646 | rs/xlog | handler.go | IDFromRequest | func IDFromRequest(r *http.Request) (xid.ID, bool) {
if r == nil {
return xid.ID{}, false
}
return IDFromContext(r.Context())
} | go | func IDFromRequest(r *http.Request) (xid.ID, bool) {
if r == nil {
return xid.ID{}, false
}
return IDFromContext(r.Context())
} | [
"func",
"IDFromRequest",
"(",
"r",
"*",
"http",
".",
"Request",
")",
"(",
"xid",
".",
"ID",
",",
"bool",
")",
"{",
"if",
"r",
"==",
"nil",
"{",
"return",
"xid",
".",
"ID",
"{",
"}",
",",
"false",
"\n",
"}",
"\n",
"return",
"IDFromContext",
"(",
"r",
".",
"Context",
"(",
")",
")",
"\n",
"}"
] | // IDFromRequest returns the unique id accociated to the request if any. | [
"IDFromRequest",
"returns",
"the",
"unique",
"id",
"accociated",
"to",
"the",
"request",
"if",
"any",
"."
] | 131980fab91b04c953b9dcb438298a7f06cf76cb | https://github.com/rs/xlog/blob/131980fab91b04c953b9dcb438298a7f06cf76cb/handler.go#L27-L32 |
11,647 | rs/xlog | handler.go | URLHandler | func URLHandler(name string) func(next http.Handler) http.Handler {
return func(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
l := FromContext(r.Context())
l.SetField(name, r.URL.String())
next.ServeHTTP(w, r)
})
}
} | go | func URLHandler(name string) func(next http.Handler) http.Handler {
return func(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
l := FromContext(r.Context())
l.SetField(name, r.URL.String())
next.ServeHTTP(w, r)
})
}
} | [
"func",
"URLHandler",
"(",
"name",
"string",
")",
"func",
"(",
"next",
"http",
".",
"Handler",
")",
"http",
".",
"Handler",
"{",
"return",
"func",
"(",
"next",
"http",
".",
"Handler",
")",
"http",
".",
"Handler",
"{",
"return",
"http",
".",
"HandlerFunc",
"(",
"func",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"l",
":=",
"FromContext",
"(",
"r",
".",
"Context",
"(",
")",
")",
"\n",
"l",
".",
"SetField",
"(",
"name",
",",
"r",
".",
"URL",
".",
"String",
"(",
")",
")",
"\n",
"next",
".",
"ServeHTTP",
"(",
"w",
",",
"r",
")",
"\n",
"}",
")",
"\n",
"}",
"\n",
"}"
] | // URLHandler returns a handler setting the request's URL as a field
// to the current context's logger using the passed name as field name. | [
"URLHandler",
"returns",
"a",
"handler",
"setting",
"the",
"request",
"s",
"URL",
"as",
"a",
"field",
"to",
"the",
"current",
"context",
"s",
"logger",
"using",
"the",
"passed",
"name",
"as",
"field",
"name",
"."
] | 131980fab91b04c953b9dcb438298a7f06cf76cb | https://github.com/rs/xlog/blob/131980fab91b04c953b9dcb438298a7f06cf76cb/handler.go#L85-L93 |
11,648 | rs/xlog | levels.go | LevelFromString | func LevelFromString(t string) (Level, error) {
l := Level(0)
err := (&l).UnmarshalText([]byte(t))
return l, err
} | go | func LevelFromString(t string) (Level, error) {
l := Level(0)
err := (&l).UnmarshalText([]byte(t))
return l, err
} | [
"func",
"LevelFromString",
"(",
"t",
"string",
")",
"(",
"Level",
",",
"error",
")",
"{",
"l",
":=",
"Level",
"(",
"0",
")",
"\n",
"err",
":=",
"(",
"&",
"l",
")",
".",
"UnmarshalText",
"(",
"[",
"]",
"byte",
"(",
"t",
")",
")",
"\n",
"return",
"l",
",",
"err",
"\n",
"}"
] | // LevelFromString returns the level based on its string representation | [
"LevelFromString",
"returns",
"the",
"level",
"based",
"on",
"its",
"string",
"representation"
] | 131980fab91b04c953b9dcb438298a7f06cf76cb | https://github.com/rs/xlog/blob/131980fab91b04c953b9dcb438298a7f06cf76cb/levels.go#L37-L41 |
11,649 | rs/xlog | levels.go | UnmarshalText | func (l *Level) UnmarshalText(text []byte) (err error) {
if bytes.Equal(text, levelBytesDebug) {
*l = LevelDebug
} else if bytes.Equal(text, levelBytesInfo) {
*l = LevelInfo
} else if bytes.Equal(text, levelBytesWarn) {
*l = LevelWarn
} else if bytes.Equal(text, levelBytesError) {
*l = LevelError
} else if bytes.Equal(text, levelBytesFatal) {
*l = LevelFatal
} else {
err = fmt.Errorf("Uknown level %v", string(text))
}
return
} | go | func (l *Level) UnmarshalText(text []byte) (err error) {
if bytes.Equal(text, levelBytesDebug) {
*l = LevelDebug
} else if bytes.Equal(text, levelBytesInfo) {
*l = LevelInfo
} else if bytes.Equal(text, levelBytesWarn) {
*l = LevelWarn
} else if bytes.Equal(text, levelBytesError) {
*l = LevelError
} else if bytes.Equal(text, levelBytesFatal) {
*l = LevelFatal
} else {
err = fmt.Errorf("Uknown level %v", string(text))
}
return
} | [
"func",
"(",
"l",
"*",
"Level",
")",
"UnmarshalText",
"(",
"text",
"[",
"]",
"byte",
")",
"(",
"err",
"error",
")",
"{",
"if",
"bytes",
".",
"Equal",
"(",
"text",
",",
"levelBytesDebug",
")",
"{",
"*",
"l",
"=",
"LevelDebug",
"\n",
"}",
"else",
"if",
"bytes",
".",
"Equal",
"(",
"text",
",",
"levelBytesInfo",
")",
"{",
"*",
"l",
"=",
"LevelInfo",
"\n",
"}",
"else",
"if",
"bytes",
".",
"Equal",
"(",
"text",
",",
"levelBytesWarn",
")",
"{",
"*",
"l",
"=",
"LevelWarn",
"\n",
"}",
"else",
"if",
"bytes",
".",
"Equal",
"(",
"text",
",",
"levelBytesError",
")",
"{",
"*",
"l",
"=",
"LevelError",
"\n",
"}",
"else",
"if",
"bytes",
".",
"Equal",
"(",
"text",
",",
"levelBytesFatal",
")",
"{",
"*",
"l",
"=",
"LevelFatal",
"\n",
"}",
"else",
"{",
"err",
"=",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"string",
"(",
"text",
")",
")",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] | // UnmarshalText lets Level implements the TextUnmarshaler interface used by encoding packages | [
"UnmarshalText",
"lets",
"Level",
"implements",
"the",
"TextUnmarshaler",
"interface",
"used",
"by",
"encoding",
"packages"
] | 131980fab91b04c953b9dcb438298a7f06cf76cb | https://github.com/rs/xlog/blob/131980fab91b04c953b9dcb438298a7f06cf76cb/levels.go#L44-L59 |
11,650 | rs/xlog | levels.go | String | func (l Level) String() string {
var t string
switch l {
case LevelDebug:
t = levelDebug
case LevelInfo:
t = levelInfo
case LevelWarn:
t = levelWarn
case LevelError:
t = levelError
case LevelFatal:
t = levelFatal
default:
t = strconv.FormatInt(int64(l), 10)
}
return t
} | go | func (l Level) String() string {
var t string
switch l {
case LevelDebug:
t = levelDebug
case LevelInfo:
t = levelInfo
case LevelWarn:
t = levelWarn
case LevelError:
t = levelError
case LevelFatal:
t = levelFatal
default:
t = strconv.FormatInt(int64(l), 10)
}
return t
} | [
"func",
"(",
"l",
"Level",
")",
"String",
"(",
")",
"string",
"{",
"var",
"t",
"string",
"\n",
"switch",
"l",
"{",
"case",
"LevelDebug",
":",
"t",
"=",
"levelDebug",
"\n",
"case",
"LevelInfo",
":",
"t",
"=",
"levelInfo",
"\n",
"case",
"LevelWarn",
":",
"t",
"=",
"levelWarn",
"\n",
"case",
"LevelError",
":",
"t",
"=",
"levelError",
"\n",
"case",
"LevelFatal",
":",
"t",
"=",
"levelFatal",
"\n",
"default",
":",
"t",
"=",
"strconv",
".",
"FormatInt",
"(",
"int64",
"(",
"l",
")",
",",
"10",
")",
"\n",
"}",
"\n",
"return",
"t",
"\n",
"}"
] | // String returns the string representation of the level. | [
"String",
"returns",
"the",
"string",
"representation",
"of",
"the",
"level",
"."
] | 131980fab91b04c953b9dcb438298a7f06cf76cb | https://github.com/rs/xlog/blob/131980fab91b04c953b9dcb438298a7f06cf76cb/levels.go#L62-L79 |
11,651 | rs/xlog | levels.go | MarshalText | func (l Level) MarshalText() ([]byte, error) {
var t []byte
switch l {
case LevelDebug:
t = levelBytesDebug
case LevelInfo:
t = levelBytesInfo
case LevelWarn:
t = levelBytesWarn
case LevelError:
t = levelBytesError
case LevelFatal:
t = levelBytesFatal
default:
t = []byte(strconv.FormatInt(int64(l), 10))
}
return t, nil
} | go | func (l Level) MarshalText() ([]byte, error) {
var t []byte
switch l {
case LevelDebug:
t = levelBytesDebug
case LevelInfo:
t = levelBytesInfo
case LevelWarn:
t = levelBytesWarn
case LevelError:
t = levelBytesError
case LevelFatal:
t = levelBytesFatal
default:
t = []byte(strconv.FormatInt(int64(l), 10))
}
return t, nil
} | [
"func",
"(",
"l",
"Level",
")",
"MarshalText",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"var",
"t",
"[",
"]",
"byte",
"\n",
"switch",
"l",
"{",
"case",
"LevelDebug",
":",
"t",
"=",
"levelBytesDebug",
"\n",
"case",
"LevelInfo",
":",
"t",
"=",
"levelBytesInfo",
"\n",
"case",
"LevelWarn",
":",
"t",
"=",
"levelBytesWarn",
"\n",
"case",
"LevelError",
":",
"t",
"=",
"levelBytesError",
"\n",
"case",
"LevelFatal",
":",
"t",
"=",
"levelBytesFatal",
"\n",
"default",
":",
"t",
"=",
"[",
"]",
"byte",
"(",
"strconv",
".",
"FormatInt",
"(",
"int64",
"(",
"l",
")",
",",
"10",
")",
")",
"\n",
"}",
"\n",
"return",
"t",
",",
"nil",
"\n",
"}"
] | // MarshalText lets Level implements the TextMarshaler interface used by encoding packages | [
"MarshalText",
"lets",
"Level",
"implements",
"the",
"TextMarshaler",
"interface",
"used",
"by",
"encoding",
"packages"
] | 131980fab91b04c953b9dcb438298a7f06cf76cb | https://github.com/rs/xlog/blob/131980fab91b04c953b9dcb438298a7f06cf76cb/levels.go#L82-L99 |
11,652 | mailjet/mailjet-apiv3-go | smtp_client.go | NewSMTPClient | func NewSMTPClient(apiKeyPublic, apiKeyPrivate string) *SMTPClient {
auth := smtp.PlainAuth(
"",
apiKeyPublic,
apiKeyPrivate,
HostSMTP,
)
return &SMTPClient{
host: fmt.Sprintf("%s:%d", HostSMTP, PortSMTP),
auth: auth,
}
} | go | func NewSMTPClient(apiKeyPublic, apiKeyPrivate string) *SMTPClient {
auth := smtp.PlainAuth(
"",
apiKeyPublic,
apiKeyPrivate,
HostSMTP,
)
return &SMTPClient{
host: fmt.Sprintf("%s:%d", HostSMTP, PortSMTP),
auth: auth,
}
} | [
"func",
"NewSMTPClient",
"(",
"apiKeyPublic",
",",
"apiKeyPrivate",
"string",
")",
"*",
"SMTPClient",
"{",
"auth",
":=",
"smtp",
".",
"PlainAuth",
"(",
"\"",
"\"",
",",
"apiKeyPublic",
",",
"apiKeyPrivate",
",",
"HostSMTP",
",",
")",
"\n",
"return",
"&",
"SMTPClient",
"{",
"host",
":",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"HostSMTP",
",",
"PortSMTP",
")",
",",
"auth",
":",
"auth",
",",
"}",
"\n",
"}"
] | // NewSMTPClient returns a new smtp client wrapper | [
"NewSMTPClient",
"returns",
"a",
"new",
"smtp",
"client",
"wrapper"
] | e508c28bf11623de2171a2331fc673391b066867 | https://github.com/mailjet/mailjet-apiv3-go/blob/e508c28bf11623de2171a2331fc673391b066867/smtp_client.go#L21-L32 |
11,653 | mailjet/mailjet-apiv3-go | fixtures/fixtures.go | New | func New() *Fixtures {
f := new(Fixtures)
f.data = make(map[interface{}][]byte)
fix := reflect.ValueOf(f)
for i := 0; i < fix.NumMethod(); i++ {
method := fix.Method(i)
if method.Type().NumIn() == 0 && method.Type().NumOut() == 2 {
values := method.Call([]reflect.Value{})
reflect.ValueOf(f.data).SetMapIndex(values[0], values[1])
}
}
return f
} | go | func New() *Fixtures {
f := new(Fixtures)
f.data = make(map[interface{}][]byte)
fix := reflect.ValueOf(f)
for i := 0; i < fix.NumMethod(); i++ {
method := fix.Method(i)
if method.Type().NumIn() == 0 && method.Type().NumOut() == 2 {
values := method.Call([]reflect.Value{})
reflect.ValueOf(f.data).SetMapIndex(values[0], values[1])
}
}
return f
} | [
"func",
"New",
"(",
")",
"*",
"Fixtures",
"{",
"f",
":=",
"new",
"(",
"Fixtures",
")",
"\n",
"f",
".",
"data",
"=",
"make",
"(",
"map",
"[",
"interface",
"{",
"}",
"]",
"[",
"]",
"byte",
")",
"\n",
"fix",
":=",
"reflect",
".",
"ValueOf",
"(",
"f",
")",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"fix",
".",
"NumMethod",
"(",
")",
";",
"i",
"++",
"{",
"method",
":=",
"fix",
".",
"Method",
"(",
"i",
")",
"\n",
"if",
"method",
".",
"Type",
"(",
")",
".",
"NumIn",
"(",
")",
"==",
"0",
"&&",
"method",
".",
"Type",
"(",
")",
".",
"NumOut",
"(",
")",
"==",
"2",
"{",
"values",
":=",
"method",
".",
"Call",
"(",
"[",
"]",
"reflect",
".",
"Value",
"{",
"}",
")",
"\n",
"reflect",
".",
"ValueOf",
"(",
"f",
".",
"data",
")",
".",
"SetMapIndex",
"(",
"values",
"[",
"0",
"]",
",",
"values",
"[",
"1",
"]",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"f",
"\n",
"}"
] | // New loads fixtures in memory by iterating through its fixture method | [
"New",
"loads",
"fixtures",
"in",
"memory",
"by",
"iterating",
"through",
"its",
"fixture",
"method"
] | e508c28bf11623de2171a2331fc673391b066867 | https://github.com/mailjet/mailjet-apiv3-go/blob/e508c28bf11623de2171a2331fc673391b066867/fixtures/fixtures.go#L18-L31 |
11,654 | mailjet/mailjet-apiv3-go | data_api.go | ListData | func (mj *Client) ListData(resource string, resp interface{}, options ...RequestOptions) (count, total int, err error) {
url := buildDataURL(mj.apiBase, &DataRequest{SourceType: resource})
req, err := createRequest("GET", url, nil, nil, options...)
if err != nil {
return count, total, err
}
return mj.httpClient.Send(req).Read(resp).Call()
} | go | func (mj *Client) ListData(resource string, resp interface{}, options ...RequestOptions) (count, total int, err error) {
url := buildDataURL(mj.apiBase, &DataRequest{SourceType: resource})
req, err := createRequest("GET", url, nil, nil, options...)
if err != nil {
return count, total, err
}
return mj.httpClient.Send(req).Read(resp).Call()
} | [
"func",
"(",
"mj",
"*",
"Client",
")",
"ListData",
"(",
"resource",
"string",
",",
"resp",
"interface",
"{",
"}",
",",
"options",
"...",
"RequestOptions",
")",
"(",
"count",
",",
"total",
"int",
",",
"err",
"error",
")",
"{",
"url",
":=",
"buildDataURL",
"(",
"mj",
".",
"apiBase",
",",
"&",
"DataRequest",
"{",
"SourceType",
":",
"resource",
"}",
")",
"\n",
"req",
",",
"err",
":=",
"createRequest",
"(",
"\"",
"\"",
",",
"url",
",",
"nil",
",",
"nil",
",",
"options",
"...",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"count",
",",
"total",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"mj",
".",
"httpClient",
".",
"Send",
"(",
"req",
")",
".",
"Read",
"(",
"resp",
")",
".",
"Call",
"(",
")",
"\n",
"}"
] | // ListData issues a GET to list the specified data resource
// and stores the result in the value pointed to by res.
// Filters can be add via functional options. | [
"ListData",
"issues",
"a",
"GET",
"to",
"list",
"the",
"specified",
"data",
"resource",
"and",
"stores",
"the",
"result",
"in",
"the",
"value",
"pointed",
"to",
"by",
"res",
".",
"Filters",
"can",
"be",
"add",
"via",
"functional",
"options",
"."
] | e508c28bf11623de2171a2331fc673391b066867 | https://github.com/mailjet/mailjet-apiv3-go/blob/e508c28bf11623de2171a2331fc673391b066867/data_api.go#L8-L16 |
11,655 | mailjet/mailjet-apiv3-go | data_api.go | GetData | func (mj *Client) GetData(mdr *DataRequest, res interface{}, options ...RequestOptions) (err error) {
url := buildDataURL(mj.apiBase, mdr)
req, err := createRequest("GET", url, nil, nil, options...)
if err != nil {
return err
}
_, _, err = mj.httpClient.Send(req).Read(res).Call()
return err
} | go | func (mj *Client) GetData(mdr *DataRequest, res interface{}, options ...RequestOptions) (err error) {
url := buildDataURL(mj.apiBase, mdr)
req, err := createRequest("GET", url, nil, nil, options...)
if err != nil {
return err
}
_, _, err = mj.httpClient.Send(req).Read(res).Call()
return err
} | [
"func",
"(",
"mj",
"*",
"Client",
")",
"GetData",
"(",
"mdr",
"*",
"DataRequest",
",",
"res",
"interface",
"{",
"}",
",",
"options",
"...",
"RequestOptions",
")",
"(",
"err",
"error",
")",
"{",
"url",
":=",
"buildDataURL",
"(",
"mj",
".",
"apiBase",
",",
"mdr",
")",
"\n",
"req",
",",
"err",
":=",
"createRequest",
"(",
"\"",
"\"",
",",
"url",
",",
"nil",
",",
"nil",
",",
"options",
"...",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"_",
",",
"_",
",",
"err",
"=",
"mj",
".",
"httpClient",
".",
"Send",
"(",
"req",
")",
".",
"Read",
"(",
"res",
")",
".",
"Call",
"(",
")",
"\n",
"return",
"err",
"\n",
"}"
] | // GetData issues a GET to view a resource specifying an id
// and stores the result in the value pointed to by res.
// Filters can be add via functional options.
// Without an specified SourceTypeID in MailjetDataRequest, it is the same as ListData. | [
"GetData",
"issues",
"a",
"GET",
"to",
"view",
"a",
"resource",
"specifying",
"an",
"id",
"and",
"stores",
"the",
"result",
"in",
"the",
"value",
"pointed",
"to",
"by",
"res",
".",
"Filters",
"can",
"be",
"add",
"via",
"functional",
"options",
".",
"Without",
"an",
"specified",
"SourceTypeID",
"in",
"MailjetDataRequest",
"it",
"is",
"the",
"same",
"as",
"ListData",
"."
] | e508c28bf11623de2171a2331fc673391b066867 | https://github.com/mailjet/mailjet-apiv3-go/blob/e508c28bf11623de2171a2331fc673391b066867/data_api.go#L22-L31 |
11,656 | mailjet/mailjet-apiv3-go | data_api.go | PostData | func (mj *Client) PostData(fmdr *FullDataRequest, res interface{}, options ...RequestOptions) (err error) {
url := buildDataURL(mj.apiBase, fmdr.Info)
req, err := createRequest("POST", url, fmdr.Payload, nil, options...)
if err != nil {
return err
}
headers := map[string]string{"Content-Type": "application/json"}
if fmdr.Info.MimeType != "" {
contentType := strings.Replace(fmdr.Info.MimeType, ":", "/", 1)
headers = map[string]string{"Content-Type": contentType}
}
_, _, err = mj.httpClient.Send(req).With(headers).Read(res).Call()
return err
} | go | func (mj *Client) PostData(fmdr *FullDataRequest, res interface{}, options ...RequestOptions) (err error) {
url := buildDataURL(mj.apiBase, fmdr.Info)
req, err := createRequest("POST", url, fmdr.Payload, nil, options...)
if err != nil {
return err
}
headers := map[string]string{"Content-Type": "application/json"}
if fmdr.Info.MimeType != "" {
contentType := strings.Replace(fmdr.Info.MimeType, ":", "/", 1)
headers = map[string]string{"Content-Type": contentType}
}
_, _, err = mj.httpClient.Send(req).With(headers).Read(res).Call()
return err
} | [
"func",
"(",
"mj",
"*",
"Client",
")",
"PostData",
"(",
"fmdr",
"*",
"FullDataRequest",
",",
"res",
"interface",
"{",
"}",
",",
"options",
"...",
"RequestOptions",
")",
"(",
"err",
"error",
")",
"{",
"url",
":=",
"buildDataURL",
"(",
"mj",
".",
"apiBase",
",",
"fmdr",
".",
"Info",
")",
"\n",
"req",
",",
"err",
":=",
"createRequest",
"(",
"\"",
"\"",
",",
"url",
",",
"fmdr",
".",
"Payload",
",",
"nil",
",",
"options",
"...",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"headers",
":=",
"map",
"[",
"string",
"]",
"string",
"{",
"\"",
"\"",
":",
"\"",
"\"",
"}",
"\n",
"if",
"fmdr",
".",
"Info",
".",
"MimeType",
"!=",
"\"",
"\"",
"{",
"contentType",
":=",
"strings",
".",
"Replace",
"(",
"fmdr",
".",
"Info",
".",
"MimeType",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"1",
")",
"\n",
"headers",
"=",
"map",
"[",
"string",
"]",
"string",
"{",
"\"",
"\"",
":",
"contentType",
"}",
"\n",
"}",
"\n\n",
"_",
",",
"_",
",",
"err",
"=",
"mj",
".",
"httpClient",
".",
"Send",
"(",
"req",
")",
".",
"With",
"(",
"headers",
")",
".",
"Read",
"(",
"res",
")",
".",
"Call",
"(",
")",
"\n",
"return",
"err",
"\n",
"}"
] | // PostData issues a POST to create a new data resource
// and stores the result in the value pointed to by res.
// Filters can be add via functional options. | [
"PostData",
"issues",
"a",
"POST",
"to",
"create",
"a",
"new",
"data",
"resource",
"and",
"stores",
"the",
"result",
"in",
"the",
"value",
"pointed",
"to",
"by",
"res",
".",
"Filters",
"can",
"be",
"add",
"via",
"functional",
"options",
"."
] | e508c28bf11623de2171a2331fc673391b066867 | https://github.com/mailjet/mailjet-apiv3-go/blob/e508c28bf11623de2171a2331fc673391b066867/data_api.go#L36-L51 |
11,657 | mailjet/mailjet-apiv3-go | data_api.go | PutData | func (mj *Client) PutData(fmr *FullDataRequest, onlyFields []string, options ...RequestOptions) (err error) {
url := buildDataURL(mj.apiBase, fmr.Info)
req, err := createRequest("PUT", url, fmr.Payload, onlyFields, options...)
if err != nil {
return err
}
headers := map[string]string{"Content-Type": "application/json"}
_, _, err = mj.httpClient.Send(req).With(headers).Call()
return err
} | go | func (mj *Client) PutData(fmr *FullDataRequest, onlyFields []string, options ...RequestOptions) (err error) {
url := buildDataURL(mj.apiBase, fmr.Info)
req, err := createRequest("PUT", url, fmr.Payload, onlyFields, options...)
if err != nil {
return err
}
headers := map[string]string{"Content-Type": "application/json"}
_, _, err = mj.httpClient.Send(req).With(headers).Call()
return err
} | [
"func",
"(",
"mj",
"*",
"Client",
")",
"PutData",
"(",
"fmr",
"*",
"FullDataRequest",
",",
"onlyFields",
"[",
"]",
"string",
",",
"options",
"...",
"RequestOptions",
")",
"(",
"err",
"error",
")",
"{",
"url",
":=",
"buildDataURL",
"(",
"mj",
".",
"apiBase",
",",
"fmr",
".",
"Info",
")",
"\n",
"req",
",",
"err",
":=",
"createRequest",
"(",
"\"",
"\"",
",",
"url",
",",
"fmr",
".",
"Payload",
",",
"onlyFields",
",",
"options",
"...",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"headers",
":=",
"map",
"[",
"string",
"]",
"string",
"{",
"\"",
"\"",
":",
"\"",
"\"",
"}",
"\n",
"_",
",",
"_",
",",
"err",
"=",
"mj",
".",
"httpClient",
".",
"Send",
"(",
"req",
")",
".",
"With",
"(",
"headers",
")",
".",
"Call",
"(",
")",
"\n\n",
"return",
"err",
"\n",
"}"
] | // PutData is used to update a data resource.
// Fields to be updated must be specified by the string array onlyFields.
// If onlyFields is nil, all fields except these with the tag read_only, are updated.
// Filters can be add via functional options. | [
"PutData",
"is",
"used",
"to",
"update",
"a",
"data",
"resource",
".",
"Fields",
"to",
"be",
"updated",
"must",
"be",
"specified",
"by",
"the",
"string",
"array",
"onlyFields",
".",
"If",
"onlyFields",
"is",
"nil",
"all",
"fields",
"except",
"these",
"with",
"the",
"tag",
"read_only",
"are",
"updated",
".",
"Filters",
"can",
"be",
"add",
"via",
"functional",
"options",
"."
] | e508c28bf11623de2171a2331fc673391b066867 | https://github.com/mailjet/mailjet-apiv3-go/blob/e508c28bf11623de2171a2331fc673391b066867/data_api.go#L57-L68 |
11,658 | mailjet/mailjet-apiv3-go | data_api.go | DeleteData | func (mj *Client) DeleteData(mdr *DataRequest) (err error) {
url := buildDataURL(mj.apiBase, mdr)
req, err := createRequest("DELETE", url, nil, nil)
if err != nil {
return err
}
_, _, err = mj.httpClient.Send(req).Call()
return err
} | go | func (mj *Client) DeleteData(mdr *DataRequest) (err error) {
url := buildDataURL(mj.apiBase, mdr)
req, err := createRequest("DELETE", url, nil, nil)
if err != nil {
return err
}
_, _, err = mj.httpClient.Send(req).Call()
return err
} | [
"func",
"(",
"mj",
"*",
"Client",
")",
"DeleteData",
"(",
"mdr",
"*",
"DataRequest",
")",
"(",
"err",
"error",
")",
"{",
"url",
":=",
"buildDataURL",
"(",
"mj",
".",
"apiBase",
",",
"mdr",
")",
"\n",
"req",
",",
"err",
":=",
"createRequest",
"(",
"\"",
"\"",
",",
"url",
",",
"nil",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"_",
",",
"_",
",",
"err",
"=",
"mj",
".",
"httpClient",
".",
"Send",
"(",
"req",
")",
".",
"Call",
"(",
")",
"\n\n",
"return",
"err",
"\n",
"}"
] | // DeleteData is used to delete a data resource. | [
"DeleteData",
"is",
"used",
"to",
"delete",
"a",
"data",
"resource",
"."
] | e508c28bf11623de2171a2331fc673391b066867 | https://github.com/mailjet/mailjet-apiv3-go/blob/e508c28bf11623de2171a2331fc673391b066867/data_api.go#L71-L81 |
11,659 | mailjet/mailjet-apiv3-go | http_client_mock.go | NewhttpClientMock | func NewhttpClientMock(valid bool) *HTTPClientMock {
return &HTTPClientMock{
apiKeyPublic: "apiKeyPublic",
apiKeyPrivate: "apiKeyPrivate",
client: http.DefaultClient,
validCreds: valid,
fx: fixtures.New(),
CallFunc: func() (int, int, error) {
if valid == true {
return 1, 1, nil
}
return 0, 0, errors.New("Unexpected error: Unexpected server response code: 401: EOF")
},
SendMailV31Func: func(req *http.Request) (*http.Response, error) {
return nil, nil
},
}
} | go | func NewhttpClientMock(valid bool) *HTTPClientMock {
return &HTTPClientMock{
apiKeyPublic: "apiKeyPublic",
apiKeyPrivate: "apiKeyPrivate",
client: http.DefaultClient,
validCreds: valid,
fx: fixtures.New(),
CallFunc: func() (int, int, error) {
if valid == true {
return 1, 1, nil
}
return 0, 0, errors.New("Unexpected error: Unexpected server response code: 401: EOF")
},
SendMailV31Func: func(req *http.Request) (*http.Response, error) {
return nil, nil
},
}
} | [
"func",
"NewhttpClientMock",
"(",
"valid",
"bool",
")",
"*",
"HTTPClientMock",
"{",
"return",
"&",
"HTTPClientMock",
"{",
"apiKeyPublic",
":",
"\"",
"\"",
",",
"apiKeyPrivate",
":",
"\"",
"\"",
",",
"client",
":",
"http",
".",
"DefaultClient",
",",
"validCreds",
":",
"valid",
",",
"fx",
":",
"fixtures",
".",
"New",
"(",
")",
",",
"CallFunc",
":",
"func",
"(",
")",
"(",
"int",
",",
"int",
",",
"error",
")",
"{",
"if",
"valid",
"==",
"true",
"{",
"return",
"1",
",",
"1",
",",
"nil",
"\n",
"}",
"\n",
"return",
"0",
",",
"0",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
",",
"SendMailV31Func",
":",
"func",
"(",
"req",
"*",
"http",
".",
"Request",
")",
"(",
"*",
"http",
".",
"Response",
",",
"error",
")",
"{",
"return",
"nil",
",",
"nil",
"\n",
"}",
",",
"}",
"\n",
"}"
] | // NewhttpClientMock instanciate new httpClientMock | [
"NewhttpClientMock",
"instanciate",
"new",
"httpClientMock"
] | e508c28bf11623de2171a2331fc673391b066867 | https://github.com/mailjet/mailjet-apiv3-go/blob/e508c28bf11623de2171a2331fc673391b066867/http_client_mock.go#L25-L43 |
11,660 | mailjet/mailjet-apiv3-go | http_client_mock.go | Send | func (c *HTTPClientMock) Send(req *http.Request) HTTPClientInterface {
c.request = req
return c
} | go | func (c *HTTPClientMock) Send(req *http.Request) HTTPClientInterface {
c.request = req
return c
} | [
"func",
"(",
"c",
"*",
"HTTPClientMock",
")",
"Send",
"(",
"req",
"*",
"http",
".",
"Request",
")",
"HTTPClientInterface",
"{",
"c",
".",
"request",
"=",
"req",
"\n",
"return",
"c",
"\n",
"}"
] | // Send data through HTTP with the current configuration | [
"Send",
"data",
"through",
"HTTP",
"with",
"the",
"current",
"configuration"
] | e508c28bf11623de2171a2331fc673391b066867 | https://github.com/mailjet/mailjet-apiv3-go/blob/e508c28bf11623de2171a2331fc673391b066867/http_client_mock.go#L66-L69 |
11,661 | mailjet/mailjet-apiv3-go | http_client_mock.go | With | func (c *HTTPClientMock) With(headers map[string]string) HTTPClientInterface {
c.headers = headers
return c
} | go | func (c *HTTPClientMock) With(headers map[string]string) HTTPClientInterface {
c.headers = headers
return c
} | [
"func",
"(",
"c",
"*",
"HTTPClientMock",
")",
"With",
"(",
"headers",
"map",
"[",
"string",
"]",
"string",
")",
"HTTPClientInterface",
"{",
"c",
".",
"headers",
"=",
"headers",
"\n",
"return",
"c",
"\n",
"}"
] | // With lets you set the http header and returns the httpClientMock with the header modified | [
"With",
"lets",
"you",
"set",
"the",
"http",
"header",
"and",
"returns",
"the",
"httpClientMock",
"with",
"the",
"header",
"modified"
] | e508c28bf11623de2171a2331fc673391b066867 | https://github.com/mailjet/mailjet-apiv3-go/blob/e508c28bf11623de2171a2331fc673391b066867/http_client_mock.go#L72-L75 |
11,662 | mailjet/mailjet-apiv3-go | http_client_mock.go | Read | func (c *HTTPClientMock) Read(response interface{}) HTTPClientInterface {
c.fx.Read(response)
return c
} | go | func (c *HTTPClientMock) Read(response interface{}) HTTPClientInterface {
c.fx.Read(response)
return c
} | [
"func",
"(",
"c",
"*",
"HTTPClientMock",
")",
"Read",
"(",
"response",
"interface",
"{",
"}",
")",
"HTTPClientInterface",
"{",
"c",
".",
"fx",
".",
"Read",
"(",
"response",
")",
"\n",
"return",
"c",
"\n",
"}"
] | // Read allow you to bind the response recieved through the underlying http client | [
"Read",
"allow",
"you",
"to",
"bind",
"the",
"response",
"recieved",
"through",
"the",
"underlying",
"http",
"client"
] | e508c28bf11623de2171a2331fc673391b066867 | https://github.com/mailjet/mailjet-apiv3-go/blob/e508c28bf11623de2171a2331fc673391b066867/http_client_mock.go#L78-L81 |
11,663 | mailjet/mailjet-apiv3-go | http_client_mock.go | SendMailV31 | func (c *HTTPClientMock) SendMailV31(req *http.Request) (*http.Response, error) {
return c.SendMailV31Func(req)
} | go | func (c *HTTPClientMock) SendMailV31(req *http.Request) (*http.Response, error) {
return c.SendMailV31Func(req)
} | [
"func",
"(",
"c",
"*",
"HTTPClientMock",
")",
"SendMailV31",
"(",
"req",
"*",
"http",
".",
"Request",
")",
"(",
"*",
"http",
".",
"Response",
",",
"error",
")",
"{",
"return",
"c",
".",
"SendMailV31Func",
"(",
"req",
")",
"\n",
"}"
] | // SendMailV31 mock function | [
"SendMailV31",
"mock",
"function"
] | e508c28bf11623de2171a2331fc673391b066867 | https://github.com/mailjet/mailjet-apiv3-go/blob/e508c28bf11623de2171a2331fc673391b066867/http_client_mock.go#L84-L86 |
11,664 | mailjet/mailjet-apiv3-go | http_client.go | NewHTTPClient | func NewHTTPClient(apiKeyPublic, apiKeyPrivate string) *HTTPClient {
return &HTTPClient{
apiKeyPublic: apiKeyPublic,
apiKeyPrivate: apiKeyPrivate,
client: http.DefaultClient,
}
} | go | func NewHTTPClient(apiKeyPublic, apiKeyPrivate string) *HTTPClient {
return &HTTPClient{
apiKeyPublic: apiKeyPublic,
apiKeyPrivate: apiKeyPrivate,
client: http.DefaultClient,
}
} | [
"func",
"NewHTTPClient",
"(",
"apiKeyPublic",
",",
"apiKeyPrivate",
"string",
")",
"*",
"HTTPClient",
"{",
"return",
"&",
"HTTPClient",
"{",
"apiKeyPublic",
":",
"apiKeyPublic",
",",
"apiKeyPrivate",
":",
"apiKeyPrivate",
",",
"client",
":",
"http",
".",
"DefaultClient",
",",
"}",
"\n",
"}"
] | // NewHTTPClient returns a new httpClient | [
"NewHTTPClient",
"returns",
"a",
"new",
"httpClient"
] | e508c28bf11623de2171a2331fc673391b066867 | https://github.com/mailjet/mailjet-apiv3-go/blob/e508c28bf11623de2171a2331fc673391b066867/http_client.go#L21-L27 |
11,665 | mailjet/mailjet-apiv3-go | http_client.go | Send | func (c *HTTPClient) Send(req *http.Request) HTTPClientInterface {
c.request = req
return c
} | go | func (c *HTTPClient) Send(req *http.Request) HTTPClientInterface {
c.request = req
return c
} | [
"func",
"(",
"c",
"*",
"HTTPClient",
")",
"Send",
"(",
"req",
"*",
"http",
".",
"Request",
")",
"HTTPClientInterface",
"{",
"c",
".",
"request",
"=",
"req",
"\n",
"return",
"c",
"\n",
"}"
] | // Send binds the request to the underlying http client | [
"Send",
"binds",
"the",
"request",
"to",
"the",
"underlying",
"http",
"client"
] | e508c28bf11623de2171a2331fc673391b066867 | https://github.com/mailjet/mailjet-apiv3-go/blob/e508c28bf11623de2171a2331fc673391b066867/http_client.go#L50-L53 |
11,666 | mailjet/mailjet-apiv3-go | http_client.go | With | func (c *HTTPClient) With(headers map[string]string) HTTPClientInterface {
c.headers = headers
return c
} | go | func (c *HTTPClient) With(headers map[string]string) HTTPClientInterface {
c.headers = headers
return c
} | [
"func",
"(",
"c",
"*",
"HTTPClient",
")",
"With",
"(",
"headers",
"map",
"[",
"string",
"]",
"string",
")",
"HTTPClientInterface",
"{",
"c",
".",
"headers",
"=",
"headers",
"\n",
"return",
"c",
"\n",
"}"
] | // With binds the header to the underlying http client | [
"With",
"binds",
"the",
"header",
"to",
"the",
"underlying",
"http",
"client"
] | e508c28bf11623de2171a2331fc673391b066867 | https://github.com/mailjet/mailjet-apiv3-go/blob/e508c28bf11623de2171a2331fc673391b066867/http_client.go#L56-L59 |
11,667 | mailjet/mailjet-apiv3-go | http_client.go | SendMailV31 | func (c *HTTPClient) SendMailV31(req *http.Request) (*http.Response, error) {
res, err := c.Client().Do(req)
return res, err
} | go | func (c *HTTPClient) SendMailV31(req *http.Request) (*http.Response, error) {
res, err := c.Client().Do(req)
return res, err
} | [
"func",
"(",
"c",
"*",
"HTTPClient",
")",
"SendMailV31",
"(",
"req",
"*",
"http",
".",
"Request",
")",
"(",
"*",
"http",
".",
"Response",
",",
"error",
")",
"{",
"res",
",",
"err",
":=",
"c",
".",
"Client",
"(",
")",
".",
"Do",
"(",
"req",
")",
"\n",
"return",
"res",
",",
"err",
"\n",
"}"
] | // SendMailV31 simply calls the underlying http client.Do function | [
"SendMailV31",
"simply",
"calls",
"the",
"underlying",
"http",
"client",
".",
"Do",
"function"
] | e508c28bf11623de2171a2331fc673391b066867 | https://github.com/mailjet/mailjet-apiv3-go/blob/e508c28bf11623de2171a2331fc673391b066867/http_client.go#L62-L65 |
11,668 | mailjet/mailjet-apiv3-go | http_client.go | Call | func (c *HTTPClient) Call() (count, total int, err error) {
defer c.reset()
for key, value := range c.headers {
c.request.Header.Add(key, value)
}
resp, err := c.doRequest(c.request)
if resp != nil {
defer resp.Body.Close()
}
if err != nil {
return count, total, err
} else if resp == nil {
return count, total, fmt.Errorf("empty response")
}
if c.response != nil {
if resp.Header["Content-Type"] != nil {
contentType := strings.ToLower(resp.Header["Content-Type"][0])
if strings.Contains(contentType, "application/json") {
return readJSONResult(resp.Body, c.response)
} else if strings.Contains(contentType, "text/csv") {
c.response, err = csv.NewReader(resp.Body).ReadAll()
}
}
}
return count, total, err
} | go | func (c *HTTPClient) Call() (count, total int, err error) {
defer c.reset()
for key, value := range c.headers {
c.request.Header.Add(key, value)
}
resp, err := c.doRequest(c.request)
if resp != nil {
defer resp.Body.Close()
}
if err != nil {
return count, total, err
} else if resp == nil {
return count, total, fmt.Errorf("empty response")
}
if c.response != nil {
if resp.Header["Content-Type"] != nil {
contentType := strings.ToLower(resp.Header["Content-Type"][0])
if strings.Contains(contentType, "application/json") {
return readJSONResult(resp.Body, c.response)
} else if strings.Contains(contentType, "text/csv") {
c.response, err = csv.NewReader(resp.Body).ReadAll()
}
}
}
return count, total, err
} | [
"func",
"(",
"c",
"*",
"HTTPClient",
")",
"Call",
"(",
")",
"(",
"count",
",",
"total",
"int",
",",
"err",
"error",
")",
"{",
"defer",
"c",
".",
"reset",
"(",
")",
"\n",
"for",
"key",
",",
"value",
":=",
"range",
"c",
".",
"headers",
"{",
"c",
".",
"request",
".",
"Header",
".",
"Add",
"(",
"key",
",",
"value",
")",
"\n",
"}",
"\n\n",
"resp",
",",
"err",
":=",
"c",
".",
"doRequest",
"(",
"c",
".",
"request",
")",
"\n",
"if",
"resp",
"!=",
"nil",
"{",
"defer",
"resp",
".",
"Body",
".",
"Close",
"(",
")",
"\n",
"}",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"count",
",",
"total",
",",
"err",
"\n",
"}",
"else",
"if",
"resp",
"==",
"nil",
"{",
"return",
"count",
",",
"total",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"c",
".",
"response",
"!=",
"nil",
"{",
"if",
"resp",
".",
"Header",
"[",
"\"",
"\"",
"]",
"!=",
"nil",
"{",
"contentType",
":=",
"strings",
".",
"ToLower",
"(",
"resp",
".",
"Header",
"[",
"\"",
"\"",
"]",
"[",
"0",
"]",
")",
"\n",
"if",
"strings",
".",
"Contains",
"(",
"contentType",
",",
"\"",
"\"",
")",
"{",
"return",
"readJSONResult",
"(",
"resp",
".",
"Body",
",",
"c",
".",
"response",
")",
"\n",
"}",
"else",
"if",
"strings",
".",
"Contains",
"(",
"contentType",
",",
"\"",
"\"",
")",
"{",
"c",
".",
"response",
",",
"err",
"=",
"csv",
".",
"NewReader",
"(",
"resp",
".",
"Body",
")",
".",
"ReadAll",
"(",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"count",
",",
"total",
",",
"err",
"\n",
"}"
] | // Call execute the HTTP call to the API | [
"Call",
"execute",
"the",
"HTTP",
"call",
"to",
"the",
"API"
] | e508c28bf11623de2171a2331fc673391b066867 | https://github.com/mailjet/mailjet-apiv3-go/blob/e508c28bf11623de2171a2331fc673391b066867/http_client.go#L74-L103 |
11,669 | mailjet/mailjet-apiv3-go | core.go | createRequest | func createRequest(method string, url string,
payload interface{}, onlyFields []string,
options ...RequestOptions) (req *http.Request, err error) {
body, err := convertPayload(payload, onlyFields)
if err != nil {
return req, fmt.Errorf("creating request: %s\n", err)
}
req, err = http.NewRequest(method, url, bytes.NewBuffer(body))
if err != nil {
return req, fmt.Errorf("creating request: %s\n", err)
}
for _, option := range options {
option(req)
}
userAgent(req)
req.Header.Add("Accept", "application/json")
return req, err
} | go | func createRequest(method string, url string,
payload interface{}, onlyFields []string,
options ...RequestOptions) (req *http.Request, err error) {
body, err := convertPayload(payload, onlyFields)
if err != nil {
return req, fmt.Errorf("creating request: %s\n", err)
}
req, err = http.NewRequest(method, url, bytes.NewBuffer(body))
if err != nil {
return req, fmt.Errorf("creating request: %s\n", err)
}
for _, option := range options {
option(req)
}
userAgent(req)
req.Header.Add("Accept", "application/json")
return req, err
} | [
"func",
"createRequest",
"(",
"method",
"string",
",",
"url",
"string",
",",
"payload",
"interface",
"{",
"}",
",",
"onlyFields",
"[",
"]",
"string",
",",
"options",
"...",
"RequestOptions",
")",
"(",
"req",
"*",
"http",
".",
"Request",
",",
"err",
"error",
")",
"{",
"body",
",",
"err",
":=",
"convertPayload",
"(",
"payload",
",",
"onlyFields",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"req",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\\n",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"req",
",",
"err",
"=",
"http",
".",
"NewRequest",
"(",
"method",
",",
"url",
",",
"bytes",
".",
"NewBuffer",
"(",
"body",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"req",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\\n",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"for",
"_",
",",
"option",
":=",
"range",
"options",
"{",
"option",
"(",
"req",
")",
"\n",
"}",
"\n",
"userAgent",
"(",
"req",
")",
"\n",
"req",
".",
"Header",
".",
"Add",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"return",
"req",
",",
"err",
"\n",
"}"
] | // createRequest is the main core function. | [
"createRequest",
"is",
"the",
"main",
"core",
"function",
"."
] | e508c28bf11623de2171a2331fc673391b066867 | https://github.com/mailjet/mailjet-apiv3-go/blob/e508c28bf11623de2171a2331fc673391b066867/core.go#L40-L58 |
11,670 | mailjet/mailjet-apiv3-go | core.go | userAgent | func userAgent(req *http.Request) {
ua := fmt.Sprintf("%s/%s;%s",
UserAgentBase,
UserAgentVersion,
runtime.Version(),
)
req.Header.Add("User-Agent", ua)
} | go | func userAgent(req *http.Request) {
ua := fmt.Sprintf("%s/%s;%s",
UserAgentBase,
UserAgentVersion,
runtime.Version(),
)
req.Header.Add("User-Agent", ua)
} | [
"func",
"userAgent",
"(",
"req",
"*",
"http",
".",
"Request",
")",
"{",
"ua",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"UserAgentBase",
",",
"UserAgentVersion",
",",
"runtime",
".",
"Version",
"(",
")",
",",
")",
"\n",
"req",
".",
"Header",
".",
"Add",
"(",
"\"",
"\"",
",",
"ua",
")",
"\n",
"}"
] | // userAgent add the User-Agent value to the request header. | [
"userAgent",
"add",
"the",
"User",
"-",
"Agent",
"value",
"to",
"the",
"request",
"header",
"."
] | e508c28bf11623de2171a2331fc673391b066867 | https://github.com/mailjet/mailjet-apiv3-go/blob/e508c28bf11623de2171a2331fc673391b066867/core.go#L147-L154 |
11,671 | mailjet/mailjet-apiv3-go | core.go | readJSONResult | func readJSONResult(r io.Reader, data interface{}) (int, int, error) {
var res RequestResult
res.Data = data
jsonBlob, err := ioutil.ReadAll(r) // ReadAll and store in jsonBlob (mandatory if we want to unmarshal two times)
if err != nil {
return 0, 0, fmt.Errorf("Error reading API response: %s", err)
}
if DebugLevel == LevelDebugFull {
log.Println("Body: ", string(jsonBlob)) // DEBUG
}
err = json.Unmarshal(jsonBlob, &res) // First try with the RequestResult struct
if err != nil {
return 0, 0, fmt.Errorf("Error decoding API response: %s", err)
} else if _, ok := data.(**SentResult); ok { // Send API case
err = json.Unmarshal(jsonBlob, data) // Trying directly with struct specified in parameter
if err != nil {
return 0, 0, fmt.Errorf("Error decoding API response: %s", err)
}
return 0, 0, nil // Count and Total are undetermined
}
return res.Count, res.Total, nil
} | go | func readJSONResult(r io.Reader, data interface{}) (int, int, error) {
var res RequestResult
res.Data = data
jsonBlob, err := ioutil.ReadAll(r) // ReadAll and store in jsonBlob (mandatory if we want to unmarshal two times)
if err != nil {
return 0, 0, fmt.Errorf("Error reading API response: %s", err)
}
if DebugLevel == LevelDebugFull {
log.Println("Body: ", string(jsonBlob)) // DEBUG
}
err = json.Unmarshal(jsonBlob, &res) // First try with the RequestResult struct
if err != nil {
return 0, 0, fmt.Errorf("Error decoding API response: %s", err)
} else if _, ok := data.(**SentResult); ok { // Send API case
err = json.Unmarshal(jsonBlob, data) // Trying directly with struct specified in parameter
if err != nil {
return 0, 0, fmt.Errorf("Error decoding API response: %s", err)
}
return 0, 0, nil // Count and Total are undetermined
}
return res.Count, res.Total, nil
} | [
"func",
"readJSONResult",
"(",
"r",
"io",
".",
"Reader",
",",
"data",
"interface",
"{",
"}",
")",
"(",
"int",
",",
"int",
",",
"error",
")",
"{",
"var",
"res",
"RequestResult",
"\n",
"res",
".",
"Data",
"=",
"data",
"\n\n",
"jsonBlob",
",",
"err",
":=",
"ioutil",
".",
"ReadAll",
"(",
"r",
")",
"// ReadAll and store in jsonBlob (mandatory if we want to unmarshal two times)",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"0",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"if",
"DebugLevel",
"==",
"LevelDebugFull",
"{",
"log",
".",
"Println",
"(",
"\"",
"\"",
",",
"string",
"(",
"jsonBlob",
")",
")",
"// DEBUG",
"\n",
"}",
"\n\n",
"err",
"=",
"json",
".",
"Unmarshal",
"(",
"jsonBlob",
",",
"&",
"res",
")",
"// First try with the RequestResult struct",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"0",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"else",
"if",
"_",
",",
"ok",
":=",
"data",
".",
"(",
"*",
"*",
"SentResult",
")",
";",
"ok",
"{",
"// Send API case",
"err",
"=",
"json",
".",
"Unmarshal",
"(",
"jsonBlob",
",",
"data",
")",
"// Trying directly with struct specified in parameter",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"0",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"return",
"0",
",",
"0",
",",
"nil",
"// Count and Total are undetermined",
"\n",
"}",
"\n",
"return",
"res",
".",
"Count",
",",
"res",
".",
"Total",
",",
"nil",
"\n",
"}"
] | // readJsonResult decodes the API response, returns Count and Total values
// and stores the Data in the value pointed to by data. | [
"readJsonResult",
"decodes",
"the",
"API",
"response",
"returns",
"Count",
"and",
"Total",
"values",
"and",
"stores",
"the",
"Data",
"in",
"the",
"value",
"pointed",
"to",
"by",
"data",
"."
] | e508c28bf11623de2171a2331fc673391b066867 | https://github.com/mailjet/mailjet-apiv3-go/blob/e508c28bf11623de2171a2331fc673391b066867/core.go#L197-L220 |
11,672 | mailjet/mailjet-apiv3-go | core.go | doRequest | func (c *HTTPClient) doRequest(req *http.Request) (resp *http.Response, err error) {
debugRequest(req) //DEBUG
req.SetBasicAuth(c.apiKeyPublic, c.apiKeyPrivate)
for attempt := 0; attempt < NbAttempt; attempt++ {
if resp != nil {
resp.Body.Close()
}
resp, err = c.client.Do(req)
if err != nil || (resp != nil && resp.StatusCode != 500) {
break
}
}
defer debugResponse(resp) //DEBUG
if err != nil {
return resp, fmt.Errorf("Error getting %s: %s", req.URL, err)
}
err = checkResponseError(resp)
return resp, err
} | go | func (c *HTTPClient) doRequest(req *http.Request) (resp *http.Response, err error) {
debugRequest(req) //DEBUG
req.SetBasicAuth(c.apiKeyPublic, c.apiKeyPrivate)
for attempt := 0; attempt < NbAttempt; attempt++ {
if resp != nil {
resp.Body.Close()
}
resp, err = c.client.Do(req)
if err != nil || (resp != nil && resp.StatusCode != 500) {
break
}
}
defer debugResponse(resp) //DEBUG
if err != nil {
return resp, fmt.Errorf("Error getting %s: %s", req.URL, err)
}
err = checkResponseError(resp)
return resp, err
} | [
"func",
"(",
"c",
"*",
"HTTPClient",
")",
"doRequest",
"(",
"req",
"*",
"http",
".",
"Request",
")",
"(",
"resp",
"*",
"http",
".",
"Response",
",",
"err",
"error",
")",
"{",
"debugRequest",
"(",
"req",
")",
"//DEBUG",
"\n",
"req",
".",
"SetBasicAuth",
"(",
"c",
".",
"apiKeyPublic",
",",
"c",
".",
"apiKeyPrivate",
")",
"\n",
"for",
"attempt",
":=",
"0",
";",
"attempt",
"<",
"NbAttempt",
";",
"attempt",
"++",
"{",
"if",
"resp",
"!=",
"nil",
"{",
"resp",
".",
"Body",
".",
"Close",
"(",
")",
"\n",
"}",
"\n",
"resp",
",",
"err",
"=",
"c",
".",
"client",
".",
"Do",
"(",
"req",
")",
"\n",
"if",
"err",
"!=",
"nil",
"||",
"(",
"resp",
"!=",
"nil",
"&&",
"resp",
".",
"StatusCode",
"!=",
"500",
")",
"{",
"break",
"\n",
"}",
"\n",
"}",
"\n",
"defer",
"debugResponse",
"(",
"resp",
")",
"//DEBUG",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"resp",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"req",
".",
"URL",
",",
"err",
")",
"\n",
"}",
"\n",
"err",
"=",
"checkResponseError",
"(",
"resp",
")",
"\n",
"return",
"resp",
",",
"err",
"\n",
"}"
] | // doRequest is called to execute the request. Authentification is set
// with the public key and the secret key specified in MailjetClient. | [
"doRequest",
"is",
"called",
"to",
"execute",
"the",
"request",
".",
"Authentification",
"is",
"set",
"with",
"the",
"public",
"key",
"and",
"the",
"secret",
"key",
"specified",
"in",
"MailjetClient",
"."
] | e508c28bf11623de2171a2331fc673391b066867 | https://github.com/mailjet/mailjet-apiv3-go/blob/e508c28bf11623de2171a2331fc673391b066867/core.go#L228-L246 |
11,673 | mailjet/mailjet-apiv3-go | core.go | debugRequest | func debugRequest(req *http.Request) {
if DebugLevel > LevelNone && req != nil {
log.Printf("Method used is: %s\n", req.Method)
log.Printf("Final URL is: %s\n", req.URL)
log.Printf("Header is: %s\n", req.Header)
}
} | go | func debugRequest(req *http.Request) {
if DebugLevel > LevelNone && req != nil {
log.Printf("Method used is: %s\n", req.Method)
log.Printf("Final URL is: %s\n", req.URL)
log.Printf("Header is: %s\n", req.Header)
}
} | [
"func",
"debugRequest",
"(",
"req",
"*",
"http",
".",
"Request",
")",
"{",
"if",
"DebugLevel",
">",
"LevelNone",
"&&",
"req",
"!=",
"nil",
"{",
"log",
".",
"Printf",
"(",
"\"",
"\\n",
"\"",
",",
"req",
".",
"Method",
")",
"\n",
"log",
".",
"Printf",
"(",
"\"",
"\\n",
"\"",
",",
"req",
".",
"URL",
")",
"\n",
"log",
".",
"Printf",
"(",
"\"",
"\\n",
"\"",
",",
"req",
".",
"Header",
")",
"\n",
"}",
"\n",
"}"
] | // debugRequest is a custom dump of the request.
// Method used, final URl called, and Header content are logged. | [
"debugRequest",
"is",
"a",
"custom",
"dump",
"of",
"the",
"request",
".",
"Method",
"used",
"final",
"URl",
"called",
"and",
"Header",
"content",
"are",
"logged",
"."
] | e508c28bf11623de2171a2331fc673391b066867 | https://github.com/mailjet/mailjet-apiv3-go/blob/e508c28bf11623de2171a2331fc673391b066867/core.go#L265-L271 |
11,674 | mailjet/mailjet-apiv3-go | core.go | debugResponse | func debugResponse(resp *http.Response) {
if DebugLevel > LevelNone && resp != nil {
log.Printf("Status is: %s\n", resp.Status)
log.Printf("Header is: %s\n", resp.Header)
}
} | go | func debugResponse(resp *http.Response) {
if DebugLevel > LevelNone && resp != nil {
log.Printf("Status is: %s\n", resp.Status)
log.Printf("Header is: %s\n", resp.Header)
}
} | [
"func",
"debugResponse",
"(",
"resp",
"*",
"http",
".",
"Response",
")",
"{",
"if",
"DebugLevel",
">",
"LevelNone",
"&&",
"resp",
"!=",
"nil",
"{",
"log",
".",
"Printf",
"(",
"\"",
"\\n",
"\"",
",",
"resp",
".",
"Status",
")",
"\n",
"log",
".",
"Printf",
"(",
"\"",
"\\n",
"\"",
",",
"resp",
".",
"Header",
")",
"\n",
"}",
"\n",
"}"
] | // debugResponse is a custom dump of the response.
// Status and Header content are logged. | [
"debugResponse",
"is",
"a",
"custom",
"dump",
"of",
"the",
"response",
".",
"Status",
"and",
"Header",
"content",
"are",
"logged",
"."
] | e508c28bf11623de2171a2331fc673391b066867 | https://github.com/mailjet/mailjet-apiv3-go/blob/e508c28bf11623de2171a2331fc673391b066867/core.go#L275-L280 |
11,675 | mailjet/mailjet-apiv3-go | mailjet_client.go | NewMailjetClient | func NewMailjetClient(apiKeyPublic, apiKeyPrivate string, baseURL ...string) *Client {
httpClient := NewHTTPClient(apiKeyPublic, apiKeyPrivate)
smtpClient := NewSMTPClient(apiKeyPublic, apiKeyPrivate)
client := &Client{
httpClient: httpClient,
smtpClient: smtpClient,
apiBase: apiBase,
}
if len(baseURL) > 0 {
client.apiBase = baseURL[0]
}
return client
} | go | func NewMailjetClient(apiKeyPublic, apiKeyPrivate string, baseURL ...string) *Client {
httpClient := NewHTTPClient(apiKeyPublic, apiKeyPrivate)
smtpClient := NewSMTPClient(apiKeyPublic, apiKeyPrivate)
client := &Client{
httpClient: httpClient,
smtpClient: smtpClient,
apiBase: apiBase,
}
if len(baseURL) > 0 {
client.apiBase = baseURL[0]
}
return client
} | [
"func",
"NewMailjetClient",
"(",
"apiKeyPublic",
",",
"apiKeyPrivate",
"string",
",",
"baseURL",
"...",
"string",
")",
"*",
"Client",
"{",
"httpClient",
":=",
"NewHTTPClient",
"(",
"apiKeyPublic",
",",
"apiKeyPrivate",
")",
"\n",
"smtpClient",
":=",
"NewSMTPClient",
"(",
"apiKeyPublic",
",",
"apiKeyPrivate",
")",
"\n\n",
"client",
":=",
"&",
"Client",
"{",
"httpClient",
":",
"httpClient",
",",
"smtpClient",
":",
"smtpClient",
",",
"apiBase",
":",
"apiBase",
",",
"}",
"\n\n",
"if",
"len",
"(",
"baseURL",
")",
">",
"0",
"{",
"client",
".",
"apiBase",
"=",
"baseURL",
"[",
"0",
"]",
"\n",
"}",
"\n",
"return",
"client",
"\n",
"}"
] | // NewMailjetClient returns a new MailjetClient using an public apikey
// and an secret apikey to be used when authenticating to API. | [
"NewMailjetClient",
"returns",
"a",
"new",
"MailjetClient",
"using",
"an",
"public",
"apikey",
"and",
"an",
"secret",
"apikey",
"to",
"be",
"used",
"when",
"authenticating",
"to",
"API",
"."
] | e508c28bf11623de2171a2331fc673391b066867 | https://github.com/mailjet/mailjet-apiv3-go/blob/e508c28bf11623de2171a2331fc673391b066867/mailjet_client.go#L23-L37 |
11,676 | mailjet/mailjet-apiv3-go | mailjet_client.go | SetURL | func (c *Client) SetURL(baseURL string) {
c.Lock()
defer c.Unlock()
c.apiBase = baseURL
} | go | func (c *Client) SetURL(baseURL string) {
c.Lock()
defer c.Unlock()
c.apiBase = baseURL
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"SetURL",
"(",
"baseURL",
"string",
")",
"{",
"c",
".",
"Lock",
"(",
")",
"\n",
"defer",
"c",
".",
"Unlock",
"(",
")",
"\n",
"c",
".",
"apiBase",
"=",
"baseURL",
"\n",
"}"
] | // SetURL function to set the base url of the wrapper instance | [
"SetURL",
"function",
"to",
"set",
"the",
"base",
"url",
"of",
"the",
"wrapper",
"instance"
] | e508c28bf11623de2171a2331fc673391b066867 | https://github.com/mailjet/mailjet-apiv3-go/blob/e508c28bf11623de2171a2331fc673391b066867/mailjet_client.go#L71-L75 |
11,677 | mailjet/mailjet-apiv3-go | mailjet_client.go | SetClient | func (c *Client) SetClient(client *http.Client) {
c.Lock()
defer c.Unlock()
c.httpClient.SetClient(client)
} | go | func (c *Client) SetClient(client *http.Client) {
c.Lock()
defer c.Unlock()
c.httpClient.SetClient(client)
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"SetClient",
"(",
"client",
"*",
"http",
".",
"Client",
")",
"{",
"c",
".",
"Lock",
"(",
")",
"\n",
"defer",
"c",
".",
"Unlock",
"(",
")",
"\n",
"c",
".",
"httpClient",
".",
"SetClient",
"(",
"client",
")",
"\n",
"}"
] | // SetClient allows to customize http client. | [
"SetClient",
"allows",
"to",
"customize",
"http",
"client",
"."
] | e508c28bf11623de2171a2331fc673391b066867 | https://github.com/mailjet/mailjet-apiv3-go/blob/e508c28bf11623de2171a2331fc673391b066867/mailjet_client.go#L83-L87 |
11,678 | mailjet/mailjet-apiv3-go | mailjet_client.go | Filter | func Filter(key, value string) RequestOptions {
return func(req *http.Request) {
q := req.URL.Query()
q.Add(key, value)
req.URL.RawQuery = strings.Replace(q.Encode(), "%2B", "+", 1)
}
} | go | func Filter(key, value string) RequestOptions {
return func(req *http.Request) {
q := req.URL.Query()
q.Add(key, value)
req.URL.RawQuery = strings.Replace(q.Encode(), "%2B", "+", 1)
}
} | [
"func",
"Filter",
"(",
"key",
",",
"value",
"string",
")",
"RequestOptions",
"{",
"return",
"func",
"(",
"req",
"*",
"http",
".",
"Request",
")",
"{",
"q",
":=",
"req",
".",
"URL",
".",
"Query",
"(",
")",
"\n",
"q",
".",
"Add",
"(",
"key",
",",
"value",
")",
"\n",
"req",
".",
"URL",
".",
"RawQuery",
"=",
"strings",
".",
"Replace",
"(",
"q",
".",
"Encode",
"(",
")",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"1",
")",
"\n",
"}",
"\n",
"}"
] | // Filter applies a filter with the defined key and value. | [
"Filter",
"applies",
"a",
"filter",
"with",
"the",
"defined",
"key",
"and",
"value",
"."
] | e508c28bf11623de2171a2331fc673391b066867 | https://github.com/mailjet/mailjet-apiv3-go/blob/e508c28bf11623de2171a2331fc673391b066867/mailjet_client.go#L90-L96 |
11,679 | mailjet/mailjet-apiv3-go | mailjet_client.go | Sort | func Sort(value string, order SortOrder) RequestOptions {
if order == SortDesc {
value = value + "+DESC"
}
return Filter("Sort", value)
} | go | func Sort(value string, order SortOrder) RequestOptions {
if order == SortDesc {
value = value + "+DESC"
}
return Filter("Sort", value)
} | [
"func",
"Sort",
"(",
"value",
"string",
",",
"order",
"SortOrder",
")",
"RequestOptions",
"{",
"if",
"order",
"==",
"SortDesc",
"{",
"value",
"=",
"value",
"+",
"\"",
"\"",
"\n",
"}",
"\n",
"return",
"Filter",
"(",
"\"",
"\"",
",",
"value",
")",
"\n",
"}"
] | // Sort applies the Sort filter to the request. | [
"Sort",
"applies",
"the",
"Sort",
"filter",
"to",
"the",
"request",
"."
] | e508c28bf11623de2171a2331fc673391b066867 | https://github.com/mailjet/mailjet-apiv3-go/blob/e508c28bf11623de2171a2331fc673391b066867/mailjet_client.go#L116-L121 |
11,680 | mailjet/mailjet-apiv3-go | mailjet_client.go | List | func (c *Client) List(resource string, resp interface{}, options ...RequestOptions) (count, total int, err error) {
url := buildURL(c.apiBase, &Request{Resource: resource})
req, err := createRequest("GET", url, nil, nil, options...)
if err != nil {
return count, total, err
}
c.Lock()
defer c.Unlock()
return c.httpClient.Send(req).Read(resp).Call()
} | go | func (c *Client) List(resource string, resp interface{}, options ...RequestOptions) (count, total int, err error) {
url := buildURL(c.apiBase, &Request{Resource: resource})
req, err := createRequest("GET", url, nil, nil, options...)
if err != nil {
return count, total, err
}
c.Lock()
defer c.Unlock()
return c.httpClient.Send(req).Read(resp).Call()
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"List",
"(",
"resource",
"string",
",",
"resp",
"interface",
"{",
"}",
",",
"options",
"...",
"RequestOptions",
")",
"(",
"count",
",",
"total",
"int",
",",
"err",
"error",
")",
"{",
"url",
":=",
"buildURL",
"(",
"c",
".",
"apiBase",
",",
"&",
"Request",
"{",
"Resource",
":",
"resource",
"}",
")",
"\n",
"req",
",",
"err",
":=",
"createRequest",
"(",
"\"",
"\"",
",",
"url",
",",
"nil",
",",
"nil",
",",
"options",
"...",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"count",
",",
"total",
",",
"err",
"\n",
"}",
"\n\n",
"c",
".",
"Lock",
"(",
")",
"\n",
"defer",
"c",
".",
"Unlock",
"(",
")",
"\n",
"return",
"c",
".",
"httpClient",
".",
"Send",
"(",
"req",
")",
".",
"Read",
"(",
"resp",
")",
".",
"Call",
"(",
")",
"\n",
"}"
] | // List issues a GET to list the specified resource
// and stores the result in the value pointed to by res.
// Filters can be add via functional options. | [
"List",
"issues",
"a",
"GET",
"to",
"list",
"the",
"specified",
"resource",
"and",
"stores",
"the",
"result",
"in",
"the",
"value",
"pointed",
"to",
"by",
"res",
".",
"Filters",
"can",
"be",
"add",
"via",
"functional",
"options",
"."
] | e508c28bf11623de2171a2331fc673391b066867 | https://github.com/mailjet/mailjet-apiv3-go/blob/e508c28bf11623de2171a2331fc673391b066867/mailjet_client.go#L126-L136 |
11,681 | mailjet/mailjet-apiv3-go | mailjet_client.go | Get | func (c *Client) Get(mr *Request, resp interface{}, options ...RequestOptions) (err error) {
url := buildURL(c.apiBase, mr)
req, err := createRequest("GET", url, nil, nil, options...)
if err != nil {
return err
}
c.Lock()
defer c.Unlock()
_, _, err = c.httpClient.Send(req).Read(resp).Call()
return err
} | go | func (c *Client) Get(mr *Request, resp interface{}, options ...RequestOptions) (err error) {
url := buildURL(c.apiBase, mr)
req, err := createRequest("GET", url, nil, nil, options...)
if err != nil {
return err
}
c.Lock()
defer c.Unlock()
_, _, err = c.httpClient.Send(req).Read(resp).Call()
return err
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"Get",
"(",
"mr",
"*",
"Request",
",",
"resp",
"interface",
"{",
"}",
",",
"options",
"...",
"RequestOptions",
")",
"(",
"err",
"error",
")",
"{",
"url",
":=",
"buildURL",
"(",
"c",
".",
"apiBase",
",",
"mr",
")",
"\n",
"req",
",",
"err",
":=",
"createRequest",
"(",
"\"",
"\"",
",",
"url",
",",
"nil",
",",
"nil",
",",
"options",
"...",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"c",
".",
"Lock",
"(",
")",
"\n",
"defer",
"c",
".",
"Unlock",
"(",
")",
"\n",
"_",
",",
"_",
",",
"err",
"=",
"c",
".",
"httpClient",
".",
"Send",
"(",
"req",
")",
".",
"Read",
"(",
"resp",
")",
".",
"Call",
"(",
")",
"\n",
"return",
"err",
"\n",
"}"
] | // Get issues a GET to view a resource specifying an id
// and stores the result in the value pointed to by res.
// Filters can be add via functional options.
// Without an specified ID in MailjetRequest, it is the same as List. | [
"Get",
"issues",
"a",
"GET",
"to",
"view",
"a",
"resource",
"specifying",
"an",
"id",
"and",
"stores",
"the",
"result",
"in",
"the",
"value",
"pointed",
"to",
"by",
"res",
".",
"Filters",
"can",
"be",
"add",
"via",
"functional",
"options",
".",
"Without",
"an",
"specified",
"ID",
"in",
"MailjetRequest",
"it",
"is",
"the",
"same",
"as",
"List",
"."
] | e508c28bf11623de2171a2331fc673391b066867 | https://github.com/mailjet/mailjet-apiv3-go/blob/e508c28bf11623de2171a2331fc673391b066867/mailjet_client.go#L142-L153 |
11,682 | mailjet/mailjet-apiv3-go | mailjet_client.go | Post | func (c *Client) Post(fmr *FullRequest, resp interface{}, options ...RequestOptions) (err error) {
url := buildURL(c.apiBase, fmr.Info)
req, err := createRequest("POST", url, fmr.Payload, nil, options...)
if err != nil {
return err
}
headers := map[string]string{"Content-Type": "application/json"}
c.Lock()
defer c.Unlock()
_, _, err = c.httpClient.Send(req).With(headers).Read(resp).Call()
return err
} | go | func (c *Client) Post(fmr *FullRequest, resp interface{}, options ...RequestOptions) (err error) {
url := buildURL(c.apiBase, fmr.Info)
req, err := createRequest("POST", url, fmr.Payload, nil, options...)
if err != nil {
return err
}
headers := map[string]string{"Content-Type": "application/json"}
c.Lock()
defer c.Unlock()
_, _, err = c.httpClient.Send(req).With(headers).Read(resp).Call()
return err
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"Post",
"(",
"fmr",
"*",
"FullRequest",
",",
"resp",
"interface",
"{",
"}",
",",
"options",
"...",
"RequestOptions",
")",
"(",
"err",
"error",
")",
"{",
"url",
":=",
"buildURL",
"(",
"c",
".",
"apiBase",
",",
"fmr",
".",
"Info",
")",
"\n",
"req",
",",
"err",
":=",
"createRequest",
"(",
"\"",
"\"",
",",
"url",
",",
"fmr",
".",
"Payload",
",",
"nil",
",",
"options",
"...",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"headers",
":=",
"map",
"[",
"string",
"]",
"string",
"{",
"\"",
"\"",
":",
"\"",
"\"",
"}",
"\n",
"c",
".",
"Lock",
"(",
")",
"\n",
"defer",
"c",
".",
"Unlock",
"(",
")",
"\n",
"_",
",",
"_",
",",
"err",
"=",
"c",
".",
"httpClient",
".",
"Send",
"(",
"req",
")",
".",
"With",
"(",
"headers",
")",
".",
"Read",
"(",
"resp",
")",
".",
"Call",
"(",
")",
"\n",
"return",
"err",
"\n",
"}"
] | // Post issues a POST to create a new resource
// and stores the result in the value pointed to by res.
// Filters can be add via functional options. | [
"Post",
"issues",
"a",
"POST",
"to",
"create",
"a",
"new",
"resource",
"and",
"stores",
"the",
"result",
"in",
"the",
"value",
"pointed",
"to",
"by",
"res",
".",
"Filters",
"can",
"be",
"add",
"via",
"functional",
"options",
"."
] | e508c28bf11623de2171a2331fc673391b066867 | https://github.com/mailjet/mailjet-apiv3-go/blob/e508c28bf11623de2171a2331fc673391b066867/mailjet_client.go#L158-L170 |
11,683 | mailjet/mailjet-apiv3-go | mailjet_client.go | Delete | func (c *Client) Delete(mr *Request) (err error) {
url := buildURL(c.apiBase, mr)
req, err := createRequest("DELETE", url, nil, nil)
if err != nil {
return err
}
c.Lock()
defer c.Unlock()
_, _, err = c.httpClient.Send(req).Call()
return err
} | go | func (c *Client) Delete(mr *Request) (err error) {
url := buildURL(c.apiBase, mr)
req, err := createRequest("DELETE", url, nil, nil)
if err != nil {
return err
}
c.Lock()
defer c.Unlock()
_, _, err = c.httpClient.Send(req).Call()
return err
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"Delete",
"(",
"mr",
"*",
"Request",
")",
"(",
"err",
"error",
")",
"{",
"url",
":=",
"buildURL",
"(",
"c",
".",
"apiBase",
",",
"mr",
")",
"\n",
"req",
",",
"err",
":=",
"createRequest",
"(",
"\"",
"\"",
",",
"url",
",",
"nil",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"c",
".",
"Lock",
"(",
")",
"\n",
"defer",
"c",
".",
"Unlock",
"(",
")",
"\n",
"_",
",",
"_",
",",
"err",
"=",
"c",
".",
"httpClient",
".",
"Send",
"(",
"req",
")",
".",
"Call",
"(",
")",
"\n",
"return",
"err",
"\n",
"}"
] | // Delete is used to delete a resource. | [
"Delete",
"is",
"used",
"to",
"delete",
"a",
"resource",
"."
] | e508c28bf11623de2171a2331fc673391b066867 | https://github.com/mailjet/mailjet-apiv3-go/blob/e508c28bf11623de2171a2331fc673391b066867/mailjet_client.go#L191-L202 |
11,684 | mailjet/mailjet-apiv3-go | mailjet_client.go | SendMail | func (c *Client) SendMail(data *InfoSendMail) (res *SentResult, err error) {
url := c.apiBase + "/send/message"
req, err := createRequest("POST", url, data, nil)
if err != nil {
return res, err
}
headers := map[string]string{"Content-Type": "application/json"}
c.Lock()
defer c.Unlock()
_, _, err = c.httpClient.Send(req).With(headers).Read(&res).Call()
return res, err
} | go | func (c *Client) SendMail(data *InfoSendMail) (res *SentResult, err error) {
url := c.apiBase + "/send/message"
req, err := createRequest("POST", url, data, nil)
if err != nil {
return res, err
}
headers := map[string]string{"Content-Type": "application/json"}
c.Lock()
defer c.Unlock()
_, _, err = c.httpClient.Send(req).With(headers).Read(&res).Call()
return res, err
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"SendMail",
"(",
"data",
"*",
"InfoSendMail",
")",
"(",
"res",
"*",
"SentResult",
",",
"err",
"error",
")",
"{",
"url",
":=",
"c",
".",
"apiBase",
"+",
"\"",
"\"",
"\n",
"req",
",",
"err",
":=",
"createRequest",
"(",
"\"",
"\"",
",",
"url",
",",
"data",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"res",
",",
"err",
"\n",
"}",
"\n\n",
"headers",
":=",
"map",
"[",
"string",
"]",
"string",
"{",
"\"",
"\"",
":",
"\"",
"\"",
"}",
"\n\n",
"c",
".",
"Lock",
"(",
")",
"\n",
"defer",
"c",
".",
"Unlock",
"(",
")",
"\n",
"_",
",",
"_",
",",
"err",
"=",
"c",
".",
"httpClient",
".",
"Send",
"(",
"req",
")",
".",
"With",
"(",
"headers",
")",
".",
"Read",
"(",
"&",
"res",
")",
".",
"Call",
"(",
")",
"\n",
"return",
"res",
",",
"err",
"\n",
"}"
] | // SendMail send mail via API. | [
"SendMail",
"send",
"mail",
"via",
"API",
"."
] | e508c28bf11623de2171a2331fc673391b066867 | https://github.com/mailjet/mailjet-apiv3-go/blob/e508c28bf11623de2171a2331fc673391b066867/mailjet_client.go#L205-L218 |
11,685 | mailjet/mailjet-apiv3-go | mailjet_client.go | SendMailSMTP | func (c *Client) SendMailSMTP(info *InfoSMTP) error {
return c.smtpClient.SendMail(
info.From,
info.Recipients,
buildMessage(info.Header, info.Content))
} | go | func (c *Client) SendMailSMTP(info *InfoSMTP) error {
return c.smtpClient.SendMail(
info.From,
info.Recipients,
buildMessage(info.Header, info.Content))
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"SendMailSMTP",
"(",
"info",
"*",
"InfoSMTP",
")",
"error",
"{",
"return",
"c",
".",
"smtpClient",
".",
"SendMail",
"(",
"info",
".",
"From",
",",
"info",
".",
"Recipients",
",",
"buildMessage",
"(",
"info",
".",
"Header",
",",
"info",
".",
"Content",
")",
")",
"\n",
"}"
] | // SendMailSMTP send mail via SMTP. | [
"SendMailSMTP",
"send",
"mail",
"via",
"SMTP",
"."
] | e508c28bf11623de2171a2331fc673391b066867 | https://github.com/mailjet/mailjet-apiv3-go/blob/e508c28bf11623de2171a2331fc673391b066867/mailjet_client.go#L221-L226 |
11,686 | mailjet/mailjet-apiv3-go | mailjet_client.go | SendMailV31 | func (c *Client) SendMailV31(data *MessagesV31) (*ResultsV31, error) {
url := c.apiBase + ".1/send"
req, err := createRequest("POST", url, data, nil)
if err != nil {
return nil, err
}
req.Header.Set("Content-Type", "application/json")
req.SetBasicAuth(c.APIKeyPublic(), c.APIKeyPrivate())
r, err := c.httpClient.SendMailV31(req)
if err != nil {
return nil, err
}
decoder := json.NewDecoder(r.Body)
switch r.StatusCode {
case http.StatusOK:
var res ResultsV31
if err := decoder.Decode(&res); err != nil {
return nil, err
}
return &res, nil
case http.StatusBadRequest, http.StatusForbidden:
var apiFeedbackErr APIFeedbackErrorsV31
if err := decoder.Decode(&apiFeedbackErr); err != nil {
return nil, err
}
return nil, &apiFeedbackErr
default:
var errInfo ErrorInfoV31
if err := decoder.Decode(&errInfo); err != nil {
return nil, err
}
return nil, &errInfo
}
} | go | func (c *Client) SendMailV31(data *MessagesV31) (*ResultsV31, error) {
url := c.apiBase + ".1/send"
req, err := createRequest("POST", url, data, nil)
if err != nil {
return nil, err
}
req.Header.Set("Content-Type", "application/json")
req.SetBasicAuth(c.APIKeyPublic(), c.APIKeyPrivate())
r, err := c.httpClient.SendMailV31(req)
if err != nil {
return nil, err
}
decoder := json.NewDecoder(r.Body)
switch r.StatusCode {
case http.StatusOK:
var res ResultsV31
if err := decoder.Decode(&res); err != nil {
return nil, err
}
return &res, nil
case http.StatusBadRequest, http.StatusForbidden:
var apiFeedbackErr APIFeedbackErrorsV31
if err := decoder.Decode(&apiFeedbackErr); err != nil {
return nil, err
}
return nil, &apiFeedbackErr
default:
var errInfo ErrorInfoV31
if err := decoder.Decode(&errInfo); err != nil {
return nil, err
}
return nil, &errInfo
}
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"SendMailV31",
"(",
"data",
"*",
"MessagesV31",
")",
"(",
"*",
"ResultsV31",
",",
"error",
")",
"{",
"url",
":=",
"c",
".",
"apiBase",
"+",
"\"",
"\"",
"\n",
"req",
",",
"err",
":=",
"createRequest",
"(",
"\"",
"\"",
",",
"url",
",",
"data",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"req",
".",
"Header",
".",
"Set",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"req",
".",
"SetBasicAuth",
"(",
"c",
".",
"APIKeyPublic",
"(",
")",
",",
"c",
".",
"APIKeyPrivate",
"(",
")",
")",
"\n\n",
"r",
",",
"err",
":=",
"c",
".",
"httpClient",
".",
"SendMailV31",
"(",
"req",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"decoder",
":=",
"json",
".",
"NewDecoder",
"(",
"r",
".",
"Body",
")",
"\n\n",
"switch",
"r",
".",
"StatusCode",
"{",
"case",
"http",
".",
"StatusOK",
":",
"var",
"res",
"ResultsV31",
"\n",
"if",
"err",
":=",
"decoder",
".",
"Decode",
"(",
"&",
"res",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"&",
"res",
",",
"nil",
"\n\n",
"case",
"http",
".",
"StatusBadRequest",
",",
"http",
".",
"StatusForbidden",
":",
"var",
"apiFeedbackErr",
"APIFeedbackErrorsV31",
"\n",
"if",
"err",
":=",
"decoder",
".",
"Decode",
"(",
"&",
"apiFeedbackErr",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"nil",
",",
"&",
"apiFeedbackErr",
"\n\n",
"default",
":",
"var",
"errInfo",
"ErrorInfoV31",
"\n",
"if",
"err",
":=",
"decoder",
".",
"Decode",
"(",
"&",
"errInfo",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"nil",
",",
"&",
"errInfo",
"\n",
"}",
"\n",
"}"
] | // SendMailV31 sends a mail to the send API v3.1 | [
"SendMailV31",
"sends",
"a",
"mail",
"to",
"the",
"send",
"API",
"v3",
".",
"1"
] | e508c28bf11623de2171a2331fc673391b066867 | https://github.com/mailjet/mailjet-apiv3-go/blob/e508c28bf11623de2171a2331fc673391b066867/mailjet_client.go#L240-L282 |
11,687 | briandowns/openweathermap | uv.go | NewUV | func NewUV(key string, options ...Option) (*UV, error) {
k, err := setKey(key)
if err != nil {
return nil, err
}
u := &UV{
Key: k,
Settings: NewSettings(),
}
if err := setOptions(u.Settings, options); err != nil {
return nil, err
}
return u, nil
} | go | func NewUV(key string, options ...Option) (*UV, error) {
k, err := setKey(key)
if err != nil {
return nil, err
}
u := &UV{
Key: k,
Settings: NewSettings(),
}
if err := setOptions(u.Settings, options); err != nil {
return nil, err
}
return u, nil
} | [
"func",
"NewUV",
"(",
"key",
"string",
",",
"options",
"...",
"Option",
")",
"(",
"*",
"UV",
",",
"error",
")",
"{",
"k",
",",
"err",
":=",
"setKey",
"(",
"key",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"u",
":=",
"&",
"UV",
"{",
"Key",
":",
"k",
",",
"Settings",
":",
"NewSettings",
"(",
")",
",",
"}",
"\n\n",
"if",
"err",
":=",
"setOptions",
"(",
"u",
".",
"Settings",
",",
"options",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"u",
",",
"nil",
"\n",
"}"
] | // NewUV creates a new reference to UV | [
"NewUV",
"creates",
"a",
"new",
"reference",
"to",
"UV"
] | 5f41b7c9d92de5d74bf32f4486375c7547bc8a3c | https://github.com/briandowns/openweathermap/blob/5f41b7c9d92de5d74bf32f4486375c7547bc8a3c/uv.go#L33-L47 |
11,688 | briandowns/openweathermap | uv.go | Current | func (u *UV) Current(coord *Coordinates) error {
response, err := u.client.Get(fmt.Sprintf("%suvi?lat=%f&lon=%f&appid=%s", uvURL, coord.Latitude, coord.Longitude, u.Key))
if err != nil {
return err
}
defer response.Body.Close()
if err = json.NewDecoder(response.Body).Decode(&u); err != nil {
return err
}
return nil
} | go | func (u *UV) Current(coord *Coordinates) error {
response, err := u.client.Get(fmt.Sprintf("%suvi?lat=%f&lon=%f&appid=%s", uvURL, coord.Latitude, coord.Longitude, u.Key))
if err != nil {
return err
}
defer response.Body.Close()
if err = json.NewDecoder(response.Body).Decode(&u); err != nil {
return err
}
return nil
} | [
"func",
"(",
"u",
"*",
"UV",
")",
"Current",
"(",
"coord",
"*",
"Coordinates",
")",
"error",
"{",
"response",
",",
"err",
":=",
"u",
".",
"client",
".",
"Get",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"uvURL",
",",
"coord",
".",
"Latitude",
",",
"coord",
".",
"Longitude",
",",
"u",
".",
"Key",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"defer",
"response",
".",
"Body",
".",
"Close",
"(",
")",
"\n\n",
"if",
"err",
"=",
"json",
".",
"NewDecoder",
"(",
"response",
".",
"Body",
")",
".",
"Decode",
"(",
"&",
"u",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // Current gets the current UV data for the given coordinates | [
"Current",
"gets",
"the",
"current",
"UV",
"data",
"for",
"the",
"given",
"coordinates"
] | 5f41b7c9d92de5d74bf32f4486375c7547bc8a3c | https://github.com/briandowns/openweathermap/blob/5f41b7c9d92de5d74bf32f4486375c7547bc8a3c/uv.go#L50-L62 |
11,689 | briandowns/openweathermap | uv.go | Historical | func (u *UV) Historical(coord *Coordinates, start, end time.Time) error {
response, err := u.client.Get(fmt.Sprintf("%shistory?lat=%f&lon=%f&start=%d&end=%d&appid=%s", uvURL, coord.Latitude, coord.Longitude, start.Unix(), end.Unix(), u.Key))
if err != nil {
return err
}
defer response.Body.Close()
if err = json.NewDecoder(response.Body).Decode(&u); err != nil {
return err
}
return nil
} | go | func (u *UV) Historical(coord *Coordinates, start, end time.Time) error {
response, err := u.client.Get(fmt.Sprintf("%shistory?lat=%f&lon=%f&start=%d&end=%d&appid=%s", uvURL, coord.Latitude, coord.Longitude, start.Unix(), end.Unix(), u.Key))
if err != nil {
return err
}
defer response.Body.Close()
if err = json.NewDecoder(response.Body).Decode(&u); err != nil {
return err
}
return nil
} | [
"func",
"(",
"u",
"*",
"UV",
")",
"Historical",
"(",
"coord",
"*",
"Coordinates",
",",
"start",
",",
"end",
"time",
".",
"Time",
")",
"error",
"{",
"response",
",",
"err",
":=",
"u",
".",
"client",
".",
"Get",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"uvURL",
",",
"coord",
".",
"Latitude",
",",
"coord",
".",
"Longitude",
",",
"start",
".",
"Unix",
"(",
")",
",",
"end",
".",
"Unix",
"(",
")",
",",
"u",
".",
"Key",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"defer",
"response",
".",
"Body",
".",
"Close",
"(",
")",
"\n\n",
"if",
"err",
"=",
"json",
".",
"NewDecoder",
"(",
"response",
".",
"Body",
")",
".",
"Decode",
"(",
"&",
"u",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // Historical gets the historical UV data for the coordinates and times | [
"Historical",
"gets",
"the",
"historical",
"UV",
"data",
"for",
"the",
"coordinates",
"and",
"times"
] | 5f41b7c9d92de5d74bf32f4486375c7547bc8a3c | https://github.com/briandowns/openweathermap/blob/5f41b7c9d92de5d74bf32f4486375c7547bc8a3c/uv.go#L65-L77 |
11,690 | briandowns/openweathermap | uv.go | UVInformation | func (u *UV) UVInformation() ([]UVIndexInfo, error) {
switch {
case u.Value != 0:
switch {
case u.Value < 2.9:
return []UVIndexInfo{UVData[0]}, nil
case u.Value > 3 && u.Value < 5.9:
return []UVIndexInfo{UVData[1]}, nil
case u.Value > 6 && u.Value < 7.9:
return []UVIndexInfo{UVData[2]}, nil
case u.Value > 8 && u.Value < 10.9:
return []UVIndexInfo{UVData[3]}, nil
case u.Value >= 11:
return []UVIndexInfo{UVData[4]}, nil
default:
return nil, errInvalidUVIndex
}
case len(u.Data) > 0:
var uvi []UVIndexInfo
for _, i := range u.Data {
switch {
case i.Value < 2.9:
uvi = append(uvi, UVData[0])
case i.Value > 3 && u.Value < 5.9:
uvi = append(uvi, UVData[1])
case i.Value > 6 && u.Value < 7.9:
uvi = append(uvi, UVData[2])
case i.Value > 8 && u.Value < 10.9:
uvi = append(uvi, UVData[3])
case i.Value >= 11:
uvi = append(uvi, UVData[4])
default:
return nil, errInvalidUVIndex
}
}
}
return nil, nil
} | go | func (u *UV) UVInformation() ([]UVIndexInfo, error) {
switch {
case u.Value != 0:
switch {
case u.Value < 2.9:
return []UVIndexInfo{UVData[0]}, nil
case u.Value > 3 && u.Value < 5.9:
return []UVIndexInfo{UVData[1]}, nil
case u.Value > 6 && u.Value < 7.9:
return []UVIndexInfo{UVData[2]}, nil
case u.Value > 8 && u.Value < 10.9:
return []UVIndexInfo{UVData[3]}, nil
case u.Value >= 11:
return []UVIndexInfo{UVData[4]}, nil
default:
return nil, errInvalidUVIndex
}
case len(u.Data) > 0:
var uvi []UVIndexInfo
for _, i := range u.Data {
switch {
case i.Value < 2.9:
uvi = append(uvi, UVData[0])
case i.Value > 3 && u.Value < 5.9:
uvi = append(uvi, UVData[1])
case i.Value > 6 && u.Value < 7.9:
uvi = append(uvi, UVData[2])
case i.Value > 8 && u.Value < 10.9:
uvi = append(uvi, UVData[3])
case i.Value >= 11:
uvi = append(uvi, UVData[4])
default:
return nil, errInvalidUVIndex
}
}
}
return nil, nil
} | [
"func",
"(",
"u",
"*",
"UV",
")",
"UVInformation",
"(",
")",
"(",
"[",
"]",
"UVIndexInfo",
",",
"error",
")",
"{",
"switch",
"{",
"case",
"u",
".",
"Value",
"!=",
"0",
":",
"switch",
"{",
"case",
"u",
".",
"Value",
"<",
"2.9",
":",
"return",
"[",
"]",
"UVIndexInfo",
"{",
"UVData",
"[",
"0",
"]",
"}",
",",
"nil",
"\n",
"case",
"u",
".",
"Value",
">",
"3",
"&&",
"u",
".",
"Value",
"<",
"5.9",
":",
"return",
"[",
"]",
"UVIndexInfo",
"{",
"UVData",
"[",
"1",
"]",
"}",
",",
"nil",
"\n",
"case",
"u",
".",
"Value",
">",
"6",
"&&",
"u",
".",
"Value",
"<",
"7.9",
":",
"return",
"[",
"]",
"UVIndexInfo",
"{",
"UVData",
"[",
"2",
"]",
"}",
",",
"nil",
"\n",
"case",
"u",
".",
"Value",
">",
"8",
"&&",
"u",
".",
"Value",
"<",
"10.9",
":",
"return",
"[",
"]",
"UVIndexInfo",
"{",
"UVData",
"[",
"3",
"]",
"}",
",",
"nil",
"\n",
"case",
"u",
".",
"Value",
">=",
"11",
":",
"return",
"[",
"]",
"UVIndexInfo",
"{",
"UVData",
"[",
"4",
"]",
"}",
",",
"nil",
"\n",
"default",
":",
"return",
"nil",
",",
"errInvalidUVIndex",
"\n",
"}",
"\n\n",
"case",
"len",
"(",
"u",
".",
"Data",
")",
">",
"0",
":",
"var",
"uvi",
"[",
"]",
"UVIndexInfo",
"\n",
"for",
"_",
",",
"i",
":=",
"range",
"u",
".",
"Data",
"{",
"switch",
"{",
"case",
"i",
".",
"Value",
"<",
"2.9",
":",
"uvi",
"=",
"append",
"(",
"uvi",
",",
"UVData",
"[",
"0",
"]",
")",
"\n",
"case",
"i",
".",
"Value",
">",
"3",
"&&",
"u",
".",
"Value",
"<",
"5.9",
":",
"uvi",
"=",
"append",
"(",
"uvi",
",",
"UVData",
"[",
"1",
"]",
")",
"\n",
"case",
"i",
".",
"Value",
">",
"6",
"&&",
"u",
".",
"Value",
"<",
"7.9",
":",
"uvi",
"=",
"append",
"(",
"uvi",
",",
"UVData",
"[",
"2",
"]",
")",
"\n",
"case",
"i",
".",
"Value",
">",
"8",
"&&",
"u",
".",
"Value",
"<",
"10.9",
":",
"uvi",
"=",
"append",
"(",
"uvi",
",",
"UVData",
"[",
"3",
"]",
")",
"\n",
"case",
"i",
".",
"Value",
">=",
"11",
":",
"uvi",
"=",
"append",
"(",
"uvi",
",",
"UVData",
"[",
"4",
"]",
")",
"\n",
"default",
":",
"return",
"nil",
",",
"errInvalidUVIndex",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"nil",
",",
"nil",
"\n",
"}"
] | // UVInformation provides information on the given UV data which includes the severity
// and "Recommended protection" | [
"UVInformation",
"provides",
"information",
"on",
"the",
"given",
"UV",
"data",
"which",
"includes",
"the",
"severity",
"and",
"Recommended",
"protection"
] | 5f41b7c9d92de5d74bf32f4486375c7547bc8a3c | https://github.com/briandowns/openweathermap/blob/5f41b7c9d92de5d74bf32f4486375c7547bc8a3c/uv.go#L131-L170 |
11,691 | briandowns/openweathermap | station.go | ValidateStationDataParameter | func ValidateStationDataParameter(param string) bool {
for _, p := range StationDataParameters {
if param == p {
return true
}
}
return false
} | go | func ValidateStationDataParameter(param string) bool {
for _, p := range StationDataParameters {
if param == p {
return true
}
}
return false
} | [
"func",
"ValidateStationDataParameter",
"(",
"param",
"string",
")",
"bool",
"{",
"for",
"_",
",",
"p",
":=",
"range",
"StationDataParameters",
"{",
"if",
"param",
"==",
"p",
"{",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"false",
"\n",
"}"
] | // ValidateStationDataParameter will make sure that whatever parameter
// supplied is one that can actually be used in the POST request. | [
"ValidateStationDataParameter",
"will",
"make",
"sure",
"that",
"whatever",
"parameter",
"supplied",
"is",
"one",
"that",
"can",
"actually",
"be",
"used",
"in",
"the",
"POST",
"request",
"."
] | 5f41b7c9d92de5d74bf32f4486375c7547bc8a3c | https://github.com/briandowns/openweathermap/blob/5f41b7c9d92de5d74bf32f4486375c7547bc8a3c/station.go#L48-L56 |
11,692 | briandowns/openweathermap | station.go | SendStationData | func SendStationData(data url.Values) {
resp, err := http.PostForm(dataPostURL, data)
if err != nil {
fmt.Println(err)
}
fmt.Println(resp.Body)
} | go | func SendStationData(data url.Values) {
resp, err := http.PostForm(dataPostURL, data)
if err != nil {
fmt.Println(err)
}
fmt.Println(resp.Body)
} | [
"func",
"SendStationData",
"(",
"data",
"url",
".",
"Values",
")",
"{",
"resp",
",",
"err",
":=",
"http",
".",
"PostForm",
"(",
"dataPostURL",
",",
"data",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"fmt",
".",
"Println",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"fmt",
".",
"Println",
"(",
"resp",
".",
"Body",
")",
"\n",
"}"
] | // SendStationData will send an instance the provided url.Values to the
// provided URL. | [
"SendStationData",
"will",
"send",
"an",
"instance",
"the",
"provided",
"url",
".",
"Values",
"to",
"the",
"provided",
"URL",
"."
] | 5f41b7c9d92de5d74bf32f4486375c7547bc8a3c | https://github.com/briandowns/openweathermap/blob/5f41b7c9d92de5d74bf32f4486375c7547bc8a3c/station.go#L73-L80 |
11,693 | briandowns/openweathermap | history.go | NewHistorical | func NewHistorical(unit, key string, options ...Option) (*HistoricalWeatherData, error) {
h := &HistoricalWeatherData{
Settings: NewSettings(),
}
unitChoice := strings.ToUpper(unit)
if !ValidDataUnit(unitChoice) {
return nil, errUnitUnavailable
}
h.Unit = DataUnits[unitChoice]
var err error
h.Key, err = setKey(key)
if err != nil {
return nil, err
}
if err := setOptions(h.Settings, options); err != nil {
return nil, err
}
return h, nil
} | go | func NewHistorical(unit, key string, options ...Option) (*HistoricalWeatherData, error) {
h := &HistoricalWeatherData{
Settings: NewSettings(),
}
unitChoice := strings.ToUpper(unit)
if !ValidDataUnit(unitChoice) {
return nil, errUnitUnavailable
}
h.Unit = DataUnits[unitChoice]
var err error
h.Key, err = setKey(key)
if err != nil {
return nil, err
}
if err := setOptions(h.Settings, options); err != nil {
return nil, err
}
return h, nil
} | [
"func",
"NewHistorical",
"(",
"unit",
",",
"key",
"string",
",",
"options",
"...",
"Option",
")",
"(",
"*",
"HistoricalWeatherData",
",",
"error",
")",
"{",
"h",
":=",
"&",
"HistoricalWeatherData",
"{",
"Settings",
":",
"NewSettings",
"(",
")",
",",
"}",
"\n\n",
"unitChoice",
":=",
"strings",
".",
"ToUpper",
"(",
"unit",
")",
"\n",
"if",
"!",
"ValidDataUnit",
"(",
"unitChoice",
")",
"{",
"return",
"nil",
",",
"errUnitUnavailable",
"\n",
"}",
"\n",
"h",
".",
"Unit",
"=",
"DataUnits",
"[",
"unitChoice",
"]",
"\n\n",
"var",
"err",
"error",
"\n",
"h",
".",
"Key",
",",
"err",
"=",
"setKey",
"(",
"key",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"setOptions",
"(",
"h",
".",
"Settings",
",",
"options",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"h",
",",
"nil",
"\n",
"}"
] | // NewHistorical returns a new HistoricalWeatherData pointer with
//the supplied arguments. | [
"NewHistorical",
"returns",
"a",
"new",
"HistoricalWeatherData",
"pointer",
"with",
"the",
"supplied",
"arguments",
"."
] | 5f41b7c9d92de5d74bf32f4486375c7547bc8a3c | https://github.com/briandowns/openweathermap/blob/5f41b7c9d92de5d74bf32f4486375c7547bc8a3c/history.go#L69-L90 |
11,694 | briandowns/openweathermap | history.go | HistoryByName | func (h *HistoricalWeatherData) HistoryByName(location string) error {
response, err := h.client.Get(fmt.Sprintf(fmt.Sprintf(historyURL, "city?appid=%s&q=%s"), h.Key, url.QueryEscape(location)))
if err != nil {
return err
}
defer response.Body.Close()
if err = json.NewDecoder(response.Body).Decode(&h); err != nil {
return err
}
return nil
} | go | func (h *HistoricalWeatherData) HistoryByName(location string) error {
response, err := h.client.Get(fmt.Sprintf(fmt.Sprintf(historyURL, "city?appid=%s&q=%s"), h.Key, url.QueryEscape(location)))
if err != nil {
return err
}
defer response.Body.Close()
if err = json.NewDecoder(response.Body).Decode(&h); err != nil {
return err
}
return nil
} | [
"func",
"(",
"h",
"*",
"HistoricalWeatherData",
")",
"HistoryByName",
"(",
"location",
"string",
")",
"error",
"{",
"response",
",",
"err",
":=",
"h",
".",
"client",
".",
"Get",
"(",
"fmt",
".",
"Sprintf",
"(",
"fmt",
".",
"Sprintf",
"(",
"historyURL",
",",
"\"",
"\"",
")",
",",
"h",
".",
"Key",
",",
"url",
".",
"QueryEscape",
"(",
"location",
")",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"defer",
"response",
".",
"Body",
".",
"Close",
"(",
")",
"\n\n",
"if",
"err",
"=",
"json",
".",
"NewDecoder",
"(",
"response",
".",
"Body",
")",
".",
"Decode",
"(",
"&",
"h",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // HistoryByName will return the history for the provided location | [
"HistoryByName",
"will",
"return",
"the",
"history",
"for",
"the",
"provided",
"location"
] | 5f41b7c9d92de5d74bf32f4486375c7547bc8a3c | https://github.com/briandowns/openweathermap/blob/5f41b7c9d92de5d74bf32f4486375c7547bc8a3c/history.go#L93-L105 |
11,695 | briandowns/openweathermap | history.go | HistoryByID | func (h *HistoricalWeatherData) HistoryByID(id int, hp ...*HistoricalParameters) error {
if len(hp) > 0 {
response, err := h.client.Get(fmt.Sprintf(fmt.Sprintf(historyURL, "city?appid=%s&id=%d&type=hour&start%d&end=%d&cnt=%d"), h.Key, id, hp[0].Start, hp[0].End, hp[0].Cnt))
if err != nil {
return err
}
defer response.Body.Close()
if err = json.NewDecoder(response.Body).Decode(&h); err != nil {
return err
}
}
response, err := h.client.Get(fmt.Sprintf(fmt.Sprintf(historyURL, "city?appid=%s&id=%d"), h.Key, id))
if err != nil {
return err
}
defer response.Body.Close()
if err = json.NewDecoder(response.Body).Decode(&h); err != nil {
return err
}
return nil
} | go | func (h *HistoricalWeatherData) HistoryByID(id int, hp ...*HistoricalParameters) error {
if len(hp) > 0 {
response, err := h.client.Get(fmt.Sprintf(fmt.Sprintf(historyURL, "city?appid=%s&id=%d&type=hour&start%d&end=%d&cnt=%d"), h.Key, id, hp[0].Start, hp[0].End, hp[0].Cnt))
if err != nil {
return err
}
defer response.Body.Close()
if err = json.NewDecoder(response.Body).Decode(&h); err != nil {
return err
}
}
response, err := h.client.Get(fmt.Sprintf(fmt.Sprintf(historyURL, "city?appid=%s&id=%d"), h.Key, id))
if err != nil {
return err
}
defer response.Body.Close()
if err = json.NewDecoder(response.Body).Decode(&h); err != nil {
return err
}
return nil
} | [
"func",
"(",
"h",
"*",
"HistoricalWeatherData",
")",
"HistoryByID",
"(",
"id",
"int",
",",
"hp",
"...",
"*",
"HistoricalParameters",
")",
"error",
"{",
"if",
"len",
"(",
"hp",
")",
">",
"0",
"{",
"response",
",",
"err",
":=",
"h",
".",
"client",
".",
"Get",
"(",
"fmt",
".",
"Sprintf",
"(",
"fmt",
".",
"Sprintf",
"(",
"historyURL",
",",
"\"",
"\"",
")",
",",
"h",
".",
"Key",
",",
"id",
",",
"hp",
"[",
"0",
"]",
".",
"Start",
",",
"hp",
"[",
"0",
"]",
".",
"End",
",",
"hp",
"[",
"0",
"]",
".",
"Cnt",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"defer",
"response",
".",
"Body",
".",
"Close",
"(",
")",
"\n\n",
"if",
"err",
"=",
"json",
".",
"NewDecoder",
"(",
"response",
".",
"Body",
")",
".",
"Decode",
"(",
"&",
"h",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"response",
",",
"err",
":=",
"h",
".",
"client",
".",
"Get",
"(",
"fmt",
".",
"Sprintf",
"(",
"fmt",
".",
"Sprintf",
"(",
"historyURL",
",",
"\"",
"\"",
")",
",",
"h",
".",
"Key",
",",
"id",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"defer",
"response",
".",
"Body",
".",
"Close",
"(",
")",
"\n\n",
"if",
"err",
"=",
"json",
".",
"NewDecoder",
"(",
"response",
".",
"Body",
")",
".",
"Decode",
"(",
"&",
"h",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // HistoryByID will return the history for the provided location ID | [
"HistoryByID",
"will",
"return",
"the",
"history",
"for",
"the",
"provided",
"location",
"ID"
] | 5f41b7c9d92de5d74bf32f4486375c7547bc8a3c | https://github.com/briandowns/openweathermap/blob/5f41b7c9d92de5d74bf32f4486375c7547bc8a3c/history.go#L108-L132 |
11,696 | briandowns/openweathermap | history.go | HistoryByCoord | func (h *HistoricalWeatherData) HistoryByCoord(location *Coordinates, hp *HistoricalParameters) error {
response, err := h.client.Get(fmt.Sprintf(fmt.Sprintf(historyURL, "appid=%s&lat=%f&lon=%f&start=%d&end=%d"), h.Key, location.Latitude, location.Longitude, hp.Start, hp.End))
if err != nil {
return err
}
defer response.Body.Close()
if err = json.NewDecoder(response.Body).Decode(&h); err != nil {
return err
}
return nil
} | go | func (h *HistoricalWeatherData) HistoryByCoord(location *Coordinates, hp *HistoricalParameters) error {
response, err := h.client.Get(fmt.Sprintf(fmt.Sprintf(historyURL, "appid=%s&lat=%f&lon=%f&start=%d&end=%d"), h.Key, location.Latitude, location.Longitude, hp.Start, hp.End))
if err != nil {
return err
}
defer response.Body.Close()
if err = json.NewDecoder(response.Body).Decode(&h); err != nil {
return err
}
return nil
} | [
"func",
"(",
"h",
"*",
"HistoricalWeatherData",
")",
"HistoryByCoord",
"(",
"location",
"*",
"Coordinates",
",",
"hp",
"*",
"HistoricalParameters",
")",
"error",
"{",
"response",
",",
"err",
":=",
"h",
".",
"client",
".",
"Get",
"(",
"fmt",
".",
"Sprintf",
"(",
"fmt",
".",
"Sprintf",
"(",
"historyURL",
",",
"\"",
"\"",
")",
",",
"h",
".",
"Key",
",",
"location",
".",
"Latitude",
",",
"location",
".",
"Longitude",
",",
"hp",
".",
"Start",
",",
"hp",
".",
"End",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"defer",
"response",
".",
"Body",
".",
"Close",
"(",
")",
"\n\n",
"if",
"err",
"=",
"json",
".",
"NewDecoder",
"(",
"response",
".",
"Body",
")",
".",
"Decode",
"(",
"&",
"h",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // HistoryByCoord will return the history for the provided coordinates | [
"HistoryByCoord",
"will",
"return",
"the",
"history",
"for",
"the",
"provided",
"coordinates"
] | 5f41b7c9d92de5d74bf32f4486375c7547bc8a3c | https://github.com/briandowns/openweathermap/blob/5f41b7c9d92de5d74bf32f4486375c7547bc8a3c/history.go#L135-L147 |
11,697 | briandowns/openweathermap | pollution.go | ValidAlias | func ValidAlias(alias string) bool {
for _, i := range DateTimeAliases {
if i == alias {
return true
}
}
return false
} | go | func ValidAlias(alias string) bool {
for _, i := range DateTimeAliases {
if i == alias {
return true
}
}
return false
} | [
"func",
"ValidAlias",
"(",
"alias",
"string",
")",
"bool",
"{",
"for",
"_",
",",
"i",
":=",
"range",
"DateTimeAliases",
"{",
"if",
"i",
"==",
"alias",
"{",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
] | // ValidAlias checks to make sure the given alias is a valid one | [
"ValidAlias",
"checks",
"to",
"make",
"sure",
"the",
"given",
"alias",
"is",
"a",
"valid",
"one"
] | 5f41b7c9d92de5d74bf32f4486375c7547bc8a3c | https://github.com/briandowns/openweathermap/blob/5f41b7c9d92de5d74bf32f4486375c7547bc8a3c/pollution.go#L14-L21 |
11,698 | briandowns/openweathermap | pollution.go | NewPollution | func NewPollution(key string, options ...Option) (*Pollution, error) {
k, err := setKey(key)
if err != nil {
return nil, err
}
p := &Pollution{
Key: k,
Settings: NewSettings(),
}
if err := setOptions(p.Settings, options); err != nil {
return nil, err
}
return p, nil
} | go | func NewPollution(key string, options ...Option) (*Pollution, error) {
k, err := setKey(key)
if err != nil {
return nil, err
}
p := &Pollution{
Key: k,
Settings: NewSettings(),
}
if err := setOptions(p.Settings, options); err != nil {
return nil, err
}
return p, nil
} | [
"func",
"NewPollution",
"(",
"key",
"string",
",",
"options",
"...",
"Option",
")",
"(",
"*",
"Pollution",
",",
"error",
")",
"{",
"k",
",",
"err",
":=",
"setKey",
"(",
"key",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"p",
":=",
"&",
"Pollution",
"{",
"Key",
":",
"k",
",",
"Settings",
":",
"NewSettings",
"(",
")",
",",
"}",
"\n\n",
"if",
"err",
":=",
"setOptions",
"(",
"p",
".",
"Settings",
",",
"options",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"p",
",",
"nil",
"\n",
"}"
] | // NewPollution creates a new reference to Pollution | [
"NewPollution",
"creates",
"a",
"new",
"reference",
"to",
"Pollution"
] | 5f41b7c9d92de5d74bf32f4486375c7547bc8a3c | https://github.com/briandowns/openweathermap/blob/5f41b7c9d92de5d74bf32f4486375c7547bc8a3c/pollution.go#L47-L61 |
11,699 | briandowns/openweathermap | pollution.go | PollutionByParams | func (p *Pollution) PollutionByParams(params *PollutionParameters) error {
url := fmt.Sprintf("%s%s,%s/%s.json?appid=%s",
pollutionURL,
strconv.FormatFloat(params.Location.Latitude, 'f', -1, 64),
strconv.FormatFloat(params.Location.Longitude, 'f', -1, 64),
params.Datetime,
p.Key)
response, err := p.client.Get(url)
if err != nil {
return err
}
defer response.Body.Close()
if err = json.NewDecoder(response.Body).Decode(&p); err != nil {
return err
}
return nil
} | go | func (p *Pollution) PollutionByParams(params *PollutionParameters) error {
url := fmt.Sprintf("%s%s,%s/%s.json?appid=%s",
pollutionURL,
strconv.FormatFloat(params.Location.Latitude, 'f', -1, 64),
strconv.FormatFloat(params.Location.Longitude, 'f', -1, 64),
params.Datetime,
p.Key)
response, err := p.client.Get(url)
if err != nil {
return err
}
defer response.Body.Close()
if err = json.NewDecoder(response.Body).Decode(&p); err != nil {
return err
}
return nil
} | [
"func",
"(",
"p",
"*",
"Pollution",
")",
"PollutionByParams",
"(",
"params",
"*",
"PollutionParameters",
")",
"error",
"{",
"url",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"pollutionURL",
",",
"strconv",
".",
"FormatFloat",
"(",
"params",
".",
"Location",
".",
"Latitude",
",",
"'f'",
",",
"-",
"1",
",",
"64",
")",
",",
"strconv",
".",
"FormatFloat",
"(",
"params",
".",
"Location",
".",
"Longitude",
",",
"'f'",
",",
"-",
"1",
",",
"64",
")",
",",
"params",
".",
"Datetime",
",",
"p",
".",
"Key",
")",
"\n",
"response",
",",
"err",
":=",
"p",
".",
"client",
".",
"Get",
"(",
"url",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"defer",
"response",
".",
"Body",
".",
"Close",
"(",
")",
"\n\n",
"if",
"err",
"=",
"json",
".",
"NewDecoder",
"(",
"response",
".",
"Body",
")",
".",
"Decode",
"(",
"&",
"p",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // PollutionByParams gets the pollution data based on the given parameters | [
"PollutionByParams",
"gets",
"the",
"pollution",
"data",
"based",
"on",
"the",
"given",
"parameters"
] | 5f41b7c9d92de5d74bf32f4486375c7547bc8a3c | https://github.com/briandowns/openweathermap/blob/5f41b7c9d92de5d74bf32f4486375c7547bc8a3c/pollution.go#L64-L82 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.