repo
stringlengths
5
67
path
stringlengths
4
218
func_name
stringlengths
0
151
original_string
stringlengths
52
373k
language
stringclasses
6 values
code
stringlengths
52
373k
code_tokens
listlengths
10
512
docstring
stringlengths
3
47.2k
docstring_tokens
listlengths
3
234
sha
stringlengths
40
40
url
stringlengths
85
339
partition
stringclasses
3 values
profitbricks/profitbricks-sdk-go
server.go
GetAttachedCdrom
func (c *Client) GetAttachedCdrom(dcid, srvid, cdid string) (*Image, error) { url := serverCdromPath(dcid, srvid, cdid) // + `?depth=` + c.client.depth + `&pretty=` + strconv.FormatBool(c.client.pretty) ret := &Image{} err := c.client.Get(url, ret, http.StatusOK) return ret, err }
go
func (c *Client) GetAttachedCdrom(dcid, srvid, cdid string) (*Image, error) { url := serverCdromPath(dcid, srvid, cdid) // + `?depth=` + c.client.depth + `&pretty=` + strconv.FormatBool(c.client.pretty) ret := &Image{} err := c.client.Get(url, ret, http.StatusOK) return ret, err }
[ "func", "(", "c", "*", "Client", ")", "GetAttachedCdrom", "(", "dcid", ",", "srvid", ",", "cdid", "string", ")", "(", "*", "Image", ",", "error", ")", "{", "url", ":=", "serverCdromPath", "(", "dcid", ",", "srvid", ",", "cdid", ")", "\n", "ret", ":=", "&", "Image", "{", "}", "\n", "err", ":=", "c", ".", "client", ".", "Get", "(", "url", ",", "ret", ",", "http", ".", "StatusOK", ")", "\n", "return", "ret", ",", "err", "\n", "}" ]
//GetAttachedCdrom gets attached cd roms
[ "GetAttachedCdrom", "gets", "attached", "cd", "roms" ]
1d2db5f00bf5dd0b6c29273541c71c60cdf4d4d4
https://github.com/profitbricks/profitbricks-sdk-go/blob/1d2db5f00bf5dd0b6c29273541c71c60cdf4d4d4/server.go#L120-L125
test
profitbricks/profitbricks-sdk-go
server.go
DetachCdrom
func (c *Client) DetachCdrom(dcid, srvid, cdid string) (*http.Header, error) { url := serverCdromPath(dcid, srvid, cdid) + `?depth=` + c.client.depth + `&pretty=` + strconv.FormatBool(c.client.pretty) ret := &http.Header{} err := c.client.Delete(url, ret, http.StatusAccepted) return ret, err }
go
func (c *Client) DetachCdrom(dcid, srvid, cdid string) (*http.Header, error) { url := serverCdromPath(dcid, srvid, cdid) + `?depth=` + c.client.depth + `&pretty=` + strconv.FormatBool(c.client.pretty) ret := &http.Header{} err := c.client.Delete(url, ret, http.StatusAccepted) return ret, err }
[ "func", "(", "c", "*", "Client", ")", "DetachCdrom", "(", "dcid", ",", "srvid", ",", "cdid", "string", ")", "(", "*", "http", ".", "Header", ",", "error", ")", "{", "url", ":=", "serverCdromPath", "(", "dcid", ",", "srvid", ",", "cdid", ")", "+", "`?depth=`", "+", "c", ".", "client", ".", "depth", "+", "`&pretty=`", "+", "strconv", ".", "FormatBool", "(", "c", ".", "client", ".", "pretty", ")", "\n", "ret", ":=", "&", "http", ".", "Header", "{", "}", "\n", "err", ":=", "c", ".", "client", ".", "Delete", "(", "url", ",", "ret", ",", "http", ".", "StatusAccepted", ")", "\n", "return", "ret", ",", "err", "\n", "}" ]
//DetachCdrom detaches a CD rom
[ "DetachCdrom", "detaches", "a", "CD", "rom" ]
1d2db5f00bf5dd0b6c29273541c71c60cdf4d4d4
https://github.com/profitbricks/profitbricks-sdk-go/blob/1d2db5f00bf5dd0b6c29273541c71c60cdf4d4d4/server.go#L128-L133
test
profitbricks/profitbricks-sdk-go
server.go
ListAttachedVolumes
func (c *Client) ListAttachedVolumes(dcid, srvid string) (*Volumes, error) { url := serverVolumeColPath(dcid, srvid) + `?depth=` + c.client.depth + `&pretty=` + strconv.FormatBool(c.client.pretty) ret := &Volumes{} err := c.client.Get(url, ret, http.StatusOK) return ret, err }
go
func (c *Client) ListAttachedVolumes(dcid, srvid string) (*Volumes, error) { url := serverVolumeColPath(dcid, srvid) + `?depth=` + c.client.depth + `&pretty=` + strconv.FormatBool(c.client.pretty) ret := &Volumes{} err := c.client.Get(url, ret, http.StatusOK) return ret, err }
[ "func", "(", "c", "*", "Client", ")", "ListAttachedVolumes", "(", "dcid", ",", "srvid", "string", ")", "(", "*", "Volumes", ",", "error", ")", "{", "url", ":=", "serverVolumeColPath", "(", "dcid", ",", "srvid", ")", "+", "`?depth=`", "+", "c", ".", "client", ".", "depth", "+", "`&pretty=`", "+", "strconv", ".", "FormatBool", "(", "c", ".", "client", ".", "pretty", ")", "\n", "ret", ":=", "&", "Volumes", "{", "}", "\n", "err", ":=", "c", ".", "client", ".", "Get", "(", "url", ",", "ret", ",", "http", ".", "StatusOK", ")", "\n", "return", "ret", ",", "err", "\n", "}" ]
//ListAttachedVolumes lists attached volumes
[ "ListAttachedVolumes", "lists", "attached", "volumes" ]
1d2db5f00bf5dd0b6c29273541c71c60cdf4d4d4
https://github.com/profitbricks/profitbricks-sdk-go/blob/1d2db5f00bf5dd0b6c29273541c71c60cdf4d4d4/server.go#L136-L141
test
profitbricks/profitbricks-sdk-go
server.go
AttachVolume
func (c *Client) AttachVolume(dcid string, srvid string, volid string) (*Volume, error) { data := struct { ID string `json:"id,omitempty"` }{ volid, } url := serverVolumeColPath(dcid, srvid) + `?depth=` + c.client.depth + `&pretty=` + strconv.FormatBool(c.client.pretty) ret := &Volume{} err := c.client.Post(url, data, ret, http.StatusAccepted) return ret, err }
go
func (c *Client) AttachVolume(dcid string, srvid string, volid string) (*Volume, error) { data := struct { ID string `json:"id,omitempty"` }{ volid, } url := serverVolumeColPath(dcid, srvid) + `?depth=` + c.client.depth + `&pretty=` + strconv.FormatBool(c.client.pretty) ret := &Volume{} err := c.client.Post(url, data, ret, http.StatusAccepted) return ret, err }
[ "func", "(", "c", "*", "Client", ")", "AttachVolume", "(", "dcid", "string", ",", "srvid", "string", ",", "volid", "string", ")", "(", "*", "Volume", ",", "error", ")", "{", "data", ":=", "struct", "{", "ID", "string", "`json:\"id,omitempty\"`", "\n", "}", "{", "volid", ",", "}", "\n", "url", ":=", "serverVolumeColPath", "(", "dcid", ",", "srvid", ")", "+", "`?depth=`", "+", "c", ".", "client", ".", "depth", "+", "`&pretty=`", "+", "strconv", ".", "FormatBool", "(", "c", ".", "client", ".", "pretty", ")", "\n", "ret", ":=", "&", "Volume", "{", "}", "\n", "err", ":=", "c", ".", "client", ".", "Post", "(", "url", ",", "data", ",", "ret", ",", "http", ".", "StatusAccepted", ")", "\n", "return", "ret", ",", "err", "\n", "}" ]
//AttachVolume attaches a volume
[ "AttachVolume", "attaches", "a", "volume" ]
1d2db5f00bf5dd0b6c29273541c71c60cdf4d4d4
https://github.com/profitbricks/profitbricks-sdk-go/blob/1d2db5f00bf5dd0b6c29273541c71c60cdf4d4d4/server.go#L144-L155
test
profitbricks/profitbricks-sdk-go
server.go
GetAttachedVolume
func (c *Client) GetAttachedVolume(dcid, srvid, volid string) (*Volume, error) { url := serverVolumePath(dcid, srvid, volid) + `?depth=` + c.client.depth + `&pretty=` + strconv.FormatBool(c.client.pretty) ret := &Volume{} err := c.client.Get(url, ret, http.StatusOK) return ret, err }
go
func (c *Client) GetAttachedVolume(dcid, srvid, volid string) (*Volume, error) { url := serverVolumePath(dcid, srvid, volid) + `?depth=` + c.client.depth + `&pretty=` + strconv.FormatBool(c.client.pretty) ret := &Volume{} err := c.client.Get(url, ret, http.StatusOK) return ret, err }
[ "func", "(", "c", "*", "Client", ")", "GetAttachedVolume", "(", "dcid", ",", "srvid", ",", "volid", "string", ")", "(", "*", "Volume", ",", "error", ")", "{", "url", ":=", "serverVolumePath", "(", "dcid", ",", "srvid", ",", "volid", ")", "+", "`?depth=`", "+", "c", ".", "client", ".", "depth", "+", "`&pretty=`", "+", "strconv", ".", "FormatBool", "(", "c", ".", "client", ".", "pretty", ")", "\n", "ret", ":=", "&", "Volume", "{", "}", "\n", "err", ":=", "c", ".", "client", ".", "Get", "(", "url", ",", "ret", ",", "http", ".", "StatusOK", ")", "\n", "return", "ret", ",", "err", "\n", "}" ]
//GetAttachedVolume gets an attached volume
[ "GetAttachedVolume", "gets", "an", "attached", "volume" ]
1d2db5f00bf5dd0b6c29273541c71c60cdf4d4d4
https://github.com/profitbricks/profitbricks-sdk-go/blob/1d2db5f00bf5dd0b6c29273541c71c60cdf4d4d4/server.go#L158-L164
test
profitbricks/profitbricks-sdk-go
server.go
DetachVolume
func (c *Client) DetachVolume(dcid, srvid, volid string) (*http.Header, error) { url := serverVolumePath(dcid, srvid, volid) ret := &http.Header{} err := c.client.Delete(url, ret, http.StatusAccepted) return ret, err }
go
func (c *Client) DetachVolume(dcid, srvid, volid string) (*http.Header, error) { url := serverVolumePath(dcid, srvid, volid) ret := &http.Header{} err := c.client.Delete(url, ret, http.StatusAccepted) return ret, err }
[ "func", "(", "c", "*", "Client", ")", "DetachVolume", "(", "dcid", ",", "srvid", ",", "volid", "string", ")", "(", "*", "http", ".", "Header", ",", "error", ")", "{", "url", ":=", "serverVolumePath", "(", "dcid", ",", "srvid", ",", "volid", ")", "\n", "ret", ":=", "&", "http", ".", "Header", "{", "}", "\n", "err", ":=", "c", ".", "client", ".", "Delete", "(", "url", ",", "ret", ",", "http", ".", "StatusAccepted", ")", "\n", "return", "ret", ",", "err", "\n", "}" ]
//DetachVolume detaches a volume
[ "DetachVolume", "detaches", "a", "volume" ]
1d2db5f00bf5dd0b6c29273541c71c60cdf4d4d4
https://github.com/profitbricks/profitbricks-sdk-go/blob/1d2db5f00bf5dd0b6c29273541c71c60cdf4d4d4/server.go#L167-L172
test
profitbricks/profitbricks-sdk-go
server.go
StartServer
func (c *Client) StartServer(dcid, srvid string) (*http.Header, error) { url := serverPath(dcid, srvid) + "/start" ret := &http.Header{} err := c.client.Post(url, nil, ret, http.StatusAccepted) return ret, err }
go
func (c *Client) StartServer(dcid, srvid string) (*http.Header, error) { url := serverPath(dcid, srvid) + "/start" ret := &http.Header{} err := c.client.Post(url, nil, ret, http.StatusAccepted) return ret, err }
[ "func", "(", "c", "*", "Client", ")", "StartServer", "(", "dcid", ",", "srvid", "string", ")", "(", "*", "http", ".", "Header", ",", "error", ")", "{", "url", ":=", "serverPath", "(", "dcid", ",", "srvid", ")", "+", "\"/start\"", "\n", "ret", ":=", "&", "http", ".", "Header", "{", "}", "\n", "err", ":=", "c", ".", "client", ".", "Post", "(", "url", ",", "nil", ",", "ret", ",", "http", ".", "StatusAccepted", ")", "\n", "return", "ret", ",", "err", "\n", "}" ]
// StartServer starts a server
[ "StartServer", "starts", "a", "server" ]
1d2db5f00bf5dd0b6c29273541c71c60cdf4d4d4
https://github.com/profitbricks/profitbricks-sdk-go/blob/1d2db5f00bf5dd0b6c29273541c71c60cdf4d4d4/server.go#L175-L180
test
profitbricks/profitbricks-sdk-go
location.go
ListLocations
func (c *Client) ListLocations() (*Locations, error) { url := locationColPath() + `?depth=` + c.client.depth + `&pretty=` + strconv.FormatBool(c.client.pretty) ret := &Locations{} err := c.client.Get(url, ret, http.StatusOK) return ret, err }
go
func (c *Client) ListLocations() (*Locations, error) { url := locationColPath() + `?depth=` + c.client.depth + `&pretty=` + strconv.FormatBool(c.client.pretty) ret := &Locations{} err := c.client.Get(url, ret, http.StatusOK) return ret, err }
[ "func", "(", "c", "*", "Client", ")", "ListLocations", "(", ")", "(", "*", "Locations", ",", "error", ")", "{", "url", ":=", "locationColPath", "(", ")", "+", "`?depth=`", "+", "c", ".", "client", ".", "depth", "+", "`&pretty=`", "+", "strconv", ".", "FormatBool", "(", "c", ".", "client", ".", "pretty", ")", "\n", "ret", ":=", "&", "Locations", "{", "}", "\n", "err", ":=", "c", ".", "client", ".", "Get", "(", "url", ",", "ret", ",", "http", ".", "StatusOK", ")", "\n", "return", "ret", ",", "err", "\n", "}" ]
// ListLocations returns location collection data
[ "ListLocations", "returns", "location", "collection", "data" ]
1d2db5f00bf5dd0b6c29273541c71c60cdf4d4d4
https://github.com/profitbricks/profitbricks-sdk-go/blob/1d2db5f00bf5dd0b6c29273541c71c60cdf4d4d4/location.go#L39-L44
test
profitbricks/profitbricks-sdk-go
location.go
GetRegionalLocations
func (c *Client) GetRegionalLocations(regid string) (*Locations, error) { url := locationRegPath(regid) + c.client.depth + `&pretty=` + strconv.FormatBool(c.client.pretty) ret := &Locations{} err := c.client.Get(url, ret, http.StatusOK) return ret, err }
go
func (c *Client) GetRegionalLocations(regid string) (*Locations, error) { url := locationRegPath(regid) + c.client.depth + `&pretty=` + strconv.FormatBool(c.client.pretty) ret := &Locations{} err := c.client.Get(url, ret, http.StatusOK) return ret, err }
[ "func", "(", "c", "*", "Client", ")", "GetRegionalLocations", "(", "regid", "string", ")", "(", "*", "Locations", ",", "error", ")", "{", "url", ":=", "locationRegPath", "(", "regid", ")", "+", "c", ".", "client", ".", "depth", "+", "`&pretty=`", "+", "strconv", ".", "FormatBool", "(", "c", ".", "client", ".", "pretty", ")", "\n", "ret", ":=", "&", "Locations", "{", "}", "\n", "err", ":=", "c", ".", "client", ".", "Get", "(", "url", ",", "ret", ",", "http", ".", "StatusOK", ")", "\n", "return", "ret", ",", "err", "\n", "}" ]
// GetRegionalLocations returns a list of available locations in a specific region
[ "GetRegionalLocations", "returns", "a", "list", "of", "available", "locations", "in", "a", "specific", "region" ]
1d2db5f00bf5dd0b6c29273541c71c60cdf4d4d4
https://github.com/profitbricks/profitbricks-sdk-go/blob/1d2db5f00bf5dd0b6c29273541c71c60cdf4d4d4/location.go#L47-L52
test
profitbricks/profitbricks-sdk-go
location.go
GetLocation
func (c *Client) GetLocation(locid string) (*Location, error) { url := locationPath(locid) + `?depth=` + c.client.depth + `&pretty=` + strconv.FormatBool(c.client.pretty) ret := &Location{} err := c.client.Get(url, ret, http.StatusOK) return ret, err }
go
func (c *Client) GetLocation(locid string) (*Location, error) { url := locationPath(locid) + `?depth=` + c.client.depth + `&pretty=` + strconv.FormatBool(c.client.pretty) ret := &Location{} err := c.client.Get(url, ret, http.StatusOK) return ret, err }
[ "func", "(", "c", "*", "Client", ")", "GetLocation", "(", "locid", "string", ")", "(", "*", "Location", ",", "error", ")", "{", "url", ":=", "locationPath", "(", "locid", ")", "+", "`?depth=`", "+", "c", ".", "client", ".", "depth", "+", "`&pretty=`", "+", "strconv", ".", "FormatBool", "(", "c", ".", "client", ".", "pretty", ")", "\n", "ret", ":=", "&", "Location", "{", "}", "\n", "err", ":=", "c", ".", "client", ".", "Get", "(", "url", ",", "ret", ",", "http", ".", "StatusOK", ")", "\n", "return", "ret", ",", "err", "\n", "}" ]
// GetLocation returns location data
[ "GetLocation", "returns", "location", "data" ]
1d2db5f00bf5dd0b6c29273541c71c60cdf4d4d4
https://github.com/profitbricks/profitbricks-sdk-go/blob/1d2db5f00bf5dd0b6c29273541c71c60cdf4d4d4/location.go#L55-L60
test
profitbricks/profitbricks-sdk-go
contractresources.go
GetContractResources
func (c *Client) GetContractResources() (*ContractResources, error) { url := contractResourcePath() + `?depth=` + c.client.depth + `&pretty=` + strconv.FormatBool(c.client.pretty) ret := &ContractResources{} err := c.client.Get(url, ret, http.StatusOK) return ret, err }
go
func (c *Client) GetContractResources() (*ContractResources, error) { url := contractResourcePath() + `?depth=` + c.client.depth + `&pretty=` + strconv.FormatBool(c.client.pretty) ret := &ContractResources{} err := c.client.Get(url, ret, http.StatusOK) return ret, err }
[ "func", "(", "c", "*", "Client", ")", "GetContractResources", "(", ")", "(", "*", "ContractResources", ",", "error", ")", "{", "url", ":=", "contractResourcePath", "(", ")", "+", "`?depth=`", "+", "c", ".", "client", ".", "depth", "+", "`&pretty=`", "+", "strconv", ".", "FormatBool", "(", "c", ".", "client", ".", "pretty", ")", "\n", "ret", ":=", "&", "ContractResources", "{", "}", "\n", "err", ":=", "c", ".", "client", ".", "Get", "(", "url", ",", "ret", ",", "http", ".", "StatusOK", ")", "\n", "return", "ret", ",", "err", "\n", "}" ]
// GetContractResources returns list of contract resources
[ "GetContractResources", "returns", "list", "of", "contract", "resources" ]
1d2db5f00bf5dd0b6c29273541c71c60cdf4d4d4
https://github.com/profitbricks/profitbricks-sdk-go/blob/1d2db5f00bf5dd0b6c29273541c71c60cdf4d4d4/contractresources.go#L47-L53
test
profitbricks/profitbricks-sdk-go
image.go
ListImages
func (c *Client) ListImages() (*Images, error) { url := imageColPath() + `?depth=` + c.client.depth + `&pretty=` + strconv.FormatBool(c.client.pretty) ret := &Images{} err := c.client.Get(url, ret, http.StatusOK) return ret, err }
go
func (c *Client) ListImages() (*Images, error) { url := imageColPath() + `?depth=` + c.client.depth + `&pretty=` + strconv.FormatBool(c.client.pretty) ret := &Images{} err := c.client.Get(url, ret, http.StatusOK) return ret, err }
[ "func", "(", "c", "*", "Client", ")", "ListImages", "(", ")", "(", "*", "Images", ",", "error", ")", "{", "url", ":=", "imageColPath", "(", ")", "+", "`?depth=`", "+", "c", ".", "client", ".", "depth", "+", "`&pretty=`", "+", "strconv", ".", "FormatBool", "(", "c", ".", "client", ".", "pretty", ")", "\n", "ret", ":=", "&", "Images", "{", "}", "\n", "err", ":=", "c", ".", "client", ".", "Get", "(", "url", ",", "ret", ",", "http", ".", "StatusOK", ")", "\n", "return", "ret", ",", "err", "\n", "}" ]
// ListImages returns an Collection struct
[ "ListImages", "returns", "an", "Collection", "struct" ]
1d2db5f00bf5dd0b6c29273541c71c60cdf4d4d4
https://github.com/profitbricks/profitbricks-sdk-go/blob/1d2db5f00bf5dd0b6c29273541c71c60cdf4d4d4/image.go#L68-L73
test
profitbricks/profitbricks-sdk-go
image.go
GetImage
func (c *Client) GetImage(imageid string) (*Image, error) { url := imagePath(imageid) ret := &Image{} err := c.client.Get(url, ret, http.StatusOK) return ret, err }
go
func (c *Client) GetImage(imageid string) (*Image, error) { url := imagePath(imageid) ret := &Image{} err := c.client.Get(url, ret, http.StatusOK) return ret, err }
[ "func", "(", "c", "*", "Client", ")", "GetImage", "(", "imageid", "string", ")", "(", "*", "Image", ",", "error", ")", "{", "url", ":=", "imagePath", "(", "imageid", ")", "\n", "ret", ":=", "&", "Image", "{", "}", "\n", "err", ":=", "c", ".", "client", ".", "Get", "(", "url", ",", "ret", ",", "http", ".", "StatusOK", ")", "\n", "return", "ret", ",", "err", "\n", "}" ]
// GetImage returns an Instance struct where id ==imageid
[ "GetImage", "returns", "an", "Instance", "struct", "where", "id", "==", "imageid" ]
1d2db5f00bf5dd0b6c29273541c71c60cdf4d4d4
https://github.com/profitbricks/profitbricks-sdk-go/blob/1d2db5f00bf5dd0b6c29273541c71c60cdf4d4d4/image.go#L76-L81
test
profitbricks/profitbricks-sdk-go
resp.go
PrintHeaders
func (r *Resp) PrintHeaders() { for key, value := range r.Headers { fmt.Println(key, " : ", value[0]) } }
go
func (r *Resp) PrintHeaders() { for key, value := range r.Headers { fmt.Println(key, " : ", value[0]) } }
[ "func", "(", "r", "*", "Resp", ")", "PrintHeaders", "(", ")", "{", "for", "key", ",", "value", ":=", "range", "r", ".", "Headers", "{", "fmt", ".", "Println", "(", "key", ",", "\" : \"", ",", "value", "[", "0", "]", ")", "\n", "}", "\n", "}" ]
// PrintHeaders prints the http headers as k,v pairs
[ "PrintHeaders", "prints", "the", "http", "headers", "as", "k", "v", "pairs" ]
1d2db5f00bf5dd0b6c29273541c71c60cdf4d4d4
https://github.com/profitbricks/profitbricks-sdk-go/blob/1d2db5f00bf5dd0b6c29273541c71c60cdf4d4d4/resp.go#L15-L20
test
profitbricks/profitbricks-sdk-go
usermanagment.go
ListGroups
func (c *Client) ListGroups() (*Groups, error) { url := umGroups() + `?depth=` + c.client.depth + `&pretty=` + strconv.FormatBool(c.client.pretty) ret := &Groups{} err := c.client.Get(url, ret, http.StatusOK) return ret, err }
go
func (c *Client) ListGroups() (*Groups, error) { url := umGroups() + `?depth=` + c.client.depth + `&pretty=` + strconv.FormatBool(c.client.pretty) ret := &Groups{} err := c.client.Get(url, ret, http.StatusOK) return ret, err }
[ "func", "(", "c", "*", "Client", ")", "ListGroups", "(", ")", "(", "*", "Groups", ",", "error", ")", "{", "url", ":=", "umGroups", "(", ")", "+", "`?depth=`", "+", "c", ".", "client", ".", "depth", "+", "`&pretty=`", "+", "strconv", ".", "FormatBool", "(", "c", ".", "client", ".", "pretty", ")", "\n", "ret", ":=", "&", "Groups", "{", "}", "\n", "err", ":=", "c", ".", "client", ".", "Get", "(", "url", ",", "ret", ",", "http", ".", "StatusOK", ")", "\n", "return", "ret", ",", "err", "\n", "}" ]
//ListGroups lists all groups
[ "ListGroups", "lists", "all", "groups" ]
1d2db5f00bf5dd0b6c29273541c71c60cdf4d4d4
https://github.com/profitbricks/profitbricks-sdk-go/blob/1d2db5f00bf5dd0b6c29273541c71c60cdf4d4d4/usermanagment.go#L166-L171
test
profitbricks/profitbricks-sdk-go
usermanagment.go
GetGroup
func (c *Client) GetGroup(groupid string) (*Group, error) { url := umGroupPath(groupid) + `?depth=` + c.client.depth + `&pretty=` + strconv.FormatBool(c.client.pretty) ret := &Group{} err := c.client.Get(url, ret, http.StatusOK) return ret, err }
go
func (c *Client) GetGroup(groupid string) (*Group, error) { url := umGroupPath(groupid) + `?depth=` + c.client.depth + `&pretty=` + strconv.FormatBool(c.client.pretty) ret := &Group{} err := c.client.Get(url, ret, http.StatusOK) return ret, err }
[ "func", "(", "c", "*", "Client", ")", "GetGroup", "(", "groupid", "string", ")", "(", "*", "Group", ",", "error", ")", "{", "url", ":=", "umGroupPath", "(", "groupid", ")", "+", "`?depth=`", "+", "c", ".", "client", ".", "depth", "+", "`&pretty=`", "+", "strconv", ".", "FormatBool", "(", "c", ".", "client", ".", "pretty", ")", "\n", "ret", ":=", "&", "Group", "{", "}", "\n", "err", ":=", "c", ".", "client", ".", "Get", "(", "url", ",", "ret", ",", "http", ".", "StatusOK", ")", "\n", "return", "ret", ",", "err", "\n", "}" ]
//GetGroup gets a group
[ "GetGroup", "gets", "a", "group" ]
1d2db5f00bf5dd0b6c29273541c71c60cdf4d4d4
https://github.com/profitbricks/profitbricks-sdk-go/blob/1d2db5f00bf5dd0b6c29273541c71c60cdf4d4d4/usermanagment.go#L174-L179
test
profitbricks/profitbricks-sdk-go
usermanagment.go
CreateGroup
func (c *Client) CreateGroup(grp Group) (*Group, error) { url := umGroups() + `?depth=` + c.client.depth + `&pretty=` + strconv.FormatBool(c.client.pretty) ret := &Group{} err := c.client.Post(url, grp, ret, http.StatusAccepted) return ret, err }
go
func (c *Client) CreateGroup(grp Group) (*Group, error) { url := umGroups() + `?depth=` + c.client.depth + `&pretty=` + strconv.FormatBool(c.client.pretty) ret := &Group{} err := c.client.Post(url, grp, ret, http.StatusAccepted) return ret, err }
[ "func", "(", "c", "*", "Client", ")", "CreateGroup", "(", "grp", "Group", ")", "(", "*", "Group", ",", "error", ")", "{", "url", ":=", "umGroups", "(", ")", "+", "`?depth=`", "+", "c", ".", "client", ".", "depth", "+", "`&pretty=`", "+", "strconv", ".", "FormatBool", "(", "c", ".", "client", ".", "pretty", ")", "\n", "ret", ":=", "&", "Group", "{", "}", "\n", "err", ":=", "c", ".", "client", ".", "Post", "(", "url", ",", "grp", ",", "ret", ",", "http", ".", "StatusAccepted", ")", "\n", "return", "ret", ",", "err", "\n", "}" ]
//CreateGroup creates a group
[ "CreateGroup", "creates", "a", "group" ]
1d2db5f00bf5dd0b6c29273541c71c60cdf4d4d4
https://github.com/profitbricks/profitbricks-sdk-go/blob/1d2db5f00bf5dd0b6c29273541c71c60cdf4d4d4/usermanagment.go#L182-L187
test
profitbricks/profitbricks-sdk-go
usermanagment.go
UpdateGroup
func (c *Client) UpdateGroup(groupid string, obj Group) (*Group, error) { url := umGroupPath(groupid) + `?depth=` + c.client.depth + `&pretty=` + strconv.FormatBool(c.client.pretty) ret := &Group{} err := c.client.Put(url, obj, ret, http.StatusAccepted) return ret, err }
go
func (c *Client) UpdateGroup(groupid string, obj Group) (*Group, error) { url := umGroupPath(groupid) + `?depth=` + c.client.depth + `&pretty=` + strconv.FormatBool(c.client.pretty) ret := &Group{} err := c.client.Put(url, obj, ret, http.StatusAccepted) return ret, err }
[ "func", "(", "c", "*", "Client", ")", "UpdateGroup", "(", "groupid", "string", ",", "obj", "Group", ")", "(", "*", "Group", ",", "error", ")", "{", "url", ":=", "umGroupPath", "(", "groupid", ")", "+", "`?depth=`", "+", "c", ".", "client", ".", "depth", "+", "`&pretty=`", "+", "strconv", ".", "FormatBool", "(", "c", ".", "client", ".", "pretty", ")", "\n", "ret", ":=", "&", "Group", "{", "}", "\n", "err", ":=", "c", ".", "client", ".", "Put", "(", "url", ",", "obj", ",", "ret", ",", "http", ".", "StatusAccepted", ")", "\n", "return", "ret", ",", "err", "\n", "}" ]
//UpdateGroup updates a group
[ "UpdateGroup", "updates", "a", "group" ]
1d2db5f00bf5dd0b6c29273541c71c60cdf4d4d4
https://github.com/profitbricks/profitbricks-sdk-go/blob/1d2db5f00bf5dd0b6c29273541c71c60cdf4d4d4/usermanagment.go#L190-L195
test
profitbricks/profitbricks-sdk-go
usermanagment.go
DeleteGroup
func (c *Client) DeleteGroup(groupid string) (*http.Header, error) { url := umGroupPath(groupid) + `?depth=` + c.client.depth + `&pretty=` + strconv.FormatBool(c.client.pretty) ret := &http.Header{} err := c.client.Delete(url, ret, http.StatusAccepted) return ret, err }
go
func (c *Client) DeleteGroup(groupid string) (*http.Header, error) { url := umGroupPath(groupid) + `?depth=` + c.client.depth + `&pretty=` + strconv.FormatBool(c.client.pretty) ret := &http.Header{} err := c.client.Delete(url, ret, http.StatusAccepted) return ret, err }
[ "func", "(", "c", "*", "Client", ")", "DeleteGroup", "(", "groupid", "string", ")", "(", "*", "http", ".", "Header", ",", "error", ")", "{", "url", ":=", "umGroupPath", "(", "groupid", ")", "+", "`?depth=`", "+", "c", ".", "client", ".", "depth", "+", "`&pretty=`", "+", "strconv", ".", "FormatBool", "(", "c", ".", "client", ".", "pretty", ")", "\n", "ret", ":=", "&", "http", ".", "Header", "{", "}", "\n", "err", ":=", "c", ".", "client", ".", "Delete", "(", "url", ",", "ret", ",", "http", ".", "StatusAccepted", ")", "\n", "return", "ret", ",", "err", "\n", "}" ]
//DeleteGroup deletes a group
[ "DeleteGroup", "deletes", "a", "group" ]
1d2db5f00bf5dd0b6c29273541c71c60cdf4d4d4
https://github.com/profitbricks/profitbricks-sdk-go/blob/1d2db5f00bf5dd0b6c29273541c71c60cdf4d4d4/usermanagment.go#L198-L203
test
profitbricks/profitbricks-sdk-go
usermanagment.go
ListShares
func (c *Client) ListShares(grpid string) (*Shares, error) { url := umGroupShares(grpid) + `?depth=` + c.client.depth + `&pretty=` + strconv.FormatBool(c.client.pretty) ret := &Shares{} err := c.client.Get(url, ret, http.StatusOK) return ret, err }
go
func (c *Client) ListShares(grpid string) (*Shares, error) { url := umGroupShares(grpid) + `?depth=` + c.client.depth + `&pretty=` + strconv.FormatBool(c.client.pretty) ret := &Shares{} err := c.client.Get(url, ret, http.StatusOK) return ret, err }
[ "func", "(", "c", "*", "Client", ")", "ListShares", "(", "grpid", "string", ")", "(", "*", "Shares", ",", "error", ")", "{", "url", ":=", "umGroupShares", "(", "grpid", ")", "+", "`?depth=`", "+", "c", ".", "client", ".", "depth", "+", "`&pretty=`", "+", "strconv", ".", "FormatBool", "(", "c", ".", "client", ".", "pretty", ")", "\n", "ret", ":=", "&", "Shares", "{", "}", "\n", "err", ":=", "c", ".", "client", ".", "Get", "(", "url", ",", "ret", ",", "http", ".", "StatusOK", ")", "\n", "return", "ret", ",", "err", "\n", "}" ]
//ListShares lists all shares
[ "ListShares", "lists", "all", "shares" ]
1d2db5f00bf5dd0b6c29273541c71c60cdf4d4d4
https://github.com/profitbricks/profitbricks-sdk-go/blob/1d2db5f00bf5dd0b6c29273541c71c60cdf4d4d4/usermanagment.go#L206-L211
test
profitbricks/profitbricks-sdk-go
usermanagment.go
GetShare
func (c *Client) GetShare(groupid string, resourceid string) (*Share, error) { url := umGroupSharePath(groupid, resourceid) + `?depth=` + c.client.depth + `&pretty=` + strconv.FormatBool(c.client.pretty) ret := &Share{} err := c.client.Get(url, ret, http.StatusOK) return ret, err }
go
func (c *Client) GetShare(groupid string, resourceid string) (*Share, error) { url := umGroupSharePath(groupid, resourceid) + `?depth=` + c.client.depth + `&pretty=` + strconv.FormatBool(c.client.pretty) ret := &Share{} err := c.client.Get(url, ret, http.StatusOK) return ret, err }
[ "func", "(", "c", "*", "Client", ")", "GetShare", "(", "groupid", "string", ",", "resourceid", "string", ")", "(", "*", "Share", ",", "error", ")", "{", "url", ":=", "umGroupSharePath", "(", "groupid", ",", "resourceid", ")", "+", "`?depth=`", "+", "c", ".", "client", ".", "depth", "+", "`&pretty=`", "+", "strconv", ".", "FormatBool", "(", "c", ".", "client", ".", "pretty", ")", "\n", "ret", ":=", "&", "Share", "{", "}", "\n", "err", ":=", "c", ".", "client", ".", "Get", "(", "url", ",", "ret", ",", "http", ".", "StatusOK", ")", "\n", "return", "ret", ",", "err", "\n", "}" ]
// GetShare gets a share
[ "GetShare", "gets", "a", "share" ]
1d2db5f00bf5dd0b6c29273541c71c60cdf4d4d4
https://github.com/profitbricks/profitbricks-sdk-go/blob/1d2db5f00bf5dd0b6c29273541c71c60cdf4d4d4/usermanagment.go#L214-L219
test
profitbricks/profitbricks-sdk-go
usermanagment.go
AddShare
func (c *Client) AddShare(groupid string, resourceid string, share Share) (*Share, error) { url := umGroupSharePath(groupid, resourceid) + `?depth=` + c.client.depth + `&pretty=` + strconv.FormatBool(c.client.pretty) ret := &Share{} err := c.client.Post(url, share, ret, http.StatusAccepted) return ret, err }
go
func (c *Client) AddShare(groupid string, resourceid string, share Share) (*Share, error) { url := umGroupSharePath(groupid, resourceid) + `?depth=` + c.client.depth + `&pretty=` + strconv.FormatBool(c.client.pretty) ret := &Share{} err := c.client.Post(url, share, ret, http.StatusAccepted) return ret, err }
[ "func", "(", "c", "*", "Client", ")", "AddShare", "(", "groupid", "string", ",", "resourceid", "string", ",", "share", "Share", ")", "(", "*", "Share", ",", "error", ")", "{", "url", ":=", "umGroupSharePath", "(", "groupid", ",", "resourceid", ")", "+", "`?depth=`", "+", "c", ".", "client", ".", "depth", "+", "`&pretty=`", "+", "strconv", ".", "FormatBool", "(", "c", ".", "client", ".", "pretty", ")", "\n", "ret", ":=", "&", "Share", "{", "}", "\n", "err", ":=", "c", ".", "client", ".", "Post", "(", "url", ",", "share", ",", "ret", ",", "http", ".", "StatusAccepted", ")", "\n", "return", "ret", ",", "err", "\n", "}" ]
// AddShare adds a share
[ "AddShare", "adds", "a", "share" ]
1d2db5f00bf5dd0b6c29273541c71c60cdf4d4d4
https://github.com/profitbricks/profitbricks-sdk-go/blob/1d2db5f00bf5dd0b6c29273541c71c60cdf4d4d4/usermanagment.go#L222-L227
test
profitbricks/profitbricks-sdk-go
usermanagment.go
UpdateShare
func (c *Client) UpdateShare(groupid string, resourceid string, obj Share) (*Share, error) { url := umGroupSharePath(groupid, resourceid) + `?depth=` + c.client.depth + `&pretty=` + strconv.FormatBool(c.client.pretty) ret := &Share{} err := c.client.Put(url, obj, ret, http.StatusAccepted) return ret, err }
go
func (c *Client) UpdateShare(groupid string, resourceid string, obj Share) (*Share, error) { url := umGroupSharePath(groupid, resourceid) + `?depth=` + c.client.depth + `&pretty=` + strconv.FormatBool(c.client.pretty) ret := &Share{} err := c.client.Put(url, obj, ret, http.StatusAccepted) return ret, err }
[ "func", "(", "c", "*", "Client", ")", "UpdateShare", "(", "groupid", "string", ",", "resourceid", "string", ",", "obj", "Share", ")", "(", "*", "Share", ",", "error", ")", "{", "url", ":=", "umGroupSharePath", "(", "groupid", ",", "resourceid", ")", "+", "`?depth=`", "+", "c", ".", "client", ".", "depth", "+", "`&pretty=`", "+", "strconv", ".", "FormatBool", "(", "c", ".", "client", ".", "pretty", ")", "\n", "ret", ":=", "&", "Share", "{", "}", "\n", "err", ":=", "c", ".", "client", ".", "Put", "(", "url", ",", "obj", ",", "ret", ",", "http", ".", "StatusAccepted", ")", "\n", "return", "ret", ",", "err", "\n", "}" ]
// UpdateShare updates a share
[ "UpdateShare", "updates", "a", "share" ]
1d2db5f00bf5dd0b6c29273541c71c60cdf4d4d4
https://github.com/profitbricks/profitbricks-sdk-go/blob/1d2db5f00bf5dd0b6c29273541c71c60cdf4d4d4/usermanagment.go#L230-L235
test
profitbricks/profitbricks-sdk-go
usermanagment.go
DeleteShare
func (c *Client) DeleteShare(groupid string, resourceid string) (*http.Header, error) { url := umGroupSharePath(groupid, resourceid) + `?depth=` + c.client.depth + `&pretty=` + strconv.FormatBool(c.client.pretty) ret := &http.Header{} err := c.client.Delete(url, ret, http.StatusAccepted) return ret, err }
go
func (c *Client) DeleteShare(groupid string, resourceid string) (*http.Header, error) { url := umGroupSharePath(groupid, resourceid) + `?depth=` + c.client.depth + `&pretty=` + strconv.FormatBool(c.client.pretty) ret := &http.Header{} err := c.client.Delete(url, ret, http.StatusAccepted) return ret, err }
[ "func", "(", "c", "*", "Client", ")", "DeleteShare", "(", "groupid", "string", ",", "resourceid", "string", ")", "(", "*", "http", ".", "Header", ",", "error", ")", "{", "url", ":=", "umGroupSharePath", "(", "groupid", ",", "resourceid", ")", "+", "`?depth=`", "+", "c", ".", "client", ".", "depth", "+", "`&pretty=`", "+", "strconv", ".", "FormatBool", "(", "c", ".", "client", ".", "pretty", ")", "\n", "ret", ":=", "&", "http", ".", "Header", "{", "}", "\n", "err", ":=", "c", ".", "client", ".", "Delete", "(", "url", ",", "ret", ",", "http", ".", "StatusAccepted", ")", "\n", "return", "ret", ",", "err", "\n", "}" ]
// DeleteShare deletes a share
[ "DeleteShare", "deletes", "a", "share" ]
1d2db5f00bf5dd0b6c29273541c71c60cdf4d4d4
https://github.com/profitbricks/profitbricks-sdk-go/blob/1d2db5f00bf5dd0b6c29273541c71c60cdf4d4d4/usermanagment.go#L238-L243
test
profitbricks/profitbricks-sdk-go
usermanagment.go
ListGroupUsers
func (c *Client) ListGroupUsers(groupid string) (*Users, error) { url := umGroupUsers(groupid) + `?depth=` + c.client.depth + `&pretty=` + strconv.FormatBool(c.client.pretty) ret := &Users{} err := c.client.Get(url, ret, http.StatusOK) return ret, err }
go
func (c *Client) ListGroupUsers(groupid string) (*Users, error) { url := umGroupUsers(groupid) + `?depth=` + c.client.depth + `&pretty=` + strconv.FormatBool(c.client.pretty) ret := &Users{} err := c.client.Get(url, ret, http.StatusOK) return ret, err }
[ "func", "(", "c", "*", "Client", ")", "ListGroupUsers", "(", "groupid", "string", ")", "(", "*", "Users", ",", "error", ")", "{", "url", ":=", "umGroupUsers", "(", "groupid", ")", "+", "`?depth=`", "+", "c", ".", "client", ".", "depth", "+", "`&pretty=`", "+", "strconv", ".", "FormatBool", "(", "c", ".", "client", ".", "pretty", ")", "\n", "ret", ":=", "&", "Users", "{", "}", "\n", "err", ":=", "c", ".", "client", ".", "Get", "(", "url", ",", "ret", ",", "http", ".", "StatusOK", ")", "\n", "return", "ret", ",", "err", "\n", "}" ]
//ListGroupUsers lists Users in a group
[ "ListGroupUsers", "lists", "Users", "in", "a", "group" ]
1d2db5f00bf5dd0b6c29273541c71c60cdf4d4d4
https://github.com/profitbricks/profitbricks-sdk-go/blob/1d2db5f00bf5dd0b6c29273541c71c60cdf4d4d4/usermanagment.go#L246-L251
test
profitbricks/profitbricks-sdk-go
usermanagment.go
AddUserToGroup
func (c *Client) AddUserToGroup(groupid string, userid string) (*User, error) { var usr User usr.ID = userid url := umGroupUsers(groupid) + `?depth=` + c.client.depth + `&pretty=` + strconv.FormatBool(c.client.pretty) ret := &User{} err := c.client.Post(url, usr, ret, http.StatusAccepted) return ret, err }
go
func (c *Client) AddUserToGroup(groupid string, userid string) (*User, error) { var usr User usr.ID = userid url := umGroupUsers(groupid) + `?depth=` + c.client.depth + `&pretty=` + strconv.FormatBool(c.client.pretty) ret := &User{} err := c.client.Post(url, usr, ret, http.StatusAccepted) return ret, err }
[ "func", "(", "c", "*", "Client", ")", "AddUserToGroup", "(", "groupid", "string", ",", "userid", "string", ")", "(", "*", "User", ",", "error", ")", "{", "var", "usr", "User", "\n", "usr", ".", "ID", "=", "userid", "\n", "url", ":=", "umGroupUsers", "(", "groupid", ")", "+", "`?depth=`", "+", "c", ".", "client", ".", "depth", "+", "`&pretty=`", "+", "strconv", ".", "FormatBool", "(", "c", ".", "client", ".", "pretty", ")", "\n", "ret", ":=", "&", "User", "{", "}", "\n", "err", ":=", "c", ".", "client", ".", "Post", "(", "url", ",", "usr", ",", "ret", ",", "http", ".", "StatusAccepted", ")", "\n", "return", "ret", ",", "err", "\n", "}" ]
// AddUserToGroup adds a user to a group
[ "AddUserToGroup", "adds", "a", "user", "to", "a", "group" ]
1d2db5f00bf5dd0b6c29273541c71c60cdf4d4d4
https://github.com/profitbricks/profitbricks-sdk-go/blob/1d2db5f00bf5dd0b6c29273541c71c60cdf4d4d4/usermanagment.go#L254-L261
test
profitbricks/profitbricks-sdk-go
usermanagment.go
DeleteUserFromGroup
func (c *Client) DeleteUserFromGroup(groupid string, userid string) (*http.Header, error) { url := umGroupUsersPath(groupid, userid) + `?depth=` + c.client.depth + `&pretty=` + strconv.FormatBool(c.client.pretty) ret := &http.Header{} err := c.client.Delete(url, ret, http.StatusAccepted) return ret, err }
go
func (c *Client) DeleteUserFromGroup(groupid string, userid string) (*http.Header, error) { url := umGroupUsersPath(groupid, userid) + `?depth=` + c.client.depth + `&pretty=` + strconv.FormatBool(c.client.pretty) ret := &http.Header{} err := c.client.Delete(url, ret, http.StatusAccepted) return ret, err }
[ "func", "(", "c", "*", "Client", ")", "DeleteUserFromGroup", "(", "groupid", "string", ",", "userid", "string", ")", "(", "*", "http", ".", "Header", ",", "error", ")", "{", "url", ":=", "umGroupUsersPath", "(", "groupid", ",", "userid", ")", "+", "`?depth=`", "+", "c", ".", "client", ".", "depth", "+", "`&pretty=`", "+", "strconv", ".", "FormatBool", "(", "c", ".", "client", ".", "pretty", ")", "\n", "ret", ":=", "&", "http", ".", "Header", "{", "}", "\n", "err", ":=", "c", ".", "client", ".", "Delete", "(", "url", ",", "ret", ",", "http", ".", "StatusAccepted", ")", "\n", "return", "ret", ",", "err", "\n", "}" ]
// DeleteUserFromGroup removes a user from a group
[ "DeleteUserFromGroup", "removes", "a", "user", "from", "a", "group" ]
1d2db5f00bf5dd0b6c29273541c71c60cdf4d4d4
https://github.com/profitbricks/profitbricks-sdk-go/blob/1d2db5f00bf5dd0b6c29273541c71c60cdf4d4d4/usermanagment.go#L264-L269
test
profitbricks/profitbricks-sdk-go
usermanagment.go
ListUsers
func (c *Client) ListUsers() (*Users, error) { url := umUsers() + `?depth=` + c.client.depth + `&pretty=` + strconv.FormatBool(c.client.pretty) ret := &Users{} err := c.client.Get(url, ret, http.StatusOK) return ret, err }
go
func (c *Client) ListUsers() (*Users, error) { url := umUsers() + `?depth=` + c.client.depth + `&pretty=` + strconv.FormatBool(c.client.pretty) ret := &Users{} err := c.client.Get(url, ret, http.StatusOK) return ret, err }
[ "func", "(", "c", "*", "Client", ")", "ListUsers", "(", ")", "(", "*", "Users", ",", "error", ")", "{", "url", ":=", "umUsers", "(", ")", "+", "`?depth=`", "+", "c", ".", "client", ".", "depth", "+", "`&pretty=`", "+", "strconv", ".", "FormatBool", "(", "c", ".", "client", ".", "pretty", ")", "\n", "ret", ":=", "&", "Users", "{", "}", "\n", "err", ":=", "c", ".", "client", ".", "Get", "(", "url", ",", "ret", ",", "http", ".", "StatusOK", ")", "\n", "return", "ret", ",", "err", "\n", "}" ]
//ListUsers lists all users
[ "ListUsers", "lists", "all", "users" ]
1d2db5f00bf5dd0b6c29273541c71c60cdf4d4d4
https://github.com/profitbricks/profitbricks-sdk-go/blob/1d2db5f00bf5dd0b6c29273541c71c60cdf4d4d4/usermanagment.go#L272-L277
test
profitbricks/profitbricks-sdk-go
usermanagment.go
GetUser
func (c *Client) GetUser(usrid string) (*User, error) { url := umUsersPath(usrid) + `?depth=` + c.client.depth + `&pretty=` + strconv.FormatBool(c.client.pretty) ret := &User{} err := c.client.Get(url, ret, http.StatusOK) return ret, err }
go
func (c *Client) GetUser(usrid string) (*User, error) { url := umUsersPath(usrid) + `?depth=` + c.client.depth + `&pretty=` + strconv.FormatBool(c.client.pretty) ret := &User{} err := c.client.Get(url, ret, http.StatusOK) return ret, err }
[ "func", "(", "c", "*", "Client", ")", "GetUser", "(", "usrid", "string", ")", "(", "*", "User", ",", "error", ")", "{", "url", ":=", "umUsersPath", "(", "usrid", ")", "+", "`?depth=`", "+", "c", ".", "client", ".", "depth", "+", "`&pretty=`", "+", "strconv", ".", "FormatBool", "(", "c", ".", "client", ".", "pretty", ")", "\n", "ret", ":=", "&", "User", "{", "}", "\n", "err", ":=", "c", ".", "client", ".", "Get", "(", "url", ",", "ret", ",", "http", ".", "StatusOK", ")", "\n", "return", "ret", ",", "err", "\n", "}" ]
// GetUser gets a user
[ "GetUser", "gets", "a", "user" ]
1d2db5f00bf5dd0b6c29273541c71c60cdf4d4d4
https://github.com/profitbricks/profitbricks-sdk-go/blob/1d2db5f00bf5dd0b6c29273541c71c60cdf4d4d4/usermanagment.go#L280-L285
test
profitbricks/profitbricks-sdk-go
usermanagment.go
CreateUser
func (c *Client) CreateUser(usr User) (*User, error) { url := umUsers() + `?depth=` + c.client.depth + `&pretty=` + strconv.FormatBool(c.client.pretty) ret := &User{} err := c.client.Post(url, usr, ret, http.StatusAccepted) return ret, err }
go
func (c *Client) CreateUser(usr User) (*User, error) { url := umUsers() + `?depth=` + c.client.depth + `&pretty=` + strconv.FormatBool(c.client.pretty) ret := &User{} err := c.client.Post(url, usr, ret, http.StatusAccepted) return ret, err }
[ "func", "(", "c", "*", "Client", ")", "CreateUser", "(", "usr", "User", ")", "(", "*", "User", ",", "error", ")", "{", "url", ":=", "umUsers", "(", ")", "+", "`?depth=`", "+", "c", ".", "client", ".", "depth", "+", "`&pretty=`", "+", "strconv", ".", "FormatBool", "(", "c", ".", "client", ".", "pretty", ")", "\n", "ret", ":=", "&", "User", "{", "}", "\n", "err", ":=", "c", ".", "client", ".", "Post", "(", "url", ",", "usr", ",", "ret", ",", "http", ".", "StatusAccepted", ")", "\n", "return", "ret", ",", "err", "\n", "}" ]
//CreateUser creates a user
[ "CreateUser", "creates", "a", "user" ]
1d2db5f00bf5dd0b6c29273541c71c60cdf4d4d4
https://github.com/profitbricks/profitbricks-sdk-go/blob/1d2db5f00bf5dd0b6c29273541c71c60cdf4d4d4/usermanagment.go#L288-L293
test
profitbricks/profitbricks-sdk-go
usermanagment.go
UpdateUser
func (c *Client) UpdateUser(userid string, obj User) (*User, error) { url := umUsersPath(userid) + `?depth=` + c.client.depth + `&pretty=` + strconv.FormatBool(c.client.pretty) ret := &User{} err := c.client.Put(url, obj, ret, http.StatusAccepted) return ret, err }
go
func (c *Client) UpdateUser(userid string, obj User) (*User, error) { url := umUsersPath(userid) + `?depth=` + c.client.depth + `&pretty=` + strconv.FormatBool(c.client.pretty) ret := &User{} err := c.client.Put(url, obj, ret, http.StatusAccepted) return ret, err }
[ "func", "(", "c", "*", "Client", ")", "UpdateUser", "(", "userid", "string", ",", "obj", "User", ")", "(", "*", "User", ",", "error", ")", "{", "url", ":=", "umUsersPath", "(", "userid", ")", "+", "`?depth=`", "+", "c", ".", "client", ".", "depth", "+", "`&pretty=`", "+", "strconv", ".", "FormatBool", "(", "c", ".", "client", ".", "pretty", ")", "\n", "ret", ":=", "&", "User", "{", "}", "\n", "err", ":=", "c", ".", "client", ".", "Put", "(", "url", ",", "obj", ",", "ret", ",", "http", ".", "StatusAccepted", ")", "\n", "return", "ret", ",", "err", "\n", "}" ]
//UpdateUser updates user information
[ "UpdateUser", "updates", "user", "information" ]
1d2db5f00bf5dd0b6c29273541c71c60cdf4d4d4
https://github.com/profitbricks/profitbricks-sdk-go/blob/1d2db5f00bf5dd0b6c29273541c71c60cdf4d4d4/usermanagment.go#L296-L301
test
profitbricks/profitbricks-sdk-go
usermanagment.go
DeleteUser
func (c *Client) DeleteUser(userid string) (*http.Header, error) { url := umUsersPath(userid) + `?depth=` + c.client.depth + `&pretty=` + strconv.FormatBool(c.client.pretty) ret := &http.Header{} err := c.client.Delete(url, ret, http.StatusAccepted) return ret, err }
go
func (c *Client) DeleteUser(userid string) (*http.Header, error) { url := umUsersPath(userid) + `?depth=` + c.client.depth + `&pretty=` + strconv.FormatBool(c.client.pretty) ret := &http.Header{} err := c.client.Delete(url, ret, http.StatusAccepted) return ret, err }
[ "func", "(", "c", "*", "Client", ")", "DeleteUser", "(", "userid", "string", ")", "(", "*", "http", ".", "Header", ",", "error", ")", "{", "url", ":=", "umUsersPath", "(", "userid", ")", "+", "`?depth=`", "+", "c", ".", "client", ".", "depth", "+", "`&pretty=`", "+", "strconv", ".", "FormatBool", "(", "c", ".", "client", ".", "pretty", ")", "\n", "ret", ":=", "&", "http", ".", "Header", "{", "}", "\n", "err", ":=", "c", ".", "client", ".", "Delete", "(", "url", ",", "ret", ",", "http", ".", "StatusAccepted", ")", "\n", "return", "ret", ",", "err", "\n", "}" ]
//DeleteUser deletes the specified user
[ "DeleteUser", "deletes", "the", "specified", "user" ]
1d2db5f00bf5dd0b6c29273541c71c60cdf4d4d4
https://github.com/profitbricks/profitbricks-sdk-go/blob/1d2db5f00bf5dd0b6c29273541c71c60cdf4d4d4/usermanagment.go#L304-L309
test
profitbricks/profitbricks-sdk-go
usermanagment.go
ListResources
func (c *Client) ListResources() (*Resources, error) { url := umResources() + `?depth=` + c.client.depth + `&pretty=` + strconv.FormatBool(c.client.pretty) ret := &Resources{} err := c.client.Get(url, ret, http.StatusOK) return ret, err }
go
func (c *Client) ListResources() (*Resources, error) { url := umResources() + `?depth=` + c.client.depth + `&pretty=` + strconv.FormatBool(c.client.pretty) ret := &Resources{} err := c.client.Get(url, ret, http.StatusOK) return ret, err }
[ "func", "(", "c", "*", "Client", ")", "ListResources", "(", ")", "(", "*", "Resources", ",", "error", ")", "{", "url", ":=", "umResources", "(", ")", "+", "`?depth=`", "+", "c", ".", "client", ".", "depth", "+", "`&pretty=`", "+", "strconv", ".", "FormatBool", "(", "c", ".", "client", ".", "pretty", ")", "\n", "ret", ":=", "&", "Resources", "{", "}", "\n", "err", ":=", "c", ".", "client", ".", "Get", "(", "url", ",", "ret", ",", "http", ".", "StatusOK", ")", "\n", "return", "ret", ",", "err", "\n", "}" ]
//ListResources lists all resources
[ "ListResources", "lists", "all", "resources" ]
1d2db5f00bf5dd0b6c29273541c71c60cdf4d4d4
https://github.com/profitbricks/profitbricks-sdk-go/blob/1d2db5f00bf5dd0b6c29273541c71c60cdf4d4d4/usermanagment.go#L312-L317
test
profitbricks/profitbricks-sdk-go
usermanagment.go
GetResourceByType
func (c *Client) GetResourceByType(resourcetype string, resourceid string) (*Resource, error) { url := umResourcesTypePath(resourcetype, resourceid) + `?depth=` + c.client.depth + `&pretty=` + strconv.FormatBool(c.client.pretty) ret := &Resource{} err := c.client.Get(url, ret, http.StatusOK) return ret, err }
go
func (c *Client) GetResourceByType(resourcetype string, resourceid string) (*Resource, error) { url := umResourcesTypePath(resourcetype, resourceid) + `?depth=` + c.client.depth + `&pretty=` + strconv.FormatBool(c.client.pretty) ret := &Resource{} err := c.client.Get(url, ret, http.StatusOK) return ret, err }
[ "func", "(", "c", "*", "Client", ")", "GetResourceByType", "(", "resourcetype", "string", ",", "resourceid", "string", ")", "(", "*", "Resource", ",", "error", ")", "{", "url", ":=", "umResourcesTypePath", "(", "resourcetype", ",", "resourceid", ")", "+", "`?depth=`", "+", "c", ".", "client", ".", "depth", "+", "`&pretty=`", "+", "strconv", ".", "FormatBool", "(", "c", ".", "client", ".", "pretty", ")", "\n", "ret", ":=", "&", "Resource", "{", "}", "\n", "err", ":=", "c", ".", "client", ".", "Get", "(", "url", ",", "ret", ",", "http", ".", "StatusOK", ")", "\n", "return", "ret", ",", "err", "\n", "}" ]
//GetResourceByType gets a resource by type
[ "GetResourceByType", "gets", "a", "resource", "by", "type" ]
1d2db5f00bf5dd0b6c29273541c71c60cdf4d4d4
https://github.com/profitbricks/profitbricks-sdk-go/blob/1d2db5f00bf5dd0b6c29273541c71c60cdf4d4d4/usermanagment.go#L320-L325
test
profitbricks/profitbricks-sdk-go
usermanagment.go
ListResourcesByType
func (c *Client) ListResourcesByType(resourcetype string) (*Resources, error) { url := umResourcesType(resourcetype) + `?depth=` + c.client.depth + `&pretty=` + strconv.FormatBool(c.client.pretty) ret := &Resources{} err := c.client.Get(url, ret, http.StatusOK) return ret, err }
go
func (c *Client) ListResourcesByType(resourcetype string) (*Resources, error) { url := umResourcesType(resourcetype) + `?depth=` + c.client.depth + `&pretty=` + strconv.FormatBool(c.client.pretty) ret := &Resources{} err := c.client.Get(url, ret, http.StatusOK) return ret, err }
[ "func", "(", "c", "*", "Client", ")", "ListResourcesByType", "(", "resourcetype", "string", ")", "(", "*", "Resources", ",", "error", ")", "{", "url", ":=", "umResourcesType", "(", "resourcetype", ")", "+", "`?depth=`", "+", "c", ".", "client", ".", "depth", "+", "`&pretty=`", "+", "strconv", ".", "FormatBool", "(", "c", ".", "client", ".", "pretty", ")", "\n", "ret", ":=", "&", "Resources", "{", "}", "\n", "err", ":=", "c", ".", "client", ".", "Get", "(", "url", ",", "ret", ",", "http", ".", "StatusOK", ")", "\n", "return", "ret", ",", "err", "\n", "}" ]
//ListResourcesByType list resources by type
[ "ListResourcesByType", "list", "resources", "by", "type" ]
1d2db5f00bf5dd0b6c29273541c71c60cdf4d4d4
https://github.com/profitbricks/profitbricks-sdk-go/blob/1d2db5f00bf5dd0b6c29273541c71c60cdf4d4d4/usermanagment.go#L328-L333
test
profitbricks/profitbricks-sdk-go
request.go
ListRequests
func (c *Client) ListRequests() (*Requests, error) { url := "/requests" + `?depth=` + c.client.depth + `&pretty=` + strconv.FormatBool(c.client.pretty) ret := &Requests{} err := c.client.Get(url, ret, http.StatusOK) return ret, err }
go
func (c *Client) ListRequests() (*Requests, error) { url := "/requests" + `?depth=` + c.client.depth + `&pretty=` + strconv.FormatBool(c.client.pretty) ret := &Requests{} err := c.client.Get(url, ret, http.StatusOK) return ret, err }
[ "func", "(", "c", "*", "Client", ")", "ListRequests", "(", ")", "(", "*", "Requests", ",", "error", ")", "{", "url", ":=", "\"/requests\"", "+", "`?depth=`", "+", "c", ".", "client", ".", "depth", "+", "`&pretty=`", "+", "strconv", ".", "FormatBool", "(", "c", ".", "client", ".", "pretty", ")", "\n", "ret", ":=", "&", "Requests", "{", "}", "\n", "err", ":=", "c", ".", "client", ".", "Get", "(", "url", ",", "ret", ",", "http", ".", "StatusOK", ")", "\n", "return", "ret", ",", "err", "\n", "}" ]
//ListRequests lists all requests
[ "ListRequests", "lists", "all", "requests" ]
1d2db5f00bf5dd0b6c29273541c71c60cdf4d4d4
https://github.com/profitbricks/profitbricks-sdk-go/blob/1d2db5f00bf5dd0b6c29273541c71c60cdf4d4d4/request.go#L72-L77
test
profitbricks/profitbricks-sdk-go
request.go
GetRequest
func (c *Client) GetRequest(reqID string) (*Request, error) { url := "/requests/" + reqID + `?depth=` + c.client.depth + `&pretty=` + strconv.FormatBool(c.client.pretty) ret := &Request{} err := c.client.Get(url, ret, http.StatusOK) return ret, err }
go
func (c *Client) GetRequest(reqID string) (*Request, error) { url := "/requests/" + reqID + `?depth=` + c.client.depth + `&pretty=` + strconv.FormatBool(c.client.pretty) ret := &Request{} err := c.client.Get(url, ret, http.StatusOK) return ret, err }
[ "func", "(", "c", "*", "Client", ")", "GetRequest", "(", "reqID", "string", ")", "(", "*", "Request", ",", "error", ")", "{", "url", ":=", "\"/requests/\"", "+", "reqID", "+", "`?depth=`", "+", "c", ".", "client", ".", "depth", "+", "`&pretty=`", "+", "strconv", ".", "FormatBool", "(", "c", ".", "client", ".", "pretty", ")", "\n", "ret", ":=", "&", "Request", "{", "}", "\n", "err", ":=", "c", ".", "client", ".", "Get", "(", "url", ",", "ret", ",", "http", ".", "StatusOK", ")", "\n", "return", "ret", ",", "err", "\n", "}" ]
//GetRequest gets a specific request
[ "GetRequest", "gets", "a", "specific", "request" ]
1d2db5f00bf5dd0b6c29273541c71c60cdf4d4d4
https://github.com/profitbricks/profitbricks-sdk-go/blob/1d2db5f00bf5dd0b6c29273541c71c60cdf4d4d4/request.go#L80-L85
test
profitbricks/profitbricks-sdk-go
request.go
GetRequestStatus
func (c *Client) GetRequestStatus(path string) (*RequestStatus, error) { url := path + `?depth=` + c.client.depth + `&pretty=` + strconv.FormatBool(c.client.pretty) ret := &RequestStatus{} err := c.client.GetRequestStatus(url, ret, http.StatusOK) return ret, err }
go
func (c *Client) GetRequestStatus(path string) (*RequestStatus, error) { url := path + `?depth=` + c.client.depth + `&pretty=` + strconv.FormatBool(c.client.pretty) ret := &RequestStatus{} err := c.client.GetRequestStatus(url, ret, http.StatusOK) return ret, err }
[ "func", "(", "c", "*", "Client", ")", "GetRequestStatus", "(", "path", "string", ")", "(", "*", "RequestStatus", ",", "error", ")", "{", "url", ":=", "path", "+", "`?depth=`", "+", "c", ".", "client", ".", "depth", "+", "`&pretty=`", "+", "strconv", ".", "FormatBool", "(", "c", ".", "client", ".", "pretty", ")", "\n", "ret", ":=", "&", "RequestStatus", "{", "}", "\n", "err", ":=", "c", ".", "client", ".", "GetRequestStatus", "(", "url", ",", "ret", ",", "http", ".", "StatusOK", ")", "\n", "return", "ret", ",", "err", "\n", "}" ]
// GetRequestStatus retursn status of the request
[ "GetRequestStatus", "retursn", "status", "of", "the", "request" ]
1d2db5f00bf5dd0b6c29273541c71c60cdf4d4d4
https://github.com/profitbricks/profitbricks-sdk-go/blob/1d2db5f00bf5dd0b6c29273541c71c60cdf4d4d4/request.go#L88-L93
test
mipearson/rfw
rfw.go
Close
func (l *Writer) Close() error { l.mutex.Lock() defer l.mutex.Unlock() return l.file.Close() }
go
func (l *Writer) Close() error { l.mutex.Lock() defer l.mutex.Unlock() return l.file.Close() }
[ "func", "(", "l", "*", "Writer", ")", "Close", "(", ")", "error", "{", "l", ".", "mutex", ".", "Lock", "(", ")", "\n", "defer", "l", ".", "mutex", ".", "Unlock", "(", ")", "\n", "return", "l", ".", "file", ".", "Close", "(", ")", "\n", "}" ]
// Close our writer. Subsequent writes will fail.
[ "Close", "our", "writer", ".", "Subsequent", "writes", "will", "fail", "." ]
6f0a6f3266ba1058df9ef0c94cda1cecd2e62852
https://github.com/mipearson/rfw/blob/6f0a6f3266ba1058df9ef0c94cda1cecd2e62852/rfw.go#L55-L60
test
qor/serializable_meta
serializable_meta.go
GetSerializableArgument
func (serialize *SerializableMeta) GetSerializableArgument(serializableMetaInterface SerializableMetaInterface) interface{} { if serialize.Value.OriginalValue != nil { return serialize.Value.OriginalValue } if res := serializableMetaInterface.GetSerializableArgumentResource(); res != nil { value := res.NewStruct() json.Unmarshal([]byte(serialize.Value.SerializedValue), value) return value } return nil }
go
func (serialize *SerializableMeta) GetSerializableArgument(serializableMetaInterface SerializableMetaInterface) interface{} { if serialize.Value.OriginalValue != nil { return serialize.Value.OriginalValue } if res := serializableMetaInterface.GetSerializableArgumentResource(); res != nil { value := res.NewStruct() json.Unmarshal([]byte(serialize.Value.SerializedValue), value) return value } return nil }
[ "func", "(", "serialize", "*", "SerializableMeta", ")", "GetSerializableArgument", "(", "serializableMetaInterface", "SerializableMetaInterface", ")", "interface", "{", "}", "{", "if", "serialize", ".", "Value", ".", "OriginalValue", "!=", "nil", "{", "return", "serialize", ".", "Value", ".", "OriginalValue", "\n", "}", "\n", "if", "res", ":=", "serializableMetaInterface", ".", "GetSerializableArgumentResource", "(", ")", ";", "res", "!=", "nil", "{", "value", ":=", "res", ".", "NewStruct", "(", ")", "\n", "json", ".", "Unmarshal", "(", "[", "]", "byte", "(", "serialize", ".", "Value", ".", "SerializedValue", ")", ",", "value", ")", "\n", "return", "value", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// GetSerializableArgument get serializable argument
[ "GetSerializableArgument", "get", "serializable", "argument" ]
5fd8542db4170c6ce0f8d669b521803b87eb0a99
https://github.com/qor/serializable_meta/blob/5fd8542db4170c6ce0f8d669b521803b87eb0a99/serializable_meta.go#L67-L78
test
ianschenck/envflag
envflag.go
BoolVar
func BoolVar(p *bool, name string, value bool, usage string) { EnvironmentFlags.BoolVar(p, name, value, usage) }
go
func BoolVar(p *bool, name string, value bool, usage string) { EnvironmentFlags.BoolVar(p, name, value, usage) }
[ "func", "BoolVar", "(", "p", "*", "bool", ",", "name", "string", ",", "value", "bool", ",", "usage", "string", ")", "{", "EnvironmentFlags", ".", "BoolVar", "(", "p", ",", "name", ",", "value", ",", "usage", ")", "\n", "}" ]
// BoolVar defines a bool flag with specified name, default value, and // usage string. The argument p points to a bool variable in which to // store the value of the flag.
[ "BoolVar", "defines", "a", "bool", "flag", "with", "specified", "name", "default", "value", "and", "usage", "string", ".", "The", "argument", "p", "points", "to", "a", "bool", "variable", "in", "which", "to", "store", "the", "value", "of", "the", "flag", "." ]
9111d830d133f952887a936367fb0211c3134f0d
https://github.com/ianschenck/envflag/blob/9111d830d133f952887a936367fb0211c3134f0d/envflag.go#L53-L55
test
ianschenck/envflag
envflag.go
Bool
func Bool(name string, value bool, usage string) *bool { return EnvironmentFlags.Bool(name, value, usage) }
go
func Bool(name string, value bool, usage string) *bool { return EnvironmentFlags.Bool(name, value, usage) }
[ "func", "Bool", "(", "name", "string", ",", "value", "bool", ",", "usage", "string", ")", "*", "bool", "{", "return", "EnvironmentFlags", ".", "Bool", "(", "name", ",", "value", ",", "usage", ")", "\n", "}" ]
// Bool defines a bool flag with specified name, default value, and // usage string. The return value is the address of a bool variable // that stores the value of the flag.
[ "Bool", "defines", "a", "bool", "flag", "with", "specified", "name", "default", "value", "and", "usage", "string", ".", "The", "return", "value", "is", "the", "address", "of", "a", "bool", "variable", "that", "stores", "the", "value", "of", "the", "flag", "." ]
9111d830d133f952887a936367fb0211c3134f0d
https://github.com/ianschenck/envflag/blob/9111d830d133f952887a936367fb0211c3134f0d/envflag.go#L60-L62
test
ianschenck/envflag
envflag.go
IntVar
func IntVar(p *int, name string, value int, usage string) { EnvironmentFlags.IntVar(p, name, value, usage) }
go
func IntVar(p *int, name string, value int, usage string) { EnvironmentFlags.IntVar(p, name, value, usage) }
[ "func", "IntVar", "(", "p", "*", "int", ",", "name", "string", ",", "value", "int", ",", "usage", "string", ")", "{", "EnvironmentFlags", ".", "IntVar", "(", "p", ",", "name", ",", "value", ",", "usage", ")", "\n", "}" ]
// IntVar defines an int flag with specified name, default value, and // usage string. The argument p points to an int variable in which to // store the value of the flag.
[ "IntVar", "defines", "an", "int", "flag", "with", "specified", "name", "default", "value", "and", "usage", "string", ".", "The", "argument", "p", "points", "to", "an", "int", "variable", "in", "which", "to", "store", "the", "value", "of", "the", "flag", "." ]
9111d830d133f952887a936367fb0211c3134f0d
https://github.com/ianschenck/envflag/blob/9111d830d133f952887a936367fb0211c3134f0d/envflag.go#L67-L69
test
ianschenck/envflag
envflag.go
Int
func Int(name string, value int, usage string) *int { return EnvironmentFlags.Int(name, value, usage) }
go
func Int(name string, value int, usage string) *int { return EnvironmentFlags.Int(name, value, usage) }
[ "func", "Int", "(", "name", "string", ",", "value", "int", ",", "usage", "string", ")", "*", "int", "{", "return", "EnvironmentFlags", ".", "Int", "(", "name", ",", "value", ",", "usage", ")", "\n", "}" ]
// Int defines an int flag with specified name, default value, and // usage string. The return value is the address of an int variable // that stores the value of the flag.
[ "Int", "defines", "an", "int", "flag", "with", "specified", "name", "default", "value", "and", "usage", "string", ".", "The", "return", "value", "is", "the", "address", "of", "an", "int", "variable", "that", "stores", "the", "value", "of", "the", "flag", "." ]
9111d830d133f952887a936367fb0211c3134f0d
https://github.com/ianschenck/envflag/blob/9111d830d133f952887a936367fb0211c3134f0d/envflag.go#L74-L76
test
ianschenck/envflag
envflag.go
Int64Var
func Int64Var(p *int64, name string, value int64, usage string) { EnvironmentFlags.Int64Var(p, name, value, usage) }
go
func Int64Var(p *int64, name string, value int64, usage string) { EnvironmentFlags.Int64Var(p, name, value, usage) }
[ "func", "Int64Var", "(", "p", "*", "int64", ",", "name", "string", ",", "value", "int64", ",", "usage", "string", ")", "{", "EnvironmentFlags", ".", "Int64Var", "(", "p", ",", "name", ",", "value", ",", "usage", ")", "\n", "}" ]
// Int64Var defines an int64 flag with specified name, default value, // and usage string. The argument p points to an int64 variable in // which to store the value of the flag.
[ "Int64Var", "defines", "an", "int64", "flag", "with", "specified", "name", "default", "value", "and", "usage", "string", ".", "The", "argument", "p", "points", "to", "an", "int64", "variable", "in", "which", "to", "store", "the", "value", "of", "the", "flag", "." ]
9111d830d133f952887a936367fb0211c3134f0d
https://github.com/ianschenck/envflag/blob/9111d830d133f952887a936367fb0211c3134f0d/envflag.go#L81-L83
test
ianschenck/envflag
envflag.go
Int64
func Int64(name string, value int64, usage string) *int64 { return EnvironmentFlags.Int64(name, value, usage) }
go
func Int64(name string, value int64, usage string) *int64 { return EnvironmentFlags.Int64(name, value, usage) }
[ "func", "Int64", "(", "name", "string", ",", "value", "int64", ",", "usage", "string", ")", "*", "int64", "{", "return", "EnvironmentFlags", ".", "Int64", "(", "name", ",", "value", ",", "usage", ")", "\n", "}" ]
// Int64 defines an int64 flag with specified name, default value, and // usage string. The return value is the address of an int64 variable // that stores the value of the flag.
[ "Int64", "defines", "an", "int64", "flag", "with", "specified", "name", "default", "value", "and", "usage", "string", ".", "The", "return", "value", "is", "the", "address", "of", "an", "int64", "variable", "that", "stores", "the", "value", "of", "the", "flag", "." ]
9111d830d133f952887a936367fb0211c3134f0d
https://github.com/ianschenck/envflag/blob/9111d830d133f952887a936367fb0211c3134f0d/envflag.go#L88-L90
test
ianschenck/envflag
envflag.go
UintVar
func UintVar(p *uint, name string, value uint, usage string) { EnvironmentFlags.UintVar(p, name, value, usage) }
go
func UintVar(p *uint, name string, value uint, usage string) { EnvironmentFlags.UintVar(p, name, value, usage) }
[ "func", "UintVar", "(", "p", "*", "uint", ",", "name", "string", ",", "value", "uint", ",", "usage", "string", ")", "{", "EnvironmentFlags", ".", "UintVar", "(", "p", ",", "name", ",", "value", ",", "usage", ")", "\n", "}" ]
// UintVar defines a uint flag with specified name, default value, and // usage string. The argument p points to a uint variable in which to // store the value of the flag.
[ "UintVar", "defines", "a", "uint", "flag", "with", "specified", "name", "default", "value", "and", "usage", "string", ".", "The", "argument", "p", "points", "to", "a", "uint", "variable", "in", "which", "to", "store", "the", "value", "of", "the", "flag", "." ]
9111d830d133f952887a936367fb0211c3134f0d
https://github.com/ianschenck/envflag/blob/9111d830d133f952887a936367fb0211c3134f0d/envflag.go#L95-L97
test
ianschenck/envflag
envflag.go
Uint
func Uint(name string, value uint, usage string) *uint { return EnvironmentFlags.Uint(name, value, usage) }
go
func Uint(name string, value uint, usage string) *uint { return EnvironmentFlags.Uint(name, value, usage) }
[ "func", "Uint", "(", "name", "string", ",", "value", "uint", ",", "usage", "string", ")", "*", "uint", "{", "return", "EnvironmentFlags", ".", "Uint", "(", "name", ",", "value", ",", "usage", ")", "\n", "}" ]
// Uint defines a uint flag with specified name, default value, and // usage string. The return value is the address of a uint variable // that stores the value of the flag.
[ "Uint", "defines", "a", "uint", "flag", "with", "specified", "name", "default", "value", "and", "usage", "string", ".", "The", "return", "value", "is", "the", "address", "of", "a", "uint", "variable", "that", "stores", "the", "value", "of", "the", "flag", "." ]
9111d830d133f952887a936367fb0211c3134f0d
https://github.com/ianschenck/envflag/blob/9111d830d133f952887a936367fb0211c3134f0d/envflag.go#L102-L104
test
ianschenck/envflag
envflag.go
Uint64Var
func Uint64Var(p *uint64, name string, value uint64, usage string) { EnvironmentFlags.Uint64Var(p, name, value, usage) }
go
func Uint64Var(p *uint64, name string, value uint64, usage string) { EnvironmentFlags.Uint64Var(p, name, value, usage) }
[ "func", "Uint64Var", "(", "p", "*", "uint64", ",", "name", "string", ",", "value", "uint64", ",", "usage", "string", ")", "{", "EnvironmentFlags", ".", "Uint64Var", "(", "p", ",", "name", ",", "value", ",", "usage", ")", "\n", "}" ]
// Uint64Var defines a uint64 flag with specified name, default value, // and usage string. The argument p points to a uint64 variable in // which to store the value of the flag.
[ "Uint64Var", "defines", "a", "uint64", "flag", "with", "specified", "name", "default", "value", "and", "usage", "string", ".", "The", "argument", "p", "points", "to", "a", "uint64", "variable", "in", "which", "to", "store", "the", "value", "of", "the", "flag", "." ]
9111d830d133f952887a936367fb0211c3134f0d
https://github.com/ianschenck/envflag/blob/9111d830d133f952887a936367fb0211c3134f0d/envflag.go#L109-L111
test
ianschenck/envflag
envflag.go
Uint64
func Uint64(name string, value uint64, usage string) *uint64 { return EnvironmentFlags.Uint64(name, value, usage) }
go
func Uint64(name string, value uint64, usage string) *uint64 { return EnvironmentFlags.Uint64(name, value, usage) }
[ "func", "Uint64", "(", "name", "string", ",", "value", "uint64", ",", "usage", "string", ")", "*", "uint64", "{", "return", "EnvironmentFlags", ".", "Uint64", "(", "name", ",", "value", ",", "usage", ")", "\n", "}" ]
// Uint64 defines a uint64 flag with specified name, default value, // and usage string. The return value is the address of a uint64 // variable that stores the value of the flag.
[ "Uint64", "defines", "a", "uint64", "flag", "with", "specified", "name", "default", "value", "and", "usage", "string", ".", "The", "return", "value", "is", "the", "address", "of", "a", "uint64", "variable", "that", "stores", "the", "value", "of", "the", "flag", "." ]
9111d830d133f952887a936367fb0211c3134f0d
https://github.com/ianschenck/envflag/blob/9111d830d133f952887a936367fb0211c3134f0d/envflag.go#L116-L118
test
ianschenck/envflag
envflag.go
StringVar
func StringVar(p *string, name string, value string, usage string) { EnvironmentFlags.StringVar(p, name, value, usage) }
go
func StringVar(p *string, name string, value string, usage string) { EnvironmentFlags.StringVar(p, name, value, usage) }
[ "func", "StringVar", "(", "p", "*", "string", ",", "name", "string", ",", "value", "string", ",", "usage", "string", ")", "{", "EnvironmentFlags", ".", "StringVar", "(", "p", ",", "name", ",", "value", ",", "usage", ")", "\n", "}" ]
// StringVar defines a string flag with specified name, default value, // and usage string. The argument p points to a string variable in // which to store the value of the flag.
[ "StringVar", "defines", "a", "string", "flag", "with", "specified", "name", "default", "value", "and", "usage", "string", ".", "The", "argument", "p", "points", "to", "a", "string", "variable", "in", "which", "to", "store", "the", "value", "of", "the", "flag", "." ]
9111d830d133f952887a936367fb0211c3134f0d
https://github.com/ianschenck/envflag/blob/9111d830d133f952887a936367fb0211c3134f0d/envflag.go#L123-L125
test
ianschenck/envflag
envflag.go
String
func String(name string, value string, usage string) *string { return EnvironmentFlags.String(name, value, usage) }
go
func String(name string, value string, usage string) *string { return EnvironmentFlags.String(name, value, usage) }
[ "func", "String", "(", "name", "string", ",", "value", "string", ",", "usage", "string", ")", "*", "string", "{", "return", "EnvironmentFlags", ".", "String", "(", "name", ",", "value", ",", "usage", ")", "\n", "}" ]
// String defines a string flag with specified name, default value, // and usage string. The return value is the address of a string // variable that stores the value of the flag.
[ "String", "defines", "a", "string", "flag", "with", "specified", "name", "default", "value", "and", "usage", "string", ".", "The", "return", "value", "is", "the", "address", "of", "a", "string", "variable", "that", "stores", "the", "value", "of", "the", "flag", "." ]
9111d830d133f952887a936367fb0211c3134f0d
https://github.com/ianschenck/envflag/blob/9111d830d133f952887a936367fb0211c3134f0d/envflag.go#L130-L132
test
ianschenck/envflag
envflag.go
Float64Var
func Float64Var(p *float64, name string, value float64, usage string) { EnvironmentFlags.Float64Var(p, name, value, usage) }
go
func Float64Var(p *float64, name string, value float64, usage string) { EnvironmentFlags.Float64Var(p, name, value, usage) }
[ "func", "Float64Var", "(", "p", "*", "float64", ",", "name", "string", ",", "value", "float64", ",", "usage", "string", ")", "{", "EnvironmentFlags", ".", "Float64Var", "(", "p", ",", "name", ",", "value", ",", "usage", ")", "\n", "}" ]
// Float64Var defines a float64 flag with specified name, default // value, and usage string. The argument p points to a float64 // variable in which to store the value of the flag.
[ "Float64Var", "defines", "a", "float64", "flag", "with", "specified", "name", "default", "value", "and", "usage", "string", ".", "The", "argument", "p", "points", "to", "a", "float64", "variable", "in", "which", "to", "store", "the", "value", "of", "the", "flag", "." ]
9111d830d133f952887a936367fb0211c3134f0d
https://github.com/ianschenck/envflag/blob/9111d830d133f952887a936367fb0211c3134f0d/envflag.go#L137-L139
test
ianschenck/envflag
envflag.go
Float64
func Float64(name string, value float64, usage string) *float64 { return EnvironmentFlags.Float64(name, value, usage) }
go
func Float64(name string, value float64, usage string) *float64 { return EnvironmentFlags.Float64(name, value, usage) }
[ "func", "Float64", "(", "name", "string", ",", "value", "float64", ",", "usage", "string", ")", "*", "float64", "{", "return", "EnvironmentFlags", ".", "Float64", "(", "name", ",", "value", ",", "usage", ")", "\n", "}" ]
// Float64 defines a float64 flag with specified name, default value, // and usage string. The return value is the address of a float64 // variable that stores the value of the flag.
[ "Float64", "defines", "a", "float64", "flag", "with", "specified", "name", "default", "value", "and", "usage", "string", ".", "The", "return", "value", "is", "the", "address", "of", "a", "float64", "variable", "that", "stores", "the", "value", "of", "the", "flag", "." ]
9111d830d133f952887a936367fb0211c3134f0d
https://github.com/ianschenck/envflag/blob/9111d830d133f952887a936367fb0211c3134f0d/envflag.go#L144-L146
test
ianschenck/envflag
envflag.go
DurationVar
func DurationVar(p *time.Duration, name string, value time.Duration, usage string) { EnvironmentFlags.DurationVar(p, name, value, usage) }
go
func DurationVar(p *time.Duration, name string, value time.Duration, usage string) { EnvironmentFlags.DurationVar(p, name, value, usage) }
[ "func", "DurationVar", "(", "p", "*", "time", ".", "Duration", ",", "name", "string", ",", "value", "time", ".", "Duration", ",", "usage", "string", ")", "{", "EnvironmentFlags", ".", "DurationVar", "(", "p", ",", "name", ",", "value", ",", "usage", ")", "\n", "}" ]
// DurationVar defines a time.Duration flag with specified name, // default value, and usage string. The argument p points to a // time.Duration variable in which to store the value of the flag.
[ "DurationVar", "defines", "a", "time", ".", "Duration", "flag", "with", "specified", "name", "default", "value", "and", "usage", "string", ".", "The", "argument", "p", "points", "to", "a", "time", ".", "Duration", "variable", "in", "which", "to", "store", "the", "value", "of", "the", "flag", "." ]
9111d830d133f952887a936367fb0211c3134f0d
https://github.com/ianschenck/envflag/blob/9111d830d133f952887a936367fb0211c3134f0d/envflag.go#L151-L153
test
ianschenck/envflag
envflag.go
Duration
func Duration(name string, value time.Duration, usage string) *time.Duration { return EnvironmentFlags.Duration(name, value, usage) }
go
func Duration(name string, value time.Duration, usage string) *time.Duration { return EnvironmentFlags.Duration(name, value, usage) }
[ "func", "Duration", "(", "name", "string", ",", "value", "time", ".", "Duration", ",", "usage", "string", ")", "*", "time", ".", "Duration", "{", "return", "EnvironmentFlags", ".", "Duration", "(", "name", ",", "value", ",", "usage", ")", "\n", "}" ]
// Duration defines a time.Duration flag with specified name, default // value, and usage string. The return value is the address of a // time.Duration variable that stores the value of the flag.
[ "Duration", "defines", "a", "time", ".", "Duration", "flag", "with", "specified", "name", "default", "value", "and", "usage", "string", ".", "The", "return", "value", "is", "the", "address", "of", "a", "time", ".", "Duration", "variable", "that", "stores", "the", "value", "of", "the", "flag", "." ]
9111d830d133f952887a936367fb0211c3134f0d
https://github.com/ianschenck/envflag/blob/9111d830d133f952887a936367fb0211c3134f0d/envflag.go#L158-L160
test
ianschenck/envflag
envflag.go
Parse
func Parse() { env := os.Environ() // Clean up and "fake" some flag k/v pairs. args := make([]string, 0, len(env)) for _, value := range env { if Lookup(value[:strings.Index(value, "=")]) == nil { continue } args = append(args, fmt.Sprintf("-%s", value)) } EnvironmentFlags.Parse(args) }
go
func Parse() { env := os.Environ() // Clean up and "fake" some flag k/v pairs. args := make([]string, 0, len(env)) for _, value := range env { if Lookup(value[:strings.Index(value, "=")]) == nil { continue } args = append(args, fmt.Sprintf("-%s", value)) } EnvironmentFlags.Parse(args) }
[ "func", "Parse", "(", ")", "{", "env", ":=", "os", ".", "Environ", "(", ")", "\n", "args", ":=", "make", "(", "[", "]", "string", ",", "0", ",", "len", "(", "env", ")", ")", "\n", "for", "_", ",", "value", ":=", "range", "env", "{", "if", "Lookup", "(", "value", "[", ":", "strings", ".", "Index", "(", "value", ",", "\"=\"", ")", "]", ")", "==", "nil", "{", "continue", "\n", "}", "\n", "args", "=", "append", "(", "args", ",", "fmt", ".", "Sprintf", "(", "\"-%s\"", ",", "value", ")", ")", "\n", "}", "\n", "EnvironmentFlags", ".", "Parse", "(", "args", ")", "\n", "}" ]
// Parse parses the environment flags from os.Environ. Must be called // after all flags are defined and before flags are accessed by the // program.
[ "Parse", "parses", "the", "environment", "flags", "from", "os", ".", "Environ", ".", "Must", "be", "called", "after", "all", "flags", "are", "defined", "and", "before", "flags", "are", "accessed", "by", "the", "program", "." ]
9111d830d133f952887a936367fb0211c3134f0d
https://github.com/ianschenck/envflag/blob/9111d830d133f952887a936367fb0211c3134f0d/envflag.go#L171-L182
test
akutz/gotil
gotil.go
WriteStringToFile
func WriteStringToFile(text, path string) error { f, err := os.OpenFile(path, os.O_CREATE|os.O_WRONLY, 0644) defer f.Close() if err != nil { return err } f.WriteString(text) return nil }
go
func WriteStringToFile(text, path string) error { f, err := os.OpenFile(path, os.O_CREATE|os.O_WRONLY, 0644) defer f.Close() if err != nil { return err } f.WriteString(text) return nil }
[ "func", "WriteStringToFile", "(", "text", ",", "path", "string", ")", "error", "{", "f", ",", "err", ":=", "os", ".", "OpenFile", "(", "path", ",", "os", ".", "O_CREATE", "|", "os", ".", "O_WRONLY", ",", "0644", ")", "\n", "defer", "f", ".", "Close", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "f", ".", "WriteString", "(", "text", ")", "\n", "return", "nil", "\n", "}" ]
// WriteStringToFile writes the string to the file at the provided path.
[ "WriteStringToFile", "writes", "the", "string", "to", "the", "file", "at", "the", "provided", "path", "." ]
6fa2e80bd3ac40f15788cfc3d12ebba49a0add92
https://github.com/akutz/gotil/blob/6fa2e80bd3ac40f15788cfc3d12ebba49a0add92/gotil.go#L67-L77
test
akutz/gotil
gotil.go
ReadFileToString
func ReadFileToString(path string) (string, error) { f, err := os.Open(path) if err != nil { return "", err } defer f.Close() scanner := bufio.NewScanner(f) scanner.Scan() return scanner.Text(), nil }
go
func ReadFileToString(path string) (string, error) { f, err := os.Open(path) if err != nil { return "", err } defer f.Close() scanner := bufio.NewScanner(f) scanner.Scan() return scanner.Text(), nil }
[ "func", "ReadFileToString", "(", "path", "string", ")", "(", "string", ",", "error", ")", "{", "f", ",", "err", ":=", "os", ".", "Open", "(", "path", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"\"", ",", "err", "\n", "}", "\n", "defer", "f", ".", "Close", "(", ")", "\n", "scanner", ":=", "bufio", ".", "NewScanner", "(", "f", ")", "\n", "scanner", ".", "Scan", "(", ")", "\n", "return", "scanner", ".", "Text", "(", ")", ",", "nil", "\n", "}" ]
// ReadFileToString reads the file at the provided path to a string.
[ "ReadFileToString", "reads", "the", "file", "at", "the", "provided", "path", "to", "a", "string", "." ]
6fa2e80bd3ac40f15788cfc3d12ebba49a0add92
https://github.com/akutz/gotil/blob/6fa2e80bd3ac40f15788cfc3d12ebba49a0add92/gotil.go#L80-L92
test
akutz/gotil
gotil.go
LineReader
func LineReader(r io.Reader) (<-chan string, error) { return lineReader(func() (io.Reader, func(), error) { return r, nil, nil }) }
go
func LineReader(r io.Reader) (<-chan string, error) { return lineReader(func() (io.Reader, func(), error) { return r, nil, nil }) }
[ "func", "LineReader", "(", "r", "io", ".", "Reader", ")", "(", "<-", "chan", "string", ",", "error", ")", "{", "return", "lineReader", "(", "func", "(", ")", "(", "io", ".", "Reader", ",", "func", "(", ")", ",", "error", ")", "{", "return", "r", ",", "nil", ",", "nil", "}", ")", "\n", "}" ]
// LineReader returns a channel that reads the contents of a reader // line-by-line.
[ "LineReader", "returns", "a", "channel", "that", "reads", "the", "contents", "of", "a", "reader", "line", "-", "by", "-", "line", "." ]
6fa2e80bd3ac40f15788cfc3d12ebba49a0add92
https://github.com/akutz/gotil/blob/6fa2e80bd3ac40f15788cfc3d12ebba49a0add92/gotil.go#L136-L138
test
akutz/gotil
gotil.go
LineReaderFrom
func LineReaderFrom(path string) (<-chan string, error) { return lineReader(func() (io.Reader, func(), error) { if !FileExists(path) { return nil, nil, nil } f, err := os.Open(path) if err != nil { return nil, nil, err } return f, func() { f.Close() }, nil }) }
go
func LineReaderFrom(path string) (<-chan string, error) { return lineReader(func() (io.Reader, func(), error) { if !FileExists(path) { return nil, nil, nil } f, err := os.Open(path) if err != nil { return nil, nil, err } return f, func() { f.Close() }, nil }) }
[ "func", "LineReaderFrom", "(", "path", "string", ")", "(", "<-", "chan", "string", ",", "error", ")", "{", "return", "lineReader", "(", "func", "(", ")", "(", "io", ".", "Reader", ",", "func", "(", ")", ",", "error", ")", "{", "if", "!", "FileExists", "(", "path", ")", "{", "return", "nil", ",", "nil", ",", "nil", "\n", "}", "\n", "f", ",", "err", ":=", "os", ".", "Open", "(", "path", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "nil", ",", "err", "\n", "}", "\n", "return", "f", ",", "func", "(", ")", "{", "f", ".", "Close", "(", ")", "}", ",", "nil", "\n", "}", ")", "\n", "}" ]
// LineReaderFrom returns a channel that reads the contents of a file // line-by-line.
[ "LineReaderFrom", "returns", "a", "channel", "that", "reads", "the", "contents", "of", "a", "file", "line", "-", "by", "-", "line", "." ]
6fa2e80bd3ac40f15788cfc3d12ebba49a0add92
https://github.com/akutz/gotil/blob/6fa2e80bd3ac40f15788cfc3d12ebba49a0add92/gotil.go#L142-L153
test
akutz/gotil
gotil.go
FileExists
func FileExists(filePath string) bool { if _, err := os.Stat(filePath); !os.IsNotExist(err) { return true } return false }
go
func FileExists(filePath string) bool { if _, err := os.Stat(filePath); !os.IsNotExist(err) { return true } return false }
[ "func", "FileExists", "(", "filePath", "string", ")", "bool", "{", "if", "_", ",", "err", ":=", "os", ".", "Stat", "(", "filePath", ")", ";", "!", "os", ".", "IsNotExist", "(", "err", ")", "{", "return", "true", "\n", "}", "\n", "return", "false", "\n", "}" ]
// FileExists returns a flag indicating whether a provided file path exists.
[ "FileExists", "returns", "a", "flag", "indicating", "whether", "a", "provided", "file", "path", "exists", "." ]
6fa2e80bd3ac40f15788cfc3d12ebba49a0add92
https://github.com/akutz/gotil/blob/6fa2e80bd3ac40f15788cfc3d12ebba49a0add92/gotil.go#L156-L161
test
akutz/gotil
gotil.go
FileExistsInPath
func FileExistsInPath(fileName string) bool { _, err := exec.LookPath(fileName) return err == nil }
go
func FileExistsInPath(fileName string) bool { _, err := exec.LookPath(fileName) return err == nil }
[ "func", "FileExistsInPath", "(", "fileName", "string", ")", "bool", "{", "_", ",", "err", ":=", "exec", ".", "LookPath", "(", "fileName", ")", "\n", "return", "err", "==", "nil", "\n", "}" ]
// FileExistsInPath returns a flag indicating whether the provided file exists // in the current path.
[ "FileExistsInPath", "returns", "a", "flag", "indicating", "whether", "the", "provided", "file", "exists", "in", "the", "current", "path", "." ]
6fa2e80bd3ac40f15788cfc3d12ebba49a0add92
https://github.com/akutz/gotil/blob/6fa2e80bd3ac40f15788cfc3d12ebba49a0add92/gotil.go#L165-L168
test
akutz/gotil
gotil.go
GetPathParts
func GetPathParts(path string) (dirPath, fileName, absPath string) { lookup, lookupErr := exec.LookPath(path) if lookupErr == nil { path = lookup } absPath, _ = filepath.Abs(path) dirPath = filepath.Dir(absPath) fileName = filepath.Base(absPath) return }
go
func GetPathParts(path string) (dirPath, fileName, absPath string) { lookup, lookupErr := exec.LookPath(path) if lookupErr == nil { path = lookup } absPath, _ = filepath.Abs(path) dirPath = filepath.Dir(absPath) fileName = filepath.Base(absPath) return }
[ "func", "GetPathParts", "(", "path", "string", ")", "(", "dirPath", ",", "fileName", ",", "absPath", "string", ")", "{", "lookup", ",", "lookupErr", ":=", "exec", ".", "LookPath", "(", "path", ")", "\n", "if", "lookupErr", "==", "nil", "{", "path", "=", "lookup", "\n", "}", "\n", "absPath", ",", "_", "=", "filepath", ".", "Abs", "(", "path", ")", "\n", "dirPath", "=", "filepath", ".", "Dir", "(", "absPath", ")", "\n", "fileName", "=", "filepath", ".", "Base", "(", "absPath", ")", "\n", "return", "\n", "}" ]
// GetPathParts returns the absolute directory path, the file name, and the // absolute path of the provided path string.
[ "GetPathParts", "returns", "the", "absolute", "directory", "path", "the", "file", "name", "and", "the", "absolute", "path", "of", "the", "provided", "path", "string", "." ]
6fa2e80bd3ac40f15788cfc3d12ebba49a0add92
https://github.com/akutz/gotil/blob/6fa2e80bd3ac40f15788cfc3d12ebba49a0add92/gotil.go#L172-L181
test
akutz/gotil
gotil.go
GetThisPathParts
func GetThisPathParts() (dirPath, fileName, absPath string) { exeFile, _ := osext.Executable() return GetPathParts(exeFile) }
go
func GetThisPathParts() (dirPath, fileName, absPath string) { exeFile, _ := osext.Executable() return GetPathParts(exeFile) }
[ "func", "GetThisPathParts", "(", ")", "(", "dirPath", ",", "fileName", ",", "absPath", "string", ")", "{", "exeFile", ",", "_", ":=", "osext", ".", "Executable", "(", ")", "\n", "return", "GetPathParts", "(", "exeFile", ")", "\n", "}" ]
// GetThisPathParts returns the same information as GetPathParts for the // current executable.
[ "GetThisPathParts", "returns", "the", "same", "information", "as", "GetPathParts", "for", "the", "current", "executable", "." ]
6fa2e80bd3ac40f15788cfc3d12ebba49a0add92
https://github.com/akutz/gotil/blob/6fa2e80bd3ac40f15788cfc3d12ebba49a0add92/gotil.go#L185-L188
test
akutz/gotil
gotil.go
RandomString
func RandomString(length int) string { src := rand.NewSource(time.Now().UnixNano()) b := make([]byte, length) for i, cache, remain := length-1, src.Int63(), letterIndexMax; i >= 0; { if remain == 0 { cache, remain = src.Int63(), letterIndexMax } if idx := int(cache & letterIndexMask); idx < len(letterBytes) { b[i] = letterBytes[idx] i-- } cache >>= letterIndexBits remain-- } return string(b) }
go
func RandomString(length int) string { src := rand.NewSource(time.Now().UnixNano()) b := make([]byte, length) for i, cache, remain := length-1, src.Int63(), letterIndexMax; i >= 0; { if remain == 0 { cache, remain = src.Int63(), letterIndexMax } if idx := int(cache & letterIndexMask); idx < len(letterBytes) { b[i] = letterBytes[idx] i-- } cache >>= letterIndexBits remain-- } return string(b) }
[ "func", "RandomString", "(", "length", "int", ")", "string", "{", "src", ":=", "rand", ".", "NewSource", "(", "time", ".", "Now", "(", ")", ".", "UnixNano", "(", ")", ")", "\n", "b", ":=", "make", "(", "[", "]", "byte", ",", "length", ")", "\n", "for", "i", ",", "cache", ",", "remain", ":=", "length", "-", "1", ",", "src", ".", "Int63", "(", ")", ",", "letterIndexMax", ";", "i", ">=", "0", ";", "{", "if", "remain", "==", "0", "{", "cache", ",", "remain", "=", "src", ".", "Int63", "(", ")", ",", "letterIndexMax", "\n", "}", "\n", "if", "idx", ":=", "int", "(", "cache", "&", "letterIndexMask", ")", ";", "idx", "<", "len", "(", "letterBytes", ")", "{", "b", "[", "i", "]", "=", "letterBytes", "[", "idx", "]", "\n", "i", "--", "\n", "}", "\n", "cache", ">>=", "letterIndexBits", "\n", "remain", "--", "\n", "}", "\n", "return", "string", "(", "b", ")", "\n", "}" ]
// RandomString generates a random set of characters with the given lenght.
[ "RandomString", "generates", "a", "random", "set", "of", "characters", "with", "the", "given", "lenght", "." ]
6fa2e80bd3ac40f15788cfc3d12ebba49a0add92
https://github.com/akutz/gotil/blob/6fa2e80bd3ac40f15788cfc3d12ebba49a0add92/gotil.go#L191-L207
test
akutz/gotil
gotil.go
ParseAddress
func ParseAddress(addr string) (proto string, path string, err error) { m := netAddrRx.FindStringSubmatch(addr) if m == nil { return "", "", goof.WithField("address", addr, "invalid address") } return m[1], m[2], nil }
go
func ParseAddress(addr string) (proto string, path string, err error) { m := netAddrRx.FindStringSubmatch(addr) if m == nil { return "", "", goof.WithField("address", addr, "invalid address") } return m[1], m[2], nil }
[ "func", "ParseAddress", "(", "addr", "string", ")", "(", "proto", "string", ",", "path", "string", ",", "err", "error", ")", "{", "m", ":=", "netAddrRx", ".", "FindStringSubmatch", "(", "addr", ")", "\n", "if", "m", "==", "nil", "{", "return", "\"\"", ",", "\"\"", ",", "goof", ".", "WithField", "(", "\"address\"", ",", "addr", ",", "\"invalid address\"", ")", "\n", "}", "\n", "return", "m", "[", "1", "]", ",", "m", "[", "2", "]", ",", "nil", "\n", "}" ]
// ParseAddress parses a standard golang network address and returns the // protocol and path.
[ "ParseAddress", "parses", "a", "standard", "golang", "network", "address", "and", "returns", "the", "protocol", "and", "path", "." ]
6fa2e80bd3ac40f15788cfc3d12ebba49a0add92
https://github.com/akutz/gotil/blob/6fa2e80bd3ac40f15788cfc3d12ebba49a0add92/gotil.go#L226-L232
test
akutz/gotil
gotil.go
HomeDir
func HomeDir() string { if homeDirSet { return homeDir } if user, err := user.Current(); err == nil { homeDir = user.HomeDir } homeDirSet = true return homeDir }
go
func HomeDir() string { if homeDirSet { return homeDir } if user, err := user.Current(); err == nil { homeDir = user.HomeDir } homeDirSet = true return homeDir }
[ "func", "HomeDir", "(", ")", "string", "{", "if", "homeDirSet", "{", "return", "homeDir", "\n", "}", "\n", "if", "user", ",", "err", ":=", "user", ".", "Current", "(", ")", ";", "err", "==", "nil", "{", "homeDir", "=", "user", ".", "HomeDir", "\n", "}", "\n", "homeDirSet", "=", "true", "\n", "return", "homeDir", "\n", "}" ]
// HomeDir returns the home directory of the user that owns the current process.
[ "HomeDir", "returns", "the", "home", "directory", "of", "the", "user", "that", "owns", "the", "current", "process", "." ]
6fa2e80bd3ac40f15788cfc3d12ebba49a0add92
https://github.com/akutz/gotil/blob/6fa2e80bd3ac40f15788cfc3d12ebba49a0add92/gotil.go#L273-L282
test
akutz/gotil
gotil.go
IsTCPPortAvailable
func IsTCPPortAvailable(port int) bool { if port < minTCPPort || port > maxTCPPort { return false } conn, err := net.Listen("tcp", fmt.Sprintf("127.0.0.1:%d", port)) if err != nil { return false } conn.Close() return true }
go
func IsTCPPortAvailable(port int) bool { if port < minTCPPort || port > maxTCPPort { return false } conn, err := net.Listen("tcp", fmt.Sprintf("127.0.0.1:%d", port)) if err != nil { return false } conn.Close() return true }
[ "func", "IsTCPPortAvailable", "(", "port", "int", ")", "bool", "{", "if", "port", "<", "minTCPPort", "||", "port", ">", "maxTCPPort", "{", "return", "false", "\n", "}", "\n", "conn", ",", "err", ":=", "net", ".", "Listen", "(", "\"tcp\"", ",", "fmt", ".", "Sprintf", "(", "\"127.0.0.1:%d\"", ",", "port", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "false", "\n", "}", "\n", "conn", ".", "Close", "(", ")", "\n", "return", "true", "\n", "}" ]
// IsTCPPortAvailable returns a flag indicating whether or not a TCP port is // available.
[ "IsTCPPortAvailable", "returns", "a", "flag", "indicating", "whether", "or", "not", "a", "TCP", "port", "is", "available", "." ]
6fa2e80bd3ac40f15788cfc3d12ebba49a0add92
https://github.com/akutz/gotil/blob/6fa2e80bd3ac40f15788cfc3d12ebba49a0add92/gotil.go#L297-L307
test
akutz/gotil
gotil.go
RandomTCPPort
func RandomTCPPort() int { for i := maxReservedTCPPort; i < maxTCPPort; i++ { p := tcpPortRand.Intn(maxRandTCPPort) + maxReservedTCPPort + 1 if IsTCPPortAvailable(p) { return p } } return -1 }
go
func RandomTCPPort() int { for i := maxReservedTCPPort; i < maxTCPPort; i++ { p := tcpPortRand.Intn(maxRandTCPPort) + maxReservedTCPPort + 1 if IsTCPPortAvailable(p) { return p } } return -1 }
[ "func", "RandomTCPPort", "(", ")", "int", "{", "for", "i", ":=", "maxReservedTCPPort", ";", "i", "<", "maxTCPPort", ";", "i", "++", "{", "p", ":=", "tcpPortRand", ".", "Intn", "(", "maxRandTCPPort", ")", "+", "maxReservedTCPPort", "+", "1", "\n", "if", "IsTCPPortAvailable", "(", "p", ")", "{", "return", "p", "\n", "}", "\n", "}", "\n", "return", "-", "1", "\n", "}" ]
// RandomTCPPort gets a free, random TCP port between 1025-65535. If no free // ports are available -1 is returned.
[ "RandomTCPPort", "gets", "a", "free", "random", "TCP", "port", "between", "1025", "-", "65535", ".", "If", "no", "free", "ports", "are", "available", "-", "1", "is", "returned", "." ]
6fa2e80bd3ac40f15788cfc3d12ebba49a0add92
https://github.com/akutz/gotil/blob/6fa2e80bd3ac40f15788cfc3d12ebba49a0add92/gotil.go#L311-L319
test
piotrkowalczuk/mnemosyne
internal/jump/jump.go
HashString
func HashString(key string, numBuckets int) int32 { // jump.Hash returns values from 0. k := Hash(Sum64(key), numBuckets) return k }
go
func HashString(key string, numBuckets int) int32 { // jump.Hash returns values from 0. k := Hash(Sum64(key), numBuckets) return k }
[ "func", "HashString", "(", "key", "string", ",", "numBuckets", "int", ")", "int32", "{", "k", ":=", "Hash", "(", "Sum64", "(", "key", ")", ",", "numBuckets", ")", "\n", "return", "k", "\n", "}" ]
// HashString works like hash but accept string as an input.
[ "HashString", "works", "like", "hash", "but", "accept", "string", "as", "an", "input", "." ]
66d59c3c5b886e8e869915bb76257bcba4a47250
https://github.com/piotrkowalczuk/mnemosyne/blob/66d59c3c5b886e8e869915bb76257bcba4a47250/internal/jump/jump.go#L33-L38
test
piotrkowalczuk/mnemosyne
mnemosyned/session_manager.go
Context
func (sm *sessionManager) Context(ctx context.Context, req *empty.Empty) (*mnemosynerpc.ContextResponse, error) { md, ok := metadata.FromIncomingContext(ctx) if !ok { return nil, status.Errorf(codes.InvalidArgument, "missing metadata in context, access token cannot be retrieved") } if len(md[mnemosyne.AccessTokenMetadataKey]) == 0 { return nil, status.Errorf(codes.InvalidArgument, "missing access token in metadata") } at := md[mnemosyne.AccessTokenMetadataKey][0] res, err := sm.Get(ctx, &mnemosynerpc.GetRequest{AccessToken: at}) if err != nil { return nil, err } return &mnemosynerpc.ContextResponse{ Session: res.Session, }, nil }
go
func (sm *sessionManager) Context(ctx context.Context, req *empty.Empty) (*mnemosynerpc.ContextResponse, error) { md, ok := metadata.FromIncomingContext(ctx) if !ok { return nil, status.Errorf(codes.InvalidArgument, "missing metadata in context, access token cannot be retrieved") } if len(md[mnemosyne.AccessTokenMetadataKey]) == 0 { return nil, status.Errorf(codes.InvalidArgument, "missing access token in metadata") } at := md[mnemosyne.AccessTokenMetadataKey][0] res, err := sm.Get(ctx, &mnemosynerpc.GetRequest{AccessToken: at}) if err != nil { return nil, err } return &mnemosynerpc.ContextResponse{ Session: res.Session, }, nil }
[ "func", "(", "sm", "*", "sessionManager", ")", "Context", "(", "ctx", "context", ".", "Context", ",", "req", "*", "empty", ".", "Empty", ")", "(", "*", "mnemosynerpc", ".", "ContextResponse", ",", "error", ")", "{", "md", ",", "ok", ":=", "metadata", ".", "FromIncomingContext", "(", "ctx", ")", "\n", "if", "!", "ok", "{", "return", "nil", ",", "status", ".", "Errorf", "(", "codes", ".", "InvalidArgument", ",", "\"missing metadata in context, access token cannot be retrieved\"", ")", "\n", "}", "\n", "if", "len", "(", "md", "[", "mnemosyne", ".", "AccessTokenMetadataKey", "]", ")", "==", "0", "{", "return", "nil", ",", "status", ".", "Errorf", "(", "codes", ".", "InvalidArgument", ",", "\"missing access token in metadata\"", ")", "\n", "}", "\n", "at", ":=", "md", "[", "mnemosyne", ".", "AccessTokenMetadataKey", "]", "[", "0", "]", "\n", "res", ",", "err", ":=", "sm", ".", "Get", "(", "ctx", ",", "&", "mnemosynerpc", ".", "GetRequest", "{", "AccessToken", ":", "at", "}", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "&", "mnemosynerpc", ".", "ContextResponse", "{", "Session", ":", "res", ".", "Session", ",", "}", ",", "nil", "\n", "}" ]
// Context gets implements RPCServer interface.
[ "Context", "gets", "implements", "RPCServer", "interface", "." ]
66d59c3c5b886e8e869915bb76257bcba4a47250
https://github.com/piotrkowalczuk/mnemosyne/blob/66d59c3c5b886e8e869915bb76257bcba4a47250/mnemosyned/session_manager.go#L123-L142
test
piotrkowalczuk/mnemosyne
mnemosynerpc/session.go
Token
func (s *Session) Token() (*oauth2.Token, error) { var ( err error expireAt time.Time ) if s.ExpireAt != nil { expireAt, err = ptypes.Timestamp(s.ExpireAt) if err != nil { return nil, err } } token := &oauth2.Token{ AccessToken: string(s.AccessToken), Expiry: expireAt, } if s.Bag != nil && len(s.Bag) > 0 { token = token.WithExtra(bagToURLValues(s.Bag)) } return token, nil }
go
func (s *Session) Token() (*oauth2.Token, error) { var ( err error expireAt time.Time ) if s.ExpireAt != nil { expireAt, err = ptypes.Timestamp(s.ExpireAt) if err != nil { return nil, err } } token := &oauth2.Token{ AccessToken: string(s.AccessToken), Expiry: expireAt, } if s.Bag != nil && len(s.Bag) > 0 { token = token.WithExtra(bagToURLValues(s.Bag)) } return token, nil }
[ "func", "(", "s", "*", "Session", ")", "Token", "(", ")", "(", "*", "oauth2", ".", "Token", ",", "error", ")", "{", "var", "(", "err", "error", "\n", "expireAt", "time", ".", "Time", "\n", ")", "\n", "if", "s", ".", "ExpireAt", "!=", "nil", "{", "expireAt", ",", "err", "=", "ptypes", ".", "Timestamp", "(", "s", ".", "ExpireAt", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "}", "\n", "token", ":=", "&", "oauth2", ".", "Token", "{", "AccessToken", ":", "string", "(", "s", ".", "AccessToken", ")", ",", "Expiry", ":", "expireAt", ",", "}", "\n", "if", "s", ".", "Bag", "!=", "nil", "&&", "len", "(", "s", ".", "Bag", ")", ">", "0", "{", "token", "=", "token", ".", "WithExtra", "(", "bagToURLValues", "(", "s", ".", "Bag", ")", ")", "\n", "}", "\n", "return", "token", ",", "nil", "\n", "}" ]
// Token implements oauth2.TokenSource interface.
[ "Token", "implements", "oauth2", ".", "TokenSource", "interface", "." ]
66d59c3c5b886e8e869915bb76257bcba4a47250
https://github.com/piotrkowalczuk/mnemosyne/blob/66d59c3c5b886e8e869915bb76257bcba4a47250/mnemosynerpc/session.go#L12-L32
test
piotrkowalczuk/mnemosyne
mnemosyned/daemon.go
NewDaemon
func NewDaemon(opts *DaemonOpts) (*Daemon, error) { d := &Daemon{ done: make(chan struct{}), opts: opts, logger: opts.Logger, serverOptions: opts.RPCOptions, rpcListener: opts.RPCListener, debugListener: opts.DebugListener, } if err := d.setPostgresConnectionParameters(); err != nil { return nil, err } if d.opts.SessionTTL == 0 { d.opts.SessionTTL = storage.DefaultTTL } if d.opts.SessionTTC == 0 { d.opts.SessionTTC = storage.DefaultTTC } if d.opts.Storage == "" { d.opts.Storage = storage.EnginePostgres } if d.opts.PostgresTable == "" { d.opts.PostgresTable = "session" } if d.opts.PostgresSchema == "" { d.opts.PostgresSchema = "mnemosyne" } return d, nil }
go
func NewDaemon(opts *DaemonOpts) (*Daemon, error) { d := &Daemon{ done: make(chan struct{}), opts: opts, logger: opts.Logger, serverOptions: opts.RPCOptions, rpcListener: opts.RPCListener, debugListener: opts.DebugListener, } if err := d.setPostgresConnectionParameters(); err != nil { return nil, err } if d.opts.SessionTTL == 0 { d.opts.SessionTTL = storage.DefaultTTL } if d.opts.SessionTTC == 0 { d.opts.SessionTTC = storage.DefaultTTC } if d.opts.Storage == "" { d.opts.Storage = storage.EnginePostgres } if d.opts.PostgresTable == "" { d.opts.PostgresTable = "session" } if d.opts.PostgresSchema == "" { d.opts.PostgresSchema = "mnemosyne" } return d, nil }
[ "func", "NewDaemon", "(", "opts", "*", "DaemonOpts", ")", "(", "*", "Daemon", ",", "error", ")", "{", "d", ":=", "&", "Daemon", "{", "done", ":", "make", "(", "chan", "struct", "{", "}", ")", ",", "opts", ":", "opts", ",", "logger", ":", "opts", ".", "Logger", ",", "serverOptions", ":", "opts", ".", "RPCOptions", ",", "rpcListener", ":", "opts", ".", "RPCListener", ",", "debugListener", ":", "opts", ".", "DebugListener", ",", "}", "\n", "if", "err", ":=", "d", ".", "setPostgresConnectionParameters", "(", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "if", "d", ".", "opts", ".", "SessionTTL", "==", "0", "{", "d", ".", "opts", ".", "SessionTTL", "=", "storage", ".", "DefaultTTL", "\n", "}", "\n", "if", "d", ".", "opts", ".", "SessionTTC", "==", "0", "{", "d", ".", "opts", ".", "SessionTTC", "=", "storage", ".", "DefaultTTC", "\n", "}", "\n", "if", "d", ".", "opts", ".", "Storage", "==", "\"\"", "{", "d", ".", "opts", ".", "Storage", "=", "storage", ".", "EnginePostgres", "\n", "}", "\n", "if", "d", ".", "opts", ".", "PostgresTable", "==", "\"\"", "{", "d", ".", "opts", ".", "PostgresTable", "=", "\"session\"", "\n", "}", "\n", "if", "d", ".", "opts", ".", "PostgresSchema", "==", "\"\"", "{", "d", ".", "opts", ".", "PostgresSchema", "=", "\"mnemosyne\"", "\n", "}", "\n", "return", "d", ",", "nil", "\n", "}" ]
// NewDaemon allocates new daemon instance using given options.
[ "NewDaemon", "allocates", "new", "daemon", "instance", "using", "given", "options", "." ]
66d59c3c5b886e8e869915bb76257bcba4a47250
https://github.com/piotrkowalczuk/mnemosyne/blob/66d59c3c5b886e8e869915bb76257bcba4a47250/mnemosyned/daemon.go#L83-L113
test
piotrkowalczuk/mnemosyne
mnemosyned/daemon.go
Close
func (d *Daemon) Close() (err error) { d.done <- struct{}{} d.server.GracefulStop() if d.postgres != nil { if err = d.postgres.Close(); err != nil { return } } if d.debugListener != nil { if err = d.debugListener.Close(); err != nil { return } } if d.tracerCloser != nil { if err = d.tracerCloser.Close(); err != nil { return } } return nil }
go
func (d *Daemon) Close() (err error) { d.done <- struct{}{} d.server.GracefulStop() if d.postgres != nil { if err = d.postgres.Close(); err != nil { return } } if d.debugListener != nil { if err = d.debugListener.Close(); err != nil { return } } if d.tracerCloser != nil { if err = d.tracerCloser.Close(); err != nil { return } } return nil }
[ "func", "(", "d", "*", "Daemon", ")", "Close", "(", ")", "(", "err", "error", ")", "{", "d", ".", "done", "<-", "struct", "{", "}", "{", "}", "\n", "d", ".", "server", ".", "GracefulStop", "(", ")", "\n", "if", "d", ".", "postgres", "!=", "nil", "{", "if", "err", "=", "d", ".", "postgres", ".", "Close", "(", ")", ";", "err", "!=", "nil", "{", "return", "\n", "}", "\n", "}", "\n", "if", "d", ".", "debugListener", "!=", "nil", "{", "if", "err", "=", "d", ".", "debugListener", ".", "Close", "(", ")", ";", "err", "!=", "nil", "{", "return", "\n", "}", "\n", "}", "\n", "if", "d", ".", "tracerCloser", "!=", "nil", "{", "if", "err", "=", "d", ".", "tracerCloser", ".", "Close", "(", ")", ";", "err", "!=", "nil", "{", "return", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Close implements io.Closer interface.
[ "Close", "implements", "io", ".", "Closer", "interface", "." ]
66d59c3c5b886e8e869915bb76257bcba4a47250
https://github.com/piotrkowalczuk/mnemosyne/blob/66d59c3c5b886e8e869915bb76257bcba4a47250/mnemosyned/daemon.go#L293-L312
test
piotrkowalczuk/mnemosyne
token.go
NewAccessTokenContext
func NewAccessTokenContext(ctx context.Context, at string) context.Context { return context.WithValue(ctx, accessTokenContextKey, at) }
go
func NewAccessTokenContext(ctx context.Context, at string) context.Context { return context.WithValue(ctx, accessTokenContextKey, at) }
[ "func", "NewAccessTokenContext", "(", "ctx", "context", ".", "Context", ",", "at", "string", ")", "context", ".", "Context", "{", "return", "context", ".", "WithValue", "(", "ctx", ",", "accessTokenContextKey", ",", "at", ")", "\n", "}" ]
// NewAccessTokenContext returns a new Context that carries token value.
[ "NewAccessTokenContext", "returns", "a", "new", "Context", "that", "carries", "token", "value", "." ]
66d59c3c5b886e8e869915bb76257bcba4a47250
https://github.com/piotrkowalczuk/mnemosyne/blob/66d59c3c5b886e8e869915bb76257bcba4a47250/token.go#L22-L24
test
piotrkowalczuk/mnemosyne
token.go
AccessTokenFromContext
func AccessTokenFromContext(ctx context.Context) (string, bool) { at, ok := ctx.Value(accessTokenContextKey).(string) return at, ok }
go
func AccessTokenFromContext(ctx context.Context) (string, bool) { at, ok := ctx.Value(accessTokenContextKey).(string) return at, ok }
[ "func", "AccessTokenFromContext", "(", "ctx", "context", ".", "Context", ")", "(", "string", ",", "bool", ")", "{", "at", ",", "ok", ":=", "ctx", ".", "Value", "(", "accessTokenContextKey", ")", ".", "(", "string", ")", "\n", "return", "at", ",", "ok", "\n", "}" ]
// AccessTokenFromContext returns the token value stored in context, if any.
[ "AccessTokenFromContext", "returns", "the", "token", "value", "stored", "in", "context", "if", "any", "." ]
66d59c3c5b886e8e869915bb76257bcba4a47250
https://github.com/piotrkowalczuk/mnemosyne/blob/66d59c3c5b886e8e869915bb76257bcba4a47250/token.go#L27-L31
test
piotrkowalczuk/mnemosyne
token.go
RandomAccessToken
func RandomAccessToken() (string, error) { buf, err := generateRandomBytes(128) if err != nil { return "", err } // A hash needs to be 64 bytes long to have 256-bit collision resistance. hash := make([]byte, 64) // Compute a 64-byte hash of buf and put it in h. sha3.ShakeSum256(hash, buf) hash2 := make([]byte, hex.EncodedLen(len(hash))) hex.Encode(hash2, hash) return string(hash2), nil }
go
func RandomAccessToken() (string, error) { buf, err := generateRandomBytes(128) if err != nil { return "", err } // A hash needs to be 64 bytes long to have 256-bit collision resistance. hash := make([]byte, 64) // Compute a 64-byte hash of buf and put it in h. sha3.ShakeSum256(hash, buf) hash2 := make([]byte, hex.EncodedLen(len(hash))) hex.Encode(hash2, hash) return string(hash2), nil }
[ "func", "RandomAccessToken", "(", ")", "(", "string", ",", "error", ")", "{", "buf", ",", "err", ":=", "generateRandomBytes", "(", "128", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"\"", ",", "err", "\n", "}", "\n", "hash", ":=", "make", "(", "[", "]", "byte", ",", "64", ")", "\n", "sha3", ".", "ShakeSum256", "(", "hash", ",", "buf", ")", "\n", "hash2", ":=", "make", "(", "[", "]", "byte", ",", "hex", ".", "EncodedLen", "(", "len", "(", "hash", ")", ")", ")", "\n", "hex", ".", "Encode", "(", "hash2", ",", "hash", ")", "\n", "return", "string", "(", "hash2", ")", ",", "nil", "\n", "}" ]
// RandomAccessToken generate Access Token with given key and generated hash of length 64.
[ "RandomAccessToken", "generate", "Access", "Token", "with", "given", "key", "and", "generated", "hash", "of", "length", "64", "." ]
66d59c3c5b886e8e869915bb76257bcba4a47250
https://github.com/piotrkowalczuk/mnemosyne/blob/66d59c3c5b886e8e869915bb76257bcba4a47250/token.go#L34-L47
test
piotrkowalczuk/mnemosyne
internal/service/logger/logger.go
Init
func Init(opts Opts) (logger *zap.Logger, err error) { var ( cfg zap.Config options []zap.Option lvl zapcore.Level ) switch opts.Environment { case "production": cfg = zap.NewProductionConfig() case "stackdriver": cfg = NewStackdriverConfig() options = append(options, zap.Fields(zap.Object("serviceContext", &ServiceContext{ Service: "mnemosyned", Version: opts.Version, }))) case "development": cfg = zap.NewDevelopmentConfig() default: cfg = zap.NewProductionConfig() } if err = lvl.Set(opts.Level); err != nil { return nil, err } cfg.Level.SetLevel(lvl) logger, err = cfg.Build(options...) if err != nil { return nil, err } logger.Info("logger has been initialized", zap.String("environment", opts.Environment)) return logger, nil }
go
func Init(opts Opts) (logger *zap.Logger, err error) { var ( cfg zap.Config options []zap.Option lvl zapcore.Level ) switch opts.Environment { case "production": cfg = zap.NewProductionConfig() case "stackdriver": cfg = NewStackdriverConfig() options = append(options, zap.Fields(zap.Object("serviceContext", &ServiceContext{ Service: "mnemosyned", Version: opts.Version, }))) case "development": cfg = zap.NewDevelopmentConfig() default: cfg = zap.NewProductionConfig() } if err = lvl.Set(opts.Level); err != nil { return nil, err } cfg.Level.SetLevel(lvl) logger, err = cfg.Build(options...) if err != nil { return nil, err } logger.Info("logger has been initialized", zap.String("environment", opts.Environment)) return logger, nil }
[ "func", "Init", "(", "opts", "Opts", ")", "(", "logger", "*", "zap", ".", "Logger", ",", "err", "error", ")", "{", "var", "(", "cfg", "zap", ".", "Config", "\n", "options", "[", "]", "zap", ".", "Option", "\n", "lvl", "zapcore", ".", "Level", "\n", ")", "\n", "switch", "opts", ".", "Environment", "{", "case", "\"production\"", ":", "cfg", "=", "zap", ".", "NewProductionConfig", "(", ")", "\n", "case", "\"stackdriver\"", ":", "cfg", "=", "NewStackdriverConfig", "(", ")", "\n", "options", "=", "append", "(", "options", ",", "zap", ".", "Fields", "(", "zap", ".", "Object", "(", "\"serviceContext\"", ",", "&", "ServiceContext", "{", "Service", ":", "\"mnemosyned\"", ",", "Version", ":", "opts", ".", "Version", ",", "}", ")", ")", ")", "\n", "case", "\"development\"", ":", "cfg", "=", "zap", ".", "NewDevelopmentConfig", "(", ")", "\n", "default", ":", "cfg", "=", "zap", ".", "NewProductionConfig", "(", ")", "\n", "}", "\n", "if", "err", "=", "lvl", ".", "Set", "(", "opts", ".", "Level", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "cfg", ".", "Level", ".", "SetLevel", "(", "lvl", ")", "\n", "logger", ",", "err", "=", "cfg", ".", "Build", "(", "options", "...", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "logger", ".", "Info", "(", "\"logger has been initialized\"", ",", "zap", ".", "String", "(", "\"environment\"", ",", "opts", ".", "Environment", ")", ")", "\n", "return", "logger", ",", "nil", "\n", "}" ]
// Init allocates new logger based on given options.
[ "Init", "allocates", "new", "logger", "based", "on", "given", "options", "." ]
66d59c3c5b886e8e869915bb76257bcba4a47250
https://github.com/piotrkowalczuk/mnemosyne/blob/66d59c3c5b886e8e869915bb76257bcba4a47250/internal/service/logger/logger.go#L34-L67
test
ikawaha/kagome.ipadic
internal/dic/dic.go
Load
func Load(path string) (d *Dic, err error) { d = new(Dic) r, err := zip.OpenReader(path) if err != nil { return d, err } defer r.Close() for _, f := range r.File { if err = func() error { rc, e := f.Open() if e != nil { return e } defer rc.Close() switch f.Name { case "morph.dic": if e = d.loadMorphDicPart(rc); e != nil { return e } case "pos.dic": if e = d.loadPOSDicPart(rc); e != nil { return e } case "content.dic": if e = d.loadContentDicPart(rc); e != nil { return e } case "index.dic": if e = d.loadIndexDicPart(rc); e != nil { return e } case "connection.dic": if e = d.loadConnectionDicPart(rc); e != nil { return e } case "chardef.dic": if e = d.loadCharDefDicPart(rc); e != nil { return e } case "unk.dic": if e = d.loadUnkDicPart(rc); e != nil { return e } } return nil }(); err != nil { return } } return }
go
func Load(path string) (d *Dic, err error) { d = new(Dic) r, err := zip.OpenReader(path) if err != nil { return d, err } defer r.Close() for _, f := range r.File { if err = func() error { rc, e := f.Open() if e != nil { return e } defer rc.Close() switch f.Name { case "morph.dic": if e = d.loadMorphDicPart(rc); e != nil { return e } case "pos.dic": if e = d.loadPOSDicPart(rc); e != nil { return e } case "content.dic": if e = d.loadContentDicPart(rc); e != nil { return e } case "index.dic": if e = d.loadIndexDicPart(rc); e != nil { return e } case "connection.dic": if e = d.loadConnectionDicPart(rc); e != nil { return e } case "chardef.dic": if e = d.loadCharDefDicPart(rc); e != nil { return e } case "unk.dic": if e = d.loadUnkDicPart(rc); e != nil { return e } } return nil }(); err != nil { return } } return }
[ "func", "Load", "(", "path", "string", ")", "(", "d", "*", "Dic", ",", "err", "error", ")", "{", "d", "=", "new", "(", "Dic", ")", "\n", "r", ",", "err", ":=", "zip", ".", "OpenReader", "(", "path", ")", "\n", "if", "err", "!=", "nil", "{", "return", "d", ",", "err", "\n", "}", "\n", "defer", "r", ".", "Close", "(", ")", "\n", "for", "_", ",", "f", ":=", "range", "r", ".", "File", "{", "if", "err", "=", "func", "(", ")", "error", "{", "rc", ",", "e", ":=", "f", ".", "Open", "(", ")", "\n", "if", "e", "!=", "nil", "{", "return", "e", "\n", "}", "\n", "defer", "rc", ".", "Close", "(", ")", "\n", "switch", "f", ".", "Name", "{", "case", "\"morph.dic\"", ":", "if", "e", "=", "d", ".", "loadMorphDicPart", "(", "rc", ")", ";", "e", "!=", "nil", "{", "return", "e", "\n", "}", "\n", "case", "\"pos.dic\"", ":", "if", "e", "=", "d", ".", "loadPOSDicPart", "(", "rc", ")", ";", "e", "!=", "nil", "{", "return", "e", "\n", "}", "\n", "case", "\"content.dic\"", ":", "if", "e", "=", "d", ".", "loadContentDicPart", "(", "rc", ")", ";", "e", "!=", "nil", "{", "return", "e", "\n", "}", "\n", "case", "\"index.dic\"", ":", "if", "e", "=", "d", ".", "loadIndexDicPart", "(", "rc", ")", ";", "e", "!=", "nil", "{", "return", "e", "\n", "}", "\n", "case", "\"connection.dic\"", ":", "if", "e", "=", "d", ".", "loadConnectionDicPart", "(", "rc", ")", ";", "e", "!=", "nil", "{", "return", "e", "\n", "}", "\n", "case", "\"chardef.dic\"", ":", "if", "e", "=", "d", ".", "loadCharDefDicPart", "(", "rc", ")", ";", "e", "!=", "nil", "{", "return", "e", "\n", "}", "\n", "case", "\"unk.dic\"", ":", "if", "e", "=", "d", ".", "loadUnkDicPart", "(", "rc", ")", ";", "e", "!=", "nil", "{", "return", "e", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}", "(", ")", ";", "err", "!=", "nil", "{", "return", "\n", "}", "\n", "}", "\n", "return", "\n", "}" ]
// Load loads a dictionary from a file.
[ "Load", "loads", "a", "dictionary", "from", "a", "file", "." ]
fe03f87a0c7c32945d956fcfc934c3e11d5eb182
https://github.com/ikawaha/kagome.ipadic/blob/fe03f87a0c7c32945d956fcfc934c3e11d5eb182/internal/dic/dic.go#L130-L181
test
piotrkowalczuk/mnemosyne
internal/storage/postgres/storage.go
Start
func (s *Storage) Start(ctx context.Context, accessToken, refreshToken, sid, sc string, b map[string]string) (*mnemosynerpc.Session, error) { span, ctx := opentracing.StartSpanFromContext(ctx, "postgres.storage.start") defer span.Finish() ent := &sessionEntity{ AccessToken: accessToken, RefreshToken: refreshToken, SubjectID: sid, SubjectClient: sc, Bag: model.Bag(b), } if err := s.save(ctx, ent); err != nil { return nil, err } return ent.session() }
go
func (s *Storage) Start(ctx context.Context, accessToken, refreshToken, sid, sc string, b map[string]string) (*mnemosynerpc.Session, error) { span, ctx := opentracing.StartSpanFromContext(ctx, "postgres.storage.start") defer span.Finish() ent := &sessionEntity{ AccessToken: accessToken, RefreshToken: refreshToken, SubjectID: sid, SubjectClient: sc, Bag: model.Bag(b), } if err := s.save(ctx, ent); err != nil { return nil, err } return ent.session() }
[ "func", "(", "s", "*", "Storage", ")", "Start", "(", "ctx", "context", ".", "Context", ",", "accessToken", ",", "refreshToken", ",", "sid", ",", "sc", "string", ",", "b", "map", "[", "string", "]", "string", ")", "(", "*", "mnemosynerpc", ".", "Session", ",", "error", ")", "{", "span", ",", "ctx", ":=", "opentracing", ".", "StartSpanFromContext", "(", "ctx", ",", "\"postgres.storage.start\"", ")", "\n", "defer", "span", ".", "Finish", "(", ")", "\n", "ent", ":=", "&", "sessionEntity", "{", "AccessToken", ":", "accessToken", ",", "RefreshToken", ":", "refreshToken", ",", "SubjectID", ":", "sid", ",", "SubjectClient", ":", "sc", ",", "Bag", ":", "model", ".", "Bag", "(", "b", ")", ",", "}", "\n", "if", "err", ":=", "s", ".", "save", "(", "ctx", ",", "ent", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "ent", ".", "session", "(", ")", "\n", "}" ]
// Start implements storage interface.
[ "Start", "implements", "storage", "interface", "." ]
66d59c3c5b886e8e869915bb76257bcba4a47250
https://github.com/piotrkowalczuk/mnemosyne/blob/66d59c3c5b886e8e869915bb76257bcba4a47250/internal/storage/postgres/storage.go#L98-L115
test
piotrkowalczuk/mnemosyne
internal/storage/postgres/storage.go
Get
func (s *Storage) Get(ctx context.Context, accessToken string) (*mnemosynerpc.Session, error) { span, ctx := opentracing.StartSpanFromContext(ctx, "postgres.storage.get") defer span.Finish() var entity sessionEntity start := time.Now() labels := prometheus.Labels{"query": "get"} err := s.db.QueryRowContext(ctx, s.queryGet, accessToken).Scan( &entity.RefreshToken, &entity.SubjectID, &entity.SubjectClient, &entity.Bag, &entity.ExpireAt, ) s.incQueries(labels, start) if err != nil { s.incError(labels) if err == sql.ErrNoRows { return nil, storage.ErrSessionNotFound } return nil, err } expireAt, err := ptypes.TimestampProto(entity.ExpireAt) if err != nil { return nil, err } return &mnemosynerpc.Session{ AccessToken: accessToken, RefreshToken: entity.RefreshToken, SubjectId: entity.SubjectID, SubjectClient: entity.SubjectClient, Bag: entity.Bag, ExpireAt: expireAt, }, nil }
go
func (s *Storage) Get(ctx context.Context, accessToken string) (*mnemosynerpc.Session, error) { span, ctx := opentracing.StartSpanFromContext(ctx, "postgres.storage.get") defer span.Finish() var entity sessionEntity start := time.Now() labels := prometheus.Labels{"query": "get"} err := s.db.QueryRowContext(ctx, s.queryGet, accessToken).Scan( &entity.RefreshToken, &entity.SubjectID, &entity.SubjectClient, &entity.Bag, &entity.ExpireAt, ) s.incQueries(labels, start) if err != nil { s.incError(labels) if err == sql.ErrNoRows { return nil, storage.ErrSessionNotFound } return nil, err } expireAt, err := ptypes.TimestampProto(entity.ExpireAt) if err != nil { return nil, err } return &mnemosynerpc.Session{ AccessToken: accessToken, RefreshToken: entity.RefreshToken, SubjectId: entity.SubjectID, SubjectClient: entity.SubjectClient, Bag: entity.Bag, ExpireAt: expireAt, }, nil }
[ "func", "(", "s", "*", "Storage", ")", "Get", "(", "ctx", "context", ".", "Context", ",", "accessToken", "string", ")", "(", "*", "mnemosynerpc", ".", "Session", ",", "error", ")", "{", "span", ",", "ctx", ":=", "opentracing", ".", "StartSpanFromContext", "(", "ctx", ",", "\"postgres.storage.get\"", ")", "\n", "defer", "span", ".", "Finish", "(", ")", "\n", "var", "entity", "sessionEntity", "\n", "start", ":=", "time", ".", "Now", "(", ")", "\n", "labels", ":=", "prometheus", ".", "Labels", "{", "\"query\"", ":", "\"get\"", "}", "\n", "err", ":=", "s", ".", "db", ".", "QueryRowContext", "(", "ctx", ",", "s", ".", "queryGet", ",", "accessToken", ")", ".", "Scan", "(", "&", "entity", ".", "RefreshToken", ",", "&", "entity", ".", "SubjectID", ",", "&", "entity", ".", "SubjectClient", ",", "&", "entity", ".", "Bag", ",", "&", "entity", ".", "ExpireAt", ",", ")", "\n", "s", ".", "incQueries", "(", "labels", ",", "start", ")", "\n", "if", "err", "!=", "nil", "{", "s", ".", "incError", "(", "labels", ")", "\n", "if", "err", "==", "sql", ".", "ErrNoRows", "{", "return", "nil", ",", "storage", ".", "ErrSessionNotFound", "\n", "}", "\n", "return", "nil", ",", "err", "\n", "}", "\n", "expireAt", ",", "err", ":=", "ptypes", ".", "TimestampProto", "(", "entity", ".", "ExpireAt", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "&", "mnemosynerpc", ".", "Session", "{", "AccessToken", ":", "accessToken", ",", "RefreshToken", ":", "entity", ".", "RefreshToken", ",", "SubjectId", ":", "entity", ".", "SubjectID", ",", "SubjectClient", ":", "entity", ".", "SubjectClient", ",", "Bag", ":", "entity", ".", "Bag", ",", "ExpireAt", ":", "expireAt", ",", "}", ",", "nil", "\n", "}" ]
// Get implements storage interface.
[ "Get", "implements", "storage", "interface", "." ]
66d59c3c5b886e8e869915bb76257bcba4a47250
https://github.com/piotrkowalczuk/mnemosyne/blob/66d59c3c5b886e8e869915bb76257bcba4a47250/internal/storage/postgres/storage.go#L139-L175
test
piotrkowalczuk/mnemosyne
internal/storage/postgres/storage.go
List
func (s *Storage) List(ctx context.Context, offset, limit int64, expiredAtFrom, expiredAtTo *time.Time) ([]*mnemosynerpc.Session, error) { span, ctx := opentracing.StartSpanFromContext(ctx, "postgres.storage.list") defer span.Finish() if limit == 0 { return nil, errors.New("cannot retrieve list of sessions, limit needs to be higher than 0") } args := []interface{}{offset, limit} query := "SELECT access_token, refresh_token, subject_id, subject_client, bag, expire_at FROM " + s.schema + "." + s.table + " " if expiredAtFrom != nil || expiredAtTo != nil { query += " WHERE " } switch { case expiredAtFrom != nil && expiredAtTo == nil: query += "expire_at > $3" args = append(args, expiredAtFrom) case expiredAtFrom == nil && expiredAtTo != nil: query += "expire_at < $3" args = append(args, expiredAtTo) case expiredAtFrom != nil && expiredAtTo != nil: query += "expire_at > $3 AND expire_at < $4" args = append(args, expiredAtFrom, expiredAtTo) } query += " OFFSET $1 LIMIT $2" labels := prometheus.Labels{"query": "list"} start := time.Now() rows, err := s.db.QueryContext(ctx, query, args...) s.incQueries(labels, start) if err != nil { s.incError(labels) return nil, err } defer rows.Close() sessions := make([]*mnemosynerpc.Session, 0, limit) for rows.Next() { var ent sessionEntity err = rows.Scan( &ent.AccessToken, &ent.RefreshToken, &ent.SubjectID, &ent.SubjectClient, &ent.Bag, &ent.ExpireAt, ) if err != nil { s.incError(labels) return nil, err } expireAt, err := ptypes.TimestampProto(ent.ExpireAt) if err != nil { return nil, err } sessions = append(sessions, &mnemosynerpc.Session{ AccessToken: ent.AccessToken, RefreshToken: ent.RefreshToken, SubjectId: ent.SubjectID, SubjectClient: ent.SubjectClient, Bag: ent.Bag, ExpireAt: expireAt, }) } if rows.Err() != nil { s.incError(labels) return nil, rows.Err() } return sessions, nil }
go
func (s *Storage) List(ctx context.Context, offset, limit int64, expiredAtFrom, expiredAtTo *time.Time) ([]*mnemosynerpc.Session, error) { span, ctx := opentracing.StartSpanFromContext(ctx, "postgres.storage.list") defer span.Finish() if limit == 0 { return nil, errors.New("cannot retrieve list of sessions, limit needs to be higher than 0") } args := []interface{}{offset, limit} query := "SELECT access_token, refresh_token, subject_id, subject_client, bag, expire_at FROM " + s.schema + "." + s.table + " " if expiredAtFrom != nil || expiredAtTo != nil { query += " WHERE " } switch { case expiredAtFrom != nil && expiredAtTo == nil: query += "expire_at > $3" args = append(args, expiredAtFrom) case expiredAtFrom == nil && expiredAtTo != nil: query += "expire_at < $3" args = append(args, expiredAtTo) case expiredAtFrom != nil && expiredAtTo != nil: query += "expire_at > $3 AND expire_at < $4" args = append(args, expiredAtFrom, expiredAtTo) } query += " OFFSET $1 LIMIT $2" labels := prometheus.Labels{"query": "list"} start := time.Now() rows, err := s.db.QueryContext(ctx, query, args...) s.incQueries(labels, start) if err != nil { s.incError(labels) return nil, err } defer rows.Close() sessions := make([]*mnemosynerpc.Session, 0, limit) for rows.Next() { var ent sessionEntity err = rows.Scan( &ent.AccessToken, &ent.RefreshToken, &ent.SubjectID, &ent.SubjectClient, &ent.Bag, &ent.ExpireAt, ) if err != nil { s.incError(labels) return nil, err } expireAt, err := ptypes.TimestampProto(ent.ExpireAt) if err != nil { return nil, err } sessions = append(sessions, &mnemosynerpc.Session{ AccessToken: ent.AccessToken, RefreshToken: ent.RefreshToken, SubjectId: ent.SubjectID, SubjectClient: ent.SubjectClient, Bag: ent.Bag, ExpireAt: expireAt, }) } if rows.Err() != nil { s.incError(labels) return nil, rows.Err() } return sessions, nil }
[ "func", "(", "s", "*", "Storage", ")", "List", "(", "ctx", "context", ".", "Context", ",", "offset", ",", "limit", "int64", ",", "expiredAtFrom", ",", "expiredAtTo", "*", "time", ".", "Time", ")", "(", "[", "]", "*", "mnemosynerpc", ".", "Session", ",", "error", ")", "{", "span", ",", "ctx", ":=", "opentracing", ".", "StartSpanFromContext", "(", "ctx", ",", "\"postgres.storage.list\"", ")", "\n", "defer", "span", ".", "Finish", "(", ")", "\n", "if", "limit", "==", "0", "{", "return", "nil", ",", "errors", ".", "New", "(", "\"cannot retrieve list of sessions, limit needs to be higher than 0\"", ")", "\n", "}", "\n", "args", ":=", "[", "]", "interface", "{", "}", "{", "offset", ",", "limit", "}", "\n", "query", ":=", "\"SELECT access_token, refresh_token, subject_id, subject_client, bag, expire_at FROM \"", "+", "s", ".", "schema", "+", "\".\"", "+", "s", ".", "table", "+", "\" \"", "\n", "if", "expiredAtFrom", "!=", "nil", "||", "expiredAtTo", "!=", "nil", "{", "query", "+=", "\" WHERE \"", "\n", "}", "\n", "switch", "{", "case", "expiredAtFrom", "!=", "nil", "&&", "expiredAtTo", "==", "nil", ":", "query", "+=", "\"expire_at > $3\"", "\n", "args", "=", "append", "(", "args", ",", "expiredAtFrom", ")", "\n", "case", "expiredAtFrom", "==", "nil", "&&", "expiredAtTo", "!=", "nil", ":", "query", "+=", "\"expire_at < $3\"", "\n", "args", "=", "append", "(", "args", ",", "expiredAtTo", ")", "\n", "case", "expiredAtFrom", "!=", "nil", "&&", "expiredAtTo", "!=", "nil", ":", "query", "+=", "\"expire_at > $3 AND expire_at < $4\"", "\n", "args", "=", "append", "(", "args", ",", "expiredAtFrom", ",", "expiredAtTo", ")", "\n", "}", "\n", "query", "+=", "\" OFFSET $1 LIMIT $2\"", "\n", "labels", ":=", "prometheus", ".", "Labels", "{", "\"query\"", ":", "\"list\"", "}", "\n", "start", ":=", "time", ".", "Now", "(", ")", "\n", "rows", ",", "err", ":=", "s", ".", "db", ".", "QueryContext", "(", "ctx", ",", "query", ",", "args", "...", ")", "\n", "s", ".", "incQueries", "(", "labels", ",", "start", ")", "\n", "if", "err", "!=", "nil", "{", "s", ".", "incError", "(", "labels", ")", "\n", "return", "nil", ",", "err", "\n", "}", "\n", "defer", "rows", ".", "Close", "(", ")", "\n", "sessions", ":=", "make", "(", "[", "]", "*", "mnemosynerpc", ".", "Session", ",", "0", ",", "limit", ")", "\n", "for", "rows", ".", "Next", "(", ")", "{", "var", "ent", "sessionEntity", "\n", "err", "=", "rows", ".", "Scan", "(", "&", "ent", ".", "AccessToken", ",", "&", "ent", ".", "RefreshToken", ",", "&", "ent", ".", "SubjectID", ",", "&", "ent", ".", "SubjectClient", ",", "&", "ent", ".", "Bag", ",", "&", "ent", ".", "ExpireAt", ",", ")", "\n", "if", "err", "!=", "nil", "{", "s", ".", "incError", "(", "labels", ")", "\n", "return", "nil", ",", "err", "\n", "}", "\n", "expireAt", ",", "err", ":=", "ptypes", ".", "TimestampProto", "(", "ent", ".", "ExpireAt", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "sessions", "=", "append", "(", "sessions", ",", "&", "mnemosynerpc", ".", "Session", "{", "AccessToken", ":", "ent", ".", "AccessToken", ",", "RefreshToken", ":", "ent", ".", "RefreshToken", ",", "SubjectId", ":", "ent", ".", "SubjectID", ",", "SubjectClient", ":", "ent", ".", "SubjectClient", ",", "Bag", ":", "ent", ".", "Bag", ",", "ExpireAt", ":", "expireAt", ",", "}", ")", "\n", "}", "\n", "if", "rows", ".", "Err", "(", ")", "!=", "nil", "{", "s", ".", "incError", "(", "labels", ")", "\n", "return", "nil", ",", "rows", ".", "Err", "(", ")", "\n", "}", "\n", "return", "sessions", ",", "nil", "\n", "}" ]
// List implements storage interface.
[ "List", "implements", "storage", "interface", "." ]
66d59c3c5b886e8e869915bb76257bcba4a47250
https://github.com/piotrkowalczuk/mnemosyne/blob/66d59c3c5b886e8e869915bb76257bcba4a47250/internal/storage/postgres/storage.go#L178-L251
test
piotrkowalczuk/mnemosyne
internal/storage/postgres/storage.go
Exists
func (s *Storage) Exists(ctx context.Context, accessToken string) (exists bool, err error) { span, ctx := opentracing.StartSpanFromContext(ctx, "postgres.storage.exists") defer span.Finish() start := time.Now() labels := prometheus.Labels{"query": "exists"} err = s.db.QueryRowContext(ctx, s.queryExists, accessToken).Scan( &exists, ) s.incQueries(labels, start) if err != nil { s.incError(labels) } return }
go
func (s *Storage) Exists(ctx context.Context, accessToken string) (exists bool, err error) { span, ctx := opentracing.StartSpanFromContext(ctx, "postgres.storage.exists") defer span.Finish() start := time.Now() labels := prometheus.Labels{"query": "exists"} err = s.db.QueryRowContext(ctx, s.queryExists, accessToken).Scan( &exists, ) s.incQueries(labels, start) if err != nil { s.incError(labels) } return }
[ "func", "(", "s", "*", "Storage", ")", "Exists", "(", "ctx", "context", ".", "Context", ",", "accessToken", "string", ")", "(", "exists", "bool", ",", "err", "error", ")", "{", "span", ",", "ctx", ":=", "opentracing", ".", "StartSpanFromContext", "(", "ctx", ",", "\"postgres.storage.exists\"", ")", "\n", "defer", "span", ".", "Finish", "(", ")", "\n", "start", ":=", "time", ".", "Now", "(", ")", "\n", "labels", ":=", "prometheus", ".", "Labels", "{", "\"query\"", ":", "\"exists\"", "}", "\n", "err", "=", "s", ".", "db", ".", "QueryRowContext", "(", "ctx", ",", "s", ".", "queryExists", ",", "accessToken", ")", ".", "Scan", "(", "&", "exists", ",", ")", "\n", "s", ".", "incQueries", "(", "labels", ",", "start", ")", "\n", "if", "err", "!=", "nil", "{", "s", ".", "incError", "(", "labels", ")", "\n", "}", "\n", "return", "\n", "}" ]
// Exists implements storage interface.
[ "Exists", "implements", "storage", "interface", "." ]
66d59c3c5b886e8e869915bb76257bcba4a47250
https://github.com/piotrkowalczuk/mnemosyne/blob/66d59c3c5b886e8e869915bb76257bcba4a47250/internal/storage/postgres/storage.go#L254-L270
test
piotrkowalczuk/mnemosyne
internal/storage/postgres/storage.go
Abandon
func (s *Storage) Abandon(ctx context.Context, accessToken string) (bool, error) { span, ctx := opentracing.StartSpanFromContext(ctx, "postgres.storage.abandon") defer span.Finish() start := time.Now() labels := prometheus.Labels{"query": "abandon"} result, err := s.db.ExecContext(ctx, s.queryAbandon, accessToken) s.incQueries(labels, start) if err != nil { s.incError(labels) return false, err } affected, err := result.RowsAffected() if err != nil { return false, err } if affected == 0 { return false, storage.ErrSessionNotFound } return true, nil }
go
func (s *Storage) Abandon(ctx context.Context, accessToken string) (bool, error) { span, ctx := opentracing.StartSpanFromContext(ctx, "postgres.storage.abandon") defer span.Finish() start := time.Now() labels := prometheus.Labels{"query": "abandon"} result, err := s.db.ExecContext(ctx, s.queryAbandon, accessToken) s.incQueries(labels, start) if err != nil { s.incError(labels) return false, err } affected, err := result.RowsAffected() if err != nil { return false, err } if affected == 0 { return false, storage.ErrSessionNotFound } return true, nil }
[ "func", "(", "s", "*", "Storage", ")", "Abandon", "(", "ctx", "context", ".", "Context", ",", "accessToken", "string", ")", "(", "bool", ",", "error", ")", "{", "span", ",", "ctx", ":=", "opentracing", ".", "StartSpanFromContext", "(", "ctx", ",", "\"postgres.storage.abandon\"", ")", "\n", "defer", "span", ".", "Finish", "(", ")", "\n", "start", ":=", "time", ".", "Now", "(", ")", "\n", "labels", ":=", "prometheus", ".", "Labels", "{", "\"query\"", ":", "\"abandon\"", "}", "\n", "result", ",", "err", ":=", "s", ".", "db", ".", "ExecContext", "(", "ctx", ",", "s", ".", "queryAbandon", ",", "accessToken", ")", "\n", "s", ".", "incQueries", "(", "labels", ",", "start", ")", "\n", "if", "err", "!=", "nil", "{", "s", ".", "incError", "(", "labels", ")", "\n", "return", "false", ",", "err", "\n", "}", "\n", "affected", ",", "err", ":=", "result", ".", "RowsAffected", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "false", ",", "err", "\n", "}", "\n", "if", "affected", "==", "0", "{", "return", "false", ",", "storage", ".", "ErrSessionNotFound", "\n", "}", "\n", "return", "true", ",", "nil", "\n", "}" ]
// Abandon implements storage interface.
[ "Abandon", "implements", "storage", "interface", "." ]
66d59c3c5b886e8e869915bb76257bcba4a47250
https://github.com/piotrkowalczuk/mnemosyne/blob/66d59c3c5b886e8e869915bb76257bcba4a47250/internal/storage/postgres/storage.go#L273-L296
test
piotrkowalczuk/mnemosyne
internal/storage/postgres/storage.go
SetValue
func (s *Storage) SetValue(ctx context.Context, accessToken string, key, value string) (map[string]string, error) { span, ctx := opentracing.StartSpanFromContext(ctx, "postgres.storage.set-value") defer span.Finish() var err error if accessToken == "" { return nil, storage.ErrMissingAccessToken } entity := &sessionEntity{ AccessToken: accessToken, } selectQuery := ` SELECT bag FROM ` + s.schema + `.` + s.table + ` WHERE access_token = $1 FOR UPDATE ` updateQuery := ` UPDATE ` + s.schema + `.` + s.table + ` SET bag = $2 WHERE access_token = $1 ` tx, err := s.db.BeginTx(ctx, nil) if err != nil { tx.Rollback() return nil, err } startSelect := time.Now() err = tx.QueryRowContext(ctx, selectQuery, accessToken).Scan( &entity.Bag, ) s.incQueries(prometheus.Labels{"query": "set_value_select"}, startSelect) if err != nil { s.incError(prometheus.Labels{"query": "set_value_select"}) tx.Rollback() if err == sql.ErrNoRows { return nil, storage.ErrSessionNotFound } return nil, err } entity.Bag.Set(key, value) startUpdate := time.Now() _, err = tx.ExecContext(ctx, updateQuery, accessToken, entity.Bag) s.incQueries(prometheus.Labels{"query": "set_value_update"}, startUpdate) if err != nil { s.incError(prometheus.Labels{"query": "set_value_update"}) tx.Rollback() return nil, err } tx.Commit() return entity.Bag, nil }
go
func (s *Storage) SetValue(ctx context.Context, accessToken string, key, value string) (map[string]string, error) { span, ctx := opentracing.StartSpanFromContext(ctx, "postgres.storage.set-value") defer span.Finish() var err error if accessToken == "" { return nil, storage.ErrMissingAccessToken } entity := &sessionEntity{ AccessToken: accessToken, } selectQuery := ` SELECT bag FROM ` + s.schema + `.` + s.table + ` WHERE access_token = $1 FOR UPDATE ` updateQuery := ` UPDATE ` + s.schema + `.` + s.table + ` SET bag = $2 WHERE access_token = $1 ` tx, err := s.db.BeginTx(ctx, nil) if err != nil { tx.Rollback() return nil, err } startSelect := time.Now() err = tx.QueryRowContext(ctx, selectQuery, accessToken).Scan( &entity.Bag, ) s.incQueries(prometheus.Labels{"query": "set_value_select"}, startSelect) if err != nil { s.incError(prometheus.Labels{"query": "set_value_select"}) tx.Rollback() if err == sql.ErrNoRows { return nil, storage.ErrSessionNotFound } return nil, err } entity.Bag.Set(key, value) startUpdate := time.Now() _, err = tx.ExecContext(ctx, updateQuery, accessToken, entity.Bag) s.incQueries(prometheus.Labels{"query": "set_value_update"}, startUpdate) if err != nil { s.incError(prometheus.Labels{"query": "set_value_update"}) tx.Rollback() return nil, err } tx.Commit() return entity.Bag, nil }
[ "func", "(", "s", "*", "Storage", ")", "SetValue", "(", "ctx", "context", ".", "Context", ",", "accessToken", "string", ",", "key", ",", "value", "string", ")", "(", "map", "[", "string", "]", "string", ",", "error", ")", "{", "span", ",", "ctx", ":=", "opentracing", ".", "StartSpanFromContext", "(", "ctx", ",", "\"postgres.storage.set-value\"", ")", "\n", "defer", "span", ".", "Finish", "(", ")", "\n", "var", "err", "error", "\n", "if", "accessToken", "==", "\"\"", "{", "return", "nil", ",", "storage", ".", "ErrMissingAccessToken", "\n", "}", "\n", "entity", ":=", "&", "sessionEntity", "{", "AccessToken", ":", "accessToken", ",", "}", "\n", "selectQuery", ":=", "`\t\tSELECT bag\t\tFROM `", "+", "s", ".", "schema", "+", "`.`", "+", "s", ".", "table", "+", "`\t\tWHERE access_token = $1\t\tFOR UPDATE\t`", "\n", "updateQuery", ":=", "`\t\tUPDATE `", "+", "s", ".", "schema", "+", "`.`", "+", "s", ".", "table", "+", "`\t\tSET\t\t\tbag = $2\t\tWHERE access_token = $1\t`", "\n", "tx", ",", "err", ":=", "s", ".", "db", ".", "BeginTx", "(", "ctx", ",", "nil", ")", "\n", "if", "err", "!=", "nil", "{", "tx", ".", "Rollback", "(", ")", "\n", "return", "nil", ",", "err", "\n", "}", "\n", "startSelect", ":=", "time", ".", "Now", "(", ")", "\n", "err", "=", "tx", ".", "QueryRowContext", "(", "ctx", ",", "selectQuery", ",", "accessToken", ")", ".", "Scan", "(", "&", "entity", ".", "Bag", ",", ")", "\n", "s", ".", "incQueries", "(", "prometheus", ".", "Labels", "{", "\"query\"", ":", "\"set_value_select\"", "}", ",", "startSelect", ")", "\n", "if", "err", "!=", "nil", "{", "s", ".", "incError", "(", "prometheus", ".", "Labels", "{", "\"query\"", ":", "\"set_value_select\"", "}", ")", "\n", "tx", ".", "Rollback", "(", ")", "\n", "if", "err", "==", "sql", ".", "ErrNoRows", "{", "return", "nil", ",", "storage", ".", "ErrSessionNotFound", "\n", "}", "\n", "return", "nil", ",", "err", "\n", "}", "\n", "entity", ".", "Bag", ".", "Set", "(", "key", ",", "value", ")", "\n", "startUpdate", ":=", "time", ".", "Now", "(", ")", "\n", "_", ",", "err", "=", "tx", ".", "ExecContext", "(", "ctx", ",", "updateQuery", ",", "accessToken", ",", "entity", ".", "Bag", ")", "\n", "s", ".", "incQueries", "(", "prometheus", ".", "Labels", "{", "\"query\"", ":", "\"set_value_update\"", "}", ",", "startUpdate", ")", "\n", "if", "err", "!=", "nil", "{", "s", ".", "incError", "(", "prometheus", ".", "Labels", "{", "\"query\"", ":", "\"set_value_update\"", "}", ")", "\n", "tx", ".", "Rollback", "(", ")", "\n", "return", "nil", ",", "err", "\n", "}", "\n", "tx", ".", "Commit", "(", ")", "\n", "return", "entity", ".", "Bag", ",", "nil", "\n", "}" ]
// SetValue implements storage interface.
[ "SetValue", "implements", "storage", "interface", "." ]
66d59c3c5b886e8e869915bb76257bcba4a47250
https://github.com/piotrkowalczuk/mnemosyne/blob/66d59c3c5b886e8e869915bb76257bcba4a47250/internal/storage/postgres/storage.go#L299-L358
test
piotrkowalczuk/mnemosyne
internal/storage/postgres/storage.go
Delete
func (s *Storage) Delete(ctx context.Context, subjectID, accessToken, refreshToken string, expiredAtFrom, expiredAtTo *time.Time) (int64, error) { span, ctx := opentracing.StartSpanFromContext(ctx, "postgres.storage.delete") defer span.Finish() where, args := s.where(subjectID, accessToken, refreshToken, expiredAtFrom, expiredAtTo) if where.Len() == 0 { return 0, fmt.Errorf("session cannot be deleted, no where parameter provided: %s", where.String()) } query := "DELETE FROM " + s.schema + "." + s.table + " WHERE " + where.String() labels := prometheus.Labels{"query": "delete"} start := time.Now() result, err := s.db.Exec(query, args...) s.incQueries(labels, start) if err != nil { s.incError(labels) return 0, err } return result.RowsAffected() }
go
func (s *Storage) Delete(ctx context.Context, subjectID, accessToken, refreshToken string, expiredAtFrom, expiredAtTo *time.Time) (int64, error) { span, ctx := opentracing.StartSpanFromContext(ctx, "postgres.storage.delete") defer span.Finish() where, args := s.where(subjectID, accessToken, refreshToken, expiredAtFrom, expiredAtTo) if where.Len() == 0 { return 0, fmt.Errorf("session cannot be deleted, no where parameter provided: %s", where.String()) } query := "DELETE FROM " + s.schema + "." + s.table + " WHERE " + where.String() labels := prometheus.Labels{"query": "delete"} start := time.Now() result, err := s.db.Exec(query, args...) s.incQueries(labels, start) if err != nil { s.incError(labels) return 0, err } return result.RowsAffected() }
[ "func", "(", "s", "*", "Storage", ")", "Delete", "(", "ctx", "context", ".", "Context", ",", "subjectID", ",", "accessToken", ",", "refreshToken", "string", ",", "expiredAtFrom", ",", "expiredAtTo", "*", "time", ".", "Time", ")", "(", "int64", ",", "error", ")", "{", "span", ",", "ctx", ":=", "opentracing", ".", "StartSpanFromContext", "(", "ctx", ",", "\"postgres.storage.delete\"", ")", "\n", "defer", "span", ".", "Finish", "(", ")", "\n", "where", ",", "args", ":=", "s", ".", "where", "(", "subjectID", ",", "accessToken", ",", "refreshToken", ",", "expiredAtFrom", ",", "expiredAtTo", ")", "\n", "if", "where", ".", "Len", "(", ")", "==", "0", "{", "return", "0", ",", "fmt", ".", "Errorf", "(", "\"session cannot be deleted, no where parameter provided: %s\"", ",", "where", ".", "String", "(", ")", ")", "\n", "}", "\n", "query", ":=", "\"DELETE FROM \"", "+", "s", ".", "schema", "+", "\".\"", "+", "s", ".", "table", "+", "\" WHERE \"", "+", "where", ".", "String", "(", ")", "\n", "labels", ":=", "prometheus", ".", "Labels", "{", "\"query\"", ":", "\"delete\"", "}", "\n", "start", ":=", "time", ".", "Now", "(", ")", "\n", "result", ",", "err", ":=", "s", ".", "db", ".", "Exec", "(", "query", ",", "args", "...", ")", "\n", "s", ".", "incQueries", "(", "labels", ",", "start", ")", "\n", "if", "err", "!=", "nil", "{", "s", ".", "incError", "(", "labels", ")", "\n", "return", "0", ",", "err", "\n", "}", "\n", "return", "result", ".", "RowsAffected", "(", ")", "\n", "}" ]
// Delete implements storage interface.
[ "Delete", "implements", "storage", "interface", "." ]
66d59c3c5b886e8e869915bb76257bcba4a47250
https://github.com/piotrkowalczuk/mnemosyne/blob/66d59c3c5b886e8e869915bb76257bcba4a47250/internal/storage/postgres/storage.go#L361-L381
test
piotrkowalczuk/mnemosyne
internal/storage/postgres/storage.go
Setup
func (s *Storage) Setup() error { query := fmt.Sprintf(` CREATE SCHEMA IF NOT EXISTS %s; CREATE TABLE IF NOT EXISTS %s.%s ( access_token BYTEA PRIMARY KEY, refresh_token BYTEA, subject_id TEXT NOT NULL, subject_client TEXT, bag bytea NOT NULL, expire_at TIMESTAMPTZ NOT NULL DEFAULT (NOW() + '%d seconds') ); CREATE INDEX ON %s.%s (refresh_token); CREATE INDEX ON %s.%s (subject_id); CREATE INDEX ON %s.%s (expire_at DESC); `, s.schema, s.schema, s.table, int64(s.ttl.Seconds()), s.schema, s.table, s.schema, s.table, s.schema, s.table, ) _, err := s.db.Exec(query) return err }
go
func (s *Storage) Setup() error { query := fmt.Sprintf(` CREATE SCHEMA IF NOT EXISTS %s; CREATE TABLE IF NOT EXISTS %s.%s ( access_token BYTEA PRIMARY KEY, refresh_token BYTEA, subject_id TEXT NOT NULL, subject_client TEXT, bag bytea NOT NULL, expire_at TIMESTAMPTZ NOT NULL DEFAULT (NOW() + '%d seconds') ); CREATE INDEX ON %s.%s (refresh_token); CREATE INDEX ON %s.%s (subject_id); CREATE INDEX ON %s.%s (expire_at DESC); `, s.schema, s.schema, s.table, int64(s.ttl.Seconds()), s.schema, s.table, s.schema, s.table, s.schema, s.table, ) _, err := s.db.Exec(query) return err }
[ "func", "(", "s", "*", "Storage", ")", "Setup", "(", ")", "error", "{", "query", ":=", "fmt", ".", "Sprintf", "(", "`\t\tCREATE SCHEMA IF NOT EXISTS %s;\t\tCREATE TABLE IF NOT EXISTS %s.%s (\t\t\taccess_token BYTEA PRIMARY KEY,\t\t\trefresh_token BYTEA,\t\t\tsubject_id TEXT NOT NULL,\t\t\tsubject_client TEXT,\t\t\tbag bytea NOT NULL,\t\t\texpire_at TIMESTAMPTZ NOT NULL DEFAULT (NOW() + '%d seconds')\t\t);\t\tCREATE INDEX ON %s.%s (refresh_token);\t\tCREATE INDEX ON %s.%s (subject_id);\t\tCREATE INDEX ON %s.%s (expire_at DESC);\t`", ",", "s", ".", "schema", ",", "s", ".", "schema", ",", "s", ".", "table", ",", "int64", "(", "s", ".", "ttl", ".", "Seconds", "(", ")", ")", ",", "s", ".", "schema", ",", "s", ".", "table", ",", "s", ".", "schema", ",", "s", ".", "table", ",", "s", ".", "schema", ",", "s", ".", "table", ",", ")", "\n", "_", ",", "err", ":=", "s", ".", "db", ".", "Exec", "(", "query", ")", "\n", "return", "err", "\n", "}" ]
// Setup implements storage interface.
[ "Setup", "implements", "storage", "interface", "." ]
66d59c3c5b886e8e869915bb76257bcba4a47250
https://github.com/piotrkowalczuk/mnemosyne/blob/66d59c3c5b886e8e869915bb76257bcba4a47250/internal/storage/postgres/storage.go#L384-L407
test
piotrkowalczuk/mnemosyne
internal/storage/postgres/storage.go
TearDown
func (s *Storage) TearDown() error { _, err := s.db.Exec(`DROP SCHEMA IF EXISTS ` + s.schema + ` CASCADE`) return err }
go
func (s *Storage) TearDown() error { _, err := s.db.Exec(`DROP SCHEMA IF EXISTS ` + s.schema + ` CASCADE`) return err }
[ "func", "(", "s", "*", "Storage", ")", "TearDown", "(", ")", "error", "{", "_", ",", "err", ":=", "s", ".", "db", ".", "Exec", "(", "`DROP SCHEMA IF EXISTS `", "+", "s", ".", "schema", "+", "` CASCADE`", ")", "\n", "return", "err", "\n", "}" ]
// TearDown implements storage interface.
[ "TearDown", "implements", "storage", "interface", "." ]
66d59c3c5b886e8e869915bb76257bcba4a47250
https://github.com/piotrkowalczuk/mnemosyne/blob/66d59c3c5b886e8e869915bb76257bcba4a47250/internal/storage/postgres/storage.go#L410-L414
test
piotrkowalczuk/mnemosyne
mnemosyned/service.go
initJaeger
func initJaeger(service, node, agentAddress string, log *zap.Logger) (opentracing.Tracer, io.Closer, error) { cfg := &config.Configuration{ Sampler: &config.SamplerConfig{ Type: "const", Param: 1, }, Tags: []opentracing.Tag{{ Key: constant.Subsystem + ".listen", Value: node, }}, Reporter: &config.ReporterConfig{ LogSpans: true, LocalAgentHostPort: agentAddress, }, } tracer, closer, err := cfg.New(service, config.Logger(zapjaeger.NewLogger(log))) if err != nil { return nil, nil, err } return tracer, closer, nil }
go
func initJaeger(service, node, agentAddress string, log *zap.Logger) (opentracing.Tracer, io.Closer, error) { cfg := &config.Configuration{ Sampler: &config.SamplerConfig{ Type: "const", Param: 1, }, Tags: []opentracing.Tag{{ Key: constant.Subsystem + ".listen", Value: node, }}, Reporter: &config.ReporterConfig{ LogSpans: true, LocalAgentHostPort: agentAddress, }, } tracer, closer, err := cfg.New(service, config.Logger(zapjaeger.NewLogger(log))) if err != nil { return nil, nil, err } return tracer, closer, nil }
[ "func", "initJaeger", "(", "service", ",", "node", ",", "agentAddress", "string", ",", "log", "*", "zap", ".", "Logger", ")", "(", "opentracing", ".", "Tracer", ",", "io", ".", "Closer", ",", "error", ")", "{", "cfg", ":=", "&", "config", ".", "Configuration", "{", "Sampler", ":", "&", "config", ".", "SamplerConfig", "{", "Type", ":", "\"const\"", ",", "Param", ":", "1", ",", "}", ",", "Tags", ":", "[", "]", "opentracing", ".", "Tag", "{", "{", "Key", ":", "constant", ".", "Subsystem", "+", "\".listen\"", ",", "Value", ":", "node", ",", "}", "}", ",", "Reporter", ":", "&", "config", ".", "ReporterConfig", "{", "LogSpans", ":", "true", ",", "LocalAgentHostPort", ":", "agentAddress", ",", "}", ",", "}", "\n", "tracer", ",", "closer", ",", "err", ":=", "cfg", ".", "New", "(", "service", ",", "config", ".", "Logger", "(", "zapjaeger", ".", "NewLogger", "(", "log", ")", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "nil", ",", "err", "\n", "}", "\n", "return", "tracer", ",", "closer", ",", "nil", "\n", "}" ]
// initJaeger returns an instance of Jaeger Tracer that samples 100% of traces and logs all spans to stdout.
[ "initJaeger", "returns", "an", "instance", "of", "Jaeger", "Tracer", "that", "samples", "100%", "of", "traces", "and", "logs", "all", "spans", "to", "stdout", "." ]
66d59c3c5b886e8e869915bb76257bcba4a47250
https://github.com/piotrkowalczuk/mnemosyne/blob/66d59c3c5b886e8e869915bb76257bcba4a47250/mnemosyned/service.go#L33-L54
test
ikawaha/kagome.ipadic
cmd/kagome/main.go
Usage
func Usage() { fmt.Fprintf(errorWriter, "Japanese Morphological Analyzer -- github.com/ikawaha/kagome.ipadic\n") fmt.Fprintf(errorWriter, "usage: %s <command>\n", path.Base(os.Args[0])) }
go
func Usage() { fmt.Fprintf(errorWriter, "Japanese Morphological Analyzer -- github.com/ikawaha/kagome.ipadic\n") fmt.Fprintf(errorWriter, "usage: %s <command>\n", path.Base(os.Args[0])) }
[ "func", "Usage", "(", ")", "{", "fmt", ".", "Fprintf", "(", "errorWriter", ",", "\"Japanese Morphological Analyzer -- github.com/ikawaha/kagome.ipadic\\n\"", ")", "\n", "\\n", "\n", "}" ]
//Usage prints to stdout information about the tool
[ "Usage", "prints", "to", "stdout", "information", "about", "the", "tool" ]
fe03f87a0c7c32945d956fcfc934c3e11d5eb182
https://github.com/ikawaha/kagome.ipadic/blob/fe03f87a0c7c32945d956fcfc934c3e11d5eb182/cmd/kagome/main.go#L60-L63
test
ikawaha/kagome.ipadic
internal/da/da.go
Build
func Build(keywords []string) (DoubleArray, error) { s := len(keywords) if s == 0 { return DoubleArray{}, nil } ids := make([]int, s, s) for i := range ids { ids[i] = i + 1 } return BuildWithIDs(keywords, ids) }
go
func Build(keywords []string) (DoubleArray, error) { s := len(keywords) if s == 0 { return DoubleArray{}, nil } ids := make([]int, s, s) for i := range ids { ids[i] = i + 1 } return BuildWithIDs(keywords, ids) }
[ "func", "Build", "(", "keywords", "[", "]", "string", ")", "(", "DoubleArray", ",", "error", ")", "{", "s", ":=", "len", "(", "keywords", ")", "\n", "if", "s", "==", "0", "{", "return", "DoubleArray", "{", "}", ",", "nil", "\n", "}", "\n", "ids", ":=", "make", "(", "[", "]", "int", ",", "s", ",", "s", ")", "\n", "for", "i", ":=", "range", "ids", "{", "ids", "[", "i", "]", "=", "i", "+", "1", "\n", "}", "\n", "return", "BuildWithIDs", "(", "keywords", ",", "ids", ")", "\n", "}" ]
// Build constructs a double array from given keywords.
[ "Build", "constructs", "a", "double", "array", "from", "given", "keywords", "." ]
fe03f87a0c7c32945d956fcfc934c3e11d5eb182
https://github.com/ikawaha/kagome.ipadic/blob/fe03f87a0c7c32945d956fcfc934c3e11d5eb182/internal/da/da.go#L37-L47
test
ikawaha/kagome.ipadic
internal/da/da.go
Read
func Read(r io.Reader) (DoubleArray, error) { var sz int64 if e := binary.Read(r, binary.LittleEndian, &sz); e != nil { return DoubleArray{}, e } //fmt.Println("read data len:", sz) d := make(DoubleArray, sz, sz) for i := range d { if e := binary.Read(r, binary.LittleEndian, &d[i].Base); e != nil { return d, e } if e := binary.Read(r, binary.LittleEndian, &d[i].Check); e != nil { return d, e } } return d, nil }
go
func Read(r io.Reader) (DoubleArray, error) { var sz int64 if e := binary.Read(r, binary.LittleEndian, &sz); e != nil { return DoubleArray{}, e } //fmt.Println("read data len:", sz) d := make(DoubleArray, sz, sz) for i := range d { if e := binary.Read(r, binary.LittleEndian, &d[i].Base); e != nil { return d, e } if e := binary.Read(r, binary.LittleEndian, &d[i].Check); e != nil { return d, e } } return d, nil }
[ "func", "Read", "(", "r", "io", ".", "Reader", ")", "(", "DoubleArray", ",", "error", ")", "{", "var", "sz", "int64", "\n", "if", "e", ":=", "binary", ".", "Read", "(", "r", ",", "binary", ".", "LittleEndian", ",", "&", "sz", ")", ";", "e", "!=", "nil", "{", "return", "DoubleArray", "{", "}", ",", "e", "\n", "}", "\n", "d", ":=", "make", "(", "DoubleArray", ",", "sz", ",", "sz", ")", "\n", "for", "i", ":=", "range", "d", "{", "if", "e", ":=", "binary", ".", "Read", "(", "r", ",", "binary", ".", "LittleEndian", ",", "&", "d", "[", "i", "]", ".", "Base", ")", ";", "e", "!=", "nil", "{", "return", "d", ",", "e", "\n", "}", "\n", "if", "e", ":=", "binary", ".", "Read", "(", "r", ",", "binary", ".", "LittleEndian", ",", "&", "d", "[", "i", "]", ".", "Check", ")", ";", "e", "!=", "nil", "{", "return", "d", ",", "e", "\n", "}", "\n", "}", "\n", "return", "d", ",", "nil", "\n", "}" ]
// Read loads a double array.
[ "Read", "loads", "a", "double", "array", "." ]
fe03f87a0c7c32945d956fcfc934c3e11d5eb182
https://github.com/ikawaha/kagome.ipadic/blob/fe03f87a0c7c32945d956fcfc934c3e11d5eb182/internal/da/da.go#L182-L198
test
piotrkowalczuk/mnemosyne
internal/cluster/cluster.go
Get
func (c *Cluster) Get(k int32) (*Node, bool) { if len(c.nodes) == 0 { return nil, false } if len(c.nodes)-1 < int(k) { return nil, false } return c.nodes[k], true }
go
func (c *Cluster) Get(k int32) (*Node, bool) { if len(c.nodes) == 0 { return nil, false } if len(c.nodes)-1 < int(k) { return nil, false } return c.nodes[k], true }
[ "func", "(", "c", "*", "Cluster", ")", "Get", "(", "k", "int32", ")", "(", "*", "Node", ",", "bool", ")", "{", "if", "len", "(", "c", ".", "nodes", ")", "==", "0", "{", "return", "nil", ",", "false", "\n", "}", "\n", "if", "len", "(", "c", ".", "nodes", ")", "-", "1", "<", "int", "(", "k", ")", "{", "return", "nil", ",", "false", "\n", "}", "\n", "return", "c", ".", "nodes", "[", "k", "]", ",", "true", "\n", "}" ]
// Get if possible returns node for a given bucket id.
[ "Get", "if", "possible", "returns", "node", "for", "a", "given", "bucket", "id", "." ]
66d59c3c5b886e8e869915bb76257bcba4a47250
https://github.com/piotrkowalczuk/mnemosyne/blob/66d59c3c5b886e8e869915bb76257bcba4a47250/internal/cluster/cluster.go#L108-L116
test
piotrkowalczuk/mnemosyne
internal/cluster/cluster.go
ExternalNodes
func (c *Cluster) ExternalNodes() (res []*Node) { for _, n := range c.nodes { if n.Addr != c.listen { res = append(res, n) } } return }
go
func (c *Cluster) ExternalNodes() (res []*Node) { for _, n := range c.nodes { if n.Addr != c.listen { res = append(res, n) } } return }
[ "func", "(", "c", "*", "Cluster", ")", "ExternalNodes", "(", ")", "(", "res", "[", "]", "*", "Node", ")", "{", "for", "_", ",", "n", ":=", "range", "c", ".", "nodes", "{", "if", "n", ".", "Addr", "!=", "c", ".", "listen", "{", "res", "=", "append", "(", "res", ",", "n", ")", "\n", "}", "\n", "}", "\n", "return", "\n", "}" ]
// ExternalNodes returns all available nodes except host.
[ "ExternalNodes", "returns", "all", "available", "nodes", "except", "host", "." ]
66d59c3c5b886e8e869915bb76257bcba4a47250
https://github.com/piotrkowalczuk/mnemosyne/blob/66d59c3c5b886e8e869915bb76257bcba4a47250/internal/cluster/cluster.go#L124-L131
test
piotrkowalczuk/mnemosyne
internal/cluster/cluster.go
GetOther
func (c *Cluster) GetOther(accessToken string) (*Node, bool) { if c == nil { return nil, false } if c.Len() == 1 { return nil, false } if node, ok := c.Get(jump.HashString(accessToken, c.Len())); ok { if node.Addr != c.listen { if node.Client != nil { return node, true } } } return nil, false }
go
func (c *Cluster) GetOther(accessToken string) (*Node, bool) { if c == nil { return nil, false } if c.Len() == 1 { return nil, false } if node, ok := c.Get(jump.HashString(accessToken, c.Len())); ok { if node.Addr != c.listen { if node.Client != nil { return node, true } } } return nil, false }
[ "func", "(", "c", "*", "Cluster", ")", "GetOther", "(", "accessToken", "string", ")", "(", "*", "Node", ",", "bool", ")", "{", "if", "c", "==", "nil", "{", "return", "nil", ",", "false", "\n", "}", "\n", "if", "c", ".", "Len", "(", ")", "==", "1", "{", "return", "nil", ",", "false", "\n", "}", "\n", "if", "node", ",", "ok", ":=", "c", ".", "Get", "(", "jump", ".", "HashString", "(", "accessToken", ",", "c", ".", "Len", "(", ")", ")", ")", ";", "ok", "{", "if", "node", ".", "Addr", "!=", "c", ".", "listen", "{", "if", "node", ".", "Client", "!=", "nil", "{", "return", "node", ",", "true", "\n", "}", "\n", "}", "\n", "}", "\n", "return", "nil", ",", "false", "\n", "}" ]
// GetOther returns node for given access token. // Returns false if cluster is nil, has only one element or if node that was found has same listen address as current one.
[ "GetOther", "returns", "node", "for", "given", "access", "token", ".", "Returns", "false", "if", "cluster", "is", "nil", "has", "only", "one", "element", "or", "if", "node", "that", "was", "found", "has", "same", "listen", "address", "as", "current", "one", "." ]
66d59c3c5b886e8e869915bb76257bcba4a47250
https://github.com/piotrkowalczuk/mnemosyne/blob/66d59c3c5b886e8e869915bb76257bcba4a47250/internal/cluster/cluster.go#L145-L161
test
piotrkowalczuk/mnemosyne
internal/cluster/cluster.go
GoString
func (c *Cluster) GoString() string { buf, _ := json.Marshal(map[string]interface{}{ "listen": c.listen, "nodes": c.nodes, "buckets": strconv.FormatInt(int64(c.buckets), 10), }) return string(buf) }
go
func (c *Cluster) GoString() string { buf, _ := json.Marshal(map[string]interface{}{ "listen": c.listen, "nodes": c.nodes, "buckets": strconv.FormatInt(int64(c.buckets), 10), }) return string(buf) }
[ "func", "(", "c", "*", "Cluster", ")", "GoString", "(", ")", "string", "{", "buf", ",", "_", ":=", "json", ".", "Marshal", "(", "map", "[", "string", "]", "interface", "{", "}", "{", "\"listen\"", ":", "c", ".", "listen", ",", "\"nodes\"", ":", "c", ".", "nodes", ",", "\"buckets\"", ":", "strconv", ".", "FormatInt", "(", "int64", "(", "c", ".", "buckets", ")", ",", "10", ")", ",", "}", ")", "\n", "return", "string", "(", "buf", ")", "\n", "}" ]
// GoString implements fmt GoStringer interface.
[ "GoString", "implements", "fmt", "GoStringer", "interface", "." ]
66d59c3c5b886e8e869915bb76257bcba4a47250
https://github.com/piotrkowalczuk/mnemosyne/blob/66d59c3c5b886e8e869915bb76257bcba4a47250/internal/cluster/cluster.go#L164-L171
test
piotrkowalczuk/mnemosyne
internal/model/backpack.go
Scan
func (b *Bag) Scan(src interface{}) (err error) { switch t := src.(type) { case []byte: err = gob.NewDecoder(bytes.NewReader(t)).Decode(b) default: return errors.New("unsupported data source type") } return }
go
func (b *Bag) Scan(src interface{}) (err error) { switch t := src.(type) { case []byte: err = gob.NewDecoder(bytes.NewReader(t)).Decode(b) default: return errors.New("unsupported data source type") } return }
[ "func", "(", "b", "*", "Bag", ")", "Scan", "(", "src", "interface", "{", "}", ")", "(", "err", "error", ")", "{", "switch", "t", ":=", "src", ".", "(", "type", ")", "{", "case", "[", "]", "byte", ":", "err", "=", "gob", ".", "NewDecoder", "(", "bytes", ".", "NewReader", "(", "t", ")", ")", ".", "Decode", "(", "b", ")", "\n", "default", ":", "return", "errors", ".", "New", "(", "\"unsupported data source type\"", ")", "\n", "}", "\n", "return", "\n", "}" ]
// Scan satisfy sql.Scanner interface.
[ "Scan", "satisfy", "sql", ".", "Scanner", "interface", "." ]
66d59c3c5b886e8e869915bb76257bcba4a47250
https://github.com/piotrkowalczuk/mnemosyne/blob/66d59c3c5b886e8e869915bb76257bcba4a47250/internal/model/backpack.go#L15-L24
test
piotrkowalczuk/mnemosyne
internal/model/backpack.go
Value
func (b Bag) Value() (driver.Value, error) { buf := bytes.NewBuffer(nil) err := gob.NewEncoder(buf).Encode(b) if err != nil { return nil, err } return buf.Bytes(), nil }
go
func (b Bag) Value() (driver.Value, error) { buf := bytes.NewBuffer(nil) err := gob.NewEncoder(buf).Encode(b) if err != nil { return nil, err } return buf.Bytes(), nil }
[ "func", "(", "b", "Bag", ")", "Value", "(", ")", "(", "driver", ".", "Value", ",", "error", ")", "{", "buf", ":=", "bytes", ".", "NewBuffer", "(", "nil", ")", "\n", "err", ":=", "gob", ".", "NewEncoder", "(", "buf", ")", ".", "Encode", "(", "b", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "buf", ".", "Bytes", "(", ")", ",", "nil", "\n", "}" ]
// Value satisfy driver.Valuer interface.
[ "Value", "satisfy", "driver", ".", "Valuer", "interface", "." ]
66d59c3c5b886e8e869915bb76257bcba4a47250
https://github.com/piotrkowalczuk/mnemosyne/blob/66d59c3c5b886e8e869915bb76257bcba4a47250/internal/model/backpack.go#L27-L35
test
piotrkowalczuk/mnemosyne
internal/model/backpack.go
Has
func (b *Bag) Has(key string) bool { _, ok := (*b)[key] return ok }
go
func (b *Bag) Has(key string) bool { _, ok := (*b)[key] return ok }
[ "func", "(", "b", "*", "Bag", ")", "Has", "(", "key", "string", ")", "bool", "{", "_", ",", "ok", ":=", "(", "*", "b", ")", "[", "key", "]", "\n", "return", "ok", "\n", "}" ]
// Has checks if the given key is set.
[ "Has", "checks", "if", "the", "given", "key", "is", "set", "." ]
66d59c3c5b886e8e869915bb76257bcba4a47250
https://github.com/piotrkowalczuk/mnemosyne/blob/66d59c3c5b886e8e869915bb76257bcba4a47250/internal/model/backpack.go#L48-L52
test