repository_name
stringlengths
5
54
func_path_in_repository
stringlengths
4
155
func_name
stringlengths
1
118
whole_func_string
stringlengths
52
3.87M
language
stringclasses
1 value
func_code_string
stringlengths
52
3.87M
func_code_tokens
sequencelengths
21
188k
func_documentation_string
stringlengths
4
26.3k
func_documentation_tokens
sequencelengths
1
3.92k
split_name
stringclasses
1 value
func_code_url
stringlengths
85
252
hashicorp/raft-boltdb
bolt_store.go
StoreLog
func (b *BoltStore) StoreLog(log *raft.Log) error { return b.StoreLogs([]*raft.Log{log}) }
go
func (b *BoltStore) StoreLog(log *raft.Log) error { return b.StoreLogs([]*raft.Log{log}) }
[ "func", "(", "b", "*", "BoltStore", ")", "StoreLog", "(", "log", "*", "raft", ".", "Log", ")", "error", "{", "return", "b", ".", "StoreLogs", "(", "[", "]", "*", "raft", ".", "Log", "{", "log", "}", ")", "\n", "}" ]
// StoreLog is used to store a single raft log
[ "StoreLog", "is", "used", "to", "store", "a", "single", "raft", "log" ]
train
https://github.com/hashicorp/raft-boltdb/blob/6e5ba93211eaf8d9a2ad7e41ffad8c6f160f9fe3/bolt_store.go#L163-L165
hashicorp/raft-boltdb
bolt_store.go
StoreLogs
func (b *BoltStore) StoreLogs(logs []*raft.Log) error { tx, err := b.conn.Begin(true) if err != nil { return err } defer tx.Rollback() for _, log := range logs { key := uint64ToBytes(log.Index) val, err := encodeMsgPack(log) if err != nil { return err } bucket := tx.Bucket(dbLogs) if err := bucket.Put(key, val.Bytes()); err != nil { return err } } return tx.Commit() }
go
func (b *BoltStore) StoreLogs(logs []*raft.Log) error { tx, err := b.conn.Begin(true) if err != nil { return err } defer tx.Rollback() for _, log := range logs { key := uint64ToBytes(log.Index) val, err := encodeMsgPack(log) if err != nil { return err } bucket := tx.Bucket(dbLogs) if err := bucket.Put(key, val.Bytes()); err != nil { return err } } return tx.Commit() }
[ "func", "(", "b", "*", "BoltStore", ")", "StoreLogs", "(", "logs", "[", "]", "*", "raft", ".", "Log", ")", "error", "{", "tx", ",", "err", ":=", "b", ".", "conn", ".", "Begin", "(", "true", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "defer", "tx", ".", "Rollback", "(", ")", "\n\n", "for", "_", ",", "log", ":=", "range", "logs", "{", "key", ":=", "uint64ToBytes", "(", "log", ".", "Index", ")", "\n", "val", ",", "err", ":=", "encodeMsgPack", "(", "log", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "bucket", ":=", "tx", ".", "Bucket", "(", "dbLogs", ")", "\n", "if", "err", ":=", "bucket", ".", "Put", "(", "key", ",", "val", ".", "Bytes", "(", ")", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n\n", "return", "tx", ".", "Commit", "(", ")", "\n", "}" ]
// StoreLogs is used to store a set of raft logs
[ "StoreLogs", "is", "used", "to", "store", "a", "set", "of", "raft", "logs" ]
train
https://github.com/hashicorp/raft-boltdb/blob/6e5ba93211eaf8d9a2ad7e41ffad8c6f160f9fe3/bolt_store.go#L168-L188
hashicorp/raft-boltdb
bolt_store.go
DeleteRange
func (b *BoltStore) DeleteRange(min, max uint64) error { minKey := uint64ToBytes(min) tx, err := b.conn.Begin(true) if err != nil { return err } defer tx.Rollback() curs := tx.Bucket(dbLogs).Cursor() for k, _ := curs.Seek(minKey); k != nil; k, _ = curs.Next() { // Handle out-of-range log index if bytesToUint64(k) > max { break } // Delete in-range log index if err := curs.Delete(); err != nil { return err } } return tx.Commit() }
go
func (b *BoltStore) DeleteRange(min, max uint64) error { minKey := uint64ToBytes(min) tx, err := b.conn.Begin(true) if err != nil { return err } defer tx.Rollback() curs := tx.Bucket(dbLogs).Cursor() for k, _ := curs.Seek(minKey); k != nil; k, _ = curs.Next() { // Handle out-of-range log index if bytesToUint64(k) > max { break } // Delete in-range log index if err := curs.Delete(); err != nil { return err } } return tx.Commit() }
[ "func", "(", "b", "*", "BoltStore", ")", "DeleteRange", "(", "min", ",", "max", "uint64", ")", "error", "{", "minKey", ":=", "uint64ToBytes", "(", "min", ")", "\n\n", "tx", ",", "err", ":=", "b", ".", "conn", ".", "Begin", "(", "true", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "defer", "tx", ".", "Rollback", "(", ")", "\n\n", "curs", ":=", "tx", ".", "Bucket", "(", "dbLogs", ")", ".", "Cursor", "(", ")", "\n", "for", "k", ",", "_", ":=", "curs", ".", "Seek", "(", "minKey", ")", ";", "k", "!=", "nil", ";", "k", ",", "_", "=", "curs", ".", "Next", "(", ")", "{", "// Handle out-of-range log index", "if", "bytesToUint64", "(", "k", ")", ">", "max", "{", "break", "\n", "}", "\n\n", "// Delete in-range log index", "if", "err", ":=", "curs", ".", "Delete", "(", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n\n", "return", "tx", ".", "Commit", "(", ")", "\n", "}" ]
// DeleteRange is used to delete logs within a given range inclusively.
[ "DeleteRange", "is", "used", "to", "delete", "logs", "within", "a", "given", "range", "inclusively", "." ]
train
https://github.com/hashicorp/raft-boltdb/blob/6e5ba93211eaf8d9a2ad7e41ffad8c6f160f9fe3/bolt_store.go#L191-L214
hashicorp/raft-boltdb
bolt_store.go
Set
func (b *BoltStore) Set(k, v []byte) error { tx, err := b.conn.Begin(true) if err != nil { return err } defer tx.Rollback() bucket := tx.Bucket(dbConf) if err := bucket.Put(k, v); err != nil { return err } return tx.Commit() }
go
func (b *BoltStore) Set(k, v []byte) error { tx, err := b.conn.Begin(true) if err != nil { return err } defer tx.Rollback() bucket := tx.Bucket(dbConf) if err := bucket.Put(k, v); err != nil { return err } return tx.Commit() }
[ "func", "(", "b", "*", "BoltStore", ")", "Set", "(", "k", ",", "v", "[", "]", "byte", ")", "error", "{", "tx", ",", "err", ":=", "b", ".", "conn", ".", "Begin", "(", "true", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "defer", "tx", ".", "Rollback", "(", ")", "\n\n", "bucket", ":=", "tx", ".", "Bucket", "(", "dbConf", ")", "\n", "if", "err", ":=", "bucket", ".", "Put", "(", "k", ",", "v", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "return", "tx", ".", "Commit", "(", ")", "\n", "}" ]
// Set is used to set a key/value set outside of the raft log
[ "Set", "is", "used", "to", "set", "a", "key", "/", "value", "set", "outside", "of", "the", "raft", "log" ]
train
https://github.com/hashicorp/raft-boltdb/blob/6e5ba93211eaf8d9a2ad7e41ffad8c6f160f9fe3/bolt_store.go#L217-L230
hashicorp/raft-boltdb
bolt_store.go
Get
func (b *BoltStore) Get(k []byte) ([]byte, error) { tx, err := b.conn.Begin(false) if err != nil { return nil, err } defer tx.Rollback() bucket := tx.Bucket(dbConf) val := bucket.Get(k) if val == nil { return nil, ErrKeyNotFound } return append([]byte(nil), val...), nil }
go
func (b *BoltStore) Get(k []byte) ([]byte, error) { tx, err := b.conn.Begin(false) if err != nil { return nil, err } defer tx.Rollback() bucket := tx.Bucket(dbConf) val := bucket.Get(k) if val == nil { return nil, ErrKeyNotFound } return append([]byte(nil), val...), nil }
[ "func", "(", "b", "*", "BoltStore", ")", "Get", "(", "k", "[", "]", "byte", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "tx", ",", "err", ":=", "b", ".", "conn", ".", "Begin", "(", "false", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "defer", "tx", ".", "Rollback", "(", ")", "\n\n", "bucket", ":=", "tx", ".", "Bucket", "(", "dbConf", ")", "\n", "val", ":=", "bucket", ".", "Get", "(", "k", ")", "\n\n", "if", "val", "==", "nil", "{", "return", "nil", ",", "ErrKeyNotFound", "\n", "}", "\n", "return", "append", "(", "[", "]", "byte", "(", "nil", ")", ",", "val", "...", ")", ",", "nil", "\n", "}" ]
// Get is used to retrieve a value from the k/v store by key
[ "Get", "is", "used", "to", "retrieve", "a", "value", "from", "the", "k", "/", "v", "store", "by", "key" ]
train
https://github.com/hashicorp/raft-boltdb/blob/6e5ba93211eaf8d9a2ad7e41ffad8c6f160f9fe3/bolt_store.go#L233-L247
hashicorp/raft-boltdb
bolt_store.go
SetUint64
func (b *BoltStore) SetUint64(key []byte, val uint64) error { return b.Set(key, uint64ToBytes(val)) }
go
func (b *BoltStore) SetUint64(key []byte, val uint64) error { return b.Set(key, uint64ToBytes(val)) }
[ "func", "(", "b", "*", "BoltStore", ")", "SetUint64", "(", "key", "[", "]", "byte", ",", "val", "uint64", ")", "error", "{", "return", "b", ".", "Set", "(", "key", ",", "uint64ToBytes", "(", "val", ")", ")", "\n", "}" ]
// SetUint64 is like Set, but handles uint64 values
[ "SetUint64", "is", "like", "Set", "but", "handles", "uint64", "values" ]
train
https://github.com/hashicorp/raft-boltdb/blob/6e5ba93211eaf8d9a2ad7e41ffad8c6f160f9fe3/bolt_store.go#L250-L252
hashicorp/raft-boltdb
bolt_store.go
GetUint64
func (b *BoltStore) GetUint64(key []byte) (uint64, error) { val, err := b.Get(key) if err != nil { return 0, err } return bytesToUint64(val), nil }
go
func (b *BoltStore) GetUint64(key []byte) (uint64, error) { val, err := b.Get(key) if err != nil { return 0, err } return bytesToUint64(val), nil }
[ "func", "(", "b", "*", "BoltStore", ")", "GetUint64", "(", "key", "[", "]", "byte", ")", "(", "uint64", ",", "error", ")", "{", "val", ",", "err", ":=", "b", ".", "Get", "(", "key", ")", "\n", "if", "err", "!=", "nil", "{", "return", "0", ",", "err", "\n", "}", "\n", "return", "bytesToUint64", "(", "val", ")", ",", "nil", "\n", "}" ]
// GetUint64 is like Get, but handles uint64 values
[ "GetUint64", "is", "like", "Get", "but", "handles", "uint64", "values" ]
train
https://github.com/hashicorp/raft-boltdb/blob/6e5ba93211eaf8d9a2ad7e41ffad8c6f160f9fe3/bolt_store.go#L255-L261
mailgun/mailgun-go
domains.go
ListDomains
func (mg *MailgunImpl) ListDomains(opts *ListOptions) *DomainsIterator { var limit int if opts != nil { limit = opts.Limit } if limit == 0 { limit = 100 } return &DomainsIterator{ mg: mg, url: generatePublicApiUrl(mg, domainsEndpoint), domainsListResponse: domainsListResponse{TotalCount: -1}, limit: limit, } }
go
func (mg *MailgunImpl) ListDomains(opts *ListOptions) *DomainsIterator { var limit int if opts != nil { limit = opts.Limit } if limit == 0 { limit = 100 } return &DomainsIterator{ mg: mg, url: generatePublicApiUrl(mg, domainsEndpoint), domainsListResponse: domainsListResponse{TotalCount: -1}, limit: limit, } }
[ "func", "(", "mg", "*", "MailgunImpl", ")", "ListDomains", "(", "opts", "*", "ListOptions", ")", "*", "DomainsIterator", "{", "var", "limit", "int", "\n", "if", "opts", "!=", "nil", "{", "limit", "=", "opts", ".", "Limit", "\n", "}", "\n\n", "if", "limit", "==", "0", "{", "limit", "=", "100", "\n", "}", "\n", "return", "&", "DomainsIterator", "{", "mg", ":", "mg", ",", "url", ":", "generatePublicApiUrl", "(", "mg", ",", "domainsEndpoint", ")", ",", "domainsListResponse", ":", "domainsListResponse", "{", "TotalCount", ":", "-", "1", "}", ",", "limit", ":", "limit", ",", "}", "\n", "}" ]
// ListDomains retrieves a set of domains from Mailgun.
[ "ListDomains", "retrieves", "a", "set", "of", "domains", "from", "Mailgun", "." ]
train
https://github.com/mailgun/mailgun-go/blob/df421608b66e7dd4c03112d5bb01525c51f344a2/domains.go#L83-L98
mailgun/mailgun-go
domains.go
Next
func (ri *DomainsIterator) Next(ctx context.Context, items *[]Domain) bool { if ri.err != nil { return false } ri.err = ri.fetch(ctx, ri.offset, ri.limit) if ri.err != nil { return false } cpy := make([]Domain, len(ri.Items)) copy(cpy, ri.Items) *items = cpy if len(ri.Items) == 0 { return false } ri.offset = ri.offset + len(ri.Items) return true }
go
func (ri *DomainsIterator) Next(ctx context.Context, items *[]Domain) bool { if ri.err != nil { return false } ri.err = ri.fetch(ctx, ri.offset, ri.limit) if ri.err != nil { return false } cpy := make([]Domain, len(ri.Items)) copy(cpy, ri.Items) *items = cpy if len(ri.Items) == 0 { return false } ri.offset = ri.offset + len(ri.Items) return true }
[ "func", "(", "ri", "*", "DomainsIterator", ")", "Next", "(", "ctx", "context", ".", "Context", ",", "items", "*", "[", "]", "Domain", ")", "bool", "{", "if", "ri", ".", "err", "!=", "nil", "{", "return", "false", "\n", "}", "\n\n", "ri", ".", "err", "=", "ri", ".", "fetch", "(", "ctx", ",", "ri", ".", "offset", ",", "ri", ".", "limit", ")", "\n", "if", "ri", ".", "err", "!=", "nil", "{", "return", "false", "\n", "}", "\n\n", "cpy", ":=", "make", "(", "[", "]", "Domain", ",", "len", "(", "ri", ".", "Items", ")", ")", "\n", "copy", "(", "cpy", ",", "ri", ".", "Items", ")", "\n", "*", "items", "=", "cpy", "\n", "if", "len", "(", "ri", ".", "Items", ")", "==", "0", "{", "return", "false", "\n", "}", "\n", "ri", ".", "offset", "=", "ri", ".", "offset", "+", "len", "(", "ri", ".", "Items", ")", "\n", "return", "true", "\n", "}" ]
// Next retrieves the next page of items from the api. Returns false when there // no more pages to retrieve or if there was an error. Use `.Err()` to retrieve // the error
[ "Next", "retrieves", "the", "next", "page", "of", "items", "from", "the", "api", ".", "Returns", "false", "when", "there", "no", "more", "pages", "to", "retrieve", "or", "if", "there", "was", "an", "error", ".", "Use", ".", "Err", "()", "to", "retrieve", "the", "error" ]
train
https://github.com/mailgun/mailgun-go/blob/df421608b66e7dd4c03112d5bb01525c51f344a2/domains.go#L123-L141
mailgun/mailgun-go
domains.go
GetDomain
func (mg *MailgunImpl) GetDomain(ctx context.Context, domain string) (DomainResponse, error) { r := newHTTPRequest(generatePublicApiUrl(mg, domainsEndpoint) + "/" + domain) r.setClient(mg.Client()) r.setBasicAuth(basicAuthUser, mg.APIKey()) var resp DomainResponse err := getResponseFromJSON(ctx, r, &resp) return resp, err }
go
func (mg *MailgunImpl) GetDomain(ctx context.Context, domain string) (DomainResponse, error) { r := newHTTPRequest(generatePublicApiUrl(mg, domainsEndpoint) + "/" + domain) r.setClient(mg.Client()) r.setBasicAuth(basicAuthUser, mg.APIKey()) var resp DomainResponse err := getResponseFromJSON(ctx, r, &resp) return resp, err }
[ "func", "(", "mg", "*", "MailgunImpl", ")", "GetDomain", "(", "ctx", "context", ".", "Context", ",", "domain", "string", ")", "(", "DomainResponse", ",", "error", ")", "{", "r", ":=", "newHTTPRequest", "(", "generatePublicApiUrl", "(", "mg", ",", "domainsEndpoint", ")", "+", "\"", "\"", "+", "domain", ")", "\n", "r", ".", "setClient", "(", "mg", ".", "Client", "(", ")", ")", "\n", "r", ".", "setBasicAuth", "(", "basicAuthUser", ",", "mg", ".", "APIKey", "(", ")", ")", "\n", "var", "resp", "DomainResponse", "\n", "err", ":=", "getResponseFromJSON", "(", "ctx", ",", "r", ",", "&", "resp", ")", "\n", "return", "resp", ",", "err", "\n", "}" ]
// GetDomain retrieves detailed information about the named domain.
[ "GetDomain", "retrieves", "detailed", "information", "about", "the", "named", "domain", "." ]
train
https://github.com/mailgun/mailgun-go/blob/df421608b66e7dd4c03112d5bb01525c51f344a2/domains.go#L235-L242
mailgun/mailgun-go
domains.go
CreateDomain
func (mg *MailgunImpl) CreateDomain(ctx context.Context, name string, opts *CreateDomainOptions) (DomainResponse, error) { r := newHTTPRequest(generatePublicApiUrl(mg, domainsEndpoint)) r.setClient(mg.Client()) r.setBasicAuth(basicAuthUser, mg.APIKey()) payload := newUrlEncodedPayload() payload.addValue("name", name) if opts != nil { if opts.SpamAction != "" { payload.addValue("spam_action", string(opts.SpamAction)) } if opts.Wildcard { payload.addValue("wildcard", boolToString(opts.Wildcard)) } if opts.ForceDKIMAuthority { payload.addValue("force_dkim_authority", boolToString(opts.ForceDKIMAuthority)) } if opts.DKIMKeySize != 0 { payload.addValue("dkim_key_size", strconv.Itoa(opts.DKIMKeySize)) } if len(opts.IPS) != 0 { payload.addValue("ips", strings.Join(opts.IPS, ",")) } if len(opts.Password) != 0 { payload.addValue("smtp_password", opts.Password) } } var resp DomainResponse err := postResponseFromJSON(ctx, r, payload, &resp) return resp, err }
go
func (mg *MailgunImpl) CreateDomain(ctx context.Context, name string, opts *CreateDomainOptions) (DomainResponse, error) { r := newHTTPRequest(generatePublicApiUrl(mg, domainsEndpoint)) r.setClient(mg.Client()) r.setBasicAuth(basicAuthUser, mg.APIKey()) payload := newUrlEncodedPayload() payload.addValue("name", name) if opts != nil { if opts.SpamAction != "" { payload.addValue("spam_action", string(opts.SpamAction)) } if opts.Wildcard { payload.addValue("wildcard", boolToString(opts.Wildcard)) } if opts.ForceDKIMAuthority { payload.addValue("force_dkim_authority", boolToString(opts.ForceDKIMAuthority)) } if opts.DKIMKeySize != 0 { payload.addValue("dkim_key_size", strconv.Itoa(opts.DKIMKeySize)) } if len(opts.IPS) != 0 { payload.addValue("ips", strings.Join(opts.IPS, ",")) } if len(opts.Password) != 0 { payload.addValue("smtp_password", opts.Password) } } var resp DomainResponse err := postResponseFromJSON(ctx, r, payload, &resp) return resp, err }
[ "func", "(", "mg", "*", "MailgunImpl", ")", "CreateDomain", "(", "ctx", "context", ".", "Context", ",", "name", "string", ",", "opts", "*", "CreateDomainOptions", ")", "(", "DomainResponse", ",", "error", ")", "{", "r", ":=", "newHTTPRequest", "(", "generatePublicApiUrl", "(", "mg", ",", "domainsEndpoint", ")", ")", "\n", "r", ".", "setClient", "(", "mg", ".", "Client", "(", ")", ")", "\n", "r", ".", "setBasicAuth", "(", "basicAuthUser", ",", "mg", ".", "APIKey", "(", ")", ")", "\n\n", "payload", ":=", "newUrlEncodedPayload", "(", ")", "\n", "payload", ".", "addValue", "(", "\"", "\"", ",", "name", ")", "\n\n", "if", "opts", "!=", "nil", "{", "if", "opts", ".", "SpamAction", "!=", "\"", "\"", "{", "payload", ".", "addValue", "(", "\"", "\"", ",", "string", "(", "opts", ".", "SpamAction", ")", ")", "\n", "}", "\n", "if", "opts", ".", "Wildcard", "{", "payload", ".", "addValue", "(", "\"", "\"", ",", "boolToString", "(", "opts", ".", "Wildcard", ")", ")", "\n", "}", "\n", "if", "opts", ".", "ForceDKIMAuthority", "{", "payload", ".", "addValue", "(", "\"", "\"", ",", "boolToString", "(", "opts", ".", "ForceDKIMAuthority", ")", ")", "\n", "}", "\n", "if", "opts", ".", "DKIMKeySize", "!=", "0", "{", "payload", ".", "addValue", "(", "\"", "\"", ",", "strconv", ".", "Itoa", "(", "opts", ".", "DKIMKeySize", ")", ")", "\n", "}", "\n", "if", "len", "(", "opts", ".", "IPS", ")", "!=", "0", "{", "payload", ".", "addValue", "(", "\"", "\"", ",", "strings", ".", "Join", "(", "opts", ".", "IPS", ",", "\"", "\"", ")", ")", "\n", "}", "\n", "if", "len", "(", "opts", ".", "Password", ")", "!=", "0", "{", "payload", ".", "addValue", "(", "\"", "\"", ",", "opts", ".", "Password", ")", "\n", "}", "\n", "}", "\n", "var", "resp", "DomainResponse", "\n", "err", ":=", "postResponseFromJSON", "(", "ctx", ",", "r", ",", "payload", ",", "&", "resp", ")", "\n", "return", "resp", ",", "err", "\n", "}" ]
// CreateDomain instructs Mailgun to create a new domain for your account. // The name parameter identifies the domain. // The smtpPassword parameter provides an access credential for the domain. // The spamAction domain must be one of Delete, Tag, or Disabled. // The wildcard parameter instructs Mailgun to treat all subdomains of this domain uniformly if true, // and as different domains if false.
[ "CreateDomain", "instructs", "Mailgun", "to", "create", "a", "new", "domain", "for", "your", "account", ".", "The", "name", "parameter", "identifies", "the", "domain", ".", "The", "smtpPassword", "parameter", "provides", "an", "access", "credential", "for", "the", "domain", ".", "The", "spamAction", "domain", "must", "be", "one", "of", "Delete", "Tag", "or", "Disabled", ".", "The", "wildcard", "parameter", "instructs", "Mailgun", "to", "treat", "all", "subdomains", "of", "this", "domain", "uniformly", "if", "true", "and", "as", "different", "domains", "if", "false", "." ]
train
https://github.com/mailgun/mailgun-go/blob/df421608b66e7dd4c03112d5bb01525c51f344a2/domains.go#L271-L302
mailgun/mailgun-go
domains.go
GetDomainConnection
func (mg *MailgunImpl) GetDomainConnection(ctx context.Context, domain string) (DomainConnection, error) { r := newHTTPRequest(generatePublicApiUrl(mg, domainsEndpoint) + "/" + domain + "/connection") r.setClient(mg.Client()) r.setBasicAuth(basicAuthUser, mg.APIKey()) var resp domainConnectionResponse err := getResponseFromJSON(ctx, r, &resp) return resp.Connection, err }
go
func (mg *MailgunImpl) GetDomainConnection(ctx context.Context, domain string) (DomainConnection, error) { r := newHTTPRequest(generatePublicApiUrl(mg, domainsEndpoint) + "/" + domain + "/connection") r.setClient(mg.Client()) r.setBasicAuth(basicAuthUser, mg.APIKey()) var resp domainConnectionResponse err := getResponseFromJSON(ctx, r, &resp) return resp.Connection, err }
[ "func", "(", "mg", "*", "MailgunImpl", ")", "GetDomainConnection", "(", "ctx", "context", ".", "Context", ",", "domain", "string", ")", "(", "DomainConnection", ",", "error", ")", "{", "r", ":=", "newHTTPRequest", "(", "generatePublicApiUrl", "(", "mg", ",", "domainsEndpoint", ")", "+", "\"", "\"", "+", "domain", "+", "\"", "\"", ")", "\n", "r", ".", "setClient", "(", "mg", ".", "Client", "(", ")", ")", "\n", "r", ".", "setBasicAuth", "(", "basicAuthUser", ",", "mg", ".", "APIKey", "(", ")", ")", "\n", "var", "resp", "domainConnectionResponse", "\n", "err", ":=", "getResponseFromJSON", "(", "ctx", ",", "r", ",", "&", "resp", ")", "\n", "return", "resp", ".", "Connection", ",", "err", "\n", "}" ]
// GetDomainConnection returns delivery connection settings for the defined domain
[ "GetDomainConnection", "returns", "delivery", "connection", "settings", "for", "the", "defined", "domain" ]
train
https://github.com/mailgun/mailgun-go/blob/df421608b66e7dd4c03112d5bb01525c51f344a2/domains.go#L305-L312
mailgun/mailgun-go
domains.go
UpdateDomainConnection
func (mg *MailgunImpl) UpdateDomainConnection(ctx context.Context, domain string, settings DomainConnection) error { r := newHTTPRequest(generatePublicApiUrl(mg, domainsEndpoint) + "/" + domain + "/connection") r.setClient(mg.Client()) r.setBasicAuth(basicAuthUser, mg.APIKey()) payload := newUrlEncodedPayload() payload.addValue("require_tls", boolToString(settings.RequireTLS)) payload.addValue("skip_verification", boolToString(settings.SkipVerification)) _, err := makePutRequest(ctx, r, payload) return err }
go
func (mg *MailgunImpl) UpdateDomainConnection(ctx context.Context, domain string, settings DomainConnection) error { r := newHTTPRequest(generatePublicApiUrl(mg, domainsEndpoint) + "/" + domain + "/connection") r.setClient(mg.Client()) r.setBasicAuth(basicAuthUser, mg.APIKey()) payload := newUrlEncodedPayload() payload.addValue("require_tls", boolToString(settings.RequireTLS)) payload.addValue("skip_verification", boolToString(settings.SkipVerification)) _, err := makePutRequest(ctx, r, payload) return err }
[ "func", "(", "mg", "*", "MailgunImpl", ")", "UpdateDomainConnection", "(", "ctx", "context", ".", "Context", ",", "domain", "string", ",", "settings", "DomainConnection", ")", "error", "{", "r", ":=", "newHTTPRequest", "(", "generatePublicApiUrl", "(", "mg", ",", "domainsEndpoint", ")", "+", "\"", "\"", "+", "domain", "+", "\"", "\"", ")", "\n", "r", ".", "setClient", "(", "mg", ".", "Client", "(", ")", ")", "\n", "r", ".", "setBasicAuth", "(", "basicAuthUser", ",", "mg", ".", "APIKey", "(", ")", ")", "\n\n", "payload", ":=", "newUrlEncodedPayload", "(", ")", "\n", "payload", ".", "addValue", "(", "\"", "\"", ",", "boolToString", "(", "settings", ".", "RequireTLS", ")", ")", "\n", "payload", ".", "addValue", "(", "\"", "\"", ",", "boolToString", "(", "settings", ".", "SkipVerification", ")", ")", "\n", "_", ",", "err", ":=", "makePutRequest", "(", "ctx", ",", "r", ",", "payload", ")", "\n", "return", "err", "\n", "}" ]
// Updates the specified delivery connection settings for the defined domain
[ "Updates", "the", "specified", "delivery", "connection", "settings", "for", "the", "defined", "domain" ]
train
https://github.com/mailgun/mailgun-go/blob/df421608b66e7dd4c03112d5bb01525c51f344a2/domains.go#L315-L325
mailgun/mailgun-go
domains.go
DeleteDomain
func (mg *MailgunImpl) DeleteDomain(ctx context.Context, name string) error { r := newHTTPRequest(generatePublicApiUrl(mg, domainsEndpoint) + "/" + name) r.setClient(mg.Client()) r.setBasicAuth(basicAuthUser, mg.APIKey()) _, err := makeDeleteRequest(ctx, r) return err }
go
func (mg *MailgunImpl) DeleteDomain(ctx context.Context, name string) error { r := newHTTPRequest(generatePublicApiUrl(mg, domainsEndpoint) + "/" + name) r.setClient(mg.Client()) r.setBasicAuth(basicAuthUser, mg.APIKey()) _, err := makeDeleteRequest(ctx, r) return err }
[ "func", "(", "mg", "*", "MailgunImpl", ")", "DeleteDomain", "(", "ctx", "context", ".", "Context", ",", "name", "string", ")", "error", "{", "r", ":=", "newHTTPRequest", "(", "generatePublicApiUrl", "(", "mg", ",", "domainsEndpoint", ")", "+", "\"", "\"", "+", "name", ")", "\n", "r", ".", "setClient", "(", "mg", ".", "Client", "(", ")", ")", "\n", "r", ".", "setBasicAuth", "(", "basicAuthUser", ",", "mg", ".", "APIKey", "(", ")", ")", "\n", "_", ",", "err", ":=", "makeDeleteRequest", "(", "ctx", ",", "r", ")", "\n", "return", "err", "\n", "}" ]
// DeleteDomain instructs Mailgun to dispose of the named domain name
[ "DeleteDomain", "instructs", "Mailgun", "to", "dispose", "of", "the", "named", "domain", "name" ]
train
https://github.com/mailgun/mailgun-go/blob/df421608b66e7dd4c03112d5bb01525c51f344a2/domains.go#L328-L334
mailgun/mailgun-go
domains.go
GetDomainTracking
func (mg *MailgunImpl) GetDomainTracking(ctx context.Context, domain string) (DomainTracking, error) { r := newHTTPRequest(generatePublicApiUrl(mg, domainsEndpoint) + "/" + domain + "/tracking") r.setClient(mg.Client()) r.setBasicAuth(basicAuthUser, mg.APIKey()) var resp domainTrackingResponse err := getResponseFromJSON(ctx, r, &resp) return resp.Tracking, err }
go
func (mg *MailgunImpl) GetDomainTracking(ctx context.Context, domain string) (DomainTracking, error) { r := newHTTPRequest(generatePublicApiUrl(mg, domainsEndpoint) + "/" + domain + "/tracking") r.setClient(mg.Client()) r.setBasicAuth(basicAuthUser, mg.APIKey()) var resp domainTrackingResponse err := getResponseFromJSON(ctx, r, &resp) return resp.Tracking, err }
[ "func", "(", "mg", "*", "MailgunImpl", ")", "GetDomainTracking", "(", "ctx", "context", ".", "Context", ",", "domain", "string", ")", "(", "DomainTracking", ",", "error", ")", "{", "r", ":=", "newHTTPRequest", "(", "generatePublicApiUrl", "(", "mg", ",", "domainsEndpoint", ")", "+", "\"", "\"", "+", "domain", "+", "\"", "\"", ")", "\n", "r", ".", "setClient", "(", "mg", ".", "Client", "(", ")", ")", "\n", "r", ".", "setBasicAuth", "(", "basicAuthUser", ",", "mg", ".", "APIKey", "(", ")", ")", "\n", "var", "resp", "domainTrackingResponse", "\n", "err", ":=", "getResponseFromJSON", "(", "ctx", ",", "r", ",", "&", "resp", ")", "\n", "return", "resp", ".", "Tracking", ",", "err", "\n", "}" ]
// GetDomainTracking returns tracking settings for a domain
[ "GetDomainTracking", "returns", "tracking", "settings", "for", "a", "domain" ]
train
https://github.com/mailgun/mailgun-go/blob/df421608b66e7dd4c03112d5bb01525c51f344a2/domains.go#L337-L344
mailgun/mailgun-go
email_validation.go
NewEmailValidator
func NewEmailValidator(apiKey string) *EmailValidatorImpl { isPublicKey := false // Did the user pass in a public key? if strings.HasPrefix(apiKey, "pubkey-") { isPublicKey = true } return &EmailValidatorImpl{ client: http.DefaultClient, isPublicKey: isPublicKey, apiBase: APIBase, apiKey: apiKey, } }
go
func NewEmailValidator(apiKey string) *EmailValidatorImpl { isPublicKey := false // Did the user pass in a public key? if strings.HasPrefix(apiKey, "pubkey-") { isPublicKey = true } return &EmailValidatorImpl{ client: http.DefaultClient, isPublicKey: isPublicKey, apiBase: APIBase, apiKey: apiKey, } }
[ "func", "NewEmailValidator", "(", "apiKey", "string", ")", "*", "EmailValidatorImpl", "{", "isPublicKey", ":=", "false", "\n\n", "// Did the user pass in a public key?", "if", "strings", ".", "HasPrefix", "(", "apiKey", ",", "\"", "\"", ")", "{", "isPublicKey", "=", "true", "\n", "}", "\n\n", "return", "&", "EmailValidatorImpl", "{", "client", ":", "http", ".", "DefaultClient", ",", "isPublicKey", ":", "isPublicKey", ",", "apiBase", ":", "APIBase", ",", "apiKey", ":", "apiKey", ",", "}", "\n", "}" ]
// Creates a new validation instance. // * If a public key is provided, uses the public validation endpoints // * If a private key is provided, uses the private validation endpoints
[ "Creates", "a", "new", "validation", "instance", ".", "*", "If", "a", "public", "key", "is", "provided", "uses", "the", "public", "validation", "endpoints", "*", "If", "a", "private", "key", "is", "provided", "uses", "the", "private", "validation", "endpoints" ]
train
https://github.com/mailgun/mailgun-go/blob/df421608b66e7dd4c03112d5bb01525c51f344a2/email_validation.go#L68-L82
mailgun/mailgun-go
email_validation.go
NewEmailValidatorFromEnv
func NewEmailValidatorFromEnv() (*EmailValidatorImpl, error) { apiKey := os.Getenv("MG_PUBLIC_API_KEY") if apiKey == "" { apiKey = os.Getenv("MG_API_KEY") if apiKey == "" { return nil, errors.New( "environment variable MG_PUBLIC_API_KEY or MG_API_KEY required for email validation") } } v := NewEmailValidator(apiKey) url := os.Getenv("MG_URL") if url != "" { v.SetAPIBase(url) } return v, nil }
go
func NewEmailValidatorFromEnv() (*EmailValidatorImpl, error) { apiKey := os.Getenv("MG_PUBLIC_API_KEY") if apiKey == "" { apiKey = os.Getenv("MG_API_KEY") if apiKey == "" { return nil, errors.New( "environment variable MG_PUBLIC_API_KEY or MG_API_KEY required for email validation") } } v := NewEmailValidator(apiKey) url := os.Getenv("MG_URL") if url != "" { v.SetAPIBase(url) } return v, nil }
[ "func", "NewEmailValidatorFromEnv", "(", ")", "(", "*", "EmailValidatorImpl", ",", "error", ")", "{", "apiKey", ":=", "os", ".", "Getenv", "(", "\"", "\"", ")", "\n", "if", "apiKey", "==", "\"", "\"", "{", "apiKey", "=", "os", ".", "Getenv", "(", "\"", "\"", ")", "\n", "if", "apiKey", "==", "\"", "\"", "{", "return", "nil", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n", "}", "\n", "v", ":=", "NewEmailValidator", "(", "apiKey", ")", "\n", "url", ":=", "os", ".", "Getenv", "(", "\"", "\"", ")", "\n", "if", "url", "!=", "\"", "\"", "{", "v", ".", "SetAPIBase", "(", "url", ")", "\n", "}", "\n", "return", "v", ",", "nil", "\n", "}" ]
// NewEmailValidatorFromEnv returns a new EmailValidator using environment variables // If MG_PUBLIC_API_KEY is set, assume using the free validation subject to daily usage limits // If only MG_API_KEY is set, assume using the /private validation routes with no daily usage limits
[ "NewEmailValidatorFromEnv", "returns", "a", "new", "EmailValidator", "using", "environment", "variables", "If", "MG_PUBLIC_API_KEY", "is", "set", "assume", "using", "the", "free", "validation", "subject", "to", "daily", "usage", "limits", "If", "only", "MG_API_KEY", "is", "set", "assume", "using", "the", "/", "private", "validation", "routes", "with", "no", "daily", "usage", "limits" ]
train
https://github.com/mailgun/mailgun-go/blob/df421608b66e7dd4c03112d5bb01525c51f344a2/email_validation.go#L87-L102
mailgun/mailgun-go
email_validation.go
ValidateEmail
func (m *EmailValidatorImpl) ValidateEmail(ctx context.Context, email string, mailBoxVerify bool) (EmailVerification, error) { r := newHTTPRequest(m.getAddressURL("validate")) r.setClient(m.Client()) r.addParameter("address", email) if mailBoxVerify { r.addParameter("mailbox_verification", "true") } r.setBasicAuth(basicAuthUser, m.APIKey()) var response EmailVerification err := getResponseFromJSON(ctx, r, &response) if err != nil { return EmailVerification{}, err } return response, nil }
go
func (m *EmailValidatorImpl) ValidateEmail(ctx context.Context, email string, mailBoxVerify bool) (EmailVerification, error) { r := newHTTPRequest(m.getAddressURL("validate")) r.setClient(m.Client()) r.addParameter("address", email) if mailBoxVerify { r.addParameter("mailbox_verification", "true") } r.setBasicAuth(basicAuthUser, m.APIKey()) var response EmailVerification err := getResponseFromJSON(ctx, r, &response) if err != nil { return EmailVerification{}, err } return response, nil }
[ "func", "(", "m", "*", "EmailValidatorImpl", ")", "ValidateEmail", "(", "ctx", "context", ".", "Context", ",", "email", "string", ",", "mailBoxVerify", "bool", ")", "(", "EmailVerification", ",", "error", ")", "{", "r", ":=", "newHTTPRequest", "(", "m", ".", "getAddressURL", "(", "\"", "\"", ")", ")", "\n", "r", ".", "setClient", "(", "m", ".", "Client", "(", ")", ")", "\n", "r", ".", "addParameter", "(", "\"", "\"", ",", "email", ")", "\n", "if", "mailBoxVerify", "{", "r", ".", "addParameter", "(", "\"", "\"", ",", "\"", "\"", ")", "\n", "}", "\n", "r", ".", "setBasicAuth", "(", "basicAuthUser", ",", "m", ".", "APIKey", "(", ")", ")", "\n\n", "var", "response", "EmailVerification", "\n", "err", ":=", "getResponseFromJSON", "(", "ctx", ",", "r", ",", "&", "response", ")", "\n", "if", "err", "!=", "nil", "{", "return", "EmailVerification", "{", "}", ",", "err", "\n", "}", "\n\n", "return", "response", ",", "nil", "\n", "}" ]
// ValidateEmail performs various checks on the email address provided to ensure it's correctly formatted. // It may also be used to break an email address into its sub-components. (See example.)
[ "ValidateEmail", "performs", "various", "checks", "on", "the", "email", "address", "provided", "to", "ensure", "it", "s", "correctly", "formatted", ".", "It", "may", "also", "be", "used", "to", "break", "an", "email", "address", "into", "its", "sub", "-", "components", ".", "(", "See", "example", ".", ")" ]
train
https://github.com/mailgun/mailgun-go/blob/df421608b66e7dd4c03112d5bb01525c51f344a2/email_validation.go#L138-L154
mailgun/mailgun-go
email_validation.go
ParseAddresses
func (m *EmailValidatorImpl) ParseAddresses(ctx context.Context, addresses ...string) ([]string, []string, error) { r := newHTTPRequest(m.getAddressURL("parse")) r.setClient(m.Client()) r.addParameter("addresses", strings.Join(addresses, ",")) r.setBasicAuth(basicAuthUser, m.APIKey()) var response addressParseResult err := getResponseFromJSON(ctx, r, &response) if err != nil { return nil, nil, err } return response.Parsed, response.Unparseable, nil }
go
func (m *EmailValidatorImpl) ParseAddresses(ctx context.Context, addresses ...string) ([]string, []string, error) { r := newHTTPRequest(m.getAddressURL("parse")) r.setClient(m.Client()) r.addParameter("addresses", strings.Join(addresses, ",")) r.setBasicAuth(basicAuthUser, m.APIKey()) var response addressParseResult err := getResponseFromJSON(ctx, r, &response) if err != nil { return nil, nil, err } return response.Parsed, response.Unparseable, nil }
[ "func", "(", "m", "*", "EmailValidatorImpl", ")", "ParseAddresses", "(", "ctx", "context", ".", "Context", ",", "addresses", "...", "string", ")", "(", "[", "]", "string", ",", "[", "]", "string", ",", "error", ")", "{", "r", ":=", "newHTTPRequest", "(", "m", ".", "getAddressURL", "(", "\"", "\"", ")", ")", "\n", "r", ".", "setClient", "(", "m", ".", "Client", "(", ")", ")", "\n", "r", ".", "addParameter", "(", "\"", "\"", ",", "strings", ".", "Join", "(", "addresses", ",", "\"", "\"", ")", ")", "\n", "r", ".", "setBasicAuth", "(", "basicAuthUser", ",", "m", ".", "APIKey", "(", ")", ")", "\n\n", "var", "response", "addressParseResult", "\n", "err", ":=", "getResponseFromJSON", "(", "ctx", ",", "r", ",", "&", "response", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "nil", ",", "err", "\n", "}", "\n\n", "return", "response", ".", "Parsed", ",", "response", ".", "Unparseable", ",", "nil", "\n", "}" ]
// ParseAddresses takes a list of addresses and sorts them into valid and invalid address categories. // NOTE: Use of this function requires a proper public API key. The private API key will not work.
[ "ParseAddresses", "takes", "a", "list", "of", "addresses", "and", "sorts", "them", "into", "valid", "and", "invalid", "address", "categories", ".", "NOTE", ":", "Use", "of", "this", "function", "requires", "a", "proper", "public", "API", "key", ".", "The", "private", "API", "key", "will", "not", "work", "." ]
train
https://github.com/mailgun/mailgun-go/blob/df421608b66e7dd4c03112d5bb01525c51f344a2/email_validation.go#L158-L171
mailgun/mailgun-go
webhooks.go
ListWebhooks
func (mg *MailgunImpl) ListWebhooks(ctx context.Context) (map[string]string, error) { r := newHTTPRequest(generateDomainApiUrl(mg, webhooksEndpoint)) r.setClient(mg.Client()) r.setBasicAuth(basicAuthUser, mg.APIKey()) var envelope struct { Webhooks map[string]interface{} `json:"webhooks"` } err := getResponseFromJSON(ctx, r, &envelope) hooks := make(map[string]string, 0) if err != nil { return hooks, err } for k, v := range envelope.Webhooks { object := v.(map[string]interface{}) url := object["url"] hooks[k] = url.(string) } return hooks, nil }
go
func (mg *MailgunImpl) ListWebhooks(ctx context.Context) (map[string]string, error) { r := newHTTPRequest(generateDomainApiUrl(mg, webhooksEndpoint)) r.setClient(mg.Client()) r.setBasicAuth(basicAuthUser, mg.APIKey()) var envelope struct { Webhooks map[string]interface{} `json:"webhooks"` } err := getResponseFromJSON(ctx, r, &envelope) hooks := make(map[string]string, 0) if err != nil { return hooks, err } for k, v := range envelope.Webhooks { object := v.(map[string]interface{}) url := object["url"] hooks[k] = url.(string) } return hooks, nil }
[ "func", "(", "mg", "*", "MailgunImpl", ")", "ListWebhooks", "(", "ctx", "context", ".", "Context", ")", "(", "map", "[", "string", "]", "string", ",", "error", ")", "{", "r", ":=", "newHTTPRequest", "(", "generateDomainApiUrl", "(", "mg", ",", "webhooksEndpoint", ")", ")", "\n", "r", ".", "setClient", "(", "mg", ".", "Client", "(", ")", ")", "\n", "r", ".", "setBasicAuth", "(", "basicAuthUser", ",", "mg", ".", "APIKey", "(", ")", ")", "\n", "var", "envelope", "struct", "{", "Webhooks", "map", "[", "string", "]", "interface", "{", "}", "`json:\"webhooks\"`", "\n", "}", "\n", "err", ":=", "getResponseFromJSON", "(", "ctx", ",", "r", ",", "&", "envelope", ")", "\n", "hooks", ":=", "make", "(", "map", "[", "string", "]", "string", ",", "0", ")", "\n", "if", "err", "!=", "nil", "{", "return", "hooks", ",", "err", "\n", "}", "\n", "for", "k", ",", "v", ":=", "range", "envelope", ".", "Webhooks", "{", "object", ":=", "v", ".", "(", "map", "[", "string", "]", "interface", "{", "}", ")", "\n", "url", ":=", "object", "[", "\"", "\"", "]", "\n", "hooks", "[", "k", "]", "=", "url", ".", "(", "string", ")", "\n", "}", "\n", "return", "hooks", ",", "nil", "\n", "}" ]
// ListWebhooks returns the complete set of webhooks configured for your domain. // Note that a zero-length mapping is not an error.
[ "ListWebhooks", "returns", "the", "complete", "set", "of", "webhooks", "configured", "for", "your", "domain", ".", "Note", "that", "a", "zero", "-", "length", "mapping", "is", "not", "an", "error", "." ]
train
https://github.com/mailgun/mailgun-go/blob/df421608b66e7dd4c03112d5bb01525c51f344a2/webhooks.go#L17-L35
mailgun/mailgun-go
webhooks.go
DeleteWebhook
func (mg *MailgunImpl) DeleteWebhook(ctx context.Context, t string) error { r := newHTTPRequest(generateDomainApiUrl(mg, webhooksEndpoint) + "/" + t) r.setClient(mg.Client()) r.setBasicAuth(basicAuthUser, mg.APIKey()) _, err := makeDeleteRequest(ctx, r) return err }
go
func (mg *MailgunImpl) DeleteWebhook(ctx context.Context, t string) error { r := newHTTPRequest(generateDomainApiUrl(mg, webhooksEndpoint) + "/" + t) r.setClient(mg.Client()) r.setBasicAuth(basicAuthUser, mg.APIKey()) _, err := makeDeleteRequest(ctx, r) return err }
[ "func", "(", "mg", "*", "MailgunImpl", ")", "DeleteWebhook", "(", "ctx", "context", ".", "Context", ",", "t", "string", ")", "error", "{", "r", ":=", "newHTTPRequest", "(", "generateDomainApiUrl", "(", "mg", ",", "webhooksEndpoint", ")", "+", "\"", "\"", "+", "t", ")", "\n", "r", ".", "setClient", "(", "mg", ".", "Client", "(", ")", ")", "\n", "r", ".", "setBasicAuth", "(", "basicAuthUser", ",", "mg", ".", "APIKey", "(", ")", ")", "\n", "_", ",", "err", ":=", "makeDeleteRequest", "(", "ctx", ",", "r", ")", "\n", "return", "err", "\n", "}" ]
// DeleteWebhook removes the specified webhook from your domain's configuration.
[ "DeleteWebhook", "removes", "the", "specified", "webhook", "from", "your", "domain", "s", "configuration", "." ]
train
https://github.com/mailgun/mailgun-go/blob/df421608b66e7dd4c03112d5bb01525c51f344a2/webhooks.go#L52-L58
mailgun/mailgun-go
webhooks.go
GetWebhook
func (mg *MailgunImpl) GetWebhook(ctx context.Context, t string) (string, error) { r := newHTTPRequest(generateDomainApiUrl(mg, webhooksEndpoint) + "/" + t) r.setClient(mg.Client()) r.setBasicAuth(basicAuthUser, mg.APIKey()) var envelope struct { Webhook struct { Url string `json:"url"` } `json:"webhook"` } err := getResponseFromJSON(ctx, r, &envelope) return envelope.Webhook.Url, err }
go
func (mg *MailgunImpl) GetWebhook(ctx context.Context, t string) (string, error) { r := newHTTPRequest(generateDomainApiUrl(mg, webhooksEndpoint) + "/" + t) r.setClient(mg.Client()) r.setBasicAuth(basicAuthUser, mg.APIKey()) var envelope struct { Webhook struct { Url string `json:"url"` } `json:"webhook"` } err := getResponseFromJSON(ctx, r, &envelope) return envelope.Webhook.Url, err }
[ "func", "(", "mg", "*", "MailgunImpl", ")", "GetWebhook", "(", "ctx", "context", ".", "Context", ",", "t", "string", ")", "(", "string", ",", "error", ")", "{", "r", ":=", "newHTTPRequest", "(", "generateDomainApiUrl", "(", "mg", ",", "webhooksEndpoint", ")", "+", "\"", "\"", "+", "t", ")", "\n", "r", ".", "setClient", "(", "mg", ".", "Client", "(", ")", ")", "\n", "r", ".", "setBasicAuth", "(", "basicAuthUser", ",", "mg", ".", "APIKey", "(", ")", ")", "\n", "var", "envelope", "struct", "{", "Webhook", "struct", "{", "Url", "string", "`json:\"url\"`", "\n", "}", "`json:\"webhook\"`", "\n", "}", "\n", "err", ":=", "getResponseFromJSON", "(", "ctx", ",", "r", ",", "&", "envelope", ")", "\n", "return", "envelope", ".", "Webhook", ".", "Url", ",", "err", "\n", "}" ]
// GetWebhook retrieves the currently assigned webhook URL associated with the provided type of webhook.
[ "GetWebhook", "retrieves", "the", "currently", "assigned", "webhook", "URL", "associated", "with", "the", "provided", "type", "of", "webhook", "." ]
train
https://github.com/mailgun/mailgun-go/blob/df421608b66e7dd4c03112d5bb01525c51f344a2/webhooks.go#L61-L72
mailgun/mailgun-go
webhooks.go
UpdateWebhook
func (mg *MailgunImpl) UpdateWebhook(ctx context.Context, t string, urls []string) error { r := newHTTPRequest(generateDomainApiUrl(mg, webhooksEndpoint) + "/" + t) r.setClient(mg.Client()) r.setBasicAuth(basicAuthUser, mg.APIKey()) p := newUrlEncodedPayload() for _, url := range urls { p.addValue("url", url) } _, err := makePutRequest(ctx, r, p) return err }
go
func (mg *MailgunImpl) UpdateWebhook(ctx context.Context, t string, urls []string) error { r := newHTTPRequest(generateDomainApiUrl(mg, webhooksEndpoint) + "/" + t) r.setClient(mg.Client()) r.setBasicAuth(basicAuthUser, mg.APIKey()) p := newUrlEncodedPayload() for _, url := range urls { p.addValue("url", url) } _, err := makePutRequest(ctx, r, p) return err }
[ "func", "(", "mg", "*", "MailgunImpl", ")", "UpdateWebhook", "(", "ctx", "context", ".", "Context", ",", "t", "string", ",", "urls", "[", "]", "string", ")", "error", "{", "r", ":=", "newHTTPRequest", "(", "generateDomainApiUrl", "(", "mg", ",", "webhooksEndpoint", ")", "+", "\"", "\"", "+", "t", ")", "\n", "r", ".", "setClient", "(", "mg", ".", "Client", "(", ")", ")", "\n", "r", ".", "setBasicAuth", "(", "basicAuthUser", ",", "mg", ".", "APIKey", "(", ")", ")", "\n", "p", ":=", "newUrlEncodedPayload", "(", ")", "\n", "for", "_", ",", "url", ":=", "range", "urls", "{", "p", ".", "addValue", "(", "\"", "\"", ",", "url", ")", "\n", "}", "\n", "_", ",", "err", ":=", "makePutRequest", "(", "ctx", ",", "r", ",", "p", ")", "\n", "return", "err", "\n", "}" ]
// UpdateWebhook replaces one webhook setting for another.
[ "UpdateWebhook", "replaces", "one", "webhook", "setting", "for", "another", "." ]
train
https://github.com/mailgun/mailgun-go/blob/df421608b66e7dd4c03112d5bb01525c51f344a2/webhooks.go#L75-L85
mailgun/mailgun-go
webhooks.go
VerifyWebhookSignature
func (mg *MailgunImpl) VerifyWebhookSignature(sig Signature) (verified bool, err error) { h := hmac.New(sha256.New, []byte(mg.APIKey())) io.WriteString(h, sig.TimeStamp) io.WriteString(h, sig.Token) calculatedSignature := h.Sum(nil) signature, err := hex.DecodeString(sig.Signature) if err != nil { return false, err } if len(calculatedSignature) != len(signature) { return false, nil } return subtle.ConstantTimeCompare(signature, calculatedSignature) == 1, nil }
go
func (mg *MailgunImpl) VerifyWebhookSignature(sig Signature) (verified bool, err error) { h := hmac.New(sha256.New, []byte(mg.APIKey())) io.WriteString(h, sig.TimeStamp) io.WriteString(h, sig.Token) calculatedSignature := h.Sum(nil) signature, err := hex.DecodeString(sig.Signature) if err != nil { return false, err } if len(calculatedSignature) != len(signature) { return false, nil } return subtle.ConstantTimeCompare(signature, calculatedSignature) == 1, nil }
[ "func", "(", "mg", "*", "MailgunImpl", ")", "VerifyWebhookSignature", "(", "sig", "Signature", ")", "(", "verified", "bool", ",", "err", "error", ")", "{", "h", ":=", "hmac", ".", "New", "(", "sha256", ".", "New", ",", "[", "]", "byte", "(", "mg", ".", "APIKey", "(", ")", ")", ")", "\n", "io", ".", "WriteString", "(", "h", ",", "sig", ".", "TimeStamp", ")", "\n", "io", ".", "WriteString", "(", "h", ",", "sig", ".", "Token", ")", "\n\n", "calculatedSignature", ":=", "h", ".", "Sum", "(", "nil", ")", "\n", "signature", ",", "err", ":=", "hex", ".", "DecodeString", "(", "sig", ".", "Signature", ")", "\n", "if", "err", "!=", "nil", "{", "return", "false", ",", "err", "\n", "}", "\n", "if", "len", "(", "calculatedSignature", ")", "!=", "len", "(", "signature", ")", "{", "return", "false", ",", "nil", "\n", "}", "\n\n", "return", "subtle", ".", "ConstantTimeCompare", "(", "signature", ",", "calculatedSignature", ")", "==", "1", ",", "nil", "\n", "}" ]
// Use this method to parse the webhook signature given as JSON in the webhook response
[ "Use", "this", "method", "to", "parse", "the", "webhook", "signature", "given", "as", "JSON", "in", "the", "webhook", "response" ]
train
https://github.com/mailgun/mailgun-go/blob/df421608b66e7dd4c03112d5bb01525c51f344a2/webhooks.go#L101-L116
mailgun/mailgun-go
webhooks.go
VerifyWebhookRequest
func (mg *MailgunImpl) VerifyWebhookRequest(req *http.Request) (verified bool, err error) { h := hmac.New(sha256.New, []byte(mg.APIKey())) io.WriteString(h, req.FormValue("timestamp")) io.WriteString(h, req.FormValue("token")) calculatedSignature := h.Sum(nil) signature, err := hex.DecodeString(req.FormValue("signature")) if err != nil { return false, err } if len(calculatedSignature) != len(signature) { return false, nil } return subtle.ConstantTimeCompare(signature, calculatedSignature) == 1, nil }
go
func (mg *MailgunImpl) VerifyWebhookRequest(req *http.Request) (verified bool, err error) { h := hmac.New(sha256.New, []byte(mg.APIKey())) io.WriteString(h, req.FormValue("timestamp")) io.WriteString(h, req.FormValue("token")) calculatedSignature := h.Sum(nil) signature, err := hex.DecodeString(req.FormValue("signature")) if err != nil { return false, err } if len(calculatedSignature) != len(signature) { return false, nil } return subtle.ConstantTimeCompare(signature, calculatedSignature) == 1, nil }
[ "func", "(", "mg", "*", "MailgunImpl", ")", "VerifyWebhookRequest", "(", "req", "*", "http", ".", "Request", ")", "(", "verified", "bool", ",", "err", "error", ")", "{", "h", ":=", "hmac", ".", "New", "(", "sha256", ".", "New", ",", "[", "]", "byte", "(", "mg", ".", "APIKey", "(", ")", ")", ")", "\n", "io", ".", "WriteString", "(", "h", ",", "req", ".", "FormValue", "(", "\"", "\"", ")", ")", "\n", "io", ".", "WriteString", "(", "h", ",", "req", ".", "FormValue", "(", "\"", "\"", ")", ")", "\n\n", "calculatedSignature", ":=", "h", ".", "Sum", "(", "nil", ")", "\n", "signature", ",", "err", ":=", "hex", ".", "DecodeString", "(", "req", ".", "FormValue", "(", "\"", "\"", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "false", ",", "err", "\n", "}", "\n", "if", "len", "(", "calculatedSignature", ")", "!=", "len", "(", "signature", ")", "{", "return", "false", ",", "nil", "\n", "}", "\n\n", "return", "subtle", ".", "ConstantTimeCompare", "(", "signature", ",", "calculatedSignature", ")", "==", "1", ",", "nil", "\n", "}" ]
// Deprecated: Please use the VerifyWebhookSignature() to parse the latest // version of WebHooks from mailgun
[ "Deprecated", ":", "Please", "use", "the", "VerifyWebhookSignature", "()", "to", "parse", "the", "latest", "version", "of", "WebHooks", "from", "mailgun" ]
train
https://github.com/mailgun/mailgun-go/blob/df421608b66e7dd4c03112d5bb01525c51f344a2/webhooks.go#L120-L135
mailgun/mailgun-go
rest_shim.go
String
func (e *UnexpectedResponseError) String() string { return fmt.Sprintf("UnexpectedResponseError URL=%s ExpectedOneOf=%#v Got=%d Error: %s", e.URL, e.Expected, e.Actual, string(e.Data)) }
go
func (e *UnexpectedResponseError) String() string { return fmt.Sprintf("UnexpectedResponseError URL=%s ExpectedOneOf=%#v Got=%d Error: %s", e.URL, e.Expected, e.Actual, string(e.Data)) }
[ "func", "(", "e", "*", "UnexpectedResponseError", ")", "String", "(", ")", "string", "{", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "e", ".", "URL", ",", "e", ".", "Expected", ",", "e", ".", "Actual", ",", "string", "(", "e", ".", "Data", ")", ")", "\n", "}" ]
// String() converts the error into a human-readable, logfmt-compliant string. // See http://godoc.org/github.com/kr/logfmt for details on logfmt formatting.
[ "String", "()", "converts", "the", "error", "into", "a", "human", "-", "readable", "logfmt", "-", "compliant", "string", ".", "See", "http", ":", "//", "godoc", ".", "org", "/", "github", ".", "com", "/", "kr", "/", "logfmt", "for", "details", "on", "logfmt", "formatting", "." ]
train
https://github.com/mailgun/mailgun-go/blob/df421608b66e7dd4c03112d5bb01525c51f344a2/rest_shim.go#L25-L27
mailgun/mailgun-go
rest_shim.go
newError
func newError(url string, expected []int, got *httpResponse) error { return &UnexpectedResponseError{ URL: url, Expected: expected, Actual: got.Code, Data: got.Data, } }
go
func newError(url string, expected []int, got *httpResponse) error { return &UnexpectedResponseError{ URL: url, Expected: expected, Actual: got.Code, Data: got.Data, } }
[ "func", "newError", "(", "url", "string", ",", "expected", "[", "]", "int", ",", "got", "*", "httpResponse", ")", "error", "{", "return", "&", "UnexpectedResponseError", "{", "URL", ":", "url", ",", "Expected", ":", "expected", ",", "Actual", ":", "got", ".", "Code", ",", "Data", ":", "got", ".", "Data", ",", "}", "\n", "}" ]
// newError creates a new error condition to be returned.
[ "newError", "creates", "a", "new", "error", "condition", "to", "be", "returned", "." ]
train
https://github.com/mailgun/mailgun-go/blob/df421608b66e7dd4c03112d5bb01525c51f344a2/rest_shim.go#L35-L42
mailgun/mailgun-go
rest_shim.go
makeRequest
func makeRequest(ctx context.Context, r *httpRequest, method string, p payload) (*httpResponse, error) { r.addHeader("User-Agent", MailgunGoUserAgent) rsp, err := r.makeRequest(ctx, method, p) if (err == nil) && notGood(rsp.Code, expected) { return rsp, newError(r.URL, expected, rsp) } return rsp, err }
go
func makeRequest(ctx context.Context, r *httpRequest, method string, p payload) (*httpResponse, error) { r.addHeader("User-Agent", MailgunGoUserAgent) rsp, err := r.makeRequest(ctx, method, p) if (err == nil) && notGood(rsp.Code, expected) { return rsp, newError(r.URL, expected, rsp) } return rsp, err }
[ "func", "makeRequest", "(", "ctx", "context", ".", "Context", ",", "r", "*", "httpRequest", ",", "method", "string", ",", "p", "payload", ")", "(", "*", "httpResponse", ",", "error", ")", "{", "r", ".", "addHeader", "(", "\"", "\"", ",", "MailgunGoUserAgent", ")", "\n", "rsp", ",", "err", ":=", "r", ".", "makeRequest", "(", "ctx", ",", "method", ",", "p", ")", "\n", "if", "(", "err", "==", "nil", ")", "&&", "notGood", "(", "rsp", ".", "Code", ",", "expected", ")", "{", "return", "rsp", ",", "newError", "(", "r", ".", "URL", ",", "expected", ",", "rsp", ")", "\n", "}", "\n", "return", "rsp", ",", "err", "\n", "}" ]
// makeRequest shim performs a generic request, checking for a positive outcome. // See simplehttp.MakeRequest for more details.
[ "makeRequest", "shim", "performs", "a", "generic", "request", "checking", "for", "a", "positive", "outcome", ".", "See", "simplehttp", ".", "MakeRequest", "for", "more", "details", "." ]
train
https://github.com/mailgun/mailgun-go/blob/df421608b66e7dd4c03112d5bb01525c51f344a2/rest_shim.go#L61-L68
mailgun/mailgun-go
rest_shim.go
getResponseFromJSON
func getResponseFromJSON(ctx context.Context, r *httpRequest, v interface{}) error { r.addHeader("User-Agent", MailgunGoUserAgent) response, err := r.makeGetRequest(ctx) if err != nil { return err } if notGood(response.Code, expected) { return newError(r.URL, expected, response) } return response.parseFromJSON(v) }
go
func getResponseFromJSON(ctx context.Context, r *httpRequest, v interface{}) error { r.addHeader("User-Agent", MailgunGoUserAgent) response, err := r.makeGetRequest(ctx) if err != nil { return err } if notGood(response.Code, expected) { return newError(r.URL, expected, response) } return response.parseFromJSON(v) }
[ "func", "getResponseFromJSON", "(", "ctx", "context", ".", "Context", ",", "r", "*", "httpRequest", ",", "v", "interface", "{", "}", ")", "error", "{", "r", ".", "addHeader", "(", "\"", "\"", ",", "MailgunGoUserAgent", ")", "\n", "response", ",", "err", ":=", "r", ".", "makeGetRequest", "(", "ctx", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "if", "notGood", "(", "response", ".", "Code", ",", "expected", ")", "{", "return", "newError", "(", "r", ".", "URL", ",", "expected", ",", "response", ")", "\n", "}", "\n", "return", "response", ".", "parseFromJSON", "(", "v", ")", "\n", "}" ]
// getResponseFromJSON shim performs a GET request, checking for a positive outcome. // See simplehttp.GetResponseFromJSON for more details.
[ "getResponseFromJSON", "shim", "performs", "a", "GET", "request", "checking", "for", "a", "positive", "outcome", ".", "See", "simplehttp", ".", "GetResponseFromJSON", "for", "more", "details", "." ]
train
https://github.com/mailgun/mailgun-go/blob/df421608b66e7dd4c03112d5bb01525c51f344a2/rest_shim.go#L72-L82
mailgun/mailgun-go
rest_shim.go
postResponseFromJSON
func postResponseFromJSON(ctx context.Context, r *httpRequest, p payload, v interface{}) error { r.addHeader("User-Agent", MailgunGoUserAgent) response, err := r.makePostRequest(ctx, p) if err != nil { return err } if notGood(response.Code, expected) { return newError(r.URL, expected, response) } return response.parseFromJSON(v) }
go
func postResponseFromJSON(ctx context.Context, r *httpRequest, p payload, v interface{}) error { r.addHeader("User-Agent", MailgunGoUserAgent) response, err := r.makePostRequest(ctx, p) if err != nil { return err } if notGood(response.Code, expected) { return newError(r.URL, expected, response) } return response.parseFromJSON(v) }
[ "func", "postResponseFromJSON", "(", "ctx", "context", ".", "Context", ",", "r", "*", "httpRequest", ",", "p", "payload", ",", "v", "interface", "{", "}", ")", "error", "{", "r", ".", "addHeader", "(", "\"", "\"", ",", "MailgunGoUserAgent", ")", "\n", "response", ",", "err", ":=", "r", ".", "makePostRequest", "(", "ctx", ",", "p", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "if", "notGood", "(", "response", ".", "Code", ",", "expected", ")", "{", "return", "newError", "(", "r", ".", "URL", ",", "expected", ",", "response", ")", "\n", "}", "\n", "return", "response", ".", "parseFromJSON", "(", "v", ")", "\n", "}" ]
// postResponseFromJSON shim performs a POST request, checking for a positive outcome. // See simplehttp.PostResponseFromJSON for more details.
[ "postResponseFromJSON", "shim", "performs", "a", "POST", "request", "checking", "for", "a", "positive", "outcome", ".", "See", "simplehttp", ".", "PostResponseFromJSON", "for", "more", "details", "." ]
train
https://github.com/mailgun/mailgun-go/blob/df421608b66e7dd4c03112d5bb01525c51f344a2/rest_shim.go#L86-L96
mailgun/mailgun-go
rest_shim.go
GetStatusFromErr
func GetStatusFromErr(err error) int { obj, ok := err.(*UnexpectedResponseError) if !ok { return -1 } return obj.Actual }
go
func GetStatusFromErr(err error) int { obj, ok := err.(*UnexpectedResponseError) if !ok { return -1 } return obj.Actual }
[ "func", "GetStatusFromErr", "(", "err", "error", ")", "int", "{", "obj", ",", "ok", ":=", "err", ".", "(", "*", "UnexpectedResponseError", ")", "\n", "if", "!", "ok", "{", "return", "-", "1", "\n", "}", "\n", "return", "obj", ".", "Actual", "\n", "}" ]
// Extract the http status code from error object
[ "Extract", "the", "http", "status", "code", "from", "error", "object" ]
train
https://github.com/mailgun/mailgun-go/blob/df421608b66e7dd4c03112d5bb01525c51f344a2/rest_shim.go#L157-L163
mailgun/mailgun-go
ips.go
ListIPS
func (mg *MailgunImpl) ListIPS(ctx context.Context, dedicated bool) ([]IPAddress, error) { r := newHTTPRequest(generatePublicApiUrl(mg, ipsEndpoint)) r.setClient(mg.Client()) if dedicated { r.addParameter("dedicated", "true") } r.setBasicAuth(basicAuthUser, mg.APIKey()) var resp ipAddressListResponse if err := getResponseFromJSON(ctx, r, &resp); err != nil { return nil, err } var result []IPAddress for _, ip := range resp.Items { result = append(result, IPAddress{IP: ip}) } return result, nil }
go
func (mg *MailgunImpl) ListIPS(ctx context.Context, dedicated bool) ([]IPAddress, error) { r := newHTTPRequest(generatePublicApiUrl(mg, ipsEndpoint)) r.setClient(mg.Client()) if dedicated { r.addParameter("dedicated", "true") } r.setBasicAuth(basicAuthUser, mg.APIKey()) var resp ipAddressListResponse if err := getResponseFromJSON(ctx, r, &resp); err != nil { return nil, err } var result []IPAddress for _, ip := range resp.Items { result = append(result, IPAddress{IP: ip}) } return result, nil }
[ "func", "(", "mg", "*", "MailgunImpl", ")", "ListIPS", "(", "ctx", "context", ".", "Context", ",", "dedicated", "bool", ")", "(", "[", "]", "IPAddress", ",", "error", ")", "{", "r", ":=", "newHTTPRequest", "(", "generatePublicApiUrl", "(", "mg", ",", "ipsEndpoint", ")", ")", "\n", "r", ".", "setClient", "(", "mg", ".", "Client", "(", ")", ")", "\n", "if", "dedicated", "{", "r", ".", "addParameter", "(", "\"", "\"", ",", "\"", "\"", ")", "\n", "}", "\n", "r", ".", "setBasicAuth", "(", "basicAuthUser", ",", "mg", ".", "APIKey", "(", ")", ")", "\n\n", "var", "resp", "ipAddressListResponse", "\n", "if", "err", ":=", "getResponseFromJSON", "(", "ctx", ",", "r", ",", "&", "resp", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "var", "result", "[", "]", "IPAddress", "\n", "for", "_", ",", "ip", ":=", "range", "resp", ".", "Items", "{", "result", "=", "append", "(", "result", ",", "IPAddress", "{", "IP", ":", "ip", "}", ")", "\n", "}", "\n", "return", "result", ",", "nil", "\n", "}" ]
// ListIPS returns a list of IPs assigned to your account
[ "ListIPS", "returns", "a", "list", "of", "IPs", "assigned", "to", "your", "account" ]
train
https://github.com/mailgun/mailgun-go/blob/df421608b66e7dd4c03112d5bb01525c51f344a2/ips.go#L22-L39