id
int32
0
167k
repo
stringlengths
5
54
path
stringlengths
4
155
func_name
stringlengths
1
118
original_string
stringlengths
52
85.5k
language
stringclasses
1 value
code
stringlengths
52
85.5k
code_tokens
listlengths
21
1.41k
docstring
stringlengths
6
2.61k
docstring_tokens
listlengths
3
215
sha
stringlengths
40
40
url
stringlengths
85
252
9,000
glycerine/zygomys
zygo/builders.go
ArrayOfFunction
func ArrayOfFunction(env *Zlisp, name string, args []Sexp) (Sexp, error) { if len(args) != 2 { return SexpNull, fmt.Errorf("insufficient arguments to ([size] regtype) array constructor. use: " + "([size...] a-regtype)\n") } sz := 0 Q("args = %#v in ArrayOfFunction", args) switch ar := args[1].(type) { case *SexpArray: if len(ar.Val) == 0 { return SexpNull, fmt.Errorf("at least one size must be specified in array constructor; e.g. ([size ...] regtype)") } asInt, isInt := ar.Val[0].(*SexpInt) if !isInt { return SexpNull, fmt.Errorf("size must be an int (not %T) in array constructor; e.g. ([size ...] regtype)", ar.Val[0]) } sz = int(asInt.Val) // TODO: implement multiple dimensional arrays (matrixes etc). default: return SexpNull, fmt.Errorf("at least one size must be specified in array constructor; e.g. ([size ...] regtype)") } var rt *RegisteredType switch arg := args[0].(type) { case *RegisteredType: rt = arg case *SexpHash: rt = arg.GoStructFactory default: return SexpNull, fmt.Errorf("argument tx in (%s x) was not regtype, "+ "instead type %T displaying as '%v' ", name, arg, arg.SexpString(nil)) } //Q("arrayOf arg = '%s' with type %T", args[0].SexpString(nil), args[0]) derivedType := reflect.ArrayOf(sz, rt.TypeCache) arrayRt := NewRegisteredType(func(env *Zlisp, h *SexpHash) (interface{}, error) { return reflect.New(derivedType), nil }) arrayRt.DisplayAs = fmt.Sprintf("(%s %s)", name, rt.DisplayAs) arrayName := "arrayOf" + rt.RegisteredName GoStructRegistry.RegisterUserdef(arrayRt, false, arrayName) return arrayRt, nil }
go
func ArrayOfFunction(env *Zlisp, name string, args []Sexp) (Sexp, error) { if len(args) != 2 { return SexpNull, fmt.Errorf("insufficient arguments to ([size] regtype) array constructor. use: " + "([size...] a-regtype)\n") } sz := 0 Q("args = %#v in ArrayOfFunction", args) switch ar := args[1].(type) { case *SexpArray: if len(ar.Val) == 0 { return SexpNull, fmt.Errorf("at least one size must be specified in array constructor; e.g. ([size ...] regtype)") } asInt, isInt := ar.Val[0].(*SexpInt) if !isInt { return SexpNull, fmt.Errorf("size must be an int (not %T) in array constructor; e.g. ([size ...] regtype)", ar.Val[0]) } sz = int(asInt.Val) // TODO: implement multiple dimensional arrays (matrixes etc). default: return SexpNull, fmt.Errorf("at least one size must be specified in array constructor; e.g. ([size ...] regtype)") } var rt *RegisteredType switch arg := args[0].(type) { case *RegisteredType: rt = arg case *SexpHash: rt = arg.GoStructFactory default: return SexpNull, fmt.Errorf("argument tx in (%s x) was not regtype, "+ "instead type %T displaying as '%v' ", name, arg, arg.SexpString(nil)) } //Q("arrayOf arg = '%s' with type %T", args[0].SexpString(nil), args[0]) derivedType := reflect.ArrayOf(sz, rt.TypeCache) arrayRt := NewRegisteredType(func(env *Zlisp, h *SexpHash) (interface{}, error) { return reflect.New(derivedType), nil }) arrayRt.DisplayAs = fmt.Sprintf("(%s %s)", name, rt.DisplayAs) arrayName := "arrayOf" + rt.RegisteredName GoStructRegistry.RegisterUserdef(arrayRt, false, arrayName) return arrayRt, nil }
[ "func", "ArrayOfFunction", "(", "env", "*", "Zlisp", ",", "name", "string", ",", "args", "[", "]", "Sexp", ")", "(", "Sexp", ",", "error", ")", "{", "if", "len", "(", "args", ")", "!=", "2", "{", "return", "SexpNull", ",", "fmt", ".", "Errorf", "(", "\"", "\"", "+", "\"", "\\n", "\"", ")", "\n", "}", "\n", "sz", ":=", "0", "\n", "Q", "(", "\"", "\"", ",", "args", ")", "\n", "switch", "ar", ":=", "args", "[", "1", "]", ".", "(", "type", ")", "{", "case", "*", "SexpArray", ":", "if", "len", "(", "ar", ".", "Val", ")", "==", "0", "{", "return", "SexpNull", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n", "asInt", ",", "isInt", ":=", "ar", ".", "Val", "[", "0", "]", ".", "(", "*", "SexpInt", ")", "\n", "if", "!", "isInt", "{", "return", "SexpNull", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "ar", ".", "Val", "[", "0", "]", ")", "\n", "}", "\n", "sz", "=", "int", "(", "asInt", ".", "Val", ")", "\n", "// TODO: implement multiple dimensional arrays (matrixes etc).", "default", ":", "return", "SexpNull", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n\n", "var", "rt", "*", "RegisteredType", "\n", "switch", "arg", ":=", "args", "[", "0", "]", ".", "(", "type", ")", "{", "case", "*", "RegisteredType", ":", "rt", "=", "arg", "\n", "case", "*", "SexpHash", ":", "rt", "=", "arg", ".", "GoStructFactory", "\n", "default", ":", "return", "SexpNull", ",", "fmt", ".", "Errorf", "(", "\"", "\"", "+", "\"", "\"", ",", "name", ",", "arg", ",", "arg", ".", "SexpString", "(", "nil", ")", ")", "\n", "}", "\n\n", "//Q(\"arrayOf arg = '%s' with type %T\", args[0].SexpString(nil), args[0])", "derivedType", ":=", "reflect", ".", "ArrayOf", "(", "sz", ",", "rt", ".", "TypeCache", ")", "\n", "arrayRt", ":=", "NewRegisteredType", "(", "func", "(", "env", "*", "Zlisp", ",", "h", "*", "SexpHash", ")", "(", "interface", "{", "}", ",", "error", ")", "{", "return", "reflect", ".", "New", "(", "derivedType", ")", ",", "nil", "\n", "}", ")", "\n", "arrayRt", ".", "DisplayAs", "=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "name", ",", "rt", ".", "DisplayAs", ")", "\n", "arrayName", ":=", "\"", "\"", "+", "rt", ".", "RegisteredName", "\n", "GoStructRegistry", ".", "RegisterUserdef", "(", "arrayRt", ",", "false", ",", "arrayName", ")", "\n", "return", "arrayRt", ",", "nil", "\n", "}" ]
// generate fixed size array
[ "generate", "fixed", "size", "array" ]
36f1c7120ff2d831cebbb6f059ddc948273a8b56
https://github.com/glycerine/zygomys/blob/36f1c7120ff2d831cebbb6f059ddc948273a8b56/zygo/builders.go#L626-L672
9,001
glycerine/zygomys
zygo/comparisons.go
compareUint64
func compareUint64(i *SexpUint64, expr Sexp) (int, error) { switch e := expr.(type) { case *SexpUint64: return signumUint64(i.Val - e.Val), nil } errmsg := fmt.Sprintf("err 101: cannot compare %T to %T", i, expr) return 0, errors.New(errmsg) }
go
func compareUint64(i *SexpUint64, expr Sexp) (int, error) { switch e := expr.(type) { case *SexpUint64: return signumUint64(i.Val - e.Val), nil } errmsg := fmt.Sprintf("err 101: cannot compare %T to %T", i, expr) return 0, errors.New(errmsg) }
[ "func", "compareUint64", "(", "i", "*", "SexpUint64", ",", "expr", "Sexp", ")", "(", "int", ",", "error", ")", "{", "switch", "e", ":=", "expr", ".", "(", "type", ")", "{", "case", "*", "SexpUint64", ":", "return", "signumUint64", "(", "i", ".", "Val", "-", "e", ".", "Val", ")", ",", "nil", "\n", "}", "\n", "errmsg", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "i", ",", "expr", ")", "\n", "return", "0", ",", "errors", ".", "New", "(", "errmsg", ")", "\n", "}" ]
// only compare uint64 to uint64
[ "only", "compare", "uint64", "to", "uint64" ]
36f1c7120ff2d831cebbb6f059ddc948273a8b56
https://github.com/glycerine/zygomys/blob/36f1c7120ff2d831cebbb6f059ddc948273a8b56/zygo/comparisons.go#L306-L313
9,002
glycerine/zygomys
slides/coro/parser.go
parseExpression
func (parser *Parser) parseExpression(depth int) (res Sexp, err error) { //getAnother: tok, err := parser.lexer.getNextToken() if err != nil { return SexpEnd, err } switch tok.typ { case TokenLParen: exp, err := parser.parseList(depth + 1) return exp, err case TokenLSquare: exp, err := parser.parseArray(depth + 1) return exp, err case TokenLCurly: exp, err := parser.parseInfix(depth + 1) return exp, err case TokenQuote: expr, err := parser.parseExpression(depth + 1) if err != nil { return SexpNull, err } return MakeList([]Sexp{parser.env.MakeSymbol("quote"), expr}), nil case TokenCaret: //... } }
go
func (parser *Parser) parseExpression(depth int) (res Sexp, err error) { //getAnother: tok, err := parser.lexer.getNextToken() if err != nil { return SexpEnd, err } switch tok.typ { case TokenLParen: exp, err := parser.parseList(depth + 1) return exp, err case TokenLSquare: exp, err := parser.parseArray(depth + 1) return exp, err case TokenLCurly: exp, err := parser.parseInfix(depth + 1) return exp, err case TokenQuote: expr, err := parser.parseExpression(depth + 1) if err != nil { return SexpNull, err } return MakeList([]Sexp{parser.env.MakeSymbol("quote"), expr}), nil case TokenCaret: //... } }
[ "func", "(", "parser", "*", "Parser", ")", "parseExpression", "(", "depth", "int", ")", "(", "res", "Sexp", ",", "err", "error", ")", "{", "//getAnother:", "tok", ",", "err", ":=", "parser", ".", "lexer", ".", "getNextToken", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "SexpEnd", ",", "err", "\n", "}", "\n\n", "switch", "tok", ".", "typ", "{", "case", "TokenLParen", ":", "exp", ",", "err", ":=", "parser", ".", "parseList", "(", "depth", "+", "1", ")", "\n", "return", "exp", ",", "err", "\n", "case", "TokenLSquare", ":", "exp", ",", "err", ":=", "parser", ".", "parseArray", "(", "depth", "+", "1", ")", "\n", "return", "exp", ",", "err", "\n", "case", "TokenLCurly", ":", "exp", ",", "err", ":=", "parser", ".", "parseInfix", "(", "depth", "+", "1", ")", "\n", "return", "exp", ",", "err", "\n", "case", "TokenQuote", ":", "expr", ",", "err", ":=", "parser", ".", "parseExpression", "(", "depth", "+", "1", ")", "\n", "if", "err", "!=", "nil", "{", "return", "SexpNull", ",", "err", "\n", "}", "\n", "return", "MakeList", "(", "[", "]", "Sexp", "{", "parser", ".", "env", ".", "MakeSymbol", "(", "\"", "\"", ")", ",", "expr", "}", ")", ",", "nil", "\n", "case", "TokenCaret", ":", "//...", "}", "\n", "}" ]
// ParserExpression is an internal Parser routine - the // main one for parsing expressions
[ "ParserExpression", "is", "an", "internal", "Parser", "routine", "-", "the", "main", "one", "for", "parsing", "expressions" ]
36f1c7120ff2d831cebbb6f059ddc948273a8b56
https://github.com/glycerine/zygomys/blob/36f1c7120ff2d831cebbb6f059ddc948273a8b56/slides/coro/parser.go#L222-L249
9,003
glycerine/zygomys
zygo/stack.go
TruncateToSize
func (stack *Stack) TruncateToSize(newsize int) { el := make([]StackElem, newsize) copy(el, stack.elements) stack.elements = el stack.tos = newsize - 1 }
go
func (stack *Stack) TruncateToSize(newsize int) { el := make([]StackElem, newsize) copy(el, stack.elements) stack.elements = el stack.tos = newsize - 1 }
[ "func", "(", "stack", "*", "Stack", ")", "TruncateToSize", "(", "newsize", "int", ")", "{", "el", ":=", "make", "(", "[", "]", "StackElem", ",", "newsize", ")", "\n", "copy", "(", "el", ",", "stack", ".", "elements", ")", "\n", "stack", ".", "elements", "=", "el", "\n", "stack", ".", "tos", "=", "newsize", "-", "1", "\n", "}" ]
// set newsize to 0 to truncate everything
[ "set", "newsize", "to", "0", "to", "truncate", "everything" ]
36f1c7120ff2d831cebbb6f059ddc948273a8b56
https://github.com/glycerine/zygomys/blob/36f1c7120ff2d831cebbb6f059ddc948273a8b56/zygo/stack.go#L196-L201
9,004
glycerine/zygomys
zygo/stack.go
nestedPathGetSet
func (s *Stack) nestedPathGetSet(env *Zlisp, dotpaths []string, setVal *Sexp) (Sexp, error) { if len(dotpaths) == 0 { return SexpNull, fmt.Errorf("internal error: in nestedPathGetSet() dotpaths" + " had zero length") } curStack := s var ret Sexp = SexpNull var err error var scop *Scope lenpath := len(dotpaths) //P("\n in nestedPathGetSet, dotpaths=%#v\n", dotpaths) for i := range dotpaths { curSym := env.MakeSymbol(stripAnyDotPrefix(dotpaths[i])) if !curStack.IsPackage { return SexpNull, fmt.Errorf("error locating symbol '%s': current Stack is not a package", curSym.name) } ret, err, scop = curStack.LookupSymbol(curSym, nil) if err != nil { return SexpNull, fmt.Errorf("could not find symbol '%s' in current package '%v'", curSym.name, curStack.PackageName) } if setVal != nil && i == lenpath-1 { // check if private err = errIfPrivate(curSym.name, curStack) if err != nil { return SexpNull, err } // assign now scop.Map[curSym.number] = *setVal // done with SET return *setVal, nil } if i == lenpath-1 { // final element switch ret.(type) { case *Stack: // allow package within package to be inspected. // done with GET return ret, nil default: // don't allow private value within package to be inspected. err = errIfPrivate(curSym.name, curStack) if err != nil { return SexpNull, err } } // done with GET return ret, nil } // invar: i < lenpath-1, so go deeper switch x := ret.(type) { case *SexpHash: err = errIfPrivate(curSym.name, curStack) if err != nil { return SexpNull, err } //P("\n found hash in x at i=%d, looping to next i\n", i) return x.nestedPathGetSet(env, dotpaths[1:], setVal) case *Stack: curStack = x default: return SexpNull, fmt.Errorf("not a record or scope: cannot get field '%s'"+ " out of type %T)", dotpaths[i+1][1:], x) } } return ret, nil }
go
func (s *Stack) nestedPathGetSet(env *Zlisp, dotpaths []string, setVal *Sexp) (Sexp, error) { if len(dotpaths) == 0 { return SexpNull, fmt.Errorf("internal error: in nestedPathGetSet() dotpaths" + " had zero length") } curStack := s var ret Sexp = SexpNull var err error var scop *Scope lenpath := len(dotpaths) //P("\n in nestedPathGetSet, dotpaths=%#v\n", dotpaths) for i := range dotpaths { curSym := env.MakeSymbol(stripAnyDotPrefix(dotpaths[i])) if !curStack.IsPackage { return SexpNull, fmt.Errorf("error locating symbol '%s': current Stack is not a package", curSym.name) } ret, err, scop = curStack.LookupSymbol(curSym, nil) if err != nil { return SexpNull, fmt.Errorf("could not find symbol '%s' in current package '%v'", curSym.name, curStack.PackageName) } if setVal != nil && i == lenpath-1 { // check if private err = errIfPrivate(curSym.name, curStack) if err != nil { return SexpNull, err } // assign now scop.Map[curSym.number] = *setVal // done with SET return *setVal, nil } if i == lenpath-1 { // final element switch ret.(type) { case *Stack: // allow package within package to be inspected. // done with GET return ret, nil default: // don't allow private value within package to be inspected. err = errIfPrivate(curSym.name, curStack) if err != nil { return SexpNull, err } } // done with GET return ret, nil } // invar: i < lenpath-1, so go deeper switch x := ret.(type) { case *SexpHash: err = errIfPrivate(curSym.name, curStack) if err != nil { return SexpNull, err } //P("\n found hash in x at i=%d, looping to next i\n", i) return x.nestedPathGetSet(env, dotpaths[1:], setVal) case *Stack: curStack = x default: return SexpNull, fmt.Errorf("not a record or scope: cannot get field '%s'"+ " out of type %T)", dotpaths[i+1][1:], x) } } return ret, nil }
[ "func", "(", "s", "*", "Stack", ")", "nestedPathGetSet", "(", "env", "*", "Zlisp", ",", "dotpaths", "[", "]", "string", ",", "setVal", "*", "Sexp", ")", "(", "Sexp", ",", "error", ")", "{", "if", "len", "(", "dotpaths", ")", "==", "0", "{", "return", "SexpNull", ",", "fmt", ".", "Errorf", "(", "\"", "\"", "+", "\"", "\"", ")", "\n", "}", "\n\n", "curStack", ":=", "s", "\n\n", "var", "ret", "Sexp", "=", "SexpNull", "\n", "var", "err", "error", "\n", "var", "scop", "*", "Scope", "\n", "lenpath", ":=", "len", "(", "dotpaths", ")", "\n", "//P(\"\\n in nestedPathGetSet, dotpaths=%#v\\n\", dotpaths)", "for", "i", ":=", "range", "dotpaths", "{", "curSym", ":=", "env", ".", "MakeSymbol", "(", "stripAnyDotPrefix", "(", "dotpaths", "[", "i", "]", ")", ")", "\n", "if", "!", "curStack", ".", "IsPackage", "{", "return", "SexpNull", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "curSym", ".", "name", ")", "\n", "}", "\n\n", "ret", ",", "err", ",", "scop", "=", "curStack", ".", "LookupSymbol", "(", "curSym", ",", "nil", ")", "\n", "if", "err", "!=", "nil", "{", "return", "SexpNull", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "curSym", ".", "name", ",", "curStack", ".", "PackageName", ")", "\n", "}", "\n", "if", "setVal", "!=", "nil", "&&", "i", "==", "lenpath", "-", "1", "{", "// check if private", "err", "=", "errIfPrivate", "(", "curSym", ".", "name", ",", "curStack", ")", "\n", "if", "err", "!=", "nil", "{", "return", "SexpNull", ",", "err", "\n", "}", "\n\n", "// assign now", "scop", ".", "Map", "[", "curSym", ".", "number", "]", "=", "*", "setVal", "\n", "// done with SET", "return", "*", "setVal", ",", "nil", "\n", "}", "\n\n", "if", "i", "==", "lenpath", "-", "1", "{", "// final element", "switch", "ret", ".", "(", "type", ")", "{", "case", "*", "Stack", ":", "// allow package within package to be inspected.", "// done with GET", "return", "ret", ",", "nil", "\n", "default", ":", "// don't allow private value within package to be inspected.", "err", "=", "errIfPrivate", "(", "curSym", ".", "name", ",", "curStack", ")", "\n", "if", "err", "!=", "nil", "{", "return", "SexpNull", ",", "err", "\n", "}", "\n", "}", "\n", "// done with GET", "return", "ret", ",", "nil", "\n", "}", "\n", "// invar: i < lenpath-1, so go deeper", "switch", "x", ":=", "ret", ".", "(", "type", ")", "{", "case", "*", "SexpHash", ":", "err", "=", "errIfPrivate", "(", "curSym", ".", "name", ",", "curStack", ")", "\n", "if", "err", "!=", "nil", "{", "return", "SexpNull", ",", "err", "\n", "}", "\n", "//P(\"\\n found hash in x at i=%d, looping to next i\\n\", i)", "return", "x", ".", "nestedPathGetSet", "(", "env", ",", "dotpaths", "[", "1", ":", "]", ",", "setVal", ")", "\n", "case", "*", "Stack", ":", "curStack", "=", "x", "\n", "default", ":", "return", "SexpNull", ",", "fmt", ".", "Errorf", "(", "\"", "\"", "+", "\"", "\"", ",", "dotpaths", "[", "i", "+", "1", "]", "[", "1", ":", "]", ",", "x", ")", "\n", "}", "\n\n", "}", "\n", "return", "ret", ",", "nil", "\n", "}" ]
// nestedPathGetSet does a top-down lookup, as opposed to LexicalLookupSymbol which is bottom up
[ "nestedPathGetSet", "does", "a", "top", "-", "down", "lookup", "as", "opposed", "to", "LexicalLookupSymbol", "which", "is", "bottom", "up" ]
36f1c7120ff2d831cebbb6f059ddc948273a8b56
https://github.com/glycerine/zygomys/blob/36f1c7120ff2d831cebbb6f059ddc948273a8b56/zygo/stack.go#L204-L278
9,005
mwitkow/go-proto-validators
helper.go
FieldError
func FieldError(fieldName string, err error) error { if fErr, ok := err.(*fieldError); ok { fErr.fieldStack = append([]string{fieldName}, fErr.fieldStack...) return err } return &fieldError{ fieldStack: []string{fieldName}, nestedErr: err, } }
go
func FieldError(fieldName string, err error) error { if fErr, ok := err.(*fieldError); ok { fErr.fieldStack = append([]string{fieldName}, fErr.fieldStack...) return err } return &fieldError{ fieldStack: []string{fieldName}, nestedErr: err, } }
[ "func", "FieldError", "(", "fieldName", "string", ",", "err", "error", ")", "error", "{", "if", "fErr", ",", "ok", ":=", "err", ".", "(", "*", "fieldError", ")", ";", "ok", "{", "fErr", ".", "fieldStack", "=", "append", "(", "[", "]", "string", "{", "fieldName", "}", ",", "fErr", ".", "fieldStack", "...", ")", "\n", "return", "err", "\n", "}", "\n", "return", "&", "fieldError", "{", "fieldStack", ":", "[", "]", "string", "{", "fieldName", "}", ",", "nestedErr", ":", "err", ",", "}", "\n", "}" ]
// FieldError wraps a given Validator error providing a message call stack.
[ "FieldError", "wraps", "a", "given", "Validator", "error", "providing", "a", "message", "call", "stack", "." ]
1f388280e944c97cc59c75d8c84a704097d1f1d6
https://github.com/mwitkow/go-proto-validators/blob/1f388280e944c97cc59c75d8c84a704097d1f1d6/helper.go#L30-L39
9,006
betacraft/yaag
examples/iris/main.go
newApp
func newApp() *iris.Application { app := iris.New() yaag.Init(&yaag.Config{ // <- IMPORTANT, init the middleware. On: true, DocTitle: "Iris", DocPath: "apidoc.html", BaseUrls: map[string]string{"Production": "", "Staging": ""}, }) app.Use(irisyaag.New()) // <- IMPORTANT, register the middleware. app.Get("/json", func(ctx context.Context) { ctx.JSON(context.Map{"result": "Hello World!"}) }) app.Get("/plain", func(ctx context.Context) { ctx.Text("Hello World!") }) app.Get("/xml", func(ctx context.Context) { ctx.XML(myXML{Result: "Hello World!"}) }) app.Get("/complex", func(ctx context.Context) { value := ctx.URLParam("key") ctx.JSON(context.Map{"value": value}) }) app.Post("/reqbody", func(ctx context.Context) { var model myModel ctx.ReadJSON(&model) ctx.Writef(model.Username) }) app.Post("/hello", func(ctx context.Context) { username := ctx.FormValue("username") ctx.Writef("Hello %s", username) }) return app }
go
func newApp() *iris.Application { app := iris.New() yaag.Init(&yaag.Config{ // <- IMPORTANT, init the middleware. On: true, DocTitle: "Iris", DocPath: "apidoc.html", BaseUrls: map[string]string{"Production": "", "Staging": ""}, }) app.Use(irisyaag.New()) // <- IMPORTANT, register the middleware. app.Get("/json", func(ctx context.Context) { ctx.JSON(context.Map{"result": "Hello World!"}) }) app.Get("/plain", func(ctx context.Context) { ctx.Text("Hello World!") }) app.Get("/xml", func(ctx context.Context) { ctx.XML(myXML{Result: "Hello World!"}) }) app.Get("/complex", func(ctx context.Context) { value := ctx.URLParam("key") ctx.JSON(context.Map{"value": value}) }) app.Post("/reqbody", func(ctx context.Context) { var model myModel ctx.ReadJSON(&model) ctx.Writef(model.Username) }) app.Post("/hello", func(ctx context.Context) { username := ctx.FormValue("username") ctx.Writef("Hello %s", username) }) return app }
[ "func", "newApp", "(", ")", "*", "iris", ".", "Application", "{", "app", ":=", "iris", ".", "New", "(", ")", "\n\n", "yaag", ".", "Init", "(", "&", "yaag", ".", "Config", "{", "// <- IMPORTANT, init the middleware.", "On", ":", "true", ",", "DocTitle", ":", "\"", "\"", ",", "DocPath", ":", "\"", "\"", ",", "BaseUrls", ":", "map", "[", "string", "]", "string", "{", "\"", "\"", ":", "\"", "\"", ",", "\"", "\"", ":", "\"", "\"", "}", ",", "}", ")", "\n\n", "app", ".", "Use", "(", "irisyaag", ".", "New", "(", ")", ")", "// <- IMPORTANT, register the middleware.", "\n\n", "app", ".", "Get", "(", "\"", "\"", ",", "func", "(", "ctx", "context", ".", "Context", ")", "{", "ctx", ".", "JSON", "(", "context", ".", "Map", "{", "\"", "\"", ":", "\"", "\"", "}", ")", "\n", "}", ")", "\n\n", "app", ".", "Get", "(", "\"", "\"", ",", "func", "(", "ctx", "context", ".", "Context", ")", "{", "ctx", ".", "Text", "(", "\"", "\"", ")", "\n", "}", ")", "\n\n", "app", ".", "Get", "(", "\"", "\"", ",", "func", "(", "ctx", "context", ".", "Context", ")", "{", "ctx", ".", "XML", "(", "myXML", "{", "Result", ":", "\"", "\"", "}", ")", "\n", "}", ")", "\n\n", "app", ".", "Get", "(", "\"", "\"", ",", "func", "(", "ctx", "context", ".", "Context", ")", "{", "value", ":=", "ctx", ".", "URLParam", "(", "\"", "\"", ")", "\n", "ctx", ".", "JSON", "(", "context", ".", "Map", "{", "\"", "\"", ":", "value", "}", ")", "\n", "}", ")", "\n\n", "app", ".", "Post", "(", "\"", "\"", ",", "func", "(", "ctx", "context", ".", "Context", ")", "{", "var", "model", "myModel", "\n", "ctx", ".", "ReadJSON", "(", "&", "model", ")", "\n", "ctx", ".", "Writef", "(", "model", ".", "Username", ")", "\n", "}", ")", "\n\n", "app", ".", "Post", "(", "\"", "\"", ",", "func", "(", "ctx", "context", ".", "Context", ")", "{", "username", ":=", "ctx", ".", "FormValue", "(", "\"", "\"", ")", "\n", "ctx", ".", "Writef", "(", "\"", "\"", ",", "username", ")", "\n", "}", ")", "\n\n", "return", "app", "\n", "}" ]
// create a function to initialize our app and yaag middleware // in order to be used on the test file as well.
[ "create", "a", "function", "to", "initialize", "our", "app", "and", "yaag", "middleware", "in", "order", "to", "be", "used", "on", "the", "test", "file", "as", "well", "." ]
872e1276787c38aa9e8e25e67419268261f15865
https://github.com/betacraft/yaag/blob/872e1276787c38aa9e8e25e67419268261f15865/examples/iris/main.go#L22-L63
9,007
betacraft/yaag
irisyaag/middleware.go
New
func New() context.Handler { return func(ctx context.Context) { if !yaag.IsOn() { // execute the main handler and exit if yaag is off. ctx.Next() return } // prepare the middleware. apiCall := &models.ApiCall{} middleware.Before(apiCall, ctx.Request()) // start the recorder instead of raw response writer, // response writer is changed for that handler now. ctx.Record() // and then fire the "main" handler. ctx.Next() //iris recorder is not http.ResponseWriter! So need to map it. r := middleware.NewResponseRecorder(ctx.Recorder().Naive()) r.Body = bytes.NewBuffer(ctx.Recorder().Body()) r.Status = ctx.Recorder().StatusCode() //iris recorder writes the recorded data to its original response recorder. So pass the testrecorder // as responsewriter to after call. middleware.After(apiCall, r, ctx.Request()) } }
go
func New() context.Handler { return func(ctx context.Context) { if !yaag.IsOn() { // execute the main handler and exit if yaag is off. ctx.Next() return } // prepare the middleware. apiCall := &models.ApiCall{} middleware.Before(apiCall, ctx.Request()) // start the recorder instead of raw response writer, // response writer is changed for that handler now. ctx.Record() // and then fire the "main" handler. ctx.Next() //iris recorder is not http.ResponseWriter! So need to map it. r := middleware.NewResponseRecorder(ctx.Recorder().Naive()) r.Body = bytes.NewBuffer(ctx.Recorder().Body()) r.Status = ctx.Recorder().StatusCode() //iris recorder writes the recorded data to its original response recorder. So pass the testrecorder // as responsewriter to after call. middleware.After(apiCall, r, ctx.Request()) } }
[ "func", "New", "(", ")", "context", ".", "Handler", "{", "return", "func", "(", "ctx", "context", ".", "Context", ")", "{", "if", "!", "yaag", ".", "IsOn", "(", ")", "{", "// execute the main handler and exit if yaag is off.", "ctx", ".", "Next", "(", ")", "\n", "return", "\n", "}", "\n\n", "// prepare the middleware.", "apiCall", ":=", "&", "models", ".", "ApiCall", "{", "}", "\n", "middleware", ".", "Before", "(", "apiCall", ",", "ctx", ".", "Request", "(", ")", ")", "\n\n", "// start the recorder instead of raw response writer,", "// response writer is changed for that handler now.", "ctx", ".", "Record", "(", ")", "\n", "// and then fire the \"main\" handler.", "ctx", ".", "Next", "(", ")", "\n\n", "//iris recorder is not http.ResponseWriter! So need to map it.", "r", ":=", "middleware", ".", "NewResponseRecorder", "(", "ctx", ".", "Recorder", "(", ")", ".", "Naive", "(", ")", ")", "\n", "r", ".", "Body", "=", "bytes", ".", "NewBuffer", "(", "ctx", ".", "Recorder", "(", ")", ".", "Body", "(", ")", ")", "\n", "r", ".", "Status", "=", "ctx", ".", "Recorder", "(", ")", ".", "StatusCode", "(", ")", "\n\n", "//iris recorder writes the recorded data to its original response recorder. So pass the testrecorder", "// as responsewriter to after call.", "middleware", ".", "After", "(", "apiCall", ",", "r", ",", "ctx", ".", "Request", "(", ")", ")", "\n", "}", "\n", "}" ]
// New returns a new yaag iris-compatible handler which is responsible to generate the rest API.
[ "New", "returns", "a", "new", "yaag", "iris", "-", "compatible", "handler", "which", "is", "responsible", "to", "generate", "the", "rest", "API", "." ]
872e1276787c38aa9e8e25e67419268261f15865
https://github.com/betacraft/yaag/blob/872e1276787c38aa9e8e25e67419268261f15865/irisyaag/middleware.go#L13-L40
9,008
Rhymond/go-money
money.go
New
func New(amount int64, code string) *Money { return &Money{ amount: &Amount{val: amount}, currency: newCurrency(code).get(), } }
go
func New(amount int64, code string) *Money { return &Money{ amount: &Amount{val: amount}, currency: newCurrency(code).get(), } }
[ "func", "New", "(", "amount", "int64", ",", "code", "string", ")", "*", "Money", "{", "return", "&", "Money", "{", "amount", ":", "&", "Amount", "{", "val", ":", "amount", "}", ",", "currency", ":", "newCurrency", "(", "code", ")", ".", "get", "(", ")", ",", "}", "\n", "}" ]
// New creates and returns new instance of Money.
[ "New", "creates", "and", "returns", "new", "instance", "of", "Money", "." ]
ebbcb76cd8ed0bd579b837982e21e9ffeab92d95
https://github.com/Rhymond/go-money/blob/ebbcb76cd8ed0bd579b837982e21e9ffeab92d95/money.go#L20-L25
9,009
Rhymond/go-money
money.go
SameCurrency
func (m *Money) SameCurrency(om *Money) bool { return m.currency.equals(om.currency) }
go
func (m *Money) SameCurrency(om *Money) bool { return m.currency.equals(om.currency) }
[ "func", "(", "m", "*", "Money", ")", "SameCurrency", "(", "om", "*", "Money", ")", "bool", "{", "return", "m", ".", "currency", ".", "equals", "(", "om", ".", "currency", ")", "\n", "}" ]
// SameCurrency check if given Money is equals by currency.
[ "SameCurrency", "check", "if", "given", "Money", "is", "equals", "by", "currency", "." ]
ebbcb76cd8ed0bd579b837982e21e9ffeab92d95
https://github.com/Rhymond/go-money/blob/ebbcb76cd8ed0bd579b837982e21e9ffeab92d95/money.go#L38-L40
9,010
Rhymond/go-money
money.go
Equals
func (m *Money) Equals(om *Money) (bool, error) { if err := m.assertSameCurrency(om); err != nil { return false, err } return m.compare(om) == 0, nil }
go
func (m *Money) Equals(om *Money) (bool, error) { if err := m.assertSameCurrency(om); err != nil { return false, err } return m.compare(om) == 0, nil }
[ "func", "(", "m", "*", "Money", ")", "Equals", "(", "om", "*", "Money", ")", "(", "bool", ",", "error", ")", "{", "if", "err", ":=", "m", ".", "assertSameCurrency", "(", "om", ")", ";", "err", "!=", "nil", "{", "return", "false", ",", "err", "\n", "}", "\n\n", "return", "m", ".", "compare", "(", "om", ")", "==", "0", ",", "nil", "\n", "}" ]
// Equals checks equality between two Money types.
[ "Equals", "checks", "equality", "between", "two", "Money", "types", "." ]
ebbcb76cd8ed0bd579b837982e21e9ffeab92d95
https://github.com/Rhymond/go-money/blob/ebbcb76cd8ed0bd579b837982e21e9ffeab92d95/money.go#L62-L68
9,011
Rhymond/go-money
money.go
Absolute
func (m *Money) Absolute() *Money { return &Money{amount: mutate.calc.absolute(m.amount), currency: m.currency} }
go
func (m *Money) Absolute() *Money { return &Money{amount: mutate.calc.absolute(m.amount), currency: m.currency} }
[ "func", "(", "m", "*", "Money", ")", "Absolute", "(", ")", "*", "Money", "{", "return", "&", "Money", "{", "amount", ":", "mutate", ".", "calc", ".", "absolute", "(", "m", ".", "amount", ")", ",", "currency", ":", "m", ".", "currency", "}", "\n", "}" ]
// Absolute returns new Money struct from given Money using absolute monetary value.
[ "Absolute", "returns", "new", "Money", "struct", "from", "given", "Money", "using", "absolute", "monetary", "value", "." ]
ebbcb76cd8ed0bd579b837982e21e9ffeab92d95
https://github.com/Rhymond/go-money/blob/ebbcb76cd8ed0bd579b837982e21e9ffeab92d95/money.go#L122-L124
9,012
Rhymond/go-money
money.go
Negative
func (m *Money) Negative() *Money { return &Money{amount: mutate.calc.negative(m.amount), currency: m.currency} }
go
func (m *Money) Negative() *Money { return &Money{amount: mutate.calc.negative(m.amount), currency: m.currency} }
[ "func", "(", "m", "*", "Money", ")", "Negative", "(", ")", "*", "Money", "{", "return", "&", "Money", "{", "amount", ":", "mutate", ".", "calc", ".", "negative", "(", "m", ".", "amount", ")", ",", "currency", ":", "m", ".", "currency", "}", "\n", "}" ]
// Negative returns new Money struct from given Money using negative monetary value.
[ "Negative", "returns", "new", "Money", "struct", "from", "given", "Money", "using", "negative", "monetary", "value", "." ]
ebbcb76cd8ed0bd579b837982e21e9ffeab92d95
https://github.com/Rhymond/go-money/blob/ebbcb76cd8ed0bd579b837982e21e9ffeab92d95/money.go#L127-L129
9,013
Rhymond/go-money
money.go
Add
func (m *Money) Add(om *Money) (*Money, error) { if err := m.assertSameCurrency(om); err != nil { return nil, err } return &Money{amount: mutate.calc.add(m.amount, om.amount), currency: m.currency}, nil }
go
func (m *Money) Add(om *Money) (*Money, error) { if err := m.assertSameCurrency(om); err != nil { return nil, err } return &Money{amount: mutate.calc.add(m.amount, om.amount), currency: m.currency}, nil }
[ "func", "(", "m", "*", "Money", ")", "Add", "(", "om", "*", "Money", ")", "(", "*", "Money", ",", "error", ")", "{", "if", "err", ":=", "m", ".", "assertSameCurrency", "(", "om", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "&", "Money", "{", "amount", ":", "mutate", ".", "calc", ".", "add", "(", "m", ".", "amount", ",", "om", ".", "amount", ")", ",", "currency", ":", "m", ".", "currency", "}", ",", "nil", "\n", "}" ]
// Add returns new Money struct with value representing sum of Self and Other Money.
[ "Add", "returns", "new", "Money", "struct", "with", "value", "representing", "sum", "of", "Self", "and", "Other", "Money", "." ]
ebbcb76cd8ed0bd579b837982e21e9ffeab92d95
https://github.com/Rhymond/go-money/blob/ebbcb76cd8ed0bd579b837982e21e9ffeab92d95/money.go#L132-L138
9,014
Rhymond/go-money
money.go
Subtract
func (m *Money) Subtract(om *Money) (*Money, error) { if err := m.assertSameCurrency(om); err != nil { return nil, err } return &Money{amount: mutate.calc.subtract(m.amount, om.amount), currency: m.currency}, nil }
go
func (m *Money) Subtract(om *Money) (*Money, error) { if err := m.assertSameCurrency(om); err != nil { return nil, err } return &Money{amount: mutate.calc.subtract(m.amount, om.amount), currency: m.currency}, nil }
[ "func", "(", "m", "*", "Money", ")", "Subtract", "(", "om", "*", "Money", ")", "(", "*", "Money", ",", "error", ")", "{", "if", "err", ":=", "m", ".", "assertSameCurrency", "(", "om", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "&", "Money", "{", "amount", ":", "mutate", ".", "calc", ".", "subtract", "(", "m", ".", "amount", ",", "om", ".", "amount", ")", ",", "currency", ":", "m", ".", "currency", "}", ",", "nil", "\n", "}" ]
// Subtract returns new Money struct with value representing difference of Self and Other Money.
[ "Subtract", "returns", "new", "Money", "struct", "with", "value", "representing", "difference", "of", "Self", "and", "Other", "Money", "." ]
ebbcb76cd8ed0bd579b837982e21e9ffeab92d95
https://github.com/Rhymond/go-money/blob/ebbcb76cd8ed0bd579b837982e21e9ffeab92d95/money.go#L141-L147
9,015
Rhymond/go-money
money.go
Multiply
func (m *Money) Multiply(mul int64) *Money { return &Money{amount: mutate.calc.multiply(m.amount, mul), currency: m.currency} }
go
func (m *Money) Multiply(mul int64) *Money { return &Money{amount: mutate.calc.multiply(m.amount, mul), currency: m.currency} }
[ "func", "(", "m", "*", "Money", ")", "Multiply", "(", "mul", "int64", ")", "*", "Money", "{", "return", "&", "Money", "{", "amount", ":", "mutate", ".", "calc", ".", "multiply", "(", "m", ".", "amount", ",", "mul", ")", ",", "currency", ":", "m", ".", "currency", "}", "\n", "}" ]
// Multiply returns new Money struct with value representing Self multiplied value by multiplier.
[ "Multiply", "returns", "new", "Money", "struct", "with", "value", "representing", "Self", "multiplied", "value", "by", "multiplier", "." ]
ebbcb76cd8ed0bd579b837982e21e9ffeab92d95
https://github.com/Rhymond/go-money/blob/ebbcb76cd8ed0bd579b837982e21e9ffeab92d95/money.go#L150-L152
9,016
Rhymond/go-money
money.go
Divide
func (m *Money) Divide(div int64) *Money { return &Money{amount: mutate.calc.divide(m.amount, div), currency: m.currency} }
go
func (m *Money) Divide(div int64) *Money { return &Money{amount: mutate.calc.divide(m.amount, div), currency: m.currency} }
[ "func", "(", "m", "*", "Money", ")", "Divide", "(", "div", "int64", ")", "*", "Money", "{", "return", "&", "Money", "{", "amount", ":", "mutate", ".", "calc", ".", "divide", "(", "m", ".", "amount", ",", "div", ")", ",", "currency", ":", "m", ".", "currency", "}", "\n", "}" ]
// Divide returns new Money struct with value representing Self division value by given divider.
[ "Divide", "returns", "new", "Money", "struct", "with", "value", "representing", "Self", "division", "value", "by", "given", "divider", "." ]
ebbcb76cd8ed0bd579b837982e21e9ffeab92d95
https://github.com/Rhymond/go-money/blob/ebbcb76cd8ed0bd579b837982e21e9ffeab92d95/money.go#L155-L157
9,017
Rhymond/go-money
money.go
Round
func (m *Money) Round() *Money { return &Money{amount: mutate.calc.round(m.amount, m.currency.Fraction), currency: m.currency} }
go
func (m *Money) Round() *Money { return &Money{amount: mutate.calc.round(m.amount, m.currency.Fraction), currency: m.currency} }
[ "func", "(", "m", "*", "Money", ")", "Round", "(", ")", "*", "Money", "{", "return", "&", "Money", "{", "amount", ":", "mutate", ".", "calc", ".", "round", "(", "m", ".", "amount", ",", "m", ".", "currency", ".", "Fraction", ")", ",", "currency", ":", "m", ".", "currency", "}", "\n", "}" ]
// Round returns new Money struct with value rounded to nearest zero.
[ "Round", "returns", "new", "Money", "struct", "with", "value", "rounded", "to", "nearest", "zero", "." ]
ebbcb76cd8ed0bd579b837982e21e9ffeab92d95
https://github.com/Rhymond/go-money/blob/ebbcb76cd8ed0bd579b837982e21e9ffeab92d95/money.go#L160-L162
9,018
Rhymond/go-money
money.go
Split
func (m *Money) Split(n int) ([]*Money, error) { if n <= 0 { return nil, errors.New("split must be higher than zero") } a := mutate.calc.divide(m.amount, int64(n)) ms := make([]*Money, n) for i := 0; i < n; i++ { ms[i] = &Money{amount: a, currency: m.currency} } l := mutate.calc.modulus(m.amount, int64(n)).val // Add leftovers to the first parties. for p := 0; l != 0; p++ { ms[p].amount = mutate.calc.add(ms[p].amount, &Amount{1}) l-- } return ms, nil }
go
func (m *Money) Split(n int) ([]*Money, error) { if n <= 0 { return nil, errors.New("split must be higher than zero") } a := mutate.calc.divide(m.amount, int64(n)) ms := make([]*Money, n) for i := 0; i < n; i++ { ms[i] = &Money{amount: a, currency: m.currency} } l := mutate.calc.modulus(m.amount, int64(n)).val // Add leftovers to the first parties. for p := 0; l != 0; p++ { ms[p].amount = mutate.calc.add(ms[p].amount, &Amount{1}) l-- } return ms, nil }
[ "func", "(", "m", "*", "Money", ")", "Split", "(", "n", "int", ")", "(", "[", "]", "*", "Money", ",", "error", ")", "{", "if", "n", "<=", "0", "{", "return", "nil", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "a", ":=", "mutate", ".", "calc", ".", "divide", "(", "m", ".", "amount", ",", "int64", "(", "n", ")", ")", "\n", "ms", ":=", "make", "(", "[", "]", "*", "Money", ",", "n", ")", "\n\n", "for", "i", ":=", "0", ";", "i", "<", "n", ";", "i", "++", "{", "ms", "[", "i", "]", "=", "&", "Money", "{", "amount", ":", "a", ",", "currency", ":", "m", ".", "currency", "}", "\n", "}", "\n\n", "l", ":=", "mutate", ".", "calc", ".", "modulus", "(", "m", ".", "amount", ",", "int64", "(", "n", ")", ")", ".", "val", "\n\n", "// Add leftovers to the first parties.", "for", "p", ":=", "0", ";", "l", "!=", "0", ";", "p", "++", "{", "ms", "[", "p", "]", ".", "amount", "=", "mutate", ".", "calc", ".", "add", "(", "ms", "[", "p", "]", ".", "amount", ",", "&", "Amount", "{", "1", "}", ")", "\n", "l", "--", "\n", "}", "\n\n", "return", "ms", ",", "nil", "\n", "}" ]
// Split returns slice of Money structs with split Self value in given number. // After division leftover pennies will be distributed round-robin amongst the parties. // This means that parties listed first will likely receive more pennies than ones that are listed later.
[ "Split", "returns", "slice", "of", "Money", "structs", "with", "split", "Self", "value", "in", "given", "number", ".", "After", "division", "leftover", "pennies", "will", "be", "distributed", "round", "-", "robin", "amongst", "the", "parties", ".", "This", "means", "that", "parties", "listed", "first", "will", "likely", "receive", "more", "pennies", "than", "ones", "that", "are", "listed", "later", "." ]
ebbcb76cd8ed0bd579b837982e21e9ffeab92d95
https://github.com/Rhymond/go-money/blob/ebbcb76cd8ed0bd579b837982e21e9ffeab92d95/money.go#L167-L188
9,019
Rhymond/go-money
money.go
Allocate
func (m *Money) Allocate(rs ...int) ([]*Money, error) { if len(rs) == 0 { return nil, errors.New("no ratios specified") } // Calculate sum of ratios. var sum int for _, r := range rs { sum += r } var total int64 var ms []*Money for _, r := range rs { party := &Money{ amount: mutate.calc.allocate(m.amount, r, sum), currency: m.currency, } ms = append(ms, party) total += party.amount.val } // Calculate leftover value and divide to first parties. lo := m.amount.val - total sub := int64(1) if lo < 0 { sub = -sub } for p := 0; lo != 0; p++ { ms[p].amount = mutate.calc.add(ms[p].amount, &Amount{sub}) lo -= sub } return ms, nil }
go
func (m *Money) Allocate(rs ...int) ([]*Money, error) { if len(rs) == 0 { return nil, errors.New("no ratios specified") } // Calculate sum of ratios. var sum int for _, r := range rs { sum += r } var total int64 var ms []*Money for _, r := range rs { party := &Money{ amount: mutate.calc.allocate(m.amount, r, sum), currency: m.currency, } ms = append(ms, party) total += party.amount.val } // Calculate leftover value and divide to first parties. lo := m.amount.val - total sub := int64(1) if lo < 0 { sub = -sub } for p := 0; lo != 0; p++ { ms[p].amount = mutate.calc.add(ms[p].amount, &Amount{sub}) lo -= sub } return ms, nil }
[ "func", "(", "m", "*", "Money", ")", "Allocate", "(", "rs", "...", "int", ")", "(", "[", "]", "*", "Money", ",", "error", ")", "{", "if", "len", "(", "rs", ")", "==", "0", "{", "return", "nil", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "// Calculate sum of ratios.", "var", "sum", "int", "\n", "for", "_", ",", "r", ":=", "range", "rs", "{", "sum", "+=", "r", "\n", "}", "\n\n", "var", "total", "int64", "\n", "var", "ms", "[", "]", "*", "Money", "\n", "for", "_", ",", "r", ":=", "range", "rs", "{", "party", ":=", "&", "Money", "{", "amount", ":", "mutate", ".", "calc", ".", "allocate", "(", "m", ".", "amount", ",", "r", ",", "sum", ")", ",", "currency", ":", "m", ".", "currency", ",", "}", "\n\n", "ms", "=", "append", "(", "ms", ",", "party", ")", "\n", "total", "+=", "party", ".", "amount", ".", "val", "\n", "}", "\n\n", "// Calculate leftover value and divide to first parties.", "lo", ":=", "m", ".", "amount", ".", "val", "-", "total", "\n", "sub", ":=", "int64", "(", "1", ")", "\n", "if", "lo", "<", "0", "{", "sub", "=", "-", "sub", "\n", "}", "\n\n", "for", "p", ":=", "0", ";", "lo", "!=", "0", ";", "p", "++", "{", "ms", "[", "p", "]", ".", "amount", "=", "mutate", ".", "calc", ".", "add", "(", "ms", "[", "p", "]", ".", "amount", ",", "&", "Amount", "{", "sub", "}", ")", "\n", "lo", "-=", "sub", "\n", "}", "\n\n", "return", "ms", ",", "nil", "\n", "}" ]
// Allocate returns slice of Money structs with split Self value in given ratios. // It lets split money by given ratios without losing pennies and as Split operations distributes // leftover pennies amongst the parties with round-robin principle.
[ "Allocate", "returns", "slice", "of", "Money", "structs", "with", "split", "Self", "value", "in", "given", "ratios", ".", "It", "lets", "split", "money", "by", "given", "ratios", "without", "losing", "pennies", "and", "as", "Split", "operations", "distributes", "leftover", "pennies", "amongst", "the", "parties", "with", "round", "-", "robin", "principle", "." ]
ebbcb76cd8ed0bd579b837982e21e9ffeab92d95
https://github.com/Rhymond/go-money/blob/ebbcb76cd8ed0bd579b837982e21e9ffeab92d95/money.go#L193-L229
9,020
Rhymond/go-money
money.go
Display
func (m *Money) Display() string { c := m.currency.get() return c.Formatter().Format(m.amount.val) }
go
func (m *Money) Display() string { c := m.currency.get() return c.Formatter().Format(m.amount.val) }
[ "func", "(", "m", "*", "Money", ")", "Display", "(", ")", "string", "{", "c", ":=", "m", ".", "currency", ".", "get", "(", ")", "\n", "return", "c", ".", "Formatter", "(", ")", ".", "Format", "(", "m", ".", "amount", ".", "val", ")", "\n", "}" ]
// Display lets represent Money struct as string in given Currency value.
[ "Display", "lets", "represent", "Money", "struct", "as", "string", "in", "given", "Currency", "value", "." ]
ebbcb76cd8ed0bd579b837982e21e9ffeab92d95
https://github.com/Rhymond/go-money/blob/ebbcb76cd8ed0bd579b837982e21e9ffeab92d95/money.go#L232-L235
9,021
Rhymond/go-money
currency.go
AddCurrency
func AddCurrency(Code, Grapheme, Template, Decimal, Thousand string, Fraction int) *Currency { currencies[Code] = &Currency{ Code: Code, Grapheme: Grapheme, Template: Template, Decimal: Decimal, Thousand: Thousand, Fraction: Fraction, } return currencies[Code] }
go
func AddCurrency(Code, Grapheme, Template, Decimal, Thousand string, Fraction int) *Currency { currencies[Code] = &Currency{ Code: Code, Grapheme: Grapheme, Template: Template, Decimal: Decimal, Thousand: Thousand, Fraction: Fraction, } return currencies[Code] }
[ "func", "AddCurrency", "(", "Code", ",", "Grapheme", ",", "Template", ",", "Decimal", ",", "Thousand", "string", ",", "Fraction", "int", ")", "*", "Currency", "{", "currencies", "[", "Code", "]", "=", "&", "Currency", "{", "Code", ":", "Code", ",", "Grapheme", ":", "Grapheme", ",", "Template", ":", "Template", ",", "Decimal", ":", "Decimal", ",", "Thousand", ":", "Thousand", ",", "Fraction", ":", "Fraction", ",", "}", "\n\n", "return", "currencies", "[", "Code", "]", "\n", "}" ]
// AddCurrency lets you insert or update currency in currencies list.
[ "AddCurrency", "lets", "you", "insert", "or", "update", "currency", "in", "currencies", "list", "." ]
ebbcb76cd8ed0bd579b837982e21e9ffeab92d95
https://github.com/Rhymond/go-money/blob/ebbcb76cd8ed0bd579b837982e21e9ffeab92d95/currency.go#L152-L163
9,022
Rhymond/go-money
currency.go
Formatter
func (c *Currency) Formatter() *Formatter { return &Formatter{ Fraction: c.Fraction, Decimal: c.Decimal, Thousand: c.Thousand, Grapheme: c.Grapheme, Template: c.Template, } }
go
func (c *Currency) Formatter() *Formatter { return &Formatter{ Fraction: c.Fraction, Decimal: c.Decimal, Thousand: c.Thousand, Grapheme: c.Grapheme, Template: c.Template, } }
[ "func", "(", "c", "*", "Currency", ")", "Formatter", "(", ")", "*", "Formatter", "{", "return", "&", "Formatter", "{", "Fraction", ":", "c", ".", "Fraction", ",", "Decimal", ":", "c", ".", "Decimal", ",", "Thousand", ":", "c", ".", "Thousand", ",", "Grapheme", ":", "c", ".", "Grapheme", ",", "Template", ":", "c", ".", "Template", ",", "}", "\n", "}" ]
// Formatter returns currency formatter representing // used currency structure.
[ "Formatter", "returns", "currency", "formatter", "representing", "used", "currency", "structure", "." ]
ebbcb76cd8ed0bd579b837982e21e9ffeab92d95
https://github.com/Rhymond/go-money/blob/ebbcb76cd8ed0bd579b837982e21e9ffeab92d95/currency.go#L176-L184
9,023
Rhymond/go-money
currency.go
getDefault
func (c *Currency) getDefault() *Currency { return &Currency{Decimal: ".", Thousand: ",", Code: c.Code, Fraction: 2, Grapheme: c.Code, Template: "1$"} }
go
func (c *Currency) getDefault() *Currency { return &Currency{Decimal: ".", Thousand: ",", Code: c.Code, Fraction: 2, Grapheme: c.Code, Template: "1$"} }
[ "func", "(", "c", "*", "Currency", ")", "getDefault", "(", ")", "*", "Currency", "{", "return", "&", "Currency", "{", "Decimal", ":", "\"", "\"", ",", "Thousand", ":", "\"", "\"", ",", "Code", ":", "c", ".", "Code", ",", "Fraction", ":", "2", ",", "Grapheme", ":", "c", ".", "Code", ",", "Template", ":", "\"", "\"", "}", "\n", "}" ]
// getDefault represent default currency if currency is not found in currencies list. // Grapheme and Code fields will be changed by currency code.
[ "getDefault", "represent", "default", "currency", "if", "currency", "is", "not", "found", "in", "currencies", "list", ".", "Grapheme", "and", "Code", "fields", "will", "be", "changed", "by", "currency", "code", "." ]
ebbcb76cd8ed0bd579b837982e21e9ffeab92d95
https://github.com/Rhymond/go-money/blob/ebbcb76cd8ed0bd579b837982e21e9ffeab92d95/currency.go#L188-L190
9,024
Rhymond/go-money
currency.go
get
func (c *Currency) get() *Currency { if curr, ok := currencies[c.Code]; ok { return curr } return c.getDefault() }
go
func (c *Currency) get() *Currency { if curr, ok := currencies[c.Code]; ok { return curr } return c.getDefault() }
[ "func", "(", "c", "*", "Currency", ")", "get", "(", ")", "*", "Currency", "{", "if", "curr", ",", "ok", ":=", "currencies", "[", "c", ".", "Code", "]", ";", "ok", "{", "return", "curr", "\n", "}", "\n\n", "return", "c", ".", "getDefault", "(", ")", "\n", "}" ]
// get extended currency using currencies list.
[ "get", "extended", "currency", "using", "currencies", "list", "." ]
ebbcb76cd8ed0bd579b837982e21e9ffeab92d95
https://github.com/Rhymond/go-money/blob/ebbcb76cd8ed0bd579b837982e21e9ffeab92d95/currency.go#L193-L199
9,025
Rhymond/go-money
formatter.go
NewFormatter
func NewFormatter(fraction int, decimal, thousand, grapheme, template string) *Formatter { return &Formatter{ Fraction: fraction, Decimal: decimal, Thousand: thousand, Grapheme: grapheme, Template: template, } }
go
func NewFormatter(fraction int, decimal, thousand, grapheme, template string) *Formatter { return &Formatter{ Fraction: fraction, Decimal: decimal, Thousand: thousand, Grapheme: grapheme, Template: template, } }
[ "func", "NewFormatter", "(", "fraction", "int", ",", "decimal", ",", "thousand", ",", "grapheme", ",", "template", "string", ")", "*", "Formatter", "{", "return", "&", "Formatter", "{", "Fraction", ":", "fraction", ",", "Decimal", ":", "decimal", ",", "Thousand", ":", "thousand", ",", "Grapheme", ":", "grapheme", ",", "Template", ":", "template", ",", "}", "\n", "}" ]
// NewFormatter creates new Formatter instance.
[ "NewFormatter", "creates", "new", "Formatter", "instance", "." ]
ebbcb76cd8ed0bd579b837982e21e9ffeab92d95
https://github.com/Rhymond/go-money/blob/ebbcb76cd8ed0bd579b837982e21e9ffeab92d95/formatter.go#L18-L26
9,026
Rhymond/go-money
formatter.go
Format
func (f *Formatter) Format(amount int64) string { // Work with absolute amount value sa := strconv.FormatInt(f.abs(amount), 10) if len(sa) <= f.Fraction { sa = strings.Repeat("0", f.Fraction-len(sa)+1) + sa } if f.Thousand != "" { for i := len(sa) - f.Fraction - 3; i > 0; i -= 3 { sa = sa[:i] + f.Thousand + sa[i:] } } if f.Fraction > 0 { sa = sa[:len(sa)-f.Fraction] + f.Decimal + sa[len(sa)-f.Fraction:] } sa = strings.Replace(f.Template, "1", sa, 1) sa = strings.Replace(sa, "$", f.Grapheme, 1) // Add minus sign for negative amount. if amount < 0 { sa = "-" + sa } return sa }
go
func (f *Formatter) Format(amount int64) string { // Work with absolute amount value sa := strconv.FormatInt(f.abs(amount), 10) if len(sa) <= f.Fraction { sa = strings.Repeat("0", f.Fraction-len(sa)+1) + sa } if f.Thousand != "" { for i := len(sa) - f.Fraction - 3; i > 0; i -= 3 { sa = sa[:i] + f.Thousand + sa[i:] } } if f.Fraction > 0 { sa = sa[:len(sa)-f.Fraction] + f.Decimal + sa[len(sa)-f.Fraction:] } sa = strings.Replace(f.Template, "1", sa, 1) sa = strings.Replace(sa, "$", f.Grapheme, 1) // Add minus sign for negative amount. if amount < 0 { sa = "-" + sa } return sa }
[ "func", "(", "f", "*", "Formatter", ")", "Format", "(", "amount", "int64", ")", "string", "{", "// Work with absolute amount value", "sa", ":=", "strconv", ".", "FormatInt", "(", "f", ".", "abs", "(", "amount", ")", ",", "10", ")", "\n\n", "if", "len", "(", "sa", ")", "<=", "f", ".", "Fraction", "{", "sa", "=", "strings", ".", "Repeat", "(", "\"", "\"", ",", "f", ".", "Fraction", "-", "len", "(", "sa", ")", "+", "1", ")", "+", "sa", "\n", "}", "\n\n", "if", "f", ".", "Thousand", "!=", "\"", "\"", "{", "for", "i", ":=", "len", "(", "sa", ")", "-", "f", ".", "Fraction", "-", "3", ";", "i", ">", "0", ";", "i", "-=", "3", "{", "sa", "=", "sa", "[", ":", "i", "]", "+", "f", ".", "Thousand", "+", "sa", "[", "i", ":", "]", "\n", "}", "\n", "}", "\n\n", "if", "f", ".", "Fraction", ">", "0", "{", "sa", "=", "sa", "[", ":", "len", "(", "sa", ")", "-", "f", ".", "Fraction", "]", "+", "f", ".", "Decimal", "+", "sa", "[", "len", "(", "sa", ")", "-", "f", ".", "Fraction", ":", "]", "\n", "}", "\n", "sa", "=", "strings", ".", "Replace", "(", "f", ".", "Template", ",", "\"", "\"", ",", "sa", ",", "1", ")", "\n", "sa", "=", "strings", ".", "Replace", "(", "sa", ",", "\"", "\"", ",", "f", ".", "Grapheme", ",", "1", ")", "\n\n", "// Add minus sign for negative amount.", "if", "amount", "<", "0", "{", "sa", "=", "\"", "\"", "+", "sa", "\n", "}", "\n\n", "return", "sa", "\n", "}" ]
// Format returns string of formatted integer using given currency template.
[ "Format", "returns", "string", "of", "formatted", "integer", "using", "given", "currency", "template", "." ]
ebbcb76cd8ed0bd579b837982e21e9ffeab92d95
https://github.com/Rhymond/go-money/blob/ebbcb76cd8ed0bd579b837982e21e9ffeab92d95/formatter.go#L29-L55
9,027
willf/bloom
bloom.go
New
func New(m uint, k uint) *BloomFilter { return &BloomFilter{max(1, m), max(1, k), bitset.New(m)} }
go
func New(m uint, k uint) *BloomFilter { return &BloomFilter{max(1, m), max(1, k), bitset.New(m)} }
[ "func", "New", "(", "m", "uint", ",", "k", "uint", ")", "*", "BloomFilter", "{", "return", "&", "BloomFilter", "{", "max", "(", "1", ",", "m", ")", ",", "max", "(", "1", ",", "k", ")", ",", "bitset", ".", "New", "(", "m", ")", "}", "\n", "}" ]
// New creates a new Bloom filter with _m_ bits and _k_ hashing functions // We force _m_ and _k_ to be at least one to avoid panics.
[ "New", "creates", "a", "new", "Bloom", "filter", "with", "_m_", "bits", "and", "_k_", "hashing", "functions", "We", "force", "_m_", "and", "_k_", "to", "be", "at", "least", "one", "to", "avoid", "panics", "." ]
25ba46ef8744ddeba999dcd048dbb8b0fa87edb3
https://github.com/willf/bloom/blob/25ba46ef8744ddeba999dcd048dbb8b0fa87edb3/bloom.go#L81-L83
9,028
willf/bloom
bloom.go
baseHashes
func baseHashes(data []byte) [4]uint64 { a1 := []byte{1} // to grab another bit of data hasher := murmur3.New128() hasher.Write(data) // #nosec v1, v2 := hasher.Sum128() hasher.Write(a1) // #nosec v3, v4 := hasher.Sum128() return [4]uint64{ v1, v2, v3, v4, } }
go
func baseHashes(data []byte) [4]uint64 { a1 := []byte{1} // to grab another bit of data hasher := murmur3.New128() hasher.Write(data) // #nosec v1, v2 := hasher.Sum128() hasher.Write(a1) // #nosec v3, v4 := hasher.Sum128() return [4]uint64{ v1, v2, v3, v4, } }
[ "func", "baseHashes", "(", "data", "[", "]", "byte", ")", "[", "4", "]", "uint64", "{", "a1", ":=", "[", "]", "byte", "{", "1", "}", "// to grab another bit of data", "\n", "hasher", ":=", "murmur3", ".", "New128", "(", ")", "\n", "hasher", ".", "Write", "(", "data", ")", "// #nosec", "\n", "v1", ",", "v2", ":=", "hasher", ".", "Sum128", "(", ")", "\n", "hasher", ".", "Write", "(", "a1", ")", "// #nosec", "\n", "v3", ",", "v4", ":=", "hasher", ".", "Sum128", "(", ")", "\n", "return", "[", "4", "]", "uint64", "{", "v1", ",", "v2", ",", "v3", ",", "v4", ",", "}", "\n", "}" ]
// baseHashes returns the four hash values of data that are used to create k // hashes
[ "baseHashes", "returns", "the", "four", "hash", "values", "of", "data", "that", "are", "used", "to", "create", "k", "hashes" ]
25ba46ef8744ddeba999dcd048dbb8b0fa87edb3
https://github.com/willf/bloom/blob/25ba46ef8744ddeba999dcd048dbb8b0fa87edb3/bloom.go#L94-L104
9,029
willf/bloom
bloom.go
NewWithEstimates
func NewWithEstimates(n uint, fp float64) *BloomFilter { m, k := EstimateParameters(n, fp) return New(m, k) }
go
func NewWithEstimates(n uint, fp float64) *BloomFilter { m, k := EstimateParameters(n, fp) return New(m, k) }
[ "func", "NewWithEstimates", "(", "n", "uint", ",", "fp", "float64", ")", "*", "BloomFilter", "{", "m", ",", "k", ":=", "EstimateParameters", "(", "n", ",", "fp", ")", "\n", "return", "New", "(", "m", ",", "k", ")", "\n", "}" ]
// NewWithEstimates creates a new Bloom filter for about n items with fp // false positive rate
[ "NewWithEstimates", "creates", "a", "new", "Bloom", "filter", "for", "about", "n", "items", "with", "fp", "false", "positive", "rate" ]
25ba46ef8744ddeba999dcd048dbb8b0fa87edb3
https://github.com/willf/bloom/blob/25ba46ef8744ddeba999dcd048dbb8b0fa87edb3/bloom.go#L128-L131
9,030
willf/bloom
bloom.go
Merge
func (f *BloomFilter) Merge(g *BloomFilter) error { // Make sure the m's and k's are the same, otherwise merging has no real use. if f.m != g.m { return fmt.Errorf("m's don't match: %d != %d", f.m, g.m) } if f.k != g.k { return fmt.Errorf("k's don't match: %d != %d", f.m, g.m) } f.b.InPlaceUnion(g.b) return nil }
go
func (f *BloomFilter) Merge(g *BloomFilter) error { // Make sure the m's and k's are the same, otherwise merging has no real use. if f.m != g.m { return fmt.Errorf("m's don't match: %d != %d", f.m, g.m) } if f.k != g.k { return fmt.Errorf("k's don't match: %d != %d", f.m, g.m) } f.b.InPlaceUnion(g.b) return nil }
[ "func", "(", "f", "*", "BloomFilter", ")", "Merge", "(", "g", "*", "BloomFilter", ")", "error", "{", "// Make sure the m's and k's are the same, otherwise merging has no real use.", "if", "f", ".", "m", "!=", "g", ".", "m", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "f", ".", "m", ",", "g", ".", "m", ")", "\n", "}", "\n\n", "if", "f", ".", "k", "!=", "g", ".", "k", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "f", ".", "m", ",", "g", ".", "m", ")", "\n", "}", "\n\n", "f", ".", "b", ".", "InPlaceUnion", "(", "g", ".", "b", ")", "\n", "return", "nil", "\n", "}" ]
// Merge the data from two Bloom Filters.
[ "Merge", "the", "data", "from", "two", "Bloom", "Filters", "." ]
25ba46ef8744ddeba999dcd048dbb8b0fa87edb3
https://github.com/willf/bloom/blob/25ba46ef8744ddeba999dcd048dbb8b0fa87edb3/bloom.go#L153-L165
9,031
willf/bloom
bloom.go
Copy
func (f *BloomFilter) Copy() *BloomFilter { fc := New(f.m, f.k) fc.Merge(f) // #nosec return fc }
go
func (f *BloomFilter) Copy() *BloomFilter { fc := New(f.m, f.k) fc.Merge(f) // #nosec return fc }
[ "func", "(", "f", "*", "BloomFilter", ")", "Copy", "(", ")", "*", "BloomFilter", "{", "fc", ":=", "New", "(", "f", ".", "m", ",", "f", ".", "k", ")", "\n", "fc", ".", "Merge", "(", "f", ")", "// #nosec", "\n", "return", "fc", "\n", "}" ]
// Copy creates a copy of a Bloom filter.
[ "Copy", "creates", "a", "copy", "of", "a", "Bloom", "filter", "." ]
25ba46ef8744ddeba999dcd048dbb8b0fa87edb3
https://github.com/willf/bloom/blob/25ba46ef8744ddeba999dcd048dbb8b0fa87edb3/bloom.go#L168-L172
9,032
willf/bloom
bloom.go
EstimateFalsePositiveRate
func (f *BloomFilter) EstimateFalsePositiveRate(n uint) (fpRate float64) { rounds := uint32(100000) f.ClearAll() n1 := make([]byte, 4) for i := uint32(0); i < uint32(n); i++ { binary.BigEndian.PutUint32(n1, i) f.Add(n1) } fp := 0 // test for number of rounds for i := uint32(0); i < rounds; i++ { binary.BigEndian.PutUint32(n1, i+uint32(n)+1) if f.Test(n1) { //fmt.Printf("%v failed.\n", i+uint32(n)+1) fp++ } } fpRate = float64(fp) / (float64(rounds)) f.ClearAll() return }
go
func (f *BloomFilter) EstimateFalsePositiveRate(n uint) (fpRate float64) { rounds := uint32(100000) f.ClearAll() n1 := make([]byte, 4) for i := uint32(0); i < uint32(n); i++ { binary.BigEndian.PutUint32(n1, i) f.Add(n1) } fp := 0 // test for number of rounds for i := uint32(0); i < rounds; i++ { binary.BigEndian.PutUint32(n1, i+uint32(n)+1) if f.Test(n1) { //fmt.Printf("%v failed.\n", i+uint32(n)+1) fp++ } } fpRate = float64(fp) / (float64(rounds)) f.ClearAll() return }
[ "func", "(", "f", "*", "BloomFilter", ")", "EstimateFalsePositiveRate", "(", "n", "uint", ")", "(", "fpRate", "float64", ")", "{", "rounds", ":=", "uint32", "(", "100000", ")", "\n", "f", ".", "ClearAll", "(", ")", "\n", "n1", ":=", "make", "(", "[", "]", "byte", ",", "4", ")", "\n", "for", "i", ":=", "uint32", "(", "0", ")", ";", "i", "<", "uint32", "(", "n", ")", ";", "i", "++", "{", "binary", ".", "BigEndian", ".", "PutUint32", "(", "n1", ",", "i", ")", "\n", "f", ".", "Add", "(", "n1", ")", "\n", "}", "\n", "fp", ":=", "0", "\n", "// test for number of rounds", "for", "i", ":=", "uint32", "(", "0", ")", ";", "i", "<", "rounds", ";", "i", "++", "{", "binary", ".", "BigEndian", ".", "PutUint32", "(", "n1", ",", "i", "+", "uint32", "(", "n", ")", "+", "1", ")", "\n", "if", "f", ".", "Test", "(", "n1", ")", "{", "//fmt.Printf(\"%v failed.\\n\", i+uint32(n)+1)", "fp", "++", "\n", "}", "\n", "}", "\n", "fpRate", "=", "float64", "(", "fp", ")", "/", "(", "float64", "(", "rounds", ")", ")", "\n", "f", ".", "ClearAll", "(", ")", "\n", "return", "\n", "}" ]
// EstimateFalsePositiveRate returns, for a BloomFilter with a estimate of m bits // and k hash functions, what the false positive rate will be // while storing n entries; runs 100,000 tests. This is an empirical // test using integers as keys. As a side-effect, it clears the BloomFilter.
[ "EstimateFalsePositiveRate", "returns", "for", "a", "BloomFilter", "with", "a", "estimate", "of", "m", "bits", "and", "k", "hash", "functions", "what", "the", "false", "positive", "rate", "will", "be", "while", "storing", "n", "entries", ";", "runs", "100", "000", "tests", ".", "This", "is", "an", "empirical", "test", "using", "integers", "as", "keys", ".", "As", "a", "side", "-", "effect", "it", "clears", "the", "BloomFilter", "." ]
25ba46ef8744ddeba999dcd048dbb8b0fa87edb3
https://github.com/willf/bloom/blob/25ba46ef8744ddeba999dcd048dbb8b0fa87edb3/bloom.go#L241-L261
9,033
willf/bloom
bloom.go
Equal
func (f *BloomFilter) Equal(g *BloomFilter) bool { return f.m == g.m && f.k == g.k && f.b.Equal(g.b) }
go
func (f *BloomFilter) Equal(g *BloomFilter) bool { return f.m == g.m && f.k == g.k && f.b.Equal(g.b) }
[ "func", "(", "f", "*", "BloomFilter", ")", "Equal", "(", "g", "*", "BloomFilter", ")", "bool", "{", "return", "f", ".", "m", "==", "g", ".", "m", "&&", "f", ".", "k", "==", "g", ".", "k", "&&", "f", ".", "b", ".", "Equal", "(", "g", ".", "b", ")", "\n", "}" ]
// Equal tests for the equality of two Bloom filters
[ "Equal", "tests", "for", "the", "equality", "of", "two", "Bloom", "filters" ]
25ba46ef8744ddeba999dcd048dbb8b0fa87edb3
https://github.com/willf/bloom/blob/25ba46ef8744ddeba999dcd048dbb8b0fa87edb3/bloom.go#L347-L349
9,034
willf/bloom
bloom.go
Locations
func Locations(data []byte, k uint) []uint64 { locs := make([]uint64, k) // calculate locations h := baseHashes(data) for i := uint(0); i < k; i++ { locs[i] = location(h, i) } return locs }
go
func Locations(data []byte, k uint) []uint64 { locs := make([]uint64, k) // calculate locations h := baseHashes(data) for i := uint(0); i < k; i++ { locs[i] = location(h, i) } return locs }
[ "func", "Locations", "(", "data", "[", "]", "byte", ",", "k", "uint", ")", "[", "]", "uint64", "{", "locs", ":=", "make", "(", "[", "]", "uint64", ",", "k", ")", "\n\n", "// calculate locations", "h", ":=", "baseHashes", "(", "data", ")", "\n", "for", "i", ":=", "uint", "(", "0", ")", ";", "i", "<", "k", ";", "i", "++", "{", "locs", "[", "i", "]", "=", "location", "(", "h", ",", "i", ")", "\n", "}", "\n\n", "return", "locs", "\n", "}" ]
// Locations returns a list of hash locations representing a data item.
[ "Locations", "returns", "a", "list", "of", "hash", "locations", "representing", "a", "data", "item", "." ]
25ba46ef8744ddeba999dcd048dbb8b0fa87edb3
https://github.com/willf/bloom/blob/25ba46ef8744ddeba999dcd048dbb8b0fa87edb3/bloom.go#L352-L362
9,035
qor/transition
transition.go
New
func New(value interface{}) *StateMachine { return &StateMachine{ states: map[string]*State{}, events: map[string]*Event{}, } }
go
func New(value interface{}) *StateMachine { return &StateMachine{ states: map[string]*State{}, events: map[string]*Event{}, } }
[ "func", "New", "(", "value", "interface", "{", "}", ")", "*", "StateMachine", "{", "return", "&", "StateMachine", "{", "states", ":", "map", "[", "string", "]", "*", "State", "{", "}", ",", "events", ":", "map", "[", "string", "]", "*", "Event", "{", "}", ",", "}", "\n", "}" ]
// New initialize a new StateMachine that hold states, events definitions
[ "New", "initialize", "a", "new", "StateMachine", "that", "hold", "states", "events", "definitions" ]
4015a3eee19c49a63b1d22beab1c0c084e72c53b
https://github.com/qor/transition/blob/4015a3eee19c49a63b1d22beab1c0c084e72c53b/transition.go#L36-L41
9,036
qor/transition
transition.go
Initial
func (sm *StateMachine) Initial(name string) *StateMachine { sm.initialState = name return sm }
go
func (sm *StateMachine) Initial(name string) *StateMachine { sm.initialState = name return sm }
[ "func", "(", "sm", "*", "StateMachine", ")", "Initial", "(", "name", "string", ")", "*", "StateMachine", "{", "sm", ".", "initialState", "=", "name", "\n", "return", "sm", "\n", "}" ]
// Initial define the initial state
[ "Initial", "define", "the", "initial", "state" ]
4015a3eee19c49a63b1d22beab1c0c084e72c53b
https://github.com/qor/transition/blob/4015a3eee19c49a63b1d22beab1c0c084e72c53b/transition.go#L51-L54
9,037
qor/transition
transition.go
State
func (sm *StateMachine) State(name string) *State { state := &State{Name: name} sm.states[name] = state return state }
go
func (sm *StateMachine) State(name string) *State { state := &State{Name: name} sm.states[name] = state return state }
[ "func", "(", "sm", "*", "StateMachine", ")", "State", "(", "name", "string", ")", "*", "State", "{", "state", ":=", "&", "State", "{", "Name", ":", "name", "}", "\n", "sm", ".", "states", "[", "name", "]", "=", "state", "\n", "return", "state", "\n", "}" ]
// State define a state
[ "State", "define", "a", "state" ]
4015a3eee19c49a63b1d22beab1c0c084e72c53b
https://github.com/qor/transition/blob/4015a3eee19c49a63b1d22beab1c0c084e72c53b/transition.go#L57-L61
9,038
qor/transition
transition.go
Event
func (sm *StateMachine) Event(name string) *Event { event := &Event{Name: name} sm.events[name] = event return event }
go
func (sm *StateMachine) Event(name string) *Event { event := &Event{Name: name} sm.events[name] = event return event }
[ "func", "(", "sm", "*", "StateMachine", ")", "Event", "(", "name", "string", ")", "*", "Event", "{", "event", ":=", "&", "Event", "{", "Name", ":", "name", "}", "\n", "sm", ".", "events", "[", "name", "]", "=", "event", "\n", "return", "event", "\n", "}" ]
// Event define an event
[ "Event", "define", "an", "event" ]
4015a3eee19c49a63b1d22beab1c0c084e72c53b
https://github.com/qor/transition/blob/4015a3eee19c49a63b1d22beab1c0c084e72c53b/transition.go#L64-L68
9,039
qor/transition
transition.go
Trigger
func (sm *StateMachine) Trigger(name string, value Stater, tx *gorm.DB, notes ...string) error { var ( newTx *gorm.DB stateWas = value.GetState() ) if tx != nil { newTx = tx.New() } if stateWas == "" { stateWas = sm.initialState value.SetState(sm.initialState) } if event := sm.events[name]; event != nil { var matchedTransitions []*EventTransition for _, transition := range event.transitions { var validFrom = len(transition.froms) == 0 if len(transition.froms) > 0 { for _, from := range transition.froms { if from == stateWas { validFrom = true } } } if validFrom { matchedTransitions = append(matchedTransitions, transition) } } if len(matchedTransitions) == 1 { transition := matchedTransitions[0] // State: exit if state, ok := sm.states[stateWas]; ok { for _, exit := range state.exits { if err := exit(value, newTx); err != nil { return err } } } // Transition: before for _, before := range transition.befores { if err := before(value, newTx); err != nil { return err } } value.SetState(transition.to) // State: enter if state, ok := sm.states[transition.to]; ok { for _, enter := range state.enters { if err := enter(value, newTx); err != nil { value.SetState(stateWas) return err } } } // Transition: after for _, after := range transition.afters { if err := after(value, newTx); err != nil { value.SetState(stateWas) return err } } if newTx != nil { scope := newTx.NewScope(value) log := StateChangeLog{ ReferTable: scope.TableName(), ReferID: GenerateReferenceKey(value, tx), From: stateWas, To: transition.to, Note: strings.Join(notes, ""), } return newTx.Save(&log).Error } return nil } } return fmt.Errorf("failed to perform event %s from state %s", name, stateWas) }
go
func (sm *StateMachine) Trigger(name string, value Stater, tx *gorm.DB, notes ...string) error { var ( newTx *gorm.DB stateWas = value.GetState() ) if tx != nil { newTx = tx.New() } if stateWas == "" { stateWas = sm.initialState value.SetState(sm.initialState) } if event := sm.events[name]; event != nil { var matchedTransitions []*EventTransition for _, transition := range event.transitions { var validFrom = len(transition.froms) == 0 if len(transition.froms) > 0 { for _, from := range transition.froms { if from == stateWas { validFrom = true } } } if validFrom { matchedTransitions = append(matchedTransitions, transition) } } if len(matchedTransitions) == 1 { transition := matchedTransitions[0] // State: exit if state, ok := sm.states[stateWas]; ok { for _, exit := range state.exits { if err := exit(value, newTx); err != nil { return err } } } // Transition: before for _, before := range transition.befores { if err := before(value, newTx); err != nil { return err } } value.SetState(transition.to) // State: enter if state, ok := sm.states[transition.to]; ok { for _, enter := range state.enters { if err := enter(value, newTx); err != nil { value.SetState(stateWas) return err } } } // Transition: after for _, after := range transition.afters { if err := after(value, newTx); err != nil { value.SetState(stateWas) return err } } if newTx != nil { scope := newTx.NewScope(value) log := StateChangeLog{ ReferTable: scope.TableName(), ReferID: GenerateReferenceKey(value, tx), From: stateWas, To: transition.to, Note: strings.Join(notes, ""), } return newTx.Save(&log).Error } return nil } } return fmt.Errorf("failed to perform event %s from state %s", name, stateWas) }
[ "func", "(", "sm", "*", "StateMachine", ")", "Trigger", "(", "name", "string", ",", "value", "Stater", ",", "tx", "*", "gorm", ".", "DB", ",", "notes", "...", "string", ")", "error", "{", "var", "(", "newTx", "*", "gorm", ".", "DB", "\n", "stateWas", "=", "value", ".", "GetState", "(", ")", "\n", ")", "\n\n", "if", "tx", "!=", "nil", "{", "newTx", "=", "tx", ".", "New", "(", ")", "\n", "}", "\n\n", "if", "stateWas", "==", "\"", "\"", "{", "stateWas", "=", "sm", ".", "initialState", "\n", "value", ".", "SetState", "(", "sm", ".", "initialState", ")", "\n", "}", "\n\n", "if", "event", ":=", "sm", ".", "events", "[", "name", "]", ";", "event", "!=", "nil", "{", "var", "matchedTransitions", "[", "]", "*", "EventTransition", "\n", "for", "_", ",", "transition", ":=", "range", "event", ".", "transitions", "{", "var", "validFrom", "=", "len", "(", "transition", ".", "froms", ")", "==", "0", "\n", "if", "len", "(", "transition", ".", "froms", ")", ">", "0", "{", "for", "_", ",", "from", ":=", "range", "transition", ".", "froms", "{", "if", "from", "==", "stateWas", "{", "validFrom", "=", "true", "\n", "}", "\n", "}", "\n", "}", "\n\n", "if", "validFrom", "{", "matchedTransitions", "=", "append", "(", "matchedTransitions", ",", "transition", ")", "\n", "}", "\n", "}", "\n\n", "if", "len", "(", "matchedTransitions", ")", "==", "1", "{", "transition", ":=", "matchedTransitions", "[", "0", "]", "\n\n", "// State: exit", "if", "state", ",", "ok", ":=", "sm", ".", "states", "[", "stateWas", "]", ";", "ok", "{", "for", "_", ",", "exit", ":=", "range", "state", ".", "exits", "{", "if", "err", ":=", "exit", "(", "value", ",", "newTx", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n", "}", "\n\n", "// Transition: before", "for", "_", ",", "before", ":=", "range", "transition", ".", "befores", "{", "if", "err", ":=", "before", "(", "value", ",", "newTx", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n\n", "value", ".", "SetState", "(", "transition", ".", "to", ")", "\n\n", "// State: enter", "if", "state", ",", "ok", ":=", "sm", ".", "states", "[", "transition", ".", "to", "]", ";", "ok", "{", "for", "_", ",", "enter", ":=", "range", "state", ".", "enters", "{", "if", "err", ":=", "enter", "(", "value", ",", "newTx", ")", ";", "err", "!=", "nil", "{", "value", ".", "SetState", "(", "stateWas", ")", "\n", "return", "err", "\n", "}", "\n", "}", "\n", "}", "\n\n", "// Transition: after", "for", "_", ",", "after", ":=", "range", "transition", ".", "afters", "{", "if", "err", ":=", "after", "(", "value", ",", "newTx", ")", ";", "err", "!=", "nil", "{", "value", ".", "SetState", "(", "stateWas", ")", "\n", "return", "err", "\n", "}", "\n", "}", "\n\n", "if", "newTx", "!=", "nil", "{", "scope", ":=", "newTx", ".", "NewScope", "(", "value", ")", "\n", "log", ":=", "StateChangeLog", "{", "ReferTable", ":", "scope", ".", "TableName", "(", ")", ",", "ReferID", ":", "GenerateReferenceKey", "(", "value", ",", "tx", ")", ",", "From", ":", "stateWas", ",", "To", ":", "transition", ".", "to", ",", "Note", ":", "strings", ".", "Join", "(", "notes", ",", "\"", "\"", ")", ",", "}", "\n", "return", "newTx", ".", "Save", "(", "&", "log", ")", ".", "Error", "\n", "}", "\n\n", "return", "nil", "\n", "}", "\n", "}", "\n", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "name", ",", "stateWas", ")", "\n", "}" ]
// Trigger trigger an event
[ "Trigger", "trigger", "an", "event" ]
4015a3eee19c49a63b1d22beab1c0c084e72c53b
https://github.com/qor/transition/blob/4015a3eee19c49a63b1d22beab1c0c084e72c53b/transition.go#L71-L158
9,040
qor/transition
transition.go
Enter
func (state *State) Enter(fc func(value interface{}, tx *gorm.DB) error) *State { state.enters = append(state.enters, fc) return state }
go
func (state *State) Enter(fc func(value interface{}, tx *gorm.DB) error) *State { state.enters = append(state.enters, fc) return state }
[ "func", "(", "state", "*", "State", ")", "Enter", "(", "fc", "func", "(", "value", "interface", "{", "}", ",", "tx", "*", "gorm", ".", "DB", ")", "error", ")", "*", "State", "{", "state", ".", "enters", "=", "append", "(", "state", ".", "enters", ",", "fc", ")", "\n", "return", "state", "\n", "}" ]
// Enter register an enter hook for State
[ "Enter", "register", "an", "enter", "hook", "for", "State" ]
4015a3eee19c49a63b1d22beab1c0c084e72c53b
https://github.com/qor/transition/blob/4015a3eee19c49a63b1d22beab1c0c084e72c53b/transition.go#L168-L171
9,041
qor/transition
transition.go
Exit
func (state *State) Exit(fc func(value interface{}, tx *gorm.DB) error) *State { state.exits = append(state.exits, fc) return state }
go
func (state *State) Exit(fc func(value interface{}, tx *gorm.DB) error) *State { state.exits = append(state.exits, fc) return state }
[ "func", "(", "state", "*", "State", ")", "Exit", "(", "fc", "func", "(", "value", "interface", "{", "}", ",", "tx", "*", "gorm", ".", "DB", ")", "error", ")", "*", "State", "{", "state", ".", "exits", "=", "append", "(", "state", ".", "exits", ",", "fc", ")", "\n", "return", "state", "\n", "}" ]
// Exit register an exit hook for State
[ "Exit", "register", "an", "exit", "hook", "for", "State" ]
4015a3eee19c49a63b1d22beab1c0c084e72c53b
https://github.com/qor/transition/blob/4015a3eee19c49a63b1d22beab1c0c084e72c53b/transition.go#L174-L177
9,042
qor/transition
transition.go
To
func (event *Event) To(name string) *EventTransition { transition := &EventTransition{to: name} event.transitions = append(event.transitions, transition) return transition }
go
func (event *Event) To(name string) *EventTransition { transition := &EventTransition{to: name} event.transitions = append(event.transitions, transition) return transition }
[ "func", "(", "event", "*", "Event", ")", "To", "(", "name", "string", ")", "*", "EventTransition", "{", "transition", ":=", "&", "EventTransition", "{", "to", ":", "name", "}", "\n", "event", ".", "transitions", "=", "append", "(", "event", ".", "transitions", ",", "transition", ")", "\n", "return", "transition", "\n", "}" ]
// To define EventTransition of go to a state
[ "To", "define", "EventTransition", "of", "go", "to", "a", "state" ]
4015a3eee19c49a63b1d22beab1c0c084e72c53b
https://github.com/qor/transition/blob/4015a3eee19c49a63b1d22beab1c0c084e72c53b/transition.go#L186-L190
9,043
qor/transition
transition.go
From
func (transition *EventTransition) From(states ...string) *EventTransition { transition.froms = states return transition }
go
func (transition *EventTransition) From(states ...string) *EventTransition { transition.froms = states return transition }
[ "func", "(", "transition", "*", "EventTransition", ")", "From", "(", "states", "...", "string", ")", "*", "EventTransition", "{", "transition", ".", "froms", "=", "states", "\n", "return", "transition", "\n", "}" ]
// From used to define from states
[ "From", "used", "to", "define", "from", "states" ]
4015a3eee19c49a63b1d22beab1c0c084e72c53b
https://github.com/qor/transition/blob/4015a3eee19c49a63b1d22beab1c0c084e72c53b/transition.go#L201-L204
9,044
qor/transition
transition.go
Before
func (transition *EventTransition) Before(fc func(value interface{}, tx *gorm.DB) error) *EventTransition { transition.befores = append(transition.befores, fc) return transition }
go
func (transition *EventTransition) Before(fc func(value interface{}, tx *gorm.DB) error) *EventTransition { transition.befores = append(transition.befores, fc) return transition }
[ "func", "(", "transition", "*", "EventTransition", ")", "Before", "(", "fc", "func", "(", "value", "interface", "{", "}", ",", "tx", "*", "gorm", ".", "DB", ")", "error", ")", "*", "EventTransition", "{", "transition", ".", "befores", "=", "append", "(", "transition", ".", "befores", ",", "fc", ")", "\n", "return", "transition", "\n", "}" ]
// Before register before hooks
[ "Before", "register", "before", "hooks" ]
4015a3eee19c49a63b1d22beab1c0c084e72c53b
https://github.com/qor/transition/blob/4015a3eee19c49a63b1d22beab1c0c084e72c53b/transition.go#L207-L210
9,045
qor/transition
transition.go
After
func (transition *EventTransition) After(fc func(value interface{}, tx *gorm.DB) error) *EventTransition { transition.afters = append(transition.afters, fc) return transition }
go
func (transition *EventTransition) After(fc func(value interface{}, tx *gorm.DB) error) *EventTransition { transition.afters = append(transition.afters, fc) return transition }
[ "func", "(", "transition", "*", "EventTransition", ")", "After", "(", "fc", "func", "(", "value", "interface", "{", "}", ",", "tx", "*", "gorm", ".", "DB", ")", "error", ")", "*", "EventTransition", "{", "transition", ".", "afters", "=", "append", "(", "transition", ".", "afters", ",", "fc", ")", "\n", "return", "transition", "\n", "}" ]
// After register after hooks
[ "After", "register", "after", "hooks" ]
4015a3eee19c49a63b1d22beab1c0c084e72c53b
https://github.com/qor/transition/blob/4015a3eee19c49a63b1d22beab1c0c084e72c53b/transition.go#L213-L216
9,046
qor/transition
state_change_log.go
GenerateReferenceKey
func GenerateReferenceKey(model interface{}, db *gorm.DB) string { var ( scope = db.NewScope(model) primaryValues []string ) for _, field := range scope.PrimaryFields() { primaryValues = append(primaryValues, fmt.Sprint(field.Field.Interface())) } return strings.Join(primaryValues, "::") }
go
func GenerateReferenceKey(model interface{}, db *gorm.DB) string { var ( scope = db.NewScope(model) primaryValues []string ) for _, field := range scope.PrimaryFields() { primaryValues = append(primaryValues, fmt.Sprint(field.Field.Interface())) } return strings.Join(primaryValues, "::") }
[ "func", "GenerateReferenceKey", "(", "model", "interface", "{", "}", ",", "db", "*", "gorm", ".", "DB", ")", "string", "{", "var", "(", "scope", "=", "db", ".", "NewScope", "(", "model", ")", "\n", "primaryValues", "[", "]", "string", "\n", ")", "\n\n", "for", "_", ",", "field", ":=", "range", "scope", ".", "PrimaryFields", "(", ")", "{", "primaryValues", "=", "append", "(", "primaryValues", ",", "fmt", ".", "Sprint", "(", "field", ".", "Field", ".", "Interface", "(", ")", ")", ")", "\n", "}", "\n\n", "return", "strings", ".", "Join", "(", "primaryValues", ",", "\"", "\"", ")", "\n", "}" ]
// GenerateReferenceKey generate reference key used for change log
[ "GenerateReferenceKey", "generate", "reference", "key", "used", "for", "change", "log" ]
4015a3eee19c49a63b1d22beab1c0c084e72c53b
https://github.com/qor/transition/blob/4015a3eee19c49a63b1d22beab1c0c084e72c53b/state_change_log.go#L26-L37
9,047
qor/transition
state_change_log.go
GetStateChangeLogs
func GetStateChangeLogs(model interface{}, db *gorm.DB) []StateChangeLog { var ( changelogs []StateChangeLog scope = db.NewScope(model) ) db.Where("refer_table = ? AND refer_id = ?", scope.TableName(), GenerateReferenceKey(model, db)).Find(&changelogs) return changelogs }
go
func GetStateChangeLogs(model interface{}, db *gorm.DB) []StateChangeLog { var ( changelogs []StateChangeLog scope = db.NewScope(model) ) db.Where("refer_table = ? AND refer_id = ?", scope.TableName(), GenerateReferenceKey(model, db)).Find(&changelogs) return changelogs }
[ "func", "GetStateChangeLogs", "(", "model", "interface", "{", "}", ",", "db", "*", "gorm", ".", "DB", ")", "[", "]", "StateChangeLog", "{", "var", "(", "changelogs", "[", "]", "StateChangeLog", "\n", "scope", "=", "db", ".", "NewScope", "(", "model", ")", "\n", ")", "\n\n", "db", ".", "Where", "(", "\"", "\"", ",", "scope", ".", "TableName", "(", ")", ",", "GenerateReferenceKey", "(", "model", ",", "db", ")", ")", ".", "Find", "(", "&", "changelogs", ")", "\n\n", "return", "changelogs", "\n", "}" ]
// GetStateChangeLogs get state change logs
[ "GetStateChangeLogs", "get", "state", "change", "logs" ]
4015a3eee19c49a63b1d22beab1c0c084e72c53b
https://github.com/qor/transition/blob/4015a3eee19c49a63b1d22beab1c0c084e72c53b/state_change_log.go#L40-L49
9,048
zmb3/spotify
user.go
GetUsersPublicProfile
func (c *Client) GetUsersPublicProfile(userID ID) (*User, error) { spotifyURL := c.baseURL + "users/" + string(userID) var user User err := c.get(spotifyURL, &user) if err != nil { return nil, err } return &user, nil }
go
func (c *Client) GetUsersPublicProfile(userID ID) (*User, error) { spotifyURL := c.baseURL + "users/" + string(userID) var user User err := c.get(spotifyURL, &user) if err != nil { return nil, err } return &user, nil }
[ "func", "(", "c", "*", "Client", ")", "GetUsersPublicProfile", "(", "userID", "ID", ")", "(", "*", "User", ",", "error", ")", "{", "spotifyURL", ":=", "c", ".", "baseURL", "+", "\"", "\"", "+", "string", "(", "userID", ")", "\n\n", "var", "user", "User", "\n\n", "err", ":=", "c", ".", "get", "(", "spotifyURL", ",", "&", "user", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "&", "user", ",", "nil", "\n", "}" ]
// GetUsersPublicProfile gets public profile information about a // Spotify User. It does not require authentication.
[ "GetUsersPublicProfile", "gets", "public", "profile", "information", "about", "a", "Spotify", "User", ".", "It", "does", "not", "require", "authentication", "." ]
94cbe6dc5cc2eaa467e36f30b130b0f827e4262d
https://github.com/zmb3/spotify/blob/94cbe6dc5cc2eaa467e36f30b130b0f827e4262d/user.go#L59-L70
9,049
zmb3/spotify
user.go
CurrentUsersTracksOpt
func (c *Client) CurrentUsersTracksOpt(opt *Options) (*SavedTrackPage, error) { spotifyURL := c.baseURL + "me/tracks" if opt != nil { v := url.Values{} if opt.Country != nil { v.Set("country", *opt.Country) } if opt.Limit != nil { v.Set("limit", strconv.Itoa(*opt.Limit)) } if opt.Offset != nil { v.Set("offset", strconv.Itoa(*opt.Offset)) } if params := v.Encode(); params != "" { spotifyURL += "?" + params } } var result SavedTrackPage err := c.get(spotifyURL, &result) if err != nil { return nil, err } return &result, nil }
go
func (c *Client) CurrentUsersTracksOpt(opt *Options) (*SavedTrackPage, error) { spotifyURL := c.baseURL + "me/tracks" if opt != nil { v := url.Values{} if opt.Country != nil { v.Set("country", *opt.Country) } if opt.Limit != nil { v.Set("limit", strconv.Itoa(*opt.Limit)) } if opt.Offset != nil { v.Set("offset", strconv.Itoa(*opt.Offset)) } if params := v.Encode(); params != "" { spotifyURL += "?" + params } } var result SavedTrackPage err := c.get(spotifyURL, &result) if err != nil { return nil, err } return &result, nil }
[ "func", "(", "c", "*", "Client", ")", "CurrentUsersTracksOpt", "(", "opt", "*", "Options", ")", "(", "*", "SavedTrackPage", ",", "error", ")", "{", "spotifyURL", ":=", "c", ".", "baseURL", "+", "\"", "\"", "\n", "if", "opt", "!=", "nil", "{", "v", ":=", "url", ".", "Values", "{", "}", "\n", "if", "opt", ".", "Country", "!=", "nil", "{", "v", ".", "Set", "(", "\"", "\"", ",", "*", "opt", ".", "Country", ")", "\n", "}", "\n", "if", "opt", ".", "Limit", "!=", "nil", "{", "v", ".", "Set", "(", "\"", "\"", ",", "strconv", ".", "Itoa", "(", "*", "opt", ".", "Limit", ")", ")", "\n", "}", "\n", "if", "opt", ".", "Offset", "!=", "nil", "{", "v", ".", "Set", "(", "\"", "\"", ",", "strconv", ".", "Itoa", "(", "*", "opt", ".", "Offset", ")", ")", "\n", "}", "\n", "if", "params", ":=", "v", ".", "Encode", "(", ")", ";", "params", "!=", "\"", "\"", "{", "spotifyURL", "+=", "\"", "\"", "+", "params", "\n", "}", "\n", "}", "\n\n", "var", "result", "SavedTrackPage", "\n\n", "err", ":=", "c", ".", "get", "(", "spotifyURL", ",", "&", "result", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "&", "result", ",", "nil", "\n", "}" ]
// CurrentUsersTracksOpt is like CurrentUsersTracks, but it accepts additional // options for sorting and filtering the results.
[ "CurrentUsersTracksOpt", "is", "like", "CurrentUsersTracks", "but", "it", "accepts", "additional", "options", "for", "sorting", "and", "filtering", "the", "results", "." ]
94cbe6dc5cc2eaa467e36f30b130b0f827e4262d
https://github.com/zmb3/spotify/blob/94cbe6dc5cc2eaa467e36f30b130b0f827e4262d/user.go#L103-L129
9,050
zmb3/spotify
user.go
FollowUser
func (c *Client) FollowUser(ids ...ID) error { return c.modifyFollowers("user", true, ids...) }
go
func (c *Client) FollowUser(ids ...ID) error { return c.modifyFollowers("user", true, ids...) }
[ "func", "(", "c", "*", "Client", ")", "FollowUser", "(", "ids", "...", "ID", ")", "error", "{", "return", "c", ".", "modifyFollowers", "(", "\"", "\"", ",", "true", ",", "ids", "...", ")", "\n", "}" ]
// FollowUser adds the current user as a follower of one or more // spotify users, identified by their Spotify IDs. // // Modifying the lists of artists or users the current user follows // requires that the application has the ScopeUserFollowModify scope.
[ "FollowUser", "adds", "the", "current", "user", "as", "a", "follower", "of", "one", "or", "more", "spotify", "users", "identified", "by", "their", "Spotify", "IDs", ".", "Modifying", "the", "lists", "of", "artists", "or", "users", "the", "current", "user", "follows", "requires", "that", "the", "application", "has", "the", "ScopeUserFollowModify", "scope", "." ]
94cbe6dc5cc2eaa467e36f30b130b0f827e4262d
https://github.com/zmb3/spotify/blob/94cbe6dc5cc2eaa467e36f30b130b0f827e4262d/user.go#L136-L138
9,051
zmb3/spotify
user.go
FollowArtist
func (c *Client) FollowArtist(ids ...ID) error { return c.modifyFollowers("artist", true, ids...) }
go
func (c *Client) FollowArtist(ids ...ID) error { return c.modifyFollowers("artist", true, ids...) }
[ "func", "(", "c", "*", "Client", ")", "FollowArtist", "(", "ids", "...", "ID", ")", "error", "{", "return", "c", ".", "modifyFollowers", "(", "\"", "\"", ",", "true", ",", "ids", "...", ")", "\n", "}" ]
// FollowArtist adds the current user as a follower of one or more // spotify artists, identified by their Spotify IDs. // // Modifying the lists of artists or users the current user follows // requires that the application has the ScopeUserFollowModify scope.
[ "FollowArtist", "adds", "the", "current", "user", "as", "a", "follower", "of", "one", "or", "more", "spotify", "artists", "identified", "by", "their", "Spotify", "IDs", ".", "Modifying", "the", "lists", "of", "artists", "or", "users", "the", "current", "user", "follows", "requires", "that", "the", "application", "has", "the", "ScopeUserFollowModify", "scope", "." ]
94cbe6dc5cc2eaa467e36f30b130b0f827e4262d
https://github.com/zmb3/spotify/blob/94cbe6dc5cc2eaa467e36f30b130b0f827e4262d/user.go#L145-L147
9,052
zmb3/spotify
user.go
UnfollowUser
func (c *Client) UnfollowUser(ids ...ID) error { return c.modifyFollowers("user", false, ids...) }
go
func (c *Client) UnfollowUser(ids ...ID) error { return c.modifyFollowers("user", false, ids...) }
[ "func", "(", "c", "*", "Client", ")", "UnfollowUser", "(", "ids", "...", "ID", ")", "error", "{", "return", "c", ".", "modifyFollowers", "(", "\"", "\"", ",", "false", ",", "ids", "...", ")", "\n", "}" ]
// UnfollowUser removes the current user as a follower of one or more // Spotify users. // // Modifying the lists of artists or users the current user follows // requires that the application has the ScopeUserFollowModify scope.
[ "UnfollowUser", "removes", "the", "current", "user", "as", "a", "follower", "of", "one", "or", "more", "Spotify", "users", ".", "Modifying", "the", "lists", "of", "artists", "or", "users", "the", "current", "user", "follows", "requires", "that", "the", "application", "has", "the", "ScopeUserFollowModify", "scope", "." ]
94cbe6dc5cc2eaa467e36f30b130b0f827e4262d
https://github.com/zmb3/spotify/blob/94cbe6dc5cc2eaa467e36f30b130b0f827e4262d/user.go#L154-L156
9,053
zmb3/spotify
user.go
UnfollowArtist
func (c *Client) UnfollowArtist(ids ...ID) error { return c.modifyFollowers("artist", false, ids...) }
go
func (c *Client) UnfollowArtist(ids ...ID) error { return c.modifyFollowers("artist", false, ids...) }
[ "func", "(", "c", "*", "Client", ")", "UnfollowArtist", "(", "ids", "...", "ID", ")", "error", "{", "return", "c", ".", "modifyFollowers", "(", "\"", "\"", ",", "false", ",", "ids", "...", ")", "\n", "}" ]
// UnfollowArtist removes the current user as a follower of one or more // Spotify artists. // // Modifying the lists of artists or users the current user follows // requires that the application has the ScopeUserFollowModify scope.
[ "UnfollowArtist", "removes", "the", "current", "user", "as", "a", "follower", "of", "one", "or", "more", "Spotify", "artists", ".", "Modifying", "the", "lists", "of", "artists", "or", "users", "the", "current", "user", "follows", "requires", "that", "the", "application", "has", "the", "ScopeUserFollowModify", "scope", "." ]
94cbe6dc5cc2eaa467e36f30b130b0f827e4262d
https://github.com/zmb3/spotify/blob/94cbe6dc5cc2eaa467e36f30b130b0f827e4262d/user.go#L163-L165
9,054
zmb3/spotify
user.go
CurrentUserFollows
func (c *Client) CurrentUserFollows(t string, ids ...ID) ([]bool, error) { if l := len(ids); l == 0 || l > 50 { return nil, errors.New("spotify: UserFollows supports 1 to 50 IDs") } if t != "artist" && t != "user" { return nil, errors.New("spotify: t must be 'artist' or 'user'") } spotifyURL := fmt.Sprintf("%sme/following/contains?type=%s&ids=%s", c.baseURL, t, strings.Join(toStringSlice(ids), ",")) var result []bool err := c.get(spotifyURL, &result) if err != nil { return nil, err } return result, nil }
go
func (c *Client) CurrentUserFollows(t string, ids ...ID) ([]bool, error) { if l := len(ids); l == 0 || l > 50 { return nil, errors.New("spotify: UserFollows supports 1 to 50 IDs") } if t != "artist" && t != "user" { return nil, errors.New("spotify: t must be 'artist' or 'user'") } spotifyURL := fmt.Sprintf("%sme/following/contains?type=%s&ids=%s", c.baseURL, t, strings.Join(toStringSlice(ids), ",")) var result []bool err := c.get(spotifyURL, &result) if err != nil { return nil, err } return result, nil }
[ "func", "(", "c", "*", "Client", ")", "CurrentUserFollows", "(", "t", "string", ",", "ids", "...", "ID", ")", "(", "[", "]", "bool", ",", "error", ")", "{", "if", "l", ":=", "len", "(", "ids", ")", ";", "l", "==", "0", "||", "l", ">", "50", "{", "return", "nil", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n", "if", "t", "!=", "\"", "\"", "&&", "t", "!=", "\"", "\"", "{", "return", "nil", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n", "spotifyURL", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "c", ".", "baseURL", ",", "t", ",", "strings", ".", "Join", "(", "toStringSlice", "(", "ids", ")", ",", "\"", "\"", ")", ")", "\n\n", "var", "result", "[", "]", "bool", "\n\n", "err", ":=", "c", ".", "get", "(", "spotifyURL", ",", "&", "result", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "result", ",", "nil", "\n", "}" ]
// CurrentUserFollows checks to see if the current user is following // one or more artists or other Spotify Users. This call requires // ScopeUserFollowRead. // // The t argument indicates the type of the IDs, and must be either // "user" or "artist". // // The result is returned as a slice of bool values in the same order // in which the IDs were specified.
[ "CurrentUserFollows", "checks", "to", "see", "if", "the", "current", "user", "is", "following", "one", "or", "more", "artists", "or", "other", "Spotify", "Users", ".", "This", "call", "requires", "ScopeUserFollowRead", ".", "The", "t", "argument", "indicates", "the", "type", "of", "the", "IDs", "and", "must", "be", "either", "user", "or", "artist", ".", "The", "result", "is", "returned", "as", "a", "slice", "of", "bool", "values", "in", "the", "same", "order", "in", "which", "the", "IDs", "were", "specified", "." ]
94cbe6dc5cc2eaa467e36f30b130b0f827e4262d
https://github.com/zmb3/spotify/blob/94cbe6dc5cc2eaa467e36f30b130b0f827e4262d/user.go#L176-L194
9,055
zmb3/spotify
auth.go
SetAuthInfo
func (a *Authenticator) SetAuthInfo(clientID, secretKey string) { a.config.ClientID = clientID a.config.ClientSecret = secretKey }
go
func (a *Authenticator) SetAuthInfo(clientID, secretKey string) { a.config.ClientID = clientID a.config.ClientSecret = secretKey }
[ "func", "(", "a", "*", "Authenticator", ")", "SetAuthInfo", "(", "clientID", ",", "secretKey", "string", ")", "{", "a", ".", "config", ".", "ClientID", "=", "clientID", "\n", "a", ".", "config", ".", "ClientSecret", "=", "secretKey", "\n", "}" ]
// SetAuthInfo overwrites the client ID and secret key used by the authenticator. // You can use this if you don't want to store this information in environment variables.
[ "SetAuthInfo", "overwrites", "the", "client", "ID", "and", "secret", "key", "used", "by", "the", "authenticator", ".", "You", "can", "use", "this", "if", "you", "don", "t", "want", "to", "store", "this", "information", "in", "environment", "variables", "." ]
94cbe6dc5cc2eaa467e36f30b130b0f827e4262d
https://github.com/zmb3/spotify/blob/94cbe6dc5cc2eaa467e36f30b130b0f827e4262d/auth.go#L120-L123
9,056
zmb3/spotify
auth.go
Token
func (a Authenticator) Token(state string, r *http.Request) (*oauth2.Token, error) { values := r.URL.Query() if e := values.Get("error"); e != "" { return nil, errors.New("spotify: auth failed - " + e) } code := values.Get("code") if code == "" { return nil, errors.New("spotify: didn't get access code") } actualState := values.Get("state") if actualState != state { return nil, errors.New("spotify: redirect state parameter doesn't match") } return a.config.Exchange(a.context, code) }
go
func (a Authenticator) Token(state string, r *http.Request) (*oauth2.Token, error) { values := r.URL.Query() if e := values.Get("error"); e != "" { return nil, errors.New("spotify: auth failed - " + e) } code := values.Get("code") if code == "" { return nil, errors.New("spotify: didn't get access code") } actualState := values.Get("state") if actualState != state { return nil, errors.New("spotify: redirect state parameter doesn't match") } return a.config.Exchange(a.context, code) }
[ "func", "(", "a", "Authenticator", ")", "Token", "(", "state", "string", ",", "r", "*", "http", ".", "Request", ")", "(", "*", "oauth2", ".", "Token", ",", "error", ")", "{", "values", ":=", "r", ".", "URL", ".", "Query", "(", ")", "\n", "if", "e", ":=", "values", ".", "Get", "(", "\"", "\"", ")", ";", "e", "!=", "\"", "\"", "{", "return", "nil", ",", "errors", ".", "New", "(", "\"", "\"", "+", "e", ")", "\n", "}", "\n", "code", ":=", "values", ".", "Get", "(", "\"", "\"", ")", "\n", "if", "code", "==", "\"", "\"", "{", "return", "nil", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n", "actualState", ":=", "values", ".", "Get", "(", "\"", "\"", ")", "\n", "if", "actualState", "!=", "state", "{", "return", "nil", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n", "return", "a", ".", "config", ".", "Exchange", "(", "a", ".", "context", ",", "code", ")", "\n", "}" ]
// Token pulls an authorization code from an HTTP request and attempts to exchange // it for an access token. The standard use case is to call Token from the handler // that handles requests to your application's redirect URL.
[ "Token", "pulls", "an", "authorization", "code", "from", "an", "HTTP", "request", "and", "attempts", "to", "exchange", "it", "for", "an", "access", "token", ".", "The", "standard", "use", "case", "is", "to", "call", "Token", "from", "the", "handler", "that", "handles", "requests", "to", "your", "application", "s", "redirect", "URL", "." ]
94cbe6dc5cc2eaa467e36f30b130b0f827e4262d
https://github.com/zmb3/spotify/blob/94cbe6dc5cc2eaa467e36f30b130b0f827e4262d/auth.go#L137-L151
9,057
zmb3/spotify
auth.go
Exchange
func (a Authenticator) Exchange(code string) (*oauth2.Token, error) { return a.config.Exchange(a.context, code) }
go
func (a Authenticator) Exchange(code string) (*oauth2.Token, error) { return a.config.Exchange(a.context, code) }
[ "func", "(", "a", "Authenticator", ")", "Exchange", "(", "code", "string", ")", "(", "*", "oauth2", ".", "Token", ",", "error", ")", "{", "return", "a", ".", "config", ".", "Exchange", "(", "a", ".", "context", ",", "code", ")", "\n", "}" ]
// Exchange is like Token, except it allows you to manually specify the access // code instead of pulling it out of an HTTP request.
[ "Exchange", "is", "like", "Token", "except", "it", "allows", "you", "to", "manually", "specify", "the", "access", "code", "instead", "of", "pulling", "it", "out", "of", "an", "HTTP", "request", "." ]
94cbe6dc5cc2eaa467e36f30b130b0f827e4262d
https://github.com/zmb3/spotify/blob/94cbe6dc5cc2eaa467e36f30b130b0f827e4262d/auth.go#L155-L157
9,058
zmb3/spotify
auth.go
NewClient
func (a Authenticator) NewClient(token *oauth2.Token) Client { client := a.config.Client(a.context, token) return Client{ http: client, baseURL: baseAddress, } }
go
func (a Authenticator) NewClient(token *oauth2.Token) Client { client := a.config.Client(a.context, token) return Client{ http: client, baseURL: baseAddress, } }
[ "func", "(", "a", "Authenticator", ")", "NewClient", "(", "token", "*", "oauth2", ".", "Token", ")", "Client", "{", "client", ":=", "a", ".", "config", ".", "Client", "(", "a", ".", "context", ",", "token", ")", "\n", "return", "Client", "{", "http", ":", "client", ",", "baseURL", ":", "baseAddress", ",", "}", "\n", "}" ]
// NewClient creates a Client that will use the specified access token for its API requests.
[ "NewClient", "creates", "a", "Client", "that", "will", "use", "the", "specified", "access", "token", "for", "its", "API", "requests", "." ]
94cbe6dc5cc2eaa467e36f30b130b0f827e4262d
https://github.com/zmb3/spotify/blob/94cbe6dc5cc2eaa467e36f30b130b0f827e4262d/auth.go#L160-L166
9,059
zmb3/spotify
auth.go
Token
func (c *Client) Token() (*oauth2.Token, error) { transport, ok := c.http.Transport.(*oauth2.Transport) if !ok { return nil, errors.New("spotify: oauth2 transport type not correct") } t, err := transport.Source.Token() if err != nil { return nil, err } return t, nil }
go
func (c *Client) Token() (*oauth2.Token, error) { transport, ok := c.http.Transport.(*oauth2.Transport) if !ok { return nil, errors.New("spotify: oauth2 transport type not correct") } t, err := transport.Source.Token() if err != nil { return nil, err } return t, nil }
[ "func", "(", "c", "*", "Client", ")", "Token", "(", ")", "(", "*", "oauth2", ".", "Token", ",", "error", ")", "{", "transport", ",", "ok", ":=", "c", ".", "http", ".", "Transport", ".", "(", "*", "oauth2", ".", "Transport", ")", "\n", "if", "!", "ok", "{", "return", "nil", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n", "t", ",", "err", ":=", "transport", ".", "Source", ".", "Token", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "t", ",", "nil", "\n", "}" ]
// Token gets the client's current token.
[ "Token", "gets", "the", "client", "s", "current", "token", "." ]
94cbe6dc5cc2eaa467e36f30b130b0f827e4262d
https://github.com/zmb3/spotify/blob/94cbe6dc5cc2eaa467e36f30b130b0f827e4262d/auth.go#L169-L180
9,060
zmb3/spotify
album.go
GetAlbum
func (c *Client) GetAlbum(id ID) (*FullAlbum, error) { spotifyURL := fmt.Sprintf("%salbums/%s", c.baseURL, id) var a FullAlbum err := c.get(spotifyURL, &a) if err != nil { return nil, err } return &a, nil }
go
func (c *Client) GetAlbum(id ID) (*FullAlbum, error) { spotifyURL := fmt.Sprintf("%salbums/%s", c.baseURL, id) var a FullAlbum err := c.get(spotifyURL, &a) if err != nil { return nil, err } return &a, nil }
[ "func", "(", "c", "*", "Client", ")", "GetAlbum", "(", "id", "ID", ")", "(", "*", "FullAlbum", ",", "error", ")", "{", "spotifyURL", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "c", ".", "baseURL", ",", "id", ")", "\n\n", "var", "a", "FullAlbum", "\n\n", "err", ":=", "c", ".", "get", "(", "spotifyURL", ",", "&", "a", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "&", "a", ",", "nil", "\n", "}" ]
// GetAlbum gets Spotify catalog information for a single album, given its Spotify ID.
[ "GetAlbum", "gets", "Spotify", "catalog", "information", "for", "a", "single", "album", "given", "its", "Spotify", "ID", "." ]
94cbe6dc5cc2eaa467e36f30b130b0f827e4262d
https://github.com/zmb3/spotify/blob/94cbe6dc5cc2eaa467e36f30b130b0f827e4262d/album.go#L113-L124
9,061
zmb3/spotify
album.go
GetAlbums
func (c *Client) GetAlbums(ids ...ID) ([]*FullAlbum, error) { if len(ids) > 20 { return nil, errors.New("spotify: exceeded maximum number of albums") } spotifyURL := fmt.Sprintf("%salbums?ids=%s", c.baseURL, strings.Join(toStringSlice(ids), ",")) var a struct { Albums []*FullAlbum `json:"albums"` } err := c.get(spotifyURL, &a) if err != nil { return nil, err } return a.Albums, nil }
go
func (c *Client) GetAlbums(ids ...ID) ([]*FullAlbum, error) { if len(ids) > 20 { return nil, errors.New("spotify: exceeded maximum number of albums") } spotifyURL := fmt.Sprintf("%salbums?ids=%s", c.baseURL, strings.Join(toStringSlice(ids), ",")) var a struct { Albums []*FullAlbum `json:"albums"` } err := c.get(spotifyURL, &a) if err != nil { return nil, err } return a.Albums, nil }
[ "func", "(", "c", "*", "Client", ")", "GetAlbums", "(", "ids", "...", "ID", ")", "(", "[", "]", "*", "FullAlbum", ",", "error", ")", "{", "if", "len", "(", "ids", ")", ">", "20", "{", "return", "nil", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n", "spotifyURL", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "c", ".", "baseURL", ",", "strings", ".", "Join", "(", "toStringSlice", "(", "ids", ")", ",", "\"", "\"", ")", ")", "\n\n", "var", "a", "struct", "{", "Albums", "[", "]", "*", "FullAlbum", "`json:\"albums\"`", "\n", "}", "\n\n", "err", ":=", "c", ".", "get", "(", "spotifyURL", ",", "&", "a", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "a", ".", "Albums", ",", "nil", "\n", "}" ]
// GetAlbums gets Spotify Catalog information for multiple albums, given their // Spotify IDs. It supports up to 20 IDs in a single call. Albums are returned // in the order requested. If an album is not found, that position in the // result slice will be nil.
[ "GetAlbums", "gets", "Spotify", "Catalog", "information", "for", "multiple", "albums", "given", "their", "Spotify", "IDs", ".", "It", "supports", "up", "to", "20", "IDs", "in", "a", "single", "call", ".", "Albums", "are", "returned", "in", "the", "order", "requested", ".", "If", "an", "album", "is", "not", "found", "that", "position", "in", "the", "result", "slice", "will", "be", "nil", "." ]
94cbe6dc5cc2eaa467e36f30b130b0f827e4262d
https://github.com/zmb3/spotify/blob/94cbe6dc5cc2eaa467e36f30b130b0f827e4262d/album.go#L138-L154
9,062
zmb3/spotify
album.go
GetAlbumTracks
func (c *Client) GetAlbumTracks(id ID) (*SimpleTrackPage, error) { return c.GetAlbumTracksOpt(id, -1, -1) }
go
func (c *Client) GetAlbumTracks(id ID) (*SimpleTrackPage, error) { return c.GetAlbumTracksOpt(id, -1, -1) }
[ "func", "(", "c", "*", "Client", ")", "GetAlbumTracks", "(", "id", "ID", ")", "(", "*", "SimpleTrackPage", ",", "error", ")", "{", "return", "c", ".", "GetAlbumTracksOpt", "(", "id", ",", "-", "1", ",", "-", "1", ")", "\n", "}" ]
// GetAlbumTracks gets the tracks for a particular album. // If you only care about the tracks, this call is more efficient // than GetAlbum.
[ "GetAlbumTracks", "gets", "the", "tracks", "for", "a", "particular", "album", ".", "If", "you", "only", "care", "about", "the", "tracks", "this", "call", "is", "more", "efficient", "than", "GetAlbum", "." ]
94cbe6dc5cc2eaa467e36f30b130b0f827e4262d
https://github.com/zmb3/spotify/blob/94cbe6dc5cc2eaa467e36f30b130b0f827e4262d/album.go#L190-L192
9,063
zmb3/spotify
album.go
GetAlbumTracksOpt
func (c *Client) GetAlbumTracksOpt(id ID, limit, offset int) (*SimpleTrackPage, error) { spotifyURL := fmt.Sprintf("%salbums/%s/tracks", c.baseURL, id) v := url.Values{} if limit != -1 { v.Set("limit", strconv.Itoa(limit)) } if offset != -1 { v.Set("offset", strconv.Itoa(offset)) } optional := v.Encode() if optional != "" { spotifyURL = spotifyURL + "?" + optional } var result SimpleTrackPage err := c.get(spotifyURL, &result) if err != nil { return nil, err } return &result, nil }
go
func (c *Client) GetAlbumTracksOpt(id ID, limit, offset int) (*SimpleTrackPage, error) { spotifyURL := fmt.Sprintf("%salbums/%s/tracks", c.baseURL, id) v := url.Values{} if limit != -1 { v.Set("limit", strconv.Itoa(limit)) } if offset != -1 { v.Set("offset", strconv.Itoa(offset)) } optional := v.Encode() if optional != "" { spotifyURL = spotifyURL + "?" + optional } var result SimpleTrackPage err := c.get(spotifyURL, &result) if err != nil { return nil, err } return &result, nil }
[ "func", "(", "c", "*", "Client", ")", "GetAlbumTracksOpt", "(", "id", "ID", ",", "limit", ",", "offset", "int", ")", "(", "*", "SimpleTrackPage", ",", "error", ")", "{", "spotifyURL", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "c", ".", "baseURL", ",", "id", ")", "\n", "v", ":=", "url", ".", "Values", "{", "}", "\n", "if", "limit", "!=", "-", "1", "{", "v", ".", "Set", "(", "\"", "\"", ",", "strconv", ".", "Itoa", "(", "limit", ")", ")", "\n", "}", "\n", "if", "offset", "!=", "-", "1", "{", "v", ".", "Set", "(", "\"", "\"", ",", "strconv", ".", "Itoa", "(", "offset", ")", ")", "\n", "}", "\n", "optional", ":=", "v", ".", "Encode", "(", ")", "\n", "if", "optional", "!=", "\"", "\"", "{", "spotifyURL", "=", "spotifyURL", "+", "\"", "\"", "+", "optional", "\n", "}", "\n\n", "var", "result", "SimpleTrackPage", "\n", "err", ":=", "c", ".", "get", "(", "spotifyURL", ",", "&", "result", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "&", "result", ",", "nil", "\n", "}" ]
// GetAlbumTracksOpt behaves like GetAlbumTracks, with the exception that it // allows you to specify extra parameters that limit the number of results returned. // The maximum number of results to return is specified by limit. // The offset argument can be used to specify the index of the first track to return. // It can be used along with limit to reqeust the next set of results.
[ "GetAlbumTracksOpt", "behaves", "like", "GetAlbumTracks", "with", "the", "exception", "that", "it", "allows", "you", "to", "specify", "extra", "parameters", "that", "limit", "the", "number", "of", "results", "returned", ".", "The", "maximum", "number", "of", "results", "to", "return", "is", "specified", "by", "limit", ".", "The", "offset", "argument", "can", "be", "used", "to", "specify", "the", "index", "of", "the", "first", "track", "to", "return", ".", "It", "can", "be", "used", "along", "with", "limit", "to", "reqeust", "the", "next", "set", "of", "results", "." ]
94cbe6dc5cc2eaa467e36f30b130b0f827e4262d
https://github.com/zmb3/spotify/blob/94cbe6dc5cc2eaa467e36f30b130b0f827e4262d/album.go#L199-L220
9,064
zmb3/spotify
playlist.go
FeaturedPlaylistsOpt
func (c *Client) FeaturedPlaylistsOpt(opt *PlaylistOptions) (message string, playlists *SimplePlaylistPage, e error) { spotifyURL := c.baseURL + "browse/featured-playlists" if opt != nil { v := url.Values{} if opt.Locale != nil { v.Set("locale", *opt.Locale) } if opt.Country != nil { v.Set("country", *opt.Country) } if opt.Timestamp != nil { v.Set("timestamp", *opt.Timestamp) } if opt.Limit != nil { v.Set("limit", strconv.Itoa(*opt.Limit)) } if opt.Offset != nil { v.Set("offset", strconv.Itoa(*opt.Offset)) } if params := v.Encode(); params != "" { spotifyURL += "?" + params } } var result struct { Playlists SimplePlaylistPage `json:"playlists"` Message string `json:"message"` } err := c.get(spotifyURL, &result) if err != nil { return "", nil, err } return result.Message, &result.Playlists, nil }
go
func (c *Client) FeaturedPlaylistsOpt(opt *PlaylistOptions) (message string, playlists *SimplePlaylistPage, e error) { spotifyURL := c.baseURL + "browse/featured-playlists" if opt != nil { v := url.Values{} if opt.Locale != nil { v.Set("locale", *opt.Locale) } if opt.Country != nil { v.Set("country", *opt.Country) } if opt.Timestamp != nil { v.Set("timestamp", *opt.Timestamp) } if opt.Limit != nil { v.Set("limit", strconv.Itoa(*opt.Limit)) } if opt.Offset != nil { v.Set("offset", strconv.Itoa(*opt.Offset)) } if params := v.Encode(); params != "" { spotifyURL += "?" + params } } var result struct { Playlists SimplePlaylistPage `json:"playlists"` Message string `json:"message"` } err := c.get(spotifyURL, &result) if err != nil { return "", nil, err } return result.Message, &result.Playlists, nil }
[ "func", "(", "c", "*", "Client", ")", "FeaturedPlaylistsOpt", "(", "opt", "*", "PlaylistOptions", ")", "(", "message", "string", ",", "playlists", "*", "SimplePlaylistPage", ",", "e", "error", ")", "{", "spotifyURL", ":=", "c", ".", "baseURL", "+", "\"", "\"", "\n", "if", "opt", "!=", "nil", "{", "v", ":=", "url", ".", "Values", "{", "}", "\n", "if", "opt", ".", "Locale", "!=", "nil", "{", "v", ".", "Set", "(", "\"", "\"", ",", "*", "opt", ".", "Locale", ")", "\n", "}", "\n", "if", "opt", ".", "Country", "!=", "nil", "{", "v", ".", "Set", "(", "\"", "\"", ",", "*", "opt", ".", "Country", ")", "\n", "}", "\n", "if", "opt", ".", "Timestamp", "!=", "nil", "{", "v", ".", "Set", "(", "\"", "\"", ",", "*", "opt", ".", "Timestamp", ")", "\n", "}", "\n", "if", "opt", ".", "Limit", "!=", "nil", "{", "v", ".", "Set", "(", "\"", "\"", ",", "strconv", ".", "Itoa", "(", "*", "opt", ".", "Limit", ")", ")", "\n", "}", "\n", "if", "opt", ".", "Offset", "!=", "nil", "{", "v", ".", "Set", "(", "\"", "\"", ",", "strconv", ".", "Itoa", "(", "*", "opt", ".", "Offset", ")", ")", "\n", "}", "\n", "if", "params", ":=", "v", ".", "Encode", "(", ")", ";", "params", "!=", "\"", "\"", "{", "spotifyURL", "+=", "\"", "\"", "+", "params", "\n", "}", "\n", "}", "\n\n", "var", "result", "struct", "{", "Playlists", "SimplePlaylistPage", "`json:\"playlists\"`", "\n", "Message", "string", "`json:\"message\"`", "\n", "}", "\n\n", "err", ":=", "c", ".", "get", "(", "spotifyURL", ",", "&", "result", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "nil", ",", "err", "\n", "}", "\n\n", "return", "result", ".", "Message", ",", "&", "result", ".", "Playlists", ",", "nil", "\n", "}" ]
// FeaturedPlaylistsOpt gets a list of playlists featured by Spotify. // It accepts a number of optional parameters via the opt argument.
[ "FeaturedPlaylistsOpt", "gets", "a", "list", "of", "playlists", "featured", "by", "Spotify", ".", "It", "accepts", "a", "number", "of", "optional", "parameters", "via", "the", "opt", "argument", "." ]
94cbe6dc5cc2eaa467e36f30b130b0f827e4262d
https://github.com/zmb3/spotify/blob/94cbe6dc5cc2eaa467e36f30b130b0f827e4262d/playlist.go#L80-L115
9,065
zmb3/spotify
playlist.go
UnfollowPlaylist
func (c *Client) UnfollowPlaylist(owner, playlist ID) error { spotifyURL := buildFollowURI(c.baseURL, owner, playlist) req, err := http.NewRequest("DELETE", spotifyURL, nil) if err != nil { return err } err = c.execute(req, nil) if err != nil { return err } return nil }
go
func (c *Client) UnfollowPlaylist(owner, playlist ID) error { spotifyURL := buildFollowURI(c.baseURL, owner, playlist) req, err := http.NewRequest("DELETE", spotifyURL, nil) if err != nil { return err } err = c.execute(req, nil) if err != nil { return err } return nil }
[ "func", "(", "c", "*", "Client", ")", "UnfollowPlaylist", "(", "owner", ",", "playlist", "ID", ")", "error", "{", "spotifyURL", ":=", "buildFollowURI", "(", "c", ".", "baseURL", ",", "owner", ",", "playlist", ")", "\n", "req", ",", "err", ":=", "http", ".", "NewRequest", "(", "\"", "\"", ",", "spotifyURL", ",", "nil", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "err", "=", "c", ".", "execute", "(", "req", ",", "nil", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// UnfollowPlaylist removes the current user as a follower of a playlist. // Unfollowing a publicly followed playlist requires ScopePlaylistModifyPublic. // Unfolowing a privately followed playlist requies ScopePlaylistModifyPrivate.
[ "UnfollowPlaylist", "removes", "the", "current", "user", "as", "a", "follower", "of", "a", "playlist", ".", "Unfollowing", "a", "publicly", "followed", "playlist", "requires", "ScopePlaylistModifyPublic", ".", "Unfolowing", "a", "privately", "followed", "playlist", "requies", "ScopePlaylistModifyPrivate", "." ]
94cbe6dc5cc2eaa467e36f30b130b0f827e4262d
https://github.com/zmb3/spotify/blob/94cbe6dc5cc2eaa467e36f30b130b0f827e4262d/playlist.go#L149-L160
9,066
zmb3/spotify
playlist.go
GetPlaylistsForUser
func (c *Client) GetPlaylistsForUser(userID string) (*SimplePlaylistPage, error) { return c.GetPlaylistsForUserOpt(userID, nil) }
go
func (c *Client) GetPlaylistsForUser(userID string) (*SimplePlaylistPage, error) { return c.GetPlaylistsForUserOpt(userID, nil) }
[ "func", "(", "c", "*", "Client", ")", "GetPlaylistsForUser", "(", "userID", "string", ")", "(", "*", "SimplePlaylistPage", ",", "error", ")", "{", "return", "c", ".", "GetPlaylistsForUserOpt", "(", "userID", ",", "nil", ")", "\n", "}" ]
// GetPlaylistsForUser gets a list of the playlists owned or followed by a // particular Spotify user. // // Private playlists and collaborative playlists are only retrievable for the // current user. In order to read private playlists, the user must have granted // the ScopePlaylistReadPrivate scope. Note that this scope alone will not // return collaborative playlists, even though they are always private. In // order to read collaborative playlists, the user must have granted the // ScopePlaylistReadCollaborative scope.
[ "GetPlaylistsForUser", "gets", "a", "list", "of", "the", "playlists", "owned", "or", "followed", "by", "a", "particular", "Spotify", "user", ".", "Private", "playlists", "and", "collaborative", "playlists", "are", "only", "retrievable", "for", "the", "current", "user", ".", "In", "order", "to", "read", "private", "playlists", "the", "user", "must", "have", "granted", "the", "ScopePlaylistReadPrivate", "scope", ".", "Note", "that", "this", "scope", "alone", "will", "not", "return", "collaborative", "playlists", "even", "though", "they", "are", "always", "private", ".", "In", "order", "to", "read", "collaborative", "playlists", "the", "user", "must", "have", "granted", "the", "ScopePlaylistReadCollaborative", "scope", "." ]
94cbe6dc5cc2eaa467e36f30b130b0f827e4262d
https://github.com/zmb3/spotify/blob/94cbe6dc5cc2eaa467e36f30b130b0f827e4262d/playlist.go#L176-L178
9,067
zmb3/spotify
playlist.go
GetPlaylist
func (c *Client) GetPlaylist(playlistID ID) (*FullPlaylist, error) { return c.GetPlaylistOpt(playlistID, "") }
go
func (c *Client) GetPlaylist(playlistID ID) (*FullPlaylist, error) { return c.GetPlaylistOpt(playlistID, "") }
[ "func", "(", "c", "*", "Client", ")", "GetPlaylist", "(", "playlistID", "ID", ")", "(", "*", "FullPlaylist", ",", "error", ")", "{", "return", "c", ".", "GetPlaylistOpt", "(", "playlistID", ",", "\"", "\"", ")", "\n", "}" ]
// GetPlaylist gets a playlist
[ "GetPlaylist", "gets", "a", "playlist" ]
94cbe6dc5cc2eaa467e36f30b130b0f827e4262d
https://github.com/zmb3/spotify/blob/94cbe6dc5cc2eaa467e36f30b130b0f827e4262d/playlist.go#L208-L210
9,068
zmb3/spotify
playlist.go
GetPlaylistTracks
func (c *Client) GetPlaylistTracks(playlistID ID) (*PlaylistTrackPage, error) { return c.GetPlaylistTracksOpt(playlistID, nil, "") }
go
func (c *Client) GetPlaylistTracks(playlistID ID) (*PlaylistTrackPage, error) { return c.GetPlaylistTracksOpt(playlistID, nil, "") }
[ "func", "(", "c", "*", "Client", ")", "GetPlaylistTracks", "(", "playlistID", "ID", ")", "(", "*", "PlaylistTrackPage", ",", "error", ")", "{", "return", "c", ".", "GetPlaylistTracksOpt", "(", "playlistID", ",", "nil", ",", "\"", "\"", ")", "\n", "}" ]
// GetPlaylistTracks gets full details of the tracks in a playlist, given the // playlist's Spotify ID.
[ "GetPlaylistTracks", "gets", "full", "details", "of", "the", "tracks", "in", "a", "playlist", "given", "the", "playlist", "s", "Spotify", "ID", "." ]
94cbe6dc5cc2eaa467e36f30b130b0f827e4262d
https://github.com/zmb3/spotify/blob/94cbe6dc5cc2eaa467e36f30b130b0f827e4262d/playlist.go#L248-L250
9,069
zmb3/spotify
playlist.go
CreatePlaylistForUser
func (c *Client) CreatePlaylistForUser(userID, playlistName, description string, public bool) (*FullPlaylist, error) { spotifyURL := fmt.Sprintf("%susers/%s/playlists", c.baseURL, userID) body := struct { Name string `json:"name"` Public bool `json:"public"` Description string `json:"description"` }{ playlistName, public, description, } bodyJSON, err := json.Marshal(body) if err != nil { return nil, err } req, err := http.NewRequest("POST", spotifyURL, bytes.NewReader(bodyJSON)) if err != nil { return nil, err } req.Header.Set("Content-Type", "application/json") var p FullPlaylist err = c.execute(req, &p, http.StatusCreated) if err != nil { return nil, err } return &p, err }
go
func (c *Client) CreatePlaylistForUser(userID, playlistName, description string, public bool) (*FullPlaylist, error) { spotifyURL := fmt.Sprintf("%susers/%s/playlists", c.baseURL, userID) body := struct { Name string `json:"name"` Public bool `json:"public"` Description string `json:"description"` }{ playlistName, public, description, } bodyJSON, err := json.Marshal(body) if err != nil { return nil, err } req, err := http.NewRequest("POST", spotifyURL, bytes.NewReader(bodyJSON)) if err != nil { return nil, err } req.Header.Set("Content-Type", "application/json") var p FullPlaylist err = c.execute(req, &p, http.StatusCreated) if err != nil { return nil, err } return &p, err }
[ "func", "(", "c", "*", "Client", ")", "CreatePlaylistForUser", "(", "userID", ",", "playlistName", ",", "description", "string", ",", "public", "bool", ")", "(", "*", "FullPlaylist", ",", "error", ")", "{", "spotifyURL", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "c", ".", "baseURL", ",", "userID", ")", "\n", "body", ":=", "struct", "{", "Name", "string", "`json:\"name\"`", "\n", "Public", "bool", "`json:\"public\"`", "\n", "Description", "string", "`json:\"description\"`", "\n", "}", "{", "playlistName", ",", "public", ",", "description", ",", "}", "\n", "bodyJSON", ",", "err", ":=", "json", ".", "Marshal", "(", "body", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "req", ",", "err", ":=", "http", ".", "NewRequest", "(", "\"", "\"", ",", "spotifyURL", ",", "bytes", ".", "NewReader", "(", "bodyJSON", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "req", ".", "Header", ".", "Set", "(", "\"", "\"", ",", "\"", "\"", ")", "\n\n", "var", "p", "FullPlaylist", "\n", "err", "=", "c", ".", "execute", "(", "req", ",", "&", "p", ",", "http", ".", "StatusCreated", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "&", "p", ",", "err", "\n", "}" ]
// CreatePlaylistForUser creates a playlist for a Spotify user. // The playlist will be empty until you add tracks to it. // The playlistName does not need to be unique - a user can have // several playlists with the same name. // // Creating a public playlist for a user requires ScopePlaylistModifyPublic; // creating a private playlist requires ScopePlaylistModifyPrivate. // // On success, the newly created playlist is returned.
[ "CreatePlaylistForUser", "creates", "a", "playlist", "for", "a", "Spotify", "user", ".", "The", "playlist", "will", "be", "empty", "until", "you", "add", "tracks", "to", "it", ".", "The", "playlistName", "does", "not", "need", "to", "be", "unique", "-", "a", "user", "can", "have", "several", "playlists", "with", "the", "same", "name", ".", "Creating", "a", "public", "playlist", "for", "a", "user", "requires", "ScopePlaylistModifyPublic", ";", "creating", "a", "private", "playlist", "requires", "ScopePlaylistModifyPrivate", ".", "On", "success", "the", "newly", "created", "playlist", "is", "returned", "." ]
94cbe6dc5cc2eaa467e36f30b130b0f827e4262d
https://github.com/zmb3/spotify/blob/94cbe6dc5cc2eaa467e36f30b130b0f827e4262d/playlist.go#L309-L337
9,070
zmb3/spotify
playlist.go
NewTrackToRemove
func NewTrackToRemove(trackID string, positions []int) TrackToRemove { return TrackToRemove{ URI: fmt.Sprintf("spotify:track:%s", trackID), Positions: positions, } }
go
func NewTrackToRemove(trackID string, positions []int) TrackToRemove { return TrackToRemove{ URI: fmt.Sprintf("spotify:track:%s", trackID), Positions: positions, } }
[ "func", "NewTrackToRemove", "(", "trackID", "string", ",", "positions", "[", "]", "int", ")", "TrackToRemove", "{", "return", "TrackToRemove", "{", "URI", ":", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "trackID", ")", ",", "Positions", ":", "positions", ",", "}", "\n", "}" ]
// NewTrackToRemove creates a new TrackToRemove object with the specified // track ID and playlist locations.
[ "NewTrackToRemove", "creates", "a", "new", "TrackToRemove", "object", "with", "the", "specified", "track", "ID", "and", "playlist", "locations", "." ]
94cbe6dc5cc2eaa467e36f30b130b0f827e4262d
https://github.com/zmb3/spotify/blob/94cbe6dc5cc2eaa467e36f30b130b0f827e4262d/playlist.go#L473-L478
9,071
zmb3/spotify
playlist.go
ReplacePlaylistTracks
func (c *Client) ReplacePlaylistTracks(playlistID ID, trackIDs ...ID) error { trackURIs := make([]string, len(trackIDs)) for i, u := range trackIDs { trackURIs[i] = fmt.Sprintf("spotify:track:%s", u) } spotifyURL := fmt.Sprintf("%splaylists/%s/tracks?uris=%s", c.baseURL, playlistID, strings.Join(trackURIs, ",")) req, err := http.NewRequest("PUT", spotifyURL, nil) if err != nil { return err } err = c.execute(req, nil, http.StatusCreated) if err != nil { return err } return nil }
go
func (c *Client) ReplacePlaylistTracks(playlistID ID, trackIDs ...ID) error { trackURIs := make([]string, len(trackIDs)) for i, u := range trackIDs { trackURIs[i] = fmt.Sprintf("spotify:track:%s", u) } spotifyURL := fmt.Sprintf("%splaylists/%s/tracks?uris=%s", c.baseURL, playlistID, strings.Join(trackURIs, ",")) req, err := http.NewRequest("PUT", spotifyURL, nil) if err != nil { return err } err = c.execute(req, nil, http.StatusCreated) if err != nil { return err } return nil }
[ "func", "(", "c", "*", "Client", ")", "ReplacePlaylistTracks", "(", "playlistID", "ID", ",", "trackIDs", "...", "ID", ")", "error", "{", "trackURIs", ":=", "make", "(", "[", "]", "string", ",", "len", "(", "trackIDs", ")", ")", "\n", "for", "i", ",", "u", ":=", "range", "trackIDs", "{", "trackURIs", "[", "i", "]", "=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "u", ")", "\n", "}", "\n", "spotifyURL", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "c", ".", "baseURL", ",", "playlistID", ",", "strings", ".", "Join", "(", "trackURIs", ",", "\"", "\"", ")", ")", "\n", "req", ",", "err", ":=", "http", ".", "NewRequest", "(", "\"", "\"", ",", "spotifyURL", ",", "nil", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "err", "=", "c", ".", "execute", "(", "req", ",", "nil", ",", "http", ".", "StatusCreated", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// ReplacePlaylistTracks replaces all of the tracks in a playlist, overwriting its // exising tracks This can be useful for replacing or reordering tracks, or for // clearing a playlist. // // Modifying a public playlist requires that the user has authorized the // ScopePlaylistModifyPublic scope. Modifying a private playlist requires the // ScopePlaylistModifyPrivate scope. // // A maximum of 100 tracks is permited in this call. Additional tracks must be // added via AddTracksToPlaylist.
[ "ReplacePlaylistTracks", "replaces", "all", "of", "the", "tracks", "in", "a", "playlist", "overwriting", "its", "exising", "tracks", "This", "can", "be", "useful", "for", "replacing", "or", "reordering", "tracks", "or", "for", "clearing", "a", "playlist", ".", "Modifying", "a", "public", "playlist", "requires", "that", "the", "user", "has", "authorized", "the", "ScopePlaylistModifyPublic", "scope", ".", "Modifying", "a", "private", "playlist", "requires", "the", "ScopePlaylistModifyPrivate", "scope", ".", "A", "maximum", "of", "100", "tracks", "is", "permited", "in", "this", "call", ".", "Additional", "tracks", "must", "be", "added", "via", "AddTracksToPlaylist", "." ]
94cbe6dc5cc2eaa467e36f30b130b0f827e4262d
https://github.com/zmb3/spotify/blob/94cbe6dc5cc2eaa467e36f30b130b0f827e4262d/playlist.go#L541-L558
9,072
zmb3/spotify
artist.go
GetArtist
func (c *Client) GetArtist(id ID) (*FullArtist, error) { spotifyURL := fmt.Sprintf("%sartists/%s", c.baseURL, id) var a FullArtist err := c.get(spotifyURL, &a) if err != nil { return nil, err } return &a, nil }
go
func (c *Client) GetArtist(id ID) (*FullArtist, error) { spotifyURL := fmt.Sprintf("%sartists/%s", c.baseURL, id) var a FullArtist err := c.get(spotifyURL, &a) if err != nil { return nil, err } return &a, nil }
[ "func", "(", "c", "*", "Client", ")", "GetArtist", "(", "id", "ID", ")", "(", "*", "FullArtist", ",", "error", ")", "{", "spotifyURL", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "c", ".", "baseURL", ",", "id", ")", "\n\n", "var", "a", "FullArtist", "\n", "err", ":=", "c", ".", "get", "(", "spotifyURL", ",", "&", "a", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "&", "a", ",", "nil", "\n", "}" ]
// GetArtist gets Spotify catalog information for a single artist, given its Spotify ID.
[ "GetArtist", "gets", "Spotify", "catalog", "information", "for", "a", "single", "artist", "given", "its", "Spotify", "ID", "." ]
94cbe6dc5cc2eaa467e36f30b130b0f827e4262d
https://github.com/zmb3/spotify/blob/94cbe6dc5cc2eaa467e36f30b130b0f827e4262d/artist.go#L36-L46
9,073
zmb3/spotify
artist.go
GetArtists
func (c *Client) GetArtists(ids ...ID) ([]*FullArtist, error) { spotifyURL := fmt.Sprintf("%sartists?ids=%s", c.baseURL, strings.Join(toStringSlice(ids), ",")) var a struct { Artists []*FullArtist } err := c.get(spotifyURL, &a) if err != nil { return nil, err } return a.Artists, nil }
go
func (c *Client) GetArtists(ids ...ID) ([]*FullArtist, error) { spotifyURL := fmt.Sprintf("%sartists?ids=%s", c.baseURL, strings.Join(toStringSlice(ids), ",")) var a struct { Artists []*FullArtist } err := c.get(spotifyURL, &a) if err != nil { return nil, err } return a.Artists, nil }
[ "func", "(", "c", "*", "Client", ")", "GetArtists", "(", "ids", "...", "ID", ")", "(", "[", "]", "*", "FullArtist", ",", "error", ")", "{", "spotifyURL", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "c", ".", "baseURL", ",", "strings", ".", "Join", "(", "toStringSlice", "(", "ids", ")", ",", "\"", "\"", ")", ")", "\n\n", "var", "a", "struct", "{", "Artists", "[", "]", "*", "FullArtist", "\n", "}", "\n\n", "err", ":=", "c", ".", "get", "(", "spotifyURL", ",", "&", "a", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "a", ".", "Artists", ",", "nil", "\n", "}" ]
// GetArtists gets spotify catalog information for several artists based on their // Spotify IDs. It supports up to 50 artists in a single call. Artists are // returned in the order requested. If an artist is not found, that position // in the result will be nil. Duplicate IDs will result in duplicate artists // in the result.
[ "GetArtists", "gets", "spotify", "catalog", "information", "for", "several", "artists", "based", "on", "their", "Spotify", "IDs", ".", "It", "supports", "up", "to", "50", "artists", "in", "a", "single", "call", ".", "Artists", "are", "returned", "in", "the", "order", "requested", ".", "If", "an", "artist", "is", "not", "found", "that", "position", "in", "the", "result", "will", "be", "nil", ".", "Duplicate", "IDs", "will", "result", "in", "duplicate", "artists", "in", "the", "result", "." ]
94cbe6dc5cc2eaa467e36f30b130b0f827e4262d
https://github.com/zmb3/spotify/blob/94cbe6dc5cc2eaa467e36f30b130b0f827e4262d/artist.go#L53-L66
9,074
zmb3/spotify
artist.go
GetArtistsTopTracks
func (c *Client) GetArtistsTopTracks(artistID ID, country string) ([]FullTrack, error) { spotifyURL := fmt.Sprintf("%sartists/%s/top-tracks?country=%s", c.baseURL, artistID, country) var t struct { Tracks []FullTrack `json:"tracks"` } err := c.get(spotifyURL, &t) if err != nil { return nil, err } return t.Tracks, nil }
go
func (c *Client) GetArtistsTopTracks(artistID ID, country string) ([]FullTrack, error) { spotifyURL := fmt.Sprintf("%sartists/%s/top-tracks?country=%s", c.baseURL, artistID, country) var t struct { Tracks []FullTrack `json:"tracks"` } err := c.get(spotifyURL, &t) if err != nil { return nil, err } return t.Tracks, nil }
[ "func", "(", "c", "*", "Client", ")", "GetArtistsTopTracks", "(", "artistID", "ID", ",", "country", "string", ")", "(", "[", "]", "FullTrack", ",", "error", ")", "{", "spotifyURL", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "c", ".", "baseURL", ",", "artistID", ",", "country", ")", "\n\n", "var", "t", "struct", "{", "Tracks", "[", "]", "FullTrack", "`json:\"tracks\"`", "\n", "}", "\n\n", "err", ":=", "c", ".", "get", "(", "spotifyURL", ",", "&", "t", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "t", ".", "Tracks", ",", "nil", "\n", "}" ]
// GetArtistsTopTracks gets Spotify catalog information about an artist's top // tracks in a particular country. It returns a maximum of 10 tracks. The // country is specified as an ISO 3166-1 alpha-2 country code.
[ "GetArtistsTopTracks", "gets", "Spotify", "catalog", "information", "about", "an", "artist", "s", "top", "tracks", "in", "a", "particular", "country", ".", "It", "returns", "a", "maximum", "of", "10", "tracks", ".", "The", "country", "is", "specified", "as", "an", "ISO", "3166", "-", "1", "alpha", "-", "2", "country", "code", "." ]
94cbe6dc5cc2eaa467e36f30b130b0f827e4262d
https://github.com/zmb3/spotify/blob/94cbe6dc5cc2eaa467e36f30b130b0f827e4262d/artist.go#L71-L84
9,075
zmb3/spotify
artist.go
GetArtistAlbumsOpt
func (c *Client) GetArtistAlbumsOpt(artistID ID, options *Options, t *AlbumType) (*SimpleAlbumPage, error) { spotifyURL := fmt.Sprintf("%sartists/%s/albums", c.baseURL, artistID) // add optional query string if options were specified values := url.Values{} if t != nil { values.Set("album_type", t.encode()) } if options != nil { if options.Country != nil { values.Set("market", *options.Country) } else { // if the market is not specified, Spotify will likely return a lot // of duplicates (one for each market in which the album is available) // - prevent this behavior by falling back to the US by default // TODO: would this ever be the desired behavior? values.Set("market", CountryUSA) } if options.Limit != nil { values.Set("limit", strconv.Itoa(*options.Limit)) } if options.Offset != nil { values.Set("offset", strconv.Itoa(*options.Offset)) } } if query := values.Encode(); query != "" { spotifyURL += "?" + query } var p SimpleAlbumPage err := c.get(spotifyURL, &p) if err != nil { return nil, err } return &p, nil }
go
func (c *Client) GetArtistAlbumsOpt(artistID ID, options *Options, t *AlbumType) (*SimpleAlbumPage, error) { spotifyURL := fmt.Sprintf("%sartists/%s/albums", c.baseURL, artistID) // add optional query string if options were specified values := url.Values{} if t != nil { values.Set("album_type", t.encode()) } if options != nil { if options.Country != nil { values.Set("market", *options.Country) } else { // if the market is not specified, Spotify will likely return a lot // of duplicates (one for each market in which the album is available) // - prevent this behavior by falling back to the US by default // TODO: would this ever be the desired behavior? values.Set("market", CountryUSA) } if options.Limit != nil { values.Set("limit", strconv.Itoa(*options.Limit)) } if options.Offset != nil { values.Set("offset", strconv.Itoa(*options.Offset)) } } if query := values.Encode(); query != "" { spotifyURL += "?" + query } var p SimpleAlbumPage err := c.get(spotifyURL, &p) if err != nil { return nil, err } return &p, nil }
[ "func", "(", "c", "*", "Client", ")", "GetArtistAlbumsOpt", "(", "artistID", "ID", ",", "options", "*", "Options", ",", "t", "*", "AlbumType", ")", "(", "*", "SimpleAlbumPage", ",", "error", ")", "{", "spotifyURL", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "c", ".", "baseURL", ",", "artistID", ")", "\n", "// add optional query string if options were specified", "values", ":=", "url", ".", "Values", "{", "}", "\n", "if", "t", "!=", "nil", "{", "values", ".", "Set", "(", "\"", "\"", ",", "t", ".", "encode", "(", ")", ")", "\n", "}", "\n", "if", "options", "!=", "nil", "{", "if", "options", ".", "Country", "!=", "nil", "{", "values", ".", "Set", "(", "\"", "\"", ",", "*", "options", ".", "Country", ")", "\n", "}", "else", "{", "// if the market is not specified, Spotify will likely return a lot", "// of duplicates (one for each market in which the album is available)", "// - prevent this behavior by falling back to the US by default", "// TODO: would this ever be the desired behavior?", "values", ".", "Set", "(", "\"", "\"", ",", "CountryUSA", ")", "\n", "}", "\n", "if", "options", ".", "Limit", "!=", "nil", "{", "values", ".", "Set", "(", "\"", "\"", ",", "strconv", ".", "Itoa", "(", "*", "options", ".", "Limit", ")", ")", "\n", "}", "\n", "if", "options", ".", "Offset", "!=", "nil", "{", "values", ".", "Set", "(", "\"", "\"", ",", "strconv", ".", "Itoa", "(", "*", "options", ".", "Offset", ")", ")", "\n", "}", "\n", "}", "\n", "if", "query", ":=", "values", ".", "Encode", "(", ")", ";", "query", "!=", "\"", "\"", "{", "spotifyURL", "+=", "\"", "\"", "+", "query", "\n", "}", "\n\n", "var", "p", "SimpleAlbumPage", "\n\n", "err", ":=", "c", ".", "get", "(", "spotifyURL", ",", "&", "p", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "&", "p", ",", "nil", "\n", "}" ]
// GetArtistAlbumsOpt is just like GetArtistAlbums, but it accepts optional // parameters used to filter and sort the result. // // The AlbumType argument can be used to find a particular type of album. Search // for multiple types by OR-ing the types together.
[ "GetArtistAlbumsOpt", "is", "just", "like", "GetArtistAlbums", "but", "it", "accepts", "optional", "parameters", "used", "to", "filter", "and", "sort", "the", "result", ".", "The", "AlbumType", "argument", "can", "be", "used", "to", "find", "a", "particular", "type", "of", "album", ".", "Search", "for", "multiple", "types", "by", "OR", "-", "ing", "the", "types", "together", "." ]
94cbe6dc5cc2eaa467e36f30b130b0f827e4262d
https://github.com/zmb3/spotify/blob/94cbe6dc5cc2eaa467e36f30b130b0f827e4262d/artist.go#L116-L152
9,076
zmb3/spotify
player.go
PlayerDevices
func (c *Client) PlayerDevices() ([]PlayerDevice, error) { var result struct { PlayerDevices []PlayerDevice `json:"devices"` } err := c.get(c.baseURL+"me/player/devices", &result) if err != nil { return nil, err } return result.PlayerDevices, nil }
go
func (c *Client) PlayerDevices() ([]PlayerDevice, error) { var result struct { PlayerDevices []PlayerDevice `json:"devices"` } err := c.get(c.baseURL+"me/player/devices", &result) if err != nil { return nil, err } return result.PlayerDevices, nil }
[ "func", "(", "c", "*", "Client", ")", "PlayerDevices", "(", ")", "(", "[", "]", "PlayerDevice", ",", "error", ")", "{", "var", "result", "struct", "{", "PlayerDevices", "[", "]", "PlayerDevice", "`json:\"devices\"`", "\n", "}", "\n\n", "err", ":=", "c", ".", "get", "(", "c", ".", "baseURL", "+", "\"", "\"", ",", "&", "result", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "result", ".", "PlayerDevices", ",", "nil", "\n", "}" ]
// PlayerDevices information about available devices for the current user. // // Requires the ScopeUserReadPlaybackState scope in order to read information
[ "PlayerDevices", "information", "about", "available", "devices", "for", "the", "current", "user", ".", "Requires", "the", "ScopeUserReadPlaybackState", "scope", "in", "order", "to", "read", "information" ]
94cbe6dc5cc2eaa467e36f30b130b0f827e4262d
https://github.com/zmb3/spotify/blob/94cbe6dc5cc2eaa467e36f30b130b0f827e4262d/player.go#L132-L143
9,077
zmb3/spotify
player.go
PlayerStateOpt
func (c *Client) PlayerStateOpt(opt *Options) (*PlayerState, error) { spotifyURL := c.baseURL + "me/player" if opt != nil { v := url.Values{} if opt.Country != nil { v.Set("market", *opt.Country) } if params := v.Encode(); params != "" { spotifyURL += "?" + params } } var result PlayerState err := c.get(spotifyURL, &result) if err != nil { return nil, err } return &result, nil }
go
func (c *Client) PlayerStateOpt(opt *Options) (*PlayerState, error) { spotifyURL := c.baseURL + "me/player" if opt != nil { v := url.Values{} if opt.Country != nil { v.Set("market", *opt.Country) } if params := v.Encode(); params != "" { spotifyURL += "?" + params } } var result PlayerState err := c.get(spotifyURL, &result) if err != nil { return nil, err } return &result, nil }
[ "func", "(", "c", "*", "Client", ")", "PlayerStateOpt", "(", "opt", "*", "Options", ")", "(", "*", "PlayerState", ",", "error", ")", "{", "spotifyURL", ":=", "c", ".", "baseURL", "+", "\"", "\"", "\n", "if", "opt", "!=", "nil", "{", "v", ":=", "url", ".", "Values", "{", "}", "\n", "if", "opt", ".", "Country", "!=", "nil", "{", "v", ".", "Set", "(", "\"", "\"", ",", "*", "opt", ".", "Country", ")", "\n", "}", "\n", "if", "params", ":=", "v", ".", "Encode", "(", ")", ";", "params", "!=", "\"", "\"", "{", "spotifyURL", "+=", "\"", "\"", "+", "params", "\n", "}", "\n", "}", "\n\n", "var", "result", "PlayerState", "\n\n", "err", ":=", "c", ".", "get", "(", "spotifyURL", ",", "&", "result", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "&", "result", ",", "nil", "\n", "}" ]
// PlayerStateOpt is like PlayerState, but it accepts additional // options for sorting and filtering the results.
[ "PlayerStateOpt", "is", "like", "PlayerState", "but", "it", "accepts", "additional", "options", "for", "sorting", "and", "filtering", "the", "results", "." ]
94cbe6dc5cc2eaa467e36f30b130b0f827e4262d
https://github.com/zmb3/spotify/blob/94cbe6dc5cc2eaa467e36f30b130b0f827e4262d/player.go#L154-L174
9,078
zmb3/spotify
player.go
PlayerCurrentlyPlayingOpt
func (c *Client) PlayerCurrentlyPlayingOpt(opt *Options) (*CurrentlyPlaying, error) { spotifyURL := c.baseURL + "me/player/currently-playing" if opt != nil { v := url.Values{} if opt.Country != nil { v.Set("market", *opt.Country) } if params := v.Encode(); params != "" { spotifyURL += "?" + params } } req, err := http.NewRequest("GET", spotifyURL, nil) if err != nil { return nil, err } var result CurrentlyPlaying err = c.execute(req, &result, http.StatusNoContent) if err != nil { return nil, err } return &result, nil }
go
func (c *Client) PlayerCurrentlyPlayingOpt(opt *Options) (*CurrentlyPlaying, error) { spotifyURL := c.baseURL + "me/player/currently-playing" if opt != nil { v := url.Values{} if opt.Country != nil { v.Set("market", *opt.Country) } if params := v.Encode(); params != "" { spotifyURL += "?" + params } } req, err := http.NewRequest("GET", spotifyURL, nil) if err != nil { return nil, err } var result CurrentlyPlaying err = c.execute(req, &result, http.StatusNoContent) if err != nil { return nil, err } return &result, nil }
[ "func", "(", "c", "*", "Client", ")", "PlayerCurrentlyPlayingOpt", "(", "opt", "*", "Options", ")", "(", "*", "CurrentlyPlaying", ",", "error", ")", "{", "spotifyURL", ":=", "c", ".", "baseURL", "+", "\"", "\"", "\n", "if", "opt", "!=", "nil", "{", "v", ":=", "url", ".", "Values", "{", "}", "\n", "if", "opt", ".", "Country", "!=", "nil", "{", "v", ".", "Set", "(", "\"", "\"", ",", "*", "opt", ".", "Country", ")", "\n", "}", "\n", "if", "params", ":=", "v", ".", "Encode", "(", ")", ";", "params", "!=", "\"", "\"", "{", "spotifyURL", "+=", "\"", "\"", "+", "params", "\n", "}", "\n", "}", "\n\n", "req", ",", "err", ":=", "http", ".", "NewRequest", "(", "\"", "\"", ",", "spotifyURL", ",", "nil", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "var", "result", "CurrentlyPlaying", "\n", "err", "=", "c", ".", "execute", "(", "req", ",", "&", "result", ",", "http", ".", "StatusNoContent", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "&", "result", ",", "nil", "\n", "}" ]
// PlayerCurrentlyPlayingOpt is like PlayerCurrentlyPlaying, but it accepts // additional options for sorting and filtering the results.
[ "PlayerCurrentlyPlayingOpt", "is", "like", "PlayerCurrentlyPlaying", "but", "it", "accepts", "additional", "options", "for", "sorting", "and", "filtering", "the", "results", "." ]
94cbe6dc5cc2eaa467e36f30b130b0f827e4262d
https://github.com/zmb3/spotify/blob/94cbe6dc5cc2eaa467e36f30b130b0f827e4262d/player.go#L187-L211
9,079
zmb3/spotify
player.go
PlayerRecentlyPlayedOpt
func (c *Client) PlayerRecentlyPlayedOpt(opt *RecentlyPlayedOptions) ([]RecentlyPlayedItem, error) { spotifyURL := c.baseURL + "me/player/recently-played" if opt != nil { v := url.Values{} if opt.Limit != 0 { v.Set("limit", strconv.FormatInt(int64(opt.Limit), 10)) } if opt.BeforeEpochMs != 0 { v.Set("before", strconv.FormatInt(int64(opt.BeforeEpochMs), 10)) } if opt.AfterEpochMs != 0 { v.Set("after", strconv.FormatInt(int64(opt.AfterEpochMs), 10)) } if params := v.Encode(); params != "" { spotifyURL += "?" + params } } result := RecentlyPlayedResult{} err := c.get(spotifyURL, &result) if err != nil { return nil, err } return result.Items, nil }
go
func (c *Client) PlayerRecentlyPlayedOpt(opt *RecentlyPlayedOptions) ([]RecentlyPlayedItem, error) { spotifyURL := c.baseURL + "me/player/recently-played" if opt != nil { v := url.Values{} if opt.Limit != 0 { v.Set("limit", strconv.FormatInt(int64(opt.Limit), 10)) } if opt.BeforeEpochMs != 0 { v.Set("before", strconv.FormatInt(int64(opt.BeforeEpochMs), 10)) } if opt.AfterEpochMs != 0 { v.Set("after", strconv.FormatInt(int64(opt.AfterEpochMs), 10)) } if params := v.Encode(); params != "" { spotifyURL += "?" + params } } result := RecentlyPlayedResult{} err := c.get(spotifyURL, &result) if err != nil { return nil, err } return result.Items, nil }
[ "func", "(", "c", "*", "Client", ")", "PlayerRecentlyPlayedOpt", "(", "opt", "*", "RecentlyPlayedOptions", ")", "(", "[", "]", "RecentlyPlayedItem", ",", "error", ")", "{", "spotifyURL", ":=", "c", ".", "baseURL", "+", "\"", "\"", "\n", "if", "opt", "!=", "nil", "{", "v", ":=", "url", ".", "Values", "{", "}", "\n", "if", "opt", ".", "Limit", "!=", "0", "{", "v", ".", "Set", "(", "\"", "\"", ",", "strconv", ".", "FormatInt", "(", "int64", "(", "opt", ".", "Limit", ")", ",", "10", ")", ")", "\n", "}", "\n", "if", "opt", ".", "BeforeEpochMs", "!=", "0", "{", "v", ".", "Set", "(", "\"", "\"", ",", "strconv", ".", "FormatInt", "(", "int64", "(", "opt", ".", "BeforeEpochMs", ")", ",", "10", ")", ")", "\n", "}", "\n", "if", "opt", ".", "AfterEpochMs", "!=", "0", "{", "v", ".", "Set", "(", "\"", "\"", ",", "strconv", ".", "FormatInt", "(", "int64", "(", "opt", ".", "AfterEpochMs", ")", ",", "10", ")", ")", "\n", "}", "\n", "if", "params", ":=", "v", ".", "Encode", "(", ")", ";", "params", "!=", "\"", "\"", "{", "spotifyURL", "+=", "\"", "\"", "+", "params", "\n", "}", "\n", "}", "\n\n", "result", ":=", "RecentlyPlayedResult", "{", "}", "\n", "err", ":=", "c", ".", "get", "(", "spotifyURL", ",", "&", "result", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "result", ".", "Items", ",", "nil", "\n", "}" ]
// PlayerRecentlyPlayedOpt is like PlayerRecentlyPlayed, but it accepts // additional options for sorting and filtering the results.
[ "PlayerRecentlyPlayedOpt", "is", "like", "PlayerRecentlyPlayed", "but", "it", "accepts", "additional", "options", "for", "sorting", "and", "filtering", "the", "results", "." ]
94cbe6dc5cc2eaa467e36f30b130b0f827e4262d
https://github.com/zmb3/spotify/blob/94cbe6dc5cc2eaa467e36f30b130b0f827e4262d/player.go#L221-L246
9,080
zmb3/spotify
player.go
TransferPlayback
func (c *Client) TransferPlayback(deviceID ID, play bool) error { reqData := struct { DeviceID []ID `json:"device_ids"` Play bool `json:"play"` }{ DeviceID: []ID{deviceID}, Play: play, } buf := new(bytes.Buffer) err := json.NewEncoder(buf).Encode(reqData) if err != nil { return err } req, err := http.NewRequest(http.MethodPut, c.baseURL+"me/player", buf) if err != nil { return err } err = c.execute(req, nil, http.StatusNoContent) if err != nil { return err } return nil }
go
func (c *Client) TransferPlayback(deviceID ID, play bool) error { reqData := struct { DeviceID []ID `json:"device_ids"` Play bool `json:"play"` }{ DeviceID: []ID{deviceID}, Play: play, } buf := new(bytes.Buffer) err := json.NewEncoder(buf).Encode(reqData) if err != nil { return err } req, err := http.NewRequest(http.MethodPut, c.baseURL+"me/player", buf) if err != nil { return err } err = c.execute(req, nil, http.StatusNoContent) if err != nil { return err } return nil }
[ "func", "(", "c", "*", "Client", ")", "TransferPlayback", "(", "deviceID", "ID", ",", "play", "bool", ")", "error", "{", "reqData", ":=", "struct", "{", "DeviceID", "[", "]", "ID", "`json:\"device_ids\"`", "\n", "Play", "bool", "`json:\"play\"`", "\n", "}", "{", "DeviceID", ":", "[", "]", "ID", "{", "deviceID", "}", ",", "Play", ":", "play", ",", "}", "\n\n", "buf", ":=", "new", "(", "bytes", ".", "Buffer", ")", "\n", "err", ":=", "json", ".", "NewEncoder", "(", "buf", ")", ".", "Encode", "(", "reqData", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "req", ",", "err", ":=", "http", ".", "NewRequest", "(", "http", ".", "MethodPut", ",", "c", ".", "baseURL", "+", "\"", "\"", ",", "buf", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "err", "=", "c", ".", "execute", "(", "req", ",", "nil", ",", "http", ".", "StatusNoContent", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// TransferPlayback transfers playback to a new device and determine if // it should start playing. // // Note that a value of false for the play parameter when also transferring // to another device_id will not pause playback. To ensure that playback is // paused on the new device you should send a pause command to the currently // active device before transferring to the new device_id. // // Requires the ScopeUserModifyPlaybackState in order to modify the player state
[ "TransferPlayback", "transfers", "playback", "to", "a", "new", "device", "and", "determine", "if", "it", "should", "start", "playing", ".", "Note", "that", "a", "value", "of", "false", "for", "the", "play", "parameter", "when", "also", "transferring", "to", "another", "device_id", "will", "not", "pause", "playback", ".", "To", "ensure", "that", "playback", "is", "paused", "on", "the", "new", "device", "you", "should", "send", "a", "pause", "command", "to", "the", "currently", "active", "device", "before", "transferring", "to", "the", "new", "device_id", ".", "Requires", "the", "ScopeUserModifyPlaybackState", "in", "order", "to", "modify", "the", "player", "state" ]
94cbe6dc5cc2eaa467e36f30b130b0f827e4262d
https://github.com/zmb3/spotify/blob/94cbe6dc5cc2eaa467e36f30b130b0f827e4262d/player.go#L257-L281
9,081
zmb3/spotify
player.go
PlayOpt
func (c *Client) PlayOpt(opt *PlayOptions) error { spotifyURL := c.baseURL + "me/player/play" buf := new(bytes.Buffer) if opt != nil { v := url.Values{} if opt.DeviceID != nil { v.Set("device_id", opt.DeviceID.String()) } if params := v.Encode(); params != "" { spotifyURL += "?" + params } err := json.NewEncoder(buf).Encode(opt) if err != nil { return err } } req, err := http.NewRequest(http.MethodPut, spotifyURL, buf) if err != nil { return err } err = c.execute(req, nil, http.StatusNoContent) if err != nil { return err } return nil }
go
func (c *Client) PlayOpt(opt *PlayOptions) error { spotifyURL := c.baseURL + "me/player/play" buf := new(bytes.Buffer) if opt != nil { v := url.Values{} if opt.DeviceID != nil { v.Set("device_id", opt.DeviceID.String()) } if params := v.Encode(); params != "" { spotifyURL += "?" + params } err := json.NewEncoder(buf).Encode(opt) if err != nil { return err } } req, err := http.NewRequest(http.MethodPut, spotifyURL, buf) if err != nil { return err } err = c.execute(req, nil, http.StatusNoContent) if err != nil { return err } return nil }
[ "func", "(", "c", "*", "Client", ")", "PlayOpt", "(", "opt", "*", "PlayOptions", ")", "error", "{", "spotifyURL", ":=", "c", ".", "baseURL", "+", "\"", "\"", "\n", "buf", ":=", "new", "(", "bytes", ".", "Buffer", ")", "\n\n", "if", "opt", "!=", "nil", "{", "v", ":=", "url", ".", "Values", "{", "}", "\n", "if", "opt", ".", "DeviceID", "!=", "nil", "{", "v", ".", "Set", "(", "\"", "\"", ",", "opt", ".", "DeviceID", ".", "String", "(", ")", ")", "\n", "}", "\n", "if", "params", ":=", "v", ".", "Encode", "(", ")", ";", "params", "!=", "\"", "\"", "{", "spotifyURL", "+=", "\"", "\"", "+", "params", "\n", "}", "\n\n", "err", ":=", "json", ".", "NewEncoder", "(", "buf", ")", ".", "Encode", "(", "opt", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n", "req", ",", "err", ":=", "http", ".", "NewRequest", "(", "http", ".", "MethodPut", ",", "spotifyURL", ",", "buf", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "err", "=", "c", ".", "execute", "(", "req", ",", "nil", ",", "http", ".", "StatusNoContent", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// PlayOpt is like Play but with more options
[ "PlayOpt", "is", "like", "Play", "but", "with", "more", "options" ]
94cbe6dc5cc2eaa467e36f30b130b0f827e4262d
https://github.com/zmb3/spotify/blob/94cbe6dc5cc2eaa467e36f30b130b0f827e4262d/player.go#L290-L317
9,082
zmb3/spotify
player.go
PauseOpt
func (c *Client) PauseOpt(opt *PlayOptions) error { spotifyURL := c.baseURL + "me/player/pause" if opt != nil { v := url.Values{} if opt.DeviceID != nil { v.Set("device_id", opt.DeviceID.String()) } if params := v.Encode(); params != "" { spotifyURL += "?" + params } } req, err := http.NewRequest(http.MethodPut, spotifyURL, nil) if err != nil { return err } err = c.execute(req, nil, http.StatusNoContent) if err != nil { return err } return nil }
go
func (c *Client) PauseOpt(opt *PlayOptions) error { spotifyURL := c.baseURL + "me/player/pause" if opt != nil { v := url.Values{} if opt.DeviceID != nil { v.Set("device_id", opt.DeviceID.String()) } if params := v.Encode(); params != "" { spotifyURL += "?" + params } } req, err := http.NewRequest(http.MethodPut, spotifyURL, nil) if err != nil { return err } err = c.execute(req, nil, http.StatusNoContent) if err != nil { return err } return nil }
[ "func", "(", "c", "*", "Client", ")", "PauseOpt", "(", "opt", "*", "PlayOptions", ")", "error", "{", "spotifyURL", ":=", "c", ".", "baseURL", "+", "\"", "\"", "\n\n", "if", "opt", "!=", "nil", "{", "v", ":=", "url", ".", "Values", "{", "}", "\n", "if", "opt", ".", "DeviceID", "!=", "nil", "{", "v", ".", "Set", "(", "\"", "\"", ",", "opt", ".", "DeviceID", ".", "String", "(", ")", ")", "\n", "}", "\n", "if", "params", ":=", "v", ".", "Encode", "(", ")", ";", "params", "!=", "\"", "\"", "{", "spotifyURL", "+=", "\"", "\"", "+", "params", "\n", "}", "\n", "}", "\n", "req", ",", "err", ":=", "http", ".", "NewRequest", "(", "http", ".", "MethodPut", ",", "spotifyURL", ",", "nil", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "err", "=", "c", ".", "execute", "(", "req", ",", "nil", ",", "http", ".", "StatusNoContent", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// PauseOpt is like Pause but with more options // // Only expects PlayOptions.DeviceID, all other options will be ignored
[ "PauseOpt", "is", "like", "Pause", "but", "with", "more", "options", "Only", "expects", "PlayOptions", ".", "DeviceID", "all", "other", "options", "will", "be", "ignored" ]
94cbe6dc5cc2eaa467e36f30b130b0f827e4262d
https://github.com/zmb3/spotify/blob/94cbe6dc5cc2eaa467e36f30b130b0f827e4262d/player.go#L329-L350
9,083
zmb3/spotify
player.go
SeekOpt
func (c *Client) SeekOpt(position int, opt *PlayOptions) error { return c.playerFuncWithOpt( "me/player/seek", url.Values{ "position_ms": []string{strconv.FormatInt(int64(position), 10)}, }, opt, ) }
go
func (c *Client) SeekOpt(position int, opt *PlayOptions) error { return c.playerFuncWithOpt( "me/player/seek", url.Values{ "position_ms": []string{strconv.FormatInt(int64(position), 10)}, }, opt, ) }
[ "func", "(", "c", "*", "Client", ")", "SeekOpt", "(", "position", "int", ",", "opt", "*", "PlayOptions", ")", "error", "{", "return", "c", ".", "playerFuncWithOpt", "(", "\"", "\"", ",", "url", ".", "Values", "{", "\"", "\"", ":", "[", "]", "string", "{", "strconv", ".", "FormatInt", "(", "int64", "(", "position", ")", ",", "10", ")", "}", ",", "}", ",", "opt", ",", ")", "\n", "}" ]
// SeekOpt is like Seek but with more options // // Only expects PlayOptions.DeviceID, all other options will be ignored
[ "SeekOpt", "is", "like", "Seek", "but", "with", "more", "options", "Only", "expects", "PlayOptions", ".", "DeviceID", "all", "other", "options", "will", "be", "ignored" ]
94cbe6dc5cc2eaa467e36f30b130b0f827e4262d
https://github.com/zmb3/spotify/blob/94cbe6dc5cc2eaa467e36f30b130b0f827e4262d/player.go#L432-L440
9,084
zmb3/spotify
player.go
Repeat
func (c *Client) Repeat(state string) error { return c.RepeatOpt(state, nil) }
go
func (c *Client) Repeat(state string) error { return c.RepeatOpt(state, nil) }
[ "func", "(", "c", "*", "Client", ")", "Repeat", "(", "state", "string", ")", "error", "{", "return", "c", ".", "RepeatOpt", "(", "state", ",", "nil", ")", "\n", "}" ]
// Repeat Set the repeat mode for the user's playback. // // Options are repeat-track, repeat-context, and off. // // Requires the ScopeUserModifyPlaybackState in order to modify the player state.
[ "Repeat", "Set", "the", "repeat", "mode", "for", "the", "user", "s", "playback", ".", "Options", "are", "repeat", "-", "track", "repeat", "-", "context", "and", "off", ".", "Requires", "the", "ScopeUserModifyPlaybackState", "in", "order", "to", "modify", "the", "player", "state", "." ]
94cbe6dc5cc2eaa467e36f30b130b0f827e4262d
https://github.com/zmb3/spotify/blob/94cbe6dc5cc2eaa467e36f30b130b0f827e4262d/player.go#L447-L449
9,085
zmb3/spotify
player.go
RepeatOpt
func (c *Client) RepeatOpt(state string, opt *PlayOptions) error { return c.playerFuncWithOpt( "me/player/repeat", url.Values{ "state": []string{state}, }, opt, ) }
go
func (c *Client) RepeatOpt(state string, opt *PlayOptions) error { return c.playerFuncWithOpt( "me/player/repeat", url.Values{ "state": []string{state}, }, opt, ) }
[ "func", "(", "c", "*", "Client", ")", "RepeatOpt", "(", "state", "string", ",", "opt", "*", "PlayOptions", ")", "error", "{", "return", "c", ".", "playerFuncWithOpt", "(", "\"", "\"", ",", "url", ".", "Values", "{", "\"", "\"", ":", "[", "]", "string", "{", "state", "}", ",", "}", ",", "opt", ",", ")", "\n", "}" ]
// RepeatOpt is like Repeat but with more options // // Only expects PlayOptions.DeviceID, all other options will be ignored.
[ "RepeatOpt", "is", "like", "Repeat", "but", "with", "more", "options", "Only", "expects", "PlayOptions", ".", "DeviceID", "all", "other", "options", "will", "be", "ignored", "." ]
94cbe6dc5cc2eaa467e36f30b130b0f827e4262d
https://github.com/zmb3/spotify/blob/94cbe6dc5cc2eaa467e36f30b130b0f827e4262d/player.go#L454-L462
9,086
zmb3/spotify
player.go
Volume
func (c *Client) Volume(percent int) error { return c.VolumeOpt(percent, nil) }
go
func (c *Client) Volume(percent int) error { return c.VolumeOpt(percent, nil) }
[ "func", "(", "c", "*", "Client", ")", "Volume", "(", "percent", "int", ")", "error", "{", "return", "c", ".", "VolumeOpt", "(", "percent", ",", "nil", ")", "\n", "}" ]
// Volume set the volume for the user's current playback device. // // Percent is must be a value from 0 to 100 inclusive. // // Requires the ScopeUserModifyPlaybackState in order to modify the player state
[ "Volume", "set", "the", "volume", "for", "the", "user", "s", "current", "playback", "device", ".", "Percent", "is", "must", "be", "a", "value", "from", "0", "to", "100", "inclusive", ".", "Requires", "the", "ScopeUserModifyPlaybackState", "in", "order", "to", "modify", "the", "player", "state" ]
94cbe6dc5cc2eaa467e36f30b130b0f827e4262d
https://github.com/zmb3/spotify/blob/94cbe6dc5cc2eaa467e36f30b130b0f827e4262d/player.go#L469-L471
9,087
zmb3/spotify
player.go
VolumeOpt
func (c *Client) VolumeOpt(percent int, opt *PlayOptions) error { return c.playerFuncWithOpt( "me/player/volume", url.Values{ "volume_percent": []string{strconv.FormatInt(int64(percent), 10)}, }, opt, ) }
go
func (c *Client) VolumeOpt(percent int, opt *PlayOptions) error { return c.playerFuncWithOpt( "me/player/volume", url.Values{ "volume_percent": []string{strconv.FormatInt(int64(percent), 10)}, }, opt, ) }
[ "func", "(", "c", "*", "Client", ")", "VolumeOpt", "(", "percent", "int", ",", "opt", "*", "PlayOptions", ")", "error", "{", "return", "c", ".", "playerFuncWithOpt", "(", "\"", "\"", ",", "url", ".", "Values", "{", "\"", "\"", ":", "[", "]", "string", "{", "strconv", ".", "FormatInt", "(", "int64", "(", "percent", ")", ",", "10", ")", "}", ",", "}", ",", "opt", ",", ")", "\n", "}" ]
// VolumeOpt is like Volume but with more options // // Only expects PlayOptions.DeviceID, all other options will be ignored
[ "VolumeOpt", "is", "like", "Volume", "but", "with", "more", "options", "Only", "expects", "PlayOptions", ".", "DeviceID", "all", "other", "options", "will", "be", "ignored" ]
94cbe6dc5cc2eaa467e36f30b130b0f827e4262d
https://github.com/zmb3/spotify/blob/94cbe6dc5cc2eaa467e36f30b130b0f827e4262d/player.go#L476-L484
9,088
zmb3/spotify
player.go
Shuffle
func (c *Client) Shuffle(shuffle bool) error { return c.ShuffleOpt(shuffle, nil) }
go
func (c *Client) Shuffle(shuffle bool) error { return c.ShuffleOpt(shuffle, nil) }
[ "func", "(", "c", "*", "Client", ")", "Shuffle", "(", "shuffle", "bool", ")", "error", "{", "return", "c", ".", "ShuffleOpt", "(", "shuffle", ",", "nil", ")", "\n", "}" ]
// Shuffle switches shuffle on or off for user's playback. // // Requires the ScopeUserModifyPlaybackState in order to modify the player state
[ "Shuffle", "switches", "shuffle", "on", "or", "off", "for", "user", "s", "playback", ".", "Requires", "the", "ScopeUserModifyPlaybackState", "in", "order", "to", "modify", "the", "player", "state" ]
94cbe6dc5cc2eaa467e36f30b130b0f827e4262d
https://github.com/zmb3/spotify/blob/94cbe6dc5cc2eaa467e36f30b130b0f827e4262d/player.go#L489-L491
9,089
zmb3/spotify
player.go
ShuffleOpt
func (c *Client) ShuffleOpt(shuffle bool, opt *PlayOptions) error { return c.playerFuncWithOpt( "me/player/shuffle", url.Values{ "state": []string{strconv.FormatBool(shuffle)}, }, opt, ) }
go
func (c *Client) ShuffleOpt(shuffle bool, opt *PlayOptions) error { return c.playerFuncWithOpt( "me/player/shuffle", url.Values{ "state": []string{strconv.FormatBool(shuffle)}, }, opt, ) }
[ "func", "(", "c", "*", "Client", ")", "ShuffleOpt", "(", "shuffle", "bool", ",", "opt", "*", "PlayOptions", ")", "error", "{", "return", "c", ".", "playerFuncWithOpt", "(", "\"", "\"", ",", "url", ".", "Values", "{", "\"", "\"", ":", "[", "]", "string", "{", "strconv", ".", "FormatBool", "(", "shuffle", ")", "}", ",", "}", ",", "opt", ",", ")", "\n", "}" ]
// ShuffleOpt is like Shuffle but with more options // // Only expects PlayOptions.DeviceID, all other options will be ignored
[ "ShuffleOpt", "is", "like", "Shuffle", "but", "with", "more", "options", "Only", "expects", "PlayOptions", ".", "DeviceID", "all", "other", "options", "will", "be", "ignored" ]
94cbe6dc5cc2eaa467e36f30b130b0f827e4262d
https://github.com/zmb3/spotify/blob/94cbe6dc5cc2eaa467e36f30b130b0f827e4262d/player.go#L496-L504
9,090
zmb3/spotify
library.go
AddTracksToLibrary
func (c *Client) AddTracksToLibrary(ids ...ID) error { return c.modifyLibraryTracks(true, ids...) }
go
func (c *Client) AddTracksToLibrary(ids ...ID) error { return c.modifyLibraryTracks(true, ids...) }
[ "func", "(", "c", "*", "Client", ")", "AddTracksToLibrary", "(", "ids", "...", "ID", ")", "error", "{", "return", "c", ".", "modifyLibraryTracks", "(", "true", ",", "ids", "...", ")", "\n", "}" ]
// AddTracksToLibrary saves one or more tracks to the current user's // "Your Music" library. This call requires the ScopeUserLibraryModify scope. // A track can only be saved once; duplicate IDs are ignored.
[ "AddTracksToLibrary", "saves", "one", "or", "more", "tracks", "to", "the", "current", "user", "s", "Your", "Music", "library", ".", "This", "call", "requires", "the", "ScopeUserLibraryModify", "scope", ".", "A", "track", "can", "only", "be", "saved", "once", ";", "duplicate", "IDs", "are", "ignored", "." ]
94cbe6dc5cc2eaa467e36f30b130b0f827e4262d
https://github.com/zmb3/spotify/blob/94cbe6dc5cc2eaa467e36f30b130b0f827e4262d/library.go#L31-L33
9,091
zmb3/spotify
library.go
RemoveTracksFromLibrary
func (c *Client) RemoveTracksFromLibrary(ids ...ID) error { return c.modifyLibraryTracks(false, ids...) }
go
func (c *Client) RemoveTracksFromLibrary(ids ...ID) error { return c.modifyLibraryTracks(false, ids...) }
[ "func", "(", "c", "*", "Client", ")", "RemoveTracksFromLibrary", "(", "ids", "...", "ID", ")", "error", "{", "return", "c", ".", "modifyLibraryTracks", "(", "false", ",", "ids", "...", ")", "\n", "}" ]
// RemoveTracksFromLibrary removes one or more tracks from the current user's // "Your Music" library. This call requires the ScopeUserModifyLibrary scope. // Trying to remove a track when you do not have the user's authorization // results in a `spotify.Error` with the status code set to http.StatusUnauthorized.
[ "RemoveTracksFromLibrary", "removes", "one", "or", "more", "tracks", "from", "the", "current", "user", "s", "Your", "Music", "library", ".", "This", "call", "requires", "the", "ScopeUserModifyLibrary", "scope", ".", "Trying", "to", "remove", "a", "track", "when", "you", "do", "not", "have", "the", "user", "s", "authorization", "results", "in", "a", "spotify", ".", "Error", "with", "the", "status", "code", "set", "to", "http", ".", "StatusUnauthorized", "." ]
94cbe6dc5cc2eaa467e36f30b130b0f827e4262d
https://github.com/zmb3/spotify/blob/94cbe6dc5cc2eaa467e36f30b130b0f827e4262d/library.go#L39-L41
9,092
zmb3/spotify
category.go
GetCategoryPlaylists
func (c *Client) GetCategoryPlaylists(catID string) (*SimplePlaylistPage, error) { return c.GetCategoryPlaylistsOpt(catID, nil) }
go
func (c *Client) GetCategoryPlaylists(catID string) (*SimplePlaylistPage, error) { return c.GetCategoryPlaylistsOpt(catID, nil) }
[ "func", "(", "c", "*", "Client", ")", "GetCategoryPlaylists", "(", "catID", "string", ")", "(", "*", "SimplePlaylistPage", ",", "error", ")", "{", "return", "c", ".", "GetCategoryPlaylistsOpt", "(", "catID", ",", "nil", ")", "\n", "}" ]
// GetCategoryPlaylists gets a list of Spotify playlists tagged with a paricular category.
[ "GetCategoryPlaylists", "gets", "a", "list", "of", "Spotify", "playlists", "tagged", "with", "a", "paricular", "category", "." ]
94cbe6dc5cc2eaa467e36f30b130b0f827e4262d
https://github.com/zmb3/spotify/blob/94cbe6dc5cc2eaa467e36f30b130b0f827e4262d/category.go#L61-L63
9,093
zmb3/spotify
category.go
GetCategoryPlaylistsOpt
func (c *Client) GetCategoryPlaylistsOpt(catID string, opt *Options) (*SimplePlaylistPage, error) { spotifyURL := fmt.Sprintf("%sbrowse/categories/%s/playlists", c.baseURL, catID) if opt != nil { values := url.Values{} if opt.Country != nil { values.Set("country", *opt.Country) } if opt.Limit != nil { values.Set("limit", strconv.Itoa(*opt.Limit)) } if opt.Offset != nil { values.Set("offset", strconv.Itoa(*opt.Offset)) } if query := values.Encode(); query != "" { spotifyURL += "?" + query } } wrapper := struct { Playlists SimplePlaylistPage `json:"playlists"` }{} err := c.get(spotifyURL, &wrapper) if err != nil { return nil, err } return &wrapper.Playlists, nil }
go
func (c *Client) GetCategoryPlaylistsOpt(catID string, opt *Options) (*SimplePlaylistPage, error) { spotifyURL := fmt.Sprintf("%sbrowse/categories/%s/playlists", c.baseURL, catID) if opt != nil { values := url.Values{} if opt.Country != nil { values.Set("country", *opt.Country) } if opt.Limit != nil { values.Set("limit", strconv.Itoa(*opt.Limit)) } if opt.Offset != nil { values.Set("offset", strconv.Itoa(*opt.Offset)) } if query := values.Encode(); query != "" { spotifyURL += "?" + query } } wrapper := struct { Playlists SimplePlaylistPage `json:"playlists"` }{} err := c.get(spotifyURL, &wrapper) if err != nil { return nil, err } return &wrapper.Playlists, nil }
[ "func", "(", "c", "*", "Client", ")", "GetCategoryPlaylistsOpt", "(", "catID", "string", ",", "opt", "*", "Options", ")", "(", "*", "SimplePlaylistPage", ",", "error", ")", "{", "spotifyURL", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "c", ".", "baseURL", ",", "catID", ")", "\n", "if", "opt", "!=", "nil", "{", "values", ":=", "url", ".", "Values", "{", "}", "\n", "if", "opt", ".", "Country", "!=", "nil", "{", "values", ".", "Set", "(", "\"", "\"", ",", "*", "opt", ".", "Country", ")", "\n", "}", "\n", "if", "opt", ".", "Limit", "!=", "nil", "{", "values", ".", "Set", "(", "\"", "\"", ",", "strconv", ".", "Itoa", "(", "*", "opt", ".", "Limit", ")", ")", "\n", "}", "\n", "if", "opt", ".", "Offset", "!=", "nil", "{", "values", ".", "Set", "(", "\"", "\"", ",", "strconv", ".", "Itoa", "(", "*", "opt", ".", "Offset", ")", ")", "\n", "}", "\n", "if", "query", ":=", "values", ".", "Encode", "(", ")", ";", "query", "!=", "\"", "\"", "{", "spotifyURL", "+=", "\"", "\"", "+", "query", "\n", "}", "\n", "}", "\n\n", "wrapper", ":=", "struct", "{", "Playlists", "SimplePlaylistPage", "`json:\"playlists\"`", "\n", "}", "{", "}", "\n\n", "err", ":=", "c", ".", "get", "(", "spotifyURL", ",", "&", "wrapper", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "&", "wrapper", ".", "Playlists", ",", "nil", "\n", "}" ]
// GetCategoryPlaylistsOpt is like GetCategoryPlaylists, but it accepts optional // arguments.
[ "GetCategoryPlaylistsOpt", "is", "like", "GetCategoryPlaylists", "but", "it", "accepts", "optional", "arguments", "." ]
94cbe6dc5cc2eaa467e36f30b130b0f827e4262d
https://github.com/zmb3/spotify/blob/94cbe6dc5cc2eaa467e36f30b130b0f827e4262d/category.go#L67-L95
9,094
zmb3/spotify
track_attributes.go
MaxAcousticness
func (ta *TrackAttributes) MaxAcousticness(acousticness float64) *TrackAttributes { ta.floatAttributes["max_acousticness"] = acousticness return ta }
go
func (ta *TrackAttributes) MaxAcousticness(acousticness float64) *TrackAttributes { ta.floatAttributes["max_acousticness"] = acousticness return ta }
[ "func", "(", "ta", "*", "TrackAttributes", ")", "MaxAcousticness", "(", "acousticness", "float64", ")", "*", "TrackAttributes", "{", "ta", ".", "floatAttributes", "[", "\"", "\"", "]", "=", "acousticness", "\n", "return", "ta", "\n", "}" ]
// MaxAcousticness sets the maximum acousticness // Acousticness is a confidence measure from 0.0 to 1.0 of whether // the track is acoustic. A value of 1.0 represents high confidence // that the track is acoustic.
[ "MaxAcousticness", "sets", "the", "maximum", "acousticness", "Acousticness", "is", "a", "confidence", "measure", "from", "0", ".", "0", "to", "1", ".", "0", "of", "whether", "the", "track", "is", "acoustic", ".", "A", "value", "of", "1", ".", "0", "represents", "high", "confidence", "that", "the", "track", "is", "acoustic", "." ]
94cbe6dc5cc2eaa467e36f30b130b0f827e4262d
https://github.com/zmb3/spotify/blob/94cbe6dc5cc2eaa467e36f30b130b0f827e4262d/track_attributes.go#L38-L41
9,095
zmb3/spotify
track_attributes.go
MinAcousticness
func (ta *TrackAttributes) MinAcousticness(acousticness float64) *TrackAttributes { ta.floatAttributes["min_acousticness"] = acousticness return ta }
go
func (ta *TrackAttributes) MinAcousticness(acousticness float64) *TrackAttributes { ta.floatAttributes["min_acousticness"] = acousticness return ta }
[ "func", "(", "ta", "*", "TrackAttributes", ")", "MinAcousticness", "(", "acousticness", "float64", ")", "*", "TrackAttributes", "{", "ta", ".", "floatAttributes", "[", "\"", "\"", "]", "=", "acousticness", "\n", "return", "ta", "\n", "}" ]
// MinAcousticness sets the minimum acousticness // Acousticness is a confidence measure from 0.0 to 1.0 of whether // the track is acoustic. A value of 1.0 represents high confidence // that the track is acoustic.
[ "MinAcousticness", "sets", "the", "minimum", "acousticness", "Acousticness", "is", "a", "confidence", "measure", "from", "0", ".", "0", "to", "1", ".", "0", "of", "whether", "the", "track", "is", "acoustic", ".", "A", "value", "of", "1", ".", "0", "represents", "high", "confidence", "that", "the", "track", "is", "acoustic", "." ]
94cbe6dc5cc2eaa467e36f30b130b0f827e4262d
https://github.com/zmb3/spotify/blob/94cbe6dc5cc2eaa467e36f30b130b0f827e4262d/track_attributes.go#L47-L50
9,096
zmb3/spotify
track_attributes.go
TargetAcousticness
func (ta *TrackAttributes) TargetAcousticness(acousticness float64) *TrackAttributes { ta.floatAttributes["target_acousticness"] = acousticness return ta }
go
func (ta *TrackAttributes) TargetAcousticness(acousticness float64) *TrackAttributes { ta.floatAttributes["target_acousticness"] = acousticness return ta }
[ "func", "(", "ta", "*", "TrackAttributes", ")", "TargetAcousticness", "(", "acousticness", "float64", ")", "*", "TrackAttributes", "{", "ta", ".", "floatAttributes", "[", "\"", "\"", "]", "=", "acousticness", "\n", "return", "ta", "\n", "}" ]
// TargetAcousticness sets the target acousticness // Acousticness is a confidence measure from 0.0 to 1.0 of whether // the track is acoustic. A value of 1.0 represents high confidence // that the track is acoustic.
[ "TargetAcousticness", "sets", "the", "target", "acousticness", "Acousticness", "is", "a", "confidence", "measure", "from", "0", ".", "0", "to", "1", ".", "0", "of", "whether", "the", "track", "is", "acoustic", ".", "A", "value", "of", "1", ".", "0", "represents", "high", "confidence", "that", "the", "track", "is", "acoustic", "." ]
94cbe6dc5cc2eaa467e36f30b130b0f827e4262d
https://github.com/zmb3/spotify/blob/94cbe6dc5cc2eaa467e36f30b130b0f827e4262d/track_attributes.go#L56-L59
9,097
zmb3/spotify
track_attributes.go
MaxDanceability
func (ta *TrackAttributes) MaxDanceability(danceability float64) *TrackAttributes { ta.floatAttributes["max_danceability"] = danceability return ta }
go
func (ta *TrackAttributes) MaxDanceability(danceability float64) *TrackAttributes { ta.floatAttributes["max_danceability"] = danceability return ta }
[ "func", "(", "ta", "*", "TrackAttributes", ")", "MaxDanceability", "(", "danceability", "float64", ")", "*", "TrackAttributes", "{", "ta", ".", "floatAttributes", "[", "\"", "\"", "]", "=", "danceability", "\n", "return", "ta", "\n", "}" ]
// MaxDanceability sets the maximum danceability // Danceability describes how suitable a track is for dancing based on // a combination of musical elements including tempo, rhythm stability, // beat strength, and overall regularity. // A value of 0.0 is least danceable and 1.0 is most danceable.
[ "MaxDanceability", "sets", "the", "maximum", "danceability", "Danceability", "describes", "how", "suitable", "a", "track", "is", "for", "dancing", "based", "on", "a", "combination", "of", "musical", "elements", "including", "tempo", "rhythm", "stability", "beat", "strength", "and", "overall", "regularity", ".", "A", "value", "of", "0", ".", "0", "is", "least", "danceable", "and", "1", ".", "0", "is", "most", "danceable", "." ]
94cbe6dc5cc2eaa467e36f30b130b0f827e4262d
https://github.com/zmb3/spotify/blob/94cbe6dc5cc2eaa467e36f30b130b0f827e4262d/track_attributes.go#L66-L69
9,098
zmb3/spotify
track_attributes.go
MinDanceability
func (ta *TrackAttributes) MinDanceability(danceability float64) *TrackAttributes { ta.floatAttributes["min_danceability"] = danceability return ta }
go
func (ta *TrackAttributes) MinDanceability(danceability float64) *TrackAttributes { ta.floatAttributes["min_danceability"] = danceability return ta }
[ "func", "(", "ta", "*", "TrackAttributes", ")", "MinDanceability", "(", "danceability", "float64", ")", "*", "TrackAttributes", "{", "ta", ".", "floatAttributes", "[", "\"", "\"", "]", "=", "danceability", "\n", "return", "ta", "\n", "}" ]
// MinDanceability sets the minimum danceability // Danceability describes how suitable a track is for dancing based on // a combination of musical elements including tempo, rhythm stability, // beat strength, and overall regularity. // A value of 0.0 is least danceable and 1.0 is most danceable.
[ "MinDanceability", "sets", "the", "minimum", "danceability", "Danceability", "describes", "how", "suitable", "a", "track", "is", "for", "dancing", "based", "on", "a", "combination", "of", "musical", "elements", "including", "tempo", "rhythm", "stability", "beat", "strength", "and", "overall", "regularity", ".", "A", "value", "of", "0", ".", "0", "is", "least", "danceable", "and", "1", ".", "0", "is", "most", "danceable", "." ]
94cbe6dc5cc2eaa467e36f30b130b0f827e4262d
https://github.com/zmb3/spotify/blob/94cbe6dc5cc2eaa467e36f30b130b0f827e4262d/track_attributes.go#L76-L79
9,099
zmb3/spotify
track_attributes.go
TargetDanceability
func (ta *TrackAttributes) TargetDanceability(danceability float64) *TrackAttributes { ta.floatAttributes["target_danceability"] = danceability return ta }
go
func (ta *TrackAttributes) TargetDanceability(danceability float64) *TrackAttributes { ta.floatAttributes["target_danceability"] = danceability return ta }
[ "func", "(", "ta", "*", "TrackAttributes", ")", "TargetDanceability", "(", "danceability", "float64", ")", "*", "TrackAttributes", "{", "ta", ".", "floatAttributes", "[", "\"", "\"", "]", "=", "danceability", "\n", "return", "ta", "\n", "}" ]
// TargetDanceability sets the target danceability // Danceability describes how suitable a track is for dancing based on // a combination of musical elements including tempo, rhythm stability, // beat strength, and overall regularity. // A value of 0.0 is least danceable and 1.0 is most danceable.
[ "TargetDanceability", "sets", "the", "target", "danceability", "Danceability", "describes", "how", "suitable", "a", "track", "is", "for", "dancing", "based", "on", "a", "combination", "of", "musical", "elements", "including", "tempo", "rhythm", "stability", "beat", "strength", "and", "overall", "regularity", ".", "A", "value", "of", "0", ".", "0", "is", "least", "danceable", "and", "1", ".", "0", "is", "most", "danceable", "." ]
94cbe6dc5cc2eaa467e36f30b130b0f827e4262d
https://github.com/zmb3/spotify/blob/94cbe6dc5cc2eaa467e36f30b130b0f827e4262d/track_attributes.go#L86-L89