id
int32
0
167k
repo
stringlengths
5
54
path
stringlengths
4
155
func_name
stringlengths
1
118
original_string
stringlengths
52
85.5k
language
stringclasses
1 value
code
stringlengths
52
85.5k
code_tokens
list
docstring
stringlengths
6
2.61k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
85
252
18,100
rsc/rsc
smugmug/smug.go
Albums
func (c *Conn) Albums(nick string) ([]*Album, error) { var out struct { Albums []*Album } if err := c.do("smugmug.albums.get", &out, "NickName", nick); err != nil { return nil, err } return out.Albums, nil }
go
func (c *Conn) Albums(nick string) ([]*Album, error) { var out struct { Albums []*Album } if err := c.do("smugmug.albums.get", &out, "NickName", nick); err != nil { return nil, err } return out.Albums, nil }
[ "func", "(", "c", "*", "Conn", ")", "Albums", "(", "nick", "string", ")", "(", "[", "]", "*", "Album", ",", "error", ")", "{", "var", "out", "struct", "{", "Albums", "[", "]", "*", "Album", "\n", "}", "\n", "if", "err", ":=", "c", ".", "do", ...
// Albums returns the albums for the user identified by the nick name. // Use c.NickName for the logged-in user.
[ "Albums", "returns", "the", "albums", "for", "the", "user", "identified", "by", "the", "nick", "name", ".", "Use", "c", ".", "NickName", "for", "the", "logged", "-", "in", "user", "." ]
fc62025902295658a9c7e89418e095fd598b2682
https://github.com/rsc/rsc/blob/fc62025902295658a9c7e89418e095fd598b2682/smugmug/smug.go#L118-L126
18,101
rsc/rsc
smugmug/smug.go
CreateAlbum
func (c *Conn) CreateAlbum(title string) (*Album, error) { var out struct { Album *Album } if err := c.do("smugmug.albums.create", &out, "Title", title, "Public", "0", "WorldSearchable", "0", "SmugSearchable", "0", ); err != nil { return nil, err } if out.Album == nil || out.Album.Key == "" { return nil, fmt.Errorf("unable to parse SmugMug result") } return out.Album, nil }
go
func (c *Conn) CreateAlbum(title string) (*Album, error) { var out struct { Album *Album } if err := c.do("smugmug.albums.create", &out, "Title", title, "Public", "0", "WorldSearchable", "0", "SmugSearchable", "0", ); err != nil { return nil, err } if out.Album == nil || out.Album.Key == "" { return nil, fmt.Errorf("unable to parse SmugMug result") } return out.Album, nil }
[ "func", "(", "c", "*", "Conn", ")", "CreateAlbum", "(", "title", "string", ")", "(", "*", "Album", ",", "error", ")", "{", "var", "out", "struct", "{", "Album", "*", "Album", "\n", "}", "\n", "if", "err", ":=", "c", ".", "do", "(", "\"", "\"", ...
// CreateAlbum creates a new album.
[ "CreateAlbum", "creates", "a", "new", "album", "." ]
fc62025902295658a9c7e89418e095fd598b2682
https://github.com/rsc/rsc/blob/fc62025902295658a9c7e89418e095fd598b2682/smugmug/smug.go#L129-L146
18,102
rsc/rsc
smugmug/smug.go
AlbumInfo
func (c *Conn) AlbumInfo(album *Album) (*AlbumInfo, error) { var out struct { Album *AlbumInfo } if err := c.do("smugmug.albums.getInfo", &out, "AlbumID", itoa64(album.ID), "AlbumKey", album.Key, ); err != nil { return nil, err } if out.Album == nil || out.Album.ID == 0 { return nil, fmt.Errorf("unable to parse SmugMug result") } return out.Album, nil }
go
func (c *Conn) AlbumInfo(album *Album) (*AlbumInfo, error) { var out struct { Album *AlbumInfo } if err := c.do("smugmug.albums.getInfo", &out, "AlbumID", itoa64(album.ID), "AlbumKey", album.Key, ); err != nil { return nil, err } if out.Album == nil || out.Album.ID == 0 { return nil, fmt.Errorf("unable to parse SmugMug result") } return out.Album, nil }
[ "func", "(", "c", "*", "Conn", ")", "AlbumInfo", "(", "album", "*", "Album", ")", "(", "*", "AlbumInfo", ",", "error", ")", "{", "var", "out", "struct", "{", "Album", "*", "AlbumInfo", "\n", "}", "\n", "if", "err", ":=", "c", ".", "do", "(", "\...
// AlbumInfo returns detailed metadata about an album.
[ "AlbumInfo", "returns", "detailed", "metadata", "about", "an", "album", "." ]
fc62025902295658a9c7e89418e095fd598b2682
https://github.com/rsc/rsc/blob/fc62025902295658a9c7e89418e095fd598b2682/smugmug/smug.go#L149-L164
18,103
rsc/rsc
smugmug/smug.go
DeleteAlbum
func (c *Conn) DeleteAlbum(album *Album) error { return c.do("smugmug.albums.delete", nil, "AlbumID", itoa64(album.ID)) }
go
func (c *Conn) DeleteAlbum(album *Album) error { return c.do("smugmug.albums.delete", nil, "AlbumID", itoa64(album.ID)) }
[ "func", "(", "c", "*", "Conn", ")", "DeleteAlbum", "(", "album", "*", "Album", ")", "error", "{", "return", "c", ".", "do", "(", "\"", "\"", ",", "nil", ",", "\"", "\"", ",", "itoa64", "(", "album", ".", "ID", ")", ")", "\n", "}" ]
// DeleteAlbum deletes an album.
[ "DeleteAlbum", "deletes", "an", "album", "." ]
fc62025902295658a9c7e89418e095fd598b2682
https://github.com/rsc/rsc/blob/fc62025902295658a9c7e89418e095fd598b2682/smugmug/smug.go#L261-L263
18,104
rsc/rsc
smugmug/smug.go
Images
func (c *Conn) Images(album *Album) ([]*Image, error) { var out struct { Album struct { Images []*Image } } if err := c.do("smugmug.images.get", &out, "AlbumID", itoa64(album.ID), "AlbumKey", album.Key, "Heavy", "1", ); err != nil { return nil, err } return out.Album.Images, nil }
go
func (c *Conn) Images(album *Album) ([]*Image, error) { var out struct { Album struct { Images []*Image } } if err := c.do("smugmug.images.get", &out, "AlbumID", itoa64(album.ID), "AlbumKey", album.Key, "Heavy", "1", ); err != nil { return nil, err } return out.Album.Images, nil }
[ "func", "(", "c", "*", "Conn", ")", "Images", "(", "album", "*", "Album", ")", "(", "[", "]", "*", "Image", ",", "error", ")", "{", "var", "out", "struct", "{", "Album", "struct", "{", "Images", "[", "]", "*", "Image", "\n", "}", "\n", "}", "...
// Images returns a list of images for an album.
[ "Images", "returns", "a", "list", "of", "images", "for", "an", "album", "." ]
fc62025902295658a9c7e89418e095fd598b2682
https://github.com/rsc/rsc/blob/fc62025902295658a9c7e89418e095fd598b2682/smugmug/smug.go#L273-L289
18,105
rsc/rsc
smugmug/smug.go
ImageInfo
func (c *Conn) ImageInfo(image *Image) (*ImageInfo, error) { var out struct { Image *ImageInfo } if err := c.do("smugmug.images.getInfo", &out, "ImageID", itoa64(image.ID), "ImageKey", image.Key, ); err != nil { return nil, err } if out.Image == nil || out.Image.ID == 0 { return nil, fmt.Errorf("unable to parse SmugMug result") } return out.Image, nil }
go
func (c *Conn) ImageInfo(image *Image) (*ImageInfo, error) { var out struct { Image *ImageInfo } if err := c.do("smugmug.images.getInfo", &out, "ImageID", itoa64(image.ID), "ImageKey", image.Key, ); err != nil { return nil, err } if out.Image == nil || out.Image.ID == 0 { return nil, fmt.Errorf("unable to parse SmugMug result") } return out.Image, nil }
[ "func", "(", "c", "*", "Conn", ")", "ImageInfo", "(", "image", "*", "Image", ")", "(", "*", "ImageInfo", ",", "error", ")", "{", "var", "out", "struct", "{", "Image", "*", "ImageInfo", "\n", "}", "\n", "if", "err", ":=", "c", ".", "do", "(", "\...
// ImageInfo returns detailed metadata about an image.
[ "ImageInfo", "returns", "detailed", "metadata", "about", "an", "image", "." ]
fc62025902295658a9c7e89418e095fd598b2682
https://github.com/rsc/rsc/blob/fc62025902295658a9c7e89418e095fd598b2682/smugmug/smug.go#L331-L346
18,106
rsc/rsc
smugmug/smug.go
DeleteImage
func (c *Conn) DeleteImage(image *Image) error { return c.do("smugmug.images.delete", nil, "ImageID", itoa64(image.ID)) }
go
func (c *Conn) DeleteImage(image *Image) error { return c.do("smugmug.images.delete", nil, "ImageID", itoa64(image.ID)) }
[ "func", "(", "c", "*", "Conn", ")", "DeleteImage", "(", "image", "*", "Image", ")", "error", "{", "return", "c", ".", "do", "(", "\"", "\"", ",", "nil", ",", "\"", "\"", ",", "itoa64", "(", "image", ".", "ID", ")", ")", "\n", "}" ]
// DeleteImage deletes an image.
[ "DeleteImage", "deletes", "an", "image", "." ]
fc62025902295658a9c7e89418e095fd598b2682
https://github.com/rsc/rsc/blob/fc62025902295658a9c7e89418e095fd598b2682/smugmug/smug.go#L415-L417
18,107
rsc/rsc
smugmug/smug.go
AddImage
func (c *Conn) AddImage(name string, data []byte, a *Album) (*Image, error) { return c.upload(name, data, "AlbumID", a.ID) }
go
func (c *Conn) AddImage(name string, data []byte, a *Album) (*Image, error) { return c.upload(name, data, "AlbumID", a.ID) }
[ "func", "(", "c", "*", "Conn", ")", "AddImage", "(", "name", "string", ",", "data", "[", "]", "byte", ",", "a", "*", "Album", ")", "(", "*", "Image", ",", "error", ")", "{", "return", "c", ".", "upload", "(", "name", ",", "data", ",", "\"", "...
// AddImage uploads a new image to an album. // The name is the file name that will be displayed on SmugMug. // The data is the raw image data.
[ "AddImage", "uploads", "a", "new", "image", "to", "an", "album", ".", "The", "name", "is", "the", "file", "name", "that", "will", "be", "displayed", "on", "SmugMug", ".", "The", "data", "is", "the", "raw", "image", "data", "." ]
fc62025902295658a9c7e89418e095fd598b2682
https://github.com/rsc/rsc/blob/fc62025902295658a9c7e89418e095fd598b2682/smugmug/smug.go#L422-L424
18,108
rsc/rsc
smugmug/smug.go
ReplaceImage
func (c *Conn) ReplaceImage(name string, data []byte, image *Image) (*Image, error) { return c.upload(name, data, "ImageID", image.ID) }
go
func (c *Conn) ReplaceImage(name string, data []byte, image *Image) (*Image, error) { return c.upload(name, data, "ImageID", image.ID) }
[ "func", "(", "c", "*", "Conn", ")", "ReplaceImage", "(", "name", "string", ",", "data", "[", "]", "byte", ",", "image", "*", "Image", ")", "(", "*", "Image", ",", "error", ")", "{", "return", "c", ".", "upload", "(", "name", ",", "data", ",", "...
// ReplaceImage replaces an image. // The name is the file name that will be displayed on SmugMug. // The data is the raw image data.
[ "ReplaceImage", "replaces", "an", "image", ".", "The", "name", "is", "the", "file", "name", "that", "will", "be", "displayed", "on", "SmugMug", ".", "The", "data", "is", "the", "raw", "image", "data", "." ]
fc62025902295658a9c7e89418e095fd598b2682
https://github.com/rsc/rsc/blob/fc62025902295658a9c7e89418e095fd598b2682/smugmug/smug.go#L429-L431
18,109
rsc/rsc
appfs/fs/fs.go
NewContext
func NewContext(req *http.Request) *Context { if ae != nil { ctxt := ae.NewContext(req) return &Context{ae: ctxt} } return newContext(req) }
go
func NewContext(req *http.Request) *Context { if ae != nil { ctxt := ae.NewContext(req) return &Context{ae: ctxt} } return newContext(req) }
[ "func", "NewContext", "(", "req", "*", "http", ".", "Request", ")", "*", "Context", "{", "if", "ae", "!=", "nil", "{", "ctxt", ":=", "ae", ".", "NewContext", "(", "req", ")", "\n", "return", "&", "Context", "{", "ae", ":", "ctxt", "}", "\n", "}",...
// NewContext returns a context associated with the given HTTP request.
[ "NewContext", "returns", "a", "context", "associated", "with", "the", "given", "HTTP", "request", "." ]
fc62025902295658a9c7e89418e095fd598b2682
https://github.com/rsc/rsc/blob/fc62025902295658a9c7e89418e095fd598b2682/appfs/fs/fs.go#L60-L66
18,110
rsc/rsc
appfs/fs/fs.go
CacheRead
func (c *Context) CacheRead(name, path string) (ckey CacheKey, data []byte, found bool) { if ae != nil { key, data, found := ae.CacheRead(c.ae, name, path) return CacheKey{ae: key}, data, found } return c.cacheRead(ckey, path) }
go
func (c *Context) CacheRead(name, path string) (ckey CacheKey, data []byte, found bool) { if ae != nil { key, data, found := ae.CacheRead(c.ae, name, path) return CacheKey{ae: key}, data, found } return c.cacheRead(ckey, path) }
[ "func", "(", "c", "*", "Context", ")", "CacheRead", "(", "name", ",", "path", "string", ")", "(", "ckey", "CacheKey", ",", "data", "[", "]", "byte", ",", "found", "bool", ")", "{", "if", "ae", "!=", "nil", "{", "key", ",", "data", ",", "found", ...
// CacheRead reads from cache the entry with the given name and path. // The path specifies the scope of information stored in the cache entry. // An entry is invalidated by a write to any location in the file tree rooted at path. // The name is an uninterpreted identifier to distinguish the cache entry // from other entries using the same path. // // If it finds a cache entry, CacheRead returns the data and found=true. // If it does not find a cache entry, CacheRead returns data=nil and found=false. // Either way, CacheRead returns an appropriate cache key for storing to the // cache entry using CacheWrite.
[ "CacheRead", "reads", "from", "cache", "the", "entry", "with", "the", "given", "name", "and", "path", ".", "The", "path", "specifies", "the", "scope", "of", "information", "stored", "in", "the", "cache", "entry", ".", "An", "entry", "is", "invalidated", "b...
fc62025902295658a9c7e89418e095fd598b2682
https://github.com/rsc/rsc/blob/fc62025902295658a9c7e89418e095fd598b2682/appfs/fs/fs.go#L99-L105
18,111
rsc/rsc
appfs/fs/fs.go
CacheLoad
func (c *Context) CacheLoad(name, path string, value interface{}) (ckey CacheKey, found bool) { ckey, data, found := c.CacheRead(name, path) if found { if err := gob.NewDecoder(bytes.NewBuffer(data)).Decode(value); err != nil { c.Criticalf("gob Decode: %v", err) found = false } } return }
go
func (c *Context) CacheLoad(name, path string, value interface{}) (ckey CacheKey, found bool) { ckey, data, found := c.CacheRead(name, path) if found { if err := gob.NewDecoder(bytes.NewBuffer(data)).Decode(value); err != nil { c.Criticalf("gob Decode: %v", err) found = false } } return }
[ "func", "(", "c", "*", "Context", ")", "CacheLoad", "(", "name", ",", "path", "string", ",", "value", "interface", "{", "}", ")", "(", "ckey", "CacheKey", ",", "found", "bool", ")", "{", "ckey", ",", "data", ",", "found", ":=", "c", ".", "CacheRead...
// CacheLoad uses CacheRead to load gob-encoded data and decodes it into value.
[ "CacheLoad", "uses", "CacheRead", "to", "load", "gob", "-", "encoded", "data", "and", "decodes", "it", "into", "value", "." ]
fc62025902295658a9c7e89418e095fd598b2682
https://github.com/rsc/rsc/blob/fc62025902295658a9c7e89418e095fd598b2682/appfs/fs/fs.go#L108-L117
18,112
rsc/rsc
appfs/fs/fs.go
CacheWrite
func (c *Context) CacheWrite(ckey CacheKey, data []byte) { if ae != nil { ae.CacheWrite(c.ae, ckey.ae, data) return } c.cacheWrite(ckey, data) }
go
func (c *Context) CacheWrite(ckey CacheKey, data []byte) { if ae != nil { ae.CacheWrite(c.ae, ckey.ae, data) return } c.cacheWrite(ckey, data) }
[ "func", "(", "c", "*", "Context", ")", "CacheWrite", "(", "ckey", "CacheKey", ",", "data", "[", "]", "byte", ")", "{", "if", "ae", "!=", "nil", "{", "ae", ".", "CacheWrite", "(", "c", ".", "ae", ",", "ckey", ".", "ae", ",", "data", ")", "\n", ...
// CacheWrite writes an entry to the cache with the given key, path, and data. // The cache entry will be invalidated the next time the file tree rooted at path is // modified in anyway.
[ "CacheWrite", "writes", "an", "entry", "to", "the", "cache", "with", "the", "given", "key", "path", "and", "data", ".", "The", "cache", "entry", "will", "be", "invalidated", "the", "next", "time", "the", "file", "tree", "rooted", "at", "path", "is", "mod...
fc62025902295658a9c7e89418e095fd598b2682
https://github.com/rsc/rsc/blob/fc62025902295658a9c7e89418e095fd598b2682/appfs/fs/fs.go#L122-L128
18,113
rsc/rsc
appfs/fs/fs.go
CacheStore
func (c *Context) CacheStore(ckey CacheKey, value interface{}) { var buf bytes.Buffer if err := gob.NewEncoder(&buf).Encode(value); err != nil { c.Criticalf("gob Encode: %v", err) return } c.CacheWrite(ckey, buf.Bytes()) }
go
func (c *Context) CacheStore(ckey CacheKey, value interface{}) { var buf bytes.Buffer if err := gob.NewEncoder(&buf).Encode(value); err != nil { c.Criticalf("gob Encode: %v", err) return } c.CacheWrite(ckey, buf.Bytes()) }
[ "func", "(", "c", "*", "Context", ")", "CacheStore", "(", "ckey", "CacheKey", ",", "value", "interface", "{", "}", ")", "{", "var", "buf", "bytes", ".", "Buffer", "\n", "if", "err", ":=", "gob", ".", "NewEncoder", "(", "&", "buf", ")", ".", "Encode...
// CacheStore uses CacheWrite to save the gob-encoded form of value.
[ "CacheStore", "uses", "CacheWrite", "to", "save", "the", "gob", "-", "encoded", "form", "of", "value", "." ]
fc62025902295658a9c7e89418e095fd598b2682
https://github.com/rsc/rsc/blob/fc62025902295658a9c7e89418e095fd598b2682/appfs/fs/fs.go#L131-L138
18,114
rsc/rsc
appfs/fs/fs.go
Read
func (c *Context) Read(path string) ([]byte, *proto.FileInfo, error) { if ae != nil { return ae.Read(c.ae, path) } return c.read(path) }
go
func (c *Context) Read(path string) ([]byte, *proto.FileInfo, error) { if ae != nil { return ae.Read(c.ae, path) } return c.read(path) }
[ "func", "(", "c", "*", "Context", ")", "Read", "(", "path", "string", ")", "(", "[", "]", "byte", ",", "*", "proto", ".", "FileInfo", ",", "error", ")", "{", "if", "ae", "!=", "nil", "{", "return", "ae", ".", "Read", "(", "c", ".", "ae", ",",...
// Read returns the data associated with the file named by path. // It is a copy and can be modified without affecting the file.
[ "Read", "returns", "the", "data", "associated", "with", "the", "file", "named", "by", "path", ".", "It", "is", "a", "copy", "and", "can", "be", "modified", "without", "affecting", "the", "file", "." ]
fc62025902295658a9c7e89418e095fd598b2682
https://github.com/rsc/rsc/blob/fc62025902295658a9c7e89418e095fd598b2682/appfs/fs/fs.go#L142-L147
18,115
rsc/rsc
appfs/fs/fs.go
Write
func (c *Context) Write(path string, data []byte) error { if ae != nil { return ae.Write(c.ae, path, data) } return c.write(path, data) }
go
func (c *Context) Write(path string, data []byte) error { if ae != nil { return ae.Write(c.ae, path, data) } return c.write(path, data) }
[ "func", "(", "c", "*", "Context", ")", "Write", "(", "path", "string", ",", "data", "[", "]", "byte", ")", "error", "{", "if", "ae", "!=", "nil", "{", "return", "ae", ".", "Write", "(", "c", ".", "ae", ",", "path", ",", "data", ")", "\n", "}"...
// Write replaces the data associated with the file named by path.
[ "Write", "replaces", "the", "data", "associated", "with", "the", "file", "named", "by", "path", "." ]
fc62025902295658a9c7e89418e095fd598b2682
https://github.com/rsc/rsc/blob/fc62025902295658a9c7e89418e095fd598b2682/appfs/fs/fs.go#L150-L155
18,116
rsc/rsc
appfs/fs/fs.go
Remove
func (c *Context) Remove(path string) error { if ae != nil { return ae.Remove(c.ae, path) } return c.remove(path) }
go
func (c *Context) Remove(path string) error { if ae != nil { return ae.Remove(c.ae, path) } return c.remove(path) }
[ "func", "(", "c", "*", "Context", ")", "Remove", "(", "path", "string", ")", "error", "{", "if", "ae", "!=", "nil", "{", "return", "ae", ".", "Remove", "(", "c", ".", "ae", ",", "path", ")", "\n", "}", "\n", "return", "c", ".", "remove", "(", ...
// Remove removes the file named by path.
[ "Remove", "removes", "the", "file", "named", "by", "path", "." ]
fc62025902295658a9c7e89418e095fd598b2682
https://github.com/rsc/rsc/blob/fc62025902295658a9c7e89418e095fd598b2682/appfs/fs/fs.go#L158-L163
18,117
rsc/rsc
appfs/fs/fs.go
Mkdir
func (c *Context) Mkdir(path string) error { if ae != nil { return ae.Mkdir(c.ae, path) } return c.mkdir(path) }
go
func (c *Context) Mkdir(path string) error { if ae != nil { return ae.Mkdir(c.ae, path) } return c.mkdir(path) }
[ "func", "(", "c", "*", "Context", ")", "Mkdir", "(", "path", "string", ")", "error", "{", "if", "ae", "!=", "nil", "{", "return", "ae", ".", "Mkdir", "(", "c", ".", "ae", ",", "path", ")", "\n", "}", "\n", "return", "c", ".", "mkdir", "(", "p...
// Mkdir creates a directory with the given path. // If the path already exists and is a directory, Mkdir returns no error.
[ "Mkdir", "creates", "a", "directory", "with", "the", "given", "path", ".", "If", "the", "path", "already", "exists", "and", "is", "a", "directory", "Mkdir", "returns", "no", "error", "." ]
fc62025902295658a9c7e89418e095fd598b2682
https://github.com/rsc/rsc/blob/fc62025902295658a9c7e89418e095fd598b2682/appfs/fs/fs.go#L167-L172
18,118
rsc/rsc
appfs/fs/fs.go
ReadDir
func (c *Context) ReadDir(path string) ([]proto.FileInfo, error) { if ae != nil { return ae.ReadDir(c.ae, path) } return c.readdir(path) }
go
func (c *Context) ReadDir(path string) ([]proto.FileInfo, error) { if ae != nil { return ae.ReadDir(c.ae, path) } return c.readdir(path) }
[ "func", "(", "c", "*", "Context", ")", "ReadDir", "(", "path", "string", ")", "(", "[", "]", "proto", ".", "FileInfo", ",", "error", ")", "{", "if", "ae", "!=", "nil", "{", "return", "ae", ".", "ReadDir", "(", "c", ".", "ae", ",", "path", ")", ...
// ReadDir returns the contents of the directory named by the path.
[ "ReadDir", "returns", "the", "contents", "of", "the", "directory", "named", "by", "the", "path", "." ]
fc62025902295658a9c7e89418e095fd598b2682
https://github.com/rsc/rsc/blob/fc62025902295658a9c7e89418e095fd598b2682/appfs/fs/fs.go#L175-L180
18,119
rsc/rsc
appfs/fs/fs.go
ServeFile
func (c *Context) ServeFile(w http.ResponseWriter, req *http.Request, name string) { root := &httpFS{c, name} http.FileServer(root).ServeHTTP(w, req) }
go
func (c *Context) ServeFile(w http.ResponseWriter, req *http.Request, name string) { root := &httpFS{c, name} http.FileServer(root).ServeHTTP(w, req) }
[ "func", "(", "c", "*", "Context", ")", "ServeFile", "(", "w", "http", ".", "ResponseWriter", ",", "req", "*", "http", ".", "Request", ",", "name", "string", ")", "{", "root", ":=", "&", "httpFS", "{", "c", ",", "name", "}", "\n", "http", ".", "Fi...
// ServeFile serves the named file as the response to the HTTP request.
[ "ServeFile", "serves", "the", "named", "file", "as", "the", "response", "to", "the", "HTTP", "request", "." ]
fc62025902295658a9c7e89418e095fd598b2682
https://github.com/rsc/rsc/blob/fc62025902295658a9c7e89418e095fd598b2682/appfs/fs/fs.go#L183-L186
18,120
rsc/rsc
appfs/fs/fs.go
Criticalf
func (c *Context) Criticalf(format string, args ...interface{}) { if ae != nil { ae.Criticalf(c.ae, format, args...) } log.Printf(format, args...) }
go
func (c *Context) Criticalf(format string, args ...interface{}) { if ae != nil { ae.Criticalf(c.ae, format, args...) } log.Printf(format, args...) }
[ "func", "(", "c", "*", "Context", ")", "Criticalf", "(", "format", "string", ",", "args", "...", "interface", "{", "}", ")", "{", "if", "ae", "!=", "nil", "{", "ae", ".", "Criticalf", "(", "c", ".", "ae", ",", "format", ",", "args", "...", ")", ...
// Criticalf logs the message at critical priority.
[ "Criticalf", "logs", "the", "message", "at", "critical", "priority", "." ]
fc62025902295658a9c7e89418e095fd598b2682
https://github.com/rsc/rsc/blob/fc62025902295658a9c7e89418e095fd598b2682/appfs/fs/fs.go#L189-L194
18,121
rsc/rsc
appfs/fs/fs.go
User
func (c *Context) User() string { if ae != nil { return ae.User(c.ae) } return os.Getenv("USER") }
go
func (c *Context) User() string { if ae != nil { return ae.User(c.ae) } return os.Getenv("USER") }
[ "func", "(", "c", "*", "Context", ")", "User", "(", ")", "string", "{", "if", "ae", "!=", "nil", "{", "return", "ae", ".", "User", "(", "c", ".", "ae", ")", "\n", "}", "\n", "return", "os", ".", "Getenv", "(", "\"", "\"", ")", "\n", "}" ]
// User returns the name of the user running the request.
[ "User", "returns", "the", "name", "of", "the", "user", "running", "the", "request", "." ]
fc62025902295658a9c7e89418e095fd598b2682
https://github.com/rsc/rsc/blob/fc62025902295658a9c7e89418e095fd598b2682/appfs/fs/fs.go#L197-L202
18,122
rsc/rsc
oauthprompt/oauth.go
GoogleToken
func GoogleToken(file, clientID, clientSecret, scope string) (*oauth.Transport, error) { cfg := &oauth.Config{ ClientId: clientID, ClientSecret: clientSecret, Scope: scope, AuthURL: "https://accounts.google.com/o/oauth2/auth", TokenURL: "https://accounts.google.com/o/oauth2/token", } return Token(file, cfg) }
go
func GoogleToken(file, clientID, clientSecret, scope string) (*oauth.Transport, error) { cfg := &oauth.Config{ ClientId: clientID, ClientSecret: clientSecret, Scope: scope, AuthURL: "https://accounts.google.com/o/oauth2/auth", TokenURL: "https://accounts.google.com/o/oauth2/token", } return Token(file, cfg) }
[ "func", "GoogleToken", "(", "file", ",", "clientID", ",", "clientSecret", ",", "scope", "string", ")", "(", "*", "oauth", ".", "Transport", ",", "error", ")", "{", "cfg", ":=", "&", "oauth", ".", "Config", "{", "ClientId", ":", "clientID", ",", "Client...
// GoogleToken is like Token but assumes the Google AuthURL and TokenURL, // so that only the client ID and secret and desired scope must be specified.
[ "GoogleToken", "is", "like", "Token", "but", "assumes", "the", "Google", "AuthURL", "and", "TokenURL", "so", "that", "only", "the", "client", "ID", "and", "secret", "and", "desired", "scope", "must", "be", "specified", "." ]
fc62025902295658a9c7e89418e095fd598b2682
https://github.com/rsc/rsc/blob/fc62025902295658a9c7e89418e095fd598b2682/oauthprompt/oauth.go#L135-L144
18,123
rsc/rsc
cc/lex.go
enum
func (lx *lexer) enum(x Syntax) { switch x := x.(type) { default: panic(fmt.Errorf("order: unexpected type %T", x)) case nil: return case *Expr: if x == nil { return } lx.enum(x.Left) lx.enum(x.Right) for _, y := range x.List { lx.enum(y) } case *Init: if x == nil { return } lx.enum(x.Expr) for _, y := range x.Braced { lx.enum(y) } case *Prog: if x == nil { return } for _, y := range x.Decls { lx.enum(y) } case *Stmt: if x == nil { return } for _, y := range x.Labels { lx.enum(y) } lx.enum(x.Pre) lx.enum(x.Expr) lx.enum(x.Post) lx.enum(x.Body) lx.enum(x.Else) for _, y := range x.Block { lx.enum(y) } case *Label: // ok case *Decl: if x == nil { return } if lx.enumSeen[x] { return } lx.enumSeen[x] = true lx.enum(x.Type) lx.enum(x.Init) lx.enum(x.Body) case *Type: if x == nil { return } lx.enum(x.Base) for _, y := range x.Decls { lx.enum(y) } return // do not record type itself, just inner decls } lx.pre = append(lx.pre, x) }
go
func (lx *lexer) enum(x Syntax) { switch x := x.(type) { default: panic(fmt.Errorf("order: unexpected type %T", x)) case nil: return case *Expr: if x == nil { return } lx.enum(x.Left) lx.enum(x.Right) for _, y := range x.List { lx.enum(y) } case *Init: if x == nil { return } lx.enum(x.Expr) for _, y := range x.Braced { lx.enum(y) } case *Prog: if x == nil { return } for _, y := range x.Decls { lx.enum(y) } case *Stmt: if x == nil { return } for _, y := range x.Labels { lx.enum(y) } lx.enum(x.Pre) lx.enum(x.Expr) lx.enum(x.Post) lx.enum(x.Body) lx.enum(x.Else) for _, y := range x.Block { lx.enum(y) } case *Label: // ok case *Decl: if x == nil { return } if lx.enumSeen[x] { return } lx.enumSeen[x] = true lx.enum(x.Type) lx.enum(x.Init) lx.enum(x.Body) case *Type: if x == nil { return } lx.enum(x.Base) for _, y := range x.Decls { lx.enum(y) } return // do not record type itself, just inner decls } lx.pre = append(lx.pre, x) }
[ "func", "(", "lx", "*", "lexer", ")", "enum", "(", "x", "Syntax", ")", "{", "switch", "x", ":=", "x", ".", "(", "type", ")", "{", "default", ":", "panic", "(", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "x", ")", ")", "\n", "case", "nil", ...
// Comment assignment. // We build two lists of all subexpressions, preorder and postorder. // The preorder list is ordered by start location, with outer expressions first. // The postorder list is ordered by end location, with outer expressions last. // We use the preorder list to assign each whole-line comment to the syntax // immediately following it, and we use the postorder list to assign each // end-of-line comment to the syntax immediately preceding it. // enum walks the expression adding it and its subexpressions to the pre list. // The order may not reflect the order in the input.
[ "Comment", "assignment", ".", "We", "build", "two", "lists", "of", "all", "subexpressions", "preorder", "and", "postorder", ".", "The", "preorder", "list", "is", "ordered", "by", "start", "location", "with", "outer", "expressions", "first", ".", "The", "postor...
fc62025902295658a9c7e89418e095fd598b2682
https://github.com/rsc/rsc/blob/fc62025902295658a9c7e89418e095fd598b2682/cc/lex.go#L609-L678
18,124
rsc/rsc
xmpp/xmpp.go
Recv
func (c *Client) Recv() (chat Chat, err error) { for { _, val, err := next(c.p) if err != nil { return Chat{}, err } switch val := val.(type) { case *clientMessage: return Chat{Remote: val.From, Type: val.Type, Text: val.Body}, nil case *clientQuery: var r Roster for _, item := range val.Item { r = append(r, Contact{item.Jid, item.Name, item.Group}) } return Chat{Type: "roster", Roster: r}, nil case *clientPresence: pr := &Presence{Remote: val.From, Status: statusCode(val.Show), StatusMsg: val.Status, Priority: atoi(val.Priority)} if val.Type == "unavailable" { pr.Status = Unavailable } return Chat{Remote: val.From, Type: "presence", Presence: pr}, nil default: //log.Printf("ignoring %T", val) } } panic("unreachable") }
go
func (c *Client) Recv() (chat Chat, err error) { for { _, val, err := next(c.p) if err != nil { return Chat{}, err } switch val := val.(type) { case *clientMessage: return Chat{Remote: val.From, Type: val.Type, Text: val.Body}, nil case *clientQuery: var r Roster for _, item := range val.Item { r = append(r, Contact{item.Jid, item.Name, item.Group}) } return Chat{Type: "roster", Roster: r}, nil case *clientPresence: pr := &Presence{Remote: val.From, Status: statusCode(val.Show), StatusMsg: val.Status, Priority: atoi(val.Priority)} if val.Type == "unavailable" { pr.Status = Unavailable } return Chat{Remote: val.From, Type: "presence", Presence: pr}, nil default: //log.Printf("ignoring %T", val) } } panic("unreachable") }
[ "func", "(", "c", "*", "Client", ")", "Recv", "(", ")", "(", "chat", "Chat", ",", "err", "error", ")", "{", "for", "{", "_", ",", "val", ",", "err", ":=", "next", "(", "c", ".", "p", ")", "\n", "if", "err", "!=", "nil", "{", "return", "Chat...
// Recv wait next token of chat.
[ "Recv", "wait", "next", "token", "of", "chat", "." ]
fc62025902295658a9c7e89418e095fd598b2682
https://github.com/rsc/rsc/blob/fc62025902295658a9c7e89418e095fd598b2682/xmpp/xmpp.go#L264-L290
18,125
rsc/rsc
xmpp/xmpp.go
Send
func (c *Client) Send(chat Chat) error { fmt.Fprintf(c.tls, "<message to='%s' from='%s' type='chat' xml:lang='en'>"+ "<body>%s</body></message>", xmlEscape(chat.Remote), xmlEscape(c.jid), xmlEscape(chat.Text)) return nil }
go
func (c *Client) Send(chat Chat) error { fmt.Fprintf(c.tls, "<message to='%s' from='%s' type='chat' xml:lang='en'>"+ "<body>%s</body></message>", xmlEscape(chat.Remote), xmlEscape(c.jid), xmlEscape(chat.Text)) return nil }
[ "func", "(", "c", "*", "Client", ")", "Send", "(", "chat", "Chat", ")", "error", "{", "fmt", ".", "Fprintf", "(", "c", ".", "tls", ",", "\"", "\"", "+", "\"", "\"", ",", "xmlEscape", "(", "chat", ".", "Remote", ")", ",", "xmlEscape", "(", "c", ...
// Send sends message text.
[ "Send", "sends", "message", "text", "." ]
fc62025902295658a9c7e89418e095fd598b2682
https://github.com/rsc/rsc/blob/fc62025902295658a9c7e89418e095fd598b2682/xmpp/xmpp.go#L293-L299
18,126
rsc/rsc
xmpp/xmpp.go
Roster
func (c *Client) Roster() error { fmt.Fprintf(c.tls, "<iq from='%s' type='get' id='roster1'><query xmlns='jabber:iq:roster'/></iq>\n", xmlEscape(c.jid)) return nil }
go
func (c *Client) Roster() error { fmt.Fprintf(c.tls, "<iq from='%s' type='get' id='roster1'><query xmlns='jabber:iq:roster'/></iq>\n", xmlEscape(c.jid)) return nil }
[ "func", "(", "c", "*", "Client", ")", "Roster", "(", ")", "error", "{", "fmt", ".", "Fprintf", "(", "c", ".", "tls", ",", "\"", "\\n", "\"", ",", "xmlEscape", "(", "c", ".", "jid", ")", ")", "\n", "return", "nil", "\n", "}" ]
// Roster asks for the chat roster.
[ "Roster", "asks", "for", "the", "chat", "roster", "." ]
fc62025902295658a9c7e89418e095fd598b2682
https://github.com/rsc/rsc/blob/fc62025902295658a9c7e89418e095fd598b2682/xmpp/xmpp.go#L302-L305
18,127
rsc/rsc
xmpp/xmpp.go
nextStart
func nextStart(p *xml.Decoder) (xml.StartElement, error) { for { t, err := p.Token() if err != nil { log.Fatal("token", err) } switch t := t.(type) { case xml.StartElement: return t, nil } } panic("unreachable") }
go
func nextStart(p *xml.Decoder) (xml.StartElement, error) { for { t, err := p.Token() if err != nil { log.Fatal("token", err) } switch t := t.(type) { case xml.StartElement: return t, nil } } panic("unreachable") }
[ "func", "nextStart", "(", "p", "*", "xml", ".", "Decoder", ")", "(", "xml", ".", "StartElement", ",", "error", ")", "{", "for", "{", "t", ",", "err", ":=", "p", ".", "Token", "(", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Fatal", ...
// Scan XML token stream to find next StartElement.
[ "Scan", "XML", "token", "stream", "to", "find", "next", "StartElement", "." ]
fc62025902295658a9c7e89418e095fd598b2682
https://github.com/rsc/rsc/blob/fc62025902295658a9c7e89418e095fd598b2682/xmpp/xmpp.go#L469-L481
18,128
rsc/rsc
xmpp/xmpp.go
next
func next(p *xml.Decoder) (xml.Name, interface{}, error) { // Read start element to find out what type we want. se, err := nextStart(p) if err != nil { return xml.Name{}, nil, err } // Put it in an interface and allocate one. var nv interface{} switch se.Name.Space + " " + se.Name.Local { case nsStream + " features": nv = &streamFeatures{} case nsStream + " error": nv = &streamError{} case nsTLS + " starttls": nv = &tlsStartTLS{} case nsTLS + " proceed": nv = &tlsProceed{} case nsTLS + " failure": nv = &tlsFailure{} case nsSASL + " mechanisms": nv = &saslMechanisms{} case nsSASL + " challenge": nv = "" case nsSASL + " response": nv = "" case nsSASL + " abort": nv = &saslAbort{} case nsSASL + " success": nv = &saslSuccess{} case nsSASL + " failure": nv = &saslFailure{} case nsBind + " bind": nv = &bindBind{} case nsClient + " message": nv = &clientMessage{} case nsClient + " presence": nv = &clientPresence{} case nsClient + " iq": nv = &clientIQ{} case nsClient + " error": nv = &clientError{} default: return xml.Name{}, nil, errors.New("unexpected XMPP message " + se.Name.Space + " <" + se.Name.Local + "/>") } // Unmarshal into that storage. if err = p.DecodeElement(nv, &se); err != nil { return xml.Name{}, nil, err } return se.Name, nv, err }
go
func next(p *xml.Decoder) (xml.Name, interface{}, error) { // Read start element to find out what type we want. se, err := nextStart(p) if err != nil { return xml.Name{}, nil, err } // Put it in an interface and allocate one. var nv interface{} switch se.Name.Space + " " + se.Name.Local { case nsStream + " features": nv = &streamFeatures{} case nsStream + " error": nv = &streamError{} case nsTLS + " starttls": nv = &tlsStartTLS{} case nsTLS + " proceed": nv = &tlsProceed{} case nsTLS + " failure": nv = &tlsFailure{} case nsSASL + " mechanisms": nv = &saslMechanisms{} case nsSASL + " challenge": nv = "" case nsSASL + " response": nv = "" case nsSASL + " abort": nv = &saslAbort{} case nsSASL + " success": nv = &saslSuccess{} case nsSASL + " failure": nv = &saslFailure{} case nsBind + " bind": nv = &bindBind{} case nsClient + " message": nv = &clientMessage{} case nsClient + " presence": nv = &clientPresence{} case nsClient + " iq": nv = &clientIQ{} case nsClient + " error": nv = &clientError{} default: return xml.Name{}, nil, errors.New("unexpected XMPP message " + se.Name.Space + " <" + se.Name.Local + "/>") } // Unmarshal into that storage. if err = p.DecodeElement(nv, &se); err != nil { return xml.Name{}, nil, err } return se.Name, nv, err }
[ "func", "next", "(", "p", "*", "xml", ".", "Decoder", ")", "(", "xml", ".", "Name", ",", "interface", "{", "}", ",", "error", ")", "{", "// Read start element to find out what type we want.", "se", ",", "err", ":=", "nextStart", "(", "p", ")", "\n", "if"...
// Scan XML token stream for next element and save into val. // If val == nil, allocate new element based on proto map. // Either way, return val.
[ "Scan", "XML", "token", "stream", "for", "next", "element", "and", "save", "into", "val", ".", "If", "val", "==", "nil", "allocate", "new", "element", "based", "on", "proto", "map", ".", "Either", "way", "return", "val", "." ]
fc62025902295658a9c7e89418e095fd598b2682
https://github.com/rsc/rsc/blob/fc62025902295658a9c7e89418e095fd598b2682/xmpp/xmpp.go#L486-L538
18,129
rsc/rsc
imap/imap.go
cmdsx0
func (c *Client) cmdsx0(format string, args ...interface{}) (*sx, error) { c.io.mustBeLocked() if c.rw == nil || !c.connected { return nil, fmt.Errorf("not connected") } cmd := fmt.Sprintf(format, args...) if Debug { fmt.Fprintf(os.Stderr, ">>> %s %s\n", tag, cmd) } if _, err := fmt.Fprintf(c.rw, "%s %s\r\n", tag, cmd); err != nil { c.connected = false return nil, err } return c.waitsx() }
go
func (c *Client) cmdsx0(format string, args ...interface{}) (*sx, error) { c.io.mustBeLocked() if c.rw == nil || !c.connected { return nil, fmt.Errorf("not connected") } cmd := fmt.Sprintf(format, args...) if Debug { fmt.Fprintf(os.Stderr, ">>> %s %s\n", tag, cmd) } if _, err := fmt.Fprintf(c.rw, "%s %s\r\n", tag, cmd); err != nil { c.connected = false return nil, err } return c.waitsx() }
[ "func", "(", "c", "*", "Client", ")", "cmdsx0", "(", "format", "string", ",", "args", "...", "interface", "{", "}", ")", "(", "*", "sx", ",", "error", ")", "{", "c", ".", "io", ".", "mustBeLocked", "(", ")", "\n", "if", "c", ".", "rw", "==", ...
// cmdsx0 runs a single command and return the sx. Does not redial.
[ "cmdsx0", "runs", "a", "single", "command", "and", "return", "the", "sx", ".", "Does", "not", "redial", "." ]
fc62025902295658a9c7e89418e095fd598b2682
https://github.com/rsc/rsc/blob/fc62025902295658a9c7e89418e095fd598b2682/imap/imap.go#L258-L273
18,130
rsc/rsc
imap/imap.go
cmdsx
func (c *Client) cmdsx(b *Box, format string, args ...interface{}) (*sx, error) { c.io.mustBeLocked() c.nextBox = b Trying: for tries := 0; ; tries++ { if c.rw == nil || !c.connected { if !c.autoReconnect { return nil, fmt.Errorf("not connected") } if err := c.reconnect(); err != nil { return nil, err } if b != nil && c.nextBox == nil { // box disappeared on reconnect return nil, fmt.Errorf("box is gone") } } if b != nil && !b.search && b != c.box { if c.box != nil { // TODO c.box.init = false } c.box = b if _, err := c.cmdsx0("SELECT %s", iquote(b.Name)); err != nil { c.box = nil if tries++; tries == 1 && (c.rw == nil || !c.connected) { continue Trying } return nil, err } } if b != nil { c.box = b } x, err := c.cmdsx0(format, args...) if err != nil { if tries++; tries == 1 && (c.rw == nil || !c.connected) { continue Trying } return nil, err } return x, nil } panic("not reached") }
go
func (c *Client) cmdsx(b *Box, format string, args ...interface{}) (*sx, error) { c.io.mustBeLocked() c.nextBox = b Trying: for tries := 0; ; tries++ { if c.rw == nil || !c.connected { if !c.autoReconnect { return nil, fmt.Errorf("not connected") } if err := c.reconnect(); err != nil { return nil, err } if b != nil && c.nextBox == nil { // box disappeared on reconnect return nil, fmt.Errorf("box is gone") } } if b != nil && !b.search && b != c.box { if c.box != nil { // TODO c.box.init = false } c.box = b if _, err := c.cmdsx0("SELECT %s", iquote(b.Name)); err != nil { c.box = nil if tries++; tries == 1 && (c.rw == nil || !c.connected) { continue Trying } return nil, err } } if b != nil { c.box = b } x, err := c.cmdsx0(format, args...) if err != nil { if tries++; tries == 1 && (c.rw == nil || !c.connected) { continue Trying } return nil, err } return x, nil } panic("not reached") }
[ "func", "(", "c", "*", "Client", ")", "cmdsx", "(", "b", "*", "Box", ",", "format", "string", ",", "args", "...", "interface", "{", "}", ")", "(", "*", "sx", ",", "error", ")", "{", "c", ".", "io", ".", "mustBeLocked", "(", ")", "\n", "c", "....
// cmdsx runs a command on box b. It does redial.
[ "cmdsx", "runs", "a", "command", "on", "box", "b", ".", "It", "does", "redial", "." ]
fc62025902295658a9c7e89418e095fd598b2682
https://github.com/rsc/rsc/blob/fc62025902295658a9c7e89418e095fd598b2682/imap/imap.go#L276-L322
18,131
rsc/rsc
ext2/fs.go
Open
func Open(name string) (*FS, error) { var off int64 if i := strings.Index(name, "@"); i >= 0 { v, err := strconv.ParseInt(name[i+1:], 0, 64) if err != nil { return nil, fmt.Errorf("invalid offset in name %q", name) } off = v name = name[:i] } f, err := os.Open(name) if err != nil { return nil, err } var r io.ReaderAt = f if off != 0 { r = &readerAtOffset{r, off} } fs, err := Init(r) if err != nil { f.Close() return nil, err } fs.c = f return fs, nil }
go
func Open(name string) (*FS, error) { var off int64 if i := strings.Index(name, "@"); i >= 0 { v, err := strconv.ParseInt(name[i+1:], 0, 64) if err != nil { return nil, fmt.Errorf("invalid offset in name %q", name) } off = v name = name[:i] } f, err := os.Open(name) if err != nil { return nil, err } var r io.ReaderAt = f if off != 0 { r = &readerAtOffset{r, off} } fs, err := Init(r) if err != nil { f.Close() return nil, err } fs.c = f return fs, nil }
[ "func", "Open", "(", "name", "string", ")", "(", "*", "FS", ",", "error", ")", "{", "var", "off", "int64", "\n", "if", "i", ":=", "strings", ".", "Index", "(", "name", ",", "\"", "\"", ")", ";", "i", ">=", "0", "{", "v", ",", "err", ":=", "...
// Open opens the file system in the named file. // // If the name contains an @ sign, it is taken to be // of the form file@offset, where offset is a decimal, // hexadecimal, or octal number according to its prefix, // and the file system is assumed to start at the given // offset in the file instead of at the beginning of the file.
[ "Open", "opens", "the", "file", "system", "in", "the", "named", "file", ".", "If", "the", "name", "contains", "an" ]
fc62025902295658a9c7e89418e095fd598b2682
https://github.com/rsc/rsc/blob/fc62025902295658a9c7e89418e095fd598b2682/ext2/fs.go#L186-L214
18,132
rsc/rsc
ext2/fs.go
Init
func Init(r io.ReaderAt) (*FS, error) { fs := &FS{ r: r, buf: make([]byte, 1024), BlockSize: superSize, } var super diskSuper if _, err := fs.read(superOff, 0, &super); err != nil { return nil, err } if super.Magic != superMagic { return nil, fmt.Errorf("bad magic %#x wanted %#x", super.Magic, superMagic) } bsize := uint32(minBlockSize << super.Logblocksize) fs.BlockSize = int(bsize) fs.NumBlock = int64(super.Nblock) fs.numGroup = (super.Nblock + super.Blockspergroup - 1) / super.Blockspergroup fs.g = make([]*diskGroup, fs.numGroup) fs.inodesPerGroup = super.Inospergroup fs.blocksPerGroup = super.Blockspergroup if super.Revlevel >= 1 { fs.inodeSize = uint32(super.Inosize) } else { fs.inodeSize = 128 } fs.inodesPerBlock = bsize / fs.inodeSize if bsize == superOff { fs.groupAddr = 2 } else { fs.groupAddr = 1 } fs.descPerBlock = bsize / diskGroupSize fs.firstBlock = super.Firstdatablock return fs, nil }
go
func Init(r io.ReaderAt) (*FS, error) { fs := &FS{ r: r, buf: make([]byte, 1024), BlockSize: superSize, } var super diskSuper if _, err := fs.read(superOff, 0, &super); err != nil { return nil, err } if super.Magic != superMagic { return nil, fmt.Errorf("bad magic %#x wanted %#x", super.Magic, superMagic) } bsize := uint32(minBlockSize << super.Logblocksize) fs.BlockSize = int(bsize) fs.NumBlock = int64(super.Nblock) fs.numGroup = (super.Nblock + super.Blockspergroup - 1) / super.Blockspergroup fs.g = make([]*diskGroup, fs.numGroup) fs.inodesPerGroup = super.Inospergroup fs.blocksPerGroup = super.Blockspergroup if super.Revlevel >= 1 { fs.inodeSize = uint32(super.Inosize) } else { fs.inodeSize = 128 } fs.inodesPerBlock = bsize / fs.inodeSize if bsize == superOff { fs.groupAddr = 2 } else { fs.groupAddr = 1 } fs.descPerBlock = bsize / diskGroupSize fs.firstBlock = super.Firstdatablock return fs, nil }
[ "func", "Init", "(", "r", "io", ".", "ReaderAt", ")", "(", "*", "FS", ",", "error", ")", "{", "fs", ":=", "&", "FS", "{", "r", ":", "r", ",", "buf", ":", "make", "(", "[", "]", "byte", ",", "1024", ")", ",", "BlockSize", ":", "superSize", "...
// Init returns an FS reading from the file system stored in r.
[ "Init", "returns", "an", "FS", "reading", "from", "the", "file", "system", "stored", "in", "r", "." ]
fc62025902295658a9c7e89418e095fd598b2682
https://github.com/rsc/rsc/blob/fc62025902295658a9c7e89418e095fd598b2682/ext2/fs.go#L217-L255
18,133
rsc/rsc
ext2/fs.go
File
func (fs *FS) File(inode uint32) (*File, error) { g, ioff, err := fs.igroup(inode) if err != nil { return nil, err } addr := int64(fs.BlockSize) * int64(g.Inodeaddr+ioff/fs.inodesPerBlock) ivoff := (ioff % fs.inodesPerBlock) * fs.inodeSize file := &File{fs: fs, inum: inode} if _, err := fs.read(addr, int(ivoff), &file.ino); err != nil { return nil, err } switch file.ino.Mode & ifmt { case ififo, ifchr, ifdir, ifblk, ifreg, iflnk, ifsock: // okay default: return nil, fmt.Errorf("invalid inode mode %#x", file.ino.Mode) } return file, nil }
go
func (fs *FS) File(inode uint32) (*File, error) { g, ioff, err := fs.igroup(inode) if err != nil { return nil, err } addr := int64(fs.BlockSize) * int64(g.Inodeaddr+ioff/fs.inodesPerBlock) ivoff := (ioff % fs.inodesPerBlock) * fs.inodeSize file := &File{fs: fs, inum: inode} if _, err := fs.read(addr, int(ivoff), &file.ino); err != nil { return nil, err } switch file.ino.Mode & ifmt { case ififo, ifchr, ifdir, ifblk, ifreg, iflnk, ifsock: // okay default: return nil, fmt.Errorf("invalid inode mode %#x", file.ino.Mode) } return file, nil }
[ "func", "(", "fs", "*", "FS", ")", "File", "(", "inode", "uint32", ")", "(", "*", "File", ",", "error", ")", "{", "g", ",", "ioff", ",", "err", ":=", "fs", ".", "igroup", "(", "inode", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil"...
// File returns the file with the given inode number.
[ "File", "returns", "the", "file", "with", "the", "given", "inode", "number", "." ]
fc62025902295658a9c7e89418e095fd598b2682
https://github.com/rsc/rsc/blob/fc62025902295658a9c7e89418e095fd598b2682/ext2/fs.go#L265-L287
18,134
rsc/rsc
ext2/fs.go
Size
func (f *File) Size() int64 { size := int64(f.ino.Size) if f.ino.Mode&ifmt == ifreg { size |= int64(f.ino.Diracl) << 32 } return size }
go
func (f *File) Size() int64 { size := int64(f.ino.Size) if f.ino.Mode&ifmt == ifreg { size |= int64(f.ino.Diracl) << 32 } return size }
[ "func", "(", "f", "*", "File", ")", "Size", "(", ")", "int64", "{", "size", ":=", "int64", "(", "f", ".", "ino", ".", "Size", ")", "\n", "if", "f", ".", "ino", ".", "Mode", "&", "ifmt", "==", "ifreg", "{", "size", "|=", "int64", "(", "f", "...
// Size returns the file's size in bytes.
[ "Size", "returns", "the", "file", "s", "size", "in", "bytes", "." ]
fc62025902295658a9c7e89418e095fd598b2682
https://github.com/rsc/rsc/blob/fc62025902295658a9c7e89418e095fd598b2682/ext2/fs.go#L321-L327
18,135
rsc/rsc
ext2/fs.go
Mode
func (f *File) Mode() os.FileMode { mode := os.FileMode(f.ino.Mode & 0777) switch f.ino.Mode & ifmt { case ififo: mode |= os.ModeNamedPipe default: // ifchr, ifblk, unknown mode |= os.ModeDevice case ifdir: mode |= os.ModeDir case ifreg: // no bits case iflnk: mode |= os.ModeSymlink case ifsock: mode |= os.ModeSocket } return mode }
go
func (f *File) Mode() os.FileMode { mode := os.FileMode(f.ino.Mode & 0777) switch f.ino.Mode & ifmt { case ififo: mode |= os.ModeNamedPipe default: // ifchr, ifblk, unknown mode |= os.ModeDevice case ifdir: mode |= os.ModeDir case ifreg: // no bits case iflnk: mode |= os.ModeSymlink case ifsock: mode |= os.ModeSocket } return mode }
[ "func", "(", "f", "*", "File", ")", "Mode", "(", ")", "os", ".", "FileMode", "{", "mode", ":=", "os", ".", "FileMode", "(", "f", ".", "ino", ".", "Mode", "&", "0777", ")", "\n", "switch", "f", ".", "ino", ".", "Mode", "&", "ifmt", "{", "case"...
// Mode returns the file's mode.
[ "Mode", "returns", "the", "file", "s", "mode", "." ]
fc62025902295658a9c7e89418e095fd598b2682
https://github.com/rsc/rsc/blob/fc62025902295658a9c7e89418e095fd598b2682/ext2/fs.go#L330-L347
18,136
rsc/rsc
ext2/fs.go
ModTime
func (f *File) ModTime() time.Time { return time.Unix(int64(f.ino.Mtime), 0) }
go
func (f *File) ModTime() time.Time { return time.Unix(int64(f.ino.Mtime), 0) }
[ "func", "(", "f", "*", "File", ")", "ModTime", "(", ")", "time", ".", "Time", "{", "return", "time", ".", "Unix", "(", "int64", "(", "f", ".", "ino", ".", "Mtime", ")", ",", "0", ")", "\n", "}" ]
// ModTime returns the file's modification time.
[ "ModTime", "returns", "the", "file", "s", "modification", "time", "." ]
fc62025902295658a9c7e89418e095fd598b2682
https://github.com/rsc/rsc/blob/fc62025902295658a9c7e89418e095fd598b2682/ext2/fs.go#L354-L356
18,137
rsc/rsc
ext2/fs.go
ReadAt
func (f *File) ReadAt(buf []byte, off int64) (n int, err error) { size := f.Size() if off >= size { return 0, io.EOF } if n = len(buf); int64(n) > size-off { n = int(size - off) } lfrag := int(uint32(off) % uint32(f.fs.BlockSize)) off -= int64(lfrag) want := lfrag + n rfrag := -want & (f.fs.BlockSize - 1) want += rfrag offb := uint32(off / int64(f.fs.BlockSize)) nblock := want / f.fs.BlockSize for i := 0; i < nblock; i++ { b, err := f.dblock(offb + uint32(i)) if err != nil { return 0, err } dbuf, err := f.fs.readData(b, 0, nil) if err != nil { return 0, err } m := copy(buf, dbuf[lfrag:]) buf = buf[m:] lfrag = 0 } return n, nil }
go
func (f *File) ReadAt(buf []byte, off int64) (n int, err error) { size := f.Size() if off >= size { return 0, io.EOF } if n = len(buf); int64(n) > size-off { n = int(size - off) } lfrag := int(uint32(off) % uint32(f.fs.BlockSize)) off -= int64(lfrag) want := lfrag + n rfrag := -want & (f.fs.BlockSize - 1) want += rfrag offb := uint32(off / int64(f.fs.BlockSize)) nblock := want / f.fs.BlockSize for i := 0; i < nblock; i++ { b, err := f.dblock(offb + uint32(i)) if err != nil { return 0, err } dbuf, err := f.fs.readData(b, 0, nil) if err != nil { return 0, err } m := copy(buf, dbuf[lfrag:]) buf = buf[m:] lfrag = 0 } return n, nil }
[ "func", "(", "f", "*", "File", ")", "ReadAt", "(", "buf", "[", "]", "byte", ",", "off", "int64", ")", "(", "n", "int", ",", "err", "error", ")", "{", "size", ":=", "f", ".", "Size", "(", ")", "\n", "if", "off", ">=", "size", "{", "return", ...
// ReadAt implements the io.ReaderAt interface.
[ "ReadAt", "implements", "the", "io", ".", "ReaderAt", "interface", "." ]
fc62025902295658a9c7e89418e095fd598b2682
https://github.com/rsc/rsc/blob/fc62025902295658a9c7e89418e095fd598b2682/ext2/fs.go#L359-L391
18,138
rsc/rsc
ext2/fs.go
ReadLink
func (f *File) ReadLink() (string, error) { if f.ino.Mode&ifmt != iflnk { return "", fmt.Errorf("not a symbolic link") } size := f.ino.Size if f.ino.Nblock != 0 { if size > uint32(f.fs.BlockSize) { return "", fmt.Errorf("invalid symlink size") } // Symlink fits in one block. b, err := f.dblock(0) if err != nil { return "", err } buf, err := f.fs.readData(b, 0, nil) if err != nil { return "", err } return string(buf[:size]), nil } if size > 4*numBlocks { return "", fmt.Errorf("invalid symlink size") } var buf [4 * numBlocks]byte for i := 0; i < numBlocks; i++ { binary.LittleEndian.PutUint32(buf[4*i:], f.ino.Block[i]) } return string(buf[:size]), nil }
go
func (f *File) ReadLink() (string, error) { if f.ino.Mode&ifmt != iflnk { return "", fmt.Errorf("not a symbolic link") } size := f.ino.Size if f.ino.Nblock != 0 { if size > uint32(f.fs.BlockSize) { return "", fmt.Errorf("invalid symlink size") } // Symlink fits in one block. b, err := f.dblock(0) if err != nil { return "", err } buf, err := f.fs.readData(b, 0, nil) if err != nil { return "", err } return string(buf[:size]), nil } if size > 4*numBlocks { return "", fmt.Errorf("invalid symlink size") } var buf [4 * numBlocks]byte for i := 0; i < numBlocks; i++ { binary.LittleEndian.PutUint32(buf[4*i:], f.ino.Block[i]) } return string(buf[:size]), nil }
[ "func", "(", "f", "*", "File", ")", "ReadLink", "(", ")", "(", "string", ",", "error", ")", "{", "if", "f", ".", "ino", ".", "Mode", "&", "ifmt", "!=", "iflnk", "{", "return", "\"", "\"", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n",...
// ReadLink returns the symbolic link content of f.
[ "ReadLink", "returns", "the", "symbolic", "link", "content", "of", "f", "." ]
fc62025902295658a9c7e89418e095fd598b2682
https://github.com/rsc/rsc/blob/fc62025902295658a9c7e89418e095fd598b2682/ext2/fs.go#L394-L425
18,139
rsc/rsc
ext2/fs.go
ReadDir
func (f *File) ReadDir() ([]Dir, error) { var dirs []Dir err := f.walkDir(func(name []byte, ino uint32) bool { dirs = append(dirs, Dir{string(name), ino}) return true }) return dirs, err }
go
func (f *File) ReadDir() ([]Dir, error) { var dirs []Dir err := f.walkDir(func(name []byte, ino uint32) bool { dirs = append(dirs, Dir{string(name), ino}) return true }) return dirs, err }
[ "func", "(", "f", "*", "File", ")", "ReadDir", "(", ")", "(", "[", "]", "Dir", ",", "error", ")", "{", "var", "dirs", "[", "]", "Dir", "\n", "err", ":=", "f", ".", "walkDir", "(", "func", "(", "name", "[", "]", "byte", ",", "ino", "uint32", ...
// ReadDir returns all the directory entries in f.
[ "ReadDir", "returns", "all", "the", "directory", "entries", "in", "f", "." ]
fc62025902295658a9c7e89418e095fd598b2682
https://github.com/rsc/rsc/blob/fc62025902295658a9c7e89418e095fd598b2682/ext2/fs.go#L477-L484
18,140
rsc/rsc
ext2/fs.go
Lookup
func (f *File) Lookup(name string) (*File, error) { var bino uint32 bname := []byte(name) err := f.walkDir(func(name []byte, ino uint32) bool { if bytes.Equal(bname, name) { bino = ino return false } return true }) if err != nil { return nil, err } if bino == 0 { return nil, fmt.Errorf("file not found") } return f.fs.File(bino) }
go
func (f *File) Lookup(name string) (*File, error) { var bino uint32 bname := []byte(name) err := f.walkDir(func(name []byte, ino uint32) bool { if bytes.Equal(bname, name) { bino = ino return false } return true }) if err != nil { return nil, err } if bino == 0 { return nil, fmt.Errorf("file not found") } return f.fs.File(bino) }
[ "func", "(", "f", "*", "File", ")", "Lookup", "(", "name", "string", ")", "(", "*", "File", ",", "error", ")", "{", "var", "bino", "uint32", "\n", "bname", ":=", "[", "]", "byte", "(", "name", ")", "\n", "err", ":=", "f", ".", "walkDir", "(", ...
// Lookup looks up the name in the directory f, returning the corresponding child file.
[ "Lookup", "looks", "up", "the", "name", "in", "the", "directory", "f", "returning", "the", "corresponding", "child", "file", "." ]
fc62025902295658a9c7e89418e095fd598b2682
https://github.com/rsc/rsc/blob/fc62025902295658a9c7e89418e095fd598b2682/ext2/fs.go#L487-L504
18,141
rsc/rsc
ext2/fs.go
Open
func (f *File) Open() (io.Reader, error) { if f.ino.Mode&ifmt != ifreg { return nil, fmt.Errorf("not a regular file") } return &fileReader{f, 0}, nil }
go
func (f *File) Open() (io.Reader, error) { if f.ino.Mode&ifmt != ifreg { return nil, fmt.Errorf("not a regular file") } return &fileReader{f, 0}, nil }
[ "func", "(", "f", "*", "File", ")", "Open", "(", ")", "(", "io", ".", "Reader", ",", "error", ")", "{", "if", "f", ".", "ino", ".", "Mode", "&", "ifmt", "!=", "ifreg", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "...
// Open returns an io.Reader for the file.
[ "Open", "returns", "an", "io", ".", "Reader", "for", "the", "file", "." ]
fc62025902295658a9c7e89418e095fd598b2682
https://github.com/rsc/rsc/blob/fc62025902295658a9c7e89418e095fd598b2682/ext2/fs.go#L563-L568
18,142
rsc/rsc
cmd/acmego/read.go
readByte
func (r *importReader) readByte() byte { c, err := r.b.ReadByte() if err == nil { r.buf = append(r.buf, c) if c == 0 { err = errNUL } } if err != nil { if err == io.EOF { r.eof = true } else if r.err == nil { r.err = err } c = 0 } return c }
go
func (r *importReader) readByte() byte { c, err := r.b.ReadByte() if err == nil { r.buf = append(r.buf, c) if c == 0 { err = errNUL } } if err != nil { if err == io.EOF { r.eof = true } else if r.err == nil { r.err = err } c = 0 } return c }
[ "func", "(", "r", "*", "importReader", ")", "readByte", "(", ")", "byte", "{", "c", ",", "err", ":=", "r", ".", "b", ".", "ReadByte", "(", ")", "\n", "if", "err", "==", "nil", "{", "r", ".", "buf", "=", "append", "(", "r", ".", "buf", ",", ...
// readByte reads the next byte from the input, saves it in buf, and returns it. // If an error occurs, readByte records the error in r.err and returns 0.
[ "readByte", "reads", "the", "next", "byte", "from", "the", "input", "saves", "it", "in", "buf", "and", "returns", "it", ".", "If", "an", "error", "occurs", "readByte", "records", "the", "error", "in", "r", ".", "err", "and", "returns", "0", "." ]
fc62025902295658a9c7e89418e095fd598b2682
https://github.com/rsc/rsc/blob/fc62025902295658a9c7e89418e095fd598b2682/cmd/acmego/read.go#L40-L57
18,143
rsc/rsc
cmd/acmego/read.go
peekByte
func (r *importReader) peekByte(skipSpace bool) byte { if r.err != nil { if r.nerr++; r.nerr > 10000 { panic("go/build: import reader looping") } return 0 } // Use r.peek as first input byte. // Don't just return r.peek here: it might have been left by peekByte(false) // and this might be peekByte(true). c := r.peek if c == 0 { c = r.readByte() } for r.err == nil && !r.eof { if skipSpace { // For the purposes of this reader, semicolons are never necessary to // understand the input and are treated as spaces. switch c { case ' ', '\f', '\t', '\r', '\n', ';': c = r.readByte() continue case '/': c = r.readByte() if c == '/' { for c != '\n' && r.err == nil && !r.eof { c = r.readByte() } } else if c == '*' { var c1 byte for (c != '*' || c1 != '/') && r.err == nil { if r.eof { r.syntaxError() } c, c1 = c1, r.readByte() } } else { r.syntaxError() } c = r.readByte() continue } } break } r.peek = c return r.peek }
go
func (r *importReader) peekByte(skipSpace bool) byte { if r.err != nil { if r.nerr++; r.nerr > 10000 { panic("go/build: import reader looping") } return 0 } // Use r.peek as first input byte. // Don't just return r.peek here: it might have been left by peekByte(false) // and this might be peekByte(true). c := r.peek if c == 0 { c = r.readByte() } for r.err == nil && !r.eof { if skipSpace { // For the purposes of this reader, semicolons are never necessary to // understand the input and are treated as spaces. switch c { case ' ', '\f', '\t', '\r', '\n', ';': c = r.readByte() continue case '/': c = r.readByte() if c == '/' { for c != '\n' && r.err == nil && !r.eof { c = r.readByte() } } else if c == '*' { var c1 byte for (c != '*' || c1 != '/') && r.err == nil { if r.eof { r.syntaxError() } c, c1 = c1, r.readByte() } } else { r.syntaxError() } c = r.readByte() continue } } break } r.peek = c return r.peek }
[ "func", "(", "r", "*", "importReader", ")", "peekByte", "(", "skipSpace", "bool", ")", "byte", "{", "if", "r", ".", "err", "!=", "nil", "{", "if", "r", ".", "nerr", "++", ";", "r", ".", "nerr", ">", "10000", "{", "panic", "(", "\"", "\"", ")", ...
// peekByte returns the next byte from the input reader but does not advance beyond it. // If skipSpace is set, peekByte skips leading spaces and comments.
[ "peekByte", "returns", "the", "next", "byte", "from", "the", "input", "reader", "but", "does", "not", "advance", "beyond", "it", ".", "If", "skipSpace", "is", "set", "peekByte", "skips", "leading", "spaces", "and", "comments", "." ]
fc62025902295658a9c7e89418e095fd598b2682
https://github.com/rsc/rsc/blob/fc62025902295658a9c7e89418e095fd598b2682/cmd/acmego/read.go#L61-L110
18,144
rsc/rsc
cmd/acmego/read.go
nextByte
func (r *importReader) nextByte(skipSpace bool) byte { c := r.peekByte(skipSpace) r.peek = 0 return c }
go
func (r *importReader) nextByte(skipSpace bool) byte { c := r.peekByte(skipSpace) r.peek = 0 return c }
[ "func", "(", "r", "*", "importReader", ")", "nextByte", "(", "skipSpace", "bool", ")", "byte", "{", "c", ":=", "r", ".", "peekByte", "(", "skipSpace", ")", "\n", "r", ".", "peek", "=", "0", "\n", "return", "c", "\n", "}" ]
// nextByte is like peekByte but advances beyond the returned byte.
[ "nextByte", "is", "like", "peekByte", "but", "advances", "beyond", "the", "returned", "byte", "." ]
fc62025902295658a9c7e89418e095fd598b2682
https://github.com/rsc/rsc/blob/fc62025902295658a9c7e89418e095fd598b2682/cmd/acmego/read.go#L113-L117
18,145
rsc/rsc
cmd/acmego/read.go
readKeyword
func (r *importReader) readKeyword(kw string) { r.peekByte(true) for i := 0; i < len(kw); i++ { if r.nextByte(false) != kw[i] { r.syntaxError() return } } if isIdent(r.peekByte(false)) { r.syntaxError() } }
go
func (r *importReader) readKeyword(kw string) { r.peekByte(true) for i := 0; i < len(kw); i++ { if r.nextByte(false) != kw[i] { r.syntaxError() return } } if isIdent(r.peekByte(false)) { r.syntaxError() } }
[ "func", "(", "r", "*", "importReader", ")", "readKeyword", "(", "kw", "string", ")", "{", "r", ".", "peekByte", "(", "true", ")", "\n", "for", "i", ":=", "0", ";", "i", "<", "len", "(", "kw", ")", ";", "i", "++", "{", "if", "r", ".", "nextByt...
// readKeyword reads the given keyword from the input. // If the keyword is not present, readKeyword records a syntax error.
[ "readKeyword", "reads", "the", "given", "keyword", "from", "the", "input", ".", "If", "the", "keyword", "is", "not", "present", "readKeyword", "records", "a", "syntax", "error", "." ]
fc62025902295658a9c7e89418e095fd598b2682
https://github.com/rsc/rsc/blob/fc62025902295658a9c7e89418e095fd598b2682/cmd/acmego/read.go#L121-L132
18,146
rsc/rsc
cmd/acmego/read.go
readIdent
func (r *importReader) readIdent() { c := r.peekByte(true) if !isIdent(c) { r.syntaxError() return } for isIdent(r.peekByte(false)) { r.peek = 0 } }
go
func (r *importReader) readIdent() { c := r.peekByte(true) if !isIdent(c) { r.syntaxError() return } for isIdent(r.peekByte(false)) { r.peek = 0 } }
[ "func", "(", "r", "*", "importReader", ")", "readIdent", "(", ")", "{", "c", ":=", "r", ".", "peekByte", "(", "true", ")", "\n", "if", "!", "isIdent", "(", "c", ")", "{", "r", ".", "syntaxError", "(", ")", "\n", "return", "\n", "}", "\n", "for"...
// readIdent reads an identifier from the input. // If an identifier is not present, readIdent records a syntax error.
[ "readIdent", "reads", "an", "identifier", "from", "the", "input", ".", "If", "an", "identifier", "is", "not", "present", "readIdent", "records", "a", "syntax", "error", "." ]
fc62025902295658a9c7e89418e095fd598b2682
https://github.com/rsc/rsc/blob/fc62025902295658a9c7e89418e095fd598b2682/cmd/acmego/read.go#L136-L145
18,147
rsc/rsc
cmd/acmego/read.go
readString
func (r *importReader) readString() { switch r.nextByte(true) { case '`': for r.err == nil { if r.nextByte(false) == '`' { break } if r.eof { r.syntaxError() } } case '"': for r.err == nil { c := r.nextByte(false) if c == '"' { break } if r.eof || c == '\n' { r.syntaxError() } if c == '\\' { r.nextByte(false) } } default: r.syntaxError() } }
go
func (r *importReader) readString() { switch r.nextByte(true) { case '`': for r.err == nil { if r.nextByte(false) == '`' { break } if r.eof { r.syntaxError() } } case '"': for r.err == nil { c := r.nextByte(false) if c == '"' { break } if r.eof || c == '\n' { r.syntaxError() } if c == '\\' { r.nextByte(false) } } default: r.syntaxError() } }
[ "func", "(", "r", "*", "importReader", ")", "readString", "(", ")", "{", "switch", "r", ".", "nextByte", "(", "true", ")", "{", "case", "'`'", ":", "for", "r", ".", "err", "==", "nil", "{", "if", "r", ".", "nextByte", "(", "false", ")", "==", "...
// readString reads a quoted string literal from the input. // If an identifier is not present, readString records a syntax error.
[ "readString", "reads", "a", "quoted", "string", "literal", "from", "the", "input", ".", "If", "an", "identifier", "is", "not", "present", "readString", "records", "a", "syntax", "error", "." ]
fc62025902295658a9c7e89418e095fd598b2682
https://github.com/rsc/rsc/blob/fc62025902295658a9c7e89418e095fd598b2682/cmd/acmego/read.go#L149-L176
18,148
rsc/rsc
cmd/acmego/read.go
readImport
func (r *importReader) readImport() { c := r.peekByte(true) if c == '.' { r.peek = 0 } else if isIdent(c) { r.readIdent() } r.readString() }
go
func (r *importReader) readImport() { c := r.peekByte(true) if c == '.' { r.peek = 0 } else if isIdent(c) { r.readIdent() } r.readString() }
[ "func", "(", "r", "*", "importReader", ")", "readImport", "(", ")", "{", "c", ":=", "r", ".", "peekByte", "(", "true", ")", "\n", "if", "c", "==", "'.'", "{", "r", ".", "peek", "=", "0", "\n", "}", "else", "if", "isIdent", "(", "c", ")", "{",...
// readImport reads an import clause - optional identifier followed by quoted string - // from the input.
[ "readImport", "reads", "an", "import", "clause", "-", "optional", "identifier", "followed", "by", "quoted", "string", "-", "from", "the", "input", "." ]
fc62025902295658a9c7e89418e095fd598b2682
https://github.com/rsc/rsc/blob/fc62025902295658a9c7e89418e095fd598b2682/cmd/acmego/read.go#L180-L188
18,149
rsc/rsc
cmd/acmego/read.go
readComments
func readComments(f io.Reader) ([]byte, error) { r := &importReader{b: bufio.NewReader(f)} r.peekByte(true) if r.err == nil && !r.eof { // Didn't reach EOF, so must have found a non-space byte. Remove it. r.buf = r.buf[:len(r.buf)-1] } return r.buf, r.err }
go
func readComments(f io.Reader) ([]byte, error) { r := &importReader{b: bufio.NewReader(f)} r.peekByte(true) if r.err == nil && !r.eof { // Didn't reach EOF, so must have found a non-space byte. Remove it. r.buf = r.buf[:len(r.buf)-1] } return r.buf, r.err }
[ "func", "readComments", "(", "f", "io", ".", "Reader", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "r", ":=", "&", "importReader", "{", "b", ":", "bufio", ".", "NewReader", "(", "f", ")", "}", "\n", "r", ".", "peekByte", "(", "true", ")...
// readComments is like ioutil.ReadAll, except that it only reads the leading // block of comments in the file.
[ "readComments", "is", "like", "ioutil", ".", "ReadAll", "except", "that", "it", "only", "reads", "the", "leading", "block", "of", "comments", "in", "the", "file", "." ]
fc62025902295658a9c7e89418e095fd598b2682
https://github.com/rsc/rsc/blob/fc62025902295658a9c7e89418e095fd598b2682/cmd/acmego/read.go#L192-L200
18,150
rsc/rsc
cmd/acmego/read.go
readImports
func readImports(f io.Reader, reportSyntaxError bool) ([]byte, error) { r := &importReader{b: bufio.NewReader(f)} r.readKeyword("package") r.readIdent() for r.peekByte(true) == 'i' { r.readKeyword("import") if r.peekByte(true) == '(' { r.nextByte(false) for r.peekByte(true) != ')' && r.err == nil { r.readImport() } r.nextByte(false) } else { r.readImport() } } // If we stopped successfully before EOF, we read a byte that told us we were done. // Return all but that last byte, which would cause a syntax error if we let it through. if r.err == nil && !r.eof { return r.buf[:len(r.buf)-1], nil } // If we stopped for a syntax error, consume the whole file so that // we are sure we don't change the errors that go/parser returns. if r.err == errSyntax && !reportSyntaxError { r.err = nil for r.err == nil && !r.eof { r.readByte() } } return r.buf, r.err }
go
func readImports(f io.Reader, reportSyntaxError bool) ([]byte, error) { r := &importReader{b: bufio.NewReader(f)} r.readKeyword("package") r.readIdent() for r.peekByte(true) == 'i' { r.readKeyword("import") if r.peekByte(true) == '(' { r.nextByte(false) for r.peekByte(true) != ')' && r.err == nil { r.readImport() } r.nextByte(false) } else { r.readImport() } } // If we stopped successfully before EOF, we read a byte that told us we were done. // Return all but that last byte, which would cause a syntax error if we let it through. if r.err == nil && !r.eof { return r.buf[:len(r.buf)-1], nil } // If we stopped for a syntax error, consume the whole file so that // we are sure we don't change the errors that go/parser returns. if r.err == errSyntax && !reportSyntaxError { r.err = nil for r.err == nil && !r.eof { r.readByte() } } return r.buf, r.err }
[ "func", "readImports", "(", "f", "io", ".", "Reader", ",", "reportSyntaxError", "bool", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "r", ":=", "&", "importReader", "{", "b", ":", "bufio", ".", "NewReader", "(", "f", ")", "}", "\n\n", "r", ...
// readImports is like ioutil.ReadAll, except that it expects a Go file as input // and stops reading the input once the imports have completed.
[ "readImports", "is", "like", "ioutil", ".", "ReadAll", "except", "that", "it", "expects", "a", "Go", "file", "as", "input", "and", "stops", "reading", "the", "input", "once", "the", "imports", "have", "completed", "." ]
fc62025902295658a9c7e89418e095fd598b2682
https://github.com/rsc/rsc/blob/fc62025902295658a9c7e89418e095fd598b2682/cmd/acmego/read.go#L204-L238
18,151
rsc/rsc
fuse/fuse.go
Mount
func Mount(dir string) (*Conn, error) { // TODO(rsc): mount options (...string?) fd, errstr := mount(dir) if errstr != "" { return nil, errors.New(errstr) } return &Conn{fd: fd}, nil }
go
func Mount(dir string) (*Conn, error) { // TODO(rsc): mount options (...string?) fd, errstr := mount(dir) if errstr != "" { return nil, errors.New(errstr) } return &Conn{fd: fd}, nil }
[ "func", "Mount", "(", "dir", "string", ")", "(", "*", "Conn", ",", "error", ")", "{", "// TODO(rsc): mount options (...string?)", "fd", ",", "errstr", ":=", "mount", "(", "dir", ")", "\n", "if", "errstr", "!=", "\"", "\"", "{", "return", "nil", ",", "e...
// Mount mounts a new FUSE connection on the named directory // and returns a connection for reading and writing FUSE messages.
[ "Mount", "mounts", "a", "new", "FUSE", "connection", "on", "the", "named", "directory", "and", "returns", "a", "connection", "for", "reading", "and", "writing", "FUSE", "messages", "." ]
fc62025902295658a9c7e89418e095fd598b2682
https://github.com/rsc/rsc/blob/fc62025902295658a9c7e89418e095fd598b2682/fuse/fuse.go#L111-L119
18,152
rsc/rsc
fuse/fuse.go
Respond
func (r *SetxattrRequest) Respond() { out := &outHeader{Unique: uint64(r.ID)} r.Conn.respond(out, unsafe.Sizeof(*out)) }
go
func (r *SetxattrRequest) Respond() { out := &outHeader{Unique: uint64(r.ID)} r.Conn.respond(out, unsafe.Sizeof(*out)) }
[ "func", "(", "r", "*", "SetxattrRequest", ")", "Respond", "(", ")", "{", "out", ":=", "&", "outHeader", "{", "Unique", ":", "uint64", "(", "r", ".", "ID", ")", "}", "\n", "r", ".", "Conn", ".", "respond", "(", "out", ",", "unsafe", ".", "Sizeof",...
// Respond replies to the request, indicating that the extended attribute was set.
[ "Respond", "replies", "to", "the", "request", "indicating", "that", "the", "extended", "attribute", "was", "set", "." ]
fc62025902295658a9c7e89418e095fd598b2682
https://github.com/rsc/rsc/blob/fc62025902295658a9c7e89418e095fd598b2682/fuse/fuse.go#L1062-L1065
18,153
rsc/rsc
fuse/fuse.go
AppendDirent
func AppendDirent(data []byte, dir Dirent) []byte { de := dirent{ Ino: dir.Inode, Namelen: uint32(len(dir.Name)), Type: dir.Type, } de.Off = uint64(len(data) + direntSize + (len(dir.Name)+7)&^7) data = append(data, (*[direntSize]byte)(unsafe.Pointer(&de))[:]...) data = append(data, dir.Name...) n := direntSize + uintptr(len(dir.Name)) if n%8 != 0 { var pad [8]byte data = append(data, pad[:8-n%8]...) } return data }
go
func AppendDirent(data []byte, dir Dirent) []byte { de := dirent{ Ino: dir.Inode, Namelen: uint32(len(dir.Name)), Type: dir.Type, } de.Off = uint64(len(data) + direntSize + (len(dir.Name)+7)&^7) data = append(data, (*[direntSize]byte)(unsafe.Pointer(&de))[:]...) data = append(data, dir.Name...) n := direntSize + uintptr(len(dir.Name)) if n%8 != 0 { var pad [8]byte data = append(data, pad[:8-n%8]...) } return data }
[ "func", "AppendDirent", "(", "data", "[", "]", "byte", ",", "dir", "Dirent", ")", "[", "]", "byte", "{", "de", ":=", "dirent", "{", "Ino", ":", "dir", ".", "Inode", ",", "Namelen", ":", "uint32", "(", "len", "(", "dir", ".", "Name", ")", ")", "...
// AppendDirent appends the encoded form of a directory entry to data // and returns the resulting slice.
[ "AppendDirent", "appends", "the", "encoded", "form", "of", "a", "directory", "entry", "to", "data", "and", "returns", "the", "resulting", "slice", "." ]
fc62025902295658a9c7e89418e095fd598b2682
https://github.com/rsc/rsc/blob/fc62025902295658a9c7e89418e095fd598b2682/fuse/fuse.go#L1312-L1327
18,154
rsc/rsc
fuse/fuse.go
Respond
func (r *SetattrRequest) Respond(resp *SetattrResponse) { out := &attrOut{ outHeader: outHeader{Unique: uint64(r.ID)}, AttrValid: uint64(resp.AttrValid / time.Second), AttrValidNsec: uint32(resp.AttrValid % time.Second / time.Nanosecond), Attr: resp.Attr.attr(), } r.Conn.respond(&out.outHeader, unsafe.Sizeof(*out)) }
go
func (r *SetattrRequest) Respond(resp *SetattrResponse) { out := &attrOut{ outHeader: outHeader{Unique: uint64(r.ID)}, AttrValid: uint64(resp.AttrValid / time.Second), AttrValidNsec: uint32(resp.AttrValid % time.Second / time.Nanosecond), Attr: resp.Attr.attr(), } r.Conn.respond(&out.outHeader, unsafe.Sizeof(*out)) }
[ "func", "(", "r", "*", "SetattrRequest", ")", "Respond", "(", "resp", "*", "SetattrResponse", ")", "{", "out", ":=", "&", "attrOut", "{", "outHeader", ":", "outHeader", "{", "Unique", ":", "uint64", "(", "r", ".", "ID", ")", "}", ",", "AttrValid", ":...
// Respond replies to the request with the given response, // giving the updated attributes.
[ "Respond", "replies", "to", "the", "request", "with", "the", "given", "response", "giving", "the", "updated", "attributes", "." ]
fc62025902295658a9c7e89418e095fd598b2682
https://github.com/rsc/rsc/blob/fc62025902295658a9c7e89418e095fd598b2682/fuse/fuse.go#L1434-L1442
18,155
rsc/rsc
keychain/doc.go
UserPasswd
func UserPasswd(server, preferredUser string) (user, passwd string, err error) { user, passwd, err = userPasswd(server, preferredUser) if err != nil { if preferredUser != "" { err = fmt.Errorf("loading password for %s@%s: %v", preferredUser, server, err) } else { err = fmt.Errorf("loading password for %s: %v", server, err) } } return }
go
func UserPasswd(server, preferredUser string) (user, passwd string, err error) { user, passwd, err = userPasswd(server, preferredUser) if err != nil { if preferredUser != "" { err = fmt.Errorf("loading password for %s@%s: %v", preferredUser, server, err) } else { err = fmt.Errorf("loading password for %s: %v", server, err) } } return }
[ "func", "UserPasswd", "(", "server", ",", "preferredUser", "string", ")", "(", "user", ",", "passwd", "string", ",", "err", "error", ")", "{", "user", ",", "passwd", ",", "err", "=", "userPasswd", "(", "server", ",", "preferredUser", ")", "\n", "if", "...
// UserPasswd returns the user name and password for authenticating // to the named server. If the user argument is non-empty, UserPasswd // restricts its search to passwords for the named user.
[ "UserPasswd", "returns", "the", "user", "name", "and", "password", "for", "authenticating", "to", "the", "named", "server", ".", "If", "the", "user", "argument", "is", "non", "-", "empty", "UserPasswd", "restricts", "its", "search", "to", "passwords", "for", ...
fc62025902295658a9c7e89418e095fd598b2682
https://github.com/rsc/rsc/blob/fc62025902295658a9c7e89418e095fd598b2682/keychain/doc.go#L18-L28
18,156
rsc/rsc
scancab/database/db.go
Open
func Open(name string) (*DB, error) { _, err := os.Stat(name) if err != nil { return nil, err } meta, err := sql.Open("sqlite3", name) if err != nil { return nil, err } store := new(dbstore.Storage) store.Register(new(Doc)) store.Register(new(thumb)) store.Register(new(text)) return &DB{meta, store, name}, nil }
go
func Open(name string) (*DB, error) { _, err := os.Stat(name) if err != nil { return nil, err } meta, err := sql.Open("sqlite3", name) if err != nil { return nil, err } store := new(dbstore.Storage) store.Register(new(Doc)) store.Register(new(thumb)) store.Register(new(text)) return &DB{meta, store, name}, nil }
[ "func", "Open", "(", "name", "string", ")", "(", "*", "DB", ",", "error", ")", "{", "_", ",", "err", ":=", "os", ".", "Stat", "(", "name", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "meta", ",", ...
// Open opens the database in the named file.
[ "Open", "opens", "the", "database", "in", "the", "named", "file", "." ]
fc62025902295658a9c7e89418e095fd598b2682
https://github.com/rsc/rsc/blob/fc62025902295658a9c7e89418e095fd598b2682/scancab/database/db.go#L33-L47
18,157
rsc/rsc
scancab/database/db.go
Write
func (db *DB) Write(doc *Doc) error { tx, err := db.meta.Begin() if err != nil { return err } defer tx.Rollback() // no-op if tx.Commit called already id := doc.ID if err := db.store.Insert(tx, doc); err != nil { doc.ID = id return err } txt := text{ ID: doc.ID, Desc: strings.ToLower(doc.Desc), Text: strings.ToLower(doc.Text), Tags: strings.ToLower(doc.Tags), } if err := db.store.Insert(tx, &txt); err != nil { doc.ID = id return err } if err := tx.Commit(); err != nil { return err } return nil }
go
func (db *DB) Write(doc *Doc) error { tx, err := db.meta.Begin() if err != nil { return err } defer tx.Rollback() // no-op if tx.Commit called already id := doc.ID if err := db.store.Insert(tx, doc); err != nil { doc.ID = id return err } txt := text{ ID: doc.ID, Desc: strings.ToLower(doc.Desc), Text: strings.ToLower(doc.Text), Tags: strings.ToLower(doc.Tags), } if err := db.store.Insert(tx, &txt); err != nil { doc.ID = id return err } if err := tx.Commit(); err != nil { return err } return nil }
[ "func", "(", "db", "*", "DB", ")", "Write", "(", "doc", "*", "Doc", ")", "error", "{", "tx", ",", "err", ":=", "db", ".", "meta", ".", "Begin", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "defer", "tx", ...
// Write adds doc to the database, overwriting any existing // entry with the same doc.ID.
[ "Write", "adds", "doc", "to", "the", "database", "overwriting", "any", "existing", "entry", "with", "the", "same", "doc", ".", "ID", "." ]
fc62025902295658a9c7e89418e095fd598b2682
https://github.com/rsc/rsc/blob/fc62025902295658a9c7e89418e095fd598b2682/scancab/database/db.go#L108-L135
18,158
rsc/rsc
scancab/database/db.go
Search
func (db *DB) Search(query, sortBy string, offset, count int) ([]*Doc, error) { var docs []*Doc err := db.store.Select(db.meta, &docs, `where "ID" in (select "ID" from "rsc.io/rsc/scancab/database.text" where "rsc.io/rsc/scancab/database.text" match ?) order by `+sortBy+` limit ? offset ?`, query, count, offset) if err != nil { return nil, err } return docs, nil }
go
func (db *DB) Search(query, sortBy string, offset, count int) ([]*Doc, error) { var docs []*Doc err := db.store.Select(db.meta, &docs, `where "ID" in (select "ID" from "rsc.io/rsc/scancab/database.text" where "rsc.io/rsc/scancab/database.text" match ?) order by `+sortBy+` limit ? offset ?`, query, count, offset) if err != nil { return nil, err } return docs, nil }
[ "func", "(", "db", "*", "DB", ")", "Search", "(", "query", ",", "sortBy", "string", ",", "offset", ",", "count", "int", ")", "(", "[", "]", "*", "Doc", ",", "error", ")", "{", "var", "docs", "[", "]", "*", "Doc", "\n", "err", ":=", "db", ".",...
// Search returns documents matching query, an SQLITE full-text search. // The results are ordered by 'sortBy', and at most count results are returned // after skipping the first offset results.
[ "Search", "returns", "documents", "matching", "query", "an", "SQLITE", "full", "-", "text", "search", ".", "The", "results", "are", "ordered", "by", "sortBy", "and", "at", "most", "count", "results", "are", "returned", "after", "skipping", "the", "first", "o...
fc62025902295658a9c7e89418e095fd598b2682
https://github.com/rsc/rsc/blob/fc62025902295658a9c7e89418e095fd598b2682/scancab/database/db.go#L169-L176
18,159
rsc/rsc
scancab/database/db.go
Pending
func (db *DB) Pending(sortBy string, offset, count int) ([]*Doc, error) { var docs []*Doc err := db.store.Select(db.meta, &docs, `where "Time" = ? order by `+sortBy+` limit ? offset ?`, time.Time{}, count, offset) if err != nil { return nil, err } return docs, nil }
go
func (db *DB) Pending(sortBy string, offset, count int) ([]*Doc, error) { var docs []*Doc err := db.store.Select(db.meta, &docs, `where "Time" = ? order by `+sortBy+` limit ? offset ?`, time.Time{}, count, offset) if err != nil { return nil, err } return docs, nil }
[ "func", "(", "db", "*", "DB", ")", "Pending", "(", "sortBy", "string", ",", "offset", ",", "count", "int", ")", "(", "[", "]", "*", "Doc", ",", "error", ")", "{", "var", "docs", "[", "]", "*", "Doc", "\n", "err", ":=", "db", ".", "store", "."...
// Pending enumerates the unfiled documents in the database, // sorting them by 'sortBy', and then returning at most count documents // after skipping offset.
[ "Pending", "enumerates", "the", "unfiled", "documents", "in", "the", "database", "sorting", "them", "by", "sortBy", "and", "then", "returning", "at", "most", "count", "documents", "after", "skipping", "offset", "." ]
fc62025902295658a9c7e89418e095fd598b2682
https://github.com/rsc/rsc/blob/fc62025902295658a9c7e89418e095fd598b2682/scancab/database/db.go#L193-L200
18,160
rsc/rsc
scancab/database/db.go
SearchFile
func (db *DB) SearchFile(name string) (*Doc, error) { var doc *Doc err := db.store.Select(db.meta, &doc, `where "File" = ?`, name) if err != nil { return nil, err } if doc == nil { return nil, ErrNotFound } return doc, nil }
go
func (db *DB) SearchFile(name string) (*Doc, error) { var doc *Doc err := db.store.Select(db.meta, &doc, `where "File" = ?`, name) if err != nil { return nil, err } if doc == nil { return nil, ErrNotFound } return doc, nil }
[ "func", "(", "db", "*", "DB", ")", "SearchFile", "(", "name", "string", ")", "(", "*", "Doc", ",", "error", ")", "{", "var", "doc", "*", "Doc", "\n", "err", ":=", "db", ".", "store", ".", "Select", "(", "db", ".", "meta", ",", "&", "doc", ","...
// SearchFile searches the database for the document describing the named file.
[ "SearchFile", "searches", "the", "database", "for", "the", "document", "describing", "the", "named", "file", "." ]
fc62025902295658a9c7e89418e095fd598b2682
https://github.com/rsc/rsc/blob/fc62025902295658a9c7e89418e095fd598b2682/scancab/database/db.go#L205-L215
18,161
rsc/rsc
scancab/database/db.go
SearchID
func (db *DB) SearchID(id int64) (*Doc, error) { var doc *Doc err := db.store.Select(db.meta, &doc, `where "ID" = ?`, id) if err != nil { return nil, err } return doc, nil }
go
func (db *DB) SearchID(id int64) (*Doc, error) { var doc *Doc err := db.store.Select(db.meta, &doc, `where "ID" = ?`, id) if err != nil { return nil, err } return doc, nil }
[ "func", "(", "db", "*", "DB", ")", "SearchID", "(", "id", "int64", ")", "(", "*", "Doc", ",", "error", ")", "{", "var", "doc", "*", "Doc", "\n", "err", ":=", "db", ".", "store", ".", "Select", "(", "db", ".", "meta", ",", "&", "doc", ",", "...
// SearchID searches the database for the document with the given ID.
[ "SearchID", "searches", "the", "database", "for", "the", "document", "with", "the", "given", "ID", "." ]
fc62025902295658a9c7e89418e095fd598b2682
https://github.com/rsc/rsc/blob/fc62025902295658a9c7e89418e095fd598b2682/scancab/database/db.go#L218-L225
18,162
rsc/rsc
cloudprint/xmpp.go
Recv
func (c *xmppClient) Recv() error { for { _, val, err := next(c.p) if err != nil { return err } switch val.(type) { case *clientMessage: return nil default: } } }
go
func (c *xmppClient) Recv() error { for { _, val, err := next(c.p) if err != nil { return err } switch val.(type) { case *clientMessage: return nil default: } } }
[ "func", "(", "c", "*", "xmppClient", ")", "Recv", "(", ")", "error", "{", "for", "{", "_", ",", "val", ",", "err", ":=", "next", "(", "c", ".", "p", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "switch", "val", ...
// Recv receives the next XMPP message. // It returns only the possible error - there's no body worth mentioning.
[ "Recv", "receives", "the", "next", "XMPP", "message", ".", "It", "returns", "only", "the", "possible", "error", "-", "there", "s", "no", "body", "worth", "mentioning", "." ]
fc62025902295658a9c7e89418e095fd598b2682
https://github.com/rsc/rsc/blob/fc62025902295658a9c7e89418e095fd598b2682/cloudprint/xmpp.go#L208-L220
18,163
rsc/rsc
cloudprint/xmpp.go
Subscribe
func (c *xmppClient) Subscribe() error { barejid := c.jid i := strings.Index(barejid, "/") if i >= 0 { barejid = barejid[:i] } println("\nok\n", "jid", c.jid, "\n") fmt.Fprintf(c.tls, "<iq type='set' id='z1'><session xmlns='urn:ietf:params:xml:ns:xmpp-session'/></iq>") fmt.Fprintf(c.tls, "<iq type='set' to='%s' id='z2'><subscribe xmlns='google:push'><item channel='cloudprint.google.com' from='cloudprint.google.com'/></subscribe></iq>", barejid) return nil }
go
func (c *xmppClient) Subscribe() error { barejid := c.jid i := strings.Index(barejid, "/") if i >= 0 { barejid = barejid[:i] } println("\nok\n", "jid", c.jid, "\n") fmt.Fprintf(c.tls, "<iq type='set' id='z1'><session xmlns='urn:ietf:params:xml:ns:xmpp-session'/></iq>") fmt.Fprintf(c.tls, "<iq type='set' to='%s' id='z2'><subscribe xmlns='google:push'><item channel='cloudprint.google.com' from='cloudprint.google.com'/></subscribe></iq>", barejid) return nil }
[ "func", "(", "c", "*", "xmppClient", ")", "Subscribe", "(", ")", "error", "{", "barejid", ":=", "c", ".", "jid", "\n", "i", ":=", "strings", ".", "Index", "(", "barejid", ",", "\"", "\"", ")", "\n", "if", "i", ">=", "0", "{", "barejid", "=", "b...
// Subscribe sends a subscription request.
[ "Subscribe", "sends", "a", "subscription", "request", "." ]
fc62025902295658a9c7e89418e095fd598b2682
https://github.com/rsc/rsc/blob/fc62025902295658a9c7e89418e095fd598b2682/cloudprint/xmpp.go#L223-L233
18,164
rsc/rsc
cloudprint/xmpp.go
Status
func (c *xmppClient) Status(status, msg string) error { fmt.Fprintf(c.tls, "<presence xml:lang='en'><show>%s</show><status>%s</status></presence>", status, xmlEscape(msg)) return nil }
go
func (c *xmppClient) Status(status, msg string) error { fmt.Fprintf(c.tls, "<presence xml:lang='en'><show>%s</show><status>%s</status></presence>", status, xmlEscape(msg)) return nil }
[ "func", "(", "c", "*", "xmppClient", ")", "Status", "(", "status", ",", "msg", "string", ")", "error", "{", "fmt", ".", "Fprintf", "(", "c", ".", "tls", ",", "\"", "\"", ",", "status", ",", "xmlEscape", "(", "msg", ")", ")", "\n", "return", "nil"...
// Status sends a presence update.
[ "Status", "sends", "a", "presence", "update", "." ]
fc62025902295658a9c7e89418e095fd598b2682
https://github.com/rsc/rsc/blob/fc62025902295658a9c7e89418e095fd598b2682/cloudprint/xmpp.go#L236-L239
18,165
rsc/rsc
cc/typecheck.go
promote2
func promote2(l, r *Type) *Type { l = promote1(l) r = promote1(r) // if mixed signedness, make l signed and r unsigned. // specifically, if l is unsigned, swap with r. if (l.Kind-Char)&1 == 1 { l, r = r, l } switch { case l.Kind == Void || r.Kind == Void || l.Kind > Double || r.Kind > Double: return nil case l.Kind == r.Kind: return l // double wins. case l.Kind == Double: return l case r.Kind == Double: return r // float wins. case l.Kind == Float: return l case r.Kind == Float: return r // if both signed or both unsigned, higher kind wins. case (l.Kind-Char)&1 == (r.Kind-Char)&1: if l.Kind < r.Kind { return r } return l // mixed signedness: l is signed, r is unsigned (see above). // if unsigned higher kind than signed, unsigned wins. case r.Kind >= l.Kind: return r // signed is higher kind than unsigned (l.Kind > r.Kind). // if signed bigger than unsigned, signed wins. // only possible way this isn't true case (l.Kind-Char)/2 > (r.Kind-Char)/2 && (l.Kind != Long || r.Kind != Uint): return l // otherwise, use unsigned type corresponding to the signed type. default: return &Type{Kind: l.Kind + 1} } panic(fmt.Sprintf("missing case in promote2(%v, %v)", l, r)) }
go
func promote2(l, r *Type) *Type { l = promote1(l) r = promote1(r) // if mixed signedness, make l signed and r unsigned. // specifically, if l is unsigned, swap with r. if (l.Kind-Char)&1 == 1 { l, r = r, l } switch { case l.Kind == Void || r.Kind == Void || l.Kind > Double || r.Kind > Double: return nil case l.Kind == r.Kind: return l // double wins. case l.Kind == Double: return l case r.Kind == Double: return r // float wins. case l.Kind == Float: return l case r.Kind == Float: return r // if both signed or both unsigned, higher kind wins. case (l.Kind-Char)&1 == (r.Kind-Char)&1: if l.Kind < r.Kind { return r } return l // mixed signedness: l is signed, r is unsigned (see above). // if unsigned higher kind than signed, unsigned wins. case r.Kind >= l.Kind: return r // signed is higher kind than unsigned (l.Kind > r.Kind). // if signed bigger than unsigned, signed wins. // only possible way this isn't true case (l.Kind-Char)/2 > (r.Kind-Char)/2 && (l.Kind != Long || r.Kind != Uint): return l // otherwise, use unsigned type corresponding to the signed type. default: return &Type{Kind: l.Kind + 1} } panic(fmt.Sprintf("missing case in promote2(%v, %v)", l, r)) }
[ "func", "promote2", "(", "l", ",", "r", "*", "Type", ")", "*", "Type", "{", "l", "=", "promote1", "(", "l", ")", "\n", "r", "=", "promote1", "(", "r", ")", "\n\n", "// if mixed signedness, make l signed and r unsigned.", "// specifically, if l is unsigned, swap ...
// The "usual arithmetic conversions".
[ "The", "usual", "arithmetic", "conversions", "." ]
fc62025902295658a9c7e89418e095fd598b2682
https://github.com/rsc/rsc/blob/fc62025902295658a9c7e89418e095fd598b2682/cc/typecheck.go#L473-L518
18,166
tvdburgt/go-argon2
argon2.go
Hash
func Hash(ctx *Context, password, salt []byte) ([]byte, error) { if ctx == nil { return nil, ErrContext } return ctx.hash(password, salt) }
go
func Hash(ctx *Context, password, salt []byte) ([]byte, error) { if ctx == nil { return nil, ErrContext } return ctx.hash(password, salt) }
[ "func", "Hash", "(", "ctx", "*", "Context", ",", "password", ",", "salt", "[", "]", "byte", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "if", "ctx", "==", "nil", "{", "return", "nil", ",", "ErrContext", "\n", "}", "\n\n", "return", "ctx",...
// Set C.FLAG_clear_internal_memory = 0 to disable internal memory clearing // Hash hashes a password given a salt and an initialized Argon2 context. It // returns the calculated hash as an output of raw bytes.
[ "Set", "C", ".", "FLAG_clear_internal_memory", "=", "0", "to", "disable", "internal", "memory", "clearing", "Hash", "hashes", "a", "password", "given", "a", "salt", "and", "an", "initialized", "Argon2", "context", ".", "It", "returns", "the", "calculated", "ha...
49d0f0e5973cfdf45080ac824b9a67c24aa38725
https://github.com/tvdburgt/go-argon2/blob/49d0f0e5973cfdf45080ac824b9a67c24aa38725/argon2.go#L44-L50
18,167
tvdburgt/go-argon2
argon2.go
HashEncoded
func HashEncoded(ctx *Context, password []byte, salt []byte) (string, error) { if ctx == nil { return "", ErrContext } if len(password) == 0 { return "", ErrPassword } if len(salt) == 0 { return "", ErrSalt } encodedlen := C.argon2_encodedlen( C.uint32_t(ctx.Iterations), C.uint32_t(ctx.Memory), C.uint32_t(ctx.Parallelism), C.uint32_t(len(salt)), C.uint32_t(ctx.HashLen), C.argon2_type(ctx.Mode)) s := make([]byte, encodedlen) result := C.argon2_hash( C.uint32_t(ctx.Iterations), C.uint32_t(ctx.Memory), C.uint32_t(ctx.Parallelism), unsafe.Pointer(&password[0]), C.size_t(len(password)), unsafe.Pointer(&salt[0]), C.size_t(len(salt)), nil, C.size_t(ctx.HashLen), (*C.char)(unsafe.Pointer(&s[0])), C.size_t(encodedlen), C.argon2_type(ctx.Mode), C.uint32_t(ctx.Version)) if result != C.ARGON2_OK { return "", Error(result) } // Strip trailing null byte(s) s = bytes.TrimRight(s, "\x00") return string(s), nil }
go
func HashEncoded(ctx *Context, password []byte, salt []byte) (string, error) { if ctx == nil { return "", ErrContext } if len(password) == 0 { return "", ErrPassword } if len(salt) == 0 { return "", ErrSalt } encodedlen := C.argon2_encodedlen( C.uint32_t(ctx.Iterations), C.uint32_t(ctx.Memory), C.uint32_t(ctx.Parallelism), C.uint32_t(len(salt)), C.uint32_t(ctx.HashLen), C.argon2_type(ctx.Mode)) s := make([]byte, encodedlen) result := C.argon2_hash( C.uint32_t(ctx.Iterations), C.uint32_t(ctx.Memory), C.uint32_t(ctx.Parallelism), unsafe.Pointer(&password[0]), C.size_t(len(password)), unsafe.Pointer(&salt[0]), C.size_t(len(salt)), nil, C.size_t(ctx.HashLen), (*C.char)(unsafe.Pointer(&s[0])), C.size_t(encodedlen), C.argon2_type(ctx.Mode), C.uint32_t(ctx.Version)) if result != C.ARGON2_OK { return "", Error(result) } // Strip trailing null byte(s) s = bytes.TrimRight(s, "\x00") return string(s), nil }
[ "func", "HashEncoded", "(", "ctx", "*", "Context", ",", "password", "[", "]", "byte", ",", "salt", "[", "]", "byte", ")", "(", "string", ",", "error", ")", "{", "if", "ctx", "==", "nil", "{", "return", "\"", "\"", ",", "ErrContext", "\n", "}", "\...
// HashEncoded hashes a password and produces a crypt-like encoded string.
[ "HashEncoded", "hashes", "a", "password", "and", "produces", "a", "crypt", "-", "like", "encoded", "string", "." ]
49d0f0e5973cfdf45080ac824b9a67c24aa38725
https://github.com/tvdburgt/go-argon2/blob/49d0f0e5973cfdf45080ac824b9a67c24aa38725/argon2.go#L53-L93
18,168
tvdburgt/go-argon2
argon2.go
Verify
func Verify(ctx *Context, hash, password, salt []byte) (bool, error) { if ctx == nil { return false, ErrContext } if len(hash) == 0 { return false, ErrHash } hash2, err := ctx.hash(password, salt) if err != nil { return false, err } return subtle.ConstantTimeCompare(hash, hash2) == 1, nil }
go
func Verify(ctx *Context, hash, password, salt []byte) (bool, error) { if ctx == nil { return false, ErrContext } if len(hash) == 0 { return false, ErrHash } hash2, err := ctx.hash(password, salt) if err != nil { return false, err } return subtle.ConstantTimeCompare(hash, hash2) == 1, nil }
[ "func", "Verify", "(", "ctx", "*", "Context", ",", "hash", ",", "password", ",", "salt", "[", "]", "byte", ")", "(", "bool", ",", "error", ")", "{", "if", "ctx", "==", "nil", "{", "return", "false", ",", "ErrContext", "\n", "}", "\n", "if", "len"...
// Verify verifies an Argon2 hash against a plaintext password.
[ "Verify", "verifies", "an", "Argon2", "hash", "against", "a", "plaintext", "password", "." ]
49d0f0e5973cfdf45080ac824b9a67c24aa38725
https://github.com/tvdburgt/go-argon2/blob/49d0f0e5973cfdf45080ac824b9a67c24aa38725/argon2.go#L96-L110
18,169
tvdburgt/go-argon2
argon2.go
VerifyEncoded
func VerifyEncoded(s string, password []byte) (bool, error) { mode, err := getMode(s) if err != nil { return false, err } cs := C.CString(s) defer C.free(unsafe.Pointer(cs)) result := C.argon2_verify( cs, unsafe.Pointer(&password[0]), C.size_t(len(password)), C.argon2_type(mode)) if result == C.ARGON2_OK { return true, nil } else if result == C.ARGON2_VERIFY_MISMATCH { return false, nil } // argon2_verify always seems to return an error in this case... return false, Error(result) }
go
func VerifyEncoded(s string, password []byte) (bool, error) { mode, err := getMode(s) if err != nil { return false, err } cs := C.CString(s) defer C.free(unsafe.Pointer(cs)) result := C.argon2_verify( cs, unsafe.Pointer(&password[0]), C.size_t(len(password)), C.argon2_type(mode)) if result == C.ARGON2_OK { return true, nil } else if result == C.ARGON2_VERIFY_MISMATCH { return false, nil } // argon2_verify always seems to return an error in this case... return false, Error(result) }
[ "func", "VerifyEncoded", "(", "s", "string", ",", "password", "[", "]", "byte", ")", "(", "bool", ",", "error", ")", "{", "mode", ",", "err", ":=", "getMode", "(", "s", ")", "\n\n", "if", "err", "!=", "nil", "{", "return", "false", ",", "err", "\...
// VerifyEncoded verifies an encoded Argon2 hash s against a plaintext password.
[ "VerifyEncoded", "verifies", "an", "encoded", "Argon2", "hash", "s", "against", "a", "plaintext", "password", "." ]
49d0f0e5973cfdf45080ac824b9a67c24aa38725
https://github.com/tvdburgt/go-argon2/blob/49d0f0e5973cfdf45080ac824b9a67c24aa38725/argon2.go#L113-L137
18,170
tvdburgt/go-argon2
argon2.go
getMode
func getMode(s string) (int, error) { switch { case strings.HasPrefix(s, "$argon2d"): return ModeArgon2d, nil case strings.HasPrefix(s, "$argon2id"): return ModeArgon2id, nil case strings.HasPrefix(s, "$argon2i"): return ModeArgon2i, nil default: return -1, ErrDecodingFail } }
go
func getMode(s string) (int, error) { switch { case strings.HasPrefix(s, "$argon2d"): return ModeArgon2d, nil case strings.HasPrefix(s, "$argon2id"): return ModeArgon2id, nil case strings.HasPrefix(s, "$argon2i"): return ModeArgon2i, nil default: return -1, ErrDecodingFail } }
[ "func", "getMode", "(", "s", "string", ")", "(", "int", ",", "error", ")", "{", "switch", "{", "case", "strings", ".", "HasPrefix", "(", "s", ",", "\"", "\"", ")", ":", "return", "ModeArgon2d", ",", "nil", "\n", "case", "strings", ".", "HasPrefix", ...
// getMode tries to extract the mode from an Argon2 encoded string.
[ "getMode", "tries", "to", "extract", "the", "mode", "from", "an", "Argon2", "encoded", "string", "." ]
49d0f0e5973cfdf45080ac824b9a67c24aa38725
https://github.com/tvdburgt/go-argon2/blob/49d0f0e5973cfdf45080ac824b9a67c24aa38725/argon2.go#L140-L151
18,171
tvdburgt/go-argon2
context.go
NewContext
func NewContext(mode ...int) *Context { context := &Context{ Iterations: 3, Memory: 1 << 12, // 4 MiB Parallelism: 1, HashLen: 32, Mode: ModeArgon2i, Version: VersionDefault, } if len(mode) >= 1 { context.Mode = mode[0] } return context }
go
func NewContext(mode ...int) *Context { context := &Context{ Iterations: 3, Memory: 1 << 12, // 4 MiB Parallelism: 1, HashLen: 32, Mode: ModeArgon2i, Version: VersionDefault, } if len(mode) >= 1 { context.Mode = mode[0] } return context }
[ "func", "NewContext", "(", "mode", "...", "int", ")", "*", "Context", "{", "context", ":=", "&", "Context", "{", "Iterations", ":", "3", ",", "Memory", ":", "1", "<<", "12", ",", "// 4 MiB", "Parallelism", ":", "1", ",", "HashLen", ":", "32", ",", ...
// NewContext initializes a new Argon2 context with reasonable defaults. // allows the mode to be set as an optional paramter
[ "NewContext", "initializes", "a", "new", "Argon2", "context", "with", "reasonable", "defaults", ".", "allows", "the", "mode", "to", "be", "set", "as", "an", "optional", "paramter" ]
49d0f0e5973cfdf45080ac824b9a67c24aa38725
https://github.com/tvdburgt/go-argon2/blob/49d0f0e5973cfdf45080ac824b9a67c24aa38725/context.go#L24-L37
18,172
tvdburgt/go-argon2
context.go
hash
func (ctx *Context) hash(password []byte, salt []byte) ([]byte, error) { if len(password) == 0 { return nil, ErrPassword } if len(salt) == 0 { return nil, ErrSalt } hash := make([]byte, ctx.HashLen) // optional secret secret := (*C.uint8_t)(nil) if len(ctx.Secret) > 0 { secret = (*C.uint8_t)(&ctx.Secret[0]) } // optional associated data associatedData := (*C.uint8_t)(nil) if len(ctx.AssociatedData) > 0 { associatedData = (*C.uint8_t)(&ctx.AssociatedData[0]) } // optional flags flags := FlagDefault if ctx.Flags != 0 { flags = ctx.Flags } // ensure version has a default version := VersionDefault if ctx.Version != 0 { version = ctx.Version } // wrapper to overcome go pointer passing limitations result := C.argon2_wrapper( (*C.uint8_t)(&hash[0]), C.uint32_t(ctx.HashLen), (*C.uint8_t)(&password[0]), C.uint32_t(len(password)), (*C.uint8_t)(&salt[0]), C.uint32_t(len(salt)), secret, C.uint32_t(len(ctx.Secret)), associatedData, C.uint32_t(len(ctx.AssociatedData)), C.uint32_t(ctx.Iterations), C.uint32_t(ctx.Memory), C.uint32_t(ctx.Parallelism), C.uint32_t(ctx.Parallelism), C.uint32_t(version), nil, nil, C.uint32_t(flags), C.argon2_type(ctx.Mode)) if result != C.ARGON2_OK { return nil, Error(result) } return hash, nil }
go
func (ctx *Context) hash(password []byte, salt []byte) ([]byte, error) { if len(password) == 0 { return nil, ErrPassword } if len(salt) == 0 { return nil, ErrSalt } hash := make([]byte, ctx.HashLen) // optional secret secret := (*C.uint8_t)(nil) if len(ctx.Secret) > 0 { secret = (*C.uint8_t)(&ctx.Secret[0]) } // optional associated data associatedData := (*C.uint8_t)(nil) if len(ctx.AssociatedData) > 0 { associatedData = (*C.uint8_t)(&ctx.AssociatedData[0]) } // optional flags flags := FlagDefault if ctx.Flags != 0 { flags = ctx.Flags } // ensure version has a default version := VersionDefault if ctx.Version != 0 { version = ctx.Version } // wrapper to overcome go pointer passing limitations result := C.argon2_wrapper( (*C.uint8_t)(&hash[0]), C.uint32_t(ctx.HashLen), (*C.uint8_t)(&password[0]), C.uint32_t(len(password)), (*C.uint8_t)(&salt[0]), C.uint32_t(len(salt)), secret, C.uint32_t(len(ctx.Secret)), associatedData, C.uint32_t(len(ctx.AssociatedData)), C.uint32_t(ctx.Iterations), C.uint32_t(ctx.Memory), C.uint32_t(ctx.Parallelism), C.uint32_t(ctx.Parallelism), C.uint32_t(version), nil, nil, C.uint32_t(flags), C.argon2_type(ctx.Mode)) if result != C.ARGON2_OK { return nil, Error(result) } return hash, nil }
[ "func", "(", "ctx", "*", "Context", ")", "hash", "(", "password", "[", "]", "byte", ",", "salt", "[", "]", "byte", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "if", "len", "(", "password", ")", "==", "0", "{", "return", "nil", ",", "E...
// hash password and salt
[ "hash", "password", "and", "salt" ]
49d0f0e5973cfdf45080ac824b9a67c24aa38725
https://github.com/tvdburgt/go-argon2/blob/49d0f0e5973cfdf45080ac824b9a67c24aa38725/context.go#L40-L96
18,173
jetbasrawi/go.geteventstore
client.go
SetBasicAuth
func (c *Client) SetBasicAuth(username, password string) { c.credentials = &basicAuthCredentials{ Username: username, Password: password, } }
go
func (c *Client) SetBasicAuth(username, password string) { c.credentials = &basicAuthCredentials{ Username: username, Password: password, } }
[ "func", "(", "c", "*", "Client", ")", "SetBasicAuth", "(", "username", ",", "password", "string", ")", "{", "c", ".", "credentials", "=", "&", "basicAuthCredentials", "{", "Username", ":", "username", ",", "Password", ":", "password", ",", "}", "\n", "}"...
// SetBasicAuth sets the credentials for requests. // // Credentials will be read from the client before each request.
[ "SetBasicAuth", "sets", "the", "credentials", "for", "requests", ".", "Credentials", "will", "be", "read", "from", "the", "client", "before", "each", "request", "." ]
79eb478399b05a176102a5b0b6493f4692fdfc1a
https://github.com/jetbasrawi/go.geteventstore/blob/79eb478399b05a176102a5b0b6493f4692fdfc1a/client.go#L141-L146
18,174
jetbasrawi/go.geteventstore
client.go
GetFeedPath
func (c *Client) GetFeedPath(stream, direction string, version int, pageSize int) (string, error) { ps := pageSize dir := "" switch direction { case "forward", "backward": dir = direction default: return "", fmt.Errorf("Invalid Direction %s. Allowed values are \"forward\" or \"backward\" \n", direction) } v := "head" if version >= 0 { v = strconv.Itoa(version) } if v == "head" && dir == "forward" { return "", fmt.Errorf("Invalid Direction (%s) and version (head) combination.\n", direction) } return fmt.Sprintf("/streams/%s/%s/%s/%d", stream, v, dir, ps), nil }
go
func (c *Client) GetFeedPath(stream, direction string, version int, pageSize int) (string, error) { ps := pageSize dir := "" switch direction { case "forward", "backward": dir = direction default: return "", fmt.Errorf("Invalid Direction %s. Allowed values are \"forward\" or \"backward\" \n", direction) } v := "head" if version >= 0 { v = strconv.Itoa(version) } if v == "head" && dir == "forward" { return "", fmt.Errorf("Invalid Direction (%s) and version (head) combination.\n", direction) } return fmt.Sprintf("/streams/%s/%s/%s/%d", stream, v, dir, ps), nil }
[ "func", "(", "c", "*", "Client", ")", "GetFeedPath", "(", "stream", ",", "direction", "string", ",", "version", "int", ",", "pageSize", "int", ")", "(", "string", ",", "error", ")", "{", "ps", ":=", "pageSize", "\n\n", "dir", ":=", "\"", "\"", "\n", ...
// GetFeedPath returns the path for a feedpage // // Valid directions are "forward" and "backward". // // To get the path to the head of the stream, pass a negative integer in the version // argument and "backward" as the direction.
[ "GetFeedPath", "returns", "the", "path", "for", "a", "feedpage", "Valid", "directions", "are", "forward", "and", "backward", ".", "To", "get", "the", "path", "to", "the", "head", "of", "the", "stream", "pass", "a", "negative", "integer", "in", "the", "vers...
79eb478399b05a176102a5b0b6493f4692fdfc1a
https://github.com/jetbasrawi/go.geteventstore/blob/79eb478399b05a176102a5b0b6493f4692fdfc1a/client.go#L244-L265
18,175
jetbasrawi/go.geteventstore
client.go
SetHeader
func (c *Client) SetHeader(key, value string) { c.headers[key] = value }
go
func (c *Client) SetHeader(key, value string) { c.headers[key] = value }
[ "func", "(", "c", "*", "Client", ")", "SetHeader", "(", "key", ",", "value", "string", ")", "{", "c", ".", "headers", "[", "key", "]", "=", "value", "\n", "}" ]
// SetHeader adds a header to the collection of headers that will be used on http requests. // // Any headers that are set on the client will be included in requests to the eventstore.
[ "SetHeader", "adds", "a", "header", "to", "the", "collection", "of", "headers", "that", "will", "be", "used", "on", "http", "requests", ".", "Any", "headers", "that", "are", "set", "on", "the", "client", "will", "be", "included", "in", "requests", "to", ...
79eb478399b05a176102a5b0b6493f4692fdfc1a
https://github.com/jetbasrawi/go.geteventstore/blob/79eb478399b05a176102a5b0b6493f4692fdfc1a/client.go#L294-L296
18,176
jetbasrawi/go.geteventstore
client.go
getError
func getError(r *http.Response, req *http.Request) error { if c := r.StatusCode; 200 <= c && c <= 299 { return nil } errorResponse := &ErrorResponse{Response: r} data, err := ioutil.ReadAll(r.Body) if err == nil && data != nil { json.Unmarshal(data, errorResponse) } errorResponse.Status = r.Status errorResponse.StatusCode = r.StatusCode errorResponse.Request = req switch r.StatusCode { case http.StatusBadRequest: return &ErrBadRequest{ErrorResponse: errorResponse} case http.StatusUnauthorized: return &ErrUnauthorized{ErrorResponse: errorResponse} case http.StatusServiceUnavailable: return &ErrTemporarilyUnavailable{ErrorResponse: errorResponse} case http.StatusNotFound: return &ErrNotFound{ErrorResponse: errorResponse} case http.StatusGone: return &ErrDeleted{ErrorResponse: errorResponse} default: return &ErrUnexpected{ErrorResponse: errorResponse} } }
go
func getError(r *http.Response, req *http.Request) error { if c := r.StatusCode; 200 <= c && c <= 299 { return nil } errorResponse := &ErrorResponse{Response: r} data, err := ioutil.ReadAll(r.Body) if err == nil && data != nil { json.Unmarshal(data, errorResponse) } errorResponse.Status = r.Status errorResponse.StatusCode = r.StatusCode errorResponse.Request = req switch r.StatusCode { case http.StatusBadRequest: return &ErrBadRequest{ErrorResponse: errorResponse} case http.StatusUnauthorized: return &ErrUnauthorized{ErrorResponse: errorResponse} case http.StatusServiceUnavailable: return &ErrTemporarilyUnavailable{ErrorResponse: errorResponse} case http.StatusNotFound: return &ErrNotFound{ErrorResponse: errorResponse} case http.StatusGone: return &ErrDeleted{ErrorResponse: errorResponse} default: return &ErrUnexpected{ErrorResponse: errorResponse} } }
[ "func", "getError", "(", "r", "*", "http", ".", "Response", ",", "req", "*", "http", ".", "Request", ")", "error", "{", "if", "c", ":=", "r", ".", "StatusCode", ";", "200", "<=", "c", "&&", "c", "<=", "299", "{", "return", "nil", "\n", "}", "\n...
// getError inspects the HTTP response and constructs an appropriate error if // the response was an error.
[ "getError", "inspects", "the", "HTTP", "response", "and", "constructs", "an", "appropriate", "error", "if", "the", "response", "was", "an", "error", "." ]
79eb478399b05a176102a5b0b6493f4692fdfc1a
https://github.com/jetbasrawi/go.geteventstore/blob/79eb478399b05a176102a5b0b6493f4692fdfc1a/client.go#L434-L462
18,177
jetbasrawi/go.geteventstore
internal/uuid/uuid.go
And
func And(u1 UUID, u2 UUID) UUID { u := UUID{} for i := 0; i < 16; i++ { u[i] = u1[i] & u2[i] } return u }
go
func And(u1 UUID, u2 UUID) UUID { u := UUID{} for i := 0; i < 16; i++ { u[i] = u1[i] & u2[i] } return u }
[ "func", "And", "(", "u1", "UUID", ",", "u2", "UUID", ")", "UUID", "{", "u", ":=", "UUID", "{", "}", "\n", "for", "i", ":=", "0", ";", "i", "<", "16", ";", "i", "++", "{", "u", "[", "i", "]", "=", "u1", "[", "i", "]", "&", "u2", "[", "...
// And returns result of binary AND of two UUIDs.
[ "And", "returns", "result", "of", "binary", "AND", "of", "two", "UUIDs", "." ]
79eb478399b05a176102a5b0b6493f4692fdfc1a
https://github.com/jetbasrawi/go.geteventstore/blob/79eb478399b05a176102a5b0b6493f4692fdfc1a/internal/uuid/uuid.go#L152-L158
18,178
jetbasrawi/go.geteventstore
internal/uuid/uuid.go
Or
func Or(u1 UUID, u2 UUID) UUID { u := UUID{} for i := 0; i < 16; i++ { u[i] = u1[i] | u2[i] } return u }
go
func Or(u1 UUID, u2 UUID) UUID { u := UUID{} for i := 0; i < 16; i++ { u[i] = u1[i] | u2[i] } return u }
[ "func", "Or", "(", "u1", "UUID", ",", "u2", "UUID", ")", "UUID", "{", "u", ":=", "UUID", "{", "}", "\n", "for", "i", ":=", "0", ";", "i", "<", "16", ";", "i", "++", "{", "u", "[", "i", "]", "=", "u1", "[", "i", "]", "|", "u2", "[", "i...
// Or returns result of binary OR of two UUIDs.
[ "Or", "returns", "result", "of", "binary", "OR", "of", "two", "UUIDs", "." ]
79eb478399b05a176102a5b0b6493f4692fdfc1a
https://github.com/jetbasrawi/go.geteventstore/blob/79eb478399b05a176102a5b0b6493f4692fdfc1a/internal/uuid/uuid.go#L161-L167
18,179
jetbasrawi/go.geteventstore
examples/02-longpoll/main.go
writeEvents
func writeEvents(client *goes.Client, streamName string) { existingEvents := createTestEvents(10, streamName, serverURL, "FooEvent") writer := client.NewStreamWriter(streamName) err := writer.Append(nil, existingEvents...) if err != nil { log.Fatal(err) } ticker := time.NewTicker(time.Second * 2) go func() { for _ = range ticker.C { num := rand.Intn(5) newEvents := createTestEvents(num, streamName, serverURL, "FooEvent") writer.Append(nil, newEvents...) } }() }
go
func writeEvents(client *goes.Client, streamName string) { existingEvents := createTestEvents(10, streamName, serverURL, "FooEvent") writer := client.NewStreamWriter(streamName) err := writer.Append(nil, existingEvents...) if err != nil { log.Fatal(err) } ticker := time.NewTicker(time.Second * 2) go func() { for _ = range ticker.C { num := rand.Intn(5) newEvents := createTestEvents(num, streamName, serverURL, "FooEvent") writer.Append(nil, newEvents...) } }() }
[ "func", "writeEvents", "(", "client", "*", "goes", ".", "Client", ",", "streamName", "string", ")", "{", "existingEvents", ":=", "createTestEvents", "(", "10", ",", "streamName", ",", "serverURL", ",", "\"", "\"", ")", "\n\n", "writer", ":=", "client", "."...
// writeEvents will create an initial set of events and then write them to // the eventstore. // At two second intervals a random number of events between 1 and 5 will be written // to the eventstore.
[ "writeEvents", "will", "create", "an", "initial", "set", "of", "events", "and", "then", "write", "them", "to", "the", "eventstore", ".", "At", "two", "second", "intervals", "a", "random", "number", "of", "events", "between", "1", "and", "5", "will", "be", ...
79eb478399b05a176102a5b0b6493f4692fdfc1a
https://github.com/jetbasrawi/go.geteventstore/blob/79eb478399b05a176102a5b0b6493f4692fdfc1a/examples/02-longpoll/main.go#L112-L130
18,180
jetbasrawi/go.geteventstore
atom/atom.go
GetLink
func (f *Feed) GetLink(name string) *Link { if f == nil { return nil } for _, v := range f.Link { if v.Rel == name { return &v } } return nil }
go
func (f *Feed) GetLink(name string) *Link { if f == nil { return nil } for _, v := range f.Link { if v.Rel == name { return &v } } return nil }
[ "func", "(", "f", "*", "Feed", ")", "GetLink", "(", "name", "string", ")", "*", "Link", "{", "if", "f", "==", "nil", "{", "return", "nil", "\n", "}", "\n\n", "for", "_", ",", "v", ":=", "range", "f", ".", "Link", "{", "if", "v", ".", "Rel", ...
// GetLink gets the link with the name specified by the link argument.
[ "GetLink", "gets", "the", "link", "with", "the", "name", "specified", "by", "the", "link", "argument", "." ]
79eb478399b05a176102a5b0b6493f4692fdfc1a
https://github.com/jetbasrawi/go.geteventstore/blob/79eb478399b05a176102a5b0b6493f4692fdfc1a/atom/atom.go#L23-L34
18,181
jetbasrawi/go.geteventstore
atom/atom.go
PrettyPrint
func (f *Feed) PrettyPrint() string { b, err := xml.MarshalIndent(f, "", " ") if err != nil { panic(err) } return string(b) }
go
func (f *Feed) PrettyPrint() string { b, err := xml.MarshalIndent(f, "", " ") if err != nil { panic(err) } return string(b) }
[ "func", "(", "f", "*", "Feed", ")", "PrettyPrint", "(", ")", "string", "{", "b", ",", "err", ":=", "xml", ".", "MarshalIndent", "(", "f", ",", "\"", "\"", ",", "\"", "\"", ")", "\n", "if", "err", "!=", "nil", "{", "panic", "(", "err", ")", "\...
// PrettyPrint returns an indented string representation of the feed.
[ "PrettyPrint", "returns", "an", "indented", "string", "representation", "of", "the", "feed", "." ]
79eb478399b05a176102a5b0b6493f4692fdfc1a
https://github.com/jetbasrawi/go.geteventstore/blob/79eb478399b05a176102a5b0b6493f4692fdfc1a/atom/atom.go#L37-L43
18,182
jetbasrawi/go.geteventstore
atom/atom.go
GetEventURLs
func (f *Feed) GetEventURLs() ([]string, error) { s := make([]string, len(f.Entry)) for i := 0; i < len(f.Entry); i++ { e := f.Entry[i] s[i] = strings.TrimRight(e.Link[1].Href, "/") } return s, nil }
go
func (f *Feed) GetEventURLs() ([]string, error) { s := make([]string, len(f.Entry)) for i := 0; i < len(f.Entry); i++ { e := f.Entry[i] s[i] = strings.TrimRight(e.Link[1].Href, "/") } return s, nil }
[ "func", "(", "f", "*", "Feed", ")", "GetEventURLs", "(", ")", "(", "[", "]", "string", ",", "error", ")", "{", "s", ":=", "make", "(", "[", "]", "string", ",", "len", "(", "f", ".", "Entry", ")", ")", "\n", "for", "i", ":=", "0", ";", "i", ...
// GetEventURLs extracts a slice of event urls from the feed object.
[ "GetEventURLs", "extracts", "a", "slice", "of", "event", "urls", "from", "the", "feed", "object", "." ]
79eb478399b05a176102a5b0b6493f4692fdfc1a
https://github.com/jetbasrawi/go.geteventstore/blob/79eb478399b05a176102a5b0b6493f4692fdfc1a/atom/atom.go#L46-L53
18,183
jetbasrawi/go.geteventstore
events.go
PrettyPrint
func (e *EventResponse) PrettyPrint() string { b, err := json.MarshalIndent(e, "", " ") if err != nil { panic(err) } return string(b) }
go
func (e *EventResponse) PrettyPrint() string { b, err := json.MarshalIndent(e, "", " ") if err != nil { panic(err) } return string(b) }
[ "func", "(", "e", "*", "EventResponse", ")", "PrettyPrint", "(", ")", "string", "{", "b", ",", "err", ":=", "json", ".", "MarshalIndent", "(", "e", ",", "\"", "\"", ",", "\"", "\"", ")", "\n", "if", "err", "!=", "nil", "{", "panic", "(", "err", ...
// PrettyPrint renders an indented json view of the EventResponse.
[ "PrettyPrint", "renders", "an", "indented", "json", "view", "of", "the", "EventResponse", "." ]
79eb478399b05a176102a5b0b6493f4692fdfc1a
https://github.com/jetbasrawi/go.geteventstore/blob/79eb478399b05a176102a5b0b6493f4692fdfc1a/events.go#L31-L39
18,184
jetbasrawi/go.geteventstore
events.go
NewEvent
func NewEvent(eventID, eventType string, data interface{}, meta interface{}) *Event { e := &Event{} e.EventID = eventID if eventID == "" { e.EventID = NewUUID() } e.EventType = eventType if eventType == "" { e.EventType = typeOf(data) } e.Data = data e.MetaData = meta return e }
go
func NewEvent(eventID, eventType string, data interface{}, meta interface{}) *Event { e := &Event{} e.EventID = eventID if eventID == "" { e.EventID = NewUUID() } e.EventType = eventType if eventType == "" { e.EventType = typeOf(data) } e.Data = data e.MetaData = meta return e }
[ "func", "NewEvent", "(", "eventID", ",", "eventType", "string", ",", "data", "interface", "{", "}", ",", "meta", "interface", "{", "}", ")", "*", "Event", "{", "e", ":=", "&", "Event", "{", "}", "\n\n", "e", ".", "EventID", "=", "eventID", "\n", "i...
// NewEvent creates a new event object. // // If an empty eventId is provided a new uuid will be generated automatically // and retured in the event. // If an empty eventType is provided the eventType will be set to the // name of the type provided. // data and meta can be nil.
[ "NewEvent", "creates", "a", "new", "event", "object", ".", "If", "an", "empty", "eventId", "is", "provided", "a", "new", "uuid", "will", "be", "generated", "automatically", "and", "retured", "in", "the", "event", ".", "If", "an", "empty", "eventType", "is"...
79eb478399b05a176102a5b0b6493f4692fdfc1a
https://github.com/jetbasrawi/go.geteventstore/blob/79eb478399b05a176102a5b0b6493f4692fdfc1a/events.go#L109-L125
18,185
jetbasrawi/go.geteventstore
events.go
typeOf
func typeOf(i interface{}) string { if i == nil { return "" } return reflect.TypeOf(i).Elem().Name() }
go
func typeOf(i interface{}) string { if i == nil { return "" } return reflect.TypeOf(i).Elem().Name() }
[ "func", "typeOf", "(", "i", "interface", "{", "}", ")", "string", "{", "if", "i", "==", "nil", "{", "return", "\"", "\"", "\n", "}", "\n", "return", "reflect", ".", "TypeOf", "(", "i", ")", ".", "Elem", "(", ")", ".", "Name", "(", ")", "\n", ...
// typeOf is a helper to get the names of types.
[ "typeOf", "is", "a", "helper", "to", "get", "the", "names", "of", "types", "." ]
79eb478399b05a176102a5b0b6493f4692fdfc1a
https://github.com/jetbasrawi/go.geteventstore/blob/79eb478399b05a176102a5b0b6493f4692fdfc1a/events.go#L133-L138
18,186
jetbasrawi/go.geteventstore
streamreader.go
Scan
func (s *StreamReader) Scan(e interface{}, m interface{}) error { if s.lasterr != nil { return s.lasterr } if s.eventResponse == nil { return &ErrNoMoreEvents{} } if e != nil { data, ok := s.eventResponse.Event.Data.(*json.RawMessage) if !ok { return fmt.Errorf("Could not unmarshal the event. Event data is not of type *json.RawMessage") } if err := json.Unmarshal(*data, e); err != nil { return err } } if m != nil && s.EventResponse().Event.MetaData != nil { meta, ok := s.eventResponse.Event.MetaData.(*json.RawMessage) if !ok { return fmt.Errorf("Could not unmarshal the event. Event data is not of type *json.RawMessage") } if err := json.Unmarshal(*meta, &m); err != nil { return err } } return nil }
go
func (s *StreamReader) Scan(e interface{}, m interface{}) error { if s.lasterr != nil { return s.lasterr } if s.eventResponse == nil { return &ErrNoMoreEvents{} } if e != nil { data, ok := s.eventResponse.Event.Data.(*json.RawMessage) if !ok { return fmt.Errorf("Could not unmarshal the event. Event data is not of type *json.RawMessage") } if err := json.Unmarshal(*data, e); err != nil { return err } } if m != nil && s.EventResponse().Event.MetaData != nil { meta, ok := s.eventResponse.Event.MetaData.(*json.RawMessage) if !ok { return fmt.Errorf("Could not unmarshal the event. Event data is not of type *json.RawMessage") } if err := json.Unmarshal(*meta, &m); err != nil { return err } } return nil }
[ "func", "(", "s", "*", "StreamReader", ")", "Scan", "(", "e", "interface", "{", "}", ",", "m", "interface", "{", "}", ")", "error", "{", "if", "s", ".", "lasterr", "!=", "nil", "{", "return", "s", ".", "lasterr", "\n", "}", "\n\n", "if", "s", "...
// Scan deserializes event and event metadata into the types passed in // as arguments e and m.
[ "Scan", "deserializes", "event", "and", "event", "metadata", "into", "the", "types", "passed", "in", "as", "arguments", "e", "and", "m", "." ]
79eb478399b05a176102a5b0b6493f4692fdfc1a
https://github.com/jetbasrawi/go.geteventstore/blob/79eb478399b05a176102a5b0b6493f4692fdfc1a/streamreader.go#L137-L170
18,187
jetbasrawi/go.geteventstore
streamreader.go
LongPoll
func (s *StreamReader) LongPoll(seconds int) { if seconds > 0 { s.client.SetHeader("ES-LongPoll", strconv.Itoa(seconds)) } else { s.client.DeleteHeader("ES-LongPoll") } }
go
func (s *StreamReader) LongPoll(seconds int) { if seconds > 0 { s.client.SetHeader("ES-LongPoll", strconv.Itoa(seconds)) } else { s.client.DeleteHeader("ES-LongPoll") } }
[ "func", "(", "s", "*", "StreamReader", ")", "LongPoll", "(", "seconds", "int", ")", "{", "if", "seconds", ">", "0", "{", "s", ".", "client", ".", "SetHeader", "(", "\"", "\"", ",", "strconv", ".", "Itoa", "(", "seconds", ")", ")", "\n", "}", "els...
// LongPoll causes the server to wait up to the number of seconds specified // for results to become available at the URL requested. // // LongPoll is useful when polling the end of the stream as it returns quickly // after new events are found which means that it is more responsive than polling // over some arbitrary time interval. It also reduces the number of // unproductive calls to the server polling for events when there are no new // events to return. // // Setting the argument seconds to any integer value above 0 will cause the // request to be made with ES-LongPoll set to that value. Any value 0 or below // will cause the request to be made without ES-LongPoll and the server will not // wait to return.
[ "LongPoll", "causes", "the", "server", "to", "wait", "up", "to", "the", "number", "of", "seconds", "specified", "for", "results", "to", "become", "available", "at", "the", "URL", "requested", ".", "LongPoll", "is", "useful", "when", "polling", "the", "end", ...
79eb478399b05a176102a5b0b6493f4692fdfc1a
https://github.com/jetbasrawi/go.geteventstore/blob/79eb478399b05a176102a5b0b6493f4692fdfc1a/streamreader.go#L185-L191
18,188
fagongzi/goetty
mem_pool.go
NewSyncPool
func NewSyncPool(minSize, maxSize, factor int) *SyncPool { n := 0 for chunkSize := minSize; chunkSize <= maxSize; chunkSize *= factor { n++ } pool := &SyncPool{ make([]sync.Pool, n), make([]int, n), minSize, maxSize, } n = 0 for chunkSize := minSize; chunkSize <= maxSize; chunkSize *= factor { pool.classesSize[n] = chunkSize pool.classes[n].New = func(size int) func() interface{} { return func() interface{} { buf := make([]byte, size) return &buf } }(chunkSize) n++ } return pool }
go
func NewSyncPool(minSize, maxSize, factor int) *SyncPool { n := 0 for chunkSize := minSize; chunkSize <= maxSize; chunkSize *= factor { n++ } pool := &SyncPool{ make([]sync.Pool, n), make([]int, n), minSize, maxSize, } n = 0 for chunkSize := minSize; chunkSize <= maxSize; chunkSize *= factor { pool.classesSize[n] = chunkSize pool.classes[n].New = func(size int) func() interface{} { return func() interface{} { buf := make([]byte, size) return &buf } }(chunkSize) n++ } return pool }
[ "func", "NewSyncPool", "(", "minSize", ",", "maxSize", ",", "factor", "int", ")", "*", "SyncPool", "{", "n", ":=", "0", "\n", "for", "chunkSize", ":=", "minSize", ";", "chunkSize", "<=", "maxSize", ";", "chunkSize", "*=", "factor", "{", "n", "++", "\n"...
// NewSyncPool create a sync.Pool base slab allocation memory pool. // minSize is the smallest chunk size. // maxSize is the lagest chunk size. // factor is used to control growth of chunk size.
[ "NewSyncPool", "create", "a", "sync", ".", "Pool", "base", "slab", "allocation", "memory", "pool", ".", "minSize", "is", "the", "smallest", "chunk", "size", ".", "maxSize", "is", "the", "lagest", "chunk", "size", ".", "factor", "is", "used", "to", "control...
8db0d25ac2019c322508640bf56de7219332f94c
https://github.com/fagongzi/goetty/blob/8db0d25ac2019c322508640bf56de7219332f94c/mem_pool.go#L26-L48
18,189
fagongzi/goetty
conn_pool.go
NewAddressBasedPool
func NewAddressBasedPool(factory func(string) IOSession, handler ConnStatusHandler) *AddressBasedPool { return &AddressBasedPool{ handler: handler, factory: factory, conns: make(map[string]IOSession), } }
go
func NewAddressBasedPool(factory func(string) IOSession, handler ConnStatusHandler) *AddressBasedPool { return &AddressBasedPool{ handler: handler, factory: factory, conns: make(map[string]IOSession), } }
[ "func", "NewAddressBasedPool", "(", "factory", "func", "(", "string", ")", "IOSession", ",", "handler", "ConnStatusHandler", ")", "*", "AddressBasedPool", "{", "return", "&", "AddressBasedPool", "{", "handler", ":", "handler", ",", "factory", ":", "factory", ","...
// NewAddressBasedPool returns a AddressBasedPool with a factory fun
[ "NewAddressBasedPool", "returns", "a", "AddressBasedPool", "with", "a", "factory", "fun" ]
8db0d25ac2019c322508640bf56de7219332f94c
https://github.com/fagongzi/goetty/blob/8db0d25ac2019c322508640bf56de7219332f94c/conn_pool.go#L175-L181
18,190
fagongzi/goetty
conn_pool.go
GetConn
func (pool *AddressBasedPool) GetConn(addr string) (IOSession, error) { conn := pool.getConnLocked(addr) if err := pool.checkConnect(addr, conn); err != nil { return nil, err } return conn, nil }
go
func (pool *AddressBasedPool) GetConn(addr string) (IOSession, error) { conn := pool.getConnLocked(addr) if err := pool.checkConnect(addr, conn); err != nil { return nil, err } return conn, nil }
[ "func", "(", "pool", "*", "AddressBasedPool", ")", "GetConn", "(", "addr", "string", ")", "(", "IOSession", ",", "error", ")", "{", "conn", ":=", "pool", ".", "getConnLocked", "(", "addr", ")", "\n", "if", "err", ":=", "pool", ".", "checkConnect", "(",...
// GetConn returns a IOSession that connected to the address // Every address has only one connection in the pool
[ "GetConn", "returns", "a", "IOSession", "that", "connected", "to", "the", "address", "Every", "address", "has", "only", "one", "connection", "in", "the", "pool" ]
8db0d25ac2019c322508640bf56de7219332f94c
https://github.com/fagongzi/goetty/blob/8db0d25ac2019c322508640bf56de7219332f94c/conn_pool.go#L185-L192
18,191
fagongzi/goetty
conn_pool.go
RemoveConn
func (pool *AddressBasedPool) RemoveConn(addr string) { pool.Lock() if conn, ok := pool.conns[addr]; ok { conn.Close() delete(pool.conns, addr) } pool.Unlock() }
go
func (pool *AddressBasedPool) RemoveConn(addr string) { pool.Lock() if conn, ok := pool.conns[addr]; ok { conn.Close() delete(pool.conns, addr) } pool.Unlock() }
[ "func", "(", "pool", "*", "AddressBasedPool", ")", "RemoveConn", "(", "addr", "string", ")", "{", "pool", ".", "Lock", "(", ")", "\n", "if", "conn", ",", "ok", ":=", "pool", ".", "conns", "[", "addr", "]", ";", "ok", "{", "conn", ".", "Close", "(...
// RemoveConn close the conn, and remove from the pool
[ "RemoveConn", "close", "the", "conn", "and", "remove", "from", "the", "pool" ]
8db0d25ac2019c322508640bf56de7219332f94c
https://github.com/fagongzi/goetty/blob/8db0d25ac2019c322508640bf56de7219332f94c/conn_pool.go#L195-L202
18,192
fagongzi/goetty
conn_pool.go
RemoveConnIfMatches
func (pool *AddressBasedPool) RemoveConnIfMatches(addr string, target IOSession) bool { removed := false pool.Lock() if conn, ok := pool.conns[addr]; ok && conn == target { conn.Close() delete(pool.conns, addr) removed = true } pool.Unlock() return removed }
go
func (pool *AddressBasedPool) RemoveConnIfMatches(addr string, target IOSession) bool { removed := false pool.Lock() if conn, ok := pool.conns[addr]; ok && conn == target { conn.Close() delete(pool.conns, addr) removed = true } pool.Unlock() return removed }
[ "func", "(", "pool", "*", "AddressBasedPool", ")", "RemoveConnIfMatches", "(", "addr", "string", ",", "target", "IOSession", ")", "bool", "{", "removed", ":=", "false", "\n", "pool", ".", "Lock", "(", ")", "\n", "if", "conn", ",", "ok", ":=", "pool", "...
// RemoveConnIfMatches close the conn, and remove from the pool if the conn in the pool is match the given
[ "RemoveConnIfMatches", "close", "the", "conn", "and", "remove", "from", "the", "pool", "if", "the", "conn", "in", "the", "pool", "is", "match", "the", "given" ]
8db0d25ac2019c322508640bf56de7219332f94c
https://github.com/fagongzi/goetty/blob/8db0d25ac2019c322508640bf56de7219332f94c/conn_pool.go#L205-L217
18,193
fagongzi/goetty
conn_pool.go
ForEach
func (pool *AddressBasedPool) ForEach(visitor func(addr string, conn IOSession)) { pool.Lock() for addr, conn := range pool.conns { visitor(addr, conn) } pool.Unlock() }
go
func (pool *AddressBasedPool) ForEach(visitor func(addr string, conn IOSession)) { pool.Lock() for addr, conn := range pool.conns { visitor(addr, conn) } pool.Unlock() }
[ "func", "(", "pool", "*", "AddressBasedPool", ")", "ForEach", "(", "visitor", "func", "(", "addr", "string", ",", "conn", "IOSession", ")", ")", "{", "pool", ".", "Lock", "(", ")", "\n", "for", "addr", ",", "conn", ":=", "range", "pool", ".", "conns"...
// ForEach do foreach session
[ "ForEach", "do", "foreach", "session" ]
8db0d25ac2019c322508640bf56de7219332f94c
https://github.com/fagongzi/goetty/blob/8db0d25ac2019c322508640bf56de7219332f94c/conn_pool.go#L274-L280
18,194
fagongzi/goetty
codec_length_field.go
NewIntLengthFieldBasedEncoderWithPrepare
func NewIntLengthFieldBasedEncoderWithPrepare(base Encoder, prepare func(data interface{}, out *ByteBuf) error) Encoder { return &IntLengthFieldBasedEncoder{ base: base, prepare: prepare, } }
go
func NewIntLengthFieldBasedEncoderWithPrepare(base Encoder, prepare func(data interface{}, out *ByteBuf) error) Encoder { return &IntLengthFieldBasedEncoder{ base: base, prepare: prepare, } }
[ "func", "NewIntLengthFieldBasedEncoderWithPrepare", "(", "base", "Encoder", ",", "prepare", "func", "(", "data", "interface", "{", "}", ",", "out", "*", "ByteBuf", ")", "error", ")", "Encoder", "{", "return", "&", "IntLengthFieldBasedEncoder", "{", "base", ":", ...
// NewIntLengthFieldBasedEncoderWithPrepare returns a encoder with base and prepare fun
[ "NewIntLengthFieldBasedEncoderWithPrepare", "returns", "a", "encoder", "with", "base", "and", "prepare", "fun" ]
8db0d25ac2019c322508640bf56de7219332f94c
https://github.com/fagongzi/goetty/blob/8db0d25ac2019c322508640bf56de7219332f94c/codec_length_field.go#L87-L92
18,195
fagongzi/goetty
buf.go
ReadN
func ReadN(r io.Reader, n int) ([]byte, error) { data := make([]byte, n) _, err := r.Read(data) if err != nil { return nil, err } return data, nil }
go
func ReadN(r io.Reader, n int) ([]byte, error) { data := make([]byte, n) _, err := r.Read(data) if err != nil { return nil, err } return data, nil }
[ "func", "ReadN", "(", "r", "io", ".", "Reader", ",", "n", "int", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "data", ":=", "make", "(", "[", "]", "byte", ",", "n", ")", "\n", "_", ",", "err", ":=", "r", ".", "Read", "(", "data", "...
//ReadN read n bytes from a reader
[ "ReadN", "read", "n", "bytes", "from", "a", "reader" ]
8db0d25ac2019c322508640bf56de7219332f94c
https://github.com/fagongzi/goetty/blob/8db0d25ac2019c322508640bf56de7219332f94c/buf.go#L14-L23
18,196
fagongzi/goetty
buf.go
ReadInt
func ReadInt(r io.Reader) (int, error) { data, err := ReadN(r, 4) if err != nil { return 0, err } return Byte2Int(data), nil }
go
func ReadInt(r io.Reader) (int, error) { data, err := ReadN(r, 4) if err != nil { return 0, err } return Byte2Int(data), nil }
[ "func", "ReadInt", "(", "r", "io", ".", "Reader", ")", "(", "int", ",", "error", ")", "{", "data", ",", "err", ":=", "ReadN", "(", "r", ",", "4", ")", "\n", "if", "err", "!=", "nil", "{", "return", "0", ",", "err", "\n", "}", "\n", "return", ...
//ReadInt read a int value from a reader
[ "ReadInt", "read", "a", "int", "value", "from", "a", "reader" ]
8db0d25ac2019c322508640bf56de7219332f94c
https://github.com/fagongzi/goetty/blob/8db0d25ac2019c322508640bf56de7219332f94c/buf.go#L26-L34
18,197
fagongzi/goetty
buf.go
Byte2Int
func Byte2Int(data []byte) int { return int((int(data[0])&0xff)<<24 | (int(data[1])&0xff)<<16 | (int(data[2])&0xff)<<8 | (int(data[3]) & 0xff)) }
go
func Byte2Int(data []byte) int { return int((int(data[0])&0xff)<<24 | (int(data[1])&0xff)<<16 | (int(data[2])&0xff)<<8 | (int(data[3]) & 0xff)) }
[ "func", "Byte2Int", "(", "data", "[", "]", "byte", ")", "int", "{", "return", "int", "(", "(", "int", "(", "data", "[", "0", "]", ")", "&", "0xff", ")", "<<", "24", "|", "(", "int", "(", "data", "[", "1", "]", ")", "&", "0xff", ")", "<<", ...
// Byte2Int byte array to int value using big order
[ "Byte2Int", "byte", "array", "to", "int", "value", "using", "big", "order" ]
8db0d25ac2019c322508640bf56de7219332f94c
https://github.com/fagongzi/goetty/blob/8db0d25ac2019c322508640bf56de7219332f94c/buf.go#L37-L39
18,198
fagongzi/goetty
buf.go
Byte2Int64
func Byte2Int64(data []byte) int64 { return int64((int64(data[0])&0xff)<<56 | (int64(data[1])&0xff)<<48 | (int64(data[2])&0xff)<<40 | (int64(data[3])&0xff)<<32 | (int64(data[4])&0xff)<<24 | (int64(data[5])&0xff)<<16 | (int64(data[6])&0xff)<<8 | (int64(data[7]) & 0xff)) }
go
func Byte2Int64(data []byte) int64 { return int64((int64(data[0])&0xff)<<56 | (int64(data[1])&0xff)<<48 | (int64(data[2])&0xff)<<40 | (int64(data[3])&0xff)<<32 | (int64(data[4])&0xff)<<24 | (int64(data[5])&0xff)<<16 | (int64(data[6])&0xff)<<8 | (int64(data[7]) & 0xff)) }
[ "func", "Byte2Int64", "(", "data", "[", "]", "byte", ")", "int64", "{", "return", "int64", "(", "(", "int64", "(", "data", "[", "0", "]", ")", "&", "0xff", ")", "<<", "56", "|", "(", "int64", "(", "data", "[", "1", "]", ")", "&", "0xff", ")",...
// Byte2Int64 byte array to int64 value using big order
[ "Byte2Int64", "byte", "array", "to", "int64", "value", "using", "big", "order" ]
8db0d25ac2019c322508640bf56de7219332f94c
https://github.com/fagongzi/goetty/blob/8db0d25ac2019c322508640bf56de7219332f94c/buf.go#L42-L44
18,199
fagongzi/goetty
buf.go
Int2BytesTo
func Int2BytesTo(v int, ret []byte) { ret[0] = byte(v >> 24) ret[1] = byte(v >> 16) ret[2] = byte(v >> 8) ret[3] = byte(v) }
go
func Int2BytesTo(v int, ret []byte) { ret[0] = byte(v >> 24) ret[1] = byte(v >> 16) ret[2] = byte(v >> 8) ret[3] = byte(v) }
[ "func", "Int2BytesTo", "(", "v", "int", ",", "ret", "[", "]", "byte", ")", "{", "ret", "[", "0", "]", "=", "byte", "(", "v", ">>", "24", ")", "\n", "ret", "[", "1", "]", "=", "byte", "(", "v", ">>", "16", ")", "\n", "ret", "[", "2", "]", ...
// Int2BytesTo int value to bytes array using big order
[ "Int2BytesTo", "int", "value", "to", "bytes", "array", "using", "big", "order" ]
8db0d25ac2019c322508640bf56de7219332f94c
https://github.com/fagongzi/goetty/blob/8db0d25ac2019c322508640bf56de7219332f94c/buf.go#L62-L67