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
partition
stringclasses
1 value
hyperhq/hyperd
storage/graphdriver/rawblock/driver.go
Status
func (d *Driver) Status() [][2]string { return [][2]string{ {"Backing Filesystem", d.backingFs}, {"Support Copy-On-Write", fmt.Sprintf("%v", d.cow)}, {"Block Filesystem", d.blockFs}, {"Block Size", fmt.Sprintf("%s", units.HumanSize(float64(d.blockSize)))}, } }
go
func (d *Driver) Status() [][2]string { return [][2]string{ {"Backing Filesystem", d.backingFs}, {"Support Copy-On-Write", fmt.Sprintf("%v", d.cow)}, {"Block Filesystem", d.blockFs}, {"Block Size", fmt.Sprintf("%s", units.HumanSize(float64(d.blockSize)))}, } }
[ "func", "(", "d", "*", "Driver", ")", "Status", "(", ")", "[", "]", "[", "2", "]", "string", "{", "return", "[", "]", "[", "2", "]", "string", "{", "{", "\"", "\"", ",", "d", ".", "backingFs", "}", ",", "{", "\"", "\"", ",", "fmt", ".", "...
// Status is used for implementing the graphdriver.ProtoDriver interface.
[ "Status", "is", "used", "for", "implementing", "the", "graphdriver", ".", "ProtoDriver", "interface", "." ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/storage/graphdriver/rawblock/driver.go#L131-L138
train
hyperhq/hyperd
storage/graphdriver/rawblock/driver.go
Create
func (d *Driver) Create(id, parent, mountLabel string) error { if err := idtools.MkdirAllAs(filepath.Dir(d.block(id)), 0700, d.uid, d.gid); err != nil { return err } if parent == "" { return CreateBlock(d.block(id), d.blockFs, mountLabel, d.blockSize) } if out, err := exec.Command("cp", "-a", "--reflink=auto", d.block(parent), d.block(id)).CombinedOutput(); err != nil { return fmt.Errorf("Failed to reflink:%v:%s", err, string(out)) } return nil }
go
func (d *Driver) Create(id, parent, mountLabel string) error { if err := idtools.MkdirAllAs(filepath.Dir(d.block(id)), 0700, d.uid, d.gid); err != nil { return err } if parent == "" { return CreateBlock(d.block(id), d.blockFs, mountLabel, d.blockSize) } if out, err := exec.Command("cp", "-a", "--reflink=auto", d.block(parent), d.block(id)).CombinedOutput(); err != nil { return fmt.Errorf("Failed to reflink:%v:%s", err, string(out)) } return nil }
[ "func", "(", "d", "*", "Driver", ")", "Create", "(", "id", ",", "parent", ",", "mountLabel", "string", ")", "error", "{", "if", "err", ":=", "idtools", ".", "MkdirAllAs", "(", "filepath", ".", "Dir", "(", "d", ".", "block", "(", "id", ")", ")", "...
// Create prepares the filesystem for the rawblock driver and copies the block from the parent.
[ "Create", "prepares", "the", "filesystem", "for", "the", "rawblock", "driver", "and", "copies", "the", "block", "from", "the", "parent", "." ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/storage/graphdriver/rawblock/driver.go#L151-L162
train
hyperhq/hyperd
storage/graphdriver/rawblock/driver.go
Exists
func (d *Driver) Exists(id string) bool { _, err := os.Stat(d.block(id)) return err == nil }
go
func (d *Driver) Exists(id string) bool { _, err := os.Stat(d.block(id)) return err == nil }
[ "func", "(", "d", "*", "Driver", ")", "Exists", "(", "id", "string", ")", "bool", "{", "_", ",", "err", ":=", "os", ".", "Stat", "(", "d", ".", "block", "(", "id", ")", ")", "\n", "return", "err", "==", "nil", "\n", "}" ]
// Exists checks to see if the directory exists for the given id.
[ "Exists", "checks", "to", "see", "if", "the", "directory", "exists", "for", "the", "given", "id", "." ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/storage/graphdriver/rawblock/driver.go#L210-L213
train
hyperhq/hyperd
engine/streams.go
Tail
func Tail(buffer *bytes.Buffer, n int) string { if n <= 0 { return "" } s := strings.TrimRightFunc(buffer.String(), unicode.IsSpace) i := len(s) - 1 for ; i >= 0 && n > 0; i-- { if s[i] == '\n' { n-- if n == 0 { break } } } // when i == -1, return the whole string which is s[0:] return s[i+1:] }
go
func Tail(buffer *bytes.Buffer, n int) string { if n <= 0 { return "" } s := strings.TrimRightFunc(buffer.String(), unicode.IsSpace) i := len(s) - 1 for ; i >= 0 && n > 0; i-- { if s[i] == '\n' { n-- if n == 0 { break } } } // when i == -1, return the whole string which is s[0:] return s[i+1:] }
[ "func", "Tail", "(", "buffer", "*", "bytes", ".", "Buffer", ",", "n", "int", ")", "string", "{", "if", "n", "<=", "0", "{", "return", "\"", "\"", "\n", "}", "\n", "s", ":=", "strings", ".", "TrimRightFunc", "(", "buffer", ".", "String", "(", ")",...
// Tail returns the n last lines of a buffer // stripped out of trailing white spaces, if any. // // if n <= 0, returns an empty string
[ "Tail", "returns", "the", "n", "last", "lines", "of", "a", "buffer", "stripped", "out", "of", "trailing", "white", "spaces", "if", "any", ".", "if", "n", "<", "=", "0", "returns", "an", "empty", "string" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/engine/streams.go#L24-L40
train
hyperhq/hyperd
engine/streams.go
Used
func (o *Output) Used() bool { o.Lock() defer o.Unlock() return o.used }
go
func (o *Output) Used() bool { o.Lock() defer o.Unlock() return o.used }
[ "func", "(", "o", "*", "Output", ")", "Used", "(", ")", "bool", "{", "o", ".", "Lock", "(", ")", "\n", "defer", "o", ".", "Unlock", "(", ")", "\n", "return", "o", ".", "used", "\n", "}" ]
// Return true if something was written on this output
[ "Return", "true", "if", "something", "was", "written", "on", "this", "output" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/engine/streams.go#L49-L53
train
hyperhq/hyperd
engine/streams.go
Add
func (o *Output) Add(dst io.Writer) { o.Lock() defer o.Unlock() o.dests = append(o.dests, dst) }
go
func (o *Output) Add(dst io.Writer) { o.Lock() defer o.Unlock() o.dests = append(o.dests, dst) }
[ "func", "(", "o", "*", "Output", ")", "Add", "(", "dst", "io", ".", "Writer", ")", "{", "o", ".", "Lock", "(", ")", "\n", "defer", "o", ".", "Unlock", "(", ")", "\n", "o", ".", "dests", "=", "append", "(", "o", ".", "dests", ",", "dst", ")"...
// Add attaches a new destination to the Output. Any data subsequently written // to the output will be written to the new destination in addition to all the others. // This method is thread-safe.
[ "Add", "attaches", "a", "new", "destination", "to", "the", "Output", ".", "Any", "data", "subsequently", "written", "to", "the", "output", "will", "be", "written", "to", "the", "new", "destination", "in", "addition", "to", "all", "the", "others", ".", "Thi...
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/engine/streams.go#L58-L62
train
hyperhq/hyperd
engine/streams.go
Set
func (o *Output) Set(dst io.Writer) { o.Close() o.Lock() defer o.Unlock() o.dests = []io.Writer{dst} }
go
func (o *Output) Set(dst io.Writer) { o.Close() o.Lock() defer o.Unlock() o.dests = []io.Writer{dst} }
[ "func", "(", "o", "*", "Output", ")", "Set", "(", "dst", "io", ".", "Writer", ")", "{", "o", ".", "Close", "(", ")", "\n", "o", ".", "Lock", "(", ")", "\n", "defer", "o", ".", "Unlock", "(", ")", "\n", "o", ".", "dests", "=", "[", "]", "i...
// Set closes and remove existing destination and then attaches a new destination to // the Output. Any data subsequently written to the output will be written to the new // destination in addition to all the others. This method is thread-safe.
[ "Set", "closes", "and", "remove", "existing", "destination", "and", "then", "attaches", "a", "new", "destination", "to", "the", "Output", ".", "Any", "data", "subsequently", "written", "to", "the", "output", "will", "be", "written", "to", "the", "new", "dest...
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/engine/streams.go#L67-L72
train
hyperhq/hyperd
engine/streams.go
Write
func (o *Output) Write(p []byte) (n int, err error) { o.Lock() defer o.Unlock() o.used = true var firstErr error for _, dst := range o.dests { _, err := dst.Write(p) if err != nil && firstErr == nil { firstErr = err } } return len(p), firstErr }
go
func (o *Output) Write(p []byte) (n int, err error) { o.Lock() defer o.Unlock() o.used = true var firstErr error for _, dst := range o.dests { _, err := dst.Write(p) if err != nil && firstErr == nil { firstErr = err } } return len(p), firstErr }
[ "func", "(", "o", "*", "Output", ")", "Write", "(", "p", "[", "]", "byte", ")", "(", "n", "int", ",", "err", "error", ")", "{", "o", ".", "Lock", "(", ")", "\n", "defer", "o", ".", "Unlock", "(", ")", "\n", "o", ".", "used", "=", "true", ...
// Write writes the same data to all registered destinations. // This method is thread-safe.
[ "Write", "writes", "the", "same", "data", "to", "all", "registered", "destinations", ".", "This", "method", "is", "thread", "-", "safe", "." ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/engine/streams.go#L86-L98
train
hyperhq/hyperd
engine/streams.go
Close
func (o *Output) Close() error { o.Lock() defer o.Unlock() var firstErr error for _, dst := range o.dests { if closer, ok := dst.(io.Closer); ok { err := closer.Close() if err != nil && firstErr == nil { firstErr = err } } } o.tasks.Wait() o.dests = nil return firstErr }
go
func (o *Output) Close() error { o.Lock() defer o.Unlock() var firstErr error for _, dst := range o.dests { if closer, ok := dst.(io.Closer); ok { err := closer.Close() if err != nil && firstErr == nil { firstErr = err } } } o.tasks.Wait() o.dests = nil return firstErr }
[ "func", "(", "o", "*", "Output", ")", "Close", "(", ")", "error", "{", "o", ".", "Lock", "(", ")", "\n", "defer", "o", ".", "Unlock", "(", ")", "\n", "var", "firstErr", "error", "\n", "for", "_", ",", "dst", ":=", "range", "o", ".", "dests", ...
// Close unregisters all destinations and waits for all background // AddTail and AddString tasks to complete. // The Close method of each destination is called if it exists.
[ "Close", "unregisters", "all", "destinations", "and", "waits", "for", "all", "background", "AddTail", "and", "AddString", "tasks", "to", "complete", ".", "The", "Close", "method", "of", "each", "destination", "is", "called", "if", "it", "exists", "." ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/engine/streams.go#L103-L118
train
hyperhq/hyperd
engine/streams.go
Read
func (i *Input) Read(p []byte) (n int, err error) { i.Mutex.Lock() defer i.Mutex.Unlock() if i.src == nil { return 0, io.EOF } return i.src.Read(p) }
go
func (i *Input) Read(p []byte) (n int, err error) { i.Mutex.Lock() defer i.Mutex.Unlock() if i.src == nil { return 0, io.EOF } return i.src.Read(p) }
[ "func", "(", "i", "*", "Input", ")", "Read", "(", "p", "[", "]", "byte", ")", "(", "n", "int", ",", "err", "error", ")", "{", "i", ".", "Mutex", ".", "Lock", "(", ")", "\n", "defer", "i", ".", "Mutex", ".", "Unlock", "(", ")", "\n", "if", ...
// Read reads from the input in a thread-safe way.
[ "Read", "reads", "from", "the", "input", "in", "a", "thread", "-", "safe", "way", "." ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/engine/streams.go#L132-L139
train
hyperhq/hyperd
engine/streams.go
Close
func (i *Input) Close() error { if i.src != nil { if closer, ok := i.src.(io.Closer); ok { return closer.Close() } } return nil }
go
func (i *Input) Close() error { if i.src != nil { if closer, ok := i.src.(io.Closer); ok { return closer.Close() } } return nil }
[ "func", "(", "i", "*", "Input", ")", "Close", "(", ")", "error", "{", "if", "i", ".", "src", "!=", "nil", "{", "if", "closer", ",", "ok", ":=", "i", ".", "src", ".", "(", "io", ".", "Closer", ")", ";", "ok", "{", "return", "closer", ".", "C...
// Closes the src // Not thread safe on purpose
[ "Closes", "the", "src", "Not", "thread", "safe", "on", "purpose" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/engine/streams.go#L143-L150
train
hyperhq/hyperd
engine/streams.go
Add
func (i *Input) Add(src io.Reader) error { i.Mutex.Lock() defer i.Mutex.Unlock() if i.src != nil { return fmt.Errorf("Maximum number of sources reached: 1") } i.src = src return nil }
go
func (i *Input) Add(src io.Reader) error { i.Mutex.Lock() defer i.Mutex.Unlock() if i.src != nil { return fmt.Errorf("Maximum number of sources reached: 1") } i.src = src return nil }
[ "func", "(", "i", "*", "Input", ")", "Add", "(", "src", "io", ".", "Reader", ")", "error", "{", "i", ".", "Mutex", ".", "Lock", "(", ")", "\n", "defer", "i", ".", "Mutex", ".", "Unlock", "(", ")", "\n", "if", "i", ".", "src", "!=", "nil", "...
// Add attaches a new source to the input. // Add can only be called once per input. Subsequent calls will // return an error.
[ "Add", "attaches", "a", "new", "source", "to", "the", "input", ".", "Add", "can", "only", "be", "called", "once", "per", "input", ".", "Subsequent", "calls", "will", "return", "an", "error", "." ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/engine/streams.go#L155-L163
train
hyperhq/hyperd
engine/streams.go
AddEnv
func (o *Output) AddEnv() (dst *Env, err error) { src, err := o.AddPipe() if err != nil { return nil, err } dst = &Env{} o.tasks.Add(1) go func() { defer o.tasks.Done() decoder := NewDecoder(src) for { env, err := decoder.Decode() if err != nil { return } *dst = *env } }() return dst, nil }
go
func (o *Output) AddEnv() (dst *Env, err error) { src, err := o.AddPipe() if err != nil { return nil, err } dst = &Env{} o.tasks.Add(1) go func() { defer o.tasks.Done() decoder := NewDecoder(src) for { env, err := decoder.Decode() if err != nil { return } *dst = *env } }() return dst, nil }
[ "func", "(", "o", "*", "Output", ")", "AddEnv", "(", ")", "(", "dst", "*", "Env", ",", "err", "error", ")", "{", "src", ",", "err", ":=", "o", ".", "AddPipe", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", ...
// AddEnv starts a new goroutine which will decode all subsequent data // as a stream of json-encoded objects, and point `dst` to the last // decoded object. // The result `env` can be queried using the type-neutral Env interface. // It is not safe to query `env` until the Output is closed.
[ "AddEnv", "starts", "a", "new", "goroutine", "which", "will", "decode", "all", "subsequent", "data", "as", "a", "stream", "of", "json", "-", "encoded", "objects", "and", "point", "dst", "to", "the", "last", "decoded", "object", ".", "The", "result", "env",...
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/engine/streams.go#L170-L189
train
hyperhq/hyperd
serverrpc/server.go
NewServerRPC
func NewServerRPC(d *daemon.Daemon) *ServerRPC { s := &ServerRPC{ server: grpc.NewServer(grpc.UnaryInterceptor(unaryLoger), grpc.StreamInterceptor(streamLoger)), daemon: d, } s.registerServer() return s }
go
func NewServerRPC(d *daemon.Daemon) *ServerRPC { s := &ServerRPC{ server: grpc.NewServer(grpc.UnaryInterceptor(unaryLoger), grpc.StreamInterceptor(streamLoger)), daemon: d, } s.registerServer() return s }
[ "func", "NewServerRPC", "(", "d", "*", "daemon", ".", "Daemon", ")", "*", "ServerRPC", "{", "s", ":=", "&", "ServerRPC", "{", "server", ":", "grpc", ".", "NewServer", "(", "grpc", ".", "UnaryInterceptor", "(", "unaryLoger", ")", ",", "grpc", ".", "Stre...
// NewServerRPC creates a new ServerRPC
[ "NewServerRPC", "creates", "a", "new", "ServerRPC" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/serverrpc/server.go#L59-L66
train
hyperhq/hyperd
serverrpc/server.go
Serve
func (s *ServerRPC) Serve(addr string) error { s.Log(hlog.DEBUG, "start server at %s", addr) l, err := net.Listen("tcp", addr) if err != nil { s.Log(hlog.ERROR, "Failed to listen %s: %v", addr, err) return err } return s.server.Serve(l) }
go
func (s *ServerRPC) Serve(addr string) error { s.Log(hlog.DEBUG, "start server at %s", addr) l, err := net.Listen("tcp", addr) if err != nil { s.Log(hlog.ERROR, "Failed to listen %s: %v", addr, err) return err } return s.server.Serve(l) }
[ "func", "(", "s", "*", "ServerRPC", ")", "Serve", "(", "addr", "string", ")", "error", "{", "s", ".", "Log", "(", "hlog", ".", "DEBUG", ",", "\"", "\"", ",", "addr", ")", "\n", "l", ",", "err", ":=", "net", ".", "Listen", "(", "\"", "\"", ","...
// Serve serves gRPC request by goroutines
[ "Serve", "serves", "gRPC", "request", "by", "goroutines" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/serverrpc/server.go#L84-L93
train
hyperhq/hyperd
integration/client.go
GetPodInfo
func (c *HyperClient) GetPodInfo(podID string) (*types.PodInfo, error) { request := types.PodInfoRequest{ PodID: podID, } pod, err := c.client.PodInfo(c.ctx, &request) if err != nil { return nil, err } return pod.PodInfo, nil }
go
func (c *HyperClient) GetPodInfo(podID string) (*types.PodInfo, error) { request := types.PodInfoRequest{ PodID: podID, } pod, err := c.client.PodInfo(c.ctx, &request) if err != nil { return nil, err } return pod.PodInfo, nil }
[ "func", "(", "c", "*", "HyperClient", ")", "GetPodInfo", "(", "podID", "string", ")", "(", "*", "types", ".", "PodInfo", ",", "error", ")", "{", "request", ":=", "types", ".", "PodInfoRequest", "{", "PodID", ":", "podID", ",", "}", "\n", "pod", ",", ...
// GetPodInfo gets pod info by podID
[ "GetPodInfo", "gets", "pod", "info", "by", "podID" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/integration/client.go#L37-L47
train
hyperhq/hyperd
integration/client.go
GetPodList
func (c *HyperClient) GetPodList() ([]*types.PodListResult, error) { request := types.PodListRequest{} podList, err := c.client.PodList( c.ctx, &request, ) if err != nil { return nil, err } return podList.PodList, nil }
go
func (c *HyperClient) GetPodList() ([]*types.PodListResult, error) { request := types.PodListRequest{} podList, err := c.client.PodList( c.ctx, &request, ) if err != nil { return nil, err } return podList.PodList, nil }
[ "func", "(", "c", "*", "HyperClient", ")", "GetPodList", "(", ")", "(", "[", "]", "*", "types", ".", "PodListResult", ",", "error", ")", "{", "request", ":=", "types", ".", "PodListRequest", "{", "}", "\n", "podList", ",", "err", ":=", "c", ".", "c...
// GetPodList get a list of Pods
[ "GetPodList", "get", "a", "list", "of", "Pods" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/integration/client.go#L50-L61
train
hyperhq/hyperd
integration/client.go
GetVMList
func (c *HyperClient) GetVMList() ([]*types.VMListResult, error) { req := types.VMListRequest{} vmList, err := c.client.VMList( c.ctx, &req, ) if err != nil { return nil, err } return vmList.VmList, nil }
go
func (c *HyperClient) GetVMList() ([]*types.VMListResult, error) { req := types.VMListRequest{} vmList, err := c.client.VMList( c.ctx, &req, ) if err != nil { return nil, err } return vmList.VmList, nil }
[ "func", "(", "c", "*", "HyperClient", ")", "GetVMList", "(", ")", "(", "[", "]", "*", "types", ".", "VMListResult", ",", "error", ")", "{", "req", ":=", "types", ".", "VMListRequest", "{", "}", "\n", "vmList", ",", "err", ":=", "c", ".", "client", ...
// GetVMList gets a list of VMs
[ "GetVMList", "gets", "a", "list", "of", "VMs" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/integration/client.go#L64-L75
train
hyperhq/hyperd
integration/client.go
GetContainerList
func (c *HyperClient) GetContainerList() ([]*types.ContainerListResult, error) { req := types.ContainerListRequest{} containerList, err := c.client.ContainerList( c.ctx, &req, ) if err != nil { return nil, err } return containerList.ContainerList, nil }
go
func (c *HyperClient) GetContainerList() ([]*types.ContainerListResult, error) { req := types.ContainerListRequest{} containerList, err := c.client.ContainerList( c.ctx, &req, ) if err != nil { return nil, err } return containerList.ContainerList, nil }
[ "func", "(", "c", "*", "HyperClient", ")", "GetContainerList", "(", ")", "(", "[", "]", "*", "types", ".", "ContainerListResult", ",", "error", ")", "{", "req", ":=", "types", ".", "ContainerListRequest", "{", "}", "\n", "containerList", ",", "err", ":="...
// GetContainerList gets a list of containers
[ "GetContainerList", "gets", "a", "list", "of", "containers" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/integration/client.go#L78-L89
train
hyperhq/hyperd
integration/client.go
GetContainerInfo
func (c *HyperClient) GetContainerInfo(container string) (*types.ContainerInfo, error) { req := types.ContainerInfoRequest{ Container: container, } cinfo, err := c.client.ContainerInfo( c.ctx, &req, ) if err != nil { return nil, err } return cinfo.ContainerInfo, nil }
go
func (c *HyperClient) GetContainerInfo(container string) (*types.ContainerInfo, error) { req := types.ContainerInfoRequest{ Container: container, } cinfo, err := c.client.ContainerInfo( c.ctx, &req, ) if err != nil { return nil, err } return cinfo.ContainerInfo, nil }
[ "func", "(", "c", "*", "HyperClient", ")", "GetContainerInfo", "(", "container", "string", ")", "(", "*", "types", ".", "ContainerInfo", ",", "error", ")", "{", "req", ":=", "types", ".", "ContainerInfoRequest", "{", "Container", ":", "container", ",", "}"...
// GetContainerInfo gets container info by container name or id
[ "GetContainerInfo", "gets", "container", "info", "by", "container", "name", "or", "id" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/integration/client.go#L92-L105
train
hyperhq/hyperd
integration/client.go
GetContainerLogs
func (c *HyperClient) GetContainerLogs(container string) ([]byte, error) { req := types.ContainerLogsRequest{ Container: container, Follow: false, Timestamps: false, Tail: "", Since: "", Stdout: true, Stderr: true, } stream, err := c.client.ContainerLogs( c.ctx, &req, ) if err != nil { return nil, err } ret := []byte{} for { res, err := stream.Recv() if err == io.EOF { if req.Follow == true { continue } break } if err != nil { return nil, err } ret = append(ret, res.Log...) } return ret, nil }
go
func (c *HyperClient) GetContainerLogs(container string) ([]byte, error) { req := types.ContainerLogsRequest{ Container: container, Follow: false, Timestamps: false, Tail: "", Since: "", Stdout: true, Stderr: true, } stream, err := c.client.ContainerLogs( c.ctx, &req, ) if err != nil { return nil, err } ret := []byte{} for { res, err := stream.Recv() if err == io.EOF { if req.Follow == true { continue } break } if err != nil { return nil, err } ret = append(ret, res.Log...) } return ret, nil }
[ "func", "(", "c", "*", "HyperClient", ")", "GetContainerLogs", "(", "container", "string", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "req", ":=", "types", ".", "ContainerLogsRequest", "{", "Container", ":", "container", ",", "Follow", ":", "fal...
// GetContainerLogs gets container log by container name or id
[ "GetContainerLogs", "gets", "container", "log", "by", "container", "name", "or", "id" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/integration/client.go#L108-L142
train
hyperhq/hyperd
integration/client.go
PostAttach
func (c *HyperClient) PostAttach(id string, tty bool) error { stream, err := c.client.Attach(c.ctx) if err != nil { return err } extractor := NewExtractor(tty) req := types.AttachMessage{ ContainerID: id, } if err := stream.Send(&req); err != nil { return err } cmd := types.AttachMessage{ Data: []byte("echo Hello Hyper\n"), } if err := stream.Send(&cmd); err != nil { return err } res, err := stream.Recv() if err != nil { return err } out, _, err := extractor.Extract(res.Data) if err != nil { return err } if string(out) != "Hello Hyper\n" { return fmt.Errorf("post attach response error\n") } return nil }
go
func (c *HyperClient) PostAttach(id string, tty bool) error { stream, err := c.client.Attach(c.ctx) if err != nil { return err } extractor := NewExtractor(tty) req := types.AttachMessage{ ContainerID: id, } if err := stream.Send(&req); err != nil { return err } cmd := types.AttachMessage{ Data: []byte("echo Hello Hyper\n"), } if err := stream.Send(&cmd); err != nil { return err } res, err := stream.Recv() if err != nil { return err } out, _, err := extractor.Extract(res.Data) if err != nil { return err } if string(out) != "Hello Hyper\n" { return fmt.Errorf("post attach response error\n") } return nil }
[ "func", "(", "c", "*", "HyperClient", ")", "PostAttach", "(", "id", "string", ",", "tty", "bool", ")", "error", "{", "stream", ",", "err", ":=", "c", ".", "client", ".", "Attach", "(", "c", ".", "ctx", ")", "\n", "if", "err", "!=", "nil", "{", ...
// PostAttach attach to a container or pod by id
[ "PostAttach", "attach", "to", "a", "container", "or", "pod", "by", "id" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/integration/client.go#L242-L279
train
hyperhq/hyperd
integration/client.go
GetImageList
func (c *HyperClient) GetImageList() ([]*types.ImageInfo, error) { req := types.ImageListRequest{} imageList, err := c.client.ImageList( c.ctx, &req, ) if err != nil { return nil, err } return imageList.ImageList, nil }
go
func (c *HyperClient) GetImageList() ([]*types.ImageInfo, error) { req := types.ImageListRequest{} imageList, err := c.client.ImageList( c.ctx, &req, ) if err != nil { return nil, err } return imageList.ImageList, nil }
[ "func", "(", "c", "*", "HyperClient", ")", "GetImageList", "(", ")", "(", "[", "]", "*", "types", ".", "ImageInfo", ",", "error", ")", "{", "req", ":=", "types", ".", "ImageListRequest", "{", "}", "\n", "imageList", ",", "err", ":=", "c", ".", "cli...
// GetImageList gets a list of images
[ "GetImageList", "gets", "a", "list", "of", "images" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/integration/client.go#L282-L293
train
hyperhq/hyperd
integration/client.go
CreatePod
func (c *HyperClient) CreatePod(spec *types.UserPod) (string, error) { req := types.PodCreateRequest{ PodSpec: spec, } resp, err := c.client.PodCreate( c.ctx, &req, ) if err != nil { return "", err } return resp.PodID, nil }
go
func (c *HyperClient) CreatePod(spec *types.UserPod) (string, error) { req := types.PodCreateRequest{ PodSpec: spec, } resp, err := c.client.PodCreate( c.ctx, &req, ) if err != nil { return "", err } return resp.PodID, nil }
[ "func", "(", "c", "*", "HyperClient", ")", "CreatePod", "(", "spec", "*", "types", ".", "UserPod", ")", "(", "string", ",", "error", ")", "{", "req", ":=", "types", ".", "PodCreateRequest", "{", "PodSpec", ":", "spec", ",", "}", "\n", "resp", ",", ...
// CreatePod creates a pod
[ "CreatePod", "creates", "a", "pod" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/integration/client.go#L296-L309
train
hyperhq/hyperd
integration/client.go
CreateContainer
func (c *HyperClient) CreateContainer(podID string, spec *types.UserContainer) (string, error) { req := types.ContainerCreateRequest{ PodID: podID, ContainerSpec: spec, } resp, err := c.client.ContainerCreate(c.ctx, &req) if err != nil { return "", err } return resp.ContainerID, nil }
go
func (c *HyperClient) CreateContainer(podID string, spec *types.UserContainer) (string, error) { req := types.ContainerCreateRequest{ PodID: podID, ContainerSpec: spec, } resp, err := c.client.ContainerCreate(c.ctx, &req) if err != nil { return "", err } return resp.ContainerID, nil }
[ "func", "(", "c", "*", "HyperClient", ")", "CreateContainer", "(", "podID", "string", ",", "spec", "*", "types", ".", "UserContainer", ")", "(", "string", ",", "error", ")", "{", "req", ":=", "types", ".", "ContainerCreateRequest", "{", "PodID", ":", "po...
// CreateContainer creates a container
[ "CreateContainer", "creates", "a", "container" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/integration/client.go#L312-L323
train
hyperhq/hyperd
integration/client.go
RenameContainer
func (c *HyperClient) RenameContainer(oldName string, newName string) error { req := types.ContainerRenameRequest{ OldContainerName: oldName, NewContainerName: newName, } _, err := c.client.ContainerRename(c.ctx, &req) if err != nil { return err } return nil }
go
func (c *HyperClient) RenameContainer(oldName string, newName string) error { req := types.ContainerRenameRequest{ OldContainerName: oldName, NewContainerName: newName, } _, err := c.client.ContainerRename(c.ctx, &req) if err != nil { return err } return nil }
[ "func", "(", "c", "*", "HyperClient", ")", "RenameContainer", "(", "oldName", "string", ",", "newName", "string", ")", "error", "{", "req", ":=", "types", ".", "ContainerRenameRequest", "{", "OldContainerName", ":", "oldName", ",", "NewContainerName", ":", "ne...
// RenameContainer renames a container
[ "RenameContainer", "renames", "a", "container" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/integration/client.go#L326-L338
train
hyperhq/hyperd
integration/client.go
RemovePod
func (c *HyperClient) RemovePod(podID string) error { _, err := c.client.PodRemove( c.ctx, &types.PodRemoveRequest{PodID: podID}, ) if err != nil { return err } return nil }
go
func (c *HyperClient) RemovePod(podID string) error { _, err := c.client.PodRemove( c.ctx, &types.PodRemoveRequest{PodID: podID}, ) if err != nil { return err } return nil }
[ "func", "(", "c", "*", "HyperClient", ")", "RemovePod", "(", "podID", "string", ")", "error", "{", "_", ",", "err", ":=", "c", ".", "client", ".", "PodRemove", "(", "c", ".", "ctx", ",", "&", "types", ".", "PodRemoveRequest", "{", "PodID", ":", "po...
// RemovePod removes a pod by podID
[ "RemovePod", "removes", "a", "pod", "by", "podID" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/integration/client.go#L341-L352
train
hyperhq/hyperd
integration/client.go
ContainerExecSignal
func (c *HyperClient) ContainerExecSignal(container, execID string, sig int64) error { req := types.ExecSignalRequest{ ContainerID: container, ExecID: execID, Signal: sig, } _, err := c.client.ExecSignal(c.ctx, &req) if err != nil { return err } return nil }
go
func (c *HyperClient) ContainerExecSignal(container, execID string, sig int64) error { req := types.ExecSignalRequest{ ContainerID: container, ExecID: execID, Signal: sig, } _, err := c.client.ExecSignal(c.ctx, &req) if err != nil { return err } return nil }
[ "func", "(", "c", "*", "HyperClient", ")", "ContainerExecSignal", "(", "container", ",", "execID", "string", ",", "sig", "int64", ")", "error", "{", "req", ":=", "types", ".", "ExecSignalRequest", "{", "ContainerID", ":", "container", ",", "ExecID", ":", "...
// ContainerExecSignal sends signal to specified exec of specified container
[ "ContainerExecSignal", "sends", "signal", "to", "specified", "exec", "of", "specified", "container" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/integration/client.go#L355-L367
train
hyperhq/hyperd
integration/client.go
ContainerExecCreate
func (c *HyperClient) ContainerExecCreate(container string, command []string, tty bool) (string, error) { req := types.ExecCreateRequest{ ContainerID: container, Command: command, Tty: tty, } resp, err := c.client.ExecCreate(c.ctx, &req) if err != nil { return "", err } return resp.ExecID, nil }
go
func (c *HyperClient) ContainerExecCreate(container string, command []string, tty bool) (string, error) { req := types.ExecCreateRequest{ ContainerID: container, Command: command, Tty: tty, } resp, err := c.client.ExecCreate(c.ctx, &req) if err != nil { return "", err } return resp.ExecID, nil }
[ "func", "(", "c", "*", "HyperClient", ")", "ContainerExecCreate", "(", "container", "string", ",", "command", "[", "]", "string", ",", "tty", "bool", ")", "(", "string", ",", "error", ")", "{", "req", ":=", "types", ".", "ExecCreateRequest", "{", "Contai...
// ContainerExecCreate creates exec in a container
[ "ContainerExecCreate", "creates", "exec", "in", "a", "container" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/integration/client.go#L370-L382
train
hyperhq/hyperd
integration/client.go
ContainerExecStart
func (c *HyperClient) ContainerExecStart(containerId, execId string, stdin io.ReadCloser, stdout, stderr io.Writer, tty bool) error { request := types.ExecStartRequest{ ContainerID: containerId, ExecID: execId, } stream, err := c.client.ExecStart(context.Background()) if err != nil { return err } if err := stream.Send(&request); err != nil { return err } extractor := NewExtractor(tty) var recvStdoutError chan error if stdout != nil || stderr != nil { recvStdoutError = promise.Go(func() (err error) { for { in, err := stream.Recv() if err != nil && err != io.EOF { return err } if in != nil && in.Stdout != nil { so, se, ee := extractor.Extract(in.Stdout) if ee != nil { return ee } if len(so) > 0 { nw, ew := stdout.Write(so) if ew != nil { return ew } if nw != len(so) { return io.ErrShortWrite } } if len(se) > 0 { nw, ew := stdout.Write(se) if ew != nil { return ew } if nw != len(se) { return io.ErrShortWrite } } } if err == io.EOF { break } } return nil }) } if stdin != nil { go func() error { defer stream.CloseSend() buf := make([]byte, 32) for { nr, err := stdin.Read(buf) if nr > 0 { if err := stream.Send(&types.ExecStartRequest{Stdin: buf[:nr]}); err != nil { return err } } if err == io.EOF { break } if err != nil { return err } } return nil }() } if stdout != nil || stderr != nil { if err := <-recvStdoutError; err != nil { return err } } return nil }
go
func (c *HyperClient) ContainerExecStart(containerId, execId string, stdin io.ReadCloser, stdout, stderr io.Writer, tty bool) error { request := types.ExecStartRequest{ ContainerID: containerId, ExecID: execId, } stream, err := c.client.ExecStart(context.Background()) if err != nil { return err } if err := stream.Send(&request); err != nil { return err } extractor := NewExtractor(tty) var recvStdoutError chan error if stdout != nil || stderr != nil { recvStdoutError = promise.Go(func() (err error) { for { in, err := stream.Recv() if err != nil && err != io.EOF { return err } if in != nil && in.Stdout != nil { so, se, ee := extractor.Extract(in.Stdout) if ee != nil { return ee } if len(so) > 0 { nw, ew := stdout.Write(so) if ew != nil { return ew } if nw != len(so) { return io.ErrShortWrite } } if len(se) > 0 { nw, ew := stdout.Write(se) if ew != nil { return ew } if nw != len(se) { return io.ErrShortWrite } } } if err == io.EOF { break } } return nil }) } if stdin != nil { go func() error { defer stream.CloseSend() buf := make([]byte, 32) for { nr, err := stdin.Read(buf) if nr > 0 { if err := stream.Send(&types.ExecStartRequest{Stdin: buf[:nr]}); err != nil { return err } } if err == io.EOF { break } if err != nil { return err } } return nil }() } if stdout != nil || stderr != nil { if err := <-recvStdoutError; err != nil { return err } } return nil }
[ "func", "(", "c", "*", "HyperClient", ")", "ContainerExecStart", "(", "containerId", ",", "execId", "string", ",", "stdin", "io", ".", "ReadCloser", ",", "stdout", ",", "stderr", "io", ".", "Writer", ",", "tty", "bool", ")", "error", "{", "request", ":="...
// ContainerExecStart starts exec in a container with input stream in and output stream out
[ "ContainerExecStart", "starts", "exec", "in", "a", "container", "with", "input", "stream", "in", "and", "output", "stream", "out" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/integration/client.go#L385-L466
train
hyperhq/hyperd
integration/client.go
StartPod
func (c *HyperClient) StartPod(podID string) error { req := &types.PodStartRequest{ PodID: podID, } _, err := c.client.PodStart(c.ctx, req) if err != nil { return err } return nil }
go
func (c *HyperClient) StartPod(podID string) error { req := &types.PodStartRequest{ PodID: podID, } _, err := c.client.PodStart(c.ctx, req) if err != nil { return err } return nil }
[ "func", "(", "c", "*", "HyperClient", ")", "StartPod", "(", "podID", "string", ")", "error", "{", "req", ":=", "&", "types", ".", "PodStartRequest", "{", "PodID", ":", "podID", ",", "}", "\n\n", "_", ",", "err", ":=", "c", ".", "client", ".", "PodS...
// StartPod starts a pod by podID
[ "StartPod", "starts", "a", "pod", "by", "podID" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/integration/client.go#L469-L480
train
hyperhq/hyperd
integration/client.go
StopPod
func (c *HyperClient) StopPod(podID string) (int, string, error) { resp, err := c.client.PodStop(c.ctx, &types.PodStopRequest{ PodID: podID, }) if err != nil { return -1, "", err } return int(resp.Code), resp.Cause, nil }
go
func (c *HyperClient) StopPod(podID string) (int, string, error) { resp, err := c.client.PodStop(c.ctx, &types.PodStopRequest{ PodID: podID, }) if err != nil { return -1, "", err } return int(resp.Code), resp.Cause, nil }
[ "func", "(", "c", "*", "HyperClient", ")", "StopPod", "(", "podID", "string", ")", "(", "int", ",", "string", ",", "error", ")", "{", "resp", ",", "err", ":=", "c", ".", "client", ".", "PodStop", "(", "c", ".", "ctx", ",", "&", "types", ".", "P...
// StopPod stops a pod
[ "StopPod", "stops", "a", "pod" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/integration/client.go#L483-L492
train
hyperhq/hyperd
integration/client.go
PausePod
func (c *HyperClient) PausePod(podID string) error { _, err := c.client.PodPause(c.ctx, &types.PodPauseRequest{ PodID: podID, }) if err != nil { return err } return nil }
go
func (c *HyperClient) PausePod(podID string) error { _, err := c.client.PodPause(c.ctx, &types.PodPauseRequest{ PodID: podID, }) if err != nil { return err } return nil }
[ "func", "(", "c", "*", "HyperClient", ")", "PausePod", "(", "podID", "string", ")", "error", "{", "_", ",", "err", ":=", "c", ".", "client", ".", "PodPause", "(", "c", ".", "ctx", ",", "&", "types", ".", "PodPauseRequest", "{", "PodID", ":", "podID...
// PausePod pauses a pod
[ "PausePod", "pauses", "a", "pod" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/integration/client.go#L495-L504
train
hyperhq/hyperd
integration/client.go
UnpausePod
func (c *HyperClient) UnpausePod(podID string) error { _, err := c.client.PodUnpause(c.ctx, &types.PodUnpauseRequest{ PodID: podID, }) if err != nil { return err } return nil }
go
func (c *HyperClient) UnpausePod(podID string) error { _, err := c.client.PodUnpause(c.ctx, &types.PodUnpauseRequest{ PodID: podID, }) if err != nil { return err } return nil }
[ "func", "(", "c", "*", "HyperClient", ")", "UnpausePod", "(", "podID", "string", ")", "error", "{", "_", ",", "err", ":=", "c", ".", "client", ".", "PodUnpause", "(", "c", ".", "ctx", ",", "&", "types", ".", "PodUnpauseRequest", "{", "PodID", ":", ...
// UnpausePod unpauses a pod
[ "UnpausePod", "unpauses", "a", "pod" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/integration/client.go#L507-L516
train
hyperhq/hyperd
integration/client.go
PodSignal
func (c *HyperClient) PodSignal(podID string, signal int64) error { _, err := c.client.PodSignal(c.ctx, &types.PodSignalRequest{ PodID: podID, Signal: signal, }) if err != nil { return err } return nil }
go
func (c *HyperClient) PodSignal(podID string, signal int64) error { _, err := c.client.PodSignal(c.ctx, &types.PodSignalRequest{ PodID: podID, Signal: signal, }) if err != nil { return err } return nil }
[ "func", "(", "c", "*", "HyperClient", ")", "PodSignal", "(", "podID", "string", ",", "signal", "int64", ")", "error", "{", "_", ",", "err", ":=", "c", ".", "client", ".", "PodSignal", "(", "c", ".", "ctx", ",", "&", "types", ".", "PodSignalRequest", ...
// PodSignal sends a signal to all containers of specified pod
[ "PodSignal", "sends", "a", "signal", "to", "all", "containers", "of", "specified", "pod" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/integration/client.go#L519-L529
train
hyperhq/hyperd
integration/client.go
DeleteService
func (c *HyperClient) DeleteService(podID string, services []*types.UserService) error { _, err := c.client.ServiceDelete( c.ctx, &types.ServiceDelRequest{PodID: podID, Services: services}, ) if err != nil { return err } return nil }
go
func (c *HyperClient) DeleteService(podID string, services []*types.UserService) error { _, err := c.client.ServiceDelete( c.ctx, &types.ServiceDelRequest{PodID: podID, Services: services}, ) if err != nil { return err } return nil }
[ "func", "(", "c", "*", "HyperClient", ")", "DeleteService", "(", "podID", "string", ",", "services", "[", "]", "*", "types", ".", "UserService", ")", "error", "{", "_", ",", "err", ":=", "c", ".", "client", ".", "ServiceDelete", "(", "c", ".", "ctx",...
// DeleteService deletes user service by podID and service content
[ "DeleteService", "deletes", "user", "service", "by", "podID", "and", "service", "content" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/integration/client.go#L620-L630
train
hyperhq/hyperd
integration/client.go
ListService
func (c *HyperClient) ListService(podID string) ([]*types.UserService, error) { resp, err := c.client.ServiceList( c.ctx, &types.ServiceListRequest{PodID: podID}, ) if err != nil { return nil, err } return resp.Services, nil }
go
func (c *HyperClient) ListService(podID string) ([]*types.UserService, error) { resp, err := c.client.ServiceList( c.ctx, &types.ServiceListRequest{PodID: podID}, ) if err != nil { return nil, err } return resp.Services, nil }
[ "func", "(", "c", "*", "HyperClient", ")", "ListService", "(", "podID", "string", ")", "(", "[", "]", "*", "types", ".", "UserService", ",", "error", ")", "{", "resp", ",", "err", ":=", "c", ".", "client", ".", "ServiceList", "(", "c", ".", "ctx", ...
// ListService lists user services by podID
[ "ListService", "lists", "user", "services", "by", "podID" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/integration/client.go#L633-L644
train
hyperhq/hyperd
integration/client.go
GetPodStats
func (c *HyperClient) GetPodStats(podID string) (*types.PodStats, error) { statsResponse, err := c.client.PodStats( c.ctx, &types.PodStatsRequest{PodID: podID}, ) if err != nil { return nil, err } return statsResponse.PodStats, nil }
go
func (c *HyperClient) GetPodStats(podID string) (*types.PodStats, error) { statsResponse, err := c.client.PodStats( c.ctx, &types.PodStatsRequest{PodID: podID}, ) if err != nil { return nil, err } return statsResponse.PodStats, nil }
[ "func", "(", "c", "*", "HyperClient", ")", "GetPodStats", "(", "podID", "string", ")", "(", "*", "types", ".", "PodStats", ",", "error", ")", "{", "statsResponse", ",", "err", ":=", "c", ".", "client", ".", "PodStats", "(", "c", ".", "ctx", ",", "&...
// GetPodStats get stats of Pod by podID
[ "GetPodStats", "get", "stats", "of", "Pod", "by", "podID" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/integration/client.go#L647-L658
train
hyperhq/hyperd
integration/client.go
AddService
func (c *HyperClient) AddService(podID string, services []*types.UserService) error { _, err := c.client.ServiceAdd( c.ctx, &types.ServiceAddRequest{PodID: podID, Services: services}, ) if err != nil { return err } return nil }
go
func (c *HyperClient) AddService(podID string, services []*types.UserService) error { _, err := c.client.ServiceAdd( c.ctx, &types.ServiceAddRequest{PodID: podID, Services: services}, ) if err != nil { return err } return nil }
[ "func", "(", "c", "*", "HyperClient", ")", "AddService", "(", "podID", "string", ",", "services", "[", "]", "*", "types", ".", "UserService", ")", "error", "{", "_", ",", "err", ":=", "c", ".", "client", ".", "ServiceAdd", "(", "c", ".", "ctx", ","...
// AddService adds user service by podID and service content
[ "AddService", "adds", "user", "service", "by", "podID", "and", "service", "content" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/integration/client.go#L661-L672
train
hyperhq/hyperd
integration/client.go
UpdateService
func (c *HyperClient) UpdateService(podID string, services []*types.UserService) error { _, err := c.client.ServiceUpdate( c.ctx, &types.ServiceUpdateRequest{PodID: podID, Services: services}, ) if err != nil { return err } return nil }
go
func (c *HyperClient) UpdateService(podID string, services []*types.UserService) error { _, err := c.client.ServiceUpdate( c.ctx, &types.ServiceUpdateRequest{PodID: podID, Services: services}, ) if err != nil { return err } return nil }
[ "func", "(", "c", "*", "HyperClient", ")", "UpdateService", "(", "podID", "string", ",", "services", "[", "]", "*", "types", ".", "UserService", ")", "error", "{", "_", ",", "err", ":=", "c", ".", "client", ".", "ServiceUpdate", "(", "c", ".", "ctx",...
// UpdateService updates user service by podID and service content
[ "UpdateService", "updates", "user", "service", "by", "podID", "and", "service", "content" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/integration/client.go#L675-L685
train
hyperhq/hyperd
integration/client.go
SetPodLabels
func (c *HyperClient) SetPodLabels(podID string, override bool, labels map[string]string) error { _, err := c.client.SetPodLabels( c.ctx, &types.PodLabelsRequest{PodID: podID, Override: override, Labels: labels}, ) if err != nil { return err } return nil }
go
func (c *HyperClient) SetPodLabels(podID string, override bool, labels map[string]string) error { _, err := c.client.SetPodLabels( c.ctx, &types.PodLabelsRequest{PodID: podID, Override: override, Labels: labels}, ) if err != nil { return err } return nil }
[ "func", "(", "c", "*", "HyperClient", ")", "SetPodLabels", "(", "podID", "string", ",", "override", "bool", ",", "labels", "map", "[", "string", "]", "string", ")", "error", "{", "_", ",", "err", ":=", "c", ".", "client", ".", "SetPodLabels", "(", "c...
// SetPodLabels sets labels to Pod by podID
[ "SetPodLabels", "sets", "labels", "to", "Pod", "by", "podID" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/integration/client.go#L688-L699
train
hyperhq/hyperd
integration/client.go
Info
func (c *HyperClient) Info() (*types.InfoResponse, error) { info, err := c.client.Info( c.ctx, &types.InfoRequest{}, ) if err != nil { return nil, err } return info, nil }
go
func (c *HyperClient) Info() (*types.InfoResponse, error) { info, err := c.client.Info( c.ctx, &types.InfoRequest{}, ) if err != nil { return nil, err } return info, nil }
[ "func", "(", "c", "*", "HyperClient", ")", "Info", "(", ")", "(", "*", "types", ".", "InfoResponse", ",", "error", ")", "{", "info", ",", "err", ":=", "c", ".", "client", ".", "Info", "(", "c", ".", "ctx", ",", "&", "types", ".", "InfoRequest", ...
// Info gets system info of hyperd
[ "Info", "gets", "system", "info", "of", "hyperd" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/integration/client.go#L702-L713
train
hyperhq/hyperd
integration/client.go
ContainerSignal
func (c *HyperClient) ContainerSignal(podID, containerID string, signal int64) error { _, err := c.client.ContainerSignal(c.ctx, &types.ContainerSignalRequest{ PodID: podID, ContainerID: containerID, Signal: signal, }) return err }
go
func (c *HyperClient) ContainerSignal(podID, containerID string, signal int64) error { _, err := c.client.ContainerSignal(c.ctx, &types.ContainerSignalRequest{ PodID: podID, ContainerID: containerID, Signal: signal, }) return err }
[ "func", "(", "c", "*", "HyperClient", ")", "ContainerSignal", "(", "podID", ",", "containerID", "string", ",", "signal", "int64", ")", "error", "{", "_", ",", "err", ":=", "c", ".", "client", ".", "ContainerSignal", "(", "c", ".", "ctx", ",", "&", "t...
// ContainerSignal sends a signal to specified container of specified pod
[ "ContainerSignal", "sends", "a", "signal", "to", "specified", "container", "of", "specified", "pod" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/integration/client.go#L730-L738
train
hyperhq/hyperd
daemon/pod/decommission.go
cleanup
func (p *XPod) cleanup() { //if removing, the remove will get the resourceLock in advance, and it will set // the pod status to NONE when it complete. // Therefore, if get into cleanup() after remove, cleanup should exit when it // got a p.resourceLock.Lock() defer p.resourceLock.Unlock() p.statusLock.Lock() if p.status == S_POD_STOPPED { p.statusLock.Unlock() return } else if p.status != S_POD_NONE { p.status = S_POD_STOPPING } p.statusLock.Unlock() err := p.decommissionResources() if err != nil { // even if error, we set the vm to be stopped p.Log(ERROR, "pod stopping failed, failed to decommit the resources: %v", err) err = nil } err = p.removeSandboxFromDB() if err != nil { p.Log(ERROR, "pod stopping failed, failed to remove sandbox persist data: %v", err) err = nil } p.Log(DEBUG, "tag pod as stopped") p.statusLock.Lock() if p.status != S_POD_NONE { p.status = S_POD_STOPPED } p.statusLock.Unlock() p.Log(INFO, "pod stopped") select { case p.stoppedChan <- true: default: } }
go
func (p *XPod) cleanup() { //if removing, the remove will get the resourceLock in advance, and it will set // the pod status to NONE when it complete. // Therefore, if get into cleanup() after remove, cleanup should exit when it // got a p.resourceLock.Lock() defer p.resourceLock.Unlock() p.statusLock.Lock() if p.status == S_POD_STOPPED { p.statusLock.Unlock() return } else if p.status != S_POD_NONE { p.status = S_POD_STOPPING } p.statusLock.Unlock() err := p.decommissionResources() if err != nil { // even if error, we set the vm to be stopped p.Log(ERROR, "pod stopping failed, failed to decommit the resources: %v", err) err = nil } err = p.removeSandboxFromDB() if err != nil { p.Log(ERROR, "pod stopping failed, failed to remove sandbox persist data: %v", err) err = nil } p.Log(DEBUG, "tag pod as stopped") p.statusLock.Lock() if p.status != S_POD_NONE { p.status = S_POD_STOPPED } p.statusLock.Unlock() p.Log(INFO, "pod stopped") select { case p.stoppedChan <- true: default: } }
[ "func", "(", "p", "*", "XPod", ")", "cleanup", "(", ")", "{", "//if removing, the remove will get the resourceLock in advance, and it will set", "// the pod status to NONE when it complete.", "// Therefore, if get into cleanup() after remove, cleanup should exit when it", "// got a", "p"...
//cleanup is used to cleanup the resource after VM shutdown. This method should only called by waitVMStop
[ "cleanup", "is", "used", "to", "cleanup", "the", "resource", "after", "VM", "shutdown", ".", "This", "method", "should", "only", "called", "by", "waitVMStop" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/daemon/pod/decommission.go#L542-L584
train
hyperhq/hyperd
client/client.go
Cmd
func (cli *HyperClient) Cmd(args ...string) error { if len(args) > 1 { method, exists := cli.getMethod(args[:2]...) if exists { return method(args[2:]...) } } if len(args) > 0 { method, exists := cli.getMethod(args[0]) if !exists { fmt.Printf("%s: '%s' is not a %s command. See '%s --help'.\n", os.Args[0], args[0], os.Args[0], os.Args[0]) os.Exit(1) } return method(args[1:]...) } return cli.HyperCmdHelp() }
go
func (cli *HyperClient) Cmd(args ...string) error { if len(args) > 1 { method, exists := cli.getMethod(args[:2]...) if exists { return method(args[2:]...) } } if len(args) > 0 { method, exists := cli.getMethod(args[0]) if !exists { fmt.Printf("%s: '%s' is not a %s command. See '%s --help'.\n", os.Args[0], args[0], os.Args[0], os.Args[0]) os.Exit(1) } return method(args[1:]...) } return cli.HyperCmdHelp() }
[ "func", "(", "cli", "*", "HyperClient", ")", "Cmd", "(", "args", "...", "string", ")", "error", "{", "if", "len", "(", "args", ")", ">", "1", "{", "method", ",", "exists", ":=", "cli", ".", "getMethod", "(", "args", "[", ":", "2", "]", "...", "...
// Cmd executes the specified command.
[ "Cmd", "executes", "the", "specified", "command", "." ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/client/client.go#L86-L102
train
hyperhq/hyperd
utils/utils.go
FormatMountLabel
func FormatMountLabel(src, mountLabel string) string { if mountLabel != "" { switch src { case "": src = fmt.Sprintf("context=%q", mountLabel) default: src = fmt.Sprintf("%s,context=%q", src, mountLabel) } } return src }
go
func FormatMountLabel(src, mountLabel string) string { if mountLabel != "" { switch src { case "": src = fmt.Sprintf("context=%q", mountLabel) default: src = fmt.Sprintf("%s,context=%q", src, mountLabel) } } return src }
[ "func", "FormatMountLabel", "(", "src", ",", "mountLabel", "string", ")", "string", "{", "if", "mountLabel", "!=", "\"", "\"", "{", "switch", "src", "{", "case", "\"", "\"", ":", "src", "=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "mountLabel", ...
// FormatMountLabel returns a string to be used by the mount command. // The format of this string will be used to alter the labeling of the mountpoint. // The string returned is suitable to be used as the options field of the mount command. // If you need to have additional mount point options, you can pass them in as // the first parameter. Second parameter is the label that you wish to apply // to all content in the mount point.
[ "FormatMountLabel", "returns", "a", "string", "to", "be", "used", "by", "the", "mount", "command", ".", "The", "format", "of", "this", "string", "will", "be", "used", "to", "alter", "the", "labeling", "of", "the", "mountpoint", ".", "The", "string", "retur...
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/utils/utils.go#L72-L82
train
hyperhq/hyperd
serverrpc/info.go
PodInfo
func (s *ServerRPC) PodInfo(c context.Context, req *types.PodInfoRequest) (*types.PodInfoResponse, error) { info, err := s.daemon.GetPodInfo(req.PodID) if err != nil { return nil, err } return &types.PodInfoResponse{ PodInfo: info, }, nil }
go
func (s *ServerRPC) PodInfo(c context.Context, req *types.PodInfoRequest) (*types.PodInfoResponse, error) { info, err := s.daemon.GetPodInfo(req.PodID) if err != nil { return nil, err } return &types.PodInfoResponse{ PodInfo: info, }, nil }
[ "func", "(", "s", "*", "ServerRPC", ")", "PodInfo", "(", "c", "context", ".", "Context", ",", "req", "*", "types", ".", "PodInfoRequest", ")", "(", "*", "types", ".", "PodInfoResponse", ",", "error", ")", "{", "info", ",", "err", ":=", "s", ".", "d...
// PodInfo gets PodInfo by podID
[ "PodInfo", "gets", "PodInfo", "by", "podID" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/serverrpc/info.go#L14-L23
train
hyperhq/hyperd
serverrpc/info.go
ContainerInfo
func (s *ServerRPC) ContainerInfo(c context.Context, req *types.ContainerInfoRequest) (*types.ContainerInfoResponse, error) { info, err := s.daemon.GetContainerInfo(req.Container) if err != nil { return nil, err } return &types.ContainerInfoResponse{ ContainerInfo: info, }, nil }
go
func (s *ServerRPC) ContainerInfo(c context.Context, req *types.ContainerInfoRequest) (*types.ContainerInfoResponse, error) { info, err := s.daemon.GetContainerInfo(req.Container) if err != nil { return nil, err } return &types.ContainerInfoResponse{ ContainerInfo: info, }, nil }
[ "func", "(", "s", "*", "ServerRPC", ")", "ContainerInfo", "(", "c", "context", ".", "Context", ",", "req", "*", "types", ".", "ContainerInfoRequest", ")", "(", "*", "types", ".", "ContainerInfoResponse", ",", "error", ")", "{", "info", ",", "err", ":=", ...
// ContainerInfo gets ContainerInfo by ID or name of container
[ "ContainerInfo", "gets", "ContainerInfo", "by", "ID", "or", "name", "of", "container" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/serverrpc/info.go#L26-L35
train
hyperhq/hyperd
serverrpc/info.go
Info
func (s *ServerRPC) Info(c context.Context, req *types.InfoRequest) (*types.InfoResponse, error) { info, err := s.daemon.CmdSystemInfo() if err != nil { return nil, err } return info, nil }
go
func (s *ServerRPC) Info(c context.Context, req *types.InfoRequest) (*types.InfoResponse, error) { info, err := s.daemon.CmdSystemInfo() if err != nil { return nil, err } return info, nil }
[ "func", "(", "s", "*", "ServerRPC", ")", "Info", "(", "c", "context", ".", "Context", ",", "req", "*", "types", ".", "InfoRequest", ")", "(", "*", "types", ".", "InfoResponse", ",", "error", ")", "{", "info", ",", "err", ":=", "s", ".", "daemon", ...
// Info gets CmdSystemInfo
[ "Info", "gets", "CmdSystemInfo" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/serverrpc/info.go#L38-L45
train
hyperhq/hyperd
serverrpc/info.go
Version
func (s *ServerRPC) Version(c context.Context, req *types.VersionRequest) (*types.VersionResponse, error) { return &types.VersionResponse{ Version: utils.VERSION, ApiVersion: GRPC_API_VERSION, }, nil }
go
func (s *ServerRPC) Version(c context.Context, req *types.VersionRequest) (*types.VersionResponse, error) { return &types.VersionResponse{ Version: utils.VERSION, ApiVersion: GRPC_API_VERSION, }, nil }
[ "func", "(", "s", "*", "ServerRPC", ")", "Version", "(", "c", "context", ".", "Context", ",", "req", "*", "types", ".", "VersionRequest", ")", "(", "*", "types", ".", "VersionResponse", ",", "error", ")", "{", "return", "&", "types", ".", "VersionRespo...
// Version gets the version and apiVersion of hyperd
[ "Version", "gets", "the", "version", "and", "apiVersion", "of", "hyperd" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/serverrpc/info.go#L48-L53
train
hyperhq/hyperd
serverrpc/container.go
ContainerCreate
func (s *ServerRPC) ContainerCreate(ctx context.Context, req *types.ContainerCreateRequest) (*types.ContainerCreateResponse, error) { containerID, err := s.daemon.CreateContainerInPod(req.PodID, req.ContainerSpec) if err != nil { return nil, err } return &types.ContainerCreateResponse{ ContainerID: containerID, }, nil }
go
func (s *ServerRPC) ContainerCreate(ctx context.Context, req *types.ContainerCreateRequest) (*types.ContainerCreateResponse, error) { containerID, err := s.daemon.CreateContainerInPod(req.PodID, req.ContainerSpec) if err != nil { return nil, err } return &types.ContainerCreateResponse{ ContainerID: containerID, }, nil }
[ "func", "(", "s", "*", "ServerRPC", ")", "ContainerCreate", "(", "ctx", "context", ".", "Context", ",", "req", "*", "types", ".", "ContainerCreateRequest", ")", "(", "*", "types", ".", "ContainerCreateResponse", ",", "error", ")", "{", "containerID", ",", ...
// ContainerCreate creates a container by UserContainer spec
[ "ContainerCreate", "creates", "a", "container", "by", "UserContainer", "spec" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/serverrpc/container.go#L9-L18
train
hyperhq/hyperd
serverrpc/container.go
ContainerRename
func (s *ServerRPC) ContainerRename(c context.Context, req *types.ContainerRenameRequest) (*types.ContainerRenameResponse, error) { err := s.daemon.ContainerRename(req.OldContainerName, req.NewContainerName) if err != nil { return nil, err } return &types.ContainerRenameResponse{}, nil }
go
func (s *ServerRPC) ContainerRename(c context.Context, req *types.ContainerRenameRequest) (*types.ContainerRenameResponse, error) { err := s.daemon.ContainerRename(req.OldContainerName, req.NewContainerName) if err != nil { return nil, err } return &types.ContainerRenameResponse{}, nil }
[ "func", "(", "s", "*", "ServerRPC", ")", "ContainerRename", "(", "c", "context", ".", "Context", ",", "req", "*", "types", ".", "ContainerRenameRequest", ")", "(", "*", "types", ".", "ContainerRenameResponse", ",", "error", ")", "{", "err", ":=", "s", "....
// ContainerRename rename a container
[ "ContainerRename", "rename", "a", "container" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/serverrpc/container.go#L40-L47
train
hyperhq/hyperd
serverrpc/container.go
ContainerSignal
func (s *ServerRPC) ContainerSignal(ctx context.Context, req *types.ContainerSignalRequest) (*types.ContainerSignalResponse, error) { err := s.daemon.KillPodContainers(req.PodID, req.ContainerID, req.Signal) if err != nil { return nil, err } return &types.ContainerSignalResponse{}, nil }
go
func (s *ServerRPC) ContainerSignal(ctx context.Context, req *types.ContainerSignalRequest) (*types.ContainerSignalResponse, error) { err := s.daemon.KillPodContainers(req.PodID, req.ContainerID, req.Signal) if err != nil { return nil, err } return &types.ContainerSignalResponse{}, nil }
[ "func", "(", "s", "*", "ServerRPC", ")", "ContainerSignal", "(", "ctx", "context", ".", "Context", ",", "req", "*", "types", ".", "ContainerSignalRequest", ")", "(", "*", "types", ".", "ContainerSignalResponse", ",", "error", ")", "{", "err", ":=", "s", ...
// ContainerSignal sends a singal to specified container of specified pod
[ "ContainerSignal", "sends", "a", "singal", "to", "specified", "container", "of", "specified", "pod" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/serverrpc/container.go#L59-L66
train
hyperhq/hyperd
daemon/daemonbuilder/builder.go
Pull
func (d Docker) Pull(name string) (builder.Image, error) { ref, err := reference.ParseNamed(name) if err != nil { return nil, err } ref = reference.WithDefaultTag(ref) pullRegistryAuth := &types.AuthConfig{} if len(d.AuthConfigs) > 0 { // The request came with a full auth config file, we prefer to use that repoInfo, err := d.Daemon.RegistryService.ResolveRepository(ref) if err != nil { return nil, err } resolvedConfig := registry.ResolveAuthConfig( d.AuthConfigs, repoInfo.Index, ) pullRegistryAuth = &resolvedConfig } if err := d.Daemon.PullImage(ref, nil, pullRegistryAuth, ioutils.NopWriteCloser(d.OutOld)); err != nil { return nil, err } return d.GetImage(name) }
go
func (d Docker) Pull(name string) (builder.Image, error) { ref, err := reference.ParseNamed(name) if err != nil { return nil, err } ref = reference.WithDefaultTag(ref) pullRegistryAuth := &types.AuthConfig{} if len(d.AuthConfigs) > 0 { // The request came with a full auth config file, we prefer to use that repoInfo, err := d.Daemon.RegistryService.ResolveRepository(ref) if err != nil { return nil, err } resolvedConfig := registry.ResolveAuthConfig( d.AuthConfigs, repoInfo.Index, ) pullRegistryAuth = &resolvedConfig } if err := d.Daemon.PullImage(ref, nil, pullRegistryAuth, ioutils.NopWriteCloser(d.OutOld)); err != nil { return nil, err } return d.GetImage(name) }
[ "func", "(", "d", "Docker", ")", "Pull", "(", "name", "string", ")", "(", "builder", ".", "Image", ",", "error", ")", "{", "ref", ",", "err", ":=", "reference", ".", "ParseNamed", "(", "name", ")", "\n", "if", "err", "!=", "nil", "{", "return", "...
// Pull tells Docker to pull image referenced by `name`.
[ "Pull", "tells", "Docker", "to", "pull", "image", "referenced", "by", "name", "." ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/daemon/daemonbuilder/builder.go#L49-L75
train
hyperhq/hyperd
daemon/daemonbuilder/builder.go
GetImage
func (d Docker) GetImage(name string) (builder.Image, error) { img, err := d.Daemon.GetImage(name) if err != nil { return nil, err } return imgWrap{img}, nil }
go
func (d Docker) GetImage(name string) (builder.Image, error) { img, err := d.Daemon.GetImage(name) if err != nil { return nil, err } return imgWrap{img}, nil }
[ "func", "(", "d", "Docker", ")", "GetImage", "(", "name", "string", ")", "(", "builder", ".", "Image", ",", "error", ")", "{", "img", ",", "err", ":=", "d", ".", "Daemon", ".", "GetImage", "(", "name", ")", "\n", "if", "err", "!=", "nil", "{", ...
// GetImage looks up a Docker image referenced by `name`.
[ "GetImage", "looks", "up", "a", "Docker", "image", "referenced", "by", "name", "." ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/daemon/daemonbuilder/builder.go#L78-L84
train
hyperhq/hyperd
daemon/daemonbuilder/builder.go
ContainerUpdateCmd
func (d Docker) ContainerUpdateCmd(cID string, cmd []string) error { c, err := d.Daemon.GetContainer(cID) if err != nil { return err } c.Path = cmd[0] c.Args = cmd[1:] return nil }
go
func (d Docker) ContainerUpdateCmd(cID string, cmd []string) error { c, err := d.Daemon.GetContainer(cID) if err != nil { return err } c.Path = cmd[0] c.Args = cmd[1:] return nil }
[ "func", "(", "d", "Docker", ")", "ContainerUpdateCmd", "(", "cID", "string", ",", "cmd", "[", "]", "string", ")", "error", "{", "c", ",", "err", ":=", "d", ".", "Daemon", ".", "GetContainer", "(", "cID", ")", "\n", "if", "err", "!=", "nil", "{", ...
// ContainerUpdateCmd updates Path and Args for the container with ID cID.
[ "ContainerUpdateCmd", "updates", "Path", "and", "Args", "for", "the", "container", "with", "ID", "cID", "." ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/daemon/daemonbuilder/builder.go#L87-L95
train
hyperhq/hyperd
daemon/daemonbuilder/builder.go
GetCachedImage
func (d Docker) GetCachedImage(imgID string, cfg *container.Config) (string, error) { cache, err := d.Daemon.ImageGetCached(image.ID(imgID), cfg) if cache == nil || err != nil { return "", err } return cache.ID().String(), nil }
go
func (d Docker) GetCachedImage(imgID string, cfg *container.Config) (string, error) { cache, err := d.Daemon.ImageGetCached(image.ID(imgID), cfg) if cache == nil || err != nil { return "", err } return cache.ID().String(), nil }
[ "func", "(", "d", "Docker", ")", "GetCachedImage", "(", "imgID", "string", ",", "cfg", "*", "container", ".", "Config", ")", "(", "string", ",", "error", ")", "{", "cache", ",", "err", ":=", "d", ".", "Daemon", ".", "ImageGetCached", "(", "image", "....
// GetCachedImage returns a reference to a cached image whose parent equals `parent` // and runconfig equals `cfg`. A cache miss is expected to return an empty ID and a nil error.
[ "GetCachedImage", "returns", "a", "reference", "to", "a", "cached", "image", "whose", "parent", "equals", "parent", "and", "runconfig", "equals", "cfg", ".", "A", "cache", "miss", "is", "expected", "to", "return", "an", "empty", "ID", "and", "a", "nil", "e...
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/daemon/daemonbuilder/builder.go#L99-L105
train
hyperhq/hyperd
daemon/pod/migration.go
MigrateLagecyPersistentData
func MigrateLagecyPersistentData(db *daemondb.DaemonDB, podFactory func() *PodFactory) (err error) { num := 0 count := 0 defer func() { logInfo := fmt.Sprintf("Migrate lagecy persistent pod data, found: %d, migrated: %d", num, count) if err == nil { hlog.Log(INFO, logInfo) } else { hlog.Log(ERROR, "%s, but failed with %v", logInfo, err) } }() list, err := db.LagecyListPod() if err != nil { return err } num = len(list) if num == 0 { return nil } ch := db.LagecyGetAllPods() if ch == nil { err = fmt.Errorf("cannot list pods in daemondb") return err } for { item, ok := <-ch if !ok { break } if item == nil { err = fmt.Errorf("error during get pods from daemondb") return err } podID := string(item.K[4:]) hlog.Log(TRACE, "try to migrate lagecy pod %s from daemondb", podID) var podSpec apitypes.UserPod if err = json.Unmarshal(item.V, &podSpec); err != nil { return err } factory := podFactory() // fill in corresponding container id in pod spec if err = setupContanerID(factory, podID, &podSpec); err != nil { return err } // convert some lagecy volume field to current format if err = setupVolumes(factory.db, podID, item.V, &podSpec); err != nil { return err } if err = persistLagecyPod(factory, &podSpec); err != nil { return err } var vmID string if vmID, err = db.LagecyGetP2V(podID); err != nil { hlog.Log(DEBUG, "no existing VM for pod %s: %v", podID, err) } else { var vmData []byte if vmData, err = db.LagecyGetVM(vmID); err != nil { return err } // save sandbox data in current layout sandboxInfo := types.SandboxPersistInfo{ Id: vmID, PersistInfo: vmData, } err = saveMessage(db, fmt.Sprintf(SB_KEY_FMT, podSpec.Id), &sandboxInfo, nil, "sandbox info") if err != nil { return err } } errs := purgeLagecyPersistPod(db, podID) if len(errs) != 0 { hlog.Log(DEBUG, "%v", errs) } count++ } return nil }
go
func MigrateLagecyPersistentData(db *daemondb.DaemonDB, podFactory func() *PodFactory) (err error) { num := 0 count := 0 defer func() { logInfo := fmt.Sprintf("Migrate lagecy persistent pod data, found: %d, migrated: %d", num, count) if err == nil { hlog.Log(INFO, logInfo) } else { hlog.Log(ERROR, "%s, but failed with %v", logInfo, err) } }() list, err := db.LagecyListPod() if err != nil { return err } num = len(list) if num == 0 { return nil } ch := db.LagecyGetAllPods() if ch == nil { err = fmt.Errorf("cannot list pods in daemondb") return err } for { item, ok := <-ch if !ok { break } if item == nil { err = fmt.Errorf("error during get pods from daemondb") return err } podID := string(item.K[4:]) hlog.Log(TRACE, "try to migrate lagecy pod %s from daemondb", podID) var podSpec apitypes.UserPod if err = json.Unmarshal(item.V, &podSpec); err != nil { return err } factory := podFactory() // fill in corresponding container id in pod spec if err = setupContanerID(factory, podID, &podSpec); err != nil { return err } // convert some lagecy volume field to current format if err = setupVolumes(factory.db, podID, item.V, &podSpec); err != nil { return err } if err = persistLagecyPod(factory, &podSpec); err != nil { return err } var vmID string if vmID, err = db.LagecyGetP2V(podID); err != nil { hlog.Log(DEBUG, "no existing VM for pod %s: %v", podID, err) } else { var vmData []byte if vmData, err = db.LagecyGetVM(vmID); err != nil { return err } // save sandbox data in current layout sandboxInfo := types.SandboxPersistInfo{ Id: vmID, PersistInfo: vmData, } err = saveMessage(db, fmt.Sprintf(SB_KEY_FMT, podSpec.Id), &sandboxInfo, nil, "sandbox info") if err != nil { return err } } errs := purgeLagecyPersistPod(db, podID) if len(errs) != 0 { hlog.Log(DEBUG, "%v", errs) } count++ } return nil }
[ "func", "MigrateLagecyPersistentData", "(", "db", "*", "daemondb", ".", "DaemonDB", ",", "podFactory", "func", "(", ")", "*", "PodFactory", ")", "(", "err", "error", ")", "{", "num", ":=", "0", "\n", "count", ":=", "0", "\n", "defer", "func", "(", ")",...
// MigrateLagecyData migrate lagecy persistence data to current layout.
[ "MigrateLagecyData", "migrate", "lagecy", "persistence", "data", "to", "current", "layout", "." ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/daemon/pod/migration.go#L17-L101
train
hyperhq/hyperd
serverrpc/portmapping.go
PortMappingList
func (s *ServerRPC) PortMappingList(ctx context.Context, req *types.PortMappingListRequest) (*types.PortMappingListResponse, error) { p, ok := s.daemon.PodList.Get(req.PodID) if !ok { return nil, fmt.Errorf("Pod not found") } return &types.PortMappingListResponse{ PortMappings: p.ListPortMappings(), }, nil }
go
func (s *ServerRPC) PortMappingList(ctx context.Context, req *types.PortMappingListRequest) (*types.PortMappingListResponse, error) { p, ok := s.daemon.PodList.Get(req.PodID) if !ok { return nil, fmt.Errorf("Pod not found") } return &types.PortMappingListResponse{ PortMappings: p.ListPortMappings(), }, nil }
[ "func", "(", "s", "*", "ServerRPC", ")", "PortMappingList", "(", "ctx", "context", ".", "Context", ",", "req", "*", "types", ".", "PortMappingListRequest", ")", "(", "*", "types", ".", "PortMappingListResponse", ",", "error", ")", "{", "p", ",", "ok", ":...
// PortMappingList get a list of PortMappings
[ "PortMappingList", "get", "a", "list", "of", "PortMappings" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/serverrpc/portmapping.go#L10-L19
train
hyperhq/hyperd
serverrpc/portmapping.go
PortMappingDel
func (s *ServerRPC) PortMappingDel(ctx context.Context, req *types.PortMappingModifyRequest) (*types.PortMappingModifyResponse, error) { p, ok := s.daemon.PodList.Get(req.PodID) if !ok { return nil, fmt.Errorf("Pod not found") } err := p.RemovePortMappingByDest(req.PortMappings) if err != nil { return nil, fmt.Errorf("p.RemovePortMappingByDest error: %v", err) } return &types.PortMappingModifyResponse{}, nil }
go
func (s *ServerRPC) PortMappingDel(ctx context.Context, req *types.PortMappingModifyRequest) (*types.PortMappingModifyResponse, error) { p, ok := s.daemon.PodList.Get(req.PodID) if !ok { return nil, fmt.Errorf("Pod not found") } err := p.RemovePortMappingByDest(req.PortMappings) if err != nil { return nil, fmt.Errorf("p.RemovePortMappingByDest error: %v", err) } return &types.PortMappingModifyResponse{}, nil }
[ "func", "(", "s", "*", "ServerRPC", ")", "PortMappingDel", "(", "ctx", "context", ".", "Context", ",", "req", "*", "types", ".", "PortMappingModifyRequest", ")", "(", "*", "types", ".", "PortMappingModifyResponse", ",", "error", ")", "{", "p", ",", "ok", ...
// PortMappingDel remove a list of PortMapping rules from a Pod
[ "PortMappingDel", "remove", "a", "list", "of", "PortMapping", "rules", "from", "a", "Pod" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/serverrpc/portmapping.go#L37-L49
train
hyperhq/hyperd
server/middleware.go
debugRequestMiddleware
func debugRequestMiddleware(handler httputils.APIFunc) httputils.APIFunc { return func(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { glog.V(3).Infof("%s %s", r.Method, r.RequestURI) if r.Method != "POST" { return handler(ctx, w, r, vars) } if err := httputils.CheckForJSON(r); err != nil { return handler(ctx, w, r, vars) } maxBodySize := 4096 // 4KB if r.ContentLength > int64(maxBodySize) { return handler(ctx, w, r, vars) } body := r.Body bufReader := bufio.NewReaderSize(body, maxBodySize) r.Body = ioutils.NewReadCloserWrapper(bufReader, func() error { return body.Close() }) b, err := bufReader.Peek(maxBodySize) if err != io.EOF { // either there was an error reading, or the buffer is full (in which case the request is too large) return handler(ctx, w, r, vars) } var postForm map[string]interface{} if err := json.Unmarshal(b, &postForm); err == nil { if _, exists := postForm["password"]; exists { postForm["password"] = "*****" } formStr, errMarshal := json.Marshal(postForm) if errMarshal == nil { glog.V(3).Infof("form data: %s", string(formStr)) } else { glog.V(3).Infof("form data: %q", postForm) } } return handler(ctx, w, r, vars) } }
go
func debugRequestMiddleware(handler httputils.APIFunc) httputils.APIFunc { return func(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { glog.V(3).Infof("%s %s", r.Method, r.RequestURI) if r.Method != "POST" { return handler(ctx, w, r, vars) } if err := httputils.CheckForJSON(r); err != nil { return handler(ctx, w, r, vars) } maxBodySize := 4096 // 4KB if r.ContentLength > int64(maxBodySize) { return handler(ctx, w, r, vars) } body := r.Body bufReader := bufio.NewReaderSize(body, maxBodySize) r.Body = ioutils.NewReadCloserWrapper(bufReader, func() error { return body.Close() }) b, err := bufReader.Peek(maxBodySize) if err != io.EOF { // either there was an error reading, or the buffer is full (in which case the request is too large) return handler(ctx, w, r, vars) } var postForm map[string]interface{} if err := json.Unmarshal(b, &postForm); err == nil { if _, exists := postForm["password"]; exists { postForm["password"] = "*****" } formStr, errMarshal := json.Marshal(postForm) if errMarshal == nil { glog.V(3).Infof("form data: %s", string(formStr)) } else { glog.V(3).Infof("form data: %q", postForm) } } return handler(ctx, w, r, vars) } }
[ "func", "debugRequestMiddleware", "(", "handler", "httputils", ".", "APIFunc", ")", "httputils", ".", "APIFunc", "{", "return", "func", "(", "ctx", "context", ".", "Context", ",", "w", "http", ".", "ResponseWriter", ",", "r", "*", "http", ".", "Request", "...
// debugRequestMiddleware dumps the request to logger
[ "debugRequestMiddleware", "dumps", "the", "request", "to", "logger" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/server/middleware.go#L27-L67
train
hyperhq/hyperd
server/middleware.go
authorizationMiddleware
func (s *Server) authorizationMiddleware(handler httputils.APIFunc) httputils.APIFunc { return func(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { // FIXME: fill when authN gets in // User and UserAuthNMethod are taken from AuthN plugins // Currently tracked in https://github.com/docker/docker/pull/13994 user := "" userAuthNMethod := "" authCtx := authorization.NewCtx(s.authZPlugins, user, userAuthNMethod, r.Method, r.RequestURI) if err := authCtx.AuthZRequest(w, r); err != nil { glog.Errorf("AuthZRequest for %s %s returned error: %s", r.Method, r.RequestURI, err) return err } rw := authorization.NewResponseModifier(w) if err := handler(ctx, rw, r, vars); err != nil { glog.Errorf("Handler for %s %s returned error: %s", r.Method, r.RequestURI, err) return err } if err := authCtx.AuthZResponse(rw, r); err != nil { glog.Errorf("AuthZResponse for %s %s returned error: %s", r.Method, r.RequestURI, err) return err } return nil } }
go
func (s *Server) authorizationMiddleware(handler httputils.APIFunc) httputils.APIFunc { return func(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { // FIXME: fill when authN gets in // User and UserAuthNMethod are taken from AuthN plugins // Currently tracked in https://github.com/docker/docker/pull/13994 user := "" userAuthNMethod := "" authCtx := authorization.NewCtx(s.authZPlugins, user, userAuthNMethod, r.Method, r.RequestURI) if err := authCtx.AuthZRequest(w, r); err != nil { glog.Errorf("AuthZRequest for %s %s returned error: %s", r.Method, r.RequestURI, err) return err } rw := authorization.NewResponseModifier(w) if err := handler(ctx, rw, r, vars); err != nil { glog.Errorf("Handler for %s %s returned error: %s", r.Method, r.RequestURI, err) return err } if err := authCtx.AuthZResponse(rw, r); err != nil { glog.Errorf("AuthZResponse for %s %s returned error: %s", r.Method, r.RequestURI, err) return err } return nil } }
[ "func", "(", "s", "*", "Server", ")", "authorizationMiddleware", "(", "handler", "httputils", ".", "APIFunc", ")", "httputils", ".", "APIFunc", "{", "return", "func", "(", "ctx", "context", ".", "Context", ",", "w", "http", ".", "ResponseWriter", ",", "r",...
// authorizationMiddleware perform authorization on the request.
[ "authorizationMiddleware", "perform", "authorization", "on", "the", "request", "." ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/server/middleware.go#L70-L97
train
hyperhq/hyperd
server/middleware.go
userAgentMiddleware
func (s *Server) userAgentMiddleware(handler httputils.APIFunc) httputils.APIFunc { return func(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { if strings.Contains(r.Header.Get("User-Agent"), "Docker-Client/") { dockerVersion := version.Version(s.cfg.Version) userAgent := strings.Split(r.Header.Get("User-Agent"), "/") // v1.20 onwards includes the GOOS of the client after the version // such as Docker/1.7.0 (linux) if len(userAgent) == 2 && strings.Contains(userAgent[1], " ") { userAgent[1] = strings.Split(userAgent[1], " ")[0] } if len(userAgent) == 2 && !dockerVersion.Equal(version.Version(userAgent[1])) { glog.V(3).Infof("Warning: client and server don't have the same version (client: %s, server: %s)", userAgent[1], dockerVersion) } } return handler(ctx, w, r, vars) } }
go
func (s *Server) userAgentMiddleware(handler httputils.APIFunc) httputils.APIFunc { return func(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { if strings.Contains(r.Header.Get("User-Agent"), "Docker-Client/") { dockerVersion := version.Version(s.cfg.Version) userAgent := strings.Split(r.Header.Get("User-Agent"), "/") // v1.20 onwards includes the GOOS of the client after the version // such as Docker/1.7.0 (linux) if len(userAgent) == 2 && strings.Contains(userAgent[1], " ") { userAgent[1] = strings.Split(userAgent[1], " ")[0] } if len(userAgent) == 2 && !dockerVersion.Equal(version.Version(userAgent[1])) { glog.V(3).Infof("Warning: client and server don't have the same version (client: %s, server: %s)", userAgent[1], dockerVersion) } } return handler(ctx, w, r, vars) } }
[ "func", "(", "s", "*", "Server", ")", "userAgentMiddleware", "(", "handler", "httputils", ".", "APIFunc", ")", "httputils", ".", "APIFunc", "{", "return", "func", "(", "ctx", "context", ".", "Context", ",", "w", "http", ".", "ResponseWriter", ",", "r", "...
// userAgentMiddleware checks the User-Agent header looking for a valid docker client spec.
[ "userAgentMiddleware", "checks", "the", "User", "-", "Agent", "header", "looking", "for", "a", "valid", "docker", "client", "spec", "." ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/server/middleware.go#L100-L119
train
hyperhq/hyperd
server/middleware.go
corsMiddleware
func (s *Server) corsMiddleware(handler httputils.APIFunc) httputils.APIFunc { return func(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { // If "api-cors-header" is not given, but "api-enable-cors" is true, we set cors to "*" // otherwise, all head values will be passed to HTTP handler corsHeaders := s.cfg.CorsHeaders if corsHeaders == "" && s.cfg.EnableCors { corsHeaders = "*" } if corsHeaders != "" { writeCorsHeaders(w, r, corsHeaders) } return handler(ctx, w, r, vars) } }
go
func (s *Server) corsMiddleware(handler httputils.APIFunc) httputils.APIFunc { return func(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { // If "api-cors-header" is not given, but "api-enable-cors" is true, we set cors to "*" // otherwise, all head values will be passed to HTTP handler corsHeaders := s.cfg.CorsHeaders if corsHeaders == "" && s.cfg.EnableCors { corsHeaders = "*" } if corsHeaders != "" { writeCorsHeaders(w, r, corsHeaders) } return handler(ctx, w, r, vars) } }
[ "func", "(", "s", "*", "Server", ")", "corsMiddleware", "(", "handler", "httputils", ".", "APIFunc", ")", "httputils", ".", "APIFunc", "{", "return", "func", "(", "ctx", "context", ".", "Context", ",", "w", "http", ".", "ResponseWriter", ",", "r", "*", ...
// corsMiddleware sets the CORS header expectations in the server.
[ "corsMiddleware", "sets", "the", "CORS", "header", "expectations", "in", "the", "server", "." ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/server/middleware.go#L122-L136
train
hyperhq/hyperd
server/middleware.go
versionMiddleware
func versionMiddleware(handler httputils.APIFunc) httputils.APIFunc { return func(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { apiVersion := version.Version(vars["version"]) if apiVersion == "" { apiVersion = api.DefaultVersion } // FIXME: do not check version now /* if apiVersion.GreaterThan(api.DefaultVersion) { return errors.ErrorCodeNewerClientVersion.WithArgs(apiVersion, api.DefaultVersion) } if apiVersion.LessThan(api.MinVersion) { return errors.ErrorCodeOldClientVersion.WithArgs(apiVersion, api.DefaultVersion) } */ w.Header().Set("Server", "Docker/"+dockerversion.Version+" ("+runtime.GOOS+")") ctx = context.WithValue(ctx, httputils.APIVersionKey, apiVersion) return handler(ctx, w, r, vars) } }
go
func versionMiddleware(handler httputils.APIFunc) httputils.APIFunc { return func(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { apiVersion := version.Version(vars["version"]) if apiVersion == "" { apiVersion = api.DefaultVersion } // FIXME: do not check version now /* if apiVersion.GreaterThan(api.DefaultVersion) { return errors.ErrorCodeNewerClientVersion.WithArgs(apiVersion, api.DefaultVersion) } if apiVersion.LessThan(api.MinVersion) { return errors.ErrorCodeOldClientVersion.WithArgs(apiVersion, api.DefaultVersion) } */ w.Header().Set("Server", "Docker/"+dockerversion.Version+" ("+runtime.GOOS+")") ctx = context.WithValue(ctx, httputils.APIVersionKey, apiVersion) return handler(ctx, w, r, vars) } }
[ "func", "versionMiddleware", "(", "handler", "httputils", ".", "APIFunc", ")", "httputils", ".", "APIFunc", "{", "return", "func", "(", "ctx", "context", ".", "Context", ",", "w", "http", ".", "ResponseWriter", ",", "r", "*", "http", ".", "Request", ",", ...
// versionMiddleware checks the api version requirements before passing the request to the server handler.
[ "versionMiddleware", "checks", "the", "api", "version", "requirements", "before", "passing", "the", "request", "to", "the", "server", "handler", "." ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/server/middleware.go#L139-L158
train
hyperhq/hyperd
storage/vbox/vbox.go
MountContainerToSharedDir
func MountContainerToSharedDir(containerId, sharedDir, devPrefix string) (string, error) { devFullName := fmt.Sprintf("%s/vbox/images/%s.vdi", utils.HYPER_ROOT, containerId) return devFullName, nil }
go
func MountContainerToSharedDir(containerId, sharedDir, devPrefix string) (string, error) { devFullName := fmt.Sprintf("%s/vbox/images/%s.vdi", utils.HYPER_ROOT, containerId) return devFullName, nil }
[ "func", "MountContainerToSharedDir", "(", "containerId", ",", "sharedDir", ",", "devPrefix", "string", ")", "(", "string", ",", "error", ")", "{", "devFullName", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "utils", ".", "HYPER_ROOT", ",", "containerId...
// For device mapper, we do not need to mount the container to sharedDir. // All of we need to provide the block device name of container.
[ "For", "device", "mapper", "we", "do", "not", "need", "to", "mount", "the", "container", "to", "sharedDir", ".", "All", "of", "we", "need", "to", "provide", "the", "block", "device", "name", "of", "container", "." ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/storage/vbox/vbox.go#L11-L14
train
hyperhq/hyperd
serverrpc/images.go
ImagePull
func (s *ServerRPC) ImagePull(req *types.ImagePullRequest, stream types.PublicAPI_ImagePullServer) error { authConfig := &enginetypes.AuthConfig{} if req.Auth != nil { authConfig = &enginetypes.AuthConfig{ Username: req.Auth.Username, Password: req.Auth.Password, Auth: req.Auth.Auth, Email: req.Auth.Email, ServerAddress: req.Auth.Serveraddress, RegistryToken: req.Auth.Registrytoken, } } glog.V(3).Infof("ImagePull with ServerStream %s request %s", stream, req.String()) r, w := io.Pipe() var pullResult error var complete = false go func() { defer r.Close() for { data := make([]byte, 512) n, err := r.Read(data) if err == io.EOF { if complete { break } else { continue } } if err != nil { glog.Errorf("Read image pull stream error: %v", err) return } if err := stream.Send(&types.ImagePullResponse{Data: data[:n]}); err != nil { glog.Errorf("Send image pull progress to stream error: %v", err) return } } }() pullResult = s.daemon.CmdImagePull(req.Image, req.Tag, authConfig, nil, w) complete = true if pullResult != nil { pullResult = fmt.Errorf("s.daemon.CmdImagePull with request %s error: %v", req.String(), pullResult) } return pullResult }
go
func (s *ServerRPC) ImagePull(req *types.ImagePullRequest, stream types.PublicAPI_ImagePullServer) error { authConfig := &enginetypes.AuthConfig{} if req.Auth != nil { authConfig = &enginetypes.AuthConfig{ Username: req.Auth.Username, Password: req.Auth.Password, Auth: req.Auth.Auth, Email: req.Auth.Email, ServerAddress: req.Auth.Serveraddress, RegistryToken: req.Auth.Registrytoken, } } glog.V(3).Infof("ImagePull with ServerStream %s request %s", stream, req.String()) r, w := io.Pipe() var pullResult error var complete = false go func() { defer r.Close() for { data := make([]byte, 512) n, err := r.Read(data) if err == io.EOF { if complete { break } else { continue } } if err != nil { glog.Errorf("Read image pull stream error: %v", err) return } if err := stream.Send(&types.ImagePullResponse{Data: data[:n]}); err != nil { glog.Errorf("Send image pull progress to stream error: %v", err) return } } }() pullResult = s.daemon.CmdImagePull(req.Image, req.Tag, authConfig, nil, w) complete = true if pullResult != nil { pullResult = fmt.Errorf("s.daemon.CmdImagePull with request %s error: %v", req.String(), pullResult) } return pullResult }
[ "func", "(", "s", "*", "ServerRPC", ")", "ImagePull", "(", "req", "*", "types", ".", "ImagePullRequest", ",", "stream", "types", ".", "PublicAPI_ImagePullServer", ")", "error", "{", "authConfig", ":=", "&", "enginetypes", ".", "AuthConfig", "{", "}", "\n", ...
// ImagePull pulls a image from registry
[ "ImagePull", "pulls", "a", "image", "from", "registry" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/serverrpc/images.go#L41-L92
train
hyperhq/hyperd
serverrpc/images.go
ImagePush
func (s *ServerRPC) ImagePush(req *types.ImagePushRequest, stream types.PublicAPI_ImagePushServer) error { authConfig := &enginetypes.AuthConfig{} if req.Auth != nil { authConfig = &enginetypes.AuthConfig{ Username: req.Auth.Username, Password: req.Auth.Password, Auth: req.Auth.Auth, Email: req.Auth.Email, ServerAddress: req.Auth.Serveraddress, RegistryToken: req.Auth.Registrytoken, } } glog.V(3).Infof("ImagePush with ServerStream %s request %s", stream, req.String()) buffer := bytes.NewBuffer([]byte{}) var pushResult error var complete = false go func() { pushResult = s.daemon.CmdImagePush(req.Repo, req.Tag, authConfig, nil, buffer) complete = true }() for { data, err := ioutil.ReadAll(buffer) if err == io.EOF { if complete { break } else { continue } } if err != nil { return fmt.Errorf("ImagePush read image push stream with request %s error: %v", req.String(), err) } if err := stream.Send(&types.ImagePushResponse{Data: data}); err != nil { return fmt.Errorf("stream.Send with request %s error: %v", req.String(), err) } } if pushResult != nil { pushResult = fmt.Errorf("s.daemon.CmdImagePush with request %s error: %v", req.String(), pushResult) } return pushResult }
go
func (s *ServerRPC) ImagePush(req *types.ImagePushRequest, stream types.PublicAPI_ImagePushServer) error { authConfig := &enginetypes.AuthConfig{} if req.Auth != nil { authConfig = &enginetypes.AuthConfig{ Username: req.Auth.Username, Password: req.Auth.Password, Auth: req.Auth.Auth, Email: req.Auth.Email, ServerAddress: req.Auth.Serveraddress, RegistryToken: req.Auth.Registrytoken, } } glog.V(3).Infof("ImagePush with ServerStream %s request %s", stream, req.String()) buffer := bytes.NewBuffer([]byte{}) var pushResult error var complete = false go func() { pushResult = s.daemon.CmdImagePush(req.Repo, req.Tag, authConfig, nil, buffer) complete = true }() for { data, err := ioutil.ReadAll(buffer) if err == io.EOF { if complete { break } else { continue } } if err != nil { return fmt.Errorf("ImagePush read image push stream with request %s error: %v", req.String(), err) } if err := stream.Send(&types.ImagePushResponse{Data: data}); err != nil { return fmt.Errorf("stream.Send with request %s error: %v", req.String(), err) } } if pushResult != nil { pushResult = fmt.Errorf("s.daemon.CmdImagePush with request %s error: %v", req.String(), pushResult) } return pushResult }
[ "func", "(", "s", "*", "ServerRPC", ")", "ImagePush", "(", "req", "*", "types", ".", "ImagePushRequest", ",", "stream", "types", ".", "PublicAPI_ImagePushServer", ")", "error", "{", "authConfig", ":=", "&", "enginetypes", ".", "AuthConfig", "{", "}", "\n", ...
// ImagePush pushes a local image to registry
[ "ImagePush", "pushes", "a", "local", "image", "to", "registry" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/serverrpc/images.go#L95-L140
train
hyperhq/hyperd
serverrpc/images.go
ImageRemove
func (s *ServerRPC) ImageRemove(ctx context.Context, req *types.ImageRemoveRequest) (*types.ImageRemoveResponse, error) { resp, err := s.daemon.CmdImageDelete(req.Image, req.Force, req.Prune) if err != nil { return nil, err } return &types.ImageRemoveResponse{ Images: resp, }, nil }
go
func (s *ServerRPC) ImageRemove(ctx context.Context, req *types.ImageRemoveRequest) (*types.ImageRemoveResponse, error) { resp, err := s.daemon.CmdImageDelete(req.Image, req.Force, req.Prune) if err != nil { return nil, err } return &types.ImageRemoveResponse{ Images: resp, }, nil }
[ "func", "(", "s", "*", "ServerRPC", ")", "ImageRemove", "(", "ctx", "context", ".", "Context", ",", "req", "*", "types", ".", "ImageRemoveRequest", ")", "(", "*", "types", ".", "ImageRemoveResponse", ",", "error", ")", "{", "resp", ",", "err", ":=", "s...
// ImageRemove deletes a image from hyperd
[ "ImageRemove", "deletes", "a", "image", "from", "hyperd" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/serverrpc/images.go#L143-L152
train
hyperhq/hyperd
serverrpc/pod.go
PodCreate
func (s *ServerRPC) PodCreate(ctx context.Context, req *types.PodCreateRequest) (*types.PodCreateResponse, error) { p, err := s.daemon.CreatePod(req.PodID, req.PodSpec) if err != nil { return nil, err } return &types.PodCreateResponse{ PodID: p.Id(), }, nil }
go
func (s *ServerRPC) PodCreate(ctx context.Context, req *types.PodCreateRequest) (*types.PodCreateResponse, error) { p, err := s.daemon.CreatePod(req.PodID, req.PodSpec) if err != nil { return nil, err } return &types.PodCreateResponse{ PodID: p.Id(), }, nil }
[ "func", "(", "s", "*", "ServerRPC", ")", "PodCreate", "(", "ctx", "context", ".", "Context", ",", "req", "*", "types", ".", "PodCreateRequest", ")", "(", "*", "types", ".", "PodCreateResponse", ",", "error", ")", "{", "p", ",", "err", ":=", "s", ".",...
// PodCreate creates a pod by PodSpec
[ "PodCreate", "creates", "a", "pod", "by", "PodSpec" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/serverrpc/pod.go#L12-L21
train
hyperhq/hyperd
serverrpc/pod.go
PodStart
func (s *ServerRPC) PodStart(ctx context.Context, req *types.PodStartRequest) (*types.PodStartResponse, error) { err := s.daemon.StartPod(req.PodID) if err != nil { return nil, err } return &types.PodStartResponse{}, nil }
go
func (s *ServerRPC) PodStart(ctx context.Context, req *types.PodStartRequest) (*types.PodStartResponse, error) { err := s.daemon.StartPod(req.PodID) if err != nil { return nil, err } return &types.PodStartResponse{}, nil }
[ "func", "(", "s", "*", "ServerRPC", ")", "PodStart", "(", "ctx", "context", ".", "Context", ",", "req", "*", "types", ".", "PodStartRequest", ")", "(", "*", "types", ".", "PodStartResponse", ",", "error", ")", "{", "err", ":=", "s", ".", "daemon", "....
// PodStart starts a pod by podID
[ "PodStart", "starts", "a", "pod", "by", "podID" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/serverrpc/pod.go#L24-L31
train
hyperhq/hyperd
serverrpc/pod.go
PodRemove
func (s *ServerRPC) PodRemove(ctx context.Context, req *types.PodRemoveRequest) (*types.PodRemoveResponse, error) { if req.PodID == "" { return nil, fmt.Errorf("PodRemove failed PodID is required for PodRemove") } code, cause, err := s.daemon.RemovePod(req.PodID) if err != nil { return nil, fmt.Errorf("s.daemon.RemovePod error: %v", err) } return &types.PodRemoveResponse{ Cause: cause, Code: int32(code), }, nil }
go
func (s *ServerRPC) PodRemove(ctx context.Context, req *types.PodRemoveRequest) (*types.PodRemoveResponse, error) { if req.PodID == "" { return nil, fmt.Errorf("PodRemove failed PodID is required for PodRemove") } code, cause, err := s.daemon.RemovePod(req.PodID) if err != nil { return nil, fmt.Errorf("s.daemon.RemovePod error: %v", err) } return &types.PodRemoveResponse{ Cause: cause, Code: int32(code), }, nil }
[ "func", "(", "s", "*", "ServerRPC", ")", "PodRemove", "(", "ctx", "context", ".", "Context", ",", "req", "*", "types", ".", "PodRemoveRequest", ")", "(", "*", "types", ".", "PodRemoveResponse", ",", "error", ")", "{", "if", "req", ".", "PodID", "==", ...
// PodRemove removes a pod by podID
[ "PodRemove", "removes", "a", "pod", "by", "podID" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/serverrpc/pod.go#L34-L48
train
hyperhq/hyperd
serverrpc/pod.go
PodStop
func (s *ServerRPC) PodStop(ctx context.Context, req *types.PodStopRequest) (*types.PodStopResponse, error) { code, cause, err := s.daemon.StopPod(req.PodID) if err != nil { return nil, err } return &types.PodStopResponse{ Cause: cause, Code: int32(code), }, nil }
go
func (s *ServerRPC) PodStop(ctx context.Context, req *types.PodStopRequest) (*types.PodStopResponse, error) { code, cause, err := s.daemon.StopPod(req.PodID) if err != nil { return nil, err } return &types.PodStopResponse{ Cause: cause, Code: int32(code), }, nil }
[ "func", "(", "s", "*", "ServerRPC", ")", "PodStop", "(", "ctx", "context", ".", "Context", ",", "req", "*", "types", ".", "PodStopRequest", ")", "(", "*", "types", ".", "PodStopResponse", ",", "error", ")", "{", "code", ",", "cause", ",", "err", ":="...
// PodStop stops a pod
[ "PodStop", "stops", "a", "pod" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/serverrpc/pod.go#L51-L61
train
hyperhq/hyperd
serverrpc/pod.go
PodSignal
func (s *ServerRPC) PodSignal(ctx context.Context, req *types.PodSignalRequest) (*types.PodSignalResponse, error) { err := s.daemon.KillPodContainers(req.PodID, "", req.Signal) if err != nil { return nil, err } return &types.PodSignalResponse{}, nil }
go
func (s *ServerRPC) PodSignal(ctx context.Context, req *types.PodSignalRequest) (*types.PodSignalResponse, error) { err := s.daemon.KillPodContainers(req.PodID, "", req.Signal) if err != nil { return nil, err } return &types.PodSignalResponse{}, nil }
[ "func", "(", "s", "*", "ServerRPC", ")", "PodSignal", "(", "ctx", "context", ".", "Context", ",", "req", "*", "types", ".", "PodSignalRequest", ")", "(", "*", "types", ".", "PodSignalResponse", ",", "error", ")", "{", "err", ":=", "s", ".", "daemon", ...
// PodSignal sends a singal to all containers of specified pod
[ "PodSignal", "sends", "a", "singal", "to", "all", "containers", "of", "specified", "pod" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/serverrpc/pod.go#L64-L71
train
hyperhq/hyperd
serverrpc/pod.go
PodPause
func (s *ServerRPC) PodPause(ctx context.Context, req *types.PodPauseRequest) (*types.PodPauseResponse, error) { err := s.daemon.PausePod(req.PodID) if err != nil { return nil, err } return &types.PodPauseResponse{}, nil }
go
func (s *ServerRPC) PodPause(ctx context.Context, req *types.PodPauseRequest) (*types.PodPauseResponse, error) { err := s.daemon.PausePod(req.PodID) if err != nil { return nil, err } return &types.PodPauseResponse{}, nil }
[ "func", "(", "s", "*", "ServerRPC", ")", "PodPause", "(", "ctx", "context", ".", "Context", ",", "req", "*", "types", ".", "PodPauseRequest", ")", "(", "*", "types", ".", "PodPauseResponse", ",", "error", ")", "{", "err", ":=", "s", ".", "daemon", "....
// PodPause pauses a pod
[ "PodPause", "pauses", "a", "pod" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/serverrpc/pod.go#L74-L81
train
hyperhq/hyperd
serverrpc/pod.go
PodUnpause
func (s *ServerRPC) PodUnpause(ctx context.Context, req *types.PodUnpauseRequest) (*types.PodUnpauseResponse, error) { err := s.daemon.UnpausePod(req.PodID) if err != nil { return nil, err } return &types.PodUnpauseResponse{}, nil }
go
func (s *ServerRPC) PodUnpause(ctx context.Context, req *types.PodUnpauseRequest) (*types.PodUnpauseResponse, error) { err := s.daemon.UnpausePod(req.PodID) if err != nil { return nil, err } return &types.PodUnpauseResponse{}, nil }
[ "func", "(", "s", "*", "ServerRPC", ")", "PodUnpause", "(", "ctx", "context", ".", "Context", ",", "req", "*", "types", ".", "PodUnpauseRequest", ")", "(", "*", "types", ".", "PodUnpauseResponse", ",", "error", ")", "{", "err", ":=", "s", ".", "daemon"...
// PodUnpause unpauses a pod
[ "PodUnpause", "unpauses", "a", "pod" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/serverrpc/pod.go#L84-L91
train
hyperhq/hyperd
serverrpc/pod.go
SetPodLabels
func (s *ServerRPC) SetPodLabels(c context.Context, req *types.PodLabelsRequest) (*types.PodLabelsResponse, error) { err := s.daemon.SetPodLabels(req.PodID, req.Override, req.Labels) if err != nil { return nil, err } return &types.PodLabelsResponse{}, nil }
go
func (s *ServerRPC) SetPodLabels(c context.Context, req *types.PodLabelsRequest) (*types.PodLabelsResponse, error) { err := s.daemon.SetPodLabels(req.PodID, req.Override, req.Labels) if err != nil { return nil, err } return &types.PodLabelsResponse{}, nil }
[ "func", "(", "s", "*", "ServerRPC", ")", "SetPodLabels", "(", "c", "context", ".", "Context", ",", "req", "*", "types", ".", "PodLabelsRequest", ")", "(", "*", "types", ".", "PodLabelsResponse", ",", "error", ")", "{", "err", ":=", "s", ".", "daemon", ...
// PodLabels sets the labels of Pod
[ "PodLabels", "sets", "the", "labels", "of", "Pod" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/serverrpc/pod.go#L94-L101
train
golang/geo
s2/point.go
Distance
func (p Point) Distance(b Point) s1.Angle { return p.Vector.Angle(b.Vector) }
go
func (p Point) Distance(b Point) s1.Angle { return p.Vector.Angle(b.Vector) }
[ "func", "(", "p", "Point", ")", "Distance", "(", "b", "Point", ")", "s1", ".", "Angle", "{", "return", "p", ".", "Vector", ".", "Angle", "(", "b", ".", "Vector", ")", "\n", "}" ]
// Distance returns the angle between two points.
[ "Distance", "returns", "the", "angle", "between", "two", "points", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/point.go#L125-L127
train
golang/geo
s2/point.go
ApproxEqual
func (p Point) ApproxEqual(other Point) bool { return p.Vector.Angle(other.Vector) <= s1.Angle(epsilon) }
go
func (p Point) ApproxEqual(other Point) bool { return p.Vector.Angle(other.Vector) <= s1.Angle(epsilon) }
[ "func", "(", "p", "Point", ")", "ApproxEqual", "(", "other", "Point", ")", "bool", "{", "return", "p", ".", "Vector", ".", "Angle", "(", "other", ".", "Vector", ")", "<=", "s1", ".", "Angle", "(", "epsilon", ")", "\n", "}" ]
// ApproxEqual reports whether the two points are similar enough to be equal.
[ "ApproxEqual", "reports", "whether", "the", "two", "points", "are", "similar", "enough", "to", "be", "equal", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/point.go#L130-L132
train
golang/geo
s2/point.go
ChordAngleBetweenPoints
func ChordAngleBetweenPoints(x, y Point) s1.ChordAngle { return s1.ChordAngle(math.Min(4.0, x.Sub(y.Vector).Norm2())) }
go
func ChordAngleBetweenPoints(x, y Point) s1.ChordAngle { return s1.ChordAngle(math.Min(4.0, x.Sub(y.Vector).Norm2())) }
[ "func", "ChordAngleBetweenPoints", "(", "x", ",", "y", "Point", ")", "s1", ".", "ChordAngle", "{", "return", "s1", ".", "ChordAngle", "(", "math", ".", "Min", "(", "4.0", ",", "x", ".", "Sub", "(", "y", ".", "Vector", ")", ".", "Norm2", "(", ")", ...
// ChordAngleBetweenPoints constructs a ChordAngle corresponding to the distance // between the two given points. The points must be unit length.
[ "ChordAngleBetweenPoints", "constructs", "a", "ChordAngle", "corresponding", "to", "the", "distance", "between", "the", "two", "given", "points", ".", "The", "points", "must", "be", "unit", "length", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/point.go#L136-L138
train
golang/geo
s2/point.go
regularPoints
func regularPoints(center Point, radius s1.Angle, numVertices int) []Point { return regularPointsForFrame(getFrame(center), radius, numVertices) }
go
func regularPoints(center Point, radius s1.Angle, numVertices int) []Point { return regularPointsForFrame(getFrame(center), radius, numVertices) }
[ "func", "regularPoints", "(", "center", "Point", ",", "radius", "s1", ".", "Angle", ",", "numVertices", "int", ")", "[", "]", "Point", "{", "return", "regularPointsForFrame", "(", "getFrame", "(", "center", ")", ",", "radius", ",", "numVertices", ")", "\n"...
// regularPoints generates a slice of points shaped as a regular polygon with // the numVertices vertices, all located on a circle of the specified angular radius // around the center. The radius is the actual distance from center to each vertex.
[ "regularPoints", "generates", "a", "slice", "of", "points", "shaped", "as", "a", "regular", "polygon", "with", "the", "numVertices", "vertices", "all", "located", "on", "a", "circle", "of", "the", "specified", "angular", "radius", "around", "the", "center", "....
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/point.go#L143-L145
train
golang/geo
s2/point.go
regularPointsForFrame
func regularPointsForFrame(frame matrix3x3, radius s1.Angle, numVertices int) []Point { // We construct the loop in the given frame coordinates, with the center at // (0, 0, 1). For a loop of radius r, the loop vertices have the form // (x, y, z) where x^2 + y^2 = sin(r) and z = cos(r). The distance on the // sphere (arc length) from each vertex to the center is acos(cos(r)) = r. z := math.Cos(radius.Radians()) r := math.Sin(radius.Radians()) radianStep := 2 * math.Pi / float64(numVertices) var vertices []Point for i := 0; i < numVertices; i++ { angle := float64(i) * radianStep p := Point{r3.Vector{r * math.Cos(angle), r * math.Sin(angle), z}} vertices = append(vertices, Point{fromFrame(frame, p).Normalize()}) } return vertices }
go
func regularPointsForFrame(frame matrix3x3, radius s1.Angle, numVertices int) []Point { // We construct the loop in the given frame coordinates, with the center at // (0, 0, 1). For a loop of radius r, the loop vertices have the form // (x, y, z) where x^2 + y^2 = sin(r) and z = cos(r). The distance on the // sphere (arc length) from each vertex to the center is acos(cos(r)) = r. z := math.Cos(radius.Radians()) r := math.Sin(radius.Radians()) radianStep := 2 * math.Pi / float64(numVertices) var vertices []Point for i := 0; i < numVertices; i++ { angle := float64(i) * radianStep p := Point{r3.Vector{r * math.Cos(angle), r * math.Sin(angle), z}} vertices = append(vertices, Point{fromFrame(frame, p).Normalize()}) } return vertices }
[ "func", "regularPointsForFrame", "(", "frame", "matrix3x3", ",", "radius", "s1", ".", "Angle", ",", "numVertices", "int", ")", "[", "]", "Point", "{", "// We construct the loop in the given frame coordinates, with the center at", "// (0, 0, 1). For a loop of radius r, the loop ...
// regularPointsForFrame generates a slice of points shaped as a regular polygon // with numVertices vertices, all on a circle of the specified angular radius around // the center. The radius is the actual distance from the center to each vertex.
[ "regularPointsForFrame", "generates", "a", "slice", "of", "points", "shaped", "as", "a", "regular", "polygon", "with", "numVertices", "vertices", "all", "on", "a", "circle", "of", "the", "specified", "angular", "radius", "around", "the", "center", ".", "The", ...
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/point.go#L150-L167
train
golang/geo
s2/crossing_edge_query.go
NewCrossingEdgeQuery
func NewCrossingEdgeQuery(index *ShapeIndex) *CrossingEdgeQuery { c := &CrossingEdgeQuery{ index: index, iter: index.Iterator(), } return c }
go
func NewCrossingEdgeQuery(index *ShapeIndex) *CrossingEdgeQuery { c := &CrossingEdgeQuery{ index: index, iter: index.Iterator(), } return c }
[ "func", "NewCrossingEdgeQuery", "(", "index", "*", "ShapeIndex", ")", "*", "CrossingEdgeQuery", "{", "c", ":=", "&", "CrossingEdgeQuery", "{", "index", ":", "index", ",", "iter", ":", "index", ".", "Iterator", "(", ")", ",", "}", "\n", "return", "c", "\n...
// NewCrossingEdgeQuery creates a CrossingEdgeQuery for the given index.
[ "NewCrossingEdgeQuery", "creates", "a", "CrossingEdgeQuery", "for", "the", "given", "index", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/crossing_edge_query.go#L43-L49
train
golang/geo
s2/crossing_edge_query.go
Crossings
func (c *CrossingEdgeQuery) Crossings(a, b Point, shape Shape, crossType CrossingType) []int { edges := c.candidates(a, b, shape) if len(edges) == 0 { return nil } crosser := NewEdgeCrosser(a, b) out := 0 n := len(edges) for in := 0; in < n; in++ { b := shape.Edge(edges[in]) sign := crosser.CrossingSign(b.V0, b.V1) if crossType == CrossingTypeAll && (sign == MaybeCross || sign == Cross) || crossType != CrossingTypeAll && sign == Cross { edges[out] = edges[in] out++ } } if out < n { edges = edges[0:out] } return edges }
go
func (c *CrossingEdgeQuery) Crossings(a, b Point, shape Shape, crossType CrossingType) []int { edges := c.candidates(a, b, shape) if len(edges) == 0 { return nil } crosser := NewEdgeCrosser(a, b) out := 0 n := len(edges) for in := 0; in < n; in++ { b := shape.Edge(edges[in]) sign := crosser.CrossingSign(b.V0, b.V1) if crossType == CrossingTypeAll && (sign == MaybeCross || sign == Cross) || crossType != CrossingTypeAll && sign == Cross { edges[out] = edges[in] out++ } } if out < n { edges = edges[0:out] } return edges }
[ "func", "(", "c", "*", "CrossingEdgeQuery", ")", "Crossings", "(", "a", ",", "b", "Point", ",", "shape", "Shape", ",", "crossType", "CrossingType", ")", "[", "]", "int", "{", "edges", ":=", "c", ".", "candidates", "(", "a", ",", "b", ",", "shape", ...
// Crossings returns the set of edge of the shape S that intersect the given edge AB. // If the CrossingType is Interior, then only intersections at a point interior to both // edges are reported, while if it is CrossingTypeAll then edges that share a vertex // are also reported.
[ "Crossings", "returns", "the", "set", "of", "edge", "of", "the", "shape", "S", "that", "intersect", "the", "given", "edge", "AB", ".", "If", "the", "CrossingType", "is", "Interior", "then", "only", "intersections", "at", "a", "point", "interior", "to", "bo...
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/crossing_edge_query.go#L55-L78
train
golang/geo
s2/crossing_edge_query.go
CrossingsEdgeMap
func (c *CrossingEdgeQuery) CrossingsEdgeMap(a, b Point, crossType CrossingType) EdgeMap { edgeMap := c.candidatesEdgeMap(a, b) if len(edgeMap) == 0 { return nil } crosser := NewEdgeCrosser(a, b) for shape, edges := range edgeMap { out := 0 n := len(edges) for in := 0; in < n; in++ { edge := shape.Edge(edges[in]) sign := crosser.CrossingSign(edge.V0, edge.V1) if (crossType == CrossingTypeAll && (sign == MaybeCross || sign == Cross)) || (crossType != CrossingTypeAll && sign == Cross) { edgeMap[shape][out] = edges[in] out++ } } if out == 0 { delete(edgeMap, shape) } else { if out < n { edgeMap[shape] = edgeMap[shape][0:out] } } } return edgeMap }
go
func (c *CrossingEdgeQuery) CrossingsEdgeMap(a, b Point, crossType CrossingType) EdgeMap { edgeMap := c.candidatesEdgeMap(a, b) if len(edgeMap) == 0 { return nil } crosser := NewEdgeCrosser(a, b) for shape, edges := range edgeMap { out := 0 n := len(edges) for in := 0; in < n; in++ { edge := shape.Edge(edges[in]) sign := crosser.CrossingSign(edge.V0, edge.V1) if (crossType == CrossingTypeAll && (sign == MaybeCross || sign == Cross)) || (crossType != CrossingTypeAll && sign == Cross) { edgeMap[shape][out] = edges[in] out++ } } if out == 0 { delete(edgeMap, shape) } else { if out < n { edgeMap[shape] = edgeMap[shape][0:out] } } } return edgeMap }
[ "func", "(", "c", "*", "CrossingEdgeQuery", ")", "CrossingsEdgeMap", "(", "a", ",", "b", "Point", ",", "crossType", "CrossingType", ")", "EdgeMap", "{", "edgeMap", ":=", "c", ".", "candidatesEdgeMap", "(", "a", ",", "b", ")", "\n", "if", "len", "(", "e...
// CrossingsEdgeMap returns the set of all edges in the index that intersect the given // edge AB. If crossType is CrossingTypeInterior, then only intersections at a // point interior to both edges are reported, while if it is CrossingTypeAll // then edges that share a vertex are also reported. // // The edges are returned as a mapping from shape to the edges of that shape // that intersect AB. Every returned shape has at least one crossing edge.
[ "CrossingsEdgeMap", "returns", "the", "set", "of", "all", "edges", "in", "the", "index", "that", "intersect", "the", "given", "edge", "AB", ".", "If", "crossType", "is", "CrossingTypeInterior", "then", "only", "intersections", "at", "a", "point", "interior", "...
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/crossing_edge_query.go#L90-L118
train
golang/geo
s2/crossing_edge_query.go
candidates
func (c *CrossingEdgeQuery) candidates(a, b Point, shape Shape) []int { var edges []int // For small loops it is faster to use brute force. The threshold below was // determined using benchmarks. const maxBruteForceEdges = 27 maxEdges := shape.NumEdges() if maxEdges <= maxBruteForceEdges { edges = make([]int, maxEdges) for i := 0; i < maxEdges; i++ { edges[i] = i } return edges } // Compute the set of index cells intersected by the query edge. c.getCellsForEdge(a, b) if len(c.cells) == 0 { return nil } // Gather all the edges that intersect those cells and sort them. // TODO(roberts): Shapes don't track their ID, so we need to range over // the index to find the ID manually. var shapeID int32 for k, v := range c.index.shapes { if v == shape { shapeID = k } } for _, cell := range c.cells { if cell == nil { } clipped := cell.findByShapeID(shapeID) if clipped == nil { continue } for _, j := range clipped.edges { edges = append(edges, j) } } if len(c.cells) > 1 { edges = uniqueInts(edges) } return edges }
go
func (c *CrossingEdgeQuery) candidates(a, b Point, shape Shape) []int { var edges []int // For small loops it is faster to use brute force. The threshold below was // determined using benchmarks. const maxBruteForceEdges = 27 maxEdges := shape.NumEdges() if maxEdges <= maxBruteForceEdges { edges = make([]int, maxEdges) for i := 0; i < maxEdges; i++ { edges[i] = i } return edges } // Compute the set of index cells intersected by the query edge. c.getCellsForEdge(a, b) if len(c.cells) == 0 { return nil } // Gather all the edges that intersect those cells and sort them. // TODO(roberts): Shapes don't track their ID, so we need to range over // the index to find the ID manually. var shapeID int32 for k, v := range c.index.shapes { if v == shape { shapeID = k } } for _, cell := range c.cells { if cell == nil { } clipped := cell.findByShapeID(shapeID) if clipped == nil { continue } for _, j := range clipped.edges { edges = append(edges, j) } } if len(c.cells) > 1 { edges = uniqueInts(edges) } return edges }
[ "func", "(", "c", "*", "CrossingEdgeQuery", ")", "candidates", "(", "a", ",", "b", "Point", ",", "shape", "Shape", ")", "[", "]", "int", "{", "var", "edges", "[", "]", "int", "\n\n", "// For small loops it is faster to use brute force. The threshold below was", ...
// candidates returns a superset of the edges of the given shape that intersect // the edge AB.
[ "candidates", "returns", "a", "superset", "of", "the", "edges", "of", "the", "given", "shape", "that", "intersect", "the", "edge", "AB", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/crossing_edge_query.go#L122-L170
train
golang/geo
s2/crossing_edge_query.go
uniqueInts
func uniqueInts(in []int) []int { var edges []int m := make(map[int]bool) for _, i := range in { if m[i] { continue } m[i] = true edges = append(edges, i) } sort.Ints(edges) return edges }
go
func uniqueInts(in []int) []int { var edges []int m := make(map[int]bool) for _, i := range in { if m[i] { continue } m[i] = true edges = append(edges, i) } sort.Ints(edges) return edges }
[ "func", "uniqueInts", "(", "in", "[", "]", "int", ")", "[", "]", "int", "{", "var", "edges", "[", "]", "int", "\n", "m", ":=", "make", "(", "map", "[", "int", "]", "bool", ")", "\n", "for", "_", ",", "i", ":=", "range", "in", "{", "if", "m"...
// uniqueInts returns the sorted uniqued values from the given input.
[ "uniqueInts", "returns", "the", "sorted", "uniqued", "values", "from", "the", "given", "input", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/crossing_edge_query.go#L173-L185
train
golang/geo
s2/crossing_edge_query.go
getCells
func (c *CrossingEdgeQuery) getCells(a, b Point, root *PaddedCell) []*ShapeIndexCell { aUV, bUV, ok := ClipToFace(a, b, root.id.Face()) if ok { c.a = aUV c.b = bUV edgeBound := r2.RectFromPoints(c.a, c.b) if root.Bound().Intersects(edgeBound) { c.computeCellsIntersected(root, edgeBound) } } if len(c.cells) == 0 { return nil } return c.cells }
go
func (c *CrossingEdgeQuery) getCells(a, b Point, root *PaddedCell) []*ShapeIndexCell { aUV, bUV, ok := ClipToFace(a, b, root.id.Face()) if ok { c.a = aUV c.b = bUV edgeBound := r2.RectFromPoints(c.a, c.b) if root.Bound().Intersects(edgeBound) { c.computeCellsIntersected(root, edgeBound) } } if len(c.cells) == 0 { return nil } return c.cells }
[ "func", "(", "c", "*", "CrossingEdgeQuery", ")", "getCells", "(", "a", ",", "b", "Point", ",", "root", "*", "PaddedCell", ")", "[", "]", "*", "ShapeIndexCell", "{", "aUV", ",", "bUV", ",", "ok", ":=", "ClipToFace", "(", "a", ",", "b", ",", "root", ...
// getCells returns the set of ShapeIndexCells that might contain edges intersecting // the edge AB in the given cell root. This method is used primarly by loop and shapeutil.
[ "getCells", "returns", "the", "set", "of", "ShapeIndexCells", "that", "might", "contain", "edges", "intersecting", "the", "edge", "AB", "in", "the", "given", "cell", "root", ".", "This", "method", "is", "used", "primarly", "by", "loop", "and", "shapeutil", "...
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/crossing_edge_query.go#L236-L252
train
golang/geo
s2/crossing_edge_query.go
getCellsForEdge
func (c *CrossingEdgeQuery) getCellsForEdge(a, b Point) { c.cells = nil segments := FaceSegments(a, b) for _, segment := range segments { c.a = segment.a c.b = segment.b // Optimization: rather than always starting the recursive subdivision at // the top level face cell, instead we start at the smallest S2CellId that // contains the edge (the edge root cell). This typically lets us skip // quite a few levels of recursion since most edges are short. edgeBound := r2.RectFromPoints(c.a, c.b) pcell := PaddedCellFromCellID(CellIDFromFace(segment.face), 0) edgeRoot := pcell.ShrinkToFit(edgeBound) // Now we need to determine how the edge root cell is related to the cells // in the spatial index (cellMap). There are three cases: // // 1. edgeRoot is an index cell or is contained within an index cell. // In this case we only need to look at the contents of that cell. // 2. edgeRoot is subdivided into one or more index cells. In this case // we recursively subdivide to find the cells intersected by AB. // 3. edgeRoot does not intersect any index cells. In this case there // is nothing to do. relation := c.iter.LocateCellID(edgeRoot) if relation == Indexed { // edgeRoot is an index cell or is contained by an index cell (case 1). c.cells = append(c.cells, c.iter.IndexCell()) } else if relation == Subdivided { // edgeRoot is subdivided into one or more index cells (case 2). We // find the cells intersected by AB using recursive subdivision. if !edgeRoot.isFace() { pcell = PaddedCellFromCellID(edgeRoot, 0) } c.computeCellsIntersected(pcell, edgeBound) } } }
go
func (c *CrossingEdgeQuery) getCellsForEdge(a, b Point) { c.cells = nil segments := FaceSegments(a, b) for _, segment := range segments { c.a = segment.a c.b = segment.b // Optimization: rather than always starting the recursive subdivision at // the top level face cell, instead we start at the smallest S2CellId that // contains the edge (the edge root cell). This typically lets us skip // quite a few levels of recursion since most edges are short. edgeBound := r2.RectFromPoints(c.a, c.b) pcell := PaddedCellFromCellID(CellIDFromFace(segment.face), 0) edgeRoot := pcell.ShrinkToFit(edgeBound) // Now we need to determine how the edge root cell is related to the cells // in the spatial index (cellMap). There are three cases: // // 1. edgeRoot is an index cell or is contained within an index cell. // In this case we only need to look at the contents of that cell. // 2. edgeRoot is subdivided into one or more index cells. In this case // we recursively subdivide to find the cells intersected by AB. // 3. edgeRoot does not intersect any index cells. In this case there // is nothing to do. relation := c.iter.LocateCellID(edgeRoot) if relation == Indexed { // edgeRoot is an index cell or is contained by an index cell (case 1). c.cells = append(c.cells, c.iter.IndexCell()) } else if relation == Subdivided { // edgeRoot is subdivided into one or more index cells (case 2). We // find the cells intersected by AB using recursive subdivision. if !edgeRoot.isFace() { pcell = PaddedCellFromCellID(edgeRoot, 0) } c.computeCellsIntersected(pcell, edgeBound) } } }
[ "func", "(", "c", "*", "CrossingEdgeQuery", ")", "getCellsForEdge", "(", "a", ",", "b", "Point", ")", "{", "c", ".", "cells", "=", "nil", "\n\n", "segments", ":=", "FaceSegments", "(", "a", ",", "b", ")", "\n", "for", "_", ",", "segment", ":=", "ra...
// getCellsForEdge populates the cells field to the set of index cells intersected by an edge AB.
[ "getCellsForEdge", "populates", "the", "cells", "field", "to", "the", "set", "of", "index", "cells", "intersected", "by", "an", "edge", "AB", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/crossing_edge_query.go#L255-L293
train
golang/geo
s2/crossing_edge_query.go
computeCellsIntersected
func (c *CrossingEdgeQuery) computeCellsIntersected(pcell *PaddedCell, edgeBound r2.Rect) { c.iter.seek(pcell.id.RangeMin()) if c.iter.Done() || c.iter.CellID() > pcell.id.RangeMax() { // The index does not contain pcell or any of its descendants. return } if c.iter.CellID() == pcell.id { // The index contains this cell exactly. c.cells = append(c.cells, c.iter.IndexCell()) return } // Otherwise, split the edge among the four children of pcell. center := pcell.Middle().Lo() if edgeBound.X.Hi < center.X { // Edge is entirely contained in the two left children. c.clipVAxis(edgeBound, center.Y, 0, pcell) return } else if edgeBound.X.Lo >= center.X { // Edge is entirely contained in the two right children. c.clipVAxis(edgeBound, center.Y, 1, pcell) return } childBounds := c.splitUBound(edgeBound, center.X) if edgeBound.Y.Hi < center.Y { // Edge is entirely contained in the two lower children. c.computeCellsIntersected(PaddedCellFromParentIJ(pcell, 0, 0), childBounds[0]) c.computeCellsIntersected(PaddedCellFromParentIJ(pcell, 1, 0), childBounds[1]) } else if edgeBound.Y.Lo >= center.Y { // Edge is entirely contained in the two upper children. c.computeCellsIntersected(PaddedCellFromParentIJ(pcell, 0, 1), childBounds[0]) c.computeCellsIntersected(PaddedCellFromParentIJ(pcell, 1, 1), childBounds[1]) } else { // The edge bound spans all four children. The edge itself intersects // at most three children (since no padding is being used). c.clipVAxis(childBounds[0], center.Y, 0, pcell) c.clipVAxis(childBounds[1], center.Y, 1, pcell) } }
go
func (c *CrossingEdgeQuery) computeCellsIntersected(pcell *PaddedCell, edgeBound r2.Rect) { c.iter.seek(pcell.id.RangeMin()) if c.iter.Done() || c.iter.CellID() > pcell.id.RangeMax() { // The index does not contain pcell or any of its descendants. return } if c.iter.CellID() == pcell.id { // The index contains this cell exactly. c.cells = append(c.cells, c.iter.IndexCell()) return } // Otherwise, split the edge among the four children of pcell. center := pcell.Middle().Lo() if edgeBound.X.Hi < center.X { // Edge is entirely contained in the two left children. c.clipVAxis(edgeBound, center.Y, 0, pcell) return } else if edgeBound.X.Lo >= center.X { // Edge is entirely contained in the two right children. c.clipVAxis(edgeBound, center.Y, 1, pcell) return } childBounds := c.splitUBound(edgeBound, center.X) if edgeBound.Y.Hi < center.Y { // Edge is entirely contained in the two lower children. c.computeCellsIntersected(PaddedCellFromParentIJ(pcell, 0, 0), childBounds[0]) c.computeCellsIntersected(PaddedCellFromParentIJ(pcell, 1, 0), childBounds[1]) } else if edgeBound.Y.Lo >= center.Y { // Edge is entirely contained in the two upper children. c.computeCellsIntersected(PaddedCellFromParentIJ(pcell, 0, 1), childBounds[0]) c.computeCellsIntersected(PaddedCellFromParentIJ(pcell, 1, 1), childBounds[1]) } else { // The edge bound spans all four children. The edge itself intersects // at most three children (since no padding is being used). c.clipVAxis(childBounds[0], center.Y, 0, pcell) c.clipVAxis(childBounds[1], center.Y, 1, pcell) } }
[ "func", "(", "c", "*", "CrossingEdgeQuery", ")", "computeCellsIntersected", "(", "pcell", "*", "PaddedCell", ",", "edgeBound", "r2", ".", "Rect", ")", "{", "c", ".", "iter", ".", "seek", "(", "pcell", ".", "id", ".", "RangeMin", "(", ")", ")", "\n", ...
// computeCellsIntersected computes the index cells intersected by the current // edge that are descendants of pcell and adds them to this queries set of cells.
[ "computeCellsIntersected", "computes", "the", "index", "cells", "intersected", "by", "the", "current", "edge", "that", "are", "descendants", "of", "pcell", "and", "adds", "them", "to", "this", "queries", "set", "of", "cells", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/crossing_edge_query.go#L297-L338
train
golang/geo
s2/crossing_edge_query.go
splitUBound
func (c *CrossingEdgeQuery) splitUBound(edgeBound r2.Rect, u float64) [2]r2.Rect { v := edgeBound.Y.ClampPoint(interpolateFloat64(u, c.a.X, c.b.X, c.a.Y, c.b.Y)) // diag indicates which diagonal of the bounding box is spanned by AB: // it is 0 if AB has positive slope, and 1 if AB has negative slope. var diag int if (c.a.X > c.b.X) != (c.a.Y > c.b.Y) { diag = 1 } return splitBound(edgeBound, 0, diag, u, v) }
go
func (c *CrossingEdgeQuery) splitUBound(edgeBound r2.Rect, u float64) [2]r2.Rect { v := edgeBound.Y.ClampPoint(interpolateFloat64(u, c.a.X, c.b.X, c.a.Y, c.b.Y)) // diag indicates which diagonal of the bounding box is spanned by AB: // it is 0 if AB has positive slope, and 1 if AB has negative slope. var diag int if (c.a.X > c.b.X) != (c.a.Y > c.b.Y) { diag = 1 } return splitBound(edgeBound, 0, diag, u, v) }
[ "func", "(", "c", "*", "CrossingEdgeQuery", ")", "splitUBound", "(", "edgeBound", "r2", ".", "Rect", ",", "u", "float64", ")", "[", "2", "]", "r2", ".", "Rect", "{", "v", ":=", "edgeBound", ".", "Y", ".", "ClampPoint", "(", "interpolateFloat64", "(", ...
// splitUBound returns the bound for two children as a result of spliting the // current edge at the given value U.
[ "splitUBound", "returns", "the", "bound", "for", "two", "children", "as", "a", "result", "of", "spliting", "the", "current", "edge", "at", "the", "given", "value", "U", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/crossing_edge_query.go#L362-L371
train
golang/geo
s2/polyline_measures.go
polylineLength
func polylineLength(p []Point) s1.Angle { var length s1.Angle for i := 1; i < len(p); i++ { length += p[i-1].Distance(p[i]) } return length }
go
func polylineLength(p []Point) s1.Angle { var length s1.Angle for i := 1; i < len(p); i++ { length += p[i-1].Distance(p[i]) } return length }
[ "func", "polylineLength", "(", "p", "[", "]", "Point", ")", "s1", ".", "Angle", "{", "var", "length", "s1", ".", "Angle", "\n\n", "for", "i", ":=", "1", ";", "i", "<", "len", "(", "p", ")", ";", "i", "++", "{", "length", "+=", "p", "[", "i", ...
// polylineLength returns the length of the given Polyline. // It returns 0 for polylines with fewer than two vertices.
[ "polylineLength", "returns", "the", "length", "of", "the", "given", "Polyline", ".", "It", "returns", "0", "for", "polylines", "with", "fewer", "than", "two", "vertices", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/polyline_measures.go#L28-L35
train
golang/geo
s2/latlng.go
LatLngFromDegrees
func LatLngFromDegrees(lat, lng float64) LatLng { return LatLng{s1.Angle(lat) * s1.Degree, s1.Angle(lng) * s1.Degree} }
go
func LatLngFromDegrees(lat, lng float64) LatLng { return LatLng{s1.Angle(lat) * s1.Degree, s1.Angle(lng) * s1.Degree} }
[ "func", "LatLngFromDegrees", "(", "lat", ",", "lng", "float64", ")", "LatLng", "{", "return", "LatLng", "{", "s1", ".", "Angle", "(", "lat", ")", "*", "s1", ".", "Degree", ",", "s1", ".", "Angle", "(", "lng", ")", "*", "s1", ".", "Degree", "}", "...
// LatLngFromDegrees returns a LatLng for the coordinates given in degrees.
[ "LatLngFromDegrees", "returns", "a", "LatLng", "for", "the", "coordinates", "given", "in", "degrees", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/latlng.go#L36-L38
train
golang/geo
s2/latlng.go
Distance
func (ll LatLng) Distance(ll2 LatLng) s1.Angle { // Haversine formula, as used in C++ S2LatLng::GetDistance. lat1, lat2 := ll.Lat.Radians(), ll2.Lat.Radians() lng1, lng2 := ll.Lng.Radians(), ll2.Lng.Radians() dlat := math.Sin(0.5 * (lat2 - lat1)) dlng := math.Sin(0.5 * (lng2 - lng1)) x := dlat*dlat + dlng*dlng*math.Cos(lat1)*math.Cos(lat2) return s1.Angle(2*math.Atan2(math.Sqrt(x), math.Sqrt(math.Max(0, 1-x)))) * s1.Radian }
go
func (ll LatLng) Distance(ll2 LatLng) s1.Angle { // Haversine formula, as used in C++ S2LatLng::GetDistance. lat1, lat2 := ll.Lat.Radians(), ll2.Lat.Radians() lng1, lng2 := ll.Lng.Radians(), ll2.Lng.Radians() dlat := math.Sin(0.5 * (lat2 - lat1)) dlng := math.Sin(0.5 * (lng2 - lng1)) x := dlat*dlat + dlng*dlng*math.Cos(lat1)*math.Cos(lat2) return s1.Angle(2*math.Atan2(math.Sqrt(x), math.Sqrt(math.Max(0, 1-x)))) * s1.Radian }
[ "func", "(", "ll", "LatLng", ")", "Distance", "(", "ll2", "LatLng", ")", "s1", ".", "Angle", "{", "// Haversine formula, as used in C++ S2LatLng::GetDistance.", "lat1", ",", "lat2", ":=", "ll", ".", "Lat", ".", "Radians", "(", ")", ",", "ll2", ".", "Lat", ...
// Distance returns the angle between two LatLngs.
[ "Distance", "returns", "the", "angle", "between", "two", "LatLngs", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/latlng.go#L61-L69
train
golang/geo
r3/vector.go
IsUnit
func (v Vector) IsUnit() bool { const epsilon = 5e-14 return math.Abs(v.Norm2()-1) <= epsilon }
go
func (v Vector) IsUnit() bool { const epsilon = 5e-14 return math.Abs(v.Norm2()-1) <= epsilon }
[ "func", "(", "v", "Vector", ")", "IsUnit", "(", ")", "bool", "{", "const", "epsilon", "=", "5e-14", "\n", "return", "math", ".", "Abs", "(", "v", ".", "Norm2", "(", ")", "-", "1", ")", "<=", "epsilon", "\n", "}" ]
// IsUnit returns whether this vector is of approximately unit length.
[ "IsUnit", "returns", "whether", "this", "vector", "is", "of", "approximately", "unit", "length", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/r3/vector.go#L53-L56
train
golang/geo
r3/vector.go
Angle
func (v Vector) Angle(ov Vector) s1.Angle { return s1.Angle(math.Atan2(v.Cross(ov).Norm(), v.Dot(ov))) * s1.Radian }
go
func (v Vector) Angle(ov Vector) s1.Angle { return s1.Angle(math.Atan2(v.Cross(ov).Norm(), v.Dot(ov))) * s1.Radian }
[ "func", "(", "v", "Vector", ")", "Angle", "(", "ov", "Vector", ")", "s1", ".", "Angle", "{", "return", "s1", ".", "Angle", "(", "math", ".", "Atan2", "(", "v", ".", "Cross", "(", "ov", ")", ".", "Norm", "(", ")", ",", "v", ".", "Dot", "(", ...
// Angle returns the angle between v and ov.
[ "Angle", "returns", "the", "angle", "between", "v", "and", "ov", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/r3/vector.go#L86-L88
train
golang/geo
s2/polygon.go
compareLoops
func compareLoops(a, b *Loop) int { if na, nb := a.NumVertices(), b.NumVertices(); na != nb { return na - nb } ai, aDir := a.CanonicalFirstVertex() bi, bDir := b.CanonicalFirstVertex() if aDir != bDir { return aDir - bDir } for n := a.NumVertices() - 1; n >= 0; n, ai, bi = n-1, ai+aDir, bi+bDir { if cmp := a.Vertex(ai).Cmp(b.Vertex(bi).Vector); cmp != 0 { return cmp } } return 0 }
go
func compareLoops(a, b *Loop) int { if na, nb := a.NumVertices(), b.NumVertices(); na != nb { return na - nb } ai, aDir := a.CanonicalFirstVertex() bi, bDir := b.CanonicalFirstVertex() if aDir != bDir { return aDir - bDir } for n := a.NumVertices() - 1; n >= 0; n, ai, bi = n-1, ai+aDir, bi+bDir { if cmp := a.Vertex(ai).Cmp(b.Vertex(bi).Vector); cmp != 0 { return cmp } } return 0 }
[ "func", "compareLoops", "(", "a", ",", "b", "*", "Loop", ")", "int", "{", "if", "na", ",", "nb", ":=", "a", ".", "NumVertices", "(", ")", ",", "b", ".", "NumVertices", "(", ")", ";", "na", "!=", "nb", "{", "return", "na", "-", "nb", "\n", "}"...
// Defines a total ordering on Loops that does not depend on the cyclic // order of loop vertices. This function is used to choose which loop to // invert in the case where several loops have exactly the same area.
[ "Defines", "a", "total", "ordering", "on", "Loops", "that", "does", "not", "depend", "on", "the", "cyclic", "order", "of", "loop", "vertices", ".", "This", "function", "is", "used", "to", "choose", "which", "loop", "to", "invert", "in", "the", "case", "w...
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/polygon.go#L254-L269
train
golang/geo
s2/polygon.go
insertLoop
func (lm loopMap) insertLoop(newLoop, parent *Loop) { var children []*Loop for done := false; !done; { children = lm[parent] done = true for _, child := range children { if child.ContainsNested(newLoop) { parent = child done = false break } } } // Now, we have found a parent for this loop, it may be that some of the // children of the parent of this loop may now be children of the new loop. newChildren := lm[newLoop] for i := 0; i < len(children); { child := children[i] if newLoop.ContainsNested(child) { newChildren = append(newChildren, child) children = append(children[0:i], children[i+1:]...) } else { i++ } } lm[newLoop] = newChildren lm[parent] = append(children, newLoop) }
go
func (lm loopMap) insertLoop(newLoop, parent *Loop) { var children []*Loop for done := false; !done; { children = lm[parent] done = true for _, child := range children { if child.ContainsNested(newLoop) { parent = child done = false break } } } // Now, we have found a parent for this loop, it may be that some of the // children of the parent of this loop may now be children of the new loop. newChildren := lm[newLoop] for i := 0; i < len(children); { child := children[i] if newLoop.ContainsNested(child) { newChildren = append(newChildren, child) children = append(children[0:i], children[i+1:]...) } else { i++ } } lm[newLoop] = newChildren lm[parent] = append(children, newLoop) }
[ "func", "(", "lm", "loopMap", ")", "insertLoop", "(", "newLoop", ",", "parent", "*", "Loop", ")", "{", "var", "children", "[", "]", "*", "Loop", "\n", "for", "done", ":=", "false", ";", "!", "done", ";", "{", "children", "=", "lm", "[", "parent", ...
// insertLoop adds the given loop to the loop map under the specified parent. // All children of the new entry are checked to see if the need to move up to // a different level.
[ "insertLoop", "adds", "the", "given", "loop", "to", "the", "loop", "map", "under", "the", "specified", "parent", ".", "All", "children", "of", "the", "new", "entry", "are", "checked", "to", "see", "if", "the", "need", "to", "move", "up", "to", "a", "di...
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/polygon.go#L305-L334
train
golang/geo
s2/polygon.go
initLoops
func (p *Polygon) initLoops(lm loopMap) { var stack loopStack stack.push(nil) depth := -1 for len(stack) > 0 { loop := stack.pop() if loop != nil { depth = loop.depth p.loops = append(p.loops, loop) } children := lm[loop] for i := len(children) - 1; i >= 0; i-- { child := children[i] child.depth = depth + 1 stack.push(child) } } }
go
func (p *Polygon) initLoops(lm loopMap) { var stack loopStack stack.push(nil) depth := -1 for len(stack) > 0 { loop := stack.pop() if loop != nil { depth = loop.depth p.loops = append(p.loops, loop) } children := lm[loop] for i := len(children) - 1; i >= 0; i-- { child := children[i] child.depth = depth + 1 stack.push(child) } } }
[ "func", "(", "p", "*", "Polygon", ")", "initLoops", "(", "lm", "loopMap", ")", "{", "var", "stack", "loopStack", "\n", "stack", ".", "push", "(", "nil", ")", "\n", "depth", ":=", "-", "1", "\n\n", "for", "len", "(", "stack", ")", ">", "0", "{", ...
// initLoops walks the mapping of loops to all of their children, and adds them in // order into to the polygons set of loops.
[ "initLoops", "walks", "the", "mapping", "of", "loops", "to", "all", "of", "their", "children", "and", "adds", "them", "in", "order", "into", "to", "the", "polygons", "set", "of", "loops", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/polygon.go#L351-L369
train
golang/geo
s2/polygon.go
initLoopProperties
func (p *Polygon) initLoopProperties() { // the loops depths are set by initNested/initOriented prior to this. p.hasHoles = false for _, l := range p.loops { if l.IsHole() { p.hasHoles = true } else { p.bound = p.bound.Union(l.RectBound()) } p.numVertices += l.NumVertices() } p.subregionBound = ExpandForSubregions(p.bound) p.initEdgesAndIndex() }
go
func (p *Polygon) initLoopProperties() { // the loops depths are set by initNested/initOriented prior to this. p.hasHoles = false for _, l := range p.loops { if l.IsHole() { p.hasHoles = true } else { p.bound = p.bound.Union(l.RectBound()) } p.numVertices += l.NumVertices() } p.subregionBound = ExpandForSubregions(p.bound) p.initEdgesAndIndex() }
[ "func", "(", "p", "*", "Polygon", ")", "initLoopProperties", "(", ")", "{", "// the loops depths are set by initNested/initOriented prior to this.", "p", ".", "hasHoles", "=", "false", "\n", "for", "_", ",", "l", ":=", "range", "p", ".", "loops", "{", "if", "l...
// initLoopProperties sets the properties for polygons with multiple loops.
[ "initLoopProperties", "sets", "the", "properties", "for", "polygons", "with", "multiple", "loops", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/polygon.go#L385-L400
train