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
10,800
jzelinskie/geddit
session.go
SubmissionsComments
func (s Session) SubmissionsComments(submissionID string) ([]*Comment, error) { redditURL := "https://www.reddit.com" redditURL += "/comments/" + submissionID redditURL += ".json" req := request{ url: redditURL, useragent: s.useragent, } body, err := req.getResponse() if err != nil { return nil, err } var comments interface{} err = json.NewDecoder(body).Decode(&comments) if err != nil { return nil, err } helper := new(helper) helper.buildComments(comments) return helper.comments, nil }
go
func (s Session) SubmissionsComments(submissionID string) ([]*Comment, error) { redditURL := "https://www.reddit.com" redditURL += "/comments/" + submissionID redditURL += ".json" req := request{ url: redditURL, useragent: s.useragent, } body, err := req.getResponse() if err != nil { return nil, err } var comments interface{} err = json.NewDecoder(body).Decode(&comments) if err != nil { return nil, err } helper := new(helper) helper.buildComments(comments) return helper.comments, nil }
[ "func", "(", "s", "Session", ")", "SubmissionsComments", "(", "submissionID", "string", ")", "(", "[", "]", "*", "Comment", ",", "error", ")", "{", "redditURL", ":=", "\"", "\"", "\n", "redditURL", "+=", "\"", "\"", "+", "submissionID", "\n", "redditURL", "+=", "\"", "\"", "\n\n", "req", ":=", "request", "{", "url", ":", "redditURL", ",", "useragent", ":", "s", ".", "useragent", ",", "}", "\n", "body", ",", "err", ":=", "req", ".", "getResponse", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "var", "comments", "interface", "{", "}", "\n", "err", "=", "json", ".", "NewDecoder", "(", "body", ")", ".", "Decode", "(", "&", "comments", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "helper", ":=", "new", "(", "helper", ")", "\n", "helper", ".", "buildComments", "(", "comments", ")", "\n\n", "return", "helper", ".", "comments", ",", "nil", "\n", "}" ]
// SubmissionComments returns the comments on a submission given it's ID.
[ "SubmissionComments", "returns", "the", "comments", "on", "a", "submission", "given", "it", "s", "ID", "." ]
a9d9445ed681c9bc2df9cce08998891b44efd806
https://github.com/jzelinskie/geddit/blob/a9d9445ed681c9bc2df9cce08998891b44efd806/session.go#L82-L105
10,801
jzelinskie/geddit
session.go
AboutRedditor
func (s Session) AboutRedditor(username string) (*Redditor, error) { req := &request{ url: fmt.Sprintf("https://www.reddit.com/user/%s/about.json", username), useragent: s.useragent, } body, err := req.getResponse() if err != nil { return nil, err } type Response struct { Data Redditor } r := new(Response) err = json.NewDecoder(body).Decode(r) if err != nil { return nil, err } return &r.Data, nil }
go
func (s Session) AboutRedditor(username string) (*Redditor, error) { req := &request{ url: fmt.Sprintf("https://www.reddit.com/user/%s/about.json", username), useragent: s.useragent, } body, err := req.getResponse() if err != nil { return nil, err } type Response struct { Data Redditor } r := new(Response) err = json.NewDecoder(body).Decode(r) if err != nil { return nil, err } return &r.Data, nil }
[ "func", "(", "s", "Session", ")", "AboutRedditor", "(", "username", "string", ")", "(", "*", "Redditor", ",", "error", ")", "{", "req", ":=", "&", "request", "{", "url", ":", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "username", ")", ",", "useragent", ":", "s", ".", "useragent", ",", "}", "\n", "body", ",", "err", ":=", "req", ".", "getResponse", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "type", "Response", "struct", "{", "Data", "Redditor", "\n", "}", "\n", "r", ":=", "new", "(", "Response", ")", "\n", "err", "=", "json", ".", "NewDecoder", "(", "body", ")", ".", "Decode", "(", "r", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "&", "r", ".", "Data", ",", "nil", "\n", "}" ]
// AboutRedditor returns a Redditor for the given username.
[ "AboutRedditor", "returns", "a", "Redditor", "for", "the", "given", "username", "." ]
a9d9445ed681c9bc2df9cce08998891b44efd806
https://github.com/jzelinskie/geddit/blob/a9d9445ed681c9bc2df9cce08998891b44efd806/session.go#L108-L128
10,802
jzelinskie/geddit
session.go
AboutSubreddit
func (s Session) AboutSubreddit(subreddit string) (*Subreddit, error) { req := &request{ url: fmt.Sprintf("https://www.reddit.com/r/%s/about.json", subreddit), useragent: s.useragent, } body, err := req.getResponse() if err != nil { return nil, err } type Response struct { Data Subreddit } r := new(Response) err = json.NewDecoder(body).Decode(r) if err != nil { return nil, err } return &r.Data, nil }
go
func (s Session) AboutSubreddit(subreddit string) (*Subreddit, error) { req := &request{ url: fmt.Sprintf("https://www.reddit.com/r/%s/about.json", subreddit), useragent: s.useragent, } body, err := req.getResponse() if err != nil { return nil, err } type Response struct { Data Subreddit } r := new(Response) err = json.NewDecoder(body).Decode(r) if err != nil { return nil, err } return &r.Data, nil }
[ "func", "(", "s", "Session", ")", "AboutSubreddit", "(", "subreddit", "string", ")", "(", "*", "Subreddit", ",", "error", ")", "{", "req", ":=", "&", "request", "{", "url", ":", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "subreddit", ")", ",", "useragent", ":", "s", ".", "useragent", ",", "}", "\n", "body", ",", "err", ":=", "req", ".", "getResponse", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "type", "Response", "struct", "{", "Data", "Subreddit", "\n", "}", "\n\n", "r", ":=", "new", "(", "Response", ")", "\n", "err", "=", "json", ".", "NewDecoder", "(", "body", ")", ".", "Decode", "(", "r", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "&", "r", ".", "Data", ",", "nil", "\n", "}" ]
// AboutSubreddit returns a subreddit for the given subreddit name.
[ "AboutSubreddit", "returns", "a", "subreddit", "for", "the", "given", "subreddit", "name", "." ]
a9d9445ed681c9bc2df9cce08998891b44efd806
https://github.com/jzelinskie/geddit/blob/a9d9445ed681c9bc2df9cce08998891b44efd806/session.go#L131-L152
10,803
jzelinskie/geddit
session.go
Comments
func (s Session) Comments(h *Submission) ([]*Comment, error) { req := &request{ url: fmt.Sprintf("https://www.reddit.com/comments/%s/.json", h.ID), useragent: s.useragent, } body, err := req.getResponse() if err != nil { return nil, err } r := json.NewDecoder(body) var interf interface{} if err = r.Decode(&interf); err != nil { return nil, err } helper := new(helper) helper.buildComments(interf) return helper.comments, nil }
go
func (s Session) Comments(h *Submission) ([]*Comment, error) { req := &request{ url: fmt.Sprintf("https://www.reddit.com/comments/%s/.json", h.ID), useragent: s.useragent, } body, err := req.getResponse() if err != nil { return nil, err } r := json.NewDecoder(body) var interf interface{} if err = r.Decode(&interf); err != nil { return nil, err } helper := new(helper) helper.buildComments(interf) return helper.comments, nil }
[ "func", "(", "s", "Session", ")", "Comments", "(", "h", "*", "Submission", ")", "(", "[", "]", "*", "Comment", ",", "error", ")", "{", "req", ":=", "&", "request", "{", "url", ":", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "h", ".", "ID", ")", ",", "useragent", ":", "s", ".", "useragent", ",", "}", "\n", "body", ",", "err", ":=", "req", ".", "getResponse", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "r", ":=", "json", ".", "NewDecoder", "(", "body", ")", "\n", "var", "interf", "interface", "{", "}", "\n", "if", "err", "=", "r", ".", "Decode", "(", "&", "interf", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "helper", ":=", "new", "(", "helper", ")", "\n", "helper", ".", "buildComments", "(", "interf", ")", "\n\n", "return", "helper", ".", "comments", ",", "nil", "\n", "}" ]
// Comments returns the comments for a given Submission.
[ "Comments", "returns", "the", "comments", "for", "a", "given", "Submission", "." ]
a9d9445ed681c9bc2df9cce08998891b44efd806
https://github.com/jzelinskie/geddit/blob/a9d9445ed681c9bc2df9cce08998891b44efd806/session.go#L155-L174
10,804
jzelinskie/geddit
session.go
CaptchaImage
func (s Session) CaptchaImage(iden string) (image.Image, error) { req := &request{ url: fmt.Sprintf("https://www.reddit.com/captcha/%s", iden), useragent: s.useragent, } p, err := req.getResponse() if err != nil { return nil, err } m, err := png.Decode(p) if err != nil { return nil, err } return m, nil }
go
func (s Session) CaptchaImage(iden string) (image.Image, error) { req := &request{ url: fmt.Sprintf("https://www.reddit.com/captcha/%s", iden), useragent: s.useragent, } p, err := req.getResponse() if err != nil { return nil, err } m, err := png.Decode(p) if err != nil { return nil, err } return m, nil }
[ "func", "(", "s", "Session", ")", "CaptchaImage", "(", "iden", "string", ")", "(", "image", ".", "Image", ",", "error", ")", "{", "req", ":=", "&", "request", "{", "url", ":", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "iden", ")", ",", "useragent", ":", "s", ".", "useragent", ",", "}", "\n\n", "p", ",", "err", ":=", "req", ".", "getResponse", "(", ")", "\n\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "m", ",", "err", ":=", "png", ".", "Decode", "(", "p", ")", "\n\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "m", ",", "nil", "\n", "}" ]
// CaptchaImage gets the png corresponding to the captcha iden and decodes it
[ "CaptchaImage", "gets", "the", "png", "corresponding", "to", "the", "captcha", "iden", "and", "decodes", "it" ]
a9d9445ed681c9bc2df9cce08998891b44efd806
https://github.com/jzelinskie/geddit/blob/a9d9445ed681c9bc2df9cce08998891b44efd806/session.go#L177-L196
10,805
jzelinskie/geddit
session.go
RedditorComments
func (s Session) RedditorComments(username string, params ListingOptions) ([]*Comment, error) { v, err := query.Values(params) if err != nil { return nil, err } baseUrl := "https://www.reddit.com" // If username given, add to URL if username != "" { baseUrl += "/user/" + username } redditUrl := fmt.Sprintf(baseUrl+"/comments.json?%s", v.Encode()) req := request{ url: redditUrl, useragent: s.useragent, } body, err := req.getResponse() if err != nil { return nil, err } var comments interface{} if err = json.NewDecoder(body).Decode(&comments); err != nil { return nil, err } helper := new(helper) helper.buildComments(comments) return helper.comments, nil }
go
func (s Session) RedditorComments(username string, params ListingOptions) ([]*Comment, error) { v, err := query.Values(params) if err != nil { return nil, err } baseUrl := "https://www.reddit.com" // If username given, add to URL if username != "" { baseUrl += "/user/" + username } redditUrl := fmt.Sprintf(baseUrl+"/comments.json?%s", v.Encode()) req := request{ url: redditUrl, useragent: s.useragent, } body, err := req.getResponse() if err != nil { return nil, err } var comments interface{} if err = json.NewDecoder(body).Decode(&comments); err != nil { return nil, err } helper := new(helper) helper.buildComments(comments) return helper.comments, nil }
[ "func", "(", "s", "Session", ")", "RedditorComments", "(", "username", "string", ",", "params", "ListingOptions", ")", "(", "[", "]", "*", "Comment", ",", "error", ")", "{", "v", ",", "err", ":=", "query", ".", "Values", "(", "params", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "baseUrl", ":=", "\"", "\"", "\n\n", "// If username given, add to URL", "if", "username", "!=", "\"", "\"", "{", "baseUrl", "+=", "\"", "\"", "+", "username", "\n", "}", "\n\n", "redditUrl", ":=", "fmt", ".", "Sprintf", "(", "baseUrl", "+", "\"", "\"", ",", "v", ".", "Encode", "(", ")", ")", "\n\n", "req", ":=", "request", "{", "url", ":", "redditUrl", ",", "useragent", ":", "s", ".", "useragent", ",", "}", "\n\n", "body", ",", "err", ":=", "req", ".", "getResponse", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "var", "comments", "interface", "{", "}", "\n", "if", "err", "=", "json", ".", "NewDecoder", "(", "body", ")", ".", "Decode", "(", "&", "comments", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "helper", ":=", "new", "(", "helper", ")", "\n", "helper", ".", "buildComments", "(", "comments", ")", "\n\n", "return", "helper", ".", "comments", ",", "nil", "\n", "}" ]
// RedditorComments returns a slice of Comments from a given Reddit user name.
[ "RedditorComments", "returns", "a", "slice", "of", "Comments", "from", "a", "given", "Reddit", "user", "name", "." ]
a9d9445ed681c9bc2df9cce08998891b44efd806
https://github.com/jzelinskie/geddit/blob/a9d9445ed681c9bc2df9cce08998891b44efd806/session.go#L235-L268
10,806
jzelinskie/geddit
subreddit.go
String
func (s *Subreddit) String() string { var subs string switch s.NumSubs { case 1: subs = "1 subscriber" default: subs = fmt.Sprintf("%d subscribers", s.NumSubs) } return fmt.Sprintf("%s (%s)", s.Title, subs) }
go
func (s *Subreddit) String() string { var subs string switch s.NumSubs { case 1: subs = "1 subscriber" default: subs = fmt.Sprintf("%d subscribers", s.NumSubs) } return fmt.Sprintf("%s (%s)", s.Title, subs) }
[ "func", "(", "s", "*", "Subreddit", ")", "String", "(", ")", "string", "{", "var", "subs", "string", "\n", "switch", "s", ".", "NumSubs", "{", "case", "1", ":", "subs", "=", "\"", "\"", "\n", "default", ":", "subs", "=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "s", ".", "NumSubs", ")", "\n", "}", "\n", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "s", ".", "Title", ",", "subs", ")", "\n", "}" ]
// String returns the string representation of a subreddit.
[ "String", "returns", "the", "string", "representation", "of", "a", "subreddit", "." ]
a9d9445ed681c9bc2df9cce08998891b44efd806
https://github.com/jzelinskie/geddit/blob/a9d9445ed681c9bc2df9cce08998891b44efd806/subreddit.go#L27-L36
10,807
jzelinskie/geddit
comment.go
makeComment
func makeComment(cmap map[string]interface{}) *Comment { ret := new(Comment) ret.Author, _ = cmap["author"].(string) ret.Body, _ = cmap["body"].(string) ret.BodyHTML, _ = cmap["body_html"].(string) ret.Subreddit, _ = cmap["subreddit"].(string) ret.LinkID, _ = cmap["link_id"].(string) ret.ParentID, _ = cmap["parent_id"].(string) ret.SubredditID, _ = cmap["subreddit_id"].(string) ret.FullID, _ = cmap["name"].(string) ret.Permalink, _ = cmap["permalink"].(string) ret.Score, _ = cmap["score"].(float64) ret.UpVotes, _ = cmap["ups"].(float64) ret.DownVotes, _ = cmap["downs"].(float64) ret.Created, _ = cmap["created_utc"].(float64) ret.Edited, _ = cmap["edited"].(bool) ret.BannedBy, _ = cmap["banned_by"].(*string) ret.ApprovedBy, _ = cmap["approved_by"].(*string) ret.AuthorFlairTxt, _ = cmap["author_flair_text"].(*string) ret.AuthorFlairCSSClass, _ = cmap["author_flair_css_class"].(*string) ret.NumReports, _ = cmap["num_reports"].(*int) ret.Likes, _ = cmap["likes"].(*int) helper := new(helper) helper.buildComments(cmap["replies"]) ret.Replies = helper.comments return ret }
go
func makeComment(cmap map[string]interface{}) *Comment { ret := new(Comment) ret.Author, _ = cmap["author"].(string) ret.Body, _ = cmap["body"].(string) ret.BodyHTML, _ = cmap["body_html"].(string) ret.Subreddit, _ = cmap["subreddit"].(string) ret.LinkID, _ = cmap["link_id"].(string) ret.ParentID, _ = cmap["parent_id"].(string) ret.SubredditID, _ = cmap["subreddit_id"].(string) ret.FullID, _ = cmap["name"].(string) ret.Permalink, _ = cmap["permalink"].(string) ret.Score, _ = cmap["score"].(float64) ret.UpVotes, _ = cmap["ups"].(float64) ret.DownVotes, _ = cmap["downs"].(float64) ret.Created, _ = cmap["created_utc"].(float64) ret.Edited, _ = cmap["edited"].(bool) ret.BannedBy, _ = cmap["banned_by"].(*string) ret.ApprovedBy, _ = cmap["approved_by"].(*string) ret.AuthorFlairTxt, _ = cmap["author_flair_text"].(*string) ret.AuthorFlairCSSClass, _ = cmap["author_flair_css_class"].(*string) ret.NumReports, _ = cmap["num_reports"].(*int) ret.Likes, _ = cmap["likes"].(*int) helper := new(helper) helper.buildComments(cmap["replies"]) ret.Replies = helper.comments return ret }
[ "func", "makeComment", "(", "cmap", "map", "[", "string", "]", "interface", "{", "}", ")", "*", "Comment", "{", "ret", ":=", "new", "(", "Comment", ")", "\n", "ret", ".", "Author", ",", "_", "=", "cmap", "[", "\"", "\"", "]", ".", "(", "string", ")", "\n", "ret", ".", "Body", ",", "_", "=", "cmap", "[", "\"", "\"", "]", ".", "(", "string", ")", "\n", "ret", ".", "BodyHTML", ",", "_", "=", "cmap", "[", "\"", "\"", "]", ".", "(", "string", ")", "\n", "ret", ".", "Subreddit", ",", "_", "=", "cmap", "[", "\"", "\"", "]", ".", "(", "string", ")", "\n", "ret", ".", "LinkID", ",", "_", "=", "cmap", "[", "\"", "\"", "]", ".", "(", "string", ")", "\n", "ret", ".", "ParentID", ",", "_", "=", "cmap", "[", "\"", "\"", "]", ".", "(", "string", ")", "\n", "ret", ".", "SubredditID", ",", "_", "=", "cmap", "[", "\"", "\"", "]", ".", "(", "string", ")", "\n", "ret", ".", "FullID", ",", "_", "=", "cmap", "[", "\"", "\"", "]", ".", "(", "string", ")", "\n", "ret", ".", "Permalink", ",", "_", "=", "cmap", "[", "\"", "\"", "]", ".", "(", "string", ")", "\n", "ret", ".", "Score", ",", "_", "=", "cmap", "[", "\"", "\"", "]", ".", "(", "float64", ")", "\n", "ret", ".", "UpVotes", ",", "_", "=", "cmap", "[", "\"", "\"", "]", ".", "(", "float64", ")", "\n", "ret", ".", "DownVotes", ",", "_", "=", "cmap", "[", "\"", "\"", "]", ".", "(", "float64", ")", "\n", "ret", ".", "Created", ",", "_", "=", "cmap", "[", "\"", "\"", "]", ".", "(", "float64", ")", "\n", "ret", ".", "Edited", ",", "_", "=", "cmap", "[", "\"", "\"", "]", ".", "(", "bool", ")", "\n", "ret", ".", "BannedBy", ",", "_", "=", "cmap", "[", "\"", "\"", "]", ".", "(", "*", "string", ")", "\n", "ret", ".", "ApprovedBy", ",", "_", "=", "cmap", "[", "\"", "\"", "]", ".", "(", "*", "string", ")", "\n", "ret", ".", "AuthorFlairTxt", ",", "_", "=", "cmap", "[", "\"", "\"", "]", ".", "(", "*", "string", ")", "\n", "ret", ".", "AuthorFlairCSSClass", ",", "_", "=", "cmap", "[", "\"", "\"", "]", ".", "(", "*", "string", ")", "\n", "ret", ".", "NumReports", ",", "_", "=", "cmap", "[", "\"", "\"", "]", ".", "(", "*", "int", ")", "\n", "ret", ".", "Likes", ",", "_", "=", "cmap", "[", "\"", "\"", "]", ".", "(", "*", "int", ")", "\n\n", "helper", ":=", "new", "(", "helper", ")", "\n", "helper", ".", "buildComments", "(", "cmap", "[", "\"", "\"", "]", ")", "\n", "ret", ".", "Replies", "=", "helper", ".", "comments", "\n\n", "return", "ret", "\n", "}" ]
// makeComment tries its best to fill as many fields as possible of a Comment.
[ "makeComment", "tries", "its", "best", "to", "fill", "as", "many", "fields", "as", "possible", "of", "a", "Comment", "." ]
a9d9445ed681c9bc2df9cce08998891b44efd806
https://github.com/jzelinskie/geddit/blob/a9d9445ed681c9bc2df9cce08998891b44efd806/comment.go#L50-L78
10,808
jzelinskie/geddit
comment.go
buildComments
func (h *helper) buildComments(inf interface{}) { switch tp := inf.(type) { case []interface{}: //Maybe array for base comments for _, k := range tp { h.buildComments(k) } case map[string]interface{}: //Maybe comment data if tp["body"] == nil { for _, k := range tp { h.buildComments(k) } } else { h.comments = append(h.comments, makeComment(tp)) } } }
go
func (h *helper) buildComments(inf interface{}) { switch tp := inf.(type) { case []interface{}: //Maybe array for base comments for _, k := range tp { h.buildComments(k) } case map[string]interface{}: //Maybe comment data if tp["body"] == nil { for _, k := range tp { h.buildComments(k) } } else { h.comments = append(h.comments, makeComment(tp)) } } }
[ "func", "(", "h", "*", "helper", ")", "buildComments", "(", "inf", "interface", "{", "}", ")", "{", "switch", "tp", ":=", "inf", ".", "(", "type", ")", "{", "case", "[", "]", "interface", "{", "}", ":", "//Maybe array for base comments", "for", "_", ",", "k", ":=", "range", "tp", "{", "h", ".", "buildComments", "(", "k", ")", "\n", "}", "\n", "case", "map", "[", "string", "]", "interface", "{", "}", ":", "//Maybe comment data", "if", "tp", "[", "\"", "\"", "]", "==", "nil", "{", "for", "_", ",", "k", ":=", "range", "tp", "{", "h", ".", "buildComments", "(", "k", ")", "\n", "}", "\n", "}", "else", "{", "h", ".", "comments", "=", "append", "(", "h", ".", "comments", ",", "makeComment", "(", "tp", ")", ")", "\n", "}", "\n", "}", "\n", "}" ]
//Recursive function to find the fields we want and build the Comments //Way too hackish for my likes
[ "Recursive", "function", "to", "find", "the", "fields", "we", "want", "and", "build", "the", "Comments", "Way", "too", "hackish", "for", "my", "likes" ]
a9d9445ed681c9bc2df9cce08998891b44efd806
https://github.com/jzelinskie/geddit/blob/a9d9445ed681c9bc2df9cce08998891b44efd806/comment.go#L87-L102
10,809
jzelinskie/geddit
types.go
NewLinkSubmission
func NewLinkSubmission(sr, title, link string, replies bool, c *Captcha) *NewSubmission { return &NewSubmission{sr, title, link, false, replies, true, true, c} }
go
func NewLinkSubmission(sr, title, link string, replies bool, c *Captcha) *NewSubmission { return &NewSubmission{sr, title, link, false, replies, true, true, c} }
[ "func", "NewLinkSubmission", "(", "sr", ",", "title", ",", "link", "string", ",", "replies", "bool", ",", "c", "*", "Captcha", ")", "*", "NewSubmission", "{", "return", "&", "NewSubmission", "{", "sr", ",", "title", ",", "link", ",", "false", ",", "replies", ",", "true", ",", "true", ",", "c", "}", "\n", "}" ]
// NewLinkSubmission returns a NewSubmission with parameters appropriate for a link submission
[ "NewLinkSubmission", "returns", "a", "NewSubmission", "with", "parameters", "appropriate", "for", "a", "link", "submission" ]
a9d9445ed681c9bc2df9cce08998891b44efd806
https://github.com/jzelinskie/geddit/blob/a9d9445ed681c9bc2df9cce08998891b44efd806/types.go#L34-L36
10,810
jzelinskie/geddit
types.go
NewTextSubmission
func NewTextSubmission(sr, title, text string, replies bool, c *Captcha) *NewSubmission { return &NewSubmission{sr, title, text, true, replies, true, true, c} }
go
func NewTextSubmission(sr, title, text string, replies bool, c *Captcha) *NewSubmission { return &NewSubmission{sr, title, text, true, replies, true, true, c} }
[ "func", "NewTextSubmission", "(", "sr", ",", "title", ",", "text", "string", ",", "replies", "bool", ",", "c", "*", "Captcha", ")", "*", "NewSubmission", "{", "return", "&", "NewSubmission", "{", "sr", ",", "title", ",", "text", ",", "true", ",", "replies", ",", "true", ",", "true", ",", "c", "}", "\n", "}" ]
// NewTextSubmission returns a NewSubmission with parameters appropriate for a text submission
[ "NewTextSubmission", "returns", "a", "NewSubmission", "with", "parameters", "appropriate", "for", "a", "text", "submission" ]
a9d9445ed681c9bc2df9cce08998891b44efd806
https://github.com/jzelinskie/geddit/blob/a9d9445ed681c9bc2df9cce08998891b44efd806/types.go#L39-L41
10,811
jzelinskie/geddit
redditor.go
String
func (r *Redditor) String() string { return fmt.Sprintf("%s (%d-%d)", r.Name, r.LinkKarma, r.CommentKarma) }
go
func (r *Redditor) String() string { return fmt.Sprintf("%s (%d-%d)", r.Name, r.LinkKarma, r.CommentKarma) }
[ "func", "(", "r", "*", "Redditor", ")", "String", "(", ")", "string", "{", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "r", ".", "Name", ",", "r", ".", "LinkKarma", ",", "r", ".", "CommentKarma", ")", "\n", "}" ]
// String returns the string representation of a reddit user.
[ "String", "returns", "the", "string", "representation", "of", "a", "reddit", "user", "." ]
a9d9445ed681c9bc2df9cce08998891b44efd806
https://github.com/jzelinskie/geddit/blob/a9d9445ed681c9bc2df9cce08998891b44efd806/redditor.go#L64-L66
10,812
jzelinskie/geddit
oauth_session.go
RoundTrip
func (t *transport) RoundTrip(req *http.Request) (resp *http.Response, err error) { req.Header.Set("User-Agent", t.useragent) return t.RoundTripper.RoundTrip(req) }
go
func (t *transport) RoundTrip(req *http.Request) (resp *http.Response, err error) { req.Header.Set("User-Agent", t.useragent) return t.RoundTripper.RoundTrip(req) }
[ "func", "(", "t", "*", "transport", ")", "RoundTrip", "(", "req", "*", "http", ".", "Request", ")", "(", "resp", "*", "http", ".", "Response", ",", "err", "error", ")", "{", "req", ".", "Header", ".", "Set", "(", "\"", "\"", ",", "t", ".", "useragent", ")", "\n", "return", "t", ".", "RoundTripper", ".", "RoundTrip", "(", "req", ")", "\n", "}" ]
// Any request headers can be modified here.
[ "Any", "request", "headers", "can", "be", "modified", "here", "." ]
a9d9445ed681c9bc2df9cce08998891b44efd806
https://github.com/jzelinskie/geddit/blob/a9d9445ed681c9bc2df9cce08998891b44efd806/oauth_session.go#L31-L34
10,813
jzelinskie/geddit
oauth_session.go
NewOAuthSession
func NewOAuthSession(clientID, clientSecret, useragent, redirectURL string) (*OAuthSession, error) { o := &OAuthSession{} if len(useragent) > 0 { o.UserAgent = useragent } else { o.UserAgent = "Geddit Reddit Bot https://github.com/jzelinskie/geddit" } // Set OAuth config o.OAuthConfig = &oauth2.Config{ ClientID: clientID, ClientSecret: clientSecret, Endpoint: oauth2.Endpoint{ AuthURL: "https://www.reddit.com/api/v1/authorize", TokenURL: "https://www.reddit.com/api/v1/access_token", }, RedirectURL: redirectURL, } // Inject our custom HTTP client so that a user-defined UA can // be passed during any authentication requests. c := &http.Client{} c.Transport = &transport{http.DefaultTransport, o.UserAgent} o.ctx = context.WithValue(context.Background(), oauth2.HTTPClient, c) return o, nil }
go
func NewOAuthSession(clientID, clientSecret, useragent, redirectURL string) (*OAuthSession, error) { o := &OAuthSession{} if len(useragent) > 0 { o.UserAgent = useragent } else { o.UserAgent = "Geddit Reddit Bot https://github.com/jzelinskie/geddit" } // Set OAuth config o.OAuthConfig = &oauth2.Config{ ClientID: clientID, ClientSecret: clientSecret, Endpoint: oauth2.Endpoint{ AuthURL: "https://www.reddit.com/api/v1/authorize", TokenURL: "https://www.reddit.com/api/v1/access_token", }, RedirectURL: redirectURL, } // Inject our custom HTTP client so that a user-defined UA can // be passed during any authentication requests. c := &http.Client{} c.Transport = &transport{http.DefaultTransport, o.UserAgent} o.ctx = context.WithValue(context.Background(), oauth2.HTTPClient, c) return o, nil }
[ "func", "NewOAuthSession", "(", "clientID", ",", "clientSecret", ",", "useragent", ",", "redirectURL", "string", ")", "(", "*", "OAuthSession", ",", "error", ")", "{", "o", ":=", "&", "OAuthSession", "{", "}", "\n\n", "if", "len", "(", "useragent", ")", ">", "0", "{", "o", ".", "UserAgent", "=", "useragent", "\n", "}", "else", "{", "o", ".", "UserAgent", "=", "\"", "\"", "\n", "}", "\n\n", "// Set OAuth config", "o", ".", "OAuthConfig", "=", "&", "oauth2", ".", "Config", "{", "ClientID", ":", "clientID", ",", "ClientSecret", ":", "clientSecret", ",", "Endpoint", ":", "oauth2", ".", "Endpoint", "{", "AuthURL", ":", "\"", "\"", ",", "TokenURL", ":", "\"", "\"", ",", "}", ",", "RedirectURL", ":", "redirectURL", ",", "}", "\n", "// Inject our custom HTTP client so that a user-defined UA can", "// be passed during any authentication requests.", "c", ":=", "&", "http", ".", "Client", "{", "}", "\n", "c", ".", "Transport", "=", "&", "transport", "{", "http", ".", "DefaultTransport", ",", "o", ".", "UserAgent", "}", "\n", "o", ".", "ctx", "=", "context", ".", "WithValue", "(", "context", ".", "Background", "(", ")", ",", "oauth2", ".", "HTTPClient", ",", "c", ")", "\n", "return", "o", ",", "nil", "\n", "}" ]
// NewOAuthSession creates a new session for those who want to log into a // reddit account via OAuth.
[ "NewOAuthSession", "creates", "a", "new", "session", "for", "those", "who", "want", "to", "log", "into", "a", "reddit", "account", "via", "OAuth", "." ]
a9d9445ed681c9bc2df9cce08998891b44efd806
https://github.com/jzelinskie/geddit/blob/a9d9445ed681c9bc2df9cce08998891b44efd806/oauth_session.go#L51-L76
10,814
jzelinskie/geddit
oauth_session.go
Throttle
func (o *OAuthSession) Throttle(interval time.Duration) { if interval == 0 { o.throttle = nil return } o.throttle = rate.New(1, interval) }
go
func (o *OAuthSession) Throttle(interval time.Duration) { if interval == 0 { o.throttle = nil return } o.throttle = rate.New(1, interval) }
[ "func", "(", "o", "*", "OAuthSession", ")", "Throttle", "(", "interval", "time", ".", "Duration", ")", "{", "if", "interval", "==", "0", "{", "o", ".", "throttle", "=", "nil", "\n", "return", "\n", "}", "\n", "o", ".", "throttle", "=", "rate", ".", "New", "(", "1", ",", "interval", ")", "\n", "}" ]
// Throttle sets the interval of each HTTP request. // Disable by setting interval to 0. Disabled by default. // Throttling is applied to invidual OAuthSession types.
[ "Throttle", "sets", "the", "interval", "of", "each", "HTTP", "request", ".", "Disable", "by", "setting", "interval", "to", "0", ".", "Disabled", "by", "default", ".", "Throttling", "is", "applied", "to", "invidual", "OAuthSession", "types", "." ]
a9d9445ed681c9bc2df9cce08998891b44efd806
https://github.com/jzelinskie/geddit/blob/a9d9445ed681c9bc2df9cce08998891b44efd806/oauth_session.go#L81-L87
10,815
jzelinskie/geddit
oauth_session.go
LoginAuth
func (o *OAuthSession) LoginAuth(username, password string) error { // Fetch OAuth token. t, err := o.OAuthConfig.PasswordCredentialsToken(o.ctx, username, password) if err != nil { return err } if !t.Valid() { msg := "Invalid OAuth token" if t != nil { if extra := t.Extra("error"); extra != nil { msg = fmt.Sprintf("%s: %s", msg, extra) } } return errors.New(msg) } o.Client = o.OAuthConfig.Client(o.ctx, t) return nil }
go
func (o *OAuthSession) LoginAuth(username, password string) error { // Fetch OAuth token. t, err := o.OAuthConfig.PasswordCredentialsToken(o.ctx, username, password) if err != nil { return err } if !t.Valid() { msg := "Invalid OAuth token" if t != nil { if extra := t.Extra("error"); extra != nil { msg = fmt.Sprintf("%s: %s", msg, extra) } } return errors.New(msg) } o.Client = o.OAuthConfig.Client(o.ctx, t) return nil }
[ "func", "(", "o", "*", "OAuthSession", ")", "LoginAuth", "(", "username", ",", "password", "string", ")", "error", "{", "// Fetch OAuth token.", "t", ",", "err", ":=", "o", ".", "OAuthConfig", ".", "PasswordCredentialsToken", "(", "o", ".", "ctx", ",", "username", ",", "password", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "if", "!", "t", ".", "Valid", "(", ")", "{", "msg", ":=", "\"", "\"", "\n", "if", "t", "!=", "nil", "{", "if", "extra", ":=", "t", ".", "Extra", "(", "\"", "\"", ")", ";", "extra", "!=", "nil", "{", "msg", "=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "msg", ",", "extra", ")", "\n", "}", "\n", "}", "\n", "return", "errors", ".", "New", "(", "msg", ")", "\n", "}", "\n", "o", ".", "Client", "=", "o", ".", "OAuthConfig", ".", "Client", "(", "o", ".", "ctx", ",", "t", ")", "\n", "return", "nil", "\n", "}" ]
// LoginAuth creates the required HTTP client with a new token.
[ "LoginAuth", "creates", "the", "required", "HTTP", "client", "with", "a", "new", "token", "." ]
a9d9445ed681c9bc2df9cce08998891b44efd806
https://github.com/jzelinskie/geddit/blob/a9d9445ed681c9bc2df9cce08998891b44efd806/oauth_session.go#L90-L107
10,816
jzelinskie/geddit
oauth_session.go
AuthCodeURL
func (o *OAuthSession) AuthCodeURL(state string, scopes []string) string { o.OAuthConfig.Scopes = scopes return o.OAuthConfig.AuthCodeURL(state, oauth2.AccessTypeOnline) }
go
func (o *OAuthSession) AuthCodeURL(state string, scopes []string) string { o.OAuthConfig.Scopes = scopes return o.OAuthConfig.AuthCodeURL(state, oauth2.AccessTypeOnline) }
[ "func", "(", "o", "*", "OAuthSession", ")", "AuthCodeURL", "(", "state", "string", ",", "scopes", "[", "]", "string", ")", "string", "{", "o", ".", "OAuthConfig", ".", "Scopes", "=", "scopes", "\n", "return", "o", ".", "OAuthConfig", ".", "AuthCodeURL", "(", "state", ",", "oauth2", ".", "AccessTypeOnline", ")", "\n", "}" ]
// AuthCodeURL creates and returns an auth URL which contains an auth code.
[ "AuthCodeURL", "creates", "and", "returns", "an", "auth", "URL", "which", "contains", "an", "auth", "code", "." ]
a9d9445ed681c9bc2df9cce08998891b44efd806
https://github.com/jzelinskie/geddit/blob/a9d9445ed681c9bc2df9cce08998891b44efd806/oauth_session.go#L110-L113
10,817
jzelinskie/geddit
oauth_session.go
CodeAuth
func (o *OAuthSession) CodeAuth(code string) error { t, err := o.OAuthConfig.Exchange(o.ctx, code) if err != nil { return err } o.Client = o.OAuthConfig.Client(o.ctx, t) return nil }
go
func (o *OAuthSession) CodeAuth(code string) error { t, err := o.OAuthConfig.Exchange(o.ctx, code) if err != nil { return err } o.Client = o.OAuthConfig.Client(o.ctx, t) return nil }
[ "func", "(", "o", "*", "OAuthSession", ")", "CodeAuth", "(", "code", "string", ")", "error", "{", "t", ",", "err", ":=", "o", ".", "OAuthConfig", ".", "Exchange", "(", "o", ".", "ctx", ",", "code", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "o", ".", "Client", "=", "o", ".", "OAuthConfig", ".", "Client", "(", "o", ".", "ctx", ",", "t", ")", "\n", "return", "nil", "\n", "}" ]
// CodeAuth creates and sets a token using an authentication code returned from AuthCodeURL.
[ "CodeAuth", "creates", "and", "sets", "a", "token", "using", "an", "authentication", "code", "returned", "from", "AuthCodeURL", "." ]
a9d9445ed681c9bc2df9cce08998891b44efd806
https://github.com/jzelinskie/geddit/blob/a9d9445ed681c9bc2df9cce08998891b44efd806/oauth_session.go#L116-L123
10,818
jzelinskie/geddit
oauth_session.go
NeedsCaptcha
func (o *OAuthSession) NeedsCaptcha() (bool, error) { var b bool err := o.getBody("https://oauth.reddit.com/api/needs_captcha", &b) if err != nil { return false, err } return b, nil }
go
func (o *OAuthSession) NeedsCaptcha() (bool, error) { var b bool err := o.getBody("https://oauth.reddit.com/api/needs_captcha", &b) if err != nil { return false, err } return b, nil }
[ "func", "(", "o", "*", "OAuthSession", ")", "NeedsCaptcha", "(", ")", "(", "bool", ",", "error", ")", "{", "var", "b", "bool", "\n", "err", ":=", "o", ".", "getBody", "(", "\"", "\"", ",", "&", "b", ")", "\n", "if", "err", "!=", "nil", "{", "return", "false", ",", "err", "\n", "}", "\n", "return", "b", ",", "nil", "\n", "}" ]
// NeedsCaptcha check whether CAPTCHAs are needed for the Submit function.
[ "NeedsCaptcha", "check", "whether", "CAPTCHAs", "are", "needed", "for", "the", "Submit", "function", "." ]
a9d9445ed681c9bc2df9cce08998891b44efd806
https://github.com/jzelinskie/geddit/blob/a9d9445ed681c9bc2df9cce08998891b44efd806/oauth_session.go#L126-L133
10,819
jzelinskie/geddit
oauth_session.go
NewCaptcha
func (o *OAuthSession) NewCaptcha() (string, error) { // Build form for POST request. v := url.Values{ "api_type": {"json"}, } type captcha struct { Json struct { Errors [][]string Data struct { Iden string } } } c := &captcha{} err := o.postBody("https://oauth.reddit.com/api/new_captcha", v, c) if err != nil { return "", err } return c.Json.Data.Iden, nil }
go
func (o *OAuthSession) NewCaptcha() (string, error) { // Build form for POST request. v := url.Values{ "api_type": {"json"}, } type captcha struct { Json struct { Errors [][]string Data struct { Iden string } } } c := &captcha{} err := o.postBody("https://oauth.reddit.com/api/new_captcha", v, c) if err != nil { return "", err } return c.Json.Data.Iden, nil }
[ "func", "(", "o", "*", "OAuthSession", ")", "NewCaptcha", "(", ")", "(", "string", ",", "error", ")", "{", "// Build form for POST request.", "v", ":=", "url", ".", "Values", "{", "\"", "\"", ":", "{", "\"", "\"", "}", ",", "}", "\n\n", "type", "captcha", "struct", "{", "Json", "struct", "{", "Errors", "[", "]", "[", "]", "string", "\n", "Data", "struct", "{", "Iden", "string", "\n", "}", "\n", "}", "\n", "}", "\n", "c", ":=", "&", "captcha", "{", "}", "\n\n", "err", ":=", "o", ".", "postBody", "(", "\"", "\"", ",", "v", ",", "c", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "err", "\n", "}", "\n", "return", "c", ".", "Json", ".", "Data", ".", "Iden", ",", "nil", "\n", "}" ]
// NewCaptcha returns a string used to create CAPTCHA links for users.
[ "NewCaptcha", "returns", "a", "string", "used", "to", "create", "CAPTCHA", "links", "for", "users", "." ]
a9d9445ed681c9bc2df9cce08998891b44efd806
https://github.com/jzelinskie/geddit/blob/a9d9445ed681c9bc2df9cce08998891b44efd806/oauth_session.go#L136-L157
10,820
jzelinskie/geddit
oauth_session.go
AboutRedditor
func (o *OAuthSession) AboutRedditor(user string) (*Redditor, error) { type redditor struct { Data Redditor } r := &redditor{} link := fmt.Sprintf("https://oauth.reddit.com/user/%s/about", user) err := o.getBody(link, r) if err != nil { return nil, err } return &r.Data, nil }
go
func (o *OAuthSession) AboutRedditor(user string) (*Redditor, error) { type redditor struct { Data Redditor } r := &redditor{} link := fmt.Sprintf("https://oauth.reddit.com/user/%s/about", user) err := o.getBody(link, r) if err != nil { return nil, err } return &r.Data, nil }
[ "func", "(", "o", "*", "OAuthSession", ")", "AboutRedditor", "(", "user", "string", ")", "(", "*", "Redditor", ",", "error", ")", "{", "type", "redditor", "struct", "{", "Data", "Redditor", "\n", "}", "\n", "r", ":=", "&", "redditor", "{", "}", "\n", "link", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "user", ")", "\n\n", "err", ":=", "o", ".", "getBody", "(", "link", ",", "r", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "&", "r", ".", "Data", ",", "nil", "\n", "}" ]
// AboutRedditor returns a Redditor for the given username using OAuth.
[ "AboutRedditor", "returns", "a", "Redditor", "for", "the", "given", "username", "using", "OAuth", "." ]
a9d9445ed681c9bc2df9cce08998891b44efd806
https://github.com/jzelinskie/geddit/blob/a9d9445ed681c9bc2df9cce08998891b44efd806/oauth_session.go#L301-L313
10,821
jzelinskie/geddit
oauth_session.go
AboutSubreddit
func (o *OAuthSession) AboutSubreddit(name string) (*Subreddit, error) { type subreddit struct { Data Subreddit } sr := &subreddit{} link := fmt.Sprintf("https://oauth.reddit.com/r/%s/about", name) err := o.getBody(link, sr) if err != nil { return nil, err } return &sr.Data, nil }
go
func (o *OAuthSession) AboutSubreddit(name string) (*Subreddit, error) { type subreddit struct { Data Subreddit } sr := &subreddit{} link := fmt.Sprintf("https://oauth.reddit.com/r/%s/about", name) err := o.getBody(link, sr) if err != nil { return nil, err } return &sr.Data, nil }
[ "func", "(", "o", "*", "OAuthSession", ")", "AboutSubreddit", "(", "name", "string", ")", "(", "*", "Subreddit", ",", "error", ")", "{", "type", "subreddit", "struct", "{", "Data", "Subreddit", "\n", "}", "\n", "sr", ":=", "&", "subreddit", "{", "}", "\n", "link", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "name", ")", "\n\n", "err", ":=", "o", ".", "getBody", "(", "link", ",", "sr", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "&", "sr", ".", "Data", ",", "nil", "\n", "}" ]
// AboutSubreddit returns a subreddit for the given subreddit name using OAuth.
[ "AboutSubreddit", "returns", "a", "subreddit", "for", "the", "given", "subreddit", "name", "using", "OAuth", "." ]
a9d9445ed681c9bc2df9cce08998891b44efd806
https://github.com/jzelinskie/geddit/blob/a9d9445ed681c9bc2df9cce08998891b44efd806/oauth_session.go#L339-L351
10,822
jzelinskie/geddit
oauth_session.go
Comments
func (o *OAuthSession) Comments(h *Submission, sort PopularitySort, params ListingOptions) ([]*Comment, error) { p, err := query.Values(params) if err != nil { return nil, err } if sort != "" { p.Set("sort", string(sort)) } var c interface{} link := fmt.Sprintf("https://oauth.reddit.com/comments/%s?%s", h.ID, p.Encode()) err = o.getBody(link, &c) if err != nil { return nil, err } helper := new(helper) helper.buildComments(c) return helper.comments, nil }
go
func (o *OAuthSession) Comments(h *Submission, sort PopularitySort, params ListingOptions) ([]*Comment, error) { p, err := query.Values(params) if err != nil { return nil, err } if sort != "" { p.Set("sort", string(sort)) } var c interface{} link := fmt.Sprintf("https://oauth.reddit.com/comments/%s?%s", h.ID, p.Encode()) err = o.getBody(link, &c) if err != nil { return nil, err } helper := new(helper) helper.buildComments(c) return helper.comments, nil }
[ "func", "(", "o", "*", "OAuthSession", ")", "Comments", "(", "h", "*", "Submission", ",", "sort", "PopularitySort", ",", "params", "ListingOptions", ")", "(", "[", "]", "*", "Comment", ",", "error", ")", "{", "p", ",", "err", ":=", "query", ".", "Values", "(", "params", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "if", "sort", "!=", "\"", "\"", "{", "p", ".", "Set", "(", "\"", "\"", ",", "string", "(", "sort", ")", ")", "\n", "}", "\n\n", "var", "c", "interface", "{", "}", "\n", "link", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "h", ".", "ID", ",", "p", ".", "Encode", "(", ")", ")", "\n", "err", "=", "o", ".", "getBody", "(", "link", ",", "&", "c", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "helper", ":=", "new", "(", "helper", ")", "\n", "helper", ".", "buildComments", "(", "c", ")", "\n", "return", "helper", ".", "comments", ",", "nil", "\n", "}" ]
// Comments returns the comments for a given Submission using OAuth.
[ "Comments", "returns", "the", "comments", "for", "a", "given", "Submission", "using", "OAuth", "." ]
a9d9445ed681c9bc2df9cce08998891b44efd806
https://github.com/jzelinskie/geddit/blob/a9d9445ed681c9bc2df9cce08998891b44efd806/oauth_session.go#L354-L373
10,823
jzelinskie/geddit
oauth_session.go
Submit
func (o *OAuthSession) Submit(ns *NewSubmission) (*Submission, error) { // Build form for POST request. v := url.Values{ "title": {ns.Title}, "url": {ns.Content}, "text": {ns.Content}, "sr": {ns.Subreddit}, "sendreplies": {strconv.FormatBool(ns.SendReplies)}, "resubmit": {strconv.FormatBool(ns.Resubmit)}, "api_type": {"json"}, // TODO implement captchas for OAuth types //"captcha": {ns.Captcha.Response}, //"iden": {ns.Captcha.Iden}, } if ns.Self { v.Add("kind", "self") } else { v.Add("kind", "link") } type submission struct { Json struct { Errors [][]string Data Submission } } submit := &submission{} err := o.postBody("https://oauth.reddit.com/api/submit", v, submit) if err != nil { return nil, err } // TODO check s.Errors and do something useful? return &submit.Json.Data, nil }
go
func (o *OAuthSession) Submit(ns *NewSubmission) (*Submission, error) { // Build form for POST request. v := url.Values{ "title": {ns.Title}, "url": {ns.Content}, "text": {ns.Content}, "sr": {ns.Subreddit}, "sendreplies": {strconv.FormatBool(ns.SendReplies)}, "resubmit": {strconv.FormatBool(ns.Resubmit)}, "api_type": {"json"}, // TODO implement captchas for OAuth types //"captcha": {ns.Captcha.Response}, //"iden": {ns.Captcha.Iden}, } if ns.Self { v.Add("kind", "self") } else { v.Add("kind", "link") } type submission struct { Json struct { Errors [][]string Data Submission } } submit := &submission{} err := o.postBody("https://oauth.reddit.com/api/submit", v, submit) if err != nil { return nil, err } // TODO check s.Errors and do something useful? return &submit.Json.Data, nil }
[ "func", "(", "o", "*", "OAuthSession", ")", "Submit", "(", "ns", "*", "NewSubmission", ")", "(", "*", "Submission", ",", "error", ")", "{", "// Build form for POST request.", "v", ":=", "url", ".", "Values", "{", "\"", "\"", ":", "{", "ns", ".", "Title", "}", ",", "\"", "\"", ":", "{", "ns", ".", "Content", "}", ",", "\"", "\"", ":", "{", "ns", ".", "Content", "}", ",", "\"", "\"", ":", "{", "ns", ".", "Subreddit", "}", ",", "\"", "\"", ":", "{", "strconv", ".", "FormatBool", "(", "ns", ".", "SendReplies", ")", "}", ",", "\"", "\"", ":", "{", "strconv", ".", "FormatBool", "(", "ns", ".", "Resubmit", ")", "}", ",", "\"", "\"", ":", "{", "\"", "\"", "}", ",", "// TODO implement captchas for OAuth types", "//\"captcha\": {ns.Captcha.Response},", "//\"iden\": {ns.Captcha.Iden},", "}", "\n", "if", "ns", ".", "Self", "{", "v", ".", "Add", "(", "\"", "\"", ",", "\"", "\"", ")", "\n", "}", "else", "{", "v", ".", "Add", "(", "\"", "\"", ",", "\"", "\"", ")", "\n", "}", "\n\n", "type", "submission", "struct", "{", "Json", "struct", "{", "Errors", "[", "]", "[", "]", "string", "\n", "Data", "Submission", "\n", "}", "\n", "}", "\n", "submit", ":=", "&", "submission", "{", "}", "\n\n", "err", ":=", "o", ".", "postBody", "(", "\"", "\"", ",", "v", ",", "submit", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "// TODO check s.Errors and do something useful?", "return", "&", "submit", ".", "Json", ".", "Data", ",", "nil", "\n", "}" ]
// Submit accepts a NewSubmission type and submits a new link using OAuth. // Returns a Submission type.
[ "Submit", "accepts", "a", "NewSubmission", "type", "and", "submits", "a", "new", "link", "using", "OAuth", ".", "Returns", "a", "Submission", "type", "." ]
a9d9445ed681c9bc2df9cce08998891b44efd806
https://github.com/jzelinskie/geddit/blob/a9d9445ed681c9bc2df9cce08998891b44efd806/oauth_session.go#L416-L451
10,824
jzelinskie/geddit
oauth_session.go
Delete
func (o *OAuthSession) Delete(d Deleter) error { // Build form for POST request. v := url.Values{} v.Add("id", d.deleteID()) return o.postBody("https://oauth.reddit.com/api/del", v, nil) }
go
func (o *OAuthSession) Delete(d Deleter) error { // Build form for POST request. v := url.Values{} v.Add("id", d.deleteID()) return o.postBody("https://oauth.reddit.com/api/del", v, nil) }
[ "func", "(", "o", "*", "OAuthSession", ")", "Delete", "(", "d", "Deleter", ")", "error", "{", "// Build form for POST request.", "v", ":=", "url", ".", "Values", "{", "}", "\n", "v", ".", "Add", "(", "\"", "\"", ",", "d", ".", "deleteID", "(", ")", ")", "\n\n", "return", "o", ".", "postBody", "(", "\"", "\"", ",", "v", ",", "nil", ")", "\n", "}" ]
// Delete deletes a link or comment using the given full name ID.
[ "Delete", "deletes", "a", "link", "or", "comment", "using", "the", "given", "full", "name", "ID", "." ]
a9d9445ed681c9bc2df9cce08998891b44efd806
https://github.com/jzelinskie/geddit/blob/a9d9445ed681c9bc2df9cce08998891b44efd806/oauth_session.go#L454-L460
10,825
jzelinskie/geddit
oauth_session.go
SubredditSubmissions
func (o *OAuthSession) SubredditSubmissions(subreddit string, sort PopularitySort, params ListingOptions) ([]*Submission, error) { v, err := query.Values(params) if err != nil { return nil, err } baseUrl := "https://oauth.reddit.com" // If subbreddit given, add to URL if subreddit != "" { baseUrl += "/r/" + subreddit } redditURL := fmt.Sprintf(baseUrl+"/%s.json?%s", sort, v.Encode()) type Response struct { Data struct { Children []struct { Data *Submission } } } r := new(Response) err = o.getBody(redditURL, r) if err != nil { return nil, err } submissions := make([]*Submission, len(r.Data.Children)) for i, child := range r.Data.Children { submissions[i] = child.Data } return submissions, nil }
go
func (o *OAuthSession) SubredditSubmissions(subreddit string, sort PopularitySort, params ListingOptions) ([]*Submission, error) { v, err := query.Values(params) if err != nil { return nil, err } baseUrl := "https://oauth.reddit.com" // If subbreddit given, add to URL if subreddit != "" { baseUrl += "/r/" + subreddit } redditURL := fmt.Sprintf(baseUrl+"/%s.json?%s", sort, v.Encode()) type Response struct { Data struct { Children []struct { Data *Submission } } } r := new(Response) err = o.getBody(redditURL, r) if err != nil { return nil, err } submissions := make([]*Submission, len(r.Data.Children)) for i, child := range r.Data.Children { submissions[i] = child.Data } return submissions, nil }
[ "func", "(", "o", "*", "OAuthSession", ")", "SubredditSubmissions", "(", "subreddit", "string", ",", "sort", "PopularitySort", ",", "params", "ListingOptions", ")", "(", "[", "]", "*", "Submission", ",", "error", ")", "{", "v", ",", "err", ":=", "query", ".", "Values", "(", "params", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "baseUrl", ":=", "\"", "\"", "\n\n", "// If subbreddit given, add to URL", "if", "subreddit", "!=", "\"", "\"", "{", "baseUrl", "+=", "\"", "\"", "+", "subreddit", "\n", "}", "\n\n", "redditURL", ":=", "fmt", ".", "Sprintf", "(", "baseUrl", "+", "\"", "\"", ",", "sort", ",", "v", ".", "Encode", "(", ")", ")", "\n\n", "type", "Response", "struct", "{", "Data", "struct", "{", "Children", "[", "]", "struct", "{", "Data", "*", "Submission", "\n", "}", "\n", "}", "\n", "}", "\n\n", "r", ":=", "new", "(", "Response", ")", "\n", "err", "=", "o", ".", "getBody", "(", "redditURL", ",", "r", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "submissions", ":=", "make", "(", "[", "]", "*", "Submission", ",", "len", "(", "r", ".", "Data", ".", "Children", ")", ")", "\n", "for", "i", ",", "child", ":=", "range", "r", ".", "Data", ".", "Children", "{", "submissions", "[", "i", "]", "=", "child", ".", "Data", "\n", "}", "\n\n", "return", "submissions", ",", "nil", "\n", "}" ]
// SubredditSubmissions returns the submissions on the given subreddit using OAuth.
[ "SubredditSubmissions", "returns", "the", "submissions", "on", "the", "given", "subreddit", "using", "OAuth", "." ]
a9d9445ed681c9bc2df9cce08998891b44efd806
https://github.com/jzelinskie/geddit/blob/a9d9445ed681c9bc2df9cce08998891b44efd806/oauth_session.go#L463-L498
10,826
jzelinskie/geddit
oauth_session.go
Frontpage
func (o *OAuthSession) Frontpage(sort PopularitySort, params ListingOptions) ([]*Submission, error) { return o.SubredditSubmissions("", sort, params) }
go
func (o *OAuthSession) Frontpage(sort PopularitySort, params ListingOptions) ([]*Submission, error) { return o.SubredditSubmissions("", sort, params) }
[ "func", "(", "o", "*", "OAuthSession", ")", "Frontpage", "(", "sort", "PopularitySort", ",", "params", "ListingOptions", ")", "(", "[", "]", "*", "Submission", ",", "error", ")", "{", "return", "o", ".", "SubredditSubmissions", "(", "\"", "\"", ",", "sort", ",", "params", ")", "\n", "}" ]
// Frontpage returns the submissions on the default reddit frontpage using OAuth.
[ "Frontpage", "returns", "the", "submissions", "on", "the", "default", "reddit", "frontpage", "using", "OAuth", "." ]
a9d9445ed681c9bc2df9cce08998891b44efd806
https://github.com/jzelinskie/geddit/blob/a9d9445ed681c9bc2df9cce08998891b44efd806/oauth_session.go#L501-L503
10,827
jzelinskie/geddit
oauth_session.go
Vote
func (o *OAuthSession) Vote(v Voter, dir Vote) error { // Build form for POST request. form := url.Values{ "id": {v.voteID()}, "dir": {string(dir)}, } var vo interface{} err := o.postBody("https://oauth.reddit.com/api/vote", form, vo) if err != nil { return err } return nil }
go
func (o *OAuthSession) Vote(v Voter, dir Vote) error { // Build form for POST request. form := url.Values{ "id": {v.voteID()}, "dir": {string(dir)}, } var vo interface{} err := o.postBody("https://oauth.reddit.com/api/vote", form, vo) if err != nil { return err } return nil }
[ "func", "(", "o", "*", "OAuthSession", ")", "Vote", "(", "v", "Voter", ",", "dir", "Vote", ")", "error", "{", "// Build form for POST request.", "form", ":=", "url", ".", "Values", "{", "\"", "\"", ":", "{", "v", ".", "voteID", "(", ")", "}", ",", "\"", "\"", ":", "{", "string", "(", "dir", ")", "}", ",", "}", "\n", "var", "vo", "interface", "{", "}", "\n\n", "err", ":=", "o", ".", "postBody", "(", "\"", "\"", ",", "form", ",", "vo", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Vote either votes or rescinds a vote for a Submission or Comment using OAuth.
[ "Vote", "either", "votes", "or", "rescinds", "a", "vote", "for", "a", "Submission", "or", "Comment", "using", "OAuth", "." ]
a9d9445ed681c9bc2df9cce08998891b44efd806
https://github.com/jzelinskie/geddit/blob/a9d9445ed681c9bc2df9cce08998891b44efd806/oauth_session.go#L506-L519
10,828
jzelinskie/geddit
oauth_session.go
Reply
func (o OAuthSession) Reply(r Replier, comment string) (*Comment, error) { // Build form for POST request. form := url.Values{ "api_type": {"json"}, "thing_id": {r.replyID()}, "text": {comment}, } type response struct { JSON struct { Errors [][]string Data struct { Things []struct { Data map[string]interface{} } } } } res := &response{} err := o.postBody("https://oauth.reddit.com/api/comment", form, res) if err != nil { return nil, err } if len(res.JSON.Errors) != 0 { var msg []string for _, k := range res.JSON.Errors { msg = append(msg, k[1]) } return nil, errors.New(strings.Join(msg, ", ")) } c := makeComment(res.JSON.Data.Things[0].Data) return c, nil }
go
func (o OAuthSession) Reply(r Replier, comment string) (*Comment, error) { // Build form for POST request. form := url.Values{ "api_type": {"json"}, "thing_id": {r.replyID()}, "text": {comment}, } type response struct { JSON struct { Errors [][]string Data struct { Things []struct { Data map[string]interface{} } } } } res := &response{} err := o.postBody("https://oauth.reddit.com/api/comment", form, res) if err != nil { return nil, err } if len(res.JSON.Errors) != 0 { var msg []string for _, k := range res.JSON.Errors { msg = append(msg, k[1]) } return nil, errors.New(strings.Join(msg, ", ")) } c := makeComment(res.JSON.Data.Things[0].Data) return c, nil }
[ "func", "(", "o", "OAuthSession", ")", "Reply", "(", "r", "Replier", ",", "comment", "string", ")", "(", "*", "Comment", ",", "error", ")", "{", "// Build form for POST request.", "form", ":=", "url", ".", "Values", "{", "\"", "\"", ":", "{", "\"", "\"", "}", ",", "\"", "\"", ":", "{", "r", ".", "replyID", "(", ")", "}", ",", "\"", "\"", ":", "{", "comment", "}", ",", "}", "\n\n", "type", "response", "struct", "{", "JSON", "struct", "{", "Errors", "[", "]", "[", "]", "string", "\n", "Data", "struct", "{", "Things", "[", "]", "struct", "{", "Data", "map", "[", "string", "]", "interface", "{", "}", "\n", "}", "\n", "}", "\n", "}", "\n", "}", "\n\n", "res", ":=", "&", "response", "{", "}", "\n\n", "err", ":=", "o", ".", "postBody", "(", "\"", "\"", ",", "form", ",", "res", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "if", "len", "(", "res", ".", "JSON", ".", "Errors", ")", "!=", "0", "{", "var", "msg", "[", "]", "string", "\n", "for", "_", ",", "k", ":=", "range", "res", ".", "JSON", ".", "Errors", "{", "msg", "=", "append", "(", "msg", ",", "k", "[", "1", "]", ")", "\n", "}", "\n", "return", "nil", ",", "errors", ".", "New", "(", "strings", ".", "Join", "(", "msg", ",", "\"", "\"", ")", ")", "\n", "}", "\n\n", "c", ":=", "makeComment", "(", "res", ".", "JSON", ".", "Data", ".", "Things", "[", "0", "]", ".", "Data", ")", "\n\n", "return", "c", ",", "nil", "\n", "}" ]
// Reply posts a comment as a response to a Submission or Comment using OAuth.
[ "Reply", "posts", "a", "comment", "as", "a", "response", "to", "a", "Submission", "or", "Comment", "using", "OAuth", "." ]
a9d9445ed681c9bc2df9cce08998891b44efd806
https://github.com/jzelinskie/geddit/blob/a9d9445ed681c9bc2df9cce08998891b44efd806/oauth_session.go#L522-L559
10,829
jzelinskie/geddit
oauth_session.go
Save
func (o *OAuthSession) Save(v Voter, category string) error { // Build form for POST request. form := url.Values{ "id": {v.voteID()}, "category": {category}, } var s interface{} err := o.postBody("https://oauth.reddit.com/api/save", form, s) if err != nil { return err } return nil }
go
func (o *OAuthSession) Save(v Voter, category string) error { // Build form for POST request. form := url.Values{ "id": {v.voteID()}, "category": {category}, } var s interface{} err := o.postBody("https://oauth.reddit.com/api/save", form, s) if err != nil { return err } return nil }
[ "func", "(", "o", "*", "OAuthSession", ")", "Save", "(", "v", "Voter", ",", "category", "string", ")", "error", "{", "// Build form for POST request.", "form", ":=", "url", ".", "Values", "{", "\"", "\"", ":", "{", "v", ".", "voteID", "(", ")", "}", ",", "\"", "\"", ":", "{", "category", "}", ",", "}", "\n", "var", "s", "interface", "{", "}", "\n\n", "err", ":=", "o", ".", "postBody", "(", "\"", "\"", ",", "form", ",", "s", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Save saves a link or comment using OAuth.
[ "Save", "saves", "a", "link", "or", "comment", "using", "OAuth", "." ]
a9d9445ed681c9bc2df9cce08998891b44efd806
https://github.com/jzelinskie/geddit/blob/a9d9445ed681c9bc2df9cce08998891b44efd806/oauth_session.go#L562-L575
10,830
jzelinskie/geddit
oauth_session.go
Unsave
func (o *OAuthSession) Unsave(v Voter, category string) error { // Build form for POST request. form := url.Values{ "id": {v.voteID()}, "category": {category}, } var u interface{} err := o.postBody("https://oauth.reddit.com/api/unsave", form, u) if err != nil { return err } return nil }
go
func (o *OAuthSession) Unsave(v Voter, category string) error { // Build form for POST request. form := url.Values{ "id": {v.voteID()}, "category": {category}, } var u interface{} err := o.postBody("https://oauth.reddit.com/api/unsave", form, u) if err != nil { return err } return nil }
[ "func", "(", "o", "*", "OAuthSession", ")", "Unsave", "(", "v", "Voter", ",", "category", "string", ")", "error", "{", "// Build form for POST request.", "form", ":=", "url", ".", "Values", "{", "\"", "\"", ":", "{", "v", ".", "voteID", "(", ")", "}", ",", "\"", "\"", ":", "{", "category", "}", ",", "}", "\n", "var", "u", "interface", "{", "}", "\n\n", "err", ":=", "o", ".", "postBody", "(", "\"", "\"", ",", "form", ",", "u", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Unsave saves a link or comment using OAuth.
[ "Unsave", "saves", "a", "link", "or", "comment", "using", "OAuth", "." ]
a9d9445ed681c9bc2df9cce08998891b44efd806
https://github.com/jzelinskie/geddit/blob/a9d9445ed681c9bc2df9cce08998891b44efd806/oauth_session.go#L578-L591
10,831
jzelinskie/geddit
oauth_session.go
SavedLinks
func (o *OAuthSession) SavedLinks(username string, params ListingOptions) ([]*Submission, error) { return o.Listing(username, "saved", "", params) }
go
func (o *OAuthSession) SavedLinks(username string, params ListingOptions) ([]*Submission, error) { return o.Listing(username, "saved", "", params) }
[ "func", "(", "o", "*", "OAuthSession", ")", "SavedLinks", "(", "username", "string", ",", "params", "ListingOptions", ")", "(", "[", "]", "*", "Submission", ",", "error", ")", "{", "return", "o", ".", "Listing", "(", "username", ",", "\"", "\"", ",", "\"", "\"", ",", "params", ")", "\n", "}" ]
// SavedLinks fetches links saved by given username using OAuth.
[ "SavedLinks", "fetches", "links", "saved", "by", "given", "username", "using", "OAuth", "." ]
a9d9445ed681c9bc2df9cce08998891b44efd806
https://github.com/jzelinskie/geddit/blob/a9d9445ed681c9bc2df9cce08998891b44efd806/oauth_session.go#L594-L596
10,832
jzelinskie/geddit
oauth_session.go
MySavedLinks
func (o *OAuthSession) MySavedLinks(params ListingOptions) ([]*Submission, error) { me, err := o.Me() if err != nil { return nil, err } return o.Listing(me.Name, "saved", "", params) }
go
func (o *OAuthSession) MySavedLinks(params ListingOptions) ([]*Submission, error) { me, err := o.Me() if err != nil { return nil, err } return o.Listing(me.Name, "saved", "", params) }
[ "func", "(", "o", "*", "OAuthSession", ")", "MySavedLinks", "(", "params", "ListingOptions", ")", "(", "[", "]", "*", "Submission", ",", "error", ")", "{", "me", ",", "err", ":=", "o", ".", "Me", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "o", ".", "Listing", "(", "me", ".", "Name", ",", "\"", "\"", ",", "\"", "\"", ",", "params", ")", "\n", "}" ]
// MySavedLinks fetches links saved by current user using OAuth.
[ "MySavedLinks", "fetches", "links", "saved", "by", "current", "user", "using", "OAuth", "." ]
a9d9445ed681c9bc2df9cce08998891b44efd806
https://github.com/jzelinskie/geddit/blob/a9d9445ed681c9bc2df9cce08998891b44efd806/oauth_session.go#L599-L605
10,833
jzelinskie/geddit
oauth_session.go
SavedComments
func (o *OAuthSession) SavedComments(user string, params ListingOptions) ([]*Comment, error) { var s interface{} url := fmt.Sprintf("https://oauth.reddit.com/user/%s/saved", user) err := o.getBody(url, &s) if err != nil { return nil, err } helper := new(helper) helper.buildComments(s) return helper.comments, nil }
go
func (o *OAuthSession) SavedComments(user string, params ListingOptions) ([]*Comment, error) { var s interface{} url := fmt.Sprintf("https://oauth.reddit.com/user/%s/saved", user) err := o.getBody(url, &s) if err != nil { return nil, err } helper := new(helper) helper.buildComments(s) return helper.comments, nil }
[ "func", "(", "o", "*", "OAuthSession", ")", "SavedComments", "(", "user", "string", ",", "params", "ListingOptions", ")", "(", "[", "]", "*", "Comment", ",", "error", ")", "{", "var", "s", "interface", "{", "}", "\n", "url", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "user", ")", "\n", "err", ":=", "o", ".", "getBody", "(", "url", ",", "&", "s", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "helper", ":=", "new", "(", "helper", ")", "\n", "helper", ".", "buildComments", "(", "s", ")", "\n", "return", "helper", ".", "comments", ",", "nil", "\n", "}" ]
// SavedComments fetches comments saved by given username using OAuth.
[ "SavedComments", "fetches", "comments", "saved", "by", "given", "username", "using", "OAuth", "." ]
a9d9445ed681c9bc2df9cce08998891b44efd806
https://github.com/jzelinskie/geddit/blob/a9d9445ed681c9bc2df9cce08998891b44efd806/oauth_session.go#L608-L619
10,834
jzelinskie/geddit
oauth_session.go
MySavedComments
func (o *OAuthSession) MySavedComments(params ListingOptions) ([]*Comment, error) { me, err := o.Me() if err != nil { return nil, err } return o.SavedComments(me.Name, params) }
go
func (o *OAuthSession) MySavedComments(params ListingOptions) ([]*Comment, error) { me, err := o.Me() if err != nil { return nil, err } return o.SavedComments(me.Name, params) }
[ "func", "(", "o", "*", "OAuthSession", ")", "MySavedComments", "(", "params", "ListingOptions", ")", "(", "[", "]", "*", "Comment", ",", "error", ")", "{", "me", ",", "err", ":=", "o", ".", "Me", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "o", ".", "SavedComments", "(", "me", ".", "Name", ",", "params", ")", "\n", "}" ]
// MySavedComments fetches comments saved by current user using OAuth.
[ "MySavedComments", "fetches", "comments", "saved", "by", "current", "user", "using", "OAuth", "." ]
a9d9445ed681c9bc2df9cce08998891b44efd806
https://github.com/jzelinskie/geddit/blob/a9d9445ed681c9bc2df9cce08998891b44efd806/oauth_session.go#L622-L628
10,835
jzelinskie/geddit
submission.go
String
func (h *Submission) String() string { plural := "" if h.NumComments != 1 { plural = "s" } comments := fmt.Sprintf("%d comment%s", h.NumComments, plural) return fmt.Sprintf("%d - %s (%s)", h.Score, h.Title, comments) }
go
func (h *Submission) String() string { plural := "" if h.NumComments != 1 { plural = "s" } comments := fmt.Sprintf("%d comment%s", h.NumComments, plural) return fmt.Sprintf("%d - %s (%s)", h.Score, h.Title, comments) }
[ "func", "(", "h", "*", "Submission", ")", "String", "(", ")", "string", "{", "plural", ":=", "\"", "\"", "\n", "if", "h", ".", "NumComments", "!=", "1", "{", "plural", "=", "\"", "\"", "\n", "}", "\n", "comments", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "h", ".", "NumComments", ",", "plural", ")", "\n", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "h", ".", "Score", ",", "h", ".", "Title", ",", "comments", ")", "\n", "}" ]
// String returns the string representation of a submission.
[ "String", "returns", "the", "string", "representation", "of", "a", "submission", "." ]
a9d9445ed681c9bc2df9cce08998891b44efd806
https://github.com/jzelinskie/geddit/blob/a9d9445ed681c9bc2df9cce08998891b44efd806/submission.go#L50-L57
10,836
weaveworks/go-odp
odp/flow.go
present
func (ta TunnelAttrs) present() TunnelAttrsPresence { // The kernel requires Ipv4Dst and Ttl to be present, so we // always mark those as present, even if we end up wildcarding // them. return TunnelAttrsPresence{ TunnelId: !AllBytes(ta.TunnelId[:], 0), Ipv4Src: !AllBytes(ta.Ipv4Src[:], 0), Ipv4Dst: true, Tos: ta.Tos != 0, Ttl: true, Df: ta.Df, Csum: ta.Csum, TpSrc: ta.TpSrc != 0, TpDst: ta.TpDst != 0, } }
go
func (ta TunnelAttrs) present() TunnelAttrsPresence { // The kernel requires Ipv4Dst and Ttl to be present, so we // always mark those as present, even if we end up wildcarding // them. return TunnelAttrsPresence{ TunnelId: !AllBytes(ta.TunnelId[:], 0), Ipv4Src: !AllBytes(ta.Ipv4Src[:], 0), Ipv4Dst: true, Tos: ta.Tos != 0, Ttl: true, Df: ta.Df, Csum: ta.Csum, TpSrc: ta.TpSrc != 0, TpDst: ta.TpDst != 0, } }
[ "func", "(", "ta", "TunnelAttrs", ")", "present", "(", ")", "TunnelAttrsPresence", "{", "// The kernel requires Ipv4Dst and Ttl to be present, so we", "// always mark those as present, even if we end up wildcarding", "// them.", "return", "TunnelAttrsPresence", "{", "TunnelId", ":", "!", "AllBytes", "(", "ta", ".", "TunnelId", "[", ":", "]", ",", "0", ")", ",", "Ipv4Src", ":", "!", "AllBytes", "(", "ta", ".", "Ipv4Src", "[", ":", "]", ",", "0", ")", ",", "Ipv4Dst", ":", "true", ",", "Tos", ":", "ta", ".", "Tos", "!=", "0", ",", "Ttl", ":", "true", ",", "Df", ":", "ta", ".", "Df", ",", "Csum", ":", "ta", ".", "Csum", ",", "TpSrc", ":", "ta", ".", "TpSrc", "!=", "0", ",", "TpDst", ":", "ta", ".", "TpDst", "!=", "0", ",", "}", "\n", "}" ]
// Extract presence information from a TunnelAttrs mask
[ "Extract", "presence", "information", "from", "a", "TunnelAttrs", "mask" ]
6b0aa22550d9325eb8f43418185859e13dc0de1d
https://github.com/weaveworks/go-odp/blob/6b0aa22550d9325eb8f43418185859e13dc0de1d/odp/flow.go#L539-L554
10,837
weaveworks/go-odp
odp/flow.go
mask
func (tap TunnelAttrsPresence) mask() (res TunnelAttrs) { if tap.TunnelId { res.TunnelId = [8]byte{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, } } if tap.Ipv4Src { res.Ipv4Src = [4]byte{0xff, 0xff, 0xff, 0xff} } if tap.Ipv4Dst { res.Ipv4Dst = [4]byte{0xff, 0xff, 0xff, 0xff} } if tap.Tos { res.Tos = 0xff } if tap.Ttl { res.Ttl = 0xff } res.Df = tap.Df res.Csum = tap.Csum if tap.TpSrc { res.TpSrc = 0xffff } if tap.TpDst { res.TpDst = 0xffff } return }
go
func (tap TunnelAttrsPresence) mask() (res TunnelAttrs) { if tap.TunnelId { res.TunnelId = [8]byte{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, } } if tap.Ipv4Src { res.Ipv4Src = [4]byte{0xff, 0xff, 0xff, 0xff} } if tap.Ipv4Dst { res.Ipv4Dst = [4]byte{0xff, 0xff, 0xff, 0xff} } if tap.Tos { res.Tos = 0xff } if tap.Ttl { res.Ttl = 0xff } res.Df = tap.Df res.Csum = tap.Csum if tap.TpSrc { res.TpSrc = 0xffff } if tap.TpDst { res.TpDst = 0xffff } return }
[ "func", "(", "tap", "TunnelAttrsPresence", ")", "mask", "(", ")", "(", "res", "TunnelAttrs", ")", "{", "if", "tap", ".", "TunnelId", "{", "res", ".", "TunnelId", "=", "[", "8", "]", "byte", "{", "0xff", ",", "0xff", ",", "0xff", ",", "0xff", ",", "0xff", ",", "0xff", ",", "0xff", ",", "0xff", ",", "}", "\n", "}", "\n\n", "if", "tap", ".", "Ipv4Src", "{", "res", ".", "Ipv4Src", "=", "[", "4", "]", "byte", "{", "0xff", ",", "0xff", ",", "0xff", ",", "0xff", "}", "\n", "}", "\n\n", "if", "tap", ".", "Ipv4Dst", "{", "res", ".", "Ipv4Dst", "=", "[", "4", "]", "byte", "{", "0xff", ",", "0xff", ",", "0xff", ",", "0xff", "}", "\n", "}", "\n\n", "if", "tap", ".", "Tos", "{", "res", ".", "Tos", "=", "0xff", "\n", "}", "\n\n", "if", "tap", ".", "Ttl", "{", "res", ".", "Ttl", "=", "0xff", "\n", "}", "\n\n", "res", ".", "Df", "=", "tap", ".", "Df", "\n", "res", ".", "Csum", "=", "tap", ".", "Csum", "\n\n", "if", "tap", ".", "TpSrc", "{", "res", ".", "TpSrc", "=", "0xffff", "\n", "}", "\n\n", "if", "tap", ".", "TpDst", "{", "res", ".", "TpDst", "=", "0xffff", "\n", "}", "\n\n", "return", "\n", "}" ]
// Convert a TunnelAttrsPresence to a mask
[ "Convert", "a", "TunnelAttrsPresence", "to", "a", "mask" ]
6b0aa22550d9325eb8f43418185859e13dc0de1d
https://github.com/weaveworks/go-odp/blob/6b0aa22550d9325eb8f43418185859e13dc0de1d/odp/flow.go#L557-L593
10,838
weaveworks/go-odp
odp/netlink.go
expand
func expand(buf []byte, l int) []byte { c := (cap(buf) + 1) * 3 / 2 for l > c { c = (c + 1) * 3 / 2 } new := MakeAlignedByteSliceCap(len(buf), c) copy(new, buf) return new }
go
func expand(buf []byte, l int) []byte { c := (cap(buf) + 1) * 3 / 2 for l > c { c = (c + 1) * 3 / 2 } new := MakeAlignedByteSliceCap(len(buf), c) copy(new, buf) return new }
[ "func", "expand", "(", "buf", "[", "]", "byte", ",", "l", "int", ")", "[", "]", "byte", "{", "c", ":=", "(", "cap", "(", "buf", ")", "+", "1", ")", "*", "3", "/", "2", "\n", "for", "l", ">", "c", "{", "c", "=", "(", "c", "+", "1", ")", "*", "3", "/", "2", "\n", "}", "\n", "new", ":=", "MakeAlignedByteSliceCap", "(", "len", "(", "buf", ")", ",", "c", ")", "\n", "copy", "(", "new", ",", "buf", ")", "\n", "return", "new", "\n", "}" ]
// Expand the array underlying a slice to have capacity of at least l
[ "Expand", "the", "array", "underlying", "a", "slice", "to", "have", "capacity", "of", "at", "least", "l" ]
6b0aa22550d9325eb8f43418185859e13dc0de1d
https://github.com/weaveworks/go-odp/blob/6b0aa22550d9325eb8f43418185859e13dc0de1d/odp/netlink.go#L97-L105
10,839
weaveworks/go-odp
odp/netlink.go
Request
func (s *NetlinkSocket) Request(req *NlMsgBuilder) (resp *NlMsgParser, err error) { seq, err := s.send(req) if err != nil { return nil, err } err = s.Receive(func(msg *NlMsgParser) (bool, error) { relevant, err := msg.checkResponseHeader(s.PortId(), seq) if relevant && err == nil { resp = msg } return true, err }) return }
go
func (s *NetlinkSocket) Request(req *NlMsgBuilder) (resp *NlMsgParser, err error) { seq, err := s.send(req) if err != nil { return nil, err } err = s.Receive(func(msg *NlMsgParser) (bool, error) { relevant, err := msg.checkResponseHeader(s.PortId(), seq) if relevant && err == nil { resp = msg } return true, err }) return }
[ "func", "(", "s", "*", "NetlinkSocket", ")", "Request", "(", "req", "*", "NlMsgBuilder", ")", "(", "resp", "*", "NlMsgParser", ",", "err", "error", ")", "{", "seq", ",", "err", ":=", "s", ".", "send", "(", "req", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "err", "=", "s", ".", "Receive", "(", "func", "(", "msg", "*", "NlMsgParser", ")", "(", "bool", ",", "error", ")", "{", "relevant", ",", "err", ":=", "msg", ".", "checkResponseHeader", "(", "s", ".", "PortId", "(", ")", ",", "seq", ")", "\n", "if", "relevant", "&&", "err", "==", "nil", "{", "resp", "=", "msg", "\n", "}", "\n", "return", "true", ",", "err", "\n", "}", ")", "\n", "return", "\n", "}" ]
// Do a netlink request that yields a single response message.
[ "Do", "a", "netlink", "request", "that", "yields", "a", "single", "response", "message", "." ]
6b0aa22550d9325eb8f43418185859e13dc0de1d
https://github.com/weaveworks/go-odp/blob/6b0aa22550d9325eb8f43418185859e13dc0de1d/odp/netlink.go#L611-L625
10,840
weaveworks/go-odp
odp/netlink.go
RequestMulti
func (s *NetlinkSocket) RequestMulti(req *NlMsgBuilder, consumer func(*NlMsgParser) error) error { seq, err := s.send(req) if err != nil { return err } return s.Receive(func(msg *NlMsgParser) (bool, error) { relevant, err := msg.checkResponseHeader(s.PortId(), seq) if !relevant || err != nil { return false, err } if msg.NlMsghdr().Type == syscall.NLMSG_DONE { return true, processNlMsgDone(msg) } err = consumer(msg) if err != nil { return true, err } return false, nil }) }
go
func (s *NetlinkSocket) RequestMulti(req *NlMsgBuilder, consumer func(*NlMsgParser) error) error { seq, err := s.send(req) if err != nil { return err } return s.Receive(func(msg *NlMsgParser) (bool, error) { relevant, err := msg.checkResponseHeader(s.PortId(), seq) if !relevant || err != nil { return false, err } if msg.NlMsghdr().Type == syscall.NLMSG_DONE { return true, processNlMsgDone(msg) } err = consumer(msg) if err != nil { return true, err } return false, nil }) }
[ "func", "(", "s", "*", "NetlinkSocket", ")", "RequestMulti", "(", "req", "*", "NlMsgBuilder", ",", "consumer", "func", "(", "*", "NlMsgParser", ")", "error", ")", "error", "{", "seq", ",", "err", ":=", "s", ".", "send", "(", "req", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "return", "s", ".", "Receive", "(", "func", "(", "msg", "*", "NlMsgParser", ")", "(", "bool", ",", "error", ")", "{", "relevant", ",", "err", ":=", "msg", ".", "checkResponseHeader", "(", "s", ".", "PortId", "(", ")", ",", "seq", ")", "\n", "if", "!", "relevant", "||", "err", "!=", "nil", "{", "return", "false", ",", "err", "\n", "}", "\n\n", "if", "msg", ".", "NlMsghdr", "(", ")", ".", "Type", "==", "syscall", ".", "NLMSG_DONE", "{", "return", "true", ",", "processNlMsgDone", "(", "msg", ")", "\n", "}", "\n\n", "err", "=", "consumer", "(", "msg", ")", "\n", "if", "err", "!=", "nil", "{", "return", "true", ",", "err", "\n", "}", "\n\n", "return", "false", ",", "nil", "\n", "}", ")", "\n", "}" ]
// Do a netlink request that yield multiple response messages.
[ "Do", "a", "netlink", "request", "that", "yield", "multiple", "response", "messages", "." ]
6b0aa22550d9325eb8f43418185859e13dc0de1d
https://github.com/weaveworks/go-odp/blob/6b0aa22550d9325eb8f43418185859e13dc0de1d/odp/netlink.go#L630-L653
10,841
weaveworks/go-odp
odp/dpif.go
loadOpenvswitchModule
func loadOpenvswitchModule() { if triedLoadOpenvswitchModule { return } // netdev ioctls don't seem to work on netlink sockets, so we // need a new socket for this purpose. s, err := syscall.Socket(syscall.AF_INET, syscall.SOCK_DGRAM, 0) if err != nil { triedLoadOpenvswitchModule = true return } defer syscall.Close(s) var req ifreqIfindex copy(req.name[:], []byte("openvswitch")) syscall.Syscall(syscall.SYS_IOCTL, uintptr(s), syscall.SIOCGIFINDEX, uintptr(unsafe.Pointer(&req))) triedLoadOpenvswitchModule = true }
go
func loadOpenvswitchModule() { if triedLoadOpenvswitchModule { return } // netdev ioctls don't seem to work on netlink sockets, so we // need a new socket for this purpose. s, err := syscall.Socket(syscall.AF_INET, syscall.SOCK_DGRAM, 0) if err != nil { triedLoadOpenvswitchModule = true return } defer syscall.Close(s) var req ifreqIfindex copy(req.name[:], []byte("openvswitch")) syscall.Syscall(syscall.SYS_IOCTL, uintptr(s), syscall.SIOCGIFINDEX, uintptr(unsafe.Pointer(&req))) triedLoadOpenvswitchModule = true }
[ "func", "loadOpenvswitchModule", "(", ")", "{", "if", "triedLoadOpenvswitchModule", "{", "return", "\n", "}", "\n\n", "// netdev ioctls don't seem to work on netlink sockets, so we", "// need a new socket for this purpose.", "s", ",", "err", ":=", "syscall", ".", "Socket", "(", "syscall", ".", "AF_INET", ",", "syscall", ".", "SOCK_DGRAM", ",", "0", ")", "\n", "if", "err", "!=", "nil", "{", "triedLoadOpenvswitchModule", "=", "true", "\n", "return", "\n", "}", "\n\n", "defer", "syscall", ".", "Close", "(", "s", ")", "\n\n", "var", "req", "ifreqIfindex", "\n", "copy", "(", "req", ".", "name", "[", ":", "]", ",", "[", "]", "byte", "(", "\"", "\"", ")", ")", "\n", "syscall", ".", "Syscall", "(", "syscall", ".", "SYS_IOCTL", ",", "uintptr", "(", "s", ")", ",", "syscall", ".", "SIOCGIFINDEX", ",", "uintptr", "(", "unsafe", ".", "Pointer", "(", "&", "req", ")", ")", ")", "\n", "triedLoadOpenvswitchModule", "=", "true", "\n", "}" ]
// This tries to provoke the kernel into loading the openvswitch // module. Yes, netdev ioctls can be used to load arbitrary modules, // if you have CAP_SYS_MODULE.
[ "This", "tries", "to", "provoke", "the", "kernel", "into", "loading", "the", "openvswitch", "module", ".", "Yes", "netdev", "ioctls", "can", "be", "used", "to", "load", "arbitrary", "modules", "if", "you", "have", "CAP_SYS_MODULE", "." ]
6b0aa22550d9325eb8f43418185859e13dc0de1d
https://github.com/weaveworks/go-odp/blob/6b0aa22550d9325eb8f43418185859e13dc0de1d/odp/dpif.go#L70-L90
10,842
weaveworks/go-odp
odp/dpif.go
Reopen
func (dpif *Dpif) Reopen() (*Dpif, error) { sock, err := OpenNetlinkSocket(syscall.NETLINK_GENERIC) if err != nil { return nil, err } return &Dpif{sock: sock, families: dpif.families}, nil }
go
func (dpif *Dpif) Reopen() (*Dpif, error) { sock, err := OpenNetlinkSocket(syscall.NETLINK_GENERIC) if err != nil { return nil, err } return &Dpif{sock: sock, families: dpif.families}, nil }
[ "func", "(", "dpif", "*", "Dpif", ")", "Reopen", "(", ")", "(", "*", "Dpif", ",", "error", ")", "{", "sock", ",", "err", ":=", "OpenNetlinkSocket", "(", "syscall", ".", "NETLINK_GENERIC", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "&", "Dpif", "{", "sock", ":", "sock", ",", "families", ":", "dpif", ".", "families", "}", ",", "nil", "\n", "}" ]
// Open a dpif with a new socket, but reuing the family info
[ "Open", "a", "dpif", "with", "a", "new", "socket", "but", "reuing", "the", "family", "info" ]
6b0aa22550d9325eb8f43418185859e13dc0de1d
https://github.com/weaveworks/go-odp/blob/6b0aa22550d9325eb8f43418185859e13dc0de1d/odp/dpif.go#L112-L119
10,843
cloudfoundry/bosh-gcscli
config/config.go
FitCompatibleLocation
func (c *GCSCli) FitCompatibleLocation(loc string) error { if c.StorageClass == "" { var err error if c.StorageClass, err = getDefaultStorageClass(loc); err != nil { return err } } _, regional := GCSRegionalLocations[loc] _, multiRegional := GCSMultiRegionalLocations[loc] if !(regional || multiRegional) { return ErrUnknownLocation } if _, ok := GCSStorageClass[c.StorageClass]; !ok { return ErrUnknownStorageClass } return validLocationStorageClass(loc, c.StorageClass) }
go
func (c *GCSCli) FitCompatibleLocation(loc string) error { if c.StorageClass == "" { var err error if c.StorageClass, err = getDefaultStorageClass(loc); err != nil { return err } } _, regional := GCSRegionalLocations[loc] _, multiRegional := GCSMultiRegionalLocations[loc] if !(regional || multiRegional) { return ErrUnknownLocation } if _, ok := GCSStorageClass[c.StorageClass]; !ok { return ErrUnknownStorageClass } return validLocationStorageClass(loc, c.StorageClass) }
[ "func", "(", "c", "*", "GCSCli", ")", "FitCompatibleLocation", "(", "loc", "string", ")", "error", "{", "if", "c", ".", "StorageClass", "==", "\"", "\"", "{", "var", "err", "error", "\n", "if", "c", ".", "StorageClass", ",", "err", "=", "getDefaultStorageClass", "(", "loc", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n\n", "_", ",", "regional", ":=", "GCSRegionalLocations", "[", "loc", "]", "\n", "_", ",", "multiRegional", ":=", "GCSMultiRegionalLocations", "[", "loc", "]", "\n", "if", "!", "(", "regional", "||", "multiRegional", ")", "{", "return", "ErrUnknownLocation", "\n", "}", "\n\n", "if", "_", ",", "ok", ":=", "GCSStorageClass", "[", "c", ".", "StorageClass", "]", ";", "!", "ok", "{", "return", "ErrUnknownStorageClass", "\n", "}", "\n\n", "return", "validLocationStorageClass", "(", "loc", ",", "c", ".", "StorageClass", ")", "\n", "}" ]
// FitCompatibleLocation returns whether a provided Location // can have c.StorageClass objects written to it. // // When c.StorageClass is empty, a compatible default is filled in. // // nil return value when compatible, otherwise a non-nil explanation.
[ "FitCompatibleLocation", "returns", "whether", "a", "provided", "Location", "can", "have", "c", ".", "StorageClass", "objects", "written", "to", "it", ".", "When", "c", ".", "StorageClass", "is", "empty", "a", "compatible", "default", "is", "filled", "in", ".", "nil", "return", "value", "when", "compatible", "otherwise", "a", "non", "-", "nil", "explanation", "." ]
2aef468b5b8561560918014b4fbce7549de2283d
https://github.com/cloudfoundry/bosh-gcscli/blob/2aef468b5b8561560918014b4fbce7549de2283d/config/config.go#L127-L146
10,844
cloudfoundry/bosh-gcscli
integration/assertions.go
AssertLifecycleWorks
func AssertLifecycleWorks(gcsCLIPath string, ctx AssertContext) { session, err := RunGCSCLI(gcsCLIPath, ctx.ConfigPath, "put", ctx.ContentFile, ctx.GCSFileName) Expect(err).ToNot(HaveOccurred()) Expect(session.ExitCode()).To(BeZero()) session, err = RunGCSCLI(gcsCLIPath, ctx.ConfigPath, "exists", ctx.GCSFileName) Expect(err).ToNot(HaveOccurred()) Expect(session.ExitCode()).To(BeZero()) Expect(session.Err.Contents()).To(MatchRegexp("File '.*' exists in bucket '.*'")) tmpLocalFile, err := ioutil.TempFile("", "gcscli-download") Expect(err).ToNot(HaveOccurred()) defer func() { _ = os.Remove(tmpLocalFile.Name()) }() err = tmpLocalFile.Close() Expect(err).ToNot(HaveOccurred()) session, err = RunGCSCLI(gcsCLIPath, ctx.ConfigPath, "get", ctx.GCSFileName, tmpLocalFile.Name()) Expect(err).ToNot(HaveOccurred()) Expect(session.ExitCode()).To(BeZero()) gottenBytes, err := ioutil.ReadFile(tmpLocalFile.Name()) Expect(err).ToNot(HaveOccurred()) Expect(string(gottenBytes)).To(Equal(ctx.ExpectedString)) session, err = RunGCSCLI(gcsCLIPath, ctx.ConfigPath, "delete", ctx.GCSFileName) Expect(err).ToNot(HaveOccurred()) Expect(session.ExitCode()).To(BeZero()) session, err = RunGCSCLI(gcsCLIPath, ctx.ConfigPath, "exists", ctx.GCSFileName) Expect(err).ToNot(HaveOccurred()) Expect(session.ExitCode()).To(Equal(3)) Expect(session.Err.Contents()).To(MatchRegexp("File '.*' does not exist in bucket '.*'")) }
go
func AssertLifecycleWorks(gcsCLIPath string, ctx AssertContext) { session, err := RunGCSCLI(gcsCLIPath, ctx.ConfigPath, "put", ctx.ContentFile, ctx.GCSFileName) Expect(err).ToNot(HaveOccurred()) Expect(session.ExitCode()).To(BeZero()) session, err = RunGCSCLI(gcsCLIPath, ctx.ConfigPath, "exists", ctx.GCSFileName) Expect(err).ToNot(HaveOccurred()) Expect(session.ExitCode()).To(BeZero()) Expect(session.Err.Contents()).To(MatchRegexp("File '.*' exists in bucket '.*'")) tmpLocalFile, err := ioutil.TempFile("", "gcscli-download") Expect(err).ToNot(HaveOccurred()) defer func() { _ = os.Remove(tmpLocalFile.Name()) }() err = tmpLocalFile.Close() Expect(err).ToNot(HaveOccurred()) session, err = RunGCSCLI(gcsCLIPath, ctx.ConfigPath, "get", ctx.GCSFileName, tmpLocalFile.Name()) Expect(err).ToNot(HaveOccurred()) Expect(session.ExitCode()).To(BeZero()) gottenBytes, err := ioutil.ReadFile(tmpLocalFile.Name()) Expect(err).ToNot(HaveOccurred()) Expect(string(gottenBytes)).To(Equal(ctx.ExpectedString)) session, err = RunGCSCLI(gcsCLIPath, ctx.ConfigPath, "delete", ctx.GCSFileName) Expect(err).ToNot(HaveOccurred()) Expect(session.ExitCode()).To(BeZero()) session, err = RunGCSCLI(gcsCLIPath, ctx.ConfigPath, "exists", ctx.GCSFileName) Expect(err).ToNot(HaveOccurred()) Expect(session.ExitCode()).To(Equal(3)) Expect(session.Err.Contents()).To(MatchRegexp("File '.*' does not exist in bucket '.*'")) }
[ "func", "AssertLifecycleWorks", "(", "gcsCLIPath", "string", ",", "ctx", "AssertContext", ")", "{", "session", ",", "err", ":=", "RunGCSCLI", "(", "gcsCLIPath", ",", "ctx", ".", "ConfigPath", ",", "\"", "\"", ",", "ctx", ".", "ContentFile", ",", "ctx", ".", "GCSFileName", ")", "\n", "Expect", "(", "err", ")", ".", "ToNot", "(", "HaveOccurred", "(", ")", ")", "\n", "Expect", "(", "session", ".", "ExitCode", "(", ")", ")", ".", "To", "(", "BeZero", "(", ")", ")", "\n\n", "session", ",", "err", "=", "RunGCSCLI", "(", "gcsCLIPath", ",", "ctx", ".", "ConfigPath", ",", "\"", "\"", ",", "ctx", ".", "GCSFileName", ")", "\n", "Expect", "(", "err", ")", ".", "ToNot", "(", "HaveOccurred", "(", ")", ")", "\n", "Expect", "(", "session", ".", "ExitCode", "(", ")", ")", ".", "To", "(", "BeZero", "(", ")", ")", "\n", "Expect", "(", "session", ".", "Err", ".", "Contents", "(", ")", ")", ".", "To", "(", "MatchRegexp", "(", "\"", "\"", ")", ")", "\n\n", "tmpLocalFile", ",", "err", ":=", "ioutil", ".", "TempFile", "(", "\"", "\"", ",", "\"", "\"", ")", "\n", "Expect", "(", "err", ")", ".", "ToNot", "(", "HaveOccurred", "(", ")", ")", "\n", "defer", "func", "(", ")", "{", "_", "=", "os", ".", "Remove", "(", "tmpLocalFile", ".", "Name", "(", ")", ")", "}", "(", ")", "\n", "err", "=", "tmpLocalFile", ".", "Close", "(", ")", "\n", "Expect", "(", "err", ")", ".", "ToNot", "(", "HaveOccurred", "(", ")", ")", "\n\n", "session", ",", "err", "=", "RunGCSCLI", "(", "gcsCLIPath", ",", "ctx", ".", "ConfigPath", ",", "\"", "\"", ",", "ctx", ".", "GCSFileName", ",", "tmpLocalFile", ".", "Name", "(", ")", ")", "\n", "Expect", "(", "err", ")", ".", "ToNot", "(", "HaveOccurred", "(", ")", ")", "\n", "Expect", "(", "session", ".", "ExitCode", "(", ")", ")", ".", "To", "(", "BeZero", "(", ")", ")", "\n\n", "gottenBytes", ",", "err", ":=", "ioutil", ".", "ReadFile", "(", "tmpLocalFile", ".", "Name", "(", ")", ")", "\n", "Expect", "(", "err", ")", ".", "ToNot", "(", "HaveOccurred", "(", ")", ")", "\n", "Expect", "(", "string", "(", "gottenBytes", ")", ")", ".", "To", "(", "Equal", "(", "ctx", ".", "ExpectedString", ")", ")", "\n\n", "session", ",", "err", "=", "RunGCSCLI", "(", "gcsCLIPath", ",", "ctx", ".", "ConfigPath", ",", "\"", "\"", ",", "ctx", ".", "GCSFileName", ")", "\n", "Expect", "(", "err", ")", ".", "ToNot", "(", "HaveOccurred", "(", ")", ")", "\n", "Expect", "(", "session", ".", "ExitCode", "(", ")", ")", ".", "To", "(", "BeZero", "(", ")", ")", "\n\n", "session", ",", "err", "=", "RunGCSCLI", "(", "gcsCLIPath", ",", "ctx", ".", "ConfigPath", ",", "\"", "\"", ",", "ctx", ".", "GCSFileName", ")", "\n", "Expect", "(", "err", ")", ".", "ToNot", "(", "HaveOccurred", "(", ")", ")", "\n", "Expect", "(", "session", ".", "ExitCode", "(", ")", ")", ".", "To", "(", "Equal", "(", "3", ")", ")", "\n", "Expect", "(", "session", ".", "Err", ".", "Contents", "(", ")", ")", ".", "To", "(", "MatchRegexp", "(", "\"", "\"", ")", ")", "\n", "}" ]
// AssertLifecycleWorks tests the main blobstore object lifecycle from // creation to deletion. // // This is using gomega matchers, so it will fail if called outside an // 'It' test.
[ "AssertLifecycleWorks", "tests", "the", "main", "blobstore", "object", "lifecycle", "from", "creation", "to", "deletion", ".", "This", "is", "using", "gomega", "matchers", "so", "it", "will", "fail", "if", "called", "outside", "an", "It", "test", "." ]
2aef468b5b8561560918014b4fbce7549de2283d
https://github.com/cloudfoundry/bosh-gcscli/blob/2aef468b5b8561560918014b4fbce7549de2283d/integration/assertions.go#L40-L77
10,845
cloudfoundry/bosh-gcscli
integration/assertcontext.go
NewAssertContext
func NewAssertContext(options ...AssertContextConfigOption) AssertContext { expectedString := GenerateRandomString() serviceAccountFile := os.Getenv(ServiceAccountFileEnv) Expect(serviceAccountFile).ToNot(BeEmpty(), fmt.Sprintf(ServiceAccountFileMsg, ServiceAccountFileEnv)) return AssertContext{ ExpectedString: expectedString, ContentFile: MakeContentFile(expectedString), GCSFileName: GenerateRandomString(), serviceAccountFile: serviceAccountFile, options: options, ctx: context.Background(), } }
go
func NewAssertContext(options ...AssertContextConfigOption) AssertContext { expectedString := GenerateRandomString() serviceAccountFile := os.Getenv(ServiceAccountFileEnv) Expect(serviceAccountFile).ToNot(BeEmpty(), fmt.Sprintf(ServiceAccountFileMsg, ServiceAccountFileEnv)) return AssertContext{ ExpectedString: expectedString, ContentFile: MakeContentFile(expectedString), GCSFileName: GenerateRandomString(), serviceAccountFile: serviceAccountFile, options: options, ctx: context.Background(), } }
[ "func", "NewAssertContext", "(", "options", "...", "AssertContextConfigOption", ")", "AssertContext", "{", "expectedString", ":=", "GenerateRandomString", "(", ")", "\n\n", "serviceAccountFile", ":=", "os", ".", "Getenv", "(", "ServiceAccountFileEnv", ")", "\n", "Expect", "(", "serviceAccountFile", ")", ".", "ToNot", "(", "BeEmpty", "(", ")", ",", "fmt", ".", "Sprintf", "(", "ServiceAccountFileMsg", ",", "ServiceAccountFileEnv", ")", ")", "\n\n", "return", "AssertContext", "{", "ExpectedString", ":", "expectedString", ",", "ContentFile", ":", "MakeContentFile", "(", "expectedString", ")", ",", "GCSFileName", ":", "GenerateRandomString", "(", ")", ",", "serviceAccountFile", ":", "serviceAccountFile", ",", "options", ":", "options", ",", "ctx", ":", "context", ".", "Background", "(", ")", ",", "}", "\n", "}" ]
// NewAssertContext returns an AssertContext with all fields // which can be generated filled in.
[ "NewAssertContext", "returns", "an", "AssertContext", "with", "all", "fields", "which", "can", "be", "generated", "filled", "in", "." ]
2aef468b5b8561560918014b4fbce7549de2283d
https://github.com/cloudfoundry/bosh-gcscli/blob/2aef468b5b8561560918014b4fbce7549de2283d/integration/assertcontext.go#L80-L95
10,846
cloudfoundry/bosh-gcscli
integration/assertcontext.go
AddConfig
func (ctx *AssertContext) AddConfig(config *config.GCSCli) { ctx.Config = config for _, opt := range ctx.options { opt(ctx) } ctx.ConfigPath = MakeConfigFile(ctx.Config) }
go
func (ctx *AssertContext) AddConfig(config *config.GCSCli) { ctx.Config = config for _, opt := range ctx.options { opt(ctx) } ctx.ConfigPath = MakeConfigFile(ctx.Config) }
[ "func", "(", "ctx", "*", "AssertContext", ")", "AddConfig", "(", "config", "*", "config", ".", "GCSCli", ")", "{", "ctx", ".", "Config", "=", "config", "\n", "for", "_", ",", "opt", ":=", "range", "ctx", ".", "options", "{", "opt", "(", "ctx", ")", "\n", "}", "\n", "ctx", ".", "ConfigPath", "=", "MakeConfigFile", "(", "ctx", ".", "Config", ")", "\n", "}" ]
// AddConfig includes the config.GCSCli required for AssertContext // // Configuration is typically not available immediately before a test // can be run, hence the need to add it later.
[ "AddConfig", "includes", "the", "config", ".", "GCSCli", "required", "for", "AssertContext", "Configuration", "is", "typically", "not", "available", "immediately", "before", "a", "test", "can", "be", "run", "hence", "the", "need", "to", "add", "it", "later", "." ]
2aef468b5b8561560918014b4fbce7549de2283d
https://github.com/cloudfoundry/bosh-gcscli/blob/2aef468b5b8561560918014b4fbce7549de2283d/integration/assertcontext.go#L101-L107
10,847
cloudfoundry/bosh-gcscli
integration/assertcontext.go
AsReadOnlyCredentials
func AsReadOnlyCredentials(ctx *AssertContext) { conf := ctx.Config Expect(conf).ToNot(BeNil(), "cannot set read-only AssertContext without config") conf.CredentialsSource = config.NoneCredentialsSource conf.ServiceAccountFile = "" }
go
func AsReadOnlyCredentials(ctx *AssertContext) { conf := ctx.Config Expect(conf).ToNot(BeNil(), "cannot set read-only AssertContext without config") conf.CredentialsSource = config.NoneCredentialsSource conf.ServiceAccountFile = "" }
[ "func", "AsReadOnlyCredentials", "(", "ctx", "*", "AssertContext", ")", "{", "conf", ":=", "ctx", ".", "Config", "\n", "Expect", "(", "conf", ")", ".", "ToNot", "(", "BeNil", "(", ")", ",", "\"", "\"", ")", "\n\n", "conf", ".", "CredentialsSource", "=", "config", ".", "NoneCredentialsSource", "\n", "conf", ".", "ServiceAccountFile", "=", "\"", "\"", "\n", "}" ]
// AsReadOnlyCredentials configures the AssertContext to be used soley for // public, read-only operations.
[ "AsReadOnlyCredentials", "configures", "the", "AssertContext", "to", "be", "used", "soley", "for", "public", "read", "-", "only", "operations", "." ]
2aef468b5b8561560918014b4fbce7549de2283d
https://github.com/cloudfoundry/bosh-gcscli/blob/2aef468b5b8561560918014b4fbce7549de2283d/integration/assertcontext.go#L117-L124
10,848
cloudfoundry/bosh-gcscli
integration/assertcontext.go
AsStaticCredentials
func AsStaticCredentials(ctx *AssertContext) { conf := ctx.Config Expect(conf).ToNot(BeNil(), "cannot set static AssertContext without config") conf.ServiceAccountFile = ctx.serviceAccountFile conf.CredentialsSource = config.ServiceAccountFileCredentialsSource }
go
func AsStaticCredentials(ctx *AssertContext) { conf := ctx.Config Expect(conf).ToNot(BeNil(), "cannot set static AssertContext without config") conf.ServiceAccountFile = ctx.serviceAccountFile conf.CredentialsSource = config.ServiceAccountFileCredentialsSource }
[ "func", "AsStaticCredentials", "(", "ctx", "*", "AssertContext", ")", "{", "conf", ":=", "ctx", ".", "Config", "\n", "Expect", "(", "conf", ")", ".", "ToNot", "(", "BeNil", "(", ")", ",", "\"", "\"", ")", "\n\n", "conf", ".", "ServiceAccountFile", "=", "ctx", ".", "serviceAccountFile", "\n", "conf", ".", "CredentialsSource", "=", "config", ".", "ServiceAccountFileCredentialsSource", "\n", "}" ]
// AsStaticCredentials configures the AssertContext to authenticate explicitly // using a Service Account File
[ "AsStaticCredentials", "configures", "the", "AssertContext", "to", "authenticate", "explicitly", "using", "a", "Service", "Account", "File" ]
2aef468b5b8561560918014b4fbce7549de2283d
https://github.com/cloudfoundry/bosh-gcscli/blob/2aef468b5b8561560918014b4fbce7549de2283d/integration/assertcontext.go#L128-L135
10,849
cloudfoundry/bosh-gcscli
integration/assertcontext.go
AsDefaultCredentials
func AsDefaultCredentials(ctx *AssertContext) { conf := ctx.Config Expect(conf).ToNot(BeNil(), "cannot set static AssertContext without config") tempFile, err := ioutil.TempFile("", "bosh-gcscli-service-account-file") Expect(err).ToNot(HaveOccurred()) defer tempFile.Close() tempFile.WriteString(ctx.serviceAccountFile) ctx.serviceAccountPath = tempFile.Name() os.Setenv(GoogleAppCredentialsEnv, ctx.serviceAccountPath) conf.CredentialsSource = config.DefaultCredentialsSource }
go
func AsDefaultCredentials(ctx *AssertContext) { conf := ctx.Config Expect(conf).ToNot(BeNil(), "cannot set static AssertContext without config") tempFile, err := ioutil.TempFile("", "bosh-gcscli-service-account-file") Expect(err).ToNot(HaveOccurred()) defer tempFile.Close() tempFile.WriteString(ctx.serviceAccountFile) ctx.serviceAccountPath = tempFile.Name() os.Setenv(GoogleAppCredentialsEnv, ctx.serviceAccountPath) conf.CredentialsSource = config.DefaultCredentialsSource }
[ "func", "AsDefaultCredentials", "(", "ctx", "*", "AssertContext", ")", "{", "conf", ":=", "ctx", ".", "Config", "\n", "Expect", "(", "conf", ")", ".", "ToNot", "(", "BeNil", "(", ")", ",", "\"", "\"", ")", "\n\n", "tempFile", ",", "err", ":=", "ioutil", ".", "TempFile", "(", "\"", "\"", ",", "\"", "\"", ")", "\n", "Expect", "(", "err", ")", ".", "ToNot", "(", "HaveOccurred", "(", ")", ")", "\n", "defer", "tempFile", ".", "Close", "(", ")", "\n\n", "tempFile", ".", "WriteString", "(", "ctx", ".", "serviceAccountFile", ")", "\n\n", "ctx", ".", "serviceAccountPath", "=", "tempFile", ".", "Name", "(", ")", "\n", "os", ".", "Setenv", "(", "GoogleAppCredentialsEnv", ",", "ctx", ".", "serviceAccountPath", ")", "\n\n", "conf", ".", "CredentialsSource", "=", "config", ".", "DefaultCredentialsSource", "\n", "}" ]
// AsDefaultCredentials configures the AssertContext to authenticate using // Application Default Credentials populated using the // testing service account file.
[ "AsDefaultCredentials", "configures", "the", "AssertContext", "to", "authenticate", "using", "Application", "Default", "Credentials", "populated", "using", "the", "testing", "service", "account", "file", "." ]
2aef468b5b8561560918014b4fbce7549de2283d
https://github.com/cloudfoundry/bosh-gcscli/blob/2aef468b5b8561560918014b4fbce7549de2283d/integration/assertcontext.go#L140-L155
10,850
cloudfoundry/bosh-gcscli
integration/assertcontext.go
Cleanup
func (ctx *AssertContext) Cleanup() { os.Remove(ctx.ConfigPath) os.Remove(ctx.ContentFile) if ctx.serviceAccountPath != "" { os.Remove(ctx.serviceAccountPath) } os.Unsetenv(GoogleAppCredentialsEnv) }
go
func (ctx *AssertContext) Cleanup() { os.Remove(ctx.ConfigPath) os.Remove(ctx.ContentFile) if ctx.serviceAccountPath != "" { os.Remove(ctx.serviceAccountPath) } os.Unsetenv(GoogleAppCredentialsEnv) }
[ "func", "(", "ctx", "*", "AssertContext", ")", "Cleanup", "(", ")", "{", "os", ".", "Remove", "(", "ctx", ".", "ConfigPath", ")", "\n", "os", ".", "Remove", "(", "ctx", ".", "ContentFile", ")", "\n\n", "if", "ctx", ".", "serviceAccountPath", "!=", "\"", "\"", "{", "os", ".", "Remove", "(", "ctx", ".", "serviceAccountPath", ")", "\n", "}", "\n", "os", ".", "Unsetenv", "(", "GoogleAppCredentialsEnv", ")", "\n", "}" ]
// Cleanup removes artifacts generated by the AssertContext.
[ "Cleanup", "removes", "artifacts", "generated", "by", "the", "AssertContext", "." ]
2aef468b5b8561560918014b4fbce7549de2283d
https://github.com/cloudfoundry/bosh-gcscli/blob/2aef468b5b8561560918014b4fbce7549de2283d/integration/assertcontext.go#L176-L184
10,851
cloudfoundry/bosh-gcscli
config/regions.go
validLocationStorageClass
func validLocationStorageClass(location, storageClass string) error { if _, ok := GCSStorageClass[storageClass]; !ok { return ErrUnknownStorageClass } if storageClass == regional { if _, ok := GCSMultiRegionalLocations[location]; ok { return ErrBadLocationStorageClass } return nil } else if _, ok := GCSStorageClass[storageClass]; ok { if _, ok := GCSRegionalLocations[location]; ok { return ErrBadLocationStorageClass } return nil } else { return ErrUnknownStorageClass } }
go
func validLocationStorageClass(location, storageClass string) error { if _, ok := GCSStorageClass[storageClass]; !ok { return ErrUnknownStorageClass } if storageClass == regional { if _, ok := GCSMultiRegionalLocations[location]; ok { return ErrBadLocationStorageClass } return nil } else if _, ok := GCSStorageClass[storageClass]; ok { if _, ok := GCSRegionalLocations[location]; ok { return ErrBadLocationStorageClass } return nil } else { return ErrUnknownStorageClass } }
[ "func", "validLocationStorageClass", "(", "location", ",", "storageClass", "string", ")", "error", "{", "if", "_", ",", "ok", ":=", "GCSStorageClass", "[", "storageClass", "]", ";", "!", "ok", "{", "return", "ErrUnknownStorageClass", "\n", "}", "\n\n", "if", "storageClass", "==", "regional", "{", "if", "_", ",", "ok", ":=", "GCSMultiRegionalLocations", "[", "location", "]", ";", "ok", "{", "return", "ErrBadLocationStorageClass", "\n", "}", "\n", "return", "nil", "\n", "}", "else", "if", "_", ",", "ok", ":=", "GCSStorageClass", "[", "storageClass", "]", ";", "ok", "{", "if", "_", ",", "ok", ":=", "GCSRegionalLocations", "[", "location", "]", ";", "ok", "{", "return", "ErrBadLocationStorageClass", "\n", "}", "\n", "return", "nil", "\n", "}", "else", "{", "return", "ErrUnknownStorageClass", "\n", "}", "\n", "}" ]
// validDurability returns nil error on valid location-durability combination // and non-nil explanation on all else.
[ "validDurability", "returns", "nil", "error", "on", "valid", "location", "-", "durability", "combination", "and", "non", "-", "nil", "explanation", "on", "all", "else", "." ]
2aef468b5b8561560918014b4fbce7549de2283d
https://github.com/cloudfoundry/bosh-gcscli/blob/2aef468b5b8561560918014b4fbce7549de2283d/config/regions.go#L72-L90
10,852
cloudfoundry/bosh-gcscli
client/client.go
validateRemoteConfig
func (client *GCSBlobstore) validateRemoteConfig() error { if client.readOnly() { return nil } bucket := client.authenticatedGCS.Bucket(client.config.BucketName) attrs, err := bucket.Attrs(context.Background()) if err != nil { return err } return client.config.FitCompatibleLocation(attrs.Location) }
go
func (client *GCSBlobstore) validateRemoteConfig() error { if client.readOnly() { return nil } bucket := client.authenticatedGCS.Bucket(client.config.BucketName) attrs, err := bucket.Attrs(context.Background()) if err != nil { return err } return client.config.FitCompatibleLocation(attrs.Location) }
[ "func", "(", "client", "*", "GCSBlobstore", ")", "validateRemoteConfig", "(", ")", "error", "{", "if", "client", ".", "readOnly", "(", ")", "{", "return", "nil", "\n", "}", "\n\n", "bucket", ":=", "client", ".", "authenticatedGCS", ".", "Bucket", "(", "client", ".", "config", ".", "BucketName", ")", "\n", "attrs", ",", "err", ":=", "bucket", ".", "Attrs", "(", "context", ".", "Background", "(", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", "client", ".", "config", ".", "FitCompatibleLocation", "(", "attrs", ".", "Location", ")", "\n", "}" ]
// validateRemoteConfig determines if the configuration of the client matches // against the remote configuration and the StorageClass is valid for the location. // // If operating in read-only mode, no mutations can be performed // so the remote bucket location is always compatible.
[ "validateRemoteConfig", "determines", "if", "the", "configuration", "of", "the", "client", "matches", "against", "the", "remote", "configuration", "and", "the", "StorageClass", "is", "valid", "for", "the", "location", ".", "If", "operating", "in", "read", "-", "only", "mode", "no", "mutations", "can", "be", "performed", "so", "the", "remote", "bucket", "location", "is", "always", "compatible", "." ]
2aef468b5b8561560918014b4fbce7549de2283d
https://github.com/cloudfoundry/bosh-gcscli/blob/2aef468b5b8561560918014b4fbce7549de2283d/client/client.go#L47-L58
10,853
cloudfoundry/bosh-gcscli
client/client.go
getObjectHandle
func (client *GCSBlobstore) getObjectHandle(gcs *storage.Client, src string) *storage.ObjectHandle { handle := gcs.Bucket(client.config.BucketName).Object(src) if client.config.EncryptionKey != nil { handle = handle.Key(client.config.EncryptionKey) } return handle }
go
func (client *GCSBlobstore) getObjectHandle(gcs *storage.Client, src string) *storage.ObjectHandle { handle := gcs.Bucket(client.config.BucketName).Object(src) if client.config.EncryptionKey != nil { handle = handle.Key(client.config.EncryptionKey) } return handle }
[ "func", "(", "client", "*", "GCSBlobstore", ")", "getObjectHandle", "(", "gcs", "*", "storage", ".", "Client", ",", "src", "string", ")", "*", "storage", ".", "ObjectHandle", "{", "handle", ":=", "gcs", ".", "Bucket", "(", "client", ".", "config", ".", "BucketName", ")", ".", "Object", "(", "src", ")", "\n", "if", "client", ".", "config", ".", "EncryptionKey", "!=", "nil", "{", "handle", "=", "handle", ".", "Key", "(", "client", ".", "config", ".", "EncryptionKey", ")", "\n", "}", "\n", "return", "handle", "\n", "}" ]
// getObjectHandle returns a handle to an object named src
[ "getObjectHandle", "returns", "a", "handle", "to", "an", "object", "named", "src" ]
2aef468b5b8561560918014b4fbce7549de2283d
https://github.com/cloudfoundry/bosh-gcscli/blob/2aef468b5b8561560918014b4fbce7549de2283d/client/client.go#L61-L67
10,854
cloudfoundry/bosh-gcscli
client/client.go
New
func New(ctx context.Context, cfg *config.GCSCli) (*GCSBlobstore, error) { if cfg == nil { return nil, errors.New("expected non-nill config object") } authenticatedGCS, publicGCS, err := newStorageClients(ctx, cfg) if err != nil { return nil, fmt.Errorf("creating storage client: %v", err) } return &GCSBlobstore{authenticatedGCS: authenticatedGCS, publicGCS: publicGCS, config: cfg}, nil }
go
func New(ctx context.Context, cfg *config.GCSCli) (*GCSBlobstore, error) { if cfg == nil { return nil, errors.New("expected non-nill config object") } authenticatedGCS, publicGCS, err := newStorageClients(ctx, cfg) if err != nil { return nil, fmt.Errorf("creating storage client: %v", err) } return &GCSBlobstore{authenticatedGCS: authenticatedGCS, publicGCS: publicGCS, config: cfg}, nil }
[ "func", "New", "(", "ctx", "context", ".", "Context", ",", "cfg", "*", "config", ".", "GCSCli", ")", "(", "*", "GCSBlobstore", ",", "error", ")", "{", "if", "cfg", "==", "nil", "{", "return", "nil", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "authenticatedGCS", ",", "publicGCS", ",", "err", ":=", "newStorageClients", "(", "ctx", ",", "cfg", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "return", "&", "GCSBlobstore", "{", "authenticatedGCS", ":", "authenticatedGCS", ",", "publicGCS", ":", "publicGCS", ",", "config", ":", "cfg", "}", ",", "nil", "\n", "}" ]
// New returns a GCSBlobstore configured to operate using the given config // // non-nil error is returned on invalid Client or config. If the configuration // is incompatible with the GCS bucket, a non-nil error is also returned.
[ "New", "returns", "a", "GCSBlobstore", "configured", "to", "operate", "using", "the", "given", "config", "non", "-", "nil", "error", "is", "returned", "on", "invalid", "Client", "or", "config", ".", "If", "the", "configuration", "is", "incompatible", "with", "the", "GCS", "bucket", "a", "non", "-", "nil", "error", "is", "also", "returned", "." ]
2aef468b5b8561560918014b4fbce7549de2283d
https://github.com/cloudfoundry/bosh-gcscli/blob/2aef468b5b8561560918014b4fbce7549de2283d/client/client.go#L73-L84
10,855
cloudfoundry/bosh-gcscli
client/client.go
Get
func (client *GCSBlobstore) Get(src string, dest io.Writer) error { reader, err := client.getReader(client.publicGCS, src) // If the public client fails, try using it as an authenticated actor if err != nil && client.authenticatedGCS != nil { reader, err = client.getReader(client.authenticatedGCS, src) } if err != nil { return err } _, err = io.Copy(dest, reader) return err }
go
func (client *GCSBlobstore) Get(src string, dest io.Writer) error { reader, err := client.getReader(client.publicGCS, src) // If the public client fails, try using it as an authenticated actor if err != nil && client.authenticatedGCS != nil { reader, err = client.getReader(client.authenticatedGCS, src) } if err != nil { return err } _, err = io.Copy(dest, reader) return err }
[ "func", "(", "client", "*", "GCSBlobstore", ")", "Get", "(", "src", "string", ",", "dest", "io", ".", "Writer", ")", "error", "{", "reader", ",", "err", ":=", "client", ".", "getReader", "(", "client", ".", "publicGCS", ",", "src", ")", "\n\n", "// If the public client fails, try using it as an authenticated actor", "if", "err", "!=", "nil", "&&", "client", ".", "authenticatedGCS", "!=", "nil", "{", "reader", ",", "err", "=", "client", ".", "getReader", "(", "client", ".", "authenticatedGCS", ",", "src", ")", "\n", "}", "\n\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "_", ",", "err", "=", "io", ".", "Copy", "(", "dest", ",", "reader", ")", "\n", "return", "err", "\n", "}" ]
// Get fetches a blob from the GCS blobstore. // Destination will be overwritten if it already exists.
[ "Get", "fetches", "a", "blob", "from", "the", "GCS", "blobstore", ".", "Destination", "will", "be", "overwritten", "if", "it", "already", "exists", "." ]
2aef468b5b8561560918014b4fbce7549de2283d
https://github.com/cloudfoundry/bosh-gcscli/blob/2aef468b5b8561560918014b4fbce7549de2283d/client/client.go#L88-L102
10,856
cloudfoundry/bosh-gcscli
client/client.go
Delete
func (client *GCSBlobstore) Delete(dest string) error { if client.readOnly() { return ErrInvalidROWriteOperation } err := client.getObjectHandle(client.authenticatedGCS, dest).Delete(context.Background()) if err == storage.ErrObjectNotExist { return nil } return err }
go
func (client *GCSBlobstore) Delete(dest string) error { if client.readOnly() { return ErrInvalidROWriteOperation } err := client.getObjectHandle(client.authenticatedGCS, dest).Delete(context.Background()) if err == storage.ErrObjectNotExist { return nil } return err }
[ "func", "(", "client", "*", "GCSBlobstore", ")", "Delete", "(", "dest", "string", ")", "error", "{", "if", "client", ".", "readOnly", "(", ")", "{", "return", "ErrInvalidROWriteOperation", "\n", "}", "\n\n", "err", ":=", "client", ".", "getObjectHandle", "(", "client", ".", "authenticatedGCS", ",", "dest", ")", ".", "Delete", "(", "context", ".", "Background", "(", ")", ")", "\n", "if", "err", "==", "storage", ".", "ErrObjectNotExist", "{", "return", "nil", "\n", "}", "\n", "return", "err", "\n", "}" ]
// Delete removes a blob from from the GCS blobstore. // // If the object does not exist, Delete returns a nil error.
[ "Delete", "removes", "a", "blob", "from", "from", "the", "GCS", "blobstore", ".", "If", "the", "object", "does", "not", "exist", "Delete", "returns", "a", "nil", "error", "." ]
2aef468b5b8561560918014b4fbce7549de2283d
https://github.com/cloudfoundry/bosh-gcscli/blob/2aef468b5b8561560918014b4fbce7549de2283d/client/client.go#L161-L171
10,857
cloudfoundry/bosh-gcscli
client/client.go
Exists
func (client *GCSBlobstore) Exists(dest string) (exists bool, err error) { if exists, err = client.exists(client.publicGCS, dest); err == nil { return exists, nil } // If the public client fails, try using it as an authenticated actor if client.authenticatedGCS != nil { return client.exists(client.authenticatedGCS, dest) } return }
go
func (client *GCSBlobstore) Exists(dest string) (exists bool, err error) { if exists, err = client.exists(client.publicGCS, dest); err == nil { return exists, nil } // If the public client fails, try using it as an authenticated actor if client.authenticatedGCS != nil { return client.exists(client.authenticatedGCS, dest) } return }
[ "func", "(", "client", "*", "GCSBlobstore", ")", "Exists", "(", "dest", "string", ")", "(", "exists", "bool", ",", "err", "error", ")", "{", "if", "exists", ",", "err", "=", "client", ".", "exists", "(", "client", ".", "publicGCS", ",", "dest", ")", ";", "err", "==", "nil", "{", "return", "exists", ",", "nil", "\n", "}", "\n\n", "// If the public client fails, try using it as an authenticated actor", "if", "client", ".", "authenticatedGCS", "!=", "nil", "{", "return", "client", ".", "exists", "(", "client", ".", "authenticatedGCS", ",", "dest", ")", "\n", "}", "\n\n", "return", "\n", "}" ]
// Exists checks if a blob exists in the GCS blobstore.
[ "Exists", "checks", "if", "a", "blob", "exists", "in", "the", "GCS", "blobstore", "." ]
2aef468b5b8561560918014b4fbce7549de2283d
https://github.com/cloudfoundry/bosh-gcscli/blob/2aef468b5b8561560918014b4fbce7549de2283d/client/client.go#L174-L185
10,858
cloudfoundry/bosh-gcscli
integration/utils.go
MakeConfigFile
func MakeConfigFile(cfg *config.GCSCli) string { cfgBytes, err := json.Marshal(cfg) Expect(err).ToNot(HaveOccurred()) tmpFile, err := ioutil.TempFile("", "gcscli-test") Expect(err).ToNot(HaveOccurred()) _, err = tmpFile.Write(cfgBytes) Expect(err).ToNot(HaveOccurred()) err = tmpFile.Close() Expect(err).ToNot(HaveOccurred()) return tmpFile.Name() }
go
func MakeConfigFile(cfg *config.GCSCli) string { cfgBytes, err := json.Marshal(cfg) Expect(err).ToNot(HaveOccurred()) tmpFile, err := ioutil.TempFile("", "gcscli-test") Expect(err).ToNot(HaveOccurred()) _, err = tmpFile.Write(cfgBytes) Expect(err).ToNot(HaveOccurred()) err = tmpFile.Close() Expect(err).ToNot(HaveOccurred()) return tmpFile.Name() }
[ "func", "MakeConfigFile", "(", "cfg", "*", "config", ".", "GCSCli", ")", "string", "{", "cfgBytes", ",", "err", ":=", "json", ".", "Marshal", "(", "cfg", ")", "\n", "Expect", "(", "err", ")", ".", "ToNot", "(", "HaveOccurred", "(", ")", ")", "\n", "tmpFile", ",", "err", ":=", "ioutil", ".", "TempFile", "(", "\"", "\"", ",", "\"", "\"", ")", "\n", "Expect", "(", "err", ")", ".", "ToNot", "(", "HaveOccurred", "(", ")", ")", "\n", "_", ",", "err", "=", "tmpFile", ".", "Write", "(", "cfgBytes", ")", "\n", "Expect", "(", "err", ")", ".", "ToNot", "(", "HaveOccurred", "(", ")", ")", "\n", "err", "=", "tmpFile", ".", "Close", "(", ")", "\n", "Expect", "(", "err", ")", ".", "ToNot", "(", "HaveOccurred", "(", ")", ")", "\n", "return", "tmpFile", ".", "Name", "(", ")", "\n", "}" ]
// MakeConfigFile creates a config file from a GCSCli config struct
[ "MakeConfigFile", "creates", "a", "config", "file", "from", "a", "GCSCli", "config", "struct" ]
2aef468b5b8561560918014b4fbce7549de2283d
https://github.com/cloudfoundry/bosh-gcscli/blob/2aef468b5b8561560918014b4fbce7549de2283d/integration/utils.go#L50-L60
10,859
cloudfoundry/bosh-gcscli
integration/utils.go
MakeContentFile
func MakeContentFile(content string) string { tmpFile, err := ioutil.TempFile("", "gcscli-test-content") Expect(err).ToNot(HaveOccurred()) _, err = tmpFile.Write([]byte(content)) Expect(err).ToNot(HaveOccurred()) err = tmpFile.Close() Expect(err).ToNot(HaveOccurred()) return tmpFile.Name() }
go
func MakeContentFile(content string) string { tmpFile, err := ioutil.TempFile("", "gcscli-test-content") Expect(err).ToNot(HaveOccurred()) _, err = tmpFile.Write([]byte(content)) Expect(err).ToNot(HaveOccurred()) err = tmpFile.Close() Expect(err).ToNot(HaveOccurred()) return tmpFile.Name() }
[ "func", "MakeContentFile", "(", "content", "string", ")", "string", "{", "tmpFile", ",", "err", ":=", "ioutil", ".", "TempFile", "(", "\"", "\"", ",", "\"", "\"", ")", "\n", "Expect", "(", "err", ")", ".", "ToNot", "(", "HaveOccurred", "(", ")", ")", "\n", "_", ",", "err", "=", "tmpFile", ".", "Write", "(", "[", "]", "byte", "(", "content", ")", ")", "\n", "Expect", "(", "err", ")", ".", "ToNot", "(", "HaveOccurred", "(", ")", ")", "\n", "err", "=", "tmpFile", ".", "Close", "(", ")", "\n", "Expect", "(", "err", ")", ".", "ToNot", "(", "HaveOccurred", "(", ")", ")", "\n", "return", "tmpFile", ".", "Name", "(", ")", "\n", "}" ]
// MakeContentFile creates a temporary file with content to upload to GCS
[ "MakeContentFile", "creates", "a", "temporary", "file", "with", "content", "to", "upload", "to", "GCS" ]
2aef468b5b8561560918014b4fbce7549de2283d
https://github.com/cloudfoundry/bosh-gcscli/blob/2aef468b5b8561560918014b4fbce7549de2283d/integration/utils.go#L63-L71
10,860
cloudfoundry/bosh-gcscli
integration/utils.go
RunGCSCLI
func RunGCSCLI(gcsCLIPath, configPath, subcommand string, args ...string) (*gexec.Session, error) { cmdArgs := []string{ "-c", configPath, subcommand, } cmdArgs = append(cmdArgs, args...) command := exec.Command(gcsCLIPath, cmdArgs...) gexecSession, err := gexec.Start(command, ginkgo.GinkgoWriter, ginkgo.GinkgoWriter) if err != nil { return nil, err } gexecSession.Wait(1 * time.Minute) return gexecSession, nil }
go
func RunGCSCLI(gcsCLIPath, configPath, subcommand string, args ...string) (*gexec.Session, error) { cmdArgs := []string{ "-c", configPath, subcommand, } cmdArgs = append(cmdArgs, args...) command := exec.Command(gcsCLIPath, cmdArgs...) gexecSession, err := gexec.Start(command, ginkgo.GinkgoWriter, ginkgo.GinkgoWriter) if err != nil { return nil, err } gexecSession.Wait(1 * time.Minute) return gexecSession, nil }
[ "func", "RunGCSCLI", "(", "gcsCLIPath", ",", "configPath", ",", "subcommand", "string", ",", "args", "...", "string", ")", "(", "*", "gexec", ".", "Session", ",", "error", ")", "{", "cmdArgs", ":=", "[", "]", "string", "{", "\"", "\"", ",", "configPath", ",", "subcommand", ",", "}", "\n", "cmdArgs", "=", "append", "(", "cmdArgs", ",", "args", "...", ")", "\n\n", "command", ":=", "exec", ".", "Command", "(", "gcsCLIPath", ",", "cmdArgs", "...", ")", "\n", "gexecSession", ",", "err", ":=", "gexec", ".", "Start", "(", "command", ",", "ginkgo", ".", "GinkgoWriter", ",", "ginkgo", ".", "GinkgoWriter", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "gexecSession", ".", "Wait", "(", "1", "*", "time", ".", "Minute", ")", "\n\n", "return", "gexecSession", ",", "nil", "\n", "}" ]
// RunGCSCLI run the gcscli and outputs the session // after waiting for it to finish
[ "RunGCSCLI", "run", "the", "gcscli", "and", "outputs", "the", "session", "after", "waiting", "for", "it", "to", "finish" ]
2aef468b5b8561560918014b4fbce7549de2283d
https://github.com/cloudfoundry/bosh-gcscli/blob/2aef468b5b8561560918014b4fbce7549de2283d/integration/utils.go#L75-L94
10,861
gotsunami/go-cloudinary
cloudinary/main.go
LoadConfig
func LoadConfig(path string) (*Config, error) { settings := &Config{} c, err := config.ReadDefault(path) if err != nil { return nil, err } // Cloudinary settings var cURI *url.URL var uri string if uri, err = c.String("cloudinary", "uri"); err != nil { return nil, err } if cURI, err = url.Parse(uri); err != nil { return nil, errors.New(fmt.Sprint("cloudinary URI: ", err.Error())) } settings.CloudinaryURI = cURI // An optional remote prepend path if prepend, err := c.String("cloudinary", "prepend"); err == nil { settings.PrependPath = cloudinary.EnsureTrailingSlash(prepend) } settings.ProdTag, _ = c.String("global", "prodtag") // Keep files regexp? (optional) var pattern string pattern, _ = c.String("cloudinary", "keepfiles") if pattern != "" { settings.KeepFilesPattern = pattern } // mongodb section (optional) uri, _ = c.String("database", "uri") if uri != "" { var mURI *url.URL if mURI, err = url.Parse(uri); err != nil { return nil, errors.New(fmt.Sprint("mongoDB URI: ", err.Error())) } settings.MongoURI = mURI } else { fmt.Fprintf(os.Stderr, "Warning: database not set (upload sync disabled)\n") } // Looks for env variables, perform substitutions if needed if err := settings.handleEnvVars(); err != nil { return nil, err } return settings, nil }
go
func LoadConfig(path string) (*Config, error) { settings := &Config{} c, err := config.ReadDefault(path) if err != nil { return nil, err } // Cloudinary settings var cURI *url.URL var uri string if uri, err = c.String("cloudinary", "uri"); err != nil { return nil, err } if cURI, err = url.Parse(uri); err != nil { return nil, errors.New(fmt.Sprint("cloudinary URI: ", err.Error())) } settings.CloudinaryURI = cURI // An optional remote prepend path if prepend, err := c.String("cloudinary", "prepend"); err == nil { settings.PrependPath = cloudinary.EnsureTrailingSlash(prepend) } settings.ProdTag, _ = c.String("global", "prodtag") // Keep files regexp? (optional) var pattern string pattern, _ = c.String("cloudinary", "keepfiles") if pattern != "" { settings.KeepFilesPattern = pattern } // mongodb section (optional) uri, _ = c.String("database", "uri") if uri != "" { var mURI *url.URL if mURI, err = url.Parse(uri); err != nil { return nil, errors.New(fmt.Sprint("mongoDB URI: ", err.Error())) } settings.MongoURI = mURI } else { fmt.Fprintf(os.Stderr, "Warning: database not set (upload sync disabled)\n") } // Looks for env variables, perform substitutions if needed if err := settings.handleEnvVars(); err != nil { return nil, err } return settings, nil }
[ "func", "LoadConfig", "(", "path", "string", ")", "(", "*", "Config", ",", "error", ")", "{", "settings", ":=", "&", "Config", "{", "}", "\n\n", "c", ",", "err", ":=", "config", ".", "ReadDefault", "(", "path", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "// Cloudinary settings", "var", "cURI", "*", "url", ".", "URL", "\n", "var", "uri", "string", "\n\n", "if", "uri", ",", "err", "=", "c", ".", "String", "(", "\"", "\"", ",", "\"", "\"", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "if", "cURI", ",", "err", "=", "url", ".", "Parse", "(", "uri", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "New", "(", "fmt", ".", "Sprint", "(", "\"", "\"", ",", "err", ".", "Error", "(", ")", ")", ")", "\n", "}", "\n", "settings", ".", "CloudinaryURI", "=", "cURI", "\n\n", "// An optional remote prepend path", "if", "prepend", ",", "err", ":=", "c", ".", "String", "(", "\"", "\"", ",", "\"", "\"", ")", ";", "err", "==", "nil", "{", "settings", ".", "PrependPath", "=", "cloudinary", ".", "EnsureTrailingSlash", "(", "prepend", ")", "\n", "}", "\n", "settings", ".", "ProdTag", ",", "_", "=", "c", ".", "String", "(", "\"", "\"", ",", "\"", "\"", ")", "\n\n", "// Keep files regexp? (optional)", "var", "pattern", "string", "\n", "pattern", ",", "_", "=", "c", ".", "String", "(", "\"", "\"", ",", "\"", "\"", ")", "\n", "if", "pattern", "!=", "\"", "\"", "{", "settings", ".", "KeepFilesPattern", "=", "pattern", "\n", "}", "\n\n", "// mongodb section (optional)", "uri", ",", "_", "=", "c", ".", "String", "(", "\"", "\"", ",", "\"", "\"", ")", "\n", "if", "uri", "!=", "\"", "\"", "{", "var", "mURI", "*", "url", ".", "URL", "\n", "if", "mURI", ",", "err", "=", "url", ".", "Parse", "(", "uri", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "New", "(", "fmt", ".", "Sprint", "(", "\"", "\"", ",", "err", ".", "Error", "(", ")", ")", ")", "\n", "}", "\n", "settings", ".", "MongoURI", "=", "mURI", "\n", "}", "else", "{", "fmt", ".", "Fprintf", "(", "os", ".", "Stderr", ",", "\"", "\\n", "\"", ")", "\n", "}", "\n\n", "// Looks for env variables, perform substitutions if needed", "if", "err", ":=", "settings", ".", "handleEnvVars", "(", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "settings", ",", "nil", "\n", "}" ]
// LoadConfig parses a config file and sets global settings // variables to be used at runtime. Note that returning an error // will cause the application to exit with code error 1.
[ "LoadConfig", "parses", "a", "config", "file", "and", "sets", "global", "settings", "variables", "to", "be", "used", "at", "runtime", ".", "Note", "that", "returning", "an", "error", "will", "cause", "the", "application", "to", "exit", "with", "code", "error", "1", "." ]
0ed519cc11198391764646f7c247e951e735ca6a
https://github.com/gotsunami/go-cloudinary/blob/0ed519cc11198391764646f7c247e951e735ca6a/cloudinary/main.go#L85-L135
10,862
gotsunami/go-cloudinary
admin.go
DropAllImages
func (s *Service) DropAllImages(w io.Writer) error { return s.dropAllResources(ImageType, w) }
go
func (s *Service) DropAllImages(w io.Writer) error { return s.dropAllResources(ImageType, w) }
[ "func", "(", "s", "*", "Service", ")", "DropAllImages", "(", "w", "io", ".", "Writer", ")", "error", "{", "return", "s", ".", "dropAllResources", "(", "ImageType", ",", "w", ")", "\n", "}" ]
// DropAllImages deletes all remote images from Cloudinary. File names are // written to io.Writer if available.
[ "DropAllImages", "deletes", "all", "remote", "images", "from", "Cloudinary", ".", "File", "names", "are", "written", "to", "io", ".", "Writer", "if", "available", "." ]
0ed519cc11198391764646f7c247e951e735ca6a
https://github.com/gotsunami/go-cloudinary/blob/0ed519cc11198391764646f7c247e951e735ca6a/admin.go#L69-L71
10,863
gotsunami/go-cloudinary
admin.go
DropAllRaws
func (s *Service) DropAllRaws(w io.Writer) error { return s.dropAllResources(RawType, w) }
go
func (s *Service) DropAllRaws(w io.Writer) error { return s.dropAllResources(RawType, w) }
[ "func", "(", "s", "*", "Service", ")", "DropAllRaws", "(", "w", "io", ".", "Writer", ")", "error", "{", "return", "s", ".", "dropAllResources", "(", "RawType", ",", "w", ")", "\n", "}" ]
// DropAllRaws deletes all remote raw files from Cloudinary. File names are // written to io.Writer if available.
[ "DropAllRaws", "deletes", "all", "remote", "raw", "files", "from", "Cloudinary", ".", "File", "names", "are", "written", "to", "io", ".", "Writer", "if", "available", "." ]
0ed519cc11198391764646f7c247e951e735ca6a
https://github.com/gotsunami/go-cloudinary/blob/0ed519cc11198391764646f7c247e951e735ca6a/admin.go#L75-L77
10,864
gotsunami/go-cloudinary
admin.go
Resources
func (s *Service) Resources(rtype ResourceType) ([]*Resource, error) { return s.doGetResources(rtype) }
go
func (s *Service) Resources(rtype ResourceType) ([]*Resource, error) { return s.doGetResources(rtype) }
[ "func", "(", "s", "*", "Service", ")", "Resources", "(", "rtype", "ResourceType", ")", "(", "[", "]", "*", "Resource", ",", "error", ")", "{", "return", "s", ".", "doGetResources", "(", "rtype", ")", "\n", "}" ]
// Resources returns a list of all uploaded resources. They can be // images or raw files, depending on the resource type passed in rtype. // Cloudinary can return a limited set of results. Pagination is supported, // so the full set of results is returned.
[ "Resources", "returns", "a", "list", "of", "all", "uploaded", "resources", ".", "They", "can", "be", "images", "or", "raw", "files", "depending", "on", "the", "resource", "type", "passed", "in", "rtype", ".", "Cloudinary", "can", "return", "a", "limited", "set", "of", "results", ".", "Pagination", "is", "supported", "so", "the", "full", "set", "of", "results", "is", "returned", "." ]
0ed519cc11198391764646f7c247e951e735ca6a
https://github.com/gotsunami/go-cloudinary/blob/0ed519cc11198391764646f7c247e951e735ca6a/admin.go#L145-L147
10,865
gotsunami/go-cloudinary
admin.go
ResourceDetails
func (s *Service) ResourceDetails(publicId string) (*ResourceDetails, error) { return s.doGetResourceDetails(publicId) }
go
func (s *Service) ResourceDetails(publicId string) (*ResourceDetails, error) { return s.doGetResourceDetails(publicId) }
[ "func", "(", "s", "*", "Service", ")", "ResourceDetails", "(", "publicId", "string", ")", "(", "*", "ResourceDetails", ",", "error", ")", "{", "return", "s", ".", "doGetResourceDetails", "(", "publicId", ")", "\n", "}" ]
// GetResourceDetails gets the details of a single resource that is specified by publicId.
[ "GetResourceDetails", "gets", "the", "details", "of", "a", "single", "resource", "that", "is", "specified", "by", "publicId", "." ]
0ed519cc11198391764646f7c247e951e735ca6a
https://github.com/gotsunami/go-cloudinary/blob/0ed519cc11198391764646f7c247e951e735ca6a/admin.go#L150-L152
10,866
gotsunami/go-cloudinary
service.go
Url
func (s *Service) Url(publicId string, rtype ResourceType) string { path := imageType if rtype == PdfType { path = pdfType } else if rtype == VideoType { path = videoType } else if rtype == RawType { path = rawType } return fmt.Sprintf("%s/%s/%s/upload/%s", baseResourceUrl, s.cloudName, path, publicId) }
go
func (s *Service) Url(publicId string, rtype ResourceType) string { path := imageType if rtype == PdfType { path = pdfType } else if rtype == VideoType { path = videoType } else if rtype == RawType { path = rawType } return fmt.Sprintf("%s/%s/%s/upload/%s", baseResourceUrl, s.cloudName, path, publicId) }
[ "func", "(", "s", "*", "Service", ")", "Url", "(", "publicId", "string", ",", "rtype", "ResourceType", ")", "string", "{", "path", ":=", "imageType", "\n", "if", "rtype", "==", "PdfType", "{", "path", "=", "pdfType", "\n", "}", "else", "if", "rtype", "==", "VideoType", "{", "path", "=", "videoType", "\n", "}", "else", "if", "rtype", "==", "RawType", "{", "path", "=", "rawType", "\n", "}", "\n", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "baseResourceUrl", ",", "s", ".", "cloudName", ",", "path", ",", "publicId", ")", "\n", "}" ]
// Url returns the complete access path in the cloud to the // resource designed by publicId or the empty string if // no match.
[ "Url", "returns", "the", "complete", "access", "path", "in", "the", "cloud", "to", "the", "resource", "designed", "by", "publicId", "or", "the", "empty", "string", "if", "no", "match", "." ]
0ed519cc11198391764646f7c247e951e735ca6a
https://github.com/gotsunami/go-cloudinary/blob/0ed519cc11198391764646f7c247e951e735ca6a/service.go#L536-L546
10,867
gotsunami/go-cloudinary
service.go
Delete
func (s *Service) Delete(publicId, prepend string, rtype ResourceType) error { // TODO: also delete resource entry from database (if used) timestamp := strconv.FormatInt(time.Now().Unix(), 10) data := url.Values{ "api_key": []string{s.apiKey}, "public_id": []string{prepend + publicId}, "timestamp": []string{timestamp}, } if s.keepFilesPattern != nil { if s.keepFilesPattern.MatchString(prepend + publicId) { fmt.Println("keep") return nil } } if s.simulate { fmt.Println("ok") return nil } // Signature hash := sha1.New() part := fmt.Sprintf("public_id=%s&timestamp=%s%s", prepend+publicId, timestamp, s.apiSecret) io.WriteString(hash, part) data.Set("signature", fmt.Sprintf("%x", hash.Sum(nil))) rt := imageType if rtype == RawType { rt = rawType } resp, err := http.PostForm(fmt.Sprintf("%s/%s/%s/destroy/", baseUploadUrl, s.cloudName, rt), data) if err != nil { return err } m, err := handleHttpResponse(resp) if err != nil { return err } if e, ok := m["result"]; ok { fmt.Println(e.(string)) } // Remove DB entry if s.dbSession != nil { if err := s.col.Remove(bson.M{"_id": prepend + publicId}); err != nil { return errors.New("can't remove entry from DB: " + err.Error()) } } return nil }
go
func (s *Service) Delete(publicId, prepend string, rtype ResourceType) error { // TODO: also delete resource entry from database (if used) timestamp := strconv.FormatInt(time.Now().Unix(), 10) data := url.Values{ "api_key": []string{s.apiKey}, "public_id": []string{prepend + publicId}, "timestamp": []string{timestamp}, } if s.keepFilesPattern != nil { if s.keepFilesPattern.MatchString(prepend + publicId) { fmt.Println("keep") return nil } } if s.simulate { fmt.Println("ok") return nil } // Signature hash := sha1.New() part := fmt.Sprintf("public_id=%s&timestamp=%s%s", prepend+publicId, timestamp, s.apiSecret) io.WriteString(hash, part) data.Set("signature", fmt.Sprintf("%x", hash.Sum(nil))) rt := imageType if rtype == RawType { rt = rawType } resp, err := http.PostForm(fmt.Sprintf("%s/%s/%s/destroy/", baseUploadUrl, s.cloudName, rt), data) if err != nil { return err } m, err := handleHttpResponse(resp) if err != nil { return err } if e, ok := m["result"]; ok { fmt.Println(e.(string)) } // Remove DB entry if s.dbSession != nil { if err := s.col.Remove(bson.M{"_id": prepend + publicId}); err != nil { return errors.New("can't remove entry from DB: " + err.Error()) } } return nil }
[ "func", "(", "s", "*", "Service", ")", "Delete", "(", "publicId", ",", "prepend", "string", ",", "rtype", "ResourceType", ")", "error", "{", "// TODO: also delete resource entry from database (if used)", "timestamp", ":=", "strconv", ".", "FormatInt", "(", "time", ".", "Now", "(", ")", ".", "Unix", "(", ")", ",", "10", ")", "\n", "data", ":=", "url", ".", "Values", "{", "\"", "\"", ":", "[", "]", "string", "{", "s", ".", "apiKey", "}", ",", "\"", "\"", ":", "[", "]", "string", "{", "prepend", "+", "publicId", "}", ",", "\"", "\"", ":", "[", "]", "string", "{", "timestamp", "}", ",", "}", "\n", "if", "s", ".", "keepFilesPattern", "!=", "nil", "{", "if", "s", ".", "keepFilesPattern", ".", "MatchString", "(", "prepend", "+", "publicId", ")", "{", "fmt", ".", "Println", "(", "\"", "\"", ")", "\n", "return", "nil", "\n", "}", "\n", "}", "\n", "if", "s", ".", "simulate", "{", "fmt", ".", "Println", "(", "\"", "\"", ")", "\n", "return", "nil", "\n", "}", "\n\n", "// Signature", "hash", ":=", "sha1", ".", "New", "(", ")", "\n", "part", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "prepend", "+", "publicId", ",", "timestamp", ",", "s", ".", "apiSecret", ")", "\n", "io", ".", "WriteString", "(", "hash", ",", "part", ")", "\n", "data", ".", "Set", "(", "\"", "\"", ",", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "hash", ".", "Sum", "(", "nil", ")", ")", ")", "\n\n", "rt", ":=", "imageType", "\n", "if", "rtype", "==", "RawType", "{", "rt", "=", "rawType", "\n", "}", "\n", "resp", ",", "err", ":=", "http", ".", "PostForm", "(", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "baseUploadUrl", ",", "s", ".", "cloudName", ",", "rt", ")", ",", "data", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "m", ",", "err", ":=", "handleHttpResponse", "(", "resp", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "if", "e", ",", "ok", ":=", "m", "[", "\"", "\"", "]", ";", "ok", "{", "fmt", ".", "Println", "(", "e", ".", "(", "string", ")", ")", "\n", "}", "\n", "// Remove DB entry", "if", "s", ".", "dbSession", "!=", "nil", "{", "if", "err", ":=", "s", ".", "col", ".", "Remove", "(", "bson", ".", "M", "{", "\"", "\"", ":", "prepend", "+", "publicId", "}", ")", ";", "err", "!=", "nil", "{", "return", "errors", ".", "New", "(", "\"", "\"", "+", "err", ".", "Error", "(", ")", ")", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Delete deletes a resource uploaded to Cloudinary.
[ "Delete", "deletes", "a", "resource", "uploaded", "to", "Cloudinary", "." ]
0ed519cc11198391764646f7c247e951e735ca6a
https://github.com/gotsunami/go-cloudinary/blob/0ed519cc11198391764646f7c247e951e735ca6a/service.go#L569-L617
10,868
gotsunami/go-cloudinary
tools.go
fileChecksum
func fileChecksum(path string) (string, error) { data, err := ioutil.ReadFile(path) if err != nil { return "", err } hash := sha1.New() io.WriteString(hash, string(data)) return fmt.Sprintf("%x", hash.Sum(nil)), nil }
go
func fileChecksum(path string) (string, error) { data, err := ioutil.ReadFile(path) if err != nil { return "", err } hash := sha1.New() io.WriteString(hash, string(data)) return fmt.Sprintf("%x", hash.Sum(nil)), nil }
[ "func", "fileChecksum", "(", "path", "string", ")", "(", "string", ",", "error", ")", "{", "data", ",", "err", ":=", "ioutil", ".", "ReadFile", "(", "path", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "err", "\n", "}", "\n", "hash", ":=", "sha1", ".", "New", "(", ")", "\n", "io", ".", "WriteString", "(", "hash", ",", "string", "(", "data", ")", ")", "\n", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "hash", ".", "Sum", "(", "nil", ")", ")", ",", "nil", "\n", "}" ]
// Returns SHA1 file checksum
[ "Returns", "SHA1", "file", "checksum" ]
0ed519cc11198391764646f7c247e951e735ca6a
https://github.com/gotsunami/go-cloudinary/blob/0ed519cc11198391764646f7c247e951e735ca6a/tools.go#L16-L24
10,869
zfjagann/golang-ring
ring.go
set
func (r *Ring) set(p int, v interface{}) { r.buff[r.mod(p)] = v }
go
func (r *Ring) set(p int, v interface{}) { r.buff[r.mod(p)] = v }
[ "func", "(", "r", "*", "Ring", ")", "set", "(", "p", "int", ",", "v", "interface", "{", "}", ")", "{", "r", ".", "buff", "[", "r", ".", "mod", "(", "p", ")", "]", "=", "v", "\n", "}" ]
// sets a value at the given unmodified index and returns the modified index of the value
[ "sets", "a", "value", "at", "the", "given", "unmodified", "index", "and", "returns", "the", "modified", "index", "of", "the", "value" ]
d34796e0a6c20df67b614d69184ee4c8093a6856
https://github.com/zfjagann/golang-ring/blob/d34796e0a6c20df67b614d69184ee4c8093a6856/ring.go#L152-L154
10,870
zfjagann/golang-ring
ring.go
get
func (r *Ring) get(p int) interface{} { return r.buff[r.mod(p)] }
go
func (r *Ring) get(p int) interface{} { return r.buff[r.mod(p)] }
[ "func", "(", "r", "*", "Ring", ")", "get", "(", "p", "int", ")", "interface", "{", "}", "{", "return", "r", ".", "buff", "[", "r", ".", "mod", "(", "p", ")", "]", "\n", "}" ]
// gets a value based at a given unmodified index
[ "gets", "a", "value", "based", "at", "a", "given", "unmodified", "index" ]
d34796e0a6c20df67b614d69184ee4c8093a6856
https://github.com/zfjagann/golang-ring/blob/d34796e0a6c20df67b614d69184ee4c8093a6856/ring.go#L157-L159
10,871
zfjagann/golang-ring
ring.go
mod
func (r *Ring) mod(p int) int { return p % len(r.buff) }
go
func (r *Ring) mod(p int) int { return p % len(r.buff) }
[ "func", "(", "r", "*", "Ring", ")", "mod", "(", "p", "int", ")", "int", "{", "return", "p", "%", "len", "(", "r", ".", "buff", ")", "\n", "}" ]
// returns the modified index of an unmodified index
[ "returns", "the", "modified", "index", "of", "an", "unmodified", "index" ]
d34796e0a6c20df67b614d69184ee4c8093a6856
https://github.com/zfjagann/golang-ring/blob/d34796e0a6c20df67b614d69184ee4c8093a6856/ring.go#L162-L164
10,872
rfjakob/eme
eme.go
multByTwo
func multByTwo(out []byte, in []byte) { if len(in) != 16 { panic("len must be 16") } tmp := make([]byte, 16) tmp[0] = 2 * in[0] if in[15] >= 128 { tmp[0] = tmp[0] ^ 135 } for j := 1; j < 16; j++ { tmp[j] = 2 * in[j] if in[j-1] >= 128 { tmp[j] += 1 } } copy(out, tmp) }
go
func multByTwo(out []byte, in []byte) { if len(in) != 16 { panic("len must be 16") } tmp := make([]byte, 16) tmp[0] = 2 * in[0] if in[15] >= 128 { tmp[0] = tmp[0] ^ 135 } for j := 1; j < 16; j++ { tmp[j] = 2 * in[j] if in[j-1] >= 128 { tmp[j] += 1 } } copy(out, tmp) }
[ "func", "multByTwo", "(", "out", "[", "]", "byte", ",", "in", "[", "]", "byte", ")", "{", "if", "len", "(", "in", ")", "!=", "16", "{", "panic", "(", "\"", "\"", ")", "\n", "}", "\n", "tmp", ":=", "make", "(", "[", "]", "byte", ",", "16", ")", "\n\n", "tmp", "[", "0", "]", "=", "2", "*", "in", "[", "0", "]", "\n", "if", "in", "[", "15", "]", ">=", "128", "{", "tmp", "[", "0", "]", "=", "tmp", "[", "0", "]", "^", "135", "\n", "}", "\n", "for", "j", ":=", "1", ";", "j", "<", "16", ";", "j", "++", "{", "tmp", "[", "j", "]", "=", "2", "*", "in", "[", "j", "]", "\n", "if", "in", "[", "j", "-", "1", "]", ">=", "128", "{", "tmp", "[", "j", "]", "+=", "1", "\n", "}", "\n", "}", "\n", "copy", "(", "out", ",", "tmp", ")", "\n", "}" ]
// multByTwo - GF multiplication as specified in the EME-32 draft
[ "multByTwo", "-", "GF", "multiplication", "as", "specified", "in", "the", "EME", "-", "32", "draft" ]
2222dbd4ba467ab3fc7e8af41562fcfe69c0d770
https://github.com/rfjakob/eme/blob/2222dbd4ba467ab3fc7e8af41562fcfe69c0d770/eme.go#L26-L43
10,873
rfjakob/eme
eme.go
tabulateL
func tabulateL(bc cipher.Block, m int) [][]byte { /* set L0 = 2*AESenc(K; 0) */ eZero := make([]byte, 16) Li := make([]byte, 16) bc.Encrypt(Li, eZero) LTable := make([][]byte, m) // Allocate pool once and slice into m pieces in the loop pool := make([]byte, m*16) for i := 0; i < m; i++ { multByTwo(Li, Li) LTable[i] = pool[i*16 : (i+1)*16] copy(LTable[i], Li) } return LTable }
go
func tabulateL(bc cipher.Block, m int) [][]byte { /* set L0 = 2*AESenc(K; 0) */ eZero := make([]byte, 16) Li := make([]byte, 16) bc.Encrypt(Li, eZero) LTable := make([][]byte, m) // Allocate pool once and slice into m pieces in the loop pool := make([]byte, m*16) for i := 0; i < m; i++ { multByTwo(Li, Li) LTable[i] = pool[i*16 : (i+1)*16] copy(LTable[i], Li) } return LTable }
[ "func", "tabulateL", "(", "bc", "cipher", ".", "Block", ",", "m", "int", ")", "[", "]", "[", "]", "byte", "{", "/* set L0 = 2*AESenc(K; 0) */", "eZero", ":=", "make", "(", "[", "]", "byte", ",", "16", ")", "\n", "Li", ":=", "make", "(", "[", "]", "byte", ",", "16", ")", "\n", "bc", ".", "Encrypt", "(", "Li", ",", "eZero", ")", "\n\n", "LTable", ":=", "make", "(", "[", "]", "[", "]", "byte", ",", "m", ")", "\n", "// Allocate pool once and slice into m pieces in the loop", "pool", ":=", "make", "(", "[", "]", "byte", ",", "m", "*", "16", ")", "\n", "for", "i", ":=", "0", ";", "i", "<", "m", ";", "i", "++", "{", "multByTwo", "(", "Li", ",", "Li", ")", "\n", "LTable", "[", "i", "]", "=", "pool", "[", "i", "*", "16", ":", "(", "i", "+", "1", ")", "*", "16", "]", "\n", "copy", "(", "LTable", "[", "i", "]", ",", "Li", ")", "\n", "}", "\n", "return", "LTable", "\n", "}" ]
// tabulateL - calculate L_i for messages up to a length of m cipher blocks
[ "tabulateL", "-", "calculate", "L_i", "for", "messages", "up", "to", "a", "length", "of", "m", "cipher", "blocks" ]
2222dbd4ba467ab3fc7e8af41562fcfe69c0d770
https://github.com/rfjakob/eme/blob/2222dbd4ba467ab3fc7e8af41562fcfe69c0d770/eme.go#L68-L83
10,874
rfjakob/eme
eme.go
Encrypt
func (e *EMECipher) Encrypt(tweak []byte, inputData []byte) []byte { return Transform(e.bc, tweak, inputData, DirectionEncrypt) }
go
func (e *EMECipher) Encrypt(tweak []byte, inputData []byte) []byte { return Transform(e.bc, tweak, inputData, DirectionEncrypt) }
[ "func", "(", "e", "*", "EMECipher", ")", "Encrypt", "(", "tweak", "[", "]", "byte", ",", "inputData", "[", "]", "byte", ")", "[", "]", "byte", "{", "return", "Transform", "(", "e", ".", "bc", ",", "tweak", ",", "inputData", ",", "DirectionEncrypt", ")", "\n", "}" ]
// Encrypt is equivalent to calling Transform with direction=DirectionEncrypt.
[ "Encrypt", "is", "equivalent", "to", "calling", "Transform", "with", "direction", "=", "DirectionEncrypt", "." ]
2222dbd4ba467ab3fc7e8af41562fcfe69c0d770
https://github.com/rfjakob/eme/blob/2222dbd4ba467ab3fc7e8af41562fcfe69c0d770/eme.go#L199-L201
10,875
rfjakob/eme
eme.go
Decrypt
func (e *EMECipher) Decrypt(tweak []byte, inputData []byte) []byte { return Transform(e.bc, tweak, inputData, DirectionDecrypt) }
go
func (e *EMECipher) Decrypt(tweak []byte, inputData []byte) []byte { return Transform(e.bc, tweak, inputData, DirectionDecrypt) }
[ "func", "(", "e", "*", "EMECipher", ")", "Decrypt", "(", "tweak", "[", "]", "byte", ",", "inputData", "[", "]", "byte", ")", "[", "]", "byte", "{", "return", "Transform", "(", "e", ".", "bc", ",", "tweak", ",", "inputData", ",", "DirectionDecrypt", ")", "\n", "}" ]
// Decrypt is equivalent to calling Transform with direction=DirectionDecrypt.
[ "Decrypt", "is", "equivalent", "to", "calling", "Transform", "with", "direction", "=", "DirectionDecrypt", "." ]
2222dbd4ba467ab3fc7e8af41562fcfe69c0d770
https://github.com/rfjakob/eme/blob/2222dbd4ba467ab3fc7e8af41562fcfe69c0d770/eme.go#L204-L206
10,876
blockloop/scan
columns.go
Columns
func Columns(v interface{}, excluded ...string) ([]string, error) { return columns(v, false, excluded...) }
go
func Columns(v interface{}, excluded ...string) ([]string, error) { return columns(v, false, excluded...) }
[ "func", "Columns", "(", "v", "interface", "{", "}", ",", "excluded", "...", "string", ")", "(", "[", "]", "string", ",", "error", ")", "{", "return", "columns", "(", "v", ",", "false", ",", "excluded", "...", ")", "\n", "}" ]
// Columns scans a struct and returns a list of strings // that represent the assumed column names based on the // db struct tag, or the field name. Any field or struct // tag that matches a string within the excluded list // will be excluded from the result
[ "Columns", "scans", "a", "struct", "and", "returns", "a", "list", "of", "strings", "that", "represent", "the", "assumed", "column", "names", "based", "on", "the", "db", "struct", "tag", "or", "the", "field", "name", ".", "Any", "field", "or", "struct", "tag", "that", "matches", "a", "string", "within", "the", "excluded", "list", "will", "be", "excluded", "from", "the", "result" ]
2e129a9c2603efc4380c7b7d318785b4ff6803ab
https://github.com/blockloop/scan/blob/2e129a9c2603efc4380c7b7d318785b4ff6803ab/columns.go#L18-L20
10,877
blockloop/scan
columns.go
ColumnsStrict
func ColumnsStrict(v interface{}, excluded ...string) ([]string, error) { return columns(v, true, excluded...) }
go
func ColumnsStrict(v interface{}, excluded ...string) ([]string, error) { return columns(v, true, excluded...) }
[ "func", "ColumnsStrict", "(", "v", "interface", "{", "}", ",", "excluded", "...", "string", ")", "(", "[", "]", "string", ",", "error", ")", "{", "return", "columns", "(", "v", ",", "true", ",", "excluded", "...", ")", "\n", "}" ]
// ColumnsStrict is identical to Columns, but it only // searches struct tags and excludes fields not tagged // with the db struct tag
[ "ColumnsStrict", "is", "identical", "to", "Columns", "but", "it", "only", "searches", "struct", "tags", "and", "excludes", "fields", "not", "tagged", "with", "the", "db", "struct", "tag" ]
2e129a9c2603efc4380c7b7d318785b4ff6803ab
https://github.com/blockloop/scan/blob/2e129a9c2603efc4380c7b7d318785b4ff6803ab/columns.go#L25-L27
10,878
blockloop/scan
scanner.go
fieldByName
func fieldByName(v reflect.Value, name string, strict bool) reflect.Value { typ := v.Type() for i := 0; i < v.NumField(); i++ { tag, ok := typ.Field(i).Tag.Lookup("db") if ok && tag == name { return v.Field(i) } } if strict { return reflect.ValueOf(nil) } return v.FieldByName(strings.Title(name)) }
go
func fieldByName(v reflect.Value, name string, strict bool) reflect.Value { typ := v.Type() for i := 0; i < v.NumField(); i++ { tag, ok := typ.Field(i).Tag.Lookup("db") if ok && tag == name { return v.Field(i) } } if strict { return reflect.ValueOf(nil) } return v.FieldByName(strings.Title(name)) }
[ "func", "fieldByName", "(", "v", "reflect", ".", "Value", ",", "name", "string", ",", "strict", "bool", ")", "reflect", ".", "Value", "{", "typ", ":=", "v", ".", "Type", "(", ")", "\n\n", "for", "i", ":=", "0", ";", "i", "<", "v", ".", "NumField", "(", ")", ";", "i", "++", "{", "tag", ",", "ok", ":=", "typ", ".", "Field", "(", "i", ")", ".", "Tag", ".", "Lookup", "(", "\"", "\"", ")", "\n", "if", "ok", "&&", "tag", "==", "name", "{", "return", "v", ".", "Field", "(", "i", ")", "\n", "}", "\n", "}", "\n", "if", "strict", "{", "return", "reflect", ".", "ValueOf", "(", "nil", ")", "\n", "}", "\n", "return", "v", ".", "FieldByName", "(", "strings", ".", "Title", "(", "name", ")", ")", "\n", "}" ]
// fieldByName gets a struct's field by first looking up the db struct tag and falling // back to the field's name in Title case.
[ "fieldByName", "gets", "a", "struct", "s", "field", "by", "first", "looking", "up", "the", "db", "struct", "tag", "and", "falling", "back", "to", "the", "field", "s", "name", "in", "Title", "case", "." ]
2e129a9c2603efc4380c7b7d318785b4ff6803ab
https://github.com/blockloop/scan/blob/2e129a9c2603efc4380c7b7d318785b4ff6803ab/scanner.go#L133-L146
10,879
jaegertracing/jaeger-lib
metrics/tally/metrics.go
Update
func (g *Gauge) Update(value int64) { g.gauge.Update(float64(value)) }
go
func (g *Gauge) Update(value int64) { g.gauge.Update(float64(value)) }
[ "func", "(", "g", "*", "Gauge", ")", "Update", "(", "value", "int64", ")", "{", "g", ".", "gauge", ".", "Update", "(", "float64", "(", "value", ")", ")", "\n", "}" ]
// Update the gauge to the value passed in.
[ "Update", "the", "gauge", "to", "the", "value", "passed", "in", "." ]
d036253de8f5b698150d81b922486f1e8e7628ec
https://github.com/jaegertracing/jaeger-lib/blob/d036253de8f5b698150d81b922486f1e8e7628ec/metrics/tally/metrics.go#L49-L51
10,880
jaegertracing/jaeger-lib
metrics/keys.go
GetKey
func GetKey(name string, tags map[string]string, tagsSep string, tagKVSep string) string { keys := make([]string, 0, len(tags)) for k := range tags { keys = append(keys, k) } sort.Strings(keys) key := name for _, k := range keys { key = key + tagsSep + k + tagKVSep + tags[k] } return key }
go
func GetKey(name string, tags map[string]string, tagsSep string, tagKVSep string) string { keys := make([]string, 0, len(tags)) for k := range tags { keys = append(keys, k) } sort.Strings(keys) key := name for _, k := range keys { key = key + tagsSep + k + tagKVSep + tags[k] } return key }
[ "func", "GetKey", "(", "name", "string", ",", "tags", "map", "[", "string", "]", "string", ",", "tagsSep", "string", ",", "tagKVSep", "string", ")", "string", "{", "keys", ":=", "make", "(", "[", "]", "string", ",", "0", ",", "len", "(", "tags", ")", ")", "\n", "for", "k", ":=", "range", "tags", "{", "keys", "=", "append", "(", "keys", ",", "k", ")", "\n", "}", "\n", "sort", ".", "Strings", "(", "keys", ")", "\n", "key", ":=", "name", "\n", "for", "_", ",", "k", ":=", "range", "keys", "{", "key", "=", "key", "+", "tagsSep", "+", "k", "+", "tagKVSep", "+", "tags", "[", "k", "]", "\n", "}", "\n", "return", "key", "\n", "}" ]
// GetKey converts name+tags into a single string of the form // "name|tag1=value1|...|tagN=valueN", where tag names are // sorted alphabetically.
[ "GetKey", "converts", "name", "+", "tags", "into", "a", "single", "string", "of", "the", "form", "name|tag1", "=", "value1|", "...", "|tagN", "=", "valueN", "where", "tag", "names", "are", "sorted", "alphabetically", "." ]
d036253de8f5b698150d81b922486f1e8e7628ec
https://github.com/jaegertracing/jaeger-lib/blob/d036253de8f5b698150d81b922486f1e8e7628ec/metrics/keys.go#L24-L35
10,881
jaegertracing/jaeger-lib
metrics/go-kit/factory.go
Wrap
func Wrap(namespace string, f Factory, options ...FactoryOption) metrics.Factory { factory := &factory{ scope: namespace, factory: f, scopeSep: ".", tagsSep: ".", tagKVSep: "_", } for i := range options { options[i](factory) } return factory }
go
func Wrap(namespace string, f Factory, options ...FactoryOption) metrics.Factory { factory := &factory{ scope: namespace, factory: f, scopeSep: ".", tagsSep: ".", tagKVSep: "_", } for i := range options { options[i](factory) } return factory }
[ "func", "Wrap", "(", "namespace", "string", ",", "f", "Factory", ",", "options", "...", "FactoryOption", ")", "metrics", ".", "Factory", "{", "factory", ":=", "&", "factory", "{", "scope", ":", "namespace", ",", "factory", ":", "f", ",", "scopeSep", ":", "\"", "\"", ",", "tagsSep", ":", "\"", "\"", ",", "tagKVSep", ":", "\"", "\"", ",", "}", "\n", "for", "i", ":=", "range", "options", "{", "options", "[", "i", "]", "(", "factory", ")", "\n", "}", "\n", "return", "factory", "\n", "}" ]
// Wrap is used to create an adapter from xkit.Factory to metrics.Factory.
[ "Wrap", "is", "used", "to", "create", "an", "adapter", "from", "xkit", ".", "Factory", "to", "metrics", ".", "Factory", "." ]
d036253de8f5b698150d81b922486f1e8e7628ec
https://github.com/jaegertracing/jaeger-lib/blob/d036253de8f5b698150d81b922486f1e8e7628ec/metrics/go-kit/factory.go#L42-L54
10,882
jaegertracing/jaeger-lib
metrics/go-kit/factory.go
nameAndTagsList
func (f *factory) nameAndTagsList(nom string, tags map[string]string) (name string, tagsList []string) { mergedTags := f.mergeTags(tags) name = f.subScope(nom) tagsList = f.tagsList(mergedTags) if len(tagsList) == 0 || f.factory.Capabilities().Tagging { return } name = metrics.GetKey(name, mergedTags, f.tagsSep, f.tagKVSep) tagsList = nil return }
go
func (f *factory) nameAndTagsList(nom string, tags map[string]string) (name string, tagsList []string) { mergedTags := f.mergeTags(tags) name = f.subScope(nom) tagsList = f.tagsList(mergedTags) if len(tagsList) == 0 || f.factory.Capabilities().Tagging { return } name = metrics.GetKey(name, mergedTags, f.tagsSep, f.tagKVSep) tagsList = nil return }
[ "func", "(", "f", "*", "factory", ")", "nameAndTagsList", "(", "nom", "string", ",", "tags", "map", "[", "string", "]", "string", ")", "(", "name", "string", ",", "tagsList", "[", "]", "string", ")", "{", "mergedTags", ":=", "f", ".", "mergeTags", "(", "tags", ")", "\n", "name", "=", "f", ".", "subScope", "(", "nom", ")", "\n", "tagsList", "=", "f", ".", "tagsList", "(", "mergedTags", ")", "\n", "if", "len", "(", "tagsList", ")", "==", "0", "||", "f", ".", "factory", ".", "Capabilities", "(", ")", ".", "Tagging", "{", "return", "\n", "}", "\n", "name", "=", "metrics", ".", "GetKey", "(", "name", ",", "mergedTags", ",", "f", ".", "tagsSep", ",", "f", ".", "tagKVSep", ")", "\n", "tagsList", "=", "nil", "\n", "return", "\n", "}" ]
// nameAndTagsList returns a name and tags list for the new metrics. // The name is a concatenation of nom and the current factory scope. // The tags list is a flattened list of passed tags merged with factory tags. // If the underlying factory does not support tags, then the tags are // transformed into a string and appended to the name.
[ "nameAndTagsList", "returns", "a", "name", "and", "tags", "list", "for", "the", "new", "metrics", ".", "The", "name", "is", "a", "concatenation", "of", "nom", "and", "the", "current", "factory", "scope", ".", "The", "tags", "list", "is", "a", "flattened", "list", "of", "passed", "tags", "merged", "with", "factory", "tags", ".", "If", "the", "underlying", "factory", "does", "not", "support", "tags", "then", "the", "tags", "are", "transformed", "into", "a", "string", "and", "appended", "to", "the", "name", "." ]
d036253de8f5b698150d81b922486f1e8e7628ec
https://github.com/jaegertracing/jaeger-lib/blob/d036253de8f5b698150d81b922486f1e8e7628ec/metrics/go-kit/factory.go#L94-L104
10,883
jaegertracing/jaeger-lib
metrics/adapters/tagless.go
WrapFactoryWithoutTags
func WrapFactoryWithoutTags(f FactoryWithoutTags, options Options) metrics.Factory { return WrapFactoryWithTags( &tagless{ Options: defaultOptions(options), factory: f, }, options, ) }
go
func WrapFactoryWithoutTags(f FactoryWithoutTags, options Options) metrics.Factory { return WrapFactoryWithTags( &tagless{ Options: defaultOptions(options), factory: f, }, options, ) }
[ "func", "WrapFactoryWithoutTags", "(", "f", "FactoryWithoutTags", ",", "options", "Options", ")", "metrics", ".", "Factory", "{", "return", "WrapFactoryWithTags", "(", "&", "tagless", "{", "Options", ":", "defaultOptions", "(", "options", ")", ",", "factory", ":", "f", ",", "}", ",", "options", ",", ")", "\n", "}" ]
// WrapFactoryWithoutTags creates a real metrics.Factory that supports subscopes.
[ "WrapFactoryWithoutTags", "creates", "a", "real", "metrics", ".", "Factory", "that", "supports", "subscopes", "." ]
d036253de8f5b698150d81b922486f1e8e7628ec
https://github.com/jaegertracing/jaeger-lib/blob/d036253de8f5b698150d81b922486f1e8e7628ec/metrics/adapters/tagless.go#L53-L61
10,884
jaegertracing/jaeger-lib
metrics/multi/multi.go
Counter
func (f *Factory) Counter(options metrics.Options) metrics.Counter { counter := &counter{ counters: make([]metrics.Counter, len(f.factories)), } for i, factory := range f.factories { counter.counters[i] = factory.Counter(options) } return counter }
go
func (f *Factory) Counter(options metrics.Options) metrics.Counter { counter := &counter{ counters: make([]metrics.Counter, len(f.factories)), } for i, factory := range f.factories { counter.counters[i] = factory.Counter(options) } return counter }
[ "func", "(", "f", "*", "Factory", ")", "Counter", "(", "options", "metrics", ".", "Options", ")", "metrics", ".", "Counter", "{", "counter", ":=", "&", "counter", "{", "counters", ":", "make", "(", "[", "]", "metrics", ".", "Counter", ",", "len", "(", "f", ".", "factories", ")", ")", ",", "}", "\n", "for", "i", ",", "factory", ":=", "range", "f", ".", "factories", "{", "counter", ".", "counters", "[", "i", "]", "=", "factory", ".", "Counter", "(", "options", ")", "\n", "}", "\n", "return", "counter", "\n", "}" ]
// Counter implements metrics.Factory interface
[ "Counter", "implements", "metrics", ".", "Factory", "interface" ]
d036253de8f5b698150d81b922486f1e8e7628ec
https://github.com/jaegertracing/jaeger-lib/blob/d036253de8f5b698150d81b922486f1e8e7628ec/metrics/multi/multi.go#L46-L54
10,885
jaegertracing/jaeger-lib
metrics/multi/multi.go
Timer
func (f *Factory) Timer(options metrics.TimerOptions) metrics.Timer { timer := &timer{ timers: make([]metrics.Timer, len(f.factories)), } for i, factory := range f.factories { timer.timers[i] = factory.Timer(options) } return timer }
go
func (f *Factory) Timer(options metrics.TimerOptions) metrics.Timer { timer := &timer{ timers: make([]metrics.Timer, len(f.factories)), } for i, factory := range f.factories { timer.timers[i] = factory.Timer(options) } return timer }
[ "func", "(", "f", "*", "Factory", ")", "Timer", "(", "options", "metrics", ".", "TimerOptions", ")", "metrics", ".", "Timer", "{", "timer", ":=", "&", "timer", "{", "timers", ":", "make", "(", "[", "]", "metrics", ".", "Timer", ",", "len", "(", "f", ".", "factories", ")", ")", ",", "}", "\n", "for", "i", ",", "factory", ":=", "range", "f", ".", "factories", "{", "timer", ".", "timers", "[", "i", "]", "=", "factory", ".", "Timer", "(", "options", ")", "\n", "}", "\n", "return", "timer", "\n", "}" ]
// Timer implements metrics.Factory interface
[ "Timer", "implements", "metrics", ".", "Factory", "interface" ]
d036253de8f5b698150d81b922486f1e8e7628ec
https://github.com/jaegertracing/jaeger-lib/blob/d036253de8f5b698150d81b922486f1e8e7628ec/metrics/multi/multi.go#L67-L75
10,886
jaegertracing/jaeger-lib
metrics/multi/multi.go
Histogram
func (f *Factory) Histogram(options metrics.HistogramOptions) metrics.Histogram { histogram := &histogram{ histograms: make([]metrics.Histogram, len(f.factories)), } for i, factory := range f.factories { histogram.histograms[i] = factory.Histogram(options) } return histogram }
go
func (f *Factory) Histogram(options metrics.HistogramOptions) metrics.Histogram { histogram := &histogram{ histograms: make([]metrics.Histogram, len(f.factories)), } for i, factory := range f.factories { histogram.histograms[i] = factory.Histogram(options) } return histogram }
[ "func", "(", "f", "*", "Factory", ")", "Histogram", "(", "options", "metrics", ".", "HistogramOptions", ")", "metrics", ".", "Histogram", "{", "histogram", ":=", "&", "histogram", "{", "histograms", ":", "make", "(", "[", "]", "metrics", ".", "Histogram", ",", "len", "(", "f", ".", "factories", ")", ")", ",", "}", "\n", "for", "i", ",", "factory", ":=", "range", "f", ".", "factories", "{", "histogram", ".", "histograms", "[", "i", "]", "=", "factory", ".", "Histogram", "(", "options", ")", "\n", "}", "\n", "return", "histogram", "\n", "}" ]
// Histogram implements metrics.Factory interface
[ "Histogram", "implements", "metrics", ".", "Factory", "interface" ]
d036253de8f5b698150d81b922486f1e8e7628ec
https://github.com/jaegertracing/jaeger-lib/blob/d036253de8f5b698150d81b922486f1e8e7628ec/metrics/multi/multi.go#L88-L96
10,887
jaegertracing/jaeger-lib
metrics/multi/multi.go
Gauge
func (f *Factory) Gauge(options metrics.Options) metrics.Gauge { gauge := &gauge{ gauges: make([]metrics.Gauge, len(f.factories)), } for i, factory := range f.factories { gauge.gauges[i] = factory.Gauge(options) } return gauge }
go
func (f *Factory) Gauge(options metrics.Options) metrics.Gauge { gauge := &gauge{ gauges: make([]metrics.Gauge, len(f.factories)), } for i, factory := range f.factories { gauge.gauges[i] = factory.Gauge(options) } return gauge }
[ "func", "(", "f", "*", "Factory", ")", "Gauge", "(", "options", "metrics", ".", "Options", ")", "metrics", ".", "Gauge", "{", "gauge", ":=", "&", "gauge", "{", "gauges", ":", "make", "(", "[", "]", "metrics", ".", "Gauge", ",", "len", "(", "f", ".", "factories", ")", ")", ",", "}", "\n", "for", "i", ",", "factory", ":=", "range", "f", ".", "factories", "{", "gauge", ".", "gauges", "[", "i", "]", "=", "factory", ".", "Gauge", "(", "options", ")", "\n", "}", "\n", "return", "gauge", "\n", "}" ]
// Gauge implements metrics.Factory interface
[ "Gauge", "implements", "metrics", ".", "Factory", "interface" ]
d036253de8f5b698150d81b922486f1e8e7628ec
https://github.com/jaegertracing/jaeger-lib/blob/d036253de8f5b698150d81b922486f1e8e7628ec/metrics/multi/multi.go#L109-L117
10,888
jaegertracing/jaeger-lib
metrics/multi/multi.go
Namespace
func (f *Factory) Namespace(scope metrics.NSOptions) metrics.Factory { newFactory := &Factory{ factories: make([]metrics.Factory, len(f.factories)), } for i, factory := range f.factories { newFactory.factories[i] = factory.Namespace(scope) } return newFactory }
go
func (f *Factory) Namespace(scope metrics.NSOptions) metrics.Factory { newFactory := &Factory{ factories: make([]metrics.Factory, len(f.factories)), } for i, factory := range f.factories { newFactory.factories[i] = factory.Namespace(scope) } return newFactory }
[ "func", "(", "f", "*", "Factory", ")", "Namespace", "(", "scope", "metrics", ".", "NSOptions", ")", "metrics", ".", "Factory", "{", "newFactory", ":=", "&", "Factory", "{", "factories", ":", "make", "(", "[", "]", "metrics", ".", "Factory", ",", "len", "(", "f", ".", "factories", ")", ")", ",", "}", "\n", "for", "i", ",", "factory", ":=", "range", "f", ".", "factories", "{", "newFactory", ".", "factories", "[", "i", "]", "=", "factory", ".", "Namespace", "(", "scope", ")", "\n", "}", "\n", "return", "newFactory", "\n", "}" ]
// Namespace implements metrics.Factory interface
[ "Namespace", "implements", "metrics", ".", "Factory", "interface" ]
d036253de8f5b698150d81b922486f1e8e7628ec
https://github.com/jaegertracing/jaeger-lib/blob/d036253de8f5b698150d81b922486f1e8e7628ec/metrics/multi/multi.go#L120-L128
10,889
jaegertracing/jaeger-lib
metrics/adapters/factory.go
WrapFactoryWithTags
func WrapFactoryWithTags(f FactoryWithTags, options Options) metrics.Factory { return &factory{ Options: defaultOptions(options), factory: f, cache: newCache(), } }
go
func WrapFactoryWithTags(f FactoryWithTags, options Options) metrics.Factory { return &factory{ Options: defaultOptions(options), factory: f, cache: newCache(), } }
[ "func", "WrapFactoryWithTags", "(", "f", "FactoryWithTags", ",", "options", "Options", ")", "metrics", ".", "Factory", "{", "return", "&", "factory", "{", "Options", ":", "defaultOptions", "(", "options", ")", ",", "factory", ":", "f", ",", "cache", ":", "newCache", "(", ")", ",", "}", "\n", "}" ]
// WrapFactoryWithTags creates a real metrics.Factory that supports subscopes.
[ "WrapFactoryWithTags", "creates", "a", "real", "metrics", ".", "Factory", "that", "supports", "subscopes", "." ]
d036253de8f5b698150d81b922486f1e8e7628ec
https://github.com/jaegertracing/jaeger-lib/blob/d036253de8f5b698150d81b922486f1e8e7628ec/metrics/adapters/factory.go#L51-L57
10,890
jaegertracing/jaeger-lib
client/log/go-kit/logger.go
NewLogger
func NewLogger(kitlogger log.Logger, options ...LoggerOption) *Logger { logger := &Logger{ infoLogger: level.Info(kitlogger), errorLogger: level.Error(kitlogger), messageKey: "msg", } for _, option := range options { option(logger) } return logger }
go
func NewLogger(kitlogger log.Logger, options ...LoggerOption) *Logger { logger := &Logger{ infoLogger: level.Info(kitlogger), errorLogger: level.Error(kitlogger), messageKey: "msg", } for _, option := range options { option(logger) } return logger }
[ "func", "NewLogger", "(", "kitlogger", "log", ".", "Logger", ",", "options", "...", "LoggerOption", ")", "*", "Logger", "{", "logger", ":=", "&", "Logger", "{", "infoLogger", ":", "level", ".", "Info", "(", "kitlogger", ")", ",", "errorLogger", ":", "level", ".", "Error", "(", "kitlogger", ")", ",", "messageKey", ":", "\"", "\"", ",", "}", "\n\n", "for", "_", ",", "option", ":=", "range", "options", "{", "option", "(", "logger", ")", "\n", "}", "\n\n", "return", "logger", "\n", "}" ]
// NewLogger creates a new Jaeger client logger from a go-kit one.
[ "NewLogger", "creates", "a", "new", "Jaeger", "client", "logger", "from", "a", "go", "-", "kit", "one", "." ]
d036253de8f5b698150d81b922486f1e8e7628ec
https://github.com/jaegertracing/jaeger-lib/blob/d036253de8f5b698150d81b922486f1e8e7628ec/client/log/go-kit/logger.go#L41-L54
10,891
jaegertracing/jaeger-lib
metrics/expvar/factory.go
NewFactory
func NewFactory(buckets int) metrics.Factory { return adapters.WrapFactoryWithoutTags( &factory{ factory: expvar.NewFactory(buckets), }, adapters.Options{}, ) }
go
func NewFactory(buckets int) metrics.Factory { return adapters.WrapFactoryWithoutTags( &factory{ factory: expvar.NewFactory(buckets), }, adapters.Options{}, ) }
[ "func", "NewFactory", "(", "buckets", "int", ")", "metrics", ".", "Factory", "{", "return", "adapters", ".", "WrapFactoryWithoutTags", "(", "&", "factory", "{", "factory", ":", "expvar", ".", "NewFactory", "(", "buckets", ")", ",", "}", ",", "adapters", ".", "Options", "{", "}", ",", ")", "\n", "}" ]
// NewFactory creates a new metrics factory using go-kit expvar package. // buckets is the number of buckets to be used in histograms.
[ "NewFactory", "creates", "a", "new", "metrics", "factory", "using", "go", "-", "kit", "expvar", "package", ".", "buckets", "is", "the", "number", "of", "buckets", "to", "be", "used", "in", "histograms", "." ]
d036253de8f5b698150d81b922486f1e8e7628ec
https://github.com/jaegertracing/jaeger-lib/blob/d036253de8f5b698150d81b922486f1e8e7628ec/metrics/expvar/factory.go#L26-L33
10,892
jaegertracing/jaeger-lib
metrics/stopwatch.go
StartStopwatch
func StartStopwatch(timer Timer) Stopwatch { return Stopwatch{t: timer, start: time.Now()} }
go
func StartStopwatch(timer Timer) Stopwatch { return Stopwatch{t: timer, start: time.Now()} }
[ "func", "StartStopwatch", "(", "timer", "Timer", ")", "Stopwatch", "{", "return", "Stopwatch", "{", "t", ":", "timer", ",", "start", ":", "time", ".", "Now", "(", ")", "}", "\n", "}" ]
// StartStopwatch begins recording the executing time of an event, returning // a Stopwatch that should be used to stop the recording the time for // that event. Multiple events can be occurring simultaneously each // represented by different active Stopwatches
[ "StartStopwatch", "begins", "recording", "the", "executing", "time", "of", "an", "event", "returning", "a", "Stopwatch", "that", "should", "be", "used", "to", "stop", "the", "recording", "the", "time", "for", "that", "event", ".", "Multiple", "events", "can", "be", "occurring", "simultaneously", "each", "represented", "by", "different", "active", "Stopwatches" ]
d036253de8f5b698150d81b922486f1e8e7628ec
https://github.com/jaegertracing/jaeger-lib/blob/d036253de8f5b698150d81b922486f1e8e7628ec/metrics/stopwatch.go#L25-L27
10,893
jaegertracing/jaeger-lib
metrics/prometheus/factory.go
WithRegisterer
func WithRegisterer(registerer prometheus.Registerer) Option { return func(opts *options) { opts.registerer = registerer } }
go
func WithRegisterer(registerer prometheus.Registerer) Option { return func(opts *options) { opts.registerer = registerer } }
[ "func", "WithRegisterer", "(", "registerer", "prometheus", ".", "Registerer", ")", "Option", "{", "return", "func", "(", "opts", "*", "options", ")", "{", "opts", ".", "registerer", "=", "registerer", "\n", "}", "\n", "}" ]
// WithRegisterer returns an option that sets the registerer. // If not used we fallback to prometheus.DefaultRegisterer.
[ "WithRegisterer", "returns", "an", "option", "that", "sets", "the", "registerer", ".", "If", "not", "used", "we", "fallback", "to", "prometheus", ".", "DefaultRegisterer", "." ]
d036253de8f5b698150d81b922486f1e8e7628ec
https://github.com/jaegertracing/jaeger-lib/blob/d036253de8f5b698150d81b922486f1e8e7628ec/metrics/prometheus/factory.go#L59-L63
10,894
jaegertracing/jaeger-lib
metrics/prometheus/factory.go
New
func New(opts ...Option) *Factory { options := applyOptions(opts) return newFactory( &Factory{ // dummy struct to be discarded cache: newVectorCache(options.registerer), buckets: options.buckets, normalizer: strings.NewReplacer(".", "_", "-", "_"), separator: options.separator, }, "", // scope nil) // tags }
go
func New(opts ...Option) *Factory { options := applyOptions(opts) return newFactory( &Factory{ // dummy struct to be discarded cache: newVectorCache(options.registerer), buckets: options.buckets, normalizer: strings.NewReplacer(".", "_", "-", "_"), separator: options.separator, }, "", // scope nil) // tags }
[ "func", "New", "(", "opts", "...", "Option", ")", "*", "Factory", "{", "options", ":=", "applyOptions", "(", "opts", ")", "\n", "return", "newFactory", "(", "&", "Factory", "{", "// dummy struct to be discarded", "cache", ":", "newVectorCache", "(", "options", ".", "registerer", ")", ",", "buckets", ":", "options", ".", "buckets", ",", "normalizer", ":", "strings", ".", "NewReplacer", "(", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ")", ",", "separator", ":", "options", ".", "separator", ",", "}", ",", "\"", "\"", ",", "// scope", "nil", ")", "// tags", "\n", "}" ]
// New creates a Factory backed by Prometheus registry. // Typically the first argument should be prometheus.DefaultRegisterer. // // Parameter buckets defines the buckets into which Timer observations are counted. // Each element in the slice is the upper inclusive bound of a bucket. The // values must be sorted in strictly increasing order. There is no need // to add a highest bucket with +Inf bound, it will be added // implicitly. The default value is prometheus.DefBuckets.
[ "New", "creates", "a", "Factory", "backed", "by", "Prometheus", "registry", ".", "Typically", "the", "first", "argument", "should", "be", "prometheus", ".", "DefaultRegisterer", ".", "Parameter", "buckets", "defines", "the", "buckets", "into", "which", "Timer", "observations", "are", "counted", ".", "Each", "element", "in", "the", "slice", "is", "the", "upper", "inclusive", "bound", "of", "a", "bucket", ".", "The", "values", "must", "be", "sorted", "in", "strictly", "increasing", "order", ".", "There", "is", "no", "need", "to", "add", "a", "highest", "bucket", "with", "+", "Inf", "bound", "it", "will", "be", "added", "implicitly", ".", "The", "default", "value", "is", "prometheus", ".", "DefBuckets", "." ]
d036253de8f5b698150d81b922486f1e8e7628ec
https://github.com/jaegertracing/jaeger-lib/blob/d036253de8f5b698150d81b922486f1e8e7628ec/metrics/prometheus/factory.go#L103-L114
10,895
jaegertracing/jaeger-lib
metrics/prometheus/factory.go
Counter
func (f *Factory) Counter(options metrics.Options) metrics.Counter { help := strings.TrimSpace(options.Help) if len(help) == 0 { help = options.Name } name := counterNamingConvention(f.subScope(options.Name)) tags := f.mergeTags(options.Tags) labelNames := f.tagNames(tags) opts := prometheus.CounterOpts{ Name: name, Help: help, } cv := f.cache.getOrMakeCounterVec(opts, labelNames) return &counter{ counter: cv.WithLabelValues(f.tagsAsLabelValues(labelNames, tags)...), } }
go
func (f *Factory) Counter(options metrics.Options) metrics.Counter { help := strings.TrimSpace(options.Help) if len(help) == 0 { help = options.Name } name := counterNamingConvention(f.subScope(options.Name)) tags := f.mergeTags(options.Tags) labelNames := f.tagNames(tags) opts := prometheus.CounterOpts{ Name: name, Help: help, } cv := f.cache.getOrMakeCounterVec(opts, labelNames) return &counter{ counter: cv.WithLabelValues(f.tagsAsLabelValues(labelNames, tags)...), } }
[ "func", "(", "f", "*", "Factory", ")", "Counter", "(", "options", "metrics", ".", "Options", ")", "metrics", ".", "Counter", "{", "help", ":=", "strings", ".", "TrimSpace", "(", "options", ".", "Help", ")", "\n", "if", "len", "(", "help", ")", "==", "0", "{", "help", "=", "options", ".", "Name", "\n", "}", "\n", "name", ":=", "counterNamingConvention", "(", "f", ".", "subScope", "(", "options", ".", "Name", ")", ")", "\n", "tags", ":=", "f", ".", "mergeTags", "(", "options", ".", "Tags", ")", "\n", "labelNames", ":=", "f", ".", "tagNames", "(", "tags", ")", "\n", "opts", ":=", "prometheus", ".", "CounterOpts", "{", "Name", ":", "name", ",", "Help", ":", "help", ",", "}", "\n", "cv", ":=", "f", ".", "cache", ".", "getOrMakeCounterVec", "(", "opts", ",", "labelNames", ")", "\n", "return", "&", "counter", "{", "counter", ":", "cv", ".", "WithLabelValues", "(", "f", ".", "tagsAsLabelValues", "(", "labelNames", ",", "tags", ")", "...", ")", ",", "}", "\n", "}" ]
// Counter implements Counter of metrics.Factory.
[ "Counter", "implements", "Counter", "of", "metrics", ".", "Factory", "." ]
d036253de8f5b698150d81b922486f1e8e7628ec
https://github.com/jaegertracing/jaeger-lib/blob/d036253de8f5b698150d81b922486f1e8e7628ec/metrics/prometheus/factory.go#L128-L144
10,896
jaegertracing/jaeger-lib
metrics/prometheus/factory.go
Gauge
func (f *Factory) Gauge(options metrics.Options) metrics.Gauge { help := strings.TrimSpace(options.Help) if len(help) == 0 { help = options.Name } name := f.subScope(options.Name) tags := f.mergeTags(options.Tags) labelNames := f.tagNames(tags) opts := prometheus.GaugeOpts{ Name: name, Help: help, } gv := f.cache.getOrMakeGaugeVec(opts, labelNames) return &gauge{ gauge: gv.WithLabelValues(f.tagsAsLabelValues(labelNames, tags)...), } }
go
func (f *Factory) Gauge(options metrics.Options) metrics.Gauge { help := strings.TrimSpace(options.Help) if len(help) == 0 { help = options.Name } name := f.subScope(options.Name) tags := f.mergeTags(options.Tags) labelNames := f.tagNames(tags) opts := prometheus.GaugeOpts{ Name: name, Help: help, } gv := f.cache.getOrMakeGaugeVec(opts, labelNames) return &gauge{ gauge: gv.WithLabelValues(f.tagsAsLabelValues(labelNames, tags)...), } }
[ "func", "(", "f", "*", "Factory", ")", "Gauge", "(", "options", "metrics", ".", "Options", ")", "metrics", ".", "Gauge", "{", "help", ":=", "strings", ".", "TrimSpace", "(", "options", ".", "Help", ")", "\n", "if", "len", "(", "help", ")", "==", "0", "{", "help", "=", "options", ".", "Name", "\n", "}", "\n", "name", ":=", "f", ".", "subScope", "(", "options", ".", "Name", ")", "\n", "tags", ":=", "f", ".", "mergeTags", "(", "options", ".", "Tags", ")", "\n", "labelNames", ":=", "f", ".", "tagNames", "(", "tags", ")", "\n", "opts", ":=", "prometheus", ".", "GaugeOpts", "{", "Name", ":", "name", ",", "Help", ":", "help", ",", "}", "\n", "gv", ":=", "f", ".", "cache", ".", "getOrMakeGaugeVec", "(", "opts", ",", "labelNames", ")", "\n", "return", "&", "gauge", "{", "gauge", ":", "gv", ".", "WithLabelValues", "(", "f", ".", "tagsAsLabelValues", "(", "labelNames", ",", "tags", ")", "...", ")", ",", "}", "\n", "}" ]
// Gauge implements Gauge of metrics.Factory.
[ "Gauge", "implements", "Gauge", "of", "metrics", ".", "Factory", "." ]
d036253de8f5b698150d81b922486f1e8e7628ec
https://github.com/jaegertracing/jaeger-lib/blob/d036253de8f5b698150d81b922486f1e8e7628ec/metrics/prometheus/factory.go#L147-L163
10,897
jaegertracing/jaeger-lib
metrics/prometheus/factory.go
Timer
func (f *Factory) Timer(options metrics.TimerOptions) metrics.Timer { help := strings.TrimSpace(options.Help) if len(help) == 0 { help = options.Name } name := f.subScope(options.Name) tags := f.mergeTags(options.Tags) labelNames := f.tagNames(tags) opts := prometheus.HistogramOpts{ Name: name, Help: help, Buckets: asFloatBuckets(options.Buckets), } hv := f.cache.getOrMakeHistogramVec(opts, labelNames) return &timer{ histogram: hv.WithLabelValues(f.tagsAsLabelValues(labelNames, tags)...), } }
go
func (f *Factory) Timer(options metrics.TimerOptions) metrics.Timer { help := strings.TrimSpace(options.Help) if len(help) == 0 { help = options.Name } name := f.subScope(options.Name) tags := f.mergeTags(options.Tags) labelNames := f.tagNames(tags) opts := prometheus.HistogramOpts{ Name: name, Help: help, Buckets: asFloatBuckets(options.Buckets), } hv := f.cache.getOrMakeHistogramVec(opts, labelNames) return &timer{ histogram: hv.WithLabelValues(f.tagsAsLabelValues(labelNames, tags)...), } }
[ "func", "(", "f", "*", "Factory", ")", "Timer", "(", "options", "metrics", ".", "TimerOptions", ")", "metrics", ".", "Timer", "{", "help", ":=", "strings", ".", "TrimSpace", "(", "options", ".", "Help", ")", "\n", "if", "len", "(", "help", ")", "==", "0", "{", "help", "=", "options", ".", "Name", "\n", "}", "\n", "name", ":=", "f", ".", "subScope", "(", "options", ".", "Name", ")", "\n", "tags", ":=", "f", ".", "mergeTags", "(", "options", ".", "Tags", ")", "\n", "labelNames", ":=", "f", ".", "tagNames", "(", "tags", ")", "\n", "opts", ":=", "prometheus", ".", "HistogramOpts", "{", "Name", ":", "name", ",", "Help", ":", "help", ",", "Buckets", ":", "asFloatBuckets", "(", "options", ".", "Buckets", ")", ",", "}", "\n", "hv", ":=", "f", ".", "cache", ".", "getOrMakeHistogramVec", "(", "opts", ",", "labelNames", ")", "\n", "return", "&", "timer", "{", "histogram", ":", "hv", ".", "WithLabelValues", "(", "f", ".", "tagsAsLabelValues", "(", "labelNames", ",", "tags", ")", "...", ")", ",", "}", "\n", "}" ]
// Timer implements Timer of metrics.Factory.
[ "Timer", "implements", "Timer", "of", "metrics", ".", "Factory", "." ]
d036253de8f5b698150d81b922486f1e8e7628ec
https://github.com/jaegertracing/jaeger-lib/blob/d036253de8f5b698150d81b922486f1e8e7628ec/metrics/prometheus/factory.go#L166-L183
10,898
jaegertracing/jaeger-lib
metrics/prometheus/factory.go
Namespace
func (f *Factory) Namespace(scope metrics.NSOptions) metrics.Factory { return newFactory(f, f.subScope(scope.Name), f.mergeTags(scope.Tags)) }
go
func (f *Factory) Namespace(scope metrics.NSOptions) metrics.Factory { return newFactory(f, f.subScope(scope.Name), f.mergeTags(scope.Tags)) }
[ "func", "(", "f", "*", "Factory", ")", "Namespace", "(", "scope", "metrics", ".", "NSOptions", ")", "metrics", ".", "Factory", "{", "return", "newFactory", "(", "f", ",", "f", ".", "subScope", "(", "scope", ".", "Name", ")", ",", "f", ".", "mergeTags", "(", "scope", ".", "Tags", ")", ")", "\n", "}" ]
// Namespace implements Namespace of metrics.Factory.
[ "Namespace", "implements", "Namespace", "of", "metrics", ".", "Factory", "." ]
d036253de8f5b698150d81b922486f1e8e7628ec
https://github.com/jaegertracing/jaeger-lib/blob/d036253de8f5b698150d81b922486f1e8e7628ec/metrics/prometheus/factory.go#L214-L216
10,899
terraform-providers/terraform-provider-random
random/seed.go
NewRand
func NewRand(seed string) *rand.Rand { var seedInt int64 if seed != "" { crcTable := crc64.MakeTable(crc64.ISO) seedInt = int64(crc64.Checksum([]byte(seed), crcTable)) } else { seedInt = time.Now().UnixNano() } randSource := rand.NewSource(seedInt) return rand.New(randSource) }
go
func NewRand(seed string) *rand.Rand { var seedInt int64 if seed != "" { crcTable := crc64.MakeTable(crc64.ISO) seedInt = int64(crc64.Checksum([]byte(seed), crcTable)) } else { seedInt = time.Now().UnixNano() } randSource := rand.NewSource(seedInt) return rand.New(randSource) }
[ "func", "NewRand", "(", "seed", "string", ")", "*", "rand", ".", "Rand", "{", "var", "seedInt", "int64", "\n", "if", "seed", "!=", "\"", "\"", "{", "crcTable", ":=", "crc64", ".", "MakeTable", "(", "crc64", ".", "ISO", ")", "\n", "seedInt", "=", "int64", "(", "crc64", ".", "Checksum", "(", "[", "]", "byte", "(", "seed", ")", ",", "crcTable", ")", ")", "\n", "}", "else", "{", "seedInt", "=", "time", ".", "Now", "(", ")", ".", "UnixNano", "(", ")", "\n", "}", "\n\n", "randSource", ":=", "rand", ".", "NewSource", "(", "seedInt", ")", "\n", "return", "rand", ".", "New", "(", "randSource", ")", "\n", "}" ]
// NewRand returns a seeded random number generator, using a seed derived // from the provided string. // // If the seed string is empty, the current time is used as a seed.
[ "NewRand", "returns", "a", "seeded", "random", "number", "generator", "using", "a", "seed", "derived", "from", "the", "provided", "string", ".", "If", "the", "seed", "string", "is", "empty", "the", "current", "time", "is", "used", "as", "a", "seed", "." ]
b26d937826325f1eca0434bb0e9c97cbf4e369d4
https://github.com/terraform-providers/terraform-provider-random/blob/b26d937826325f1eca0434bb0e9c97cbf4e369d4/random/seed.go#L13-L24