id
int32
0
167k
repo
stringlengths
5
54
path
stringlengths
4
155
func_name
stringlengths
1
118
original_string
stringlengths
52
85.5k
language
stringclasses
1 value
code
stringlengths
52
85.5k
code_tokens
listlengths
21
1.41k
docstring
stringlengths
6
2.61k
docstring_tokens
listlengths
3
215
sha
stringlengths
40
40
url
stringlengths
85
252
11,300
vulcand/vulcand
proxy/frontend/frontend.go
AppendRTMTo
func (fe *T) AppendRTMTo(aggregate *memmetrics.RTMetrics) { fe.mu.Lock() rtmCollect := fe.rtmCollect fe.mu.Unlock() if rtmCollect == nil { return } rtmCollect.AppendFeRTMTo(aggregate) }
go
func (fe *T) AppendRTMTo(aggregate *memmetrics.RTMetrics) { fe.mu.Lock() rtmCollect := fe.rtmCollect fe.mu.Unlock() if rtmCollect == nil { return } rtmCollect.AppendFeRTMTo(aggregate) }
[ "func", "(", "fe", "*", "T", ")", "AppendRTMTo", "(", "aggregate", "*", "memmetrics", ".", "RTMetrics", ")", "{", "fe", ".", "mu", ".", "Lock", "(", ")", "\n", "rtmCollect", ":=", "fe", ".", "rtmCollect", "\n", "fe", ".", "mu", ".", "Unlock", "(", ")", "\n\n", "if", "rtmCollect", "==", "nil", "{", "return", "\n", "}", "\n", "rtmCollect", ".", "AppendFeRTMTo", "(", "aggregate", ")", "\n", "}" ]
// AppendRTMTo appends frontend round-trip metrics to an aggregate.
[ "AppendRTMTo", "appends", "frontend", "round", "-", "trip", "metrics", "to", "an", "aggregate", "." ]
5fb2302c78e2db24de076c2b2c6276bf6f48ebf0
https://github.com/vulcand/vulcand/blob/5fb2302c78e2db24de076c2b2c6276bf6f48ebf0/proxy/frontend/frontend.go#L155-L164
11,301
vulcand/vulcand
proxy/frontend/frontend.go
syncServers
func syncServers(balancer *roundrobin.Rebalancer, beSrvs []backend.Srv, watcher *rtmcollect.T) { // First, collect and parse servers to add newServers := make(map[backend.SrvURLKey]backend.Srv) for _, newBeSrv := range beSrvs { newServers[newBeSrv.URLKey()] = newBeSrv } // Memorize what endpoints exist in load balancer at the moment oldServers := make(map[backend.SrvURLKey]*url.URL) for _, oldBeSrvURL := range balancer.Servers() { oldServers[backend.NewSrvURLKey(oldBeSrvURL)] = oldBeSrvURL } // First, add endpoints, that should be added and are not in lb for newBeSrvURLKey, newBeSrv := range newServers { if _, ok := oldServers[newBeSrvURLKey]; !ok { if err := balancer.UpsertServer(newBeSrv.URL()); err != nil { log.Errorf("Failed to add %v, err: %s", newBeSrv.URL(), err) } watcher.UpsertServer(newBeSrv) } } // Second, remove endpoints that should not be there any more for oldBeSrvURLKey, oldBeSrvURL := range oldServers { if _, ok := newServers[oldBeSrvURLKey]; !ok { if err := balancer.RemoveServer(oldBeSrvURL); err != nil { log.Errorf("Failed to remove %v, err: %v", oldBeSrvURL, err) } watcher.RemoveServer(oldBeSrvURLKey) } } }
go
func syncServers(balancer *roundrobin.Rebalancer, beSrvs []backend.Srv, watcher *rtmcollect.T) { // First, collect and parse servers to add newServers := make(map[backend.SrvURLKey]backend.Srv) for _, newBeSrv := range beSrvs { newServers[newBeSrv.URLKey()] = newBeSrv } // Memorize what endpoints exist in load balancer at the moment oldServers := make(map[backend.SrvURLKey]*url.URL) for _, oldBeSrvURL := range balancer.Servers() { oldServers[backend.NewSrvURLKey(oldBeSrvURL)] = oldBeSrvURL } // First, add endpoints, that should be added and are not in lb for newBeSrvURLKey, newBeSrv := range newServers { if _, ok := oldServers[newBeSrvURLKey]; !ok { if err := balancer.UpsertServer(newBeSrv.URL()); err != nil { log.Errorf("Failed to add %v, err: %s", newBeSrv.URL(), err) } watcher.UpsertServer(newBeSrv) } } // Second, remove endpoints that should not be there any more for oldBeSrvURLKey, oldBeSrvURL := range oldServers { if _, ok := newServers[oldBeSrvURLKey]; !ok { if err := balancer.RemoveServer(oldBeSrvURL); err != nil { log.Errorf("Failed to remove %v, err: %v", oldBeSrvURL, err) } watcher.RemoveServer(oldBeSrvURLKey) } } }
[ "func", "syncServers", "(", "balancer", "*", "roundrobin", ".", "Rebalancer", ",", "beSrvs", "[", "]", "backend", ".", "Srv", ",", "watcher", "*", "rtmcollect", ".", "T", ")", "{", "// First, collect and parse servers to add", "newServers", ":=", "make", "(", "map", "[", "backend", ".", "SrvURLKey", "]", "backend", ".", "Srv", ")", "\n", "for", "_", ",", "newBeSrv", ":=", "range", "beSrvs", "{", "newServers", "[", "newBeSrv", ".", "URLKey", "(", ")", "]", "=", "newBeSrv", "\n", "}", "\n\n", "// Memorize what endpoints exist in load balancer at the moment", "oldServers", ":=", "make", "(", "map", "[", "backend", ".", "SrvURLKey", "]", "*", "url", ".", "URL", ")", "\n", "for", "_", ",", "oldBeSrvURL", ":=", "range", "balancer", ".", "Servers", "(", ")", "{", "oldServers", "[", "backend", ".", "NewSrvURLKey", "(", "oldBeSrvURL", ")", "]", "=", "oldBeSrvURL", "\n", "}", "\n\n", "// First, add endpoints, that should be added and are not in lb", "for", "newBeSrvURLKey", ",", "newBeSrv", ":=", "range", "newServers", "{", "if", "_", ",", "ok", ":=", "oldServers", "[", "newBeSrvURLKey", "]", ";", "!", "ok", "{", "if", "err", ":=", "balancer", ".", "UpsertServer", "(", "newBeSrv", ".", "URL", "(", ")", ")", ";", "err", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "newBeSrv", ".", "URL", "(", ")", ",", "err", ")", "\n", "}", "\n", "watcher", ".", "UpsertServer", "(", "newBeSrv", ")", "\n", "}", "\n", "}", "\n\n", "// Second, remove endpoints that should not be there any more", "for", "oldBeSrvURLKey", ",", "oldBeSrvURL", ":=", "range", "oldServers", "{", "if", "_", ",", "ok", ":=", "newServers", "[", "oldBeSrvURLKey", "]", ";", "!", "ok", "{", "if", "err", ":=", "balancer", ".", "RemoveServer", "(", "oldBeSrvURL", ")", ";", "err", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "oldBeSrvURL", ",", "err", ")", "\n", "}", "\n", "watcher", ".", "RemoveServer", "(", "oldBeSrvURLKey", ")", "\n", "}", "\n", "}", "\n", "}" ]
// syncServers syncs backend servers and rebalancer state.
[ "syncServers", "syncs", "backend", "servers", "and", "rebalancer", "state", "." ]
5fb2302c78e2db24de076c2b2c6276bf6f48ebf0
https://github.com/vulcand/vulcand/blob/5fb2302c78e2db24de076c2b2c6276bf6f48ebf0/proxy/frontend/frontend.go#L308-L340
11,302
vulcand/vulcand
proxy/connctr/connctr.go
New
func New() *T { return &T{ new: make(map[string]int64), active: make(map[string]int64), idle: make(map[string]int64), } }
go
func New() *T { return &T{ new: make(map[string]int64), active: make(map[string]int64), idle: make(map[string]int64), } }
[ "func", "New", "(", ")", "*", "T", "{", "return", "&", "T", "{", "new", ":", "make", "(", "map", "[", "string", "]", "int64", ")", ",", "active", ":", "make", "(", "map", "[", "string", "]", "int64", ")", ",", "idle", ":", "make", "(", "map", "[", "string", "]", "int64", ")", ",", "}", "\n", "}" ]
// New returns a new connection counter instance
[ "New", "returns", "a", "new", "connection", "counter", "instance" ]
5fb2302c78e2db24de076c2b2c6276bf6f48ebf0
https://github.com/vulcand/vulcand/blob/5fb2302c78e2db24de076c2b2c6276bf6f48ebf0/proxy/connctr/connctr.go#L21-L27
11,303
vulcand/vulcand
proxy/connctr/connctr.go
RegisterStateChange
func (c *T) RegisterStateChange(conn net.Conn, prev http.ConnState, cur http.ConnState) { c.mu.Lock() defer c.mu.Unlock() if cur == http.StateNew || cur == http.StateIdle || cur == http.StateActive { c.inc(conn, cur, 1) } if cur != http.StateNew { c.inc(conn, prev, -1) } }
go
func (c *T) RegisterStateChange(conn net.Conn, prev http.ConnState, cur http.ConnState) { c.mu.Lock() defer c.mu.Unlock() if cur == http.StateNew || cur == http.StateIdle || cur == http.StateActive { c.inc(conn, cur, 1) } if cur != http.StateNew { c.inc(conn, prev, -1) } }
[ "func", "(", "c", "*", "T", ")", "RegisterStateChange", "(", "conn", "net", ".", "Conn", ",", "prev", "http", ".", "ConnState", ",", "cur", "http", ".", "ConnState", ")", "{", "c", ".", "mu", ".", "Lock", "(", ")", "\n", "defer", "c", ".", "mu", ".", "Unlock", "(", ")", "\n\n", "if", "cur", "==", "http", ".", "StateNew", "||", "cur", "==", "http", ".", "StateIdle", "||", "cur", "==", "http", ".", "StateActive", "{", "c", ".", "inc", "(", "conn", ",", "cur", ",", "1", ")", "\n", "}", "\n\n", "if", "cur", "!=", "http", ".", "StateNew", "{", "c", ".", "inc", "(", "conn", ",", "prev", ",", "-", "1", ")", "\n", "}", "\n", "}" ]
// RegisterStateChange implements conntracker.ConnectionTracker.
[ "RegisterStateChange", "implements", "conntracker", ".", "ConnectionTracker", "." ]
5fb2302c78e2db24de076c2b2c6276bf6f48ebf0
https://github.com/vulcand/vulcand/blob/5fb2302c78e2db24de076c2b2c6276bf6f48ebf0/proxy/connctr/connctr.go#L30-L41
11,304
vulcand/vulcand
proxy/connctr/connctr.go
Counts
func (c *T) Counts() conntracker.ConnectionStats { c.mu.Lock() defer c.mu.Unlock() return conntracker.ConnectionStats{ http.StateNew: c.copy(c.new), http.StateActive: c.copy(c.active), http.StateIdle: c.copy(c.idle), } }
go
func (c *T) Counts() conntracker.ConnectionStats { c.mu.Lock() defer c.mu.Unlock() return conntracker.ConnectionStats{ http.StateNew: c.copy(c.new), http.StateActive: c.copy(c.active), http.StateIdle: c.copy(c.idle), } }
[ "func", "(", "c", "*", "T", ")", "Counts", "(", ")", "conntracker", ".", "ConnectionStats", "{", "c", ".", "mu", ".", "Lock", "(", ")", "\n", "defer", "c", ".", "mu", ".", "Unlock", "(", ")", "\n\n", "return", "conntracker", ".", "ConnectionStats", "{", "http", ".", "StateNew", ":", "c", ".", "copy", "(", "c", ".", "new", ")", ",", "http", ".", "StateActive", ":", "c", ".", "copy", "(", "c", ".", "active", ")", ",", "http", ".", "StateIdle", ":", "c", ".", "copy", "(", "c", ".", "idle", ")", ",", "}", "\n", "}" ]
// Counts implements conntracker.ConnectionTracker.
[ "Counts", "implements", "conntracker", ".", "ConnectionTracker", "." ]
5fb2302c78e2db24de076c2b2c6276bf6f48ebf0
https://github.com/vulcand/vulcand/blob/5fb2302c78e2db24de076c2b2c6276bf6f48ebf0/proxy/connctr/connctr.go#L44-L53
11,305
vulcand/vulcand
proxy/server/server.go
New
func New(lsnCfg engine.Listener, router http.Handler, stapler stapler.Stapler, connTck conntracker.ConnectionTracker, autoCertCache autocert.Cache, wg *sync.WaitGroup, ) (*T, error) { scopedRouter, err := newScopeRouter(lsnCfg.Scope, router) if err != nil { return nil, err } return &T{ lsnCfg: lsnCfg, router: router, stapler: stapler, connTck: connTck, autoCertCache: autoCertCache, serveWg: wg, scopedRouter: scopedRouter, state: srvStateInit, }, nil }
go
func New(lsnCfg engine.Listener, router http.Handler, stapler stapler.Stapler, connTck conntracker.ConnectionTracker, autoCertCache autocert.Cache, wg *sync.WaitGroup, ) (*T, error) { scopedRouter, err := newScopeRouter(lsnCfg.Scope, router) if err != nil { return nil, err } return &T{ lsnCfg: lsnCfg, router: router, stapler: stapler, connTck: connTck, autoCertCache: autoCertCache, serveWg: wg, scopedRouter: scopedRouter, state: srvStateInit, }, nil }
[ "func", "New", "(", "lsnCfg", "engine", ".", "Listener", ",", "router", "http", ".", "Handler", ",", "stapler", "stapler", ".", "Stapler", ",", "connTck", "conntracker", ".", "ConnectionTracker", ",", "autoCertCache", "autocert", ".", "Cache", ",", "wg", "*", "sync", ".", "WaitGroup", ",", ")", "(", "*", "T", ",", "error", ")", "{", "scopedRouter", ",", "err", ":=", "newScopeRouter", "(", "lsnCfg", ".", "Scope", ",", "router", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "&", "T", "{", "lsnCfg", ":", "lsnCfg", ",", "router", ":", "router", ",", "stapler", ":", "stapler", ",", "connTck", ":", "connTck", ",", "autoCertCache", ":", "autoCertCache", ",", "serveWg", ":", "wg", ",", "scopedRouter", ":", "scopedRouter", ",", "state", ":", "srvStateInit", ",", "}", ",", "nil", "\n", "}" ]
// New creates a new server instance.
[ "New", "creates", "a", "new", "server", "instance", "." ]
5fb2302c78e2db24de076c2b2c6276bf6f48ebf0
https://github.com/vulcand/vulcand/blob/5fb2302c78e2db24de076c2b2c6276bf6f48ebf0/proxy/server/server.go#L46-L64
11,306
vulcand/vulcand
proxy/server/server.go
Start
func (s *T) Start(hostCfgs map[engine.HostKey]engine.Host) error { log.Infof("%s start", s) switch s.state { case srvStateInit: lsn, err := net.Listen(s.lsnCfg.Address.Network, s.lsnCfg.Address.Address) if err != nil { return err } lsn = &graceful.TCPKeepAliveListener{TCPListener: lsn.(*net.TCPListener)} if s.isProxyProto() { lsn = &proxyproto.Listener{ Listener: lsn, ProxyHeaderTimeout: s.options.ReadTimeout, } } if s.isTLS() { config, err := s.newTLSCfg(hostCfgs) if err != nil { return err } lsn = graceful.NewTLSListener(lsn, config) } s.srv = graceful.NewWithOptions( graceful.Options{ Server: s.newHTTPServer(), Listener: lsn, StateHandler: s.connTck.RegisterStateChange, }) s.state = srvStateActive s.serveWg.Add(1) go s.serve(s.srv) return nil case srvStateHijacked: s.state = srvStateActive s.serveWg.Add(1) go s.serve(s.srv) return nil } return errors.Errorf("%v Calling start in unsupported state", s) }
go
func (s *T) Start(hostCfgs map[engine.HostKey]engine.Host) error { log.Infof("%s start", s) switch s.state { case srvStateInit: lsn, err := net.Listen(s.lsnCfg.Address.Network, s.lsnCfg.Address.Address) if err != nil { return err } lsn = &graceful.TCPKeepAliveListener{TCPListener: lsn.(*net.TCPListener)} if s.isProxyProto() { lsn = &proxyproto.Listener{ Listener: lsn, ProxyHeaderTimeout: s.options.ReadTimeout, } } if s.isTLS() { config, err := s.newTLSCfg(hostCfgs) if err != nil { return err } lsn = graceful.NewTLSListener(lsn, config) } s.srv = graceful.NewWithOptions( graceful.Options{ Server: s.newHTTPServer(), Listener: lsn, StateHandler: s.connTck.RegisterStateChange, }) s.state = srvStateActive s.serveWg.Add(1) go s.serve(s.srv) return nil case srvStateHijacked: s.state = srvStateActive s.serveWg.Add(1) go s.serve(s.srv) return nil } return errors.Errorf("%v Calling start in unsupported state", s) }
[ "func", "(", "s", "*", "T", ")", "Start", "(", "hostCfgs", "map", "[", "engine", ".", "HostKey", "]", "engine", ".", "Host", ")", "error", "{", "log", ".", "Infof", "(", "\"", "\"", ",", "s", ")", "\n", "switch", "s", ".", "state", "{", "case", "srvStateInit", ":", "lsn", ",", "err", ":=", "net", ".", "Listen", "(", "s", ".", "lsnCfg", ".", "Address", ".", "Network", ",", "s", ".", "lsnCfg", ".", "Address", ".", "Address", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "lsn", "=", "&", "graceful", ".", "TCPKeepAliveListener", "{", "TCPListener", ":", "lsn", ".", "(", "*", "net", ".", "TCPListener", ")", "}", "\n\n", "if", "s", ".", "isProxyProto", "(", ")", "{", "lsn", "=", "&", "proxyproto", ".", "Listener", "{", "Listener", ":", "lsn", ",", "ProxyHeaderTimeout", ":", "s", ".", "options", ".", "ReadTimeout", ",", "}", "\n", "}", "\n\n", "if", "s", ".", "isTLS", "(", ")", "{", "config", ",", "err", ":=", "s", ".", "newTLSCfg", "(", "hostCfgs", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "lsn", "=", "graceful", ".", "NewTLSListener", "(", "lsn", ",", "config", ")", "\n", "}", "\n", "s", ".", "srv", "=", "graceful", ".", "NewWithOptions", "(", "graceful", ".", "Options", "{", "Server", ":", "s", ".", "newHTTPServer", "(", ")", ",", "Listener", ":", "lsn", ",", "StateHandler", ":", "s", ".", "connTck", ".", "RegisterStateChange", ",", "}", ")", "\n", "s", ".", "state", "=", "srvStateActive", "\n", "s", ".", "serveWg", ".", "Add", "(", "1", ")", "\n", "go", "s", ".", "serve", "(", "s", ".", "srv", ")", "\n", "return", "nil", "\n", "case", "srvStateHijacked", ":", "s", ".", "state", "=", "srvStateActive", "\n", "s", ".", "serveWg", ".", "Add", "(", "1", ")", "\n", "go", "s", ".", "serve", "(", "s", ".", "srv", ")", "\n", "return", "nil", "\n", "}", "\n", "return", "errors", ".", "Errorf", "(", "\"", "\"", ",", "s", ")", "\n", "}" ]
// Start starts the server to handle a list of specified hosts.
[ "Start", "starts", "the", "server", "to", "handle", "a", "list", "of", "specified", "hosts", "." ]
5fb2302c78e2db24de076c2b2c6276bf6f48ebf0
https://github.com/vulcand/vulcand/blob/5fb2302c78e2db24de076c2b2c6276bf6f48ebf0/proxy/server/server.go#L93-L135
11,307
vulcand/vulcand
proxy/server/server.go
OnHostsUpdated
func (s *T) OnHostsUpdated(hostCfgs map[engine.HostKey]engine.Host) { if !s.isTLS() { return } if err := s.reloadTLSCfg(hostCfgs); err != nil { log.Errorf("Failed to reload TLS config: %v", err) } }
go
func (s *T) OnHostsUpdated(hostCfgs map[engine.HostKey]engine.Host) { if !s.isTLS() { return } if err := s.reloadTLSCfg(hostCfgs); err != nil { log.Errorf("Failed to reload TLS config: %v", err) } }
[ "func", "(", "s", "*", "T", ")", "OnHostsUpdated", "(", "hostCfgs", "map", "[", "engine", ".", "HostKey", "]", "engine", ".", "Host", ")", "{", "if", "!", "s", ".", "isTLS", "(", ")", "{", "return", "\n", "}", "\n", "if", "err", ":=", "s", ".", "reloadTLSCfg", "(", "hostCfgs", ")", ";", "err", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "}" ]
// OnHostsUpdated is supposed to be called whenever a list of hosts is updated, // or an OCSP notification for a host is received.
[ "OnHostsUpdated", "is", "supposed", "to", "be", "called", "whenever", "a", "list", "of", "hosts", "is", "updated", "or", "an", "OCSP", "notification", "for", "a", "host", "is", "received", "." ]
5fb2302c78e2db24de076c2b2c6276bf6f48ebf0
https://github.com/vulcand/vulcand/blob/5fb2302c78e2db24de076c2b2c6276bf6f48ebf0/proxy/server/server.go#L207-L214
11,308
vulcand/vulcand
proxy/server/server.go
certFuncForHost
func certFuncForHost(hostCfg engine.Host, autoCertCache autocert.Cache, s stapler.Stapler) (getCertificateFunc, error) { ac := hostCfg.Settings.AutoCert // Each host gets its own Autocert Manager - this allows individual // certs to use different autocert authorities, as well as auth keys autoCertMgr := &autocert.Manager{ Prompt: autocert.AcceptTOS, Cache: autoCertCache, HostPolicy: autocert.HostWhitelist(hostCfg.Name), Email: ac.Email, } if ac.RenewBefore > 0 { autoCertMgr.RenewBefore = ac.RenewBefore } // if either directory or key are non-empty, we need to generate // a custom ACME client to override either. if ac.Key != "" || ac.DirectoryURL != "" { // If DirectoryURL is empty, the default Let's Encrypt URL will be picked. autoCertMgr.Client = &acme.Client{ DirectoryURL: ac.DirectoryURL, } // If Key is non-empty, then decode it as RSA or EC which are the only two keys // we support. Go's crypto library doesn't support a generic function to provide back // a private key interface. if ac.Key != "" { block, _ := pem.Decode([]byte(ac.Key)) if block == nil { return nil, fmt.Errorf("Autocert Key PEM Block for Host %s is invalid.", hostCfg.Name) } else if block.Type == "RSA PRIVATE KEY" { rsaPrivateKey, err := x509.ParsePKCS1PrivateKey(block.Bytes) if err != nil { return nil, errors.Wrapf(err, "Error parsing Autocert Key block of type %s, for Host %s, as an RSA Private Key.", block.Type, hostCfg.Name) } autoCertMgr.Client.Key = rsaPrivateKey } else if block.Type == "EC PRIVATE KEY" { ecPrivateKey, err := x509.ParseECPrivateKey(block.Bytes) if err != nil { return nil, errors.Wrapf(err, "Error parsing Autocert Key block of type %s, for Host %s, as an ECDSA Private Key.", block.Type, hostCfg.Name) } autoCertMgr.Client.Key = ecPrivateKey } else { return nil, fmt.Errorf("AutoCert Private Key for Host %s is of unrecognized type: %s. Supported types"+ "are RSA PRIVATE KEY and EC PRIVATE KEY.", hostCfg.Name, block.Type) } } } getCertFuncForStapling := stapler.WithGetCertFunc(hostCfg.Name, stapler.GetCertificateFunc(autoCertMgr.GetCertificate)) // Wrap the GetCert for this host, so we can generate and staple // an optional OCSP response when requested. stapledGetCert := func(info *tls.ClientHelloInfo) (*tls.Certificate, error) { keyPair, err := autoCertMgr.GetCertificate(info) ocspStapleToCert(s, hostCfg, keyPair, getCertFuncForStapling) return keyPair, err } return stapledGetCert, nil }
go
func certFuncForHost(hostCfg engine.Host, autoCertCache autocert.Cache, s stapler.Stapler) (getCertificateFunc, error) { ac := hostCfg.Settings.AutoCert // Each host gets its own Autocert Manager - this allows individual // certs to use different autocert authorities, as well as auth keys autoCertMgr := &autocert.Manager{ Prompt: autocert.AcceptTOS, Cache: autoCertCache, HostPolicy: autocert.HostWhitelist(hostCfg.Name), Email: ac.Email, } if ac.RenewBefore > 0 { autoCertMgr.RenewBefore = ac.RenewBefore } // if either directory or key are non-empty, we need to generate // a custom ACME client to override either. if ac.Key != "" || ac.DirectoryURL != "" { // If DirectoryURL is empty, the default Let's Encrypt URL will be picked. autoCertMgr.Client = &acme.Client{ DirectoryURL: ac.DirectoryURL, } // If Key is non-empty, then decode it as RSA or EC which are the only two keys // we support. Go's crypto library doesn't support a generic function to provide back // a private key interface. if ac.Key != "" { block, _ := pem.Decode([]byte(ac.Key)) if block == nil { return nil, fmt.Errorf("Autocert Key PEM Block for Host %s is invalid.", hostCfg.Name) } else if block.Type == "RSA PRIVATE KEY" { rsaPrivateKey, err := x509.ParsePKCS1PrivateKey(block.Bytes) if err != nil { return nil, errors.Wrapf(err, "Error parsing Autocert Key block of type %s, for Host %s, as an RSA Private Key.", block.Type, hostCfg.Name) } autoCertMgr.Client.Key = rsaPrivateKey } else if block.Type == "EC PRIVATE KEY" { ecPrivateKey, err := x509.ParseECPrivateKey(block.Bytes) if err != nil { return nil, errors.Wrapf(err, "Error parsing Autocert Key block of type %s, for Host %s, as an ECDSA Private Key.", block.Type, hostCfg.Name) } autoCertMgr.Client.Key = ecPrivateKey } else { return nil, fmt.Errorf("AutoCert Private Key for Host %s is of unrecognized type: %s. Supported types"+ "are RSA PRIVATE KEY and EC PRIVATE KEY.", hostCfg.Name, block.Type) } } } getCertFuncForStapling := stapler.WithGetCertFunc(hostCfg.Name, stapler.GetCertificateFunc(autoCertMgr.GetCertificate)) // Wrap the GetCert for this host, so we can generate and staple // an optional OCSP response when requested. stapledGetCert := func(info *tls.ClientHelloInfo) (*tls.Certificate, error) { keyPair, err := autoCertMgr.GetCertificate(info) ocspStapleToCert(s, hostCfg, keyPair, getCertFuncForStapling) return keyPair, err } return stapledGetCert, nil }
[ "func", "certFuncForHost", "(", "hostCfg", "engine", ".", "Host", ",", "autoCertCache", "autocert", ".", "Cache", ",", "s", "stapler", ".", "Stapler", ")", "(", "getCertificateFunc", ",", "error", ")", "{", "ac", ":=", "hostCfg", ".", "Settings", ".", "AutoCert", "\n\n", "// Each host gets its own Autocert Manager - this allows individual", "// certs to use different autocert authorities, as well as auth keys", "autoCertMgr", ":=", "&", "autocert", ".", "Manager", "{", "Prompt", ":", "autocert", ".", "AcceptTOS", ",", "Cache", ":", "autoCertCache", ",", "HostPolicy", ":", "autocert", ".", "HostWhitelist", "(", "hostCfg", ".", "Name", ")", ",", "Email", ":", "ac", ".", "Email", ",", "}", "\n\n", "if", "ac", ".", "RenewBefore", ">", "0", "{", "autoCertMgr", ".", "RenewBefore", "=", "ac", ".", "RenewBefore", "\n", "}", "\n\n", "// if either directory or key are non-empty, we need to generate", "// a custom ACME client to override either.", "if", "ac", ".", "Key", "!=", "\"", "\"", "||", "ac", ".", "DirectoryURL", "!=", "\"", "\"", "{", "// If DirectoryURL is empty, the default Let's Encrypt URL will be picked.", "autoCertMgr", ".", "Client", "=", "&", "acme", ".", "Client", "{", "DirectoryURL", ":", "ac", ".", "DirectoryURL", ",", "}", "\n\n", "// If Key is non-empty, then decode it as RSA or EC which are the only two keys", "// we support. Go's crypto library doesn't support a generic function to provide back", "// a private key interface.", "if", "ac", ".", "Key", "!=", "\"", "\"", "{", "block", ",", "_", ":=", "pem", ".", "Decode", "(", "[", "]", "byte", "(", "ac", ".", "Key", ")", ")", "\n", "if", "block", "==", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "hostCfg", ".", "Name", ")", "\n", "}", "else", "if", "block", ".", "Type", "==", "\"", "\"", "{", "rsaPrivateKey", ",", "err", ":=", "x509", ".", "ParsePKCS1PrivateKey", "(", "block", ".", "Bytes", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Wrapf", "(", "err", ",", "\"", "\"", ",", "block", ".", "Type", ",", "hostCfg", ".", "Name", ")", "\n", "}", "\n", "autoCertMgr", ".", "Client", ".", "Key", "=", "rsaPrivateKey", "\n", "}", "else", "if", "block", ".", "Type", "==", "\"", "\"", "{", "ecPrivateKey", ",", "err", ":=", "x509", ".", "ParseECPrivateKey", "(", "block", ".", "Bytes", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Wrapf", "(", "err", ",", "\"", "\"", ",", "block", ".", "Type", ",", "hostCfg", ".", "Name", ")", "\n", "}", "\n", "autoCertMgr", ".", "Client", ".", "Key", "=", "ecPrivateKey", "\n", "}", "else", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", "+", "\"", "\"", ",", "hostCfg", ".", "Name", ",", "block", ".", "Type", ")", "\n", "}", "\n", "}", "\n", "}", "\n\n", "getCertFuncForStapling", ":=", "stapler", ".", "WithGetCertFunc", "(", "hostCfg", ".", "Name", ",", "stapler", ".", "GetCertificateFunc", "(", "autoCertMgr", ".", "GetCertificate", ")", ")", "\n\n", "// Wrap the GetCert for this host, so we can generate and staple", "// an optional OCSP response when requested.", "stapledGetCert", ":=", "func", "(", "info", "*", "tls", ".", "ClientHelloInfo", ")", "(", "*", "tls", ".", "Certificate", ",", "error", ")", "{", "keyPair", ",", "err", ":=", "autoCertMgr", ".", "GetCertificate", "(", "info", ")", "\n", "ocspStapleToCert", "(", "s", ",", "hostCfg", ",", "keyPair", ",", "getCertFuncForStapling", ")", "\n", "return", "keyPair", ",", "err", "\n", "}", "\n\n", "return", "stapledGetCert", ",", "nil", "\n", "}" ]
// Returns a GetCertificate function for this host based on AutoCert settings, // by generating an autocert manager for the host. // It optionally will staple the OCSP response to the cert when it is generated, // if OCSP stapling is enabled for the host.
[ "Returns", "a", "GetCertificate", "function", "for", "this", "host", "based", "on", "AutoCert", "settings", "by", "generating", "an", "autocert", "manager", "for", "the", "host", ".", "It", "optionally", "will", "staple", "the", "OCSP", "response", "to", "the", "cert", "when", "it", "is", "generated", "if", "OCSP", "stapling", "is", "enabled", "for", "the", "host", "." ]
5fb2302c78e2db24de076c2b2c6276bf6f48ebf0
https://github.com/vulcand/vulcand/blob/5fb2302c78e2db24de076c2b2c6276bf6f48ebf0/proxy/server/server.go#L385-L447
11,309
vulcand/vulcand
proxy/server/server.go
certForHost
func certForHost(hostCfg engine.Host) (tls.Certificate, error) { c := hostCfg.Settings.KeyPair cert, err := tls.X509KeyPair(c.Cert, c.Key) if err != nil { return tls.Certificate{}, err } return cert, nil }
go
func certForHost(hostCfg engine.Host) (tls.Certificate, error) { c := hostCfg.Settings.KeyPair cert, err := tls.X509KeyPair(c.Cert, c.Key) if err != nil { return tls.Certificate{}, err } return cert, nil }
[ "func", "certForHost", "(", "hostCfg", "engine", ".", "Host", ")", "(", "tls", ".", "Certificate", ",", "error", ")", "{", "c", ":=", "hostCfg", ".", "Settings", ".", "KeyPair", "\n", "cert", ",", "err", ":=", "tls", ".", "X509KeyPair", "(", "c", ".", "Cert", ",", "c", ".", "Key", ")", "\n", "if", "err", "!=", "nil", "{", "return", "tls", ".", "Certificate", "{", "}", ",", "err", "\n", "}", "\n", "return", "cert", ",", "nil", "\n", "}" ]
// Returns a certificate based on a hosts KeyPair settings.
[ "Returns", "a", "certificate", "based", "on", "a", "hosts", "KeyPair", "settings", "." ]
5fb2302c78e2db24de076c2b2c6276bf6f48ebf0
https://github.com/vulcand/vulcand/blob/5fb2302c78e2db24de076c2b2c6276bf6f48ebf0/proxy/server/server.go#L510-L517
11,310
vulcand/vulcand
vctl/command/command.go
findVulcanUrl
func findVulcanUrl(args []string) (string, []string, error) { for i, arg := range args { if strings.HasPrefix(arg, "--vulcan=") || strings.HasPrefix(arg, "-vulcan=") { out := strings.Split(arg, "=") return out[1], cut(i, i+1, args), nil } else if strings.HasPrefix(arg, "-vulcan") || strings.HasPrefix(arg, "--vulcan") { // This argument should not be the last one if i > len(args)-2 { return "", nil, fmt.Errorf("provide a valid vulcan URL") } return args[i+1], cut(i, i+2, args), nil } } return "http://localhost:8182", args, nil }
go
func findVulcanUrl(args []string) (string, []string, error) { for i, arg := range args { if strings.HasPrefix(arg, "--vulcan=") || strings.HasPrefix(arg, "-vulcan=") { out := strings.Split(arg, "=") return out[1], cut(i, i+1, args), nil } else if strings.HasPrefix(arg, "-vulcan") || strings.HasPrefix(arg, "--vulcan") { // This argument should not be the last one if i > len(args)-2 { return "", nil, fmt.Errorf("provide a valid vulcan URL") } return args[i+1], cut(i, i+2, args), nil } } return "http://localhost:8182", args, nil }
[ "func", "findVulcanUrl", "(", "args", "[", "]", "string", ")", "(", "string", ",", "[", "]", "string", ",", "error", ")", "{", "for", "i", ",", "arg", ":=", "range", "args", "{", "if", "strings", ".", "HasPrefix", "(", "arg", ",", "\"", "\"", ")", "||", "strings", ".", "HasPrefix", "(", "arg", ",", "\"", "\"", ")", "{", "out", ":=", "strings", ".", "Split", "(", "arg", ",", "\"", "\"", ")", "\n", "return", "out", "[", "1", "]", ",", "cut", "(", "i", ",", "i", "+", "1", ",", "args", ")", ",", "nil", "\n", "}", "else", "if", "strings", ".", "HasPrefix", "(", "arg", ",", "\"", "\"", ")", "||", "strings", ".", "HasPrefix", "(", "arg", ",", "\"", "\"", ")", "{", "// This argument should not be the last one", "if", "i", ">", "len", "(", "args", ")", "-", "2", "{", "return", "\"", "\"", ",", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n", "return", "args", "[", "i", "+", "1", "]", ",", "cut", "(", "i", ",", "i", "+", "2", ",", "args", ")", ",", "nil", "\n", "}", "\n", "}", "\n", "return", "\"", "\"", ",", "args", ",", "nil", "\n", "}" ]
// This function extracts vulcan url from the command line regardless of it's position // this is a workaround, as cli libary does not support "superglobal" urls yet.
[ "This", "function", "extracts", "vulcan", "url", "from", "the", "command", "line", "regardless", "of", "it", "s", "position", "this", "is", "a", "workaround", "as", "cli", "libary", "does", "not", "support", "superglobal", "urls", "yet", "." ]
5fb2302c78e2db24de076c2b2c6276bf6f48ebf0
https://github.com/vulcand/vulcand/blob/5fb2302c78e2db24de076c2b2c6276bf6f48ebf0/vctl/command/command.go#L60-L74
11,311
vulcand/vulcand
graceful/server.go
NewWithOptions
func NewWithOptions(o Options) *Server { var listener *Listener if o.Listener != nil { g, ok := o.Listener.(*Listener) if !ok { listener = NewListener(o.Listener) } else { listener = g } } if o.Server == nil { o.Server = new(http.Server) } return &Server{ Server: o.Server, listener: listener, stateHandler: o.StateHandler, shutdown: make(chan bool), shutdownFinished: make(chan bool, 1), wg: new(sync.WaitGroup), connToProps: make(map[net.Conn]connProperties), } }
go
func NewWithOptions(o Options) *Server { var listener *Listener if o.Listener != nil { g, ok := o.Listener.(*Listener) if !ok { listener = NewListener(o.Listener) } else { listener = g } } if o.Server == nil { o.Server = new(http.Server) } return &Server{ Server: o.Server, listener: listener, stateHandler: o.StateHandler, shutdown: make(chan bool), shutdownFinished: make(chan bool, 1), wg: new(sync.WaitGroup), connToProps: make(map[net.Conn]connProperties), } }
[ "func", "NewWithOptions", "(", "o", "Options", ")", "*", "Server", "{", "var", "listener", "*", "Listener", "\n", "if", "o", ".", "Listener", "!=", "nil", "{", "g", ",", "ok", ":=", "o", ".", "Listener", ".", "(", "*", "Listener", ")", "\n", "if", "!", "ok", "{", "listener", "=", "NewListener", "(", "o", ".", "Listener", ")", "\n", "}", "else", "{", "listener", "=", "g", "\n", "}", "\n", "}", "\n", "if", "o", ".", "Server", "==", "nil", "{", "o", ".", "Server", "=", "new", "(", "http", ".", "Server", ")", "\n", "}", "\n", "return", "&", "Server", "{", "Server", ":", "o", ".", "Server", ",", "listener", ":", "listener", ",", "stateHandler", ":", "o", ".", "StateHandler", ",", "shutdown", ":", "make", "(", "chan", "bool", ")", ",", "shutdownFinished", ":", "make", "(", "chan", "bool", ",", "1", ")", ",", "wg", ":", "new", "(", "sync", ".", "WaitGroup", ")", ",", "connToProps", ":", "make", "(", "map", "[", "net", ".", "Conn", "]", "connProperties", ")", ",", "}", "\n", "}" ]
// NewWithOptions creates a GracefulServer instance with the specified options.
[ "NewWithOptions", "creates", "a", "GracefulServer", "instance", "with", "the", "specified", "options", "." ]
5fb2302c78e2db24de076c2b2c6276bf6f48ebf0
https://github.com/vulcand/vulcand/blob/5fb2302c78e2db24de076c2b2c6276bf6f48ebf0/graceful/server.go#L100-L122
11,312
vulcand/vulcand
plugin/trace/trace.go
New
func New(addr string, reqHeaders, respHeaders []string) (*Trace, error) { if _, err := newWriter(addr); err != nil { return nil, err } return &Trace{ ReqHeaders: reqHeaders, RespHeaders: respHeaders, Addr: addr, }, nil }
go
func New(addr string, reqHeaders, respHeaders []string) (*Trace, error) { if _, err := newWriter(addr); err != nil { return nil, err } return &Trace{ ReqHeaders: reqHeaders, RespHeaders: respHeaders, Addr: addr, }, nil }
[ "func", "New", "(", "addr", "string", ",", "reqHeaders", ",", "respHeaders", "[", "]", "string", ")", "(", "*", "Trace", ",", "error", ")", "{", "if", "_", ",", "err", ":=", "newWriter", "(", "addr", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "&", "Trace", "{", "ReqHeaders", ":", "reqHeaders", ",", "RespHeaders", ":", "respHeaders", ",", "Addr", ":", "addr", ",", "}", ",", "nil", "\n", "}" ]
// New returns a new Trace plugin
[ "New", "returns", "a", "new", "Trace", "plugin" ]
5fb2302c78e2db24de076c2b2c6276bf6f48ebf0
https://github.com/vulcand/vulcand/blob/5fb2302c78e2db24de076c2b2c6276bf6f48ebf0/plugin/trace/trace.go#L29-L38
11,313
vulcand/vulcand
plugin/trace/trace.go
NewHandler
func (t *Trace) NewHandler(next http.Handler) (http.Handler, error) { return newTraceHandler(next, t) }
go
func (t *Trace) NewHandler(next http.Handler) (http.Handler, error) { return newTraceHandler(next, t) }
[ "func", "(", "t", "*", "Trace", ")", "NewHandler", "(", "next", "http", ".", "Handler", ")", "(", "http", ".", "Handler", ",", "error", ")", "{", "return", "newTraceHandler", "(", "next", ",", "t", ")", "\n", "}" ]
// NewHandler creates a new http.Handler middleware
[ "NewHandler", "creates", "a", "new", "http", ".", "Handler", "middleware" ]
5fb2302c78e2db24de076c2b2c6276bf6f48ebf0
https://github.com/vulcand/vulcand/blob/5fb2302c78e2db24de076c2b2c6276bf6f48ebf0/plugin/trace/trace.go#L41-L43
11,314
vulcand/vulcand
plugin/trace/trace.go
String
func (t *Trace) String() string { return fmt.Sprintf("addr=%v, reqHeaders=%v, respHeaders=%v", t.Addr, t.ReqHeaders, t.RespHeaders) }
go
func (t *Trace) String() string { return fmt.Sprintf("addr=%v, reqHeaders=%v, respHeaders=%v", t.Addr, t.ReqHeaders, t.RespHeaders) }
[ "func", "(", "t", "*", "Trace", ")", "String", "(", ")", "string", "{", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "t", ".", "Addr", ",", "t", ".", "ReqHeaders", ",", "t", ".", "RespHeaders", ")", "\n", "}" ]
// String is a user-friendly representation of the handler
[ "String", "is", "a", "user", "-", "friendly", "representation", "of", "the", "handler" ]
5fb2302c78e2db24de076c2b2c6276bf6f48ebf0
https://github.com/vulcand/vulcand/blob/5fb2302c78e2db24de076c2b2c6276bf6f48ebf0/plugin/trace/trace.go#L46-L48
11,315
vulcand/vulcand
plugin/trace/trace.go
FromOther
func FromOther(t Trace) (plugin.Middleware, error) { return New(t.Addr, t.ReqHeaders, t.RespHeaders) }
go
func FromOther(t Trace) (plugin.Middleware, error) { return New(t.Addr, t.ReqHeaders, t.RespHeaders) }
[ "func", "FromOther", "(", "t", "Trace", ")", "(", "plugin", ".", "Middleware", ",", "error", ")", "{", "return", "New", "(", "t", ".", "Addr", ",", "t", ".", "ReqHeaders", ",", "t", ".", "RespHeaders", ")", "\n", "}" ]
// FromOther creates and validates Trace plugin instance from serialized format
[ "FromOther", "creates", "and", "validates", "Trace", "plugin", "instance", "from", "serialized", "format" ]
5fb2302c78e2db24de076c2b2c6276bf6f48ebf0
https://github.com/vulcand/vulcand/blob/5fb2302c78e2db24de076c2b2c6276bf6f48ebf0/plugin/trace/trace.go#L59-L61
11,316
vulcand/vulcand
plugin/trace/trace.go
FromCli
func FromCli(c *cli.Context) (plugin.Middleware, error) { return New(c.String("addr"), c.StringSlice("reqHeader"), c.StringSlice("respHeader")) }
go
func FromCli(c *cli.Context) (plugin.Middleware, error) { return New(c.String("addr"), c.StringSlice("reqHeader"), c.StringSlice("respHeader")) }
[ "func", "FromCli", "(", "c", "*", "cli", ".", "Context", ")", "(", "plugin", ".", "Middleware", ",", "error", ")", "{", "return", "New", "(", "c", ".", "String", "(", "\"", "\"", ")", ",", "c", ".", "StringSlice", "(", "\"", "\"", ")", ",", "c", ".", "StringSlice", "(", "\"", "\"", ")", ")", "\n", "}" ]
// FromCli creates a Trace plugin object from command line
[ "FromCli", "creates", "a", "Trace", "plugin", "object", "from", "command", "line" ]
5fb2302c78e2db24de076c2b2c6276bf6f48ebf0
https://github.com/vulcand/vulcand/blob/5fb2302c78e2db24de076c2b2c6276bf6f48ebf0/plugin/trace/trace.go#L64-L66
11,317
vulcand/vulcand
plugin/trace/trace.go
CliFlags
func CliFlags() []cli.Flag { return []cli.Flag{ cli.StringFlag{ Name: "addr", Usage: "Address of the output, e.g. syslog:///tmp/out.sock", }, cli.StringSliceFlag{ Name: "reqHeader", Usage: "if provided, captures headers from requests", Value: &cli.StringSlice{}, }, cli.StringSliceFlag{ Name: "respHeader", Usage: "if provided, captures headers from response", Value: &cli.StringSlice{}, }, } }
go
func CliFlags() []cli.Flag { return []cli.Flag{ cli.StringFlag{ Name: "addr", Usage: "Address of the output, e.g. syslog:///tmp/out.sock", }, cli.StringSliceFlag{ Name: "reqHeader", Usage: "if provided, captures headers from requests", Value: &cli.StringSlice{}, }, cli.StringSliceFlag{ Name: "respHeader", Usage: "if provided, captures headers from response", Value: &cli.StringSlice{}, }, } }
[ "func", "CliFlags", "(", ")", "[", "]", "cli", ".", "Flag", "{", "return", "[", "]", "cli", ".", "Flag", "{", "cli", ".", "StringFlag", "{", "Name", ":", "\"", "\"", ",", "Usage", ":", "\"", "\"", ",", "}", ",", "cli", ".", "StringSliceFlag", "{", "Name", ":", "\"", "\"", ",", "Usage", ":", "\"", "\"", ",", "Value", ":", "&", "cli", ".", "StringSlice", "{", "}", ",", "}", ",", "cli", ".", "StringSliceFlag", "{", "Name", ":", "\"", "\"", ",", "Usage", ":", "\"", "\"", ",", "Value", ":", "&", "cli", ".", "StringSlice", "{", "}", ",", "}", ",", "}", "\n", "}" ]
// CliFlags is used to add command-line arguments to the CLI tool - vctl
[ "CliFlags", "is", "used", "to", "add", "command", "-", "line", "arguments", "to", "the", "CLI", "tool", "-", "vctl" ]
5fb2302c78e2db24de076c2b2c6276bf6f48ebf0
https://github.com/vulcand/vulcand/blob/5fb2302c78e2db24de076c2b2c6276bf6f48ebf0/plugin/trace/trace.go#L79-L96
11,318
vulcand/vulcand
stapler/stapler.go
Clock
func Clock(clock timetools.TimeProvider) StaplerOption { return func(s *stapler) { s.clock = clock } }
go
func Clock(clock timetools.TimeProvider) StaplerOption { return func(s *stapler) { s.clock = clock } }
[ "func", "Clock", "(", "clock", "timetools", ".", "TimeProvider", ")", "StaplerOption", "{", "return", "func", "(", "s", "*", "stapler", ")", "{", "s", ".", "clock", "=", "clock", "\n", "}", "\n", "}" ]
// Clock is an optional argument to the New function, by default the system clock is used
[ "Clock", "is", "an", "optional", "argument", "to", "the", "New", "function", "by", "default", "the", "system", "clock", "is", "used" ]
5fb2302c78e2db24de076c2b2c6276bf6f48ebf0
https://github.com/vulcand/vulcand/blob/5fb2302c78e2db24de076c2b2c6276bf6f48ebf0/stapler/stapler.go#L45-L49
11,319
vulcand/vulcand
stapler/stapler.go
New
func New(opts ...StaplerOption) Stapler { s := &stapler{ v: make(map[string]*hostStapler), mtx: &sync.Mutex{}, eventsC: make(chan *stapleFetched), closeC: make(chan struct{}), subscribers: make(map[int32]chan *StapleUpdated), kickC: make(chan bool), discardC: nil, // setup transport more aggressive timeouts for OCSP staple responses client: &http.Client{ Transport: &http.Transport{ Dial: (&net.Dialer{ Timeout: 10 * time.Second, KeepAlive: 5 * time.Second, }).Dial, TLSHandshakeTimeout: 5 * time.Second, }, }, } for _, o := range opts { o(s) } if s.clock == nil { s.clock = &timetools.RealTime{} } go s.fanOut() return s }
go
func New(opts ...StaplerOption) Stapler { s := &stapler{ v: make(map[string]*hostStapler), mtx: &sync.Mutex{}, eventsC: make(chan *stapleFetched), closeC: make(chan struct{}), subscribers: make(map[int32]chan *StapleUpdated), kickC: make(chan bool), discardC: nil, // setup transport more aggressive timeouts for OCSP staple responses client: &http.Client{ Transport: &http.Transport{ Dial: (&net.Dialer{ Timeout: 10 * time.Second, KeepAlive: 5 * time.Second, }).Dial, TLSHandshakeTimeout: 5 * time.Second, }, }, } for _, o := range opts { o(s) } if s.clock == nil { s.clock = &timetools.RealTime{} } go s.fanOut() return s }
[ "func", "New", "(", "opts", "...", "StaplerOption", ")", "Stapler", "{", "s", ":=", "&", "stapler", "{", "v", ":", "make", "(", "map", "[", "string", "]", "*", "hostStapler", ")", ",", "mtx", ":", "&", "sync", ".", "Mutex", "{", "}", ",", "eventsC", ":", "make", "(", "chan", "*", "stapleFetched", ")", ",", "closeC", ":", "make", "(", "chan", "struct", "{", "}", ")", ",", "subscribers", ":", "make", "(", "map", "[", "int32", "]", "chan", "*", "StapleUpdated", ")", ",", "kickC", ":", "make", "(", "chan", "bool", ")", ",", "discardC", ":", "nil", ",", "// setup transport more aggressive timeouts for OCSP staple responses", "client", ":", "&", "http", ".", "Client", "{", "Transport", ":", "&", "http", ".", "Transport", "{", "Dial", ":", "(", "&", "net", ".", "Dialer", "{", "Timeout", ":", "10", "*", "time", ".", "Second", ",", "KeepAlive", ":", "5", "*", "time", ".", "Second", ",", "}", ")", ".", "Dial", ",", "TLSHandshakeTimeout", ":", "5", "*", "time", ".", "Second", ",", "}", ",", "}", ",", "}", "\n", "for", "_", ",", "o", ":=", "range", "opts", "{", "o", "(", "s", ")", "\n", "}", "\n", "if", "s", ".", "clock", "==", "nil", "{", "s", ".", "clock", "=", "&", "timetools", ".", "RealTime", "{", "}", "\n", "}", "\n", "go", "s", ".", "fanOut", "(", ")", "\n", "return", "s", "\n", "}" ]
// New returns a new instance of in-memory Staple resolver and cache
[ "New", "returns", "a", "new", "instance", "of", "in", "-", "memory", "Staple", "resolver", "and", "cache" ]
5fb2302c78e2db24de076c2b2c6276bf6f48ebf0
https://github.com/vulcand/vulcand/blob/5fb2302c78e2db24de076c2b2c6276bf6f48ebf0/stapler/stapler.go#L62-L90
11,320
vulcand/vulcand
proxy/rtmcollect/rtmcollect.go
CfgWithStats
func (e *BeSrvEntry) CfgWithStats() engine.Server { cfg := e.beSrvCfg var err error cfg.Stats, err = engine.NewRoundTripStats(e.rtm) if err != nil { panic(errors.Wrap(err, "must never fail")) } return cfg }
go
func (e *BeSrvEntry) CfgWithStats() engine.Server { cfg := e.beSrvCfg var err error cfg.Stats, err = engine.NewRoundTripStats(e.rtm) if err != nil { panic(errors.Wrap(err, "must never fail")) } return cfg }
[ "func", "(", "e", "*", "BeSrvEntry", ")", "CfgWithStats", "(", ")", "engine", ".", "Server", "{", "cfg", ":=", "e", ".", "beSrvCfg", "\n", "var", "err", "error", "\n", "cfg", ".", "Stats", ",", "err", "=", "engine", ".", "NewRoundTripStats", "(", "e", ".", "rtm", ")", "\n", "if", "err", "!=", "nil", "{", "panic", "(", "errors", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", ")", "\n", "}", "\n", "return", "cfg", "\n", "}" ]
// CfgWithStats returns a backend server storage config along with round-trip // stats.
[ "CfgWithStats", "returns", "a", "backend", "server", "storage", "config", "along", "with", "round", "-", "trip", "stats", "." ]
5fb2302c78e2db24de076c2b2c6276bf6f48ebf0
https://github.com/vulcand/vulcand/blob/5fb2302c78e2db24de076c2b2c6276bf6f48ebf0/proxy/rtmcollect/rtmcollect.go#L44-L52
11,321
vulcand/vulcand
proxy/rtmcollect/rtmcollect.go
New
func New(handler http.Handler) (*T, error) { feRTM, err := memmetrics.NewRTMetrics() if err != nil { return nil, err } return &T{ rtm: feRTM, beSrvRTMs: make(map[backend.SrvURLKey]BeSrvEntry), clock: &timetools.RealTime{}, handler: handler, }, nil }
go
func New(handler http.Handler) (*T, error) { feRTM, err := memmetrics.NewRTMetrics() if err != nil { return nil, err } return &T{ rtm: feRTM, beSrvRTMs: make(map[backend.SrvURLKey]BeSrvEntry), clock: &timetools.RealTime{}, handler: handler, }, nil }
[ "func", "New", "(", "handler", "http", ".", "Handler", ")", "(", "*", "T", ",", "error", ")", "{", "feRTM", ",", "err", ":=", "memmetrics", ".", "NewRTMetrics", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "&", "T", "{", "rtm", ":", "feRTM", ",", "beSrvRTMs", ":", "make", "(", "map", "[", "backend", ".", "SrvURLKey", "]", "BeSrvEntry", ")", ",", "clock", ":", "&", "timetools", ".", "RealTime", "{", "}", ",", "handler", ":", "handler", ",", "}", ",", "nil", "\n", "}" ]
// New returns a new round-trip metrics collector instance.
[ "New", "returns", "a", "new", "round", "-", "trip", "metrics", "collector", "instance", "." ]
5fb2302c78e2db24de076c2b2c6276bf6f48ebf0
https://github.com/vulcand/vulcand/blob/5fb2302c78e2db24de076c2b2c6276bf6f48ebf0/proxy/rtmcollect/rtmcollect.go#L55-L66
11,322
vulcand/vulcand
proxy/rtmcollect/rtmcollect.go
RTStats
func (c *T) RTStats() (*engine.RoundTripStats, error) { c.mu.Lock() defer c.mu.Unlock() return engine.NewRoundTripStats(c.rtm) }
go
func (c *T) RTStats() (*engine.RoundTripStats, error) { c.mu.Lock() defer c.mu.Unlock() return engine.NewRoundTripStats(c.rtm) }
[ "func", "(", "c", "*", "T", ")", "RTStats", "(", ")", "(", "*", "engine", ".", "RoundTripStats", ",", "error", ")", "{", "c", ".", "mu", ".", "Lock", "(", ")", "\n", "defer", "c", ".", "mu", ".", "Unlock", "(", ")", "\n\n", "return", "engine", ".", "NewRoundTripStats", "(", "c", ".", "rtm", ")", "\n", "}" ]
// RTStats returns round-trip stats of the associated frontend.
[ "RTStats", "returns", "round", "-", "trip", "stats", "of", "the", "associated", "frontend", "." ]
5fb2302c78e2db24de076c2b2c6276bf6f48ebf0
https://github.com/vulcand/vulcand/blob/5fb2302c78e2db24de076c2b2c6276bf6f48ebf0/proxy/rtmcollect/rtmcollect.go#L85-L90
11,323
vulcand/vulcand
proxy/rtmcollect/rtmcollect.go
UpsertServer
func (c *T) UpsertServer(beSrv backend.Srv) { c.mu.Lock() defer c.mu.Unlock() c.beSrvRTMs[beSrv.URLKey()] = BeSrvEntry{beSrv.Cfg(), NewRTMetrics()} }
go
func (c *T) UpsertServer(beSrv backend.Srv) { c.mu.Lock() defer c.mu.Unlock() c.beSrvRTMs[beSrv.URLKey()] = BeSrvEntry{beSrv.Cfg(), NewRTMetrics()} }
[ "func", "(", "c", "*", "T", ")", "UpsertServer", "(", "beSrv", "backend", ".", "Srv", ")", "{", "c", ".", "mu", ".", "Lock", "(", ")", "\n", "defer", "c", ".", "mu", ".", "Unlock", "(", ")", "\n\n", "c", ".", "beSrvRTMs", "[", "beSrv", ".", "URLKey", "(", ")", "]", "=", "BeSrvEntry", "{", "beSrv", ".", "Cfg", "(", ")", ",", "NewRTMetrics", "(", ")", "}", "\n", "}" ]
// UpsertServer upserts a backend server to collect round-trip metrics for.
[ "UpsertServer", "upserts", "a", "backend", "server", "to", "collect", "round", "-", "trip", "metrics", "for", "." ]
5fb2302c78e2db24de076c2b2c6276bf6f48ebf0
https://github.com/vulcand/vulcand/blob/5fb2302c78e2db24de076c2b2c6276bf6f48ebf0/proxy/rtmcollect/rtmcollect.go#L93-L98
11,324
vulcand/vulcand
proxy/rtmcollect/rtmcollect.go
RemoveServer
func (c *T) RemoveServer(beSrvURLKey backend.SrvURLKey) { c.mu.Lock() defer c.mu.Unlock() delete(c.beSrvRTMs, beSrvURLKey) }
go
func (c *T) RemoveServer(beSrvURLKey backend.SrvURLKey) { c.mu.Lock() defer c.mu.Unlock() delete(c.beSrvRTMs, beSrvURLKey) }
[ "func", "(", "c", "*", "T", ")", "RemoveServer", "(", "beSrvURLKey", "backend", ".", "SrvURLKey", ")", "{", "c", ".", "mu", ".", "Lock", "(", ")", "\n", "defer", "c", ".", "mu", ".", "Unlock", "(", ")", "\n\n", "delete", "(", "c", ".", "beSrvRTMs", ",", "beSrvURLKey", ")", "\n", "}" ]
// RemoveServer removes a backend server from the list of servers that it // collects round-trip metrics for.
[ "RemoveServer", "removes", "a", "backend", "server", "from", "the", "list", "of", "servers", "that", "it", "collects", "round", "-", "trip", "metrics", "for", "." ]
5fb2302c78e2db24de076c2b2c6276bf6f48ebf0
https://github.com/vulcand/vulcand/blob/5fb2302c78e2db24de076c2b2c6276bf6f48ebf0/proxy/rtmcollect/rtmcollect.go#L102-L107
11,325
vulcand/vulcand
proxy/rtmcollect/rtmcollect.go
AppendFeRTMTo
func (c *T) AppendFeRTMTo(aggregate *memmetrics.RTMetrics) error { c.mu.Lock() defer c.mu.Unlock() return aggregate.Append(c.rtm) }
go
func (c *T) AppendFeRTMTo(aggregate *memmetrics.RTMetrics) error { c.mu.Lock() defer c.mu.Unlock() return aggregate.Append(c.rtm) }
[ "func", "(", "c", "*", "T", ")", "AppendFeRTMTo", "(", "aggregate", "*", "memmetrics", ".", "RTMetrics", ")", "error", "{", "c", ".", "mu", ".", "Lock", "(", ")", "\n", "defer", "c", ".", "mu", ".", "Unlock", "(", ")", "\n\n", "return", "aggregate", ".", "Append", "(", "c", ".", "rtm", ")", "\n", "}" ]
// AppendFeRTMTo appends frontend round-trip metrics to an aggregate.
[ "AppendFeRTMTo", "appends", "frontend", "round", "-", "trip", "metrics", "to", "an", "aggregate", "." ]
5fb2302c78e2db24de076c2b2c6276bf6f48ebf0
https://github.com/vulcand/vulcand/blob/5fb2302c78e2db24de076c2b2c6276bf6f48ebf0/proxy/rtmcollect/rtmcollect.go#L110-L115
11,326
vulcand/vulcand
plugin/cbreaker/spec.go
NewHandler
func (c *Spec) NewHandler(next http.Handler) (http.Handler, error) { return fromSpec(c, next) }
go
func (c *Spec) NewHandler(next http.Handler) (http.Handler, error) { return fromSpec(c, next) }
[ "func", "(", "c", "*", "Spec", ")", "NewHandler", "(", "next", "http", ".", "Handler", ")", "(", "http", ".", "Handler", ",", "error", ")", "{", "return", "fromSpec", "(", "c", ",", "next", ")", "\n", "}" ]
// NewMiddleware vulcan library compatible middleware
[ "NewMiddleware", "vulcan", "library", "compatible", "middleware" ]
5fb2302c78e2db24de076c2b2c6276bf6f48ebf0
https://github.com/vulcand/vulcand/blob/5fb2302c78e2db24de076c2b2c6276bf6f48ebf0/plugin/cbreaker/spec.go#L119-L121
11,327
vulcand/vulcand
plugin/cbreaker/spec.go
NewSpec
func NewSpec(condition string, fallback, onTripped, onStandby interface{}, fallbackDuration, recoveryDuration, checkPeriod time.Duration) (*Spec, error) { spec := &Spec{ Condition: condition, Fallback: fallback, OnTripped: onTripped, OnStandby: onStandby, RecoveryDuration: recoveryDuration, FallbackDuration: fallbackDuration, CheckPeriod: checkPeriod, } if _, err := fromSpec(spec, nil); err != nil { return nil, err } return spec, nil }
go
func NewSpec(condition string, fallback, onTripped, onStandby interface{}, fallbackDuration, recoveryDuration, checkPeriod time.Duration) (*Spec, error) { spec := &Spec{ Condition: condition, Fallback: fallback, OnTripped: onTripped, OnStandby: onStandby, RecoveryDuration: recoveryDuration, FallbackDuration: fallbackDuration, CheckPeriod: checkPeriod, } if _, err := fromSpec(spec, nil); err != nil { return nil, err } return spec, nil }
[ "func", "NewSpec", "(", "condition", "string", ",", "fallback", ",", "onTripped", ",", "onStandby", "interface", "{", "}", ",", "fallbackDuration", ",", "recoveryDuration", ",", "checkPeriod", "time", ".", "Duration", ")", "(", "*", "Spec", ",", "error", ")", "{", "spec", ":=", "&", "Spec", "{", "Condition", ":", "condition", ",", "Fallback", ":", "fallback", ",", "OnTripped", ":", "onTripped", ",", "OnStandby", ":", "onStandby", ",", "RecoveryDuration", ":", "recoveryDuration", ",", "FallbackDuration", ":", "fallbackDuration", ",", "CheckPeriod", ":", "checkPeriod", ",", "}", "\n", "if", "_", ",", "err", ":=", "fromSpec", "(", "spec", ",", "nil", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "spec", ",", "nil", "\n", "}" ]
// NewSpec check parameters and returns new specification for the middleware
[ "NewSpec", "check", "parameters", "and", "returns", "new", "specification", "for", "the", "middleware" ]
5fb2302c78e2db24de076c2b2c6276bf6f48ebf0
https://github.com/vulcand/vulcand/blob/5fb2302c78e2db24de076c2b2c6276bf6f48ebf0/plugin/cbreaker/spec.go#L124-L138
11,328
vulcand/vulcand
plugin/cbreaker/spec.go
FromOther
func FromOther(c Spec) (plugin.Middleware, error) { return NewSpec(c.Condition, c.Fallback, c.OnTripped, c.OnStandby, c.FallbackDuration, c.RecoveryDuration, c.CheckPeriod) }
go
func FromOther(c Spec) (plugin.Middleware, error) { return NewSpec(c.Condition, c.Fallback, c.OnTripped, c.OnStandby, c.FallbackDuration, c.RecoveryDuration, c.CheckPeriod) }
[ "func", "FromOther", "(", "c", "Spec", ")", "(", "plugin", ".", "Middleware", ",", "error", ")", "{", "return", "NewSpec", "(", "c", ".", "Condition", ",", "c", ".", "Fallback", ",", "c", ".", "OnTripped", ",", "c", ".", "OnStandby", ",", "c", ".", "FallbackDuration", ",", "c", ".", "RecoveryDuration", ",", "c", ".", "CheckPeriod", ")", "\n", "}" ]
// FromOther is used to read spec from the serialized format
[ "FromOther", "is", "used", "to", "read", "spec", "from", "the", "serialized", "format" ]
5fb2302c78e2db24de076c2b2c6276bf6f48ebf0
https://github.com/vulcand/vulcand/blob/5fb2302c78e2db24de076c2b2c6276bf6f48ebf0/plugin/cbreaker/spec.go#L145-L147
11,329
vulcand/vulcand
plugin/cbreaker/spec.go
FromCli
func FromCli(c *cli.Context) (plugin.Middleware, error) { return NewSpec(c.String("condition"), c.String("fallback"), c.String("onTripped"), c.String("onStandby"), c.Duration("fallbackDuration"), c.Duration("recoveryDuration"), c.Duration("checkPeriod")) }
go
func FromCli(c *cli.Context) (plugin.Middleware, error) { return NewSpec(c.String("condition"), c.String("fallback"), c.String("onTripped"), c.String("onStandby"), c.Duration("fallbackDuration"), c.Duration("recoveryDuration"), c.Duration("checkPeriod")) }
[ "func", "FromCli", "(", "c", "*", "cli", ".", "Context", ")", "(", "plugin", ".", "Middleware", ",", "error", ")", "{", "return", "NewSpec", "(", "c", ".", "String", "(", "\"", "\"", ")", ",", "c", ".", "String", "(", "\"", "\"", ")", ",", "c", ".", "String", "(", "\"", "\"", ")", ",", "c", ".", "String", "(", "\"", "\"", ")", ",", "c", ".", "Duration", "(", "\"", "\"", ")", ",", "c", ".", "Duration", "(", "\"", "\"", ")", ",", "c", ".", "Duration", "(", "\"", "\"", ")", ")", "\n", "}" ]
// FromCli constructs the middleware from the command line arguments
[ "FromCli", "constructs", "the", "middleware", "from", "the", "command", "line", "arguments" ]
5fb2302c78e2db24de076c2b2c6276bf6f48ebf0
https://github.com/vulcand/vulcand/blob/5fb2302c78e2db24de076c2b2c6276bf6f48ebf0/plugin/cbreaker/spec.go#L150-L152
11,330
vulcand/vulcand
engine/tls.go
NewTLSConfig
func NewTLSConfig(s *TLSSettings) (*tls.Config, error) { // Parse min and max TLS versions var min, max uint16 var err error if s.MinVersion == "" { min = tls.VersionTLS10 } else if min, err = ParseTLSVersion(s.MinVersion); err != nil { return nil, err } if s.MaxVersion == "" { max = tls.VersionTLS12 } else if max, err = ParseTLSVersion(s.MaxVersion); err != nil { return nil, err } var css []uint16 if len(s.CipherSuites) == 0 { css = []uint16{ tls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, tls.TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA, tls.TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA, tls.TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA, tls.TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA, tls.TLS_RSA_WITH_AES_256_CBC_SHA, tls.TLS_RSA_WITH_AES_128_CBC_SHA, } } else { css = make([]uint16, len(s.CipherSuites)) for i, suite := range s.CipherSuites { cs, err := ParseCipherSuite(suite) if err != nil { return nil, err } css[i] = cs } } var cache tls.ClientSessionCache if !s.SessionTicketsDisabled { cache, err = NewTLSSessionCache(&s.SessionCache) if err != nil { return nil, err } } return &tls.Config{ MinVersion: min, MaxVersion: max, SessionTicketsDisabled: s.SessionTicketsDisabled, ClientSessionCache: cache, PreferServerCipherSuites: s.PreferServerCipherSuites, CipherSuites: css, InsecureSkipVerify: s.InsecureSkipVerify, }, nil }
go
func NewTLSConfig(s *TLSSettings) (*tls.Config, error) { // Parse min and max TLS versions var min, max uint16 var err error if s.MinVersion == "" { min = tls.VersionTLS10 } else if min, err = ParseTLSVersion(s.MinVersion); err != nil { return nil, err } if s.MaxVersion == "" { max = tls.VersionTLS12 } else if max, err = ParseTLSVersion(s.MaxVersion); err != nil { return nil, err } var css []uint16 if len(s.CipherSuites) == 0 { css = []uint16{ tls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, tls.TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA, tls.TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA, tls.TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA, tls.TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA, tls.TLS_RSA_WITH_AES_256_CBC_SHA, tls.TLS_RSA_WITH_AES_128_CBC_SHA, } } else { css = make([]uint16, len(s.CipherSuites)) for i, suite := range s.CipherSuites { cs, err := ParseCipherSuite(suite) if err != nil { return nil, err } css[i] = cs } } var cache tls.ClientSessionCache if !s.SessionTicketsDisabled { cache, err = NewTLSSessionCache(&s.SessionCache) if err != nil { return nil, err } } return &tls.Config{ MinVersion: min, MaxVersion: max, SessionTicketsDisabled: s.SessionTicketsDisabled, ClientSessionCache: cache, PreferServerCipherSuites: s.PreferServerCipherSuites, CipherSuites: css, InsecureSkipVerify: s.InsecureSkipVerify, }, nil }
[ "func", "NewTLSConfig", "(", "s", "*", "TLSSettings", ")", "(", "*", "tls", ".", "Config", ",", "error", ")", "{", "// Parse min and max TLS versions", "var", "min", ",", "max", "uint16", "\n", "var", "err", "error", "\n\n", "if", "s", ".", "MinVersion", "==", "\"", "\"", "{", "min", "=", "tls", ".", "VersionTLS10", "\n", "}", "else", "if", "min", ",", "err", "=", "ParseTLSVersion", "(", "s", ".", "MinVersion", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "if", "s", ".", "MaxVersion", "==", "\"", "\"", "{", "max", "=", "tls", ".", "VersionTLS12", "\n", "}", "else", "if", "max", ",", "err", "=", "ParseTLSVersion", "(", "s", ".", "MaxVersion", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "var", "css", "[", "]", "uint16", "\n", "if", "len", "(", "s", ".", "CipherSuites", ")", "==", "0", "{", "css", "=", "[", "]", "uint16", "{", "tls", ".", "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256", ",", "tls", ".", "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256", ",", "tls", ".", "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA", ",", "tls", ".", "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA", ",", "tls", ".", "TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA", ",", "tls", ".", "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA", ",", "tls", ".", "TLS_RSA_WITH_AES_256_CBC_SHA", ",", "tls", ".", "TLS_RSA_WITH_AES_128_CBC_SHA", ",", "}", "\n", "}", "else", "{", "css", "=", "make", "(", "[", "]", "uint16", ",", "len", "(", "s", ".", "CipherSuites", ")", ")", "\n", "for", "i", ",", "suite", ":=", "range", "s", ".", "CipherSuites", "{", "cs", ",", "err", ":=", "ParseCipherSuite", "(", "suite", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "css", "[", "i", "]", "=", "cs", "\n", "}", "\n", "}", "\n\n", "var", "cache", "tls", ".", "ClientSessionCache", "\n", "if", "!", "s", ".", "SessionTicketsDisabled", "{", "cache", ",", "err", "=", "NewTLSSessionCache", "(", "&", "s", ".", "SessionCache", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "}", "\n\n", "return", "&", "tls", ".", "Config", "{", "MinVersion", ":", "min", ",", "MaxVersion", ":", "max", ",", "SessionTicketsDisabled", ":", "s", ".", "SessionTicketsDisabled", ",", "ClientSessionCache", ":", "cache", ",", "PreferServerCipherSuites", ":", "s", ".", "PreferServerCipherSuites", ",", "CipherSuites", ":", "css", ",", "InsecureSkipVerify", ":", "s", ".", "InsecureSkipVerify", ",", "}", ",", "nil", "\n", "}" ]
// NewTLSConfig validates the TLSSettings and returns the tls.Config with the converted parameters
[ "NewTLSConfig", "validates", "the", "TLSSettings", "and", "returns", "the", "tls", ".", "Config", "with", "the", "converted", "parameters" ]
5fb2302c78e2db24de076c2b2c6276bf6f48ebf0
https://github.com/vulcand/vulcand/blob/5fb2302c78e2db24de076c2b2c6276bf6f48ebf0/engine/tls.go#L54-L117
11,331
vulcand/vulcand
engine/tls.go
NewTLSSessionCache
func NewTLSSessionCache(s *TLSSessionCache) (tls.ClientSessionCache, error) { cacheType := s.Type if cacheType == "" { cacheType = LRUCacheType } if cacheType != LRUCacheType { return nil, fmt.Errorf("unsupported session cache type: %v", s.Type) } var capacity int if params := s.Settings; params != nil { if params.Capacity < 0 { return nil, fmt.Errorf("bad LRU capacity: %v", params.Capacity) } else if params.Capacity == 0 { capacity = DefaultLRUCapacity } else { capacity = params.Capacity } } return tls.NewLRUClientSessionCache(capacity), nil }
go
func NewTLSSessionCache(s *TLSSessionCache) (tls.ClientSessionCache, error) { cacheType := s.Type if cacheType == "" { cacheType = LRUCacheType } if cacheType != LRUCacheType { return nil, fmt.Errorf("unsupported session cache type: %v", s.Type) } var capacity int if params := s.Settings; params != nil { if params.Capacity < 0 { return nil, fmt.Errorf("bad LRU capacity: %v", params.Capacity) } else if params.Capacity == 0 { capacity = DefaultLRUCapacity } else { capacity = params.Capacity } } return tls.NewLRUClientSessionCache(capacity), nil }
[ "func", "NewTLSSessionCache", "(", "s", "*", "TLSSessionCache", ")", "(", "tls", ".", "ClientSessionCache", ",", "error", ")", "{", "cacheType", ":=", "s", ".", "Type", "\n", "if", "cacheType", "==", "\"", "\"", "{", "cacheType", "=", "LRUCacheType", "\n", "}", "\n", "if", "cacheType", "!=", "LRUCacheType", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "s", ".", "Type", ")", "\n", "}", "\n", "var", "capacity", "int", "\n", "if", "params", ":=", "s", ".", "Settings", ";", "params", "!=", "nil", "{", "if", "params", ".", "Capacity", "<", "0", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "params", ".", "Capacity", ")", "\n", "}", "else", "if", "params", ".", "Capacity", "==", "0", "{", "capacity", "=", "DefaultLRUCapacity", "\n", "}", "else", "{", "capacity", "=", "params", ".", "Capacity", "\n", "}", "\n", "}", "\n", "return", "tls", ".", "NewLRUClientSessionCache", "(", "capacity", ")", ",", "nil", "\n", "}" ]
// NewTLSSessionCache validates parameters and creates a new TLS session cache
[ "NewTLSSessionCache", "validates", "parameters", "and", "creates", "a", "new", "TLS", "session", "cache" ]
5fb2302c78e2db24de076c2b2c6276bf6f48ebf0
https://github.com/vulcand/vulcand/blob/5fb2302c78e2db24de076c2b2c6276bf6f48ebf0/engine/tls.go#L120-L139
11,332
vulcand/vulcand
engine/etcdng/v2/etcd.go
parseChange
func (n *ng) parseChange(response *etcd.Response) (interface{}, error) { // Order parsers from the most to the least frequently used. matchers := []MatcherFn{ n.parseBackendServerChange, n.parseBackendChange, n.parseFrontendMiddlewareChange, n.parseFrontendChange, n.parseHostChange, n.parseListenerChange, } for _, matcher := range matchers { a, err := matcher(response) if a != nil || err != nil { return a, err } } return nil, nil }
go
func (n *ng) parseChange(response *etcd.Response) (interface{}, error) { // Order parsers from the most to the least frequently used. matchers := []MatcherFn{ n.parseBackendServerChange, n.parseBackendChange, n.parseFrontendMiddlewareChange, n.parseFrontendChange, n.parseHostChange, n.parseListenerChange, } for _, matcher := range matchers { a, err := matcher(response) if a != nil || err != nil { return a, err } } return nil, nil }
[ "func", "(", "n", "*", "ng", ")", "parseChange", "(", "response", "*", "etcd", ".", "Response", ")", "(", "interface", "{", "}", ",", "error", ")", "{", "// Order parsers from the most to the least frequently used.", "matchers", ":=", "[", "]", "MatcherFn", "{", "n", ".", "parseBackendServerChange", ",", "n", ".", "parseBackendChange", ",", "n", ".", "parseFrontendMiddlewareChange", ",", "n", ".", "parseFrontendChange", ",", "n", ".", "parseHostChange", ",", "n", ".", "parseListenerChange", ",", "}", "\n", "for", "_", ",", "matcher", ":=", "range", "matchers", "{", "a", ",", "err", ":=", "matcher", "(", "response", ")", "\n", "if", "a", "!=", "nil", "||", "err", "!=", "nil", "{", "return", "a", ",", "err", "\n", "}", "\n", "}", "\n", "return", "nil", ",", "nil", "\n", "}" ]
// Dispatches etcd key changes changes to the etcd to the matching functions
[ "Dispatches", "etcd", "key", "changes", "changes", "to", "the", "etcd", "to", "the", "matching", "functions" ]
5fb2302c78e2db24de076c2b2c6276bf6f48ebf0
https://github.com/vulcand/vulcand/blob/5fb2302c78e2db24de076c2b2c6276bf6f48ebf0/engine/etcdng/v2/etcd.go#L656-L673
11,333
vulcand/vulcand
engine/model.go
NewHTTPBackend
func NewHTTPBackend(id string, s HTTPBackendSettings) (*Backend, error) { if _, err := s.TransportSettings(); err != nil { return nil, err } return &Backend{ Id: id, Type: HTTP, Settings: s, }, nil }
go
func NewHTTPBackend(id string, s HTTPBackendSettings) (*Backend, error) { if _, err := s.TransportSettings(); err != nil { return nil, err } return &Backend{ Id: id, Type: HTTP, Settings: s, }, nil }
[ "func", "NewHTTPBackend", "(", "id", "string", ",", "s", "HTTPBackendSettings", ")", "(", "*", "Backend", ",", "error", ")", "{", "if", "_", ",", "err", ":=", "s", ".", "TransportSettings", "(", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "&", "Backend", "{", "Id", ":", "id", ",", "Type", ":", "HTTP", ",", "Settings", ":", "s", ",", "}", ",", "nil", "\n", "}" ]
// NewBackend creates a new instance of the backend object
[ "NewBackend", "creates", "a", "new", "instance", "of", "the", "backend", "object" ]
5fb2302c78e2db24de076c2b2c6276bf6f48ebf0
https://github.com/vulcand/vulcand/blob/5fb2302c78e2db24de076c2b2c6276bf6f48ebf0/engine/model.go#L495-L504
11,334
vulcand/vulcand
engine/model.go
NetErrorRatio
func (e *RoundTripStats) NetErrorRatio() float64 { if e.Counters.Total == 0 { return 0 } return (float64(e.Counters.NetErrors) / float64(e.Counters.Total)) }
go
func (e *RoundTripStats) NetErrorRatio() float64 { if e.Counters.Total == 0 { return 0 } return (float64(e.Counters.NetErrors) / float64(e.Counters.Total)) }
[ "func", "(", "e", "*", "RoundTripStats", ")", "NetErrorRatio", "(", ")", "float64", "{", "if", "e", ".", "Counters", ".", "Total", "==", "0", "{", "return", "0", "\n", "}", "\n", "return", "(", "float64", "(", "e", ".", "Counters", ".", "NetErrors", ")", "/", "float64", "(", "e", ".", "Counters", ".", "Total", ")", ")", "\n", "}" ]
// NetErroRate calculates the amont of ntwork errors such as time outs and dropped connection // that occured in the given time window
[ "NetErroRate", "calculates", "the", "amont", "of", "ntwork", "errors", "such", "as", "time", "outs", "and", "dropped", "connection", "that", "occured", "in", "the", "given", "time", "window" ]
5fb2302c78e2db24de076c2b2c6276bf6f48ebf0
https://github.com/vulcand/vulcand/blob/5fb2302c78e2db24de076c2b2c6276bf6f48ebf0/engine/model.go#L602-L607
11,335
vulcand/vulcand
engine/model.go
AppErrorRatio
func (e *RoundTripStats) AppErrorRatio() float64 { return e.ResponseCodeRatio(http.StatusInternalServerError, http.StatusInternalServerError+1, 200, 300) }
go
func (e *RoundTripStats) AppErrorRatio() float64 { return e.ResponseCodeRatio(http.StatusInternalServerError, http.StatusInternalServerError+1, 200, 300) }
[ "func", "(", "e", "*", "RoundTripStats", ")", "AppErrorRatio", "(", ")", "float64", "{", "return", "e", ".", "ResponseCodeRatio", "(", "http", ".", "StatusInternalServerError", ",", "http", ".", "StatusInternalServerError", "+", "1", ",", "200", ",", "300", ")", "\n", "}" ]
// AppErrorRate calculates the ratio of 500 responses that designate internal server errors // to success responses - 2xx, it specifically not counts 4xx or any other than 500 error to avoid noisy results.
[ "AppErrorRate", "calculates", "the", "ratio", "of", "500", "responses", "that", "designate", "internal", "server", "errors", "to", "success", "responses", "-", "2xx", "it", "specifically", "not", "counts", "4xx", "or", "any", "other", "than", "500", "error", "to", "avoid", "noisy", "results", "." ]
5fb2302c78e2db24de076c2b2c6276bf6f48ebf0
https://github.com/vulcand/vulcand/blob/5fb2302c78e2db24de076c2b2c6276bf6f48ebf0/engine/model.go#L611-L613
11,336
vulcand/vulcand
proxy/backend/backend.go
Cfg
func (s *Srv) Cfg() engine.Server { return engine.Server{ Id: s.id, URL: s.rawURL, } }
go
func (s *Srv) Cfg() engine.Server { return engine.Server{ Id: s.id, URL: s.rawURL, } }
[ "func", "(", "s", "*", "Srv", ")", "Cfg", "(", ")", "engine", ".", "Server", "{", "return", "engine", ".", "Server", "{", "Id", ":", "s", ".", "id", ",", "URL", ":", "s", ".", "rawURL", ",", "}", "\n", "}" ]
// Cfg returns engine.Server config of the backend server instance.
[ "Cfg", "returns", "engine", ".", "Server", "config", "of", "the", "backend", "server", "instance", "." ]
5fb2302c78e2db24de076c2b2c6276bf6f48ebf0
https://github.com/vulcand/vulcand/blob/5fb2302c78e2db24de076c2b2c6276bf6f48ebf0/proxy/backend/backend.go#L35-L40
11,337
vulcand/vulcand
proxy/backend/backend.go
NewSrvURLKey
func NewSrvURLKey(u *url.URL) SrvURLKey { return SrvURLKey{scheme: u.Scheme, host: u.Host} }
go
func NewSrvURLKey(u *url.URL) SrvURLKey { return SrvURLKey{scheme: u.Scheme, host: u.Host} }
[ "func", "NewSrvURLKey", "(", "u", "*", "url", ".", "URL", ")", "SrvURLKey", "{", "return", "SrvURLKey", "{", "scheme", ":", "u", ".", "Scheme", ",", "host", ":", "u", ".", "Host", "}", "\n", "}" ]
// NewSrvURLKey creates an SrvURLKey from a server URL.
[ "NewSrvURLKey", "creates", "an", "SrvURLKey", "from", "a", "server", "URL", "." ]
5fb2302c78e2db24de076c2b2c6276bf6f48ebf0
https://github.com/vulcand/vulcand/blob/5fb2302c78e2db24de076c2b2c6276bf6f48ebf0/proxy/backend/backend.go#L49-L51
11,338
vulcand/vulcand
proxy/backend/backend.go
NewServer
func NewServer(beSrvCfg engine.Server) (Srv, error) { parsedURL, err := url.Parse(beSrvCfg.URL) if err != nil { return Srv{}, errors.Wrapf(err, "bad url %v", beSrvCfg.URL) } return Srv{ id: beSrvCfg.Id, rawURL: beSrvCfg.URL, parsedURL: parsedURL, }, nil }
go
func NewServer(beSrvCfg engine.Server) (Srv, error) { parsedURL, err := url.Parse(beSrvCfg.URL) if err != nil { return Srv{}, errors.Wrapf(err, "bad url %v", beSrvCfg.URL) } return Srv{ id: beSrvCfg.Id, rawURL: beSrvCfg.URL, parsedURL: parsedURL, }, nil }
[ "func", "NewServer", "(", "beSrvCfg", "engine", ".", "Server", ")", "(", "Srv", ",", "error", ")", "{", "parsedURL", ",", "err", ":=", "url", ".", "Parse", "(", "beSrvCfg", ".", "URL", ")", "\n", "if", "err", "!=", "nil", "{", "return", "Srv", "{", "}", ",", "errors", ".", "Wrapf", "(", "err", ",", "\"", "\"", ",", "beSrvCfg", ".", "URL", ")", "\n", "}", "\n", "return", "Srv", "{", "id", ":", "beSrvCfg", ".", "Id", ",", "rawURL", ":", "beSrvCfg", ".", "URL", ",", "parsedURL", ":", "parsedURL", ",", "}", ",", "nil", "\n", "}" ]
// NewServer creates a backend server from a config fetched from a storage // engine.
[ "NewServer", "creates", "a", "backend", "server", "from", "a", "config", "fetched", "from", "a", "storage", "engine", "." ]
5fb2302c78e2db24de076c2b2c6276bf6f48ebf0
https://github.com/vulcand/vulcand/blob/5fb2302c78e2db24de076c2b2c6276bf6f48ebf0/proxy/backend/backend.go#L55-L65
11,339
vulcand/vulcand
proxy/backend/backend.go
New
func New(beCfg engine.Backend, opts proxy.Options, beSrvs []Srv) (*T, error) { tpCfg, err := newTransportCfg(beCfg.HTTPSettings(), opts) if err != nil { return nil, errors.Wrap(err, "bad config") } return &T{ id: beCfg.Id, httpCfg: beCfg.HTTPSettings(), httpTp: newTransport(tpCfg), srvs: beSrvs, }, nil }
go
func New(beCfg engine.Backend, opts proxy.Options, beSrvs []Srv) (*T, error) { tpCfg, err := newTransportCfg(beCfg.HTTPSettings(), opts) if err != nil { return nil, errors.Wrap(err, "bad config") } return &T{ id: beCfg.Id, httpCfg: beCfg.HTTPSettings(), httpTp: newTransport(tpCfg), srvs: beSrvs, }, nil }
[ "func", "New", "(", "beCfg", "engine", ".", "Backend", ",", "opts", "proxy", ".", "Options", ",", "beSrvs", "[", "]", "Srv", ")", "(", "*", "T", ",", "error", ")", "{", "tpCfg", ",", "err", ":=", "newTransportCfg", "(", "beCfg", ".", "HTTPSettings", "(", ")", ",", "opts", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n", "return", "&", "T", "{", "id", ":", "beCfg", ".", "Id", ",", "httpCfg", ":", "beCfg", ".", "HTTPSettings", "(", ")", ",", "httpTp", ":", "newTransport", "(", "tpCfg", ")", ",", "srvs", ":", "beSrvs", ",", "}", ",", "nil", "\n", "}" ]
// New creates a new backend instance from a config fetched from a storage // engine and proxy options. An initial list of backend servers can be provided.
[ "New", "creates", "a", "new", "backend", "instance", "from", "a", "config", "fetched", "from", "a", "storage", "engine", "and", "proxy", "options", ".", "An", "initial", "list", "of", "backend", "servers", "can", "be", "provided", "." ]
5fb2302c78e2db24de076c2b2c6276bf6f48ebf0
https://github.com/vulcand/vulcand/blob/5fb2302c78e2db24de076c2b2c6276bf6f48ebf0/proxy/backend/backend.go#L79-L90
11,340
vulcand/vulcand
proxy/backend/backend.go
Key
func (be *T) Key() engine.BackendKey { return engine.BackendKey{Id: be.id} }
go
func (be *T) Key() engine.BackendKey { return engine.BackendKey{Id: be.id} }
[ "func", "(", "be", "*", "T", ")", "Key", "(", ")", "engine", ".", "BackendKey", "{", "return", "engine", ".", "BackendKey", "{", "Id", ":", "be", ".", "id", "}", "\n", "}" ]
// Key returns storage backend key.
[ "Key", "returns", "storage", "backend", "key", "." ]
5fb2302c78e2db24de076c2b2c6276bf6f48ebf0
https://github.com/vulcand/vulcand/blob/5fb2302c78e2db24de076c2b2c6276bf6f48ebf0/proxy/backend/backend.go#L93-L95
11,341
vulcand/vulcand
proxy/backend/backend.go
Update
func (be *T) Update(beCfg engine.Backend, opts proxy.Options) (bool, error) { be.mu.Lock() defer be.mu.Unlock() if beCfg.Key() != be.Key() { return false, errors.Errorf("invalid key, want=%v, got=%v", be.Key(), beCfg.Key()) } // Config has not changed. if be.httpCfg.Equals(beCfg.HTTPSettings()) { return false, nil } tpCfg, err := newTransportCfg(beCfg.HTTPSettings(), opts) if err != nil { return false, errors.Wrap(err, "bad config") } // FIXME: But what about active connections? be.httpTp.CloseIdleConnections() be.httpCfg = beCfg.HTTPSettings() httpTp := newTransport(tpCfg) be.httpTp = httpTp return true, nil }
go
func (be *T) Update(beCfg engine.Backend, opts proxy.Options) (bool, error) { be.mu.Lock() defer be.mu.Unlock() if beCfg.Key() != be.Key() { return false, errors.Errorf("invalid key, want=%v, got=%v", be.Key(), beCfg.Key()) } // Config has not changed. if be.httpCfg.Equals(beCfg.HTTPSettings()) { return false, nil } tpCfg, err := newTransportCfg(beCfg.HTTPSettings(), opts) if err != nil { return false, errors.Wrap(err, "bad config") } // FIXME: But what about active connections? be.httpTp.CloseIdleConnections() be.httpCfg = beCfg.HTTPSettings() httpTp := newTransport(tpCfg) be.httpTp = httpTp return true, nil }
[ "func", "(", "be", "*", "T", ")", "Update", "(", "beCfg", "engine", ".", "Backend", ",", "opts", "proxy", ".", "Options", ")", "(", "bool", ",", "error", ")", "{", "be", ".", "mu", ".", "Lock", "(", ")", "\n", "defer", "be", ".", "mu", ".", "Unlock", "(", ")", "\n\n", "if", "beCfg", ".", "Key", "(", ")", "!=", "be", ".", "Key", "(", ")", "{", "return", "false", ",", "errors", ".", "Errorf", "(", "\"", "\"", ",", "be", ".", "Key", "(", ")", ",", "beCfg", ".", "Key", "(", ")", ")", "\n", "}", "\n\n", "// Config has not changed.", "if", "be", ".", "httpCfg", ".", "Equals", "(", "beCfg", ".", "HTTPSettings", "(", ")", ")", "{", "return", "false", ",", "nil", "\n", "}", "\n\n", "tpCfg", ",", "err", ":=", "newTransportCfg", "(", "beCfg", ".", "HTTPSettings", "(", ")", ",", "opts", ")", "\n", "if", "err", "!=", "nil", "{", "return", "false", ",", "errors", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n\n", "// FIXME: But what about active connections?", "be", ".", "httpTp", ".", "CloseIdleConnections", "(", ")", "\n\n", "be", ".", "httpCfg", "=", "beCfg", ".", "HTTPSettings", "(", ")", "\n", "httpTp", ":=", "newTransport", "(", "tpCfg", ")", "\n", "be", ".", "httpTp", "=", "httpTp", "\n", "return", "true", ",", "nil", "\n", "}" ]
// Update updates the instance configuration.
[ "Update", "updates", "the", "instance", "configuration", "." ]
5fb2302c78e2db24de076c2b2c6276bf6f48ebf0
https://github.com/vulcand/vulcand/blob/5fb2302c78e2db24de076c2b2c6276bf6f48ebf0/proxy/backend/backend.go#L110-L135
11,342
vulcand/vulcand
proxy/backend/backend.go
UpsertServer
func (be *T) UpsertServer(beSrvCfg engine.Server) (bool, error) { be.mu.Lock() defer be.mu.Unlock() beSrv, err := NewServer(beSrvCfg) if err != nil { return false, errors.Wrapf(err, "bad config %v", beSrvCfg) } if i := be.indexOfServer(beSrvCfg.Id); i != -1 { if be.srvs[i].URLKey() == beSrv.URLKey() { return false, nil } be.cloneSrvCfgsIfSeen() be.srvs[i] = beSrv return true, nil } be.cloneSrvCfgsIfSeen() be.srvs = append(be.srvs, beSrv) return true, nil }
go
func (be *T) UpsertServer(beSrvCfg engine.Server) (bool, error) { be.mu.Lock() defer be.mu.Unlock() beSrv, err := NewServer(beSrvCfg) if err != nil { return false, errors.Wrapf(err, "bad config %v", beSrvCfg) } if i := be.indexOfServer(beSrvCfg.Id); i != -1 { if be.srvs[i].URLKey() == beSrv.URLKey() { return false, nil } be.cloneSrvCfgsIfSeen() be.srvs[i] = beSrv return true, nil } be.cloneSrvCfgsIfSeen() be.srvs = append(be.srvs, beSrv) return true, nil }
[ "func", "(", "be", "*", "T", ")", "UpsertServer", "(", "beSrvCfg", "engine", ".", "Server", ")", "(", "bool", ",", "error", ")", "{", "be", ".", "mu", ".", "Lock", "(", ")", "\n", "defer", "be", ".", "mu", ".", "Unlock", "(", ")", "\n\n", "beSrv", ",", "err", ":=", "NewServer", "(", "beSrvCfg", ")", "\n", "if", "err", "!=", "nil", "{", "return", "false", ",", "errors", ".", "Wrapf", "(", "err", ",", "\"", "\"", ",", "beSrvCfg", ")", "\n", "}", "\n", "if", "i", ":=", "be", ".", "indexOfServer", "(", "beSrvCfg", ".", "Id", ")", ";", "i", "!=", "-", "1", "{", "if", "be", ".", "srvs", "[", "i", "]", ".", "URLKey", "(", ")", "==", "beSrv", ".", "URLKey", "(", ")", "{", "return", "false", ",", "nil", "\n", "}", "\n", "be", ".", "cloneSrvCfgsIfSeen", "(", ")", "\n", "be", ".", "srvs", "[", "i", "]", "=", "beSrv", "\n", "return", "true", ",", "nil", "\n", "}", "\n", "be", ".", "cloneSrvCfgsIfSeen", "(", ")", "\n", "be", ".", "srvs", "=", "append", "(", "be", ".", "srvs", ",", "beSrv", ")", "\n", "return", "true", ",", "nil", "\n", "}" ]
// UpsertServer upserts a new backend server.
[ "UpsertServer", "upserts", "a", "new", "backend", "server", "." ]
5fb2302c78e2db24de076c2b2c6276bf6f48ebf0
https://github.com/vulcand/vulcand/blob/5fb2302c78e2db24de076c2b2c6276bf6f48ebf0/proxy/backend/backend.go#L138-L157
11,343
vulcand/vulcand
proxy/backend/backend.go
DeleteServer
func (be *T) DeleteServer(beSrvKey engine.ServerKey) bool { be.mu.Lock() defer be.mu.Unlock() i := be.indexOfServer(beSrvKey.Id) if i == -1 { log.Warnf("Cannot delete missing server %v from backend %v", beSrvKey.Id, be.id) return false } be.cloneSrvCfgsIfSeen() lastIdx := len(be.srvs) - 1 copy(be.srvs[i:], be.srvs[i+1:]) be.srvs[lastIdx] = Srv{} be.srvs = be.srvs[:lastIdx] return true }
go
func (be *T) DeleteServer(beSrvKey engine.ServerKey) bool { be.mu.Lock() defer be.mu.Unlock() i := be.indexOfServer(beSrvKey.Id) if i == -1 { log.Warnf("Cannot delete missing server %v from backend %v", beSrvKey.Id, be.id) return false } be.cloneSrvCfgsIfSeen() lastIdx := len(be.srvs) - 1 copy(be.srvs[i:], be.srvs[i+1:]) be.srvs[lastIdx] = Srv{} be.srvs = be.srvs[:lastIdx] return true }
[ "func", "(", "be", "*", "T", ")", "DeleteServer", "(", "beSrvKey", "engine", ".", "ServerKey", ")", "bool", "{", "be", ".", "mu", ".", "Lock", "(", ")", "\n", "defer", "be", ".", "mu", ".", "Unlock", "(", ")", "\n\n", "i", ":=", "be", ".", "indexOfServer", "(", "beSrvKey", ".", "Id", ")", "\n", "if", "i", "==", "-", "1", "{", "log", ".", "Warnf", "(", "\"", "\"", ",", "beSrvKey", ".", "Id", ",", "be", ".", "id", ")", "\n", "return", "false", "\n", "}", "\n", "be", ".", "cloneSrvCfgsIfSeen", "(", ")", "\n", "lastIdx", ":=", "len", "(", "be", ".", "srvs", ")", "-", "1", "\n", "copy", "(", "be", ".", "srvs", "[", "i", ":", "]", ",", "be", ".", "srvs", "[", "i", "+", "1", ":", "]", ")", "\n", "be", ".", "srvs", "[", "lastIdx", "]", "=", "Srv", "{", "}", "\n", "be", ".", "srvs", "=", "be", ".", "srvs", "[", ":", "lastIdx", "]", "\n", "return", "true", "\n", "}" ]
// DeleteServer deletes a new backend server.
[ "DeleteServer", "deletes", "a", "new", "backend", "server", "." ]
5fb2302c78e2db24de076c2b2c6276bf6f48ebf0
https://github.com/vulcand/vulcand/blob/5fb2302c78e2db24de076c2b2c6276bf6f48ebf0/proxy/backend/backend.go#L160-L175
11,344
vulcand/vulcand
proxy/backend/backend.go
Snapshot
func (be *T) Snapshot() (*http.Transport, []Srv) { be.mu.Lock() defer be.mu.Unlock() be.srvCfgsSeen = true return be.httpTp, be.srvs }
go
func (be *T) Snapshot() (*http.Transport, []Srv) { be.mu.Lock() defer be.mu.Unlock() be.srvCfgsSeen = true return be.httpTp, be.srvs }
[ "func", "(", "be", "*", "T", ")", "Snapshot", "(", ")", "(", "*", "http", ".", "Transport", ",", "[", "]", "Srv", ")", "{", "be", ".", "mu", ".", "Lock", "(", ")", "\n", "defer", "be", ".", "mu", ".", "Unlock", "(", ")", "\n\n", "be", ".", "srvCfgsSeen", "=", "true", "\n", "return", "be", ".", "httpTp", ",", "be", ".", "srvs", "\n", "}" ]
// Snapshot returns configured HTTP transport instance and a list of backend // servers. Due to copy-on-write semantic it is the returned server list is // immutable from callers prospective and it is efficient to call this function // as frequently as you want for it won't make excessive allocations.
[ "Snapshot", "returns", "configured", "HTTP", "transport", "instance", "and", "a", "list", "of", "backend", "servers", ".", "Due", "to", "copy", "-", "on", "-", "write", "semantic", "it", "is", "the", "returned", "server", "list", "is", "immutable", "from", "callers", "prospective", "and", "it", "is", "efficient", "to", "call", "this", "function", "as", "frequently", "as", "you", "want", "for", "it", "won", "t", "make", "excessive", "allocations", "." ]
5fb2302c78e2db24de076c2b2c6276bf6f48ebf0
https://github.com/vulcand/vulcand/blob/5fb2302c78e2db24de076c2b2c6276bf6f48ebf0/proxy/backend/backend.go#L181-L187
11,345
vulcand/vulcand
proxy/backend/backend.go
Server
func (be *T) Server(beSrvKey engine.ServerKey) (Srv, bool) { be.mu.Lock() defer be.mu.Unlock() i := be.indexOfServer(beSrvKey.Id) if i == -1 { return Srv{}, false } return be.srvs[i], true }
go
func (be *T) Server(beSrvKey engine.ServerKey) (Srv, bool) { be.mu.Lock() defer be.mu.Unlock() i := be.indexOfServer(beSrvKey.Id) if i == -1 { return Srv{}, false } return be.srvs[i], true }
[ "func", "(", "be", "*", "T", ")", "Server", "(", "beSrvKey", "engine", ".", "ServerKey", ")", "(", "Srv", ",", "bool", ")", "{", "be", ".", "mu", ".", "Lock", "(", ")", "\n", "defer", "be", ".", "mu", ".", "Unlock", "(", ")", "\n\n", "i", ":=", "be", ".", "indexOfServer", "(", "beSrvKey", ".", "Id", ")", "\n", "if", "i", "==", "-", "1", "{", "return", "Srv", "{", "}", ",", "false", "\n", "}", "\n", "return", "be", ".", "srvs", "[", "i", "]", ",", "true", "\n", "}" ]
// Server returns a backend server by a storage key if exists.
[ "Server", "returns", "a", "backend", "server", "by", "a", "storage", "key", "if", "exists", "." ]
5fb2302c78e2db24de076c2b2c6276bf6f48ebf0
https://github.com/vulcand/vulcand/blob/5fb2302c78e2db24de076c2b2c6276bf6f48ebf0/proxy/backend/backend.go#L190-L199
11,346
vulcand/vulcand
proxy/builder/builder.go
NewProxy
func NewProxy(id int, st stapler.Stapler, o proxy.Options) (proxy.Proxy, error) { return mux.New(id, st, o) }
go
func NewProxy(id int, st stapler.Stapler, o proxy.Options) (proxy.Proxy, error) { return mux.New(id, st, o) }
[ "func", "NewProxy", "(", "id", "int", ",", "st", "stapler", ".", "Stapler", ",", "o", "proxy", ".", "Options", ")", "(", "proxy", ".", "Proxy", ",", "error", ")", "{", "return", "mux", ".", "New", "(", "id", ",", "st", ",", "o", ")", "\n", "}" ]
// NewProxy returns a new Proxy instance.
[ "NewProxy", "returns", "a", "new", "Proxy", "instance", "." ]
5fb2302c78e2db24de076c2b2c6276bf6f48ebf0
https://github.com/vulcand/vulcand/blob/5fb2302c78e2db24de076c2b2c6276bf6f48ebf0/proxy/builder/builder.go#L10-L12
11,347
vulcand/vulcand
graceful/listener.go
NewListener
func NewListener(l net.Listener) *Listener { return &Listener{ listener: l, mutex: &sync.RWMutex{}, open: true, } }
go
func NewListener(l net.Listener) *Listener { return &Listener{ listener: l, mutex: &sync.RWMutex{}, open: true, } }
[ "func", "NewListener", "(", "l", "net", ".", "Listener", ")", "*", "Listener", "{", "return", "&", "Listener", "{", "listener", ":", "l", ",", "mutex", ":", "&", "sync", ".", "RWMutex", "{", "}", ",", "open", ":", "true", ",", "}", "\n", "}" ]
// NewListener wraps an existing listener for use with // GracefulServer. // // Note that you generally don't need to use this directly as // GracefulServer will automatically wrap any non-graceful listeners // supplied to it.
[ "NewListener", "wraps", "an", "existing", "listener", "for", "use", "with", "GracefulServer", ".", "Note", "that", "you", "generally", "don", "t", "need", "to", "use", "this", "directly", "as", "GracefulServer", "will", "automatically", "wrap", "any", "non", "-", "graceful", "listeners", "supplied", "to", "it", "." ]
5fb2302c78e2db24de076c2b2c6276bf6f48ebf0
https://github.com/vulcand/vulcand/blob/5fb2302c78e2db24de076c2b2c6276bf6f48ebf0/graceful/listener.go#L21-L27
11,348
vulcand/vulcand
graceful/listener.go
Accept
func (l *Listener) Accept() (net.Conn, error) { conn, err := l.listener.Accept() if err != nil { if l.isClosed() { err = fmt.Errorf("listener already closed: err=(%s)", err) } return nil, err } return conn, nil }
go
func (l *Listener) Accept() (net.Conn, error) { conn, err := l.listener.Accept() if err != nil { if l.isClosed() { err = fmt.Errorf("listener already closed: err=(%s)", err) } return nil, err } return conn, nil }
[ "func", "(", "l", "*", "Listener", ")", "Accept", "(", ")", "(", "net", ".", "Conn", ",", "error", ")", "{", "conn", ",", "err", ":=", "l", ".", "listener", ".", "Accept", "(", ")", "\n", "if", "err", "!=", "nil", "{", "if", "l", ".", "isClosed", "(", ")", "{", "err", "=", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "return", "nil", ",", "err", "\n", "}", "\n", "return", "conn", ",", "nil", "\n", "}" ]
// Accept implements the Accept method in the Listener interface.
[ "Accept", "implements", "the", "Accept", "method", "in", "the", "Listener", "interface", "." ]
5fb2302c78e2db24de076c2b2c6276bf6f48ebf0
https://github.com/vulcand/vulcand/blob/5fb2302c78e2db24de076c2b2c6276bf6f48ebf0/graceful/listener.go#L49-L58
11,349
vulcand/vulcand
graceful/listener.go
Close
func (l *Listener) Close() error { l.mutex.Lock() defer l.mutex.Unlock() if !l.open { return nil } l.open = false return l.listener.Close() }
go
func (l *Listener) Close() error { l.mutex.Lock() defer l.mutex.Unlock() if !l.open { return nil } l.open = false return l.listener.Close() }
[ "func", "(", "l", "*", "Listener", ")", "Close", "(", ")", "error", "{", "l", ".", "mutex", ".", "Lock", "(", ")", "\n", "defer", "l", ".", "mutex", ".", "Unlock", "(", ")", "\n", "if", "!", "l", ".", "open", "{", "return", "nil", "\n", "}", "\n", "l", ".", "open", "=", "false", "\n", "return", "l", ".", "listener", ".", "Close", "(", ")", "\n", "}" ]
// Close tells the wrapped listener to stop listening. It is idempotent.
[ "Close", "tells", "the", "wrapped", "listener", "to", "stop", "listening", ".", "It", "is", "idempotent", "." ]
5fb2302c78e2db24de076c2b2c6276bf6f48ebf0
https://github.com/vulcand/vulcand/blob/5fb2302c78e2db24de076c2b2c6276bf6f48ebf0/graceful/listener.go#L61-L69
11,350
vulcand/vulcand
graceful/listener.go
NewTLSListener
func NewTLSListener(inner net.Listener, config *tls.Config) net.Listener { l := new(TLSListener) l.Listener = inner l.config = config return l }
go
func NewTLSListener(inner net.Listener, config *tls.Config) net.Listener { l := new(TLSListener) l.Listener = inner l.config = config return l }
[ "func", "NewTLSListener", "(", "inner", "net", ".", "Listener", ",", "config", "*", "tls", ".", "Config", ")", "net", ".", "Listener", "{", "l", ":=", "new", "(", "TLSListener", ")", "\n", "l", ".", "Listener", "=", "inner", "\n", "l", ".", "config", "=", "config", "\n", "return", "l", "\n", "}" ]
// NewListener creates a Listener which accepts connections from an inner // Listener and wraps each connection with Server. // The configuration config must be non-nil and must have // at least one certificate.
[ "NewListener", "creates", "a", "Listener", "which", "accepts", "connections", "from", "an", "inner", "Listener", "and", "wraps", "each", "connection", "with", "Server", ".", "The", "configuration", "config", "must", "be", "non", "-", "nil", "and", "must", "have", "at", "least", "one", "certificate", "." ]
5fb2302c78e2db24de076c2b2c6276bf6f48ebf0
https://github.com/vulcand/vulcand/blob/5fb2302c78e2db24de076c2b2c6276bf6f48ebf0/graceful/listener.go#L118-L123
11,351
vulcand/vulcand
service/service.go
initLogger
func (s *Service) initLogger() { log.SetLevel(s.options.LogSeverity.S) // If LogFormatter is specified then Log is ignored. if s.options.LogFormatter != nil { log.SetOutput(os.Stdout) log.SetFormatter(s.options.LogFormatter) return } if s.options.Log == "console" { log.SetOutput(os.Stdout) log.SetFormatter(&log.TextFormatter{}) return } var err error if s.options.Log == "syslog" { var devNull *os.File devNull, err = os.OpenFile("/dev/null", os.O_WRONLY, 0) if err == nil { var hook *logrus_syslog.SyslogHook hook, err = logrus_syslog.NewSyslogHook("udp", "127.0.0.1:514", syslog.LOG_INFO|syslog.LOG_MAIL, "vulcand") if err == nil { log.SetOutput(devNull) log.SetFormatter(&log.TextFormatter{DisableColors: true}) log.AddHook(hook) return } } } if s.options.Log == "json" { log.SetOutput(os.Stdout) log.SetFormatter(&log.JSONFormatter{}) return } if s.options.Log == "logstash" { log.SetOutput(os.Stdout) log.SetFormatter(&logrus_logstash.LogstashFormatter{Fields: log.Fields{"type": "logs"}}) return } log.SetOutput(os.Stdout) log.SetFormatter(&log.TextFormatter{}) log.Warnf("Failed to initialized logger. Fallback to default: logger=%s, err=(%s)", s.options.Log, err) }
go
func (s *Service) initLogger() { log.SetLevel(s.options.LogSeverity.S) // If LogFormatter is specified then Log is ignored. if s.options.LogFormatter != nil { log.SetOutput(os.Stdout) log.SetFormatter(s.options.LogFormatter) return } if s.options.Log == "console" { log.SetOutput(os.Stdout) log.SetFormatter(&log.TextFormatter{}) return } var err error if s.options.Log == "syslog" { var devNull *os.File devNull, err = os.OpenFile("/dev/null", os.O_WRONLY, 0) if err == nil { var hook *logrus_syslog.SyslogHook hook, err = logrus_syslog.NewSyslogHook("udp", "127.0.0.1:514", syslog.LOG_INFO|syslog.LOG_MAIL, "vulcand") if err == nil { log.SetOutput(devNull) log.SetFormatter(&log.TextFormatter{DisableColors: true}) log.AddHook(hook) return } } } if s.options.Log == "json" { log.SetOutput(os.Stdout) log.SetFormatter(&log.JSONFormatter{}) return } if s.options.Log == "logstash" { log.SetOutput(os.Stdout) log.SetFormatter(&logrus_logstash.LogstashFormatter{Fields: log.Fields{"type": "logs"}}) return } log.SetOutput(os.Stdout) log.SetFormatter(&log.TextFormatter{}) log.Warnf("Failed to initialized logger. Fallback to default: logger=%s, err=(%s)", s.options.Log, err) }
[ "func", "(", "s", "*", "Service", ")", "initLogger", "(", ")", "{", "log", ".", "SetLevel", "(", "s", ".", "options", ".", "LogSeverity", ".", "S", ")", "\n", "// If LogFormatter is specified then Log is ignored.", "if", "s", ".", "options", ".", "LogFormatter", "!=", "nil", "{", "log", ".", "SetOutput", "(", "os", ".", "Stdout", ")", "\n", "log", ".", "SetFormatter", "(", "s", ".", "options", ".", "LogFormatter", ")", "\n", "return", "\n", "}", "\n", "if", "s", ".", "options", ".", "Log", "==", "\"", "\"", "{", "log", ".", "SetOutput", "(", "os", ".", "Stdout", ")", "\n", "log", ".", "SetFormatter", "(", "&", "log", ".", "TextFormatter", "{", "}", ")", "\n", "return", "\n", "}", "\n", "var", "err", "error", "\n", "if", "s", ".", "options", ".", "Log", "==", "\"", "\"", "{", "var", "devNull", "*", "os", ".", "File", "\n", "devNull", ",", "err", "=", "os", ".", "OpenFile", "(", "\"", "\"", ",", "os", ".", "O_WRONLY", ",", "0", ")", "\n", "if", "err", "==", "nil", "{", "var", "hook", "*", "logrus_syslog", ".", "SyslogHook", "\n", "hook", ",", "err", "=", "logrus_syslog", ".", "NewSyslogHook", "(", "\"", "\"", ",", "\"", "\"", ",", "syslog", ".", "LOG_INFO", "|", "syslog", ".", "LOG_MAIL", ",", "\"", "\"", ")", "\n", "if", "err", "==", "nil", "{", "log", ".", "SetOutput", "(", "devNull", ")", "\n", "log", ".", "SetFormatter", "(", "&", "log", ".", "TextFormatter", "{", "DisableColors", ":", "true", "}", ")", "\n", "log", ".", "AddHook", "(", "hook", ")", "\n", "return", "\n", "}", "\n", "}", "\n", "}", "\n", "if", "s", ".", "options", ".", "Log", "==", "\"", "\"", "{", "log", ".", "SetOutput", "(", "os", ".", "Stdout", ")", "\n", "log", ".", "SetFormatter", "(", "&", "log", ".", "JSONFormatter", "{", "}", ")", "\n", "return", "\n", "}", "\n", "if", "s", ".", "options", ".", "Log", "==", "\"", "\"", "{", "log", ".", "SetOutput", "(", "os", ".", "Stdout", ")", "\n", "log", ".", "SetFormatter", "(", "&", "logrus_logstash", ".", "LogstashFormatter", "{", "Fields", ":", "log", ".", "Fields", "{", "\"", "\"", ":", "\"", "\"", "}", "}", ")", "\n", "return", "\n", "}", "\n", "log", ".", "SetOutput", "(", "os", ".", "Stdout", ")", "\n", "log", ".", "SetFormatter", "(", "&", "log", ".", "TextFormatter", "{", "}", ")", "\n", "log", ".", "Warnf", "(", "\"", "\"", ",", "s", ".", "options", ".", "Log", ",", "err", ")", "\n", "}" ]
// initLogger initializes logger specified in the service options. This // function never fails. In case of any error a console logger with the text // formatter is initialized and the error details are logged as a warning.
[ "initLogger", "initializes", "logger", "specified", "in", "the", "service", "options", ".", "This", "function", "never", "fails", ".", "In", "case", "of", "any", "error", "a", "console", "logger", "with", "the", "text", "formatter", "is", "initialized", "and", "the", "error", "details", "are", "logged", "as", "a", "warning", "." ]
5fb2302c78e2db24de076c2b2c6276bf6f48ebf0
https://github.com/vulcand/vulcand/blob/5fb2302c78e2db24de076c2b2c6276bf6f48ebf0/service/service.go#L201-L242
11,352
vulcand/vulcand
service/service.go
filesFromString
func filesFromString(in string) ([]*proxy.FileDescriptor, error) { var out []fileDescriptor if err := json.Unmarshal([]byte(in), &out); err != nil { return nil, err } files := make([]*proxy.FileDescriptor, len(out)) for i, o := range out { files[i] = &proxy.FileDescriptor{ File: os.NewFile(uintptr(o.FileFD), o.FileName), Address: o.Address, } } return files, nil }
go
func filesFromString(in string) ([]*proxy.FileDescriptor, error) { var out []fileDescriptor if err := json.Unmarshal([]byte(in), &out); err != nil { return nil, err } files := make([]*proxy.FileDescriptor, len(out)) for i, o := range out { files[i] = &proxy.FileDescriptor{ File: os.NewFile(uintptr(o.FileFD), o.FileName), Address: o.Address, } } return files, nil }
[ "func", "filesFromString", "(", "in", "string", ")", "(", "[", "]", "*", "proxy", ".", "FileDescriptor", ",", "error", ")", "{", "var", "out", "[", "]", "fileDescriptor", "\n", "if", "err", ":=", "json", ".", "Unmarshal", "(", "[", "]", "byte", "(", "in", ")", ",", "&", "out", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "files", ":=", "make", "(", "[", "]", "*", "proxy", ".", "FileDescriptor", ",", "len", "(", "out", ")", ")", "\n", "for", "i", ",", "o", ":=", "range", "out", "{", "files", "[", "i", "]", "=", "&", "proxy", ".", "FileDescriptor", "{", "File", ":", "os", ".", "NewFile", "(", "uintptr", "(", "o", ".", "FileFD", ")", ",", "o", ".", "FileName", ")", ",", "Address", ":", "o", ".", "Address", ",", "}", "\n", "}", "\n", "return", "files", ",", "nil", "\n", "}" ]
// filesFromString de-serializes the file descriptors and turns them in the os.Files
[ "filesFromString", "de", "-", "serializes", "the", "file", "descriptors", "and", "turns", "them", "in", "the", "os", ".", "Files" ]
5fb2302c78e2db24de076c2b2c6276bf6f48ebf0
https://github.com/vulcand/vulcand/blob/5fb2302c78e2db24de076c2b2c6276bf6f48ebf0/service/service.go#L511-L524
11,353
codingsince1985/geo-golang
examples/geocoder_example.go
ExampleGeocoder
func ExampleGeocoder() { fmt.Println("Google Geocoding API") try(google.Geocoder(os.Getenv("GOOGLE_API_KEY"))) fmt.Println("Mapquest Nominatim") try(nominatim.Geocoder(os.Getenv("MAPQUEST_NOMINATIM_KEY"))) fmt.Println("Mapquest Open streetmaps") try(open.Geocoder(os.Getenv("MAPQUEST_OPEN_KEY"))) fmt.Println("OpenCage Data") try(opencage.Geocoder(os.Getenv("OPENCAGE_API_KEY"))) fmt.Println("HERE API") try(here.Geocoder(os.Getenv("HERE_APP_ID"), os.Getenv("HERE_APP_CODE"), radius)) fmt.Println("Bing Geocoding API") try(bing.Geocoder(os.Getenv("BING_API_KEY"))) fmt.Println("Mapbox API") try(mapbox.Geocoder(os.Getenv("MAPBOX_API_KEY"))) fmt.Println("OpenStreetMap") try(openstreetmap.Geocoder()) fmt.Println("PickPoint") try(pickpoint.Geocoder(os.Getenv("PICKPOINT_API_KEY"))) fmt.Println("LocationIQ") try(locationiq.Geocoder(os.Getenv("LOCATIONIQ_API_KEY"), zoom)) fmt.Println("ArcGIS") try(arcgis.Geocoder(os.Getenv("ARCGIS_TOKEN"))) fmt.Println("geocod.io") try(geocod.Geocoder(os.Getenv("GEOCOD_API_KEY"))) fmt.Println("Mapzen") try(mapzen.Geocoder(os.Getenv("MAPZEN_API_KEY"))) fmt.Println("TomTom") try(tomtom.Geocoder(os.Getenv("TOMTOM_API_KEY"))) fmt.Println("Yandex") try(yandex.Geocoder(os.Getenv("YANDEX_API_KEY"))) // Chained geocoder will fallback to subsequent geocoders fmt.Println("ChainedAPI[OpenStreetmap -> Google]") try(chained.Geocoder( openstreetmap.Geocoder(), google.Geocoder(os.Getenv("GOOGLE_API_KEY")), )) // Output: Google Geocoding API // Melbourne VIC location is (-37.813611, 144.963056) // Address of (-37.813611,144.963056) is 197 Elizabeth St, Melbourne VIC 3000, Australia // Detailed address: &geo.Address{FormattedAddress:"197 Elizabeth St, Melbourne VIC 3000, Australia", // Street:"Elizabeth Street", HouseNumber:"197", Suburb:"", Postcode:"3000", State:"Victoria", // StateDistrict:"Melbourne City", County:"", Country:"Australia", CountryCode:"AU", City:"Melbourne"} // // Mapquest Nominatim // Melbourne VIC location is (-37.814218, 144.963161) // Address of (-37.813611,144.963056) is Melbourne's GPO, Postal Lane, Melbourne, City of Melbourne, Greater Melbourne, Victoria, 3000, Australia // Detailed address: &geo.Address{FormattedAddress:"Melbourne's GPO, Postal Lane, Melbourne, City of Melbourne, // Greater Melbourne, Victoria, 3000, Australia", Street:"Postal Lane", HouseNumber:"", Suburb:"Melbourne", // Postcode:"3000", State:"Victoria", StateDistrict:"", County:"City of Melbourne", Country:"Australia", CountryCode:"AU", City:"Melbourne"} // // Mapquest Open streetmaps // Melbourne VIC location is (-37.814218, 144.963161) // Address of (-37.813611,144.963056) is Elizabeth Street, Melbourne, Victoria, AU // Detailed address: &geo.Address{FormattedAddress:"Elizabeth Street, 3000, Melbourne, Victoria, AU", // Street:"Elizabeth Street", HouseNumber:"", Suburb:"", Postcode:"3000", State:"Victoria", StateDistrict:"", // County:"", Country:"", CountryCode:"AU", City:"Melbourne"} // // OpenCage Data // Melbourne VIC location is (-37.814217, 144.963161) // Address of (-37.813611,144.963056) is Melbourne's GPO, Postal Lane, Melbourne VIC 3000, Australia // Detailed address: &geo.Address{FormattedAddress:"Melbourne's GPO, Postal Lane, Melbourne VIC 3000, Australia", // Street:"Postal Lane", HouseNumber:"", Suburb:"Melbourne (3000)", Postcode:"3000", State:"Victoria", // StateDistrict:"", County:"City of Melbourne", Country:"Australia", CountryCode:"AU", City:"Melbourne"} // // HERE API // Melbourne VIC location is (-37.817530, 144.967150) // Address of (-37.813611,144.963056) is 197 Elizabeth St, Melbourne VIC 3000, Australia // Detailed address: &geo.Address{FormattedAddress:"197 Elizabeth St, Melbourne VIC 3000, Australia", Street:"Elizabeth St", // HouseNumber:"197", Suburb:"", Postcode:"3000", State:"Victoria", StateDistrict:"", County:"", Country:"Australia", // CountryCode:"AUS", City:"Melbourne"} // // Bing Geocoding API // Melbourne VIC location is (-37.824299, 144.977997) // Address of (-37.813611,144.963056) is Elizabeth St, Melbourne, VIC 3000 // Detailed address: &geo.Address{FormattedAddress:"Elizabeth St, Melbourne, VIC 3000", Street:"Elizabeth St", // HouseNumber:"", Suburb:"", Postcode:"3000", State:"", StateDistrict:"", County:"", Country:"Australia", CountryCode:"", City:"Melbourne"} // // Mapbox API // Melbourne VIC location is (-37.814200, 144.963200) // Address of (-37.813611,144.963056) is Elwood Park Playground, Melbourne, Victoria 3000, Australia // Detailed address: &geo.Address{FormattedAddress:"Elwood Park Playground, Melbourne, Victoria 3000, Australia", // Street:"Elwood Park Playground", HouseNumber:"", Suburb:"", Postcode:"3000", State:"Victoria", StateDistrict:"", // County:"", Country:"Australia", CountryCode:"AU", City:"Melbourne"} // // OpenStreetMap // Melbourne VIC location is (-37.814217, 144.963161) // Address of (-37.813611,144.963056) is Melbourne's GPO, Postal Lane, Chinatown, Melbourne, City of Melbourne, Greater Melbourne, Victoria, 3000, Australia // Detailed address: &geo.Address{FormattedAddress:"Melbourne's GPO, Postal Lane, Chinatown, Melbourne, City of Melbourne, Greater Melbourne, // Victoria, 3000, Australia", Street:"Postal Lane", HouseNumber:"", Suburb:"Melbourne", Postcode:"3000", State:"Victoria", // StateDistrict:"", County:"", Country:"Australia", CountryCode:"AU", City:"Melbourne"} // // PickPoint // Melbourne VIC location is (-37.814217, 144.963161) // Address of (-37.813611,144.963056) is Melbourne's GPO, Postal Lane, Chinatown, Melbourne, City of Melbourne, Greater Melbourne, Victoria, 3000, Australia // Detailed address: &geo.Address{FormattedAddress:"Melbourne's GPO, Postal Lane, Chinatown, Melbourne, City of Melbourne, Greater Melbourne, // Victoria, 3000, Australia", Street:"Postal Lane", HouseNumber:"", Suburb:"Melbourne", Postcode:"3000", State:"Victoria", // StateDistrict:"", County:"", Country:"Australia", CountryCode:"AU", City:"Melbourne"} // // LocationIQ // Melbourne VIC location is (-37.814217, 144.963161) // Address of (-37.813611,144.963056) is Melbourne's GPO, Postal Lane, Chinatown, Melbourne, City of Melbourne, Greater Melbourne, Victoria, 3000, Australia // Detailed address: &geo.Address{FormattedAddress:"Melbourne's GPO, Postal Lane, Chinatown, Melbourne, City of Melbourne, Greater Melbourne, // Victoria, 3000, Australia", Street:"Postal Lane", HouseNumber:"", Suburb:"Melbourne", Postcode:"3000", State:"Victoria", // StateDistrict:"", County:"", Country:"Australia", CountryCode:"AU", City:"Melbourne"} // // ArcGIS // Melbourne VIC location is (-37.817530, 144.967150) // Address of (-37.813611,144.963056) is Melbourne's Gpo // Detailed address: &geo.Address{FormattedAddress:"Melbourne's Gpo", Street:"350 Bourke Street Mall", HouseNumber:"350", Suburb:"", Postcode:"3000", State:"Victoria", StateDistrict:"", County:"", Country:"", CountryCode:"AUS", City:""} // // geocod.io // Melbourne VIC location is (28.079357, -80.623618) // got <nil> address // // Mapzen // Melbourne VIC location is (45.551136, 11.533929) // Address of (-37.813611,144.963056) is Stop 3: Bourke Street Mall, Bourke Street, Melbourne, Australia // Detailed address: &geo.Address{FormattedAddress:"Stop 3: Bourke Street Mall, Bourke Street, Melbourne, Australia", Street:"", HouseNumber:"", Suburb:"", Postcode:"", State:"Victoria", StateDistrict:"", County:"", Country:"Australia", CountryCode:"AUS", City:""} // // TomTom // Melbourne VIC location is (-37.815340, 144.963230) // Address of (-37.813611,144.963056) is Doyles Road, Elaine, West Central Victoria, Victoria, 3334 // Detailed address: &geo.Address{FormattedAddress:"Doyles Road, Elaine, West Central Victoria, Victoria, 3334", Street:"Doyles Road", HouseNumber:"", Suburb:"", Postcode:"3334", State:"Victoria", StateDistrict:"", County:"", Country:"Australia", CountryCode:"AU", City:"Elaine"} // // Yandex // Melbourne VIC location is (41.926823, 2.254232) // Address of (-37.813611,144.963056) is Victoria, City of Melbourne, Elizabeth Street // Detailed address: &geo.Address{FormattedAddress:"Victoria, City of Melbourne, Elizabeth Street", Street:"Elizabeth Street", // HouseNumber:"", Suburb:"", Postcode:"", State:"Victoria", StateDistrict:"", County:"", Country:"Australia", CountryCode:"AU", // City:"City of Melbourne"} // // ChainedAPI[OpenStreetmap -> Google] // Melbourne VIC location is (-37.814217, 144.963161) // Address of (-37.813611,144.963056) is Melbourne's GPO, Postal Lane, Chinatown, Melbourne, City of Melbourne, Greater Melbourne, Victoria, 3000, Australia // Detailed address: &geo.Address{FormattedAddress:"Melbourne's GPO, Postal Lane, Chinatown, Melbourne, City of Melbourne, Greater Melbourne, // Victoria, 3000, Australia", Street:"Postal Lane", HouseNumber:"", Suburb:"Melbourne", Postcode:"3000", State:"Victoria", // StateDistrict:"", County:"", Country:"Australia", CountryCode:"AU", City:"Melbourne"} }
go
func ExampleGeocoder() { fmt.Println("Google Geocoding API") try(google.Geocoder(os.Getenv("GOOGLE_API_KEY"))) fmt.Println("Mapquest Nominatim") try(nominatim.Geocoder(os.Getenv("MAPQUEST_NOMINATIM_KEY"))) fmt.Println("Mapquest Open streetmaps") try(open.Geocoder(os.Getenv("MAPQUEST_OPEN_KEY"))) fmt.Println("OpenCage Data") try(opencage.Geocoder(os.Getenv("OPENCAGE_API_KEY"))) fmt.Println("HERE API") try(here.Geocoder(os.Getenv("HERE_APP_ID"), os.Getenv("HERE_APP_CODE"), radius)) fmt.Println("Bing Geocoding API") try(bing.Geocoder(os.Getenv("BING_API_KEY"))) fmt.Println("Mapbox API") try(mapbox.Geocoder(os.Getenv("MAPBOX_API_KEY"))) fmt.Println("OpenStreetMap") try(openstreetmap.Geocoder()) fmt.Println("PickPoint") try(pickpoint.Geocoder(os.Getenv("PICKPOINT_API_KEY"))) fmt.Println("LocationIQ") try(locationiq.Geocoder(os.Getenv("LOCATIONIQ_API_KEY"), zoom)) fmt.Println("ArcGIS") try(arcgis.Geocoder(os.Getenv("ARCGIS_TOKEN"))) fmt.Println("geocod.io") try(geocod.Geocoder(os.Getenv("GEOCOD_API_KEY"))) fmt.Println("Mapzen") try(mapzen.Geocoder(os.Getenv("MAPZEN_API_KEY"))) fmt.Println("TomTom") try(tomtom.Geocoder(os.Getenv("TOMTOM_API_KEY"))) fmt.Println("Yandex") try(yandex.Geocoder(os.Getenv("YANDEX_API_KEY"))) // Chained geocoder will fallback to subsequent geocoders fmt.Println("ChainedAPI[OpenStreetmap -> Google]") try(chained.Geocoder( openstreetmap.Geocoder(), google.Geocoder(os.Getenv("GOOGLE_API_KEY")), )) // Output: Google Geocoding API // Melbourne VIC location is (-37.813611, 144.963056) // Address of (-37.813611,144.963056) is 197 Elizabeth St, Melbourne VIC 3000, Australia // Detailed address: &geo.Address{FormattedAddress:"197 Elizabeth St, Melbourne VIC 3000, Australia", // Street:"Elizabeth Street", HouseNumber:"197", Suburb:"", Postcode:"3000", State:"Victoria", // StateDistrict:"Melbourne City", County:"", Country:"Australia", CountryCode:"AU", City:"Melbourne"} // // Mapquest Nominatim // Melbourne VIC location is (-37.814218, 144.963161) // Address of (-37.813611,144.963056) is Melbourne's GPO, Postal Lane, Melbourne, City of Melbourne, Greater Melbourne, Victoria, 3000, Australia // Detailed address: &geo.Address{FormattedAddress:"Melbourne's GPO, Postal Lane, Melbourne, City of Melbourne, // Greater Melbourne, Victoria, 3000, Australia", Street:"Postal Lane", HouseNumber:"", Suburb:"Melbourne", // Postcode:"3000", State:"Victoria", StateDistrict:"", County:"City of Melbourne", Country:"Australia", CountryCode:"AU", City:"Melbourne"} // // Mapquest Open streetmaps // Melbourne VIC location is (-37.814218, 144.963161) // Address of (-37.813611,144.963056) is Elizabeth Street, Melbourne, Victoria, AU // Detailed address: &geo.Address{FormattedAddress:"Elizabeth Street, 3000, Melbourne, Victoria, AU", // Street:"Elizabeth Street", HouseNumber:"", Suburb:"", Postcode:"3000", State:"Victoria", StateDistrict:"", // County:"", Country:"", CountryCode:"AU", City:"Melbourne"} // // OpenCage Data // Melbourne VIC location is (-37.814217, 144.963161) // Address of (-37.813611,144.963056) is Melbourne's GPO, Postal Lane, Melbourne VIC 3000, Australia // Detailed address: &geo.Address{FormattedAddress:"Melbourne's GPO, Postal Lane, Melbourne VIC 3000, Australia", // Street:"Postal Lane", HouseNumber:"", Suburb:"Melbourne (3000)", Postcode:"3000", State:"Victoria", // StateDistrict:"", County:"City of Melbourne", Country:"Australia", CountryCode:"AU", City:"Melbourne"} // // HERE API // Melbourne VIC location is (-37.817530, 144.967150) // Address of (-37.813611,144.963056) is 197 Elizabeth St, Melbourne VIC 3000, Australia // Detailed address: &geo.Address{FormattedAddress:"197 Elizabeth St, Melbourne VIC 3000, Australia", Street:"Elizabeth St", // HouseNumber:"197", Suburb:"", Postcode:"3000", State:"Victoria", StateDistrict:"", County:"", Country:"Australia", // CountryCode:"AUS", City:"Melbourne"} // // Bing Geocoding API // Melbourne VIC location is (-37.824299, 144.977997) // Address of (-37.813611,144.963056) is Elizabeth St, Melbourne, VIC 3000 // Detailed address: &geo.Address{FormattedAddress:"Elizabeth St, Melbourne, VIC 3000", Street:"Elizabeth St", // HouseNumber:"", Suburb:"", Postcode:"3000", State:"", StateDistrict:"", County:"", Country:"Australia", CountryCode:"", City:"Melbourne"} // // Mapbox API // Melbourne VIC location is (-37.814200, 144.963200) // Address of (-37.813611,144.963056) is Elwood Park Playground, Melbourne, Victoria 3000, Australia // Detailed address: &geo.Address{FormattedAddress:"Elwood Park Playground, Melbourne, Victoria 3000, Australia", // Street:"Elwood Park Playground", HouseNumber:"", Suburb:"", Postcode:"3000", State:"Victoria", StateDistrict:"", // County:"", Country:"Australia", CountryCode:"AU", City:"Melbourne"} // // OpenStreetMap // Melbourne VIC location is (-37.814217, 144.963161) // Address of (-37.813611,144.963056) is Melbourne's GPO, Postal Lane, Chinatown, Melbourne, City of Melbourne, Greater Melbourne, Victoria, 3000, Australia // Detailed address: &geo.Address{FormattedAddress:"Melbourne's GPO, Postal Lane, Chinatown, Melbourne, City of Melbourne, Greater Melbourne, // Victoria, 3000, Australia", Street:"Postal Lane", HouseNumber:"", Suburb:"Melbourne", Postcode:"3000", State:"Victoria", // StateDistrict:"", County:"", Country:"Australia", CountryCode:"AU", City:"Melbourne"} // // PickPoint // Melbourne VIC location is (-37.814217, 144.963161) // Address of (-37.813611,144.963056) is Melbourne's GPO, Postal Lane, Chinatown, Melbourne, City of Melbourne, Greater Melbourne, Victoria, 3000, Australia // Detailed address: &geo.Address{FormattedAddress:"Melbourne's GPO, Postal Lane, Chinatown, Melbourne, City of Melbourne, Greater Melbourne, // Victoria, 3000, Australia", Street:"Postal Lane", HouseNumber:"", Suburb:"Melbourne", Postcode:"3000", State:"Victoria", // StateDistrict:"", County:"", Country:"Australia", CountryCode:"AU", City:"Melbourne"} // // LocationIQ // Melbourne VIC location is (-37.814217, 144.963161) // Address of (-37.813611,144.963056) is Melbourne's GPO, Postal Lane, Chinatown, Melbourne, City of Melbourne, Greater Melbourne, Victoria, 3000, Australia // Detailed address: &geo.Address{FormattedAddress:"Melbourne's GPO, Postal Lane, Chinatown, Melbourne, City of Melbourne, Greater Melbourne, // Victoria, 3000, Australia", Street:"Postal Lane", HouseNumber:"", Suburb:"Melbourne", Postcode:"3000", State:"Victoria", // StateDistrict:"", County:"", Country:"Australia", CountryCode:"AU", City:"Melbourne"} // // ArcGIS // Melbourne VIC location is (-37.817530, 144.967150) // Address of (-37.813611,144.963056) is Melbourne's Gpo // Detailed address: &geo.Address{FormattedAddress:"Melbourne's Gpo", Street:"350 Bourke Street Mall", HouseNumber:"350", Suburb:"", Postcode:"3000", State:"Victoria", StateDistrict:"", County:"", Country:"", CountryCode:"AUS", City:""} // // geocod.io // Melbourne VIC location is (28.079357, -80.623618) // got <nil> address // // Mapzen // Melbourne VIC location is (45.551136, 11.533929) // Address of (-37.813611,144.963056) is Stop 3: Bourke Street Mall, Bourke Street, Melbourne, Australia // Detailed address: &geo.Address{FormattedAddress:"Stop 3: Bourke Street Mall, Bourke Street, Melbourne, Australia", Street:"", HouseNumber:"", Suburb:"", Postcode:"", State:"Victoria", StateDistrict:"", County:"", Country:"Australia", CountryCode:"AUS", City:""} // // TomTom // Melbourne VIC location is (-37.815340, 144.963230) // Address of (-37.813611,144.963056) is Doyles Road, Elaine, West Central Victoria, Victoria, 3334 // Detailed address: &geo.Address{FormattedAddress:"Doyles Road, Elaine, West Central Victoria, Victoria, 3334", Street:"Doyles Road", HouseNumber:"", Suburb:"", Postcode:"3334", State:"Victoria", StateDistrict:"", County:"", Country:"Australia", CountryCode:"AU", City:"Elaine"} // // Yandex // Melbourne VIC location is (41.926823, 2.254232) // Address of (-37.813611,144.963056) is Victoria, City of Melbourne, Elizabeth Street // Detailed address: &geo.Address{FormattedAddress:"Victoria, City of Melbourne, Elizabeth Street", Street:"Elizabeth Street", // HouseNumber:"", Suburb:"", Postcode:"", State:"Victoria", StateDistrict:"", County:"", Country:"Australia", CountryCode:"AU", // City:"City of Melbourne"} // // ChainedAPI[OpenStreetmap -> Google] // Melbourne VIC location is (-37.814217, 144.963161) // Address of (-37.813611,144.963056) is Melbourne's GPO, Postal Lane, Chinatown, Melbourne, City of Melbourne, Greater Melbourne, Victoria, 3000, Australia // Detailed address: &geo.Address{FormattedAddress:"Melbourne's GPO, Postal Lane, Chinatown, Melbourne, City of Melbourne, Greater Melbourne, // Victoria, 3000, Australia", Street:"Postal Lane", HouseNumber:"", Suburb:"Melbourne", Postcode:"3000", State:"Victoria", // StateDistrict:"", County:"", Country:"Australia", CountryCode:"AU", City:"Melbourne"} }
[ "func", "ExampleGeocoder", "(", ")", "{", "fmt", ".", "Println", "(", "\"", "\"", ")", "\n", "try", "(", "google", ".", "Geocoder", "(", "os", ".", "Getenv", "(", "\"", "\"", ")", ")", ")", "\n\n", "fmt", ".", "Println", "(", "\"", "\"", ")", "\n", "try", "(", "nominatim", ".", "Geocoder", "(", "os", ".", "Getenv", "(", "\"", "\"", ")", ")", ")", "\n\n", "fmt", ".", "Println", "(", "\"", "\"", ")", "\n", "try", "(", "open", ".", "Geocoder", "(", "os", ".", "Getenv", "(", "\"", "\"", ")", ")", ")", "\n\n", "fmt", ".", "Println", "(", "\"", "\"", ")", "\n", "try", "(", "opencage", ".", "Geocoder", "(", "os", ".", "Getenv", "(", "\"", "\"", ")", ")", ")", "\n\n", "fmt", ".", "Println", "(", "\"", "\"", ")", "\n", "try", "(", "here", ".", "Geocoder", "(", "os", ".", "Getenv", "(", "\"", "\"", ")", ",", "os", ".", "Getenv", "(", "\"", "\"", ")", ",", "radius", ")", ")", "\n\n", "fmt", ".", "Println", "(", "\"", "\"", ")", "\n", "try", "(", "bing", ".", "Geocoder", "(", "os", ".", "Getenv", "(", "\"", "\"", ")", ")", ")", "\n\n", "fmt", ".", "Println", "(", "\"", "\"", ")", "\n", "try", "(", "mapbox", ".", "Geocoder", "(", "os", ".", "Getenv", "(", "\"", "\"", ")", ")", ")", "\n\n", "fmt", ".", "Println", "(", "\"", "\"", ")", "\n", "try", "(", "openstreetmap", ".", "Geocoder", "(", ")", ")", "\n\n", "fmt", ".", "Println", "(", "\"", "\"", ")", "\n", "try", "(", "pickpoint", ".", "Geocoder", "(", "os", ".", "Getenv", "(", "\"", "\"", ")", ")", ")", "\n\n", "fmt", ".", "Println", "(", "\"", "\"", ")", "\n", "try", "(", "locationiq", ".", "Geocoder", "(", "os", ".", "Getenv", "(", "\"", "\"", ")", ",", "zoom", ")", ")", "\n\n", "fmt", ".", "Println", "(", "\"", "\"", ")", "\n", "try", "(", "arcgis", ".", "Geocoder", "(", "os", ".", "Getenv", "(", "\"", "\"", ")", ")", ")", "\n\n", "fmt", ".", "Println", "(", "\"", "\"", ")", "\n", "try", "(", "geocod", ".", "Geocoder", "(", "os", ".", "Getenv", "(", "\"", "\"", ")", ")", ")", "\n\n", "fmt", ".", "Println", "(", "\"", "\"", ")", "\n", "try", "(", "mapzen", ".", "Geocoder", "(", "os", ".", "Getenv", "(", "\"", "\"", ")", ")", ")", "\n\n", "fmt", ".", "Println", "(", "\"", "\"", ")", "\n", "try", "(", "tomtom", ".", "Geocoder", "(", "os", ".", "Getenv", "(", "\"", "\"", ")", ")", ")", "\n\n", "fmt", ".", "Println", "(", "\"", "\"", ")", "\n", "try", "(", "yandex", ".", "Geocoder", "(", "os", ".", "Getenv", "(", "\"", "\"", ")", ")", ")", "\n\n", "// Chained geocoder will fallback to subsequent geocoders", "fmt", ".", "Println", "(", "\"", "\"", ")", "\n", "try", "(", "chained", ".", "Geocoder", "(", "openstreetmap", ".", "Geocoder", "(", ")", ",", "google", ".", "Geocoder", "(", "os", ".", "Getenv", "(", "\"", "\"", ")", ")", ",", ")", ")", "\n", "// Output: Google Geocoding API", "// Melbourne VIC location is (-37.813611, 144.963056)", "// Address of (-37.813611,144.963056) is 197 Elizabeth St, Melbourne VIC 3000, Australia", "// Detailed address: &geo.Address{FormattedAddress:\"197 Elizabeth St, Melbourne VIC 3000, Australia\",", "// \tStreet:\"Elizabeth Street\", HouseNumber:\"197\", Suburb:\"\", Postcode:\"3000\", State:\"Victoria\",", "// \tStateDistrict:\"Melbourne City\", County:\"\", Country:\"Australia\", CountryCode:\"AU\", City:\"Melbourne\"}", "//", "// Mapquest Nominatim", "// Melbourne VIC location is (-37.814218, 144.963161)", "// Address of (-37.813611,144.963056) is Melbourne's GPO, Postal Lane, Melbourne, City of Melbourne, Greater Melbourne, Victoria, 3000, Australia", "// Detailed address: &geo.Address{FormattedAddress:\"Melbourne's GPO, Postal Lane, Melbourne, City of Melbourne,", "// \tGreater Melbourne, Victoria, 3000, Australia\", Street:\"Postal Lane\", HouseNumber:\"\", Suburb:\"Melbourne\",", "// \tPostcode:\"3000\", State:\"Victoria\", StateDistrict:\"\", County:\"City of Melbourne\", Country:\"Australia\", CountryCode:\"AU\", City:\"Melbourne\"}", "//", "// Mapquest Open streetmaps", "// Melbourne VIC location is (-37.814218, 144.963161)", "// Address of (-37.813611,144.963056) is Elizabeth Street, Melbourne, Victoria, AU", "// Detailed address: &geo.Address{FormattedAddress:\"Elizabeth Street, 3000, Melbourne, Victoria, AU\",", "// \tStreet:\"Elizabeth Street\", HouseNumber:\"\", Suburb:\"\", Postcode:\"3000\", State:\"Victoria\", StateDistrict:\"\",", "// \tCounty:\"\", Country:\"\", CountryCode:\"AU\", City:\"Melbourne\"}", "//", "// OpenCage Data", "// Melbourne VIC location is (-37.814217, 144.963161)", "// Address of (-37.813611,144.963056) is Melbourne's GPO, Postal Lane, Melbourne VIC 3000, Australia", "// Detailed address: &geo.Address{FormattedAddress:\"Melbourne's GPO, Postal Lane, Melbourne VIC 3000, Australia\",", "// \tStreet:\"Postal Lane\", HouseNumber:\"\", Suburb:\"Melbourne (3000)\", Postcode:\"3000\", State:\"Victoria\",", "// \tStateDistrict:\"\", County:\"City of Melbourne\", Country:\"Australia\", CountryCode:\"AU\", City:\"Melbourne\"}", "//", "// HERE API", "// Melbourne VIC location is (-37.817530, 144.967150)", "// Address of (-37.813611,144.963056) is 197 Elizabeth St, Melbourne VIC 3000, Australia", "// Detailed address: &geo.Address{FormattedAddress:\"197 Elizabeth St, Melbourne VIC 3000, Australia\", Street:\"Elizabeth St\",", "// \tHouseNumber:\"197\", Suburb:\"\", Postcode:\"3000\", State:\"Victoria\", StateDistrict:\"\", County:\"\", Country:\"Australia\",", "// \tCountryCode:\"AUS\", City:\"Melbourne\"}", "//", "// Bing Geocoding API", "// Melbourne VIC location is (-37.824299, 144.977997)", "// Address of (-37.813611,144.963056) is Elizabeth St, Melbourne, VIC 3000", "// Detailed address: &geo.Address{FormattedAddress:\"Elizabeth St, Melbourne, VIC 3000\", Street:\"Elizabeth St\",", "// \tHouseNumber:\"\", Suburb:\"\", Postcode:\"3000\", State:\"\", StateDistrict:\"\", County:\"\", Country:\"Australia\", CountryCode:\"\", City:\"Melbourne\"}", "//", "// Mapbox API", "// Melbourne VIC location is (-37.814200, 144.963200)", "// Address of (-37.813611,144.963056) is Elwood Park Playground, Melbourne, Victoria 3000, Australia", "// Detailed address: &geo.Address{FormattedAddress:\"Elwood Park Playground, Melbourne, Victoria 3000, Australia\",", "// \tStreet:\"Elwood Park Playground\", HouseNumber:\"\", Suburb:\"\", Postcode:\"3000\", State:\"Victoria\", StateDistrict:\"\",", "// \tCounty:\"\", Country:\"Australia\", CountryCode:\"AU\", City:\"Melbourne\"}", "//", "// OpenStreetMap", "// Melbourne VIC location is (-37.814217, 144.963161)", "// Address of (-37.813611,144.963056) is Melbourne's GPO, Postal Lane, Chinatown, Melbourne, City of Melbourne, Greater Melbourne, Victoria, 3000, Australia", "// Detailed address: &geo.Address{FormattedAddress:\"Melbourne's GPO, Postal Lane, Chinatown, Melbourne, City of Melbourne, Greater Melbourne,", "// \tVictoria, 3000, Australia\", Street:\"Postal Lane\", HouseNumber:\"\", Suburb:\"Melbourne\", Postcode:\"3000\", State:\"Victoria\",", "// \tStateDistrict:\"\", County:\"\", Country:\"Australia\", CountryCode:\"AU\", City:\"Melbourne\"}", "//", "// PickPoint", "// Melbourne VIC location is (-37.814217, 144.963161)", "// Address of (-37.813611,144.963056) is Melbourne's GPO, Postal Lane, Chinatown, Melbourne, City of Melbourne, Greater Melbourne, Victoria, 3000, Australia", "// Detailed address: &geo.Address{FormattedAddress:\"Melbourne's GPO, Postal Lane, Chinatown, Melbourne, City of Melbourne, Greater Melbourne,", "// \tVictoria, 3000, Australia\", Street:\"Postal Lane\", HouseNumber:\"\", Suburb:\"Melbourne\", Postcode:\"3000\", State:\"Victoria\",", "// \tStateDistrict:\"\", County:\"\", Country:\"Australia\", CountryCode:\"AU\", City:\"Melbourne\"}", "//", "// LocationIQ", "// Melbourne VIC location is (-37.814217, 144.963161)", "// Address of (-37.813611,144.963056) is Melbourne's GPO, Postal Lane, Chinatown, Melbourne, City of Melbourne, Greater Melbourne, Victoria, 3000, Australia", "// Detailed address: &geo.Address{FormattedAddress:\"Melbourne's GPO, Postal Lane, Chinatown, Melbourne, City of Melbourne, Greater Melbourne,", "// \tVictoria, 3000, Australia\", Street:\"Postal Lane\", HouseNumber:\"\", Suburb:\"Melbourne\", Postcode:\"3000\", State:\"Victoria\",", "// \tStateDistrict:\"\", County:\"\", Country:\"Australia\", CountryCode:\"AU\", City:\"Melbourne\"}", "//", "// ArcGIS", "// Melbourne VIC location is (-37.817530, 144.967150)", "// Address of (-37.813611,144.963056) is Melbourne's Gpo", "// Detailed address: &geo.Address{FormattedAddress:\"Melbourne's Gpo\", Street:\"350 Bourke Street Mall\", HouseNumber:\"350\", Suburb:\"\", Postcode:\"3000\", State:\"Victoria\", StateDistrict:\"\", County:\"\", Country:\"\", CountryCode:\"AUS\", City:\"\"}", "//", "// geocod.io", "// Melbourne VIC location is (28.079357, -80.623618)", "// got <nil> address", "//", "// Mapzen", "// Melbourne VIC location is (45.551136, 11.533929)", "// Address of (-37.813611,144.963056) is Stop 3: Bourke Street Mall, Bourke Street, Melbourne, Australia", "// Detailed address: &geo.Address{FormattedAddress:\"Stop 3: Bourke Street Mall, Bourke Street, Melbourne, Australia\", Street:\"\", HouseNumber:\"\", Suburb:\"\", Postcode:\"\", State:\"Victoria\", StateDistrict:\"\", County:\"\", Country:\"Australia\", CountryCode:\"AUS\", City:\"\"}", "//", "// TomTom", "// Melbourne VIC location is (-37.815340, 144.963230)", "// Address of (-37.813611,144.963056) is Doyles Road, Elaine, West Central Victoria, Victoria, 3334", "// Detailed address: &geo.Address{FormattedAddress:\"Doyles Road, Elaine, West Central Victoria, Victoria, 3334\", Street:\"Doyles Road\", HouseNumber:\"\", Suburb:\"\", Postcode:\"3334\", State:\"Victoria\", StateDistrict:\"\", County:\"\", Country:\"Australia\", CountryCode:\"AU\", City:\"Elaine\"}", "//", "// Yandex", "// Melbourne VIC location is (41.926823, 2.254232)", "// Address of (-37.813611,144.963056) is Victoria, City of Melbourne, Elizabeth Street", "// Detailed address: &geo.Address{FormattedAddress:\"Victoria, City of Melbourne, Elizabeth Street\", Street:\"Elizabeth Street\",", "// HouseNumber:\"\", Suburb:\"\", Postcode:\"\", State:\"Victoria\", StateDistrict:\"\", County:\"\", Country:\"Australia\", CountryCode:\"AU\",", "// City:\"City of Melbourne\"}", "//", "// ChainedAPI[OpenStreetmap -> Google]", "// Melbourne VIC location is (-37.814217, 144.963161)", "// Address of (-37.813611,144.963056) is Melbourne's GPO, Postal Lane, Chinatown, Melbourne, City of Melbourne, Greater Melbourne, Victoria, 3000, Australia", "// Detailed address: &geo.Address{FormattedAddress:\"Melbourne's GPO, Postal Lane, Chinatown, Melbourne, City of Melbourne, Greater Melbourne,", "// \tVictoria, 3000, Australia\", Street:\"Postal Lane\", HouseNumber:\"\", Suburb:\"Melbourne\", Postcode:\"3000\", State:\"Victoria\",", "// \tStateDistrict:\"\", County:\"\", Country:\"Australia\", CountryCode:\"AU\", City:\"Melbourne\"}", "}" ]
// ExampleGeocoder demonstrates the different geocoding services
[ "ExampleGeocoder", "demonstrates", "the", "different", "geocoding", "services" ]
d393bef084a8e317ed96087b35943f87a228eac6
https://github.com/codingsince1985/geo-golang/blob/d393bef084a8e317ed96087b35943f87a228eac6/examples/geocoder_example.go#L38-L191
11,354
codingsince1985/geo-golang
locationiq/geocoder.go
Geocoder
func Geocoder(k string, z int, baseURLs ...string) geo.Geocoder { key = k var url string if len(baseURLs) > 0 { url = baseURLs[0] } else { url = defaultURL } if z > minZoom && z <= maxZoom { zoom = z } else { zoom = defaultZoom } return geo.HTTPGeocoder{ EndpointBuilder: baseURL(url), ResponseParserFactory: func() geo.ResponseParser { return &geocodeResponse{} }, } }
go
func Geocoder(k string, z int, baseURLs ...string) geo.Geocoder { key = k var url string if len(baseURLs) > 0 { url = baseURLs[0] } else { url = defaultURL } if z > minZoom && z <= maxZoom { zoom = z } else { zoom = defaultZoom } return geo.HTTPGeocoder{ EndpointBuilder: baseURL(url), ResponseParserFactory: func() geo.ResponseParser { return &geocodeResponse{} }, } }
[ "func", "Geocoder", "(", "k", "string", ",", "z", "int", ",", "baseURLs", "...", "string", ")", "geo", ".", "Geocoder", "{", "key", "=", "k", "\n\n", "var", "url", "string", "\n", "if", "len", "(", "baseURLs", ")", ">", "0", "{", "url", "=", "baseURLs", "[", "0", "]", "\n", "}", "else", "{", "url", "=", "defaultURL", "\n", "}", "\n\n", "if", "z", ">", "minZoom", "&&", "z", "<=", "maxZoom", "{", "zoom", "=", "z", "\n", "}", "else", "{", "zoom", "=", "defaultZoom", "\n", "}", "\n\n", "return", "geo", ".", "HTTPGeocoder", "{", "EndpointBuilder", ":", "baseURL", "(", "url", ")", ",", "ResponseParserFactory", ":", "func", "(", ")", "geo", ".", "ResponseParser", "{", "return", "&", "geocodeResponse", "{", "}", "}", ",", "}", "\n", "}" ]
// Geocoder constructs LocationIQ geocoder
[ "Geocoder", "constructs", "LocationIQ", "geocoder" ]
d393bef084a8e317ed96087b35943f87a228eac6
https://github.com/codingsince1985/geo-golang/blob/d393bef084a8e317ed96087b35943f87a228eac6/locationiq/geocoder.go#L33-L53
11,355
codingsince1985/geo-golang
data/geocoder.go
Geocoder
func Geocoder(addressToLocation AddressToLocation, LocationToAddress LocationToAddress) geo.Geocoder { return dataGeocoder{ AddressToLocation: addressToLocation, LocationToAddress: LocationToAddress, } }
go
func Geocoder(addressToLocation AddressToLocation, LocationToAddress LocationToAddress) geo.Geocoder { return dataGeocoder{ AddressToLocation: addressToLocation, LocationToAddress: LocationToAddress, } }
[ "func", "Geocoder", "(", "addressToLocation", "AddressToLocation", ",", "LocationToAddress", "LocationToAddress", ")", "geo", ".", "Geocoder", "{", "return", "dataGeocoder", "{", "AddressToLocation", ":", "addressToLocation", ",", "LocationToAddress", ":", "LocationToAddress", ",", "}", "\n", "}" ]
// Geocoder constructs data geocoder
[ "Geocoder", "constructs", "data", "geocoder" ]
d393bef084a8e317ed96087b35943f87a228eac6
https://github.com/codingsince1985/geo-golang/blob/d393bef084a8e317ed96087b35943f87a228eac6/data/geocoder.go#L20-L25
11,356
codingsince1985/geo-golang
cached/geocoder.go
Geocoder
func Geocoder(geocoder geo.Geocoder, cache *cache.Cache) geo.Geocoder { return cachedGeocoder{Geocoder: geocoder, Cache: cache} }
go
func Geocoder(geocoder geo.Geocoder, cache *cache.Cache) geo.Geocoder { return cachedGeocoder{Geocoder: geocoder, Cache: cache} }
[ "func", "Geocoder", "(", "geocoder", "geo", ".", "Geocoder", ",", "cache", "*", "cache", ".", "Cache", ")", "geo", ".", "Geocoder", "{", "return", "cachedGeocoder", "{", "Geocoder", ":", "geocoder", ",", "Cache", ":", "cache", "}", "\n", "}" ]
// Geocoder creates a chain of Geocoders to lookup address and fallback on
[ "Geocoder", "creates", "a", "chain", "of", "Geocoders", "to", "lookup", "address", "and", "fallback", "on" ]
d393bef084a8e317ed96087b35943f87a228eac6
https://github.com/codingsince1985/geo-golang/blob/d393bef084a8e317ed96087b35943f87a228eac6/cached/geocoder.go#L16-L18
11,357
codingsince1985/geo-golang
arcgis/geocoder.go
Geocoder
func Geocoder(token string, baseURLs ...string) geo.Geocoder { return geo.HTTPGeocoder{ EndpointBuilder: baseURL(getUrl(token, baseURLs...)), ResponseParserFactory: func() geo.ResponseParser { return &geocodeResponse{} }, } }
go
func Geocoder(token string, baseURLs ...string) geo.Geocoder { return geo.HTTPGeocoder{ EndpointBuilder: baseURL(getUrl(token, baseURLs...)), ResponseParserFactory: func() geo.ResponseParser { return &geocodeResponse{} }, } }
[ "func", "Geocoder", "(", "token", "string", ",", "baseURLs", "...", "string", ")", "geo", ".", "Geocoder", "{", "return", "geo", ".", "HTTPGeocoder", "{", "EndpointBuilder", ":", "baseURL", "(", "getUrl", "(", "token", ",", "baseURLs", "...", ")", ")", ",", "ResponseParserFactory", ":", "func", "(", ")", "geo", ".", "ResponseParser", "{", "return", "&", "geocodeResponse", "{", "}", "}", ",", "}", "\n", "}" ]
// Geocoder constructs ArcGIS geocoder
[ "Geocoder", "constructs", "ArcGIS", "geocoder" ]
d393bef084a8e317ed96087b35943f87a228eac6
https://github.com/codingsince1985/geo-golang/blob/d393bef084a8e317ed96087b35943f87a228eac6/arcgis/geocoder.go#L39-L44
11,358
codingsince1985/geo-golang
openstreetmap/geocoder.go
GeocoderWithURL
func GeocoderWithURL(nominatimURL string) geo.Geocoder { return geo.HTTPGeocoder{ EndpointBuilder: baseURL(nominatimURL), ResponseParserFactory: func() geo.ResponseParser { return &geocodeResponse{} }, } }
go
func GeocoderWithURL(nominatimURL string) geo.Geocoder { return geo.HTTPGeocoder{ EndpointBuilder: baseURL(nominatimURL), ResponseParserFactory: func() geo.ResponseParser { return &geocodeResponse{} }, } }
[ "func", "GeocoderWithURL", "(", "nominatimURL", "string", ")", "geo", ".", "Geocoder", "{", "return", "geo", ".", "HTTPGeocoder", "{", "EndpointBuilder", ":", "baseURL", "(", "nominatimURL", ")", ",", "ResponseParserFactory", ":", "func", "(", ")", "geo", ".", "ResponseParser", "{", "return", "&", "geocodeResponse", "{", "}", "}", ",", "}", "\n", "}" ]
// GeocoderWithURL constructs OpenStreetMap geocoder using a custom installation of Nominatim
[ "GeocoderWithURL", "constructs", "OpenStreetMap", "geocoder", "using", "a", "custom", "installation", "of", "Nominatim" ]
d393bef084a8e317ed96087b35943f87a228eac6
https://github.com/codingsince1985/geo-golang/blob/d393bef084a8e317ed96087b35943f87a228eac6/openstreetmap/geocoder.go#L27-L32
11,359
codingsince1985/geo-golang
http_geocoder.go
response
func response(ctx context.Context, url string, obj ResponseParser) error { req, err := http.NewRequest(http.MethodGet, url, nil) if err != nil { return err } req = req.WithContext(ctx) resp, err := http.DefaultClient.Do(req) if err != nil { return err } defer resp.Body.Close() data, err := ioutil.ReadAll(resp.Body) if err != nil { return err } body := strings.Trim(string(data), " []") if body == "" { return nil } if err := json.Unmarshal([]byte(body), obj); err != nil { Logger.Printf("payload: %s\n", body) return err } return nil }
go
func response(ctx context.Context, url string, obj ResponseParser) error { req, err := http.NewRequest(http.MethodGet, url, nil) if err != nil { return err } req = req.WithContext(ctx) resp, err := http.DefaultClient.Do(req) if err != nil { return err } defer resp.Body.Close() data, err := ioutil.ReadAll(resp.Body) if err != nil { return err } body := strings.Trim(string(data), " []") if body == "" { return nil } if err := json.Unmarshal([]byte(body), obj); err != nil { Logger.Printf("payload: %s\n", body) return err } return nil }
[ "func", "response", "(", "ctx", "context", ".", "Context", ",", "url", "string", ",", "obj", "ResponseParser", ")", "error", "{", "req", ",", "err", ":=", "http", ".", "NewRequest", "(", "http", ".", "MethodGet", ",", "url", ",", "nil", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "req", "=", "req", ".", "WithContext", "(", "ctx", ")", "\n\n", "resp", ",", "err", ":=", "http", ".", "DefaultClient", ".", "Do", "(", "req", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "defer", "resp", ".", "Body", ".", "Close", "(", ")", "\n", "data", ",", "err", ":=", "ioutil", ".", "ReadAll", "(", "resp", ".", "Body", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "body", ":=", "strings", ".", "Trim", "(", "string", "(", "data", ")", ",", "\"", "\"", ")", "\n", "if", "body", "==", "\"", "\"", "{", "return", "nil", "\n", "}", "\n", "if", "err", ":=", "json", ".", "Unmarshal", "(", "[", "]", "byte", "(", "body", ")", ",", "obj", ")", ";", "err", "!=", "nil", "{", "Logger", ".", "Printf", "(", "\"", "\\n", "\"", ",", "body", ")", "\n", "return", "err", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// Response gets response from url
[ "Response", "gets", "response", "from", "url" ]
d393bef084a8e317ed96087b35943f87a228eac6
https://github.com/codingsince1985/geo-golang/blob/d393bef084a8e317ed96087b35943f87a228eac6/http_geocoder.go#L115-L143
11,360
codingsince1985/geo-golang
http_geocoder.go
ParseFloat
func ParseFloat(value string) float64 { f, _ := strconv.ParseFloat(value, 64) return f }
go
func ParseFloat(value string) float64 { f, _ := strconv.ParseFloat(value, 64) return f }
[ "func", "ParseFloat", "(", "value", "string", ")", "float64", "{", "f", ",", "_", ":=", "strconv", ".", "ParseFloat", "(", "value", ",", "64", ")", "\n", "return", "f", "\n", "}" ]
// ParseFloat is a helper to parse a string to a float
[ "ParseFloat", "is", "a", "helper", "to", "parse", "a", "string", "to", "a", "float" ]
d393bef084a8e317ed96087b35943f87a228eac6
https://github.com/codingsince1985/geo-golang/blob/d393bef084a8e317ed96087b35943f87a228eac6/http_geocoder.go#L146-L149
11,361
codingsince1985/geo-golang
here/geocoder.go
Geocoder
func Geocoder(id, code string, radius int, baseURLs ...string) geo.Geocoder { if radius > 0 { r = radius } p := "gen=9&app_id=" + id + "&app_code=" + code return geo.HTTPGeocoder{ EndpointBuilder: baseURL{ getGeocodeURL(p, baseURLs...), getReverseGeocodeURL(p, baseURLs...)}, ResponseParserFactory: func() geo.ResponseParser { return &geocodeResponse{} }, } }
go
func Geocoder(id, code string, radius int, baseURLs ...string) geo.Geocoder { if radius > 0 { r = radius } p := "gen=9&app_id=" + id + "&app_code=" + code return geo.HTTPGeocoder{ EndpointBuilder: baseURL{ getGeocodeURL(p, baseURLs...), getReverseGeocodeURL(p, baseURLs...)}, ResponseParserFactory: func() geo.ResponseParser { return &geocodeResponse{} }, } }
[ "func", "Geocoder", "(", "id", ",", "code", "string", ",", "radius", "int", ",", "baseURLs", "...", "string", ")", "geo", ".", "Geocoder", "{", "if", "radius", ">", "0", "{", "r", "=", "radius", "\n", "}", "\n", "p", ":=", "\"", "\"", "+", "id", "+", "\"", "\"", "+", "code", "\n", "return", "geo", ".", "HTTPGeocoder", "{", "EndpointBuilder", ":", "baseURL", "{", "getGeocodeURL", "(", "p", ",", "baseURLs", "...", ")", ",", "getReverseGeocodeURL", "(", "p", ",", "baseURLs", "...", ")", "}", ",", "ResponseParserFactory", ":", "func", "(", ")", "geo", ".", "ResponseParser", "{", "return", "&", "geocodeResponse", "{", "}", "}", ",", "}", "\n", "}" ]
// Geocoder constructs HERE geocoder
[ "Geocoder", "constructs", "HERE", "geocoder" ]
d393bef084a8e317ed96087b35943f87a228eac6
https://github.com/codingsince1985/geo-golang/blob/d393bef084a8e317ed96087b35943f87a228eac6/here/geocoder.go#L52-L63
11,362
codingsince1985/geo-golang
osm/osm.go
Locality
func (a Address) Locality() string { var locality string if a.City != "" { locality = a.City } else if a.Town != "" { locality = a.Town } else if a.Village != "" { locality = a.Village } return locality }
go
func (a Address) Locality() string { var locality string if a.City != "" { locality = a.City } else if a.Town != "" { locality = a.Town } else if a.Village != "" { locality = a.Village } return locality }
[ "func", "(", "a", "Address", ")", "Locality", "(", ")", "string", "{", "var", "locality", "string", "\n\n", "if", "a", ".", "City", "!=", "\"", "\"", "{", "locality", "=", "a", ".", "City", "\n", "}", "else", "if", "a", ".", "Town", "!=", "\"", "\"", "{", "locality", "=", "a", ".", "Town", "\n", "}", "else", "if", "a", ".", "Village", "!=", "\"", "\"", "{", "locality", "=", "a", ".", "Village", "\n", "}", "\n\n", "return", "locality", "\n", "}" ]
// Locality checks different fields for the locality name
[ "Locality", "checks", "different", "fields", "for", "the", "locality", "name" ]
d393bef084a8e317ed96087b35943f87a228eac6
https://github.com/codingsince1985/geo-golang/blob/d393bef084a8e317ed96087b35943f87a228eac6/osm/osm.go#L27-L39
11,363
codingsince1985/geo-golang
osm/osm.go
Street
func (a Address) Street() string { var street string if a.Road != "" { street = a.Road } else if a.Pedestrian != "" { street = a.Pedestrian } else if a.Path != "" { street = a.Path } else if a.Cycleway != "" { street = a.Cycleway } else if a.Footway != "" { street = a.Footway } else if a.Highway != "" { street = a.Highway } return street }
go
func (a Address) Street() string { var street string if a.Road != "" { street = a.Road } else if a.Pedestrian != "" { street = a.Pedestrian } else if a.Path != "" { street = a.Path } else if a.Cycleway != "" { street = a.Cycleway } else if a.Footway != "" { street = a.Footway } else if a.Highway != "" { street = a.Highway } return street }
[ "func", "(", "a", "Address", ")", "Street", "(", ")", "string", "{", "var", "street", "string", "\n\n", "if", "a", ".", "Road", "!=", "\"", "\"", "{", "street", "=", "a", ".", "Road", "\n", "}", "else", "if", "a", ".", "Pedestrian", "!=", "\"", "\"", "{", "street", "=", "a", ".", "Pedestrian", "\n", "}", "else", "if", "a", ".", "Path", "!=", "\"", "\"", "{", "street", "=", "a", ".", "Path", "\n", "}", "else", "if", "a", ".", "Cycleway", "!=", "\"", "\"", "{", "street", "=", "a", ".", "Cycleway", "\n", "}", "else", "if", "a", ".", "Footway", "!=", "\"", "\"", "{", "street", "=", "a", ".", "Footway", "\n", "}", "else", "if", "a", ".", "Highway", "!=", "\"", "\"", "{", "street", "=", "a", ".", "Highway", "\n", "}", "\n\n", "return", "street", "\n", "}" ]
// Street checks different fields for the street name
[ "Street", "checks", "different", "fields", "for", "the", "street", "name" ]
d393bef084a8e317ed96087b35943f87a228eac6
https://github.com/codingsince1985/geo-golang/blob/d393bef084a8e317ed96087b35943f87a228eac6/osm/osm.go#L42-L60
11,364
pkg/term
term_windows.go
SetOption
func (t *Term) SetOption(options ...func(*Term) error) error { for _, opt := range options { if err := opt(t); err != nil { return err } } return nil }
go
func (t *Term) SetOption(options ...func(*Term) error) error { for _, opt := range options { if err := opt(t); err != nil { return err } } return nil }
[ "func", "(", "t", "*", "Term", ")", "SetOption", "(", "options", "...", "func", "(", "*", "Term", ")", "error", ")", "error", "{", "for", "_", ",", "opt", ":=", "range", "options", "{", "if", "err", ":=", "opt", "(", "t", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// SetOption takes one or more option function and applies them in order to Term.
[ "SetOption", "takes", "one", "or", "more", "option", "function", "and", "applies", "them", "in", "order", "to", "Term", "." ]
aa71e9d9e942418fbb97d80895dcea70efed297c
https://github.com/pkg/term/blob/aa71e9d9e942418fbb97d80895dcea70efed297c/term_windows.go#L23-L30
11,365
pkg/term
term_windows.go
Close
func (t *Term) Close() error { err := syscall.Close(t.fd) t.fd = -1 return err }
go
func (t *Term) Close() error { err := syscall.Close(t.fd) t.fd = -1 return err }
[ "func", "(", "t", "*", "Term", ")", "Close", "(", ")", "error", "{", "err", ":=", "syscall", ".", "Close", "(", "t", ".", "fd", ")", "\n", "t", ".", "fd", "=", "-", "1", "\n", "return", "err", "\n", "}" ]
// Close closes the device and releases any associated resources.
[ "Close", "closes", "the", "device", "and", "releases", "any", "associated", "resources", "." ]
aa71e9d9e942418fbb97d80895dcea70efed297c
https://github.com/pkg/term/blob/aa71e9d9e942418fbb97d80895dcea70efed297c/term_windows.go#L67-L71
11,366
pkg/term
term_windows.go
CBreakMode
func CBreakMode(t *Term) error { var a attr if err := termios.Tcgetattr(uintptr(t.fd), (*syscall.Termios)(&a)); err != nil { return err } termios.Cfmakecbreak((*syscall.Termios)(&a)) return termios.Tcsetattr(uintptr(t.fd), termios.TCSANOW, (*syscall.Termios)(&a)) }
go
func CBreakMode(t *Term) error { var a attr if err := termios.Tcgetattr(uintptr(t.fd), (*syscall.Termios)(&a)); err != nil { return err } termios.Cfmakecbreak((*syscall.Termios)(&a)) return termios.Tcsetattr(uintptr(t.fd), termios.TCSANOW, (*syscall.Termios)(&a)) }
[ "func", "CBreakMode", "(", "t", "*", "Term", ")", "error", "{", "var", "a", "attr", "\n", "if", "err", ":=", "termios", ".", "Tcgetattr", "(", "uintptr", "(", "t", ".", "fd", ")", ",", "(", "*", "syscall", ".", "Termios", ")", "(", "&", "a", ")", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "termios", ".", "Cfmakecbreak", "(", "(", "*", "syscall", ".", "Termios", ")", "(", "&", "a", ")", ")", "\n", "return", "termios", ".", "Tcsetattr", "(", "uintptr", "(", "t", ".", "fd", ")", ",", "termios", ".", "TCSANOW", ",", "(", "*", "syscall", ".", "Termios", ")", "(", "&", "a", ")", ")", "\n", "}" ]
// CBreakMode places the terminal into cbreak mode.
[ "CBreakMode", "places", "the", "terminal", "into", "cbreak", "mode", "." ]
aa71e9d9e942418fbb97d80895dcea70efed297c
https://github.com/pkg/term/blob/aa71e9d9e942418fbb97d80895dcea70efed297c/term_windows.go#L79-L86
11,367
pkg/term
term_windows.go
RawMode
func RawMode(t *Term) error { var a attr if err := termios.Tcgetattr(uintptr(t.fd), (*syscall.Termios)(&a)); err != nil { return err } termios.Cfmakeraw((*syscall.Termios)(&a)) return termios.Tcsetattr(uintptr(t.fd), termios.TCSANOW, (*syscall.Termios)(&a)) }
go
func RawMode(t *Term) error { var a attr if err := termios.Tcgetattr(uintptr(t.fd), (*syscall.Termios)(&a)); err != nil { return err } termios.Cfmakeraw((*syscall.Termios)(&a)) return termios.Tcsetattr(uintptr(t.fd), termios.TCSANOW, (*syscall.Termios)(&a)) }
[ "func", "RawMode", "(", "t", "*", "Term", ")", "error", "{", "var", "a", "attr", "\n", "if", "err", ":=", "termios", ".", "Tcgetattr", "(", "uintptr", "(", "t", ".", "fd", ")", ",", "(", "*", "syscall", ".", "Termios", ")", "(", "&", "a", ")", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "termios", ".", "Cfmakeraw", "(", "(", "*", "syscall", ".", "Termios", ")", "(", "&", "a", ")", ")", "\n", "return", "termios", ".", "Tcsetattr", "(", "uintptr", "(", "t", ".", "fd", ")", ",", "termios", ".", "TCSANOW", ",", "(", "*", "syscall", ".", "Termios", ")", "(", "&", "a", ")", ")", "\n", "}" ]
// RawMode places the terminal into raw mode.
[ "RawMode", "places", "the", "terminal", "into", "raw", "mode", "." ]
aa71e9d9e942418fbb97d80895dcea70efed297c
https://github.com/pkg/term/blob/aa71e9d9e942418fbb97d80895dcea70efed297c/term_windows.go#L94-L101
11,368
pkg/term
term_windows.go
Speed
func Speed(baud int) func(*Term) error { return func(t *Term) error { return t.setSpeed(baud) } }
go
func Speed(baud int) func(*Term) error { return func(t *Term) error { return t.setSpeed(baud) } }
[ "func", "Speed", "(", "baud", "int", ")", "func", "(", "*", "Term", ")", "error", "{", "return", "func", "(", "t", "*", "Term", ")", "error", "{", "return", "t", ".", "setSpeed", "(", "baud", ")", "\n", "}", "\n", "}" ]
// Speed sets the baud rate option for the terminal.
[ "Speed", "sets", "the", "baud", "rate", "option", "for", "the", "terminal", "." ]
aa71e9d9e942418fbb97d80895dcea70efed297c
https://github.com/pkg/term/blob/aa71e9d9e942418fbb97d80895dcea70efed297c/term_windows.go#L104-L108
11,369
pkg/term
term_windows.go
SetSpeed
func (t *Term) SetSpeed(baud int) error { return t.SetOption(Speed(baud)) }
go
func (t *Term) SetSpeed(baud int) error { return t.SetOption(Speed(baud)) }
[ "func", "(", "t", "*", "Term", ")", "SetSpeed", "(", "baud", "int", ")", "error", "{", "return", "t", ".", "SetOption", "(", "Speed", "(", "baud", ")", ")", "\n", "}" ]
// SetSpeed sets the receive and transmit baud rates.
[ "SetSpeed", "sets", "the", "receive", "and", "transmit", "baud", "rates", "." ]
aa71e9d9e942418fbb97d80895dcea70efed297c
https://github.com/pkg/term/blob/aa71e9d9e942418fbb97d80895dcea70efed297c/term_windows.go#L111-L113
11,370
pkg/term
term_windows.go
Flush
func (t *Term) Flush() error { return termios.Tcflush(uintptr(t.fd), termios.TCIOFLUSH) }
go
func (t *Term) Flush() error { return termios.Tcflush(uintptr(t.fd), termios.TCIOFLUSH) }
[ "func", "(", "t", "*", "Term", ")", "Flush", "(", ")", "error", "{", "return", "termios", ".", "Tcflush", "(", "uintptr", "(", "t", ".", "fd", ")", ",", "termios", ".", "TCIOFLUSH", ")", "\n", "}" ]
// Flush flushes both data received but not read, and data written but not transmitted.
[ "Flush", "flushes", "both", "data", "received", "but", "not", "read", "and", "data", "written", "but", "not", "transmitted", "." ]
aa71e9d9e942418fbb97d80895dcea70efed297c
https://github.com/pkg/term/blob/aa71e9d9e942418fbb97d80895dcea70efed297c/term_windows.go#L125-L127
11,371
pkg/term
term_windows.go
Restore
func (t *Term) Restore() error { return termios.Tcsetattr(uintptr(t.fd), termios.TCIOFLUSH, &t.orig) }
go
func (t *Term) Restore() error { return termios.Tcsetattr(uintptr(t.fd), termios.TCIOFLUSH, &t.orig) }
[ "func", "(", "t", "*", "Term", ")", "Restore", "(", ")", "error", "{", "return", "termios", ".", "Tcsetattr", "(", "uintptr", "(", "t", ".", "fd", ")", ",", "termios", ".", "TCIOFLUSH", ",", "&", "t", ".", "orig", ")", "\n", "}" ]
// Restore restores the state of the terminal captured at the point that // the terminal was originally opened.
[ "Restore", "restores", "the", "state", "of", "the", "terminal", "captured", "at", "the", "point", "that", "the", "terminal", "was", "originally", "opened", "." ]
aa71e9d9e942418fbb97d80895dcea70efed297c
https://github.com/pkg/term/blob/aa71e9d9e942418fbb97d80895dcea70efed297c/term_windows.go#L170-L172
11,372
pkg/term
termios/termios.go
Tiocmget
func Tiocmget(fd uintptr, status *int) error { return ioctl(fd, syscall.TIOCMGET, uintptr(unsafe.Pointer(status))) }
go
func Tiocmget(fd uintptr, status *int) error { return ioctl(fd, syscall.TIOCMGET, uintptr(unsafe.Pointer(status))) }
[ "func", "Tiocmget", "(", "fd", "uintptr", ",", "status", "*", "int", ")", "error", "{", "return", "ioctl", "(", "fd", ",", "syscall", ".", "TIOCMGET", ",", "uintptr", "(", "unsafe", ".", "Pointer", "(", "status", ")", ")", ")", "\n", "}" ]
// Tiocmget returns the state of the MODEM bits.
[ "Tiocmget", "returns", "the", "state", "of", "the", "MODEM", "bits", "." ]
aa71e9d9e942418fbb97d80895dcea70efed297c
https://github.com/pkg/term/blob/aa71e9d9e942418fbb97d80895dcea70efed297c/termios/termios.go#L11-L13
11,373
pkg/term
termios/termios.go
Tiocmset
func Tiocmset(fd uintptr, status *int) error { return ioctl(fd, syscall.TIOCMSET, uintptr(unsafe.Pointer(status))) }
go
func Tiocmset(fd uintptr, status *int) error { return ioctl(fd, syscall.TIOCMSET, uintptr(unsafe.Pointer(status))) }
[ "func", "Tiocmset", "(", "fd", "uintptr", ",", "status", "*", "int", ")", "error", "{", "return", "ioctl", "(", "fd", ",", "syscall", ".", "TIOCMSET", ",", "uintptr", "(", "unsafe", ".", "Pointer", "(", "status", ")", ")", ")", "\n", "}" ]
// Tiocmset sets the state of the MODEM bits.
[ "Tiocmset", "sets", "the", "state", "of", "the", "MODEM", "bits", "." ]
aa71e9d9e942418fbb97d80895dcea70efed297c
https://github.com/pkg/term/blob/aa71e9d9e942418fbb97d80895dcea70efed297c/termios/termios.go#L16-L18
11,374
pkg/term
termios/termios.go
Tiocmbis
func Tiocmbis(fd uintptr, status *int) error { return ioctl(fd, syscall.TIOCMBIS, uintptr(unsafe.Pointer(status))) }
go
func Tiocmbis(fd uintptr, status *int) error { return ioctl(fd, syscall.TIOCMBIS, uintptr(unsafe.Pointer(status))) }
[ "func", "Tiocmbis", "(", "fd", "uintptr", ",", "status", "*", "int", ")", "error", "{", "return", "ioctl", "(", "fd", ",", "syscall", ".", "TIOCMBIS", ",", "uintptr", "(", "unsafe", ".", "Pointer", "(", "status", ")", ")", ")", "\n", "}" ]
// Tiocmbis sets the indicated modem bits.
[ "Tiocmbis", "sets", "the", "indicated", "modem", "bits", "." ]
aa71e9d9e942418fbb97d80895dcea70efed297c
https://github.com/pkg/term/blob/aa71e9d9e942418fbb97d80895dcea70efed297c/termios/termios.go#L21-L23
11,375
pkg/term
termios/termios.go
Tiocmbic
func Tiocmbic(fd uintptr, status *int) error { return ioctl(fd, syscall.TIOCMBIC, uintptr(unsafe.Pointer(status))) }
go
func Tiocmbic(fd uintptr, status *int) error { return ioctl(fd, syscall.TIOCMBIC, uintptr(unsafe.Pointer(status))) }
[ "func", "Tiocmbic", "(", "fd", "uintptr", ",", "status", "*", "int", ")", "error", "{", "return", "ioctl", "(", "fd", ",", "syscall", ".", "TIOCMBIC", ",", "uintptr", "(", "unsafe", ".", "Pointer", "(", "status", ")", ")", ")", "\n", "}" ]
// Tiocmbic clears the indicated modem bits.
[ "Tiocmbic", "clears", "the", "indicated", "modem", "bits", "." ]
aa71e9d9e942418fbb97d80895dcea70efed297c
https://github.com/pkg/term/blob/aa71e9d9e942418fbb97d80895dcea70efed297c/termios/termios.go#L26-L28
11,376
pkg/term
termios/termios.go
Cfmakecbreak
func Cfmakecbreak(attr *syscall.Termios) { attr.Lflag &^= syscall.ECHO | syscall.ICANON attr.Cc[syscall.VMIN] = 1 attr.Cc[syscall.VTIME] = 0 }
go
func Cfmakecbreak(attr *syscall.Termios) { attr.Lflag &^= syscall.ECHO | syscall.ICANON attr.Cc[syscall.VMIN] = 1 attr.Cc[syscall.VTIME] = 0 }
[ "func", "Cfmakecbreak", "(", "attr", "*", "syscall", ".", "Termios", ")", "{", "attr", ".", "Lflag", "&^=", "syscall", ".", "ECHO", "|", "syscall", ".", "ICANON", "\n", "attr", ".", "Cc", "[", "syscall", ".", "VMIN", "]", "=", "1", "\n", "attr", ".", "Cc", "[", "syscall", ".", "VTIME", "]", "=", "0", "\n", "}" ]
// Cfmakecbreak modifies attr for cbreak mode.
[ "Cfmakecbreak", "modifies", "attr", "for", "cbreak", "mode", "." ]
aa71e9d9e942418fbb97d80895dcea70efed297c
https://github.com/pkg/term/blob/aa71e9d9e942418fbb97d80895dcea70efed297c/termios/termios.go#L31-L35
11,377
pkg/term
termios/termios.go
Cfmakeraw
func Cfmakeraw(attr *syscall.Termios) { attr.Iflag &^= syscall.BRKINT | syscall.ICRNL | syscall.INPCK | syscall.ISTRIP | syscall.IXON attr.Oflag &^= syscall.OPOST attr.Cflag &^= syscall.CSIZE | syscall.PARENB attr.Cflag |= syscall.CS8 attr.Lflag &^= syscall.ECHO | syscall.ICANON | syscall.IEXTEN | syscall.ISIG attr.Cc[syscall.VMIN] = 1 attr.Cc[syscall.VTIME] = 0 }
go
func Cfmakeraw(attr *syscall.Termios) { attr.Iflag &^= syscall.BRKINT | syscall.ICRNL | syscall.INPCK | syscall.ISTRIP | syscall.IXON attr.Oflag &^= syscall.OPOST attr.Cflag &^= syscall.CSIZE | syscall.PARENB attr.Cflag |= syscall.CS8 attr.Lflag &^= syscall.ECHO | syscall.ICANON | syscall.IEXTEN | syscall.ISIG attr.Cc[syscall.VMIN] = 1 attr.Cc[syscall.VTIME] = 0 }
[ "func", "Cfmakeraw", "(", "attr", "*", "syscall", ".", "Termios", ")", "{", "attr", ".", "Iflag", "&^=", "syscall", ".", "BRKINT", "|", "syscall", ".", "ICRNL", "|", "syscall", ".", "INPCK", "|", "syscall", ".", "ISTRIP", "|", "syscall", ".", "IXON", "\n", "attr", ".", "Oflag", "&^=", "syscall", ".", "OPOST", "\n", "attr", ".", "Cflag", "&^=", "syscall", ".", "CSIZE", "|", "syscall", ".", "PARENB", "\n", "attr", ".", "Cflag", "|=", "syscall", ".", "CS8", "\n", "attr", ".", "Lflag", "&^=", "syscall", ".", "ECHO", "|", "syscall", ".", "ICANON", "|", "syscall", ".", "IEXTEN", "|", "syscall", ".", "ISIG", "\n", "attr", ".", "Cc", "[", "syscall", ".", "VMIN", "]", "=", "1", "\n", "attr", ".", "Cc", "[", "syscall", ".", "VTIME", "]", "=", "0", "\n", "}" ]
// Cfmakeraw modifies attr for raw mode.
[ "Cfmakeraw", "modifies", "attr", "for", "raw", "mode", "." ]
aa71e9d9e942418fbb97d80895dcea70efed297c
https://github.com/pkg/term/blob/aa71e9d9e942418fbb97d80895dcea70efed297c/termios/termios.go#L38-L46
11,378
pkg/term
term_posix.go
timeoutVals
func timeoutVals(d time.Duration) (uint8, uint8) { if d > 0 { // VTIME is expressed in terms of deciseconds vtimeDeci := d.Nanoseconds() / 1e6 / 100 // ensure valid range vtime := uint8(clamp(vtimeDeci, 1, 0xff)) return 0, vtime } // block indefinitely until we receive at least 1 byte return 1, 0 }
go
func timeoutVals(d time.Duration) (uint8, uint8) { if d > 0 { // VTIME is expressed in terms of deciseconds vtimeDeci := d.Nanoseconds() / 1e6 / 100 // ensure valid range vtime := uint8(clamp(vtimeDeci, 1, 0xff)) return 0, vtime } // block indefinitely until we receive at least 1 byte return 1, 0 }
[ "func", "timeoutVals", "(", "d", "time", ".", "Duration", ")", "(", "uint8", ",", "uint8", ")", "{", "if", "d", ">", "0", "{", "// VTIME is expressed in terms of deciseconds", "vtimeDeci", ":=", "d", ".", "Nanoseconds", "(", ")", "/", "1e6", "/", "100", "\n", "// ensure valid range", "vtime", ":=", "uint8", "(", "clamp", "(", "vtimeDeci", ",", "1", ",", "0xff", ")", ")", "\n", "return", "0", ",", "vtime", "\n", "}", "\n", "// block indefinitely until we receive at least 1 byte", "return", "1", ",", "0", "\n", "}" ]
// timeoutVals converts d into values suitable for termios VMIN and VTIME ctrl chars
[ "timeoutVals", "converts", "d", "into", "values", "suitable", "for", "termios", "VMIN", "and", "VTIME", "ctrl", "chars" ]
aa71e9d9e942418fbb97d80895dcea70efed297c
https://github.com/pkg/term/blob/aa71e9d9e942418fbb97d80895dcea70efed297c/term_posix.go#L81-L91
11,379
pkg/term
term_posix.go
ReadTimeout
func ReadTimeout(d time.Duration) func(*Term) error { return func(t *Term) error { return t.setReadTimeout(d) } }
go
func ReadTimeout(d time.Duration) func(*Term) error { return func(t *Term) error { return t.setReadTimeout(d) } }
[ "func", "ReadTimeout", "(", "d", "time", ".", "Duration", ")", "func", "(", "*", "Term", ")", "error", "{", "return", "func", "(", "t", "*", "Term", ")", "error", "{", "return", "t", ".", "setReadTimeout", "(", "d", ")", "\n", "}", "\n", "}" ]
// ReadTimeout sets the read timeout option for the terminal.
[ "ReadTimeout", "sets", "the", "read", "timeout", "option", "for", "the", "terminal", "." ]
aa71e9d9e942418fbb97d80895dcea70efed297c
https://github.com/pkg/term/blob/aa71e9d9e942418fbb97d80895dcea70efed297c/term_posix.go#L94-L98
11,380
pkg/term
term_posix.go
SetReadTimeout
func (t *Term) SetReadTimeout(d time.Duration) error { return t.SetOption(ReadTimeout(d)) }
go
func (t *Term) SetReadTimeout(d time.Duration) error { return t.SetOption(ReadTimeout(d)) }
[ "func", "(", "t", "*", "Term", ")", "SetReadTimeout", "(", "d", "time", ".", "Duration", ")", "error", "{", "return", "t", ".", "SetOption", "(", "ReadTimeout", "(", "d", ")", ")", "\n", "}" ]
// SetReadTimeout sets the read timeout. // A zero value for d means read operations will not time out.
[ "SetReadTimeout", "sets", "the", "read", "timeout", ".", "A", "zero", "value", "for", "d", "means", "read", "operations", "will", "not", "time", "out", "." ]
aa71e9d9e942418fbb97d80895dcea70efed297c
https://github.com/pkg/term/blob/aa71e9d9e942418fbb97d80895dcea70efed297c/term_posix.go#L102-L104
11,381
pkg/term
term_posix.go
FlowControl
func FlowControl(kind int) func(*Term) error { return func(t *Term) error { return t.setFlowControl(kind) } }
go
func FlowControl(kind int) func(*Term) error { return func(t *Term) error { return t.setFlowControl(kind) } }
[ "func", "FlowControl", "(", "kind", "int", ")", "func", "(", "*", "Term", ")", "error", "{", "return", "func", "(", "t", "*", "Term", ")", "error", "{", "return", "t", ".", "setFlowControl", "(", "kind", ")", "\n", "}", "\n", "}" ]
// FlowControl sets the flow control option for the terminal.
[ "FlowControl", "sets", "the", "flow", "control", "option", "for", "the", "terminal", "." ]
aa71e9d9e942418fbb97d80895dcea70efed297c
https://github.com/pkg/term/blob/aa71e9d9e942418fbb97d80895dcea70efed297c/term_posix.go#L116-L120
11,382
pkg/term
term_posix.go
SetFlowControl
func (t *Term) SetFlowControl(kind int) error { return t.SetOption(FlowControl(kind)) }
go
func (t *Term) SetFlowControl(kind int) error { return t.SetOption(FlowControl(kind)) }
[ "func", "(", "t", "*", "Term", ")", "SetFlowControl", "(", "kind", "int", ")", "error", "{", "return", "t", ".", "SetOption", "(", "FlowControl", "(", "kind", ")", ")", "\n", "}" ]
// SetFlowControl sets whether hardware flow control is enabled.
[ "SetFlowControl", "sets", "whether", "hardware", "flow", "control", "is", "enabled", "." ]
aa71e9d9e942418fbb97d80895dcea70efed297c
https://github.com/pkg/term/blob/aa71e9d9e942418fbb97d80895dcea70efed297c/term_posix.go#L123-L125
11,383
pkg/term
termios/termios_linux.go
Tcdrain
func Tcdrain(fd uintptr) error { // simulate drain with TCSADRAIN var attr syscall.Termios if err := Tcgetattr(fd, &attr); err != nil { return err } return Tcsetattr(fd, TCSADRAIN, &attr) }
go
func Tcdrain(fd uintptr) error { // simulate drain with TCSADRAIN var attr syscall.Termios if err := Tcgetattr(fd, &attr); err != nil { return err } return Tcsetattr(fd, TCSADRAIN, &attr) }
[ "func", "Tcdrain", "(", "fd", "uintptr", ")", "error", "{", "// simulate drain with TCSADRAIN", "var", "attr", "syscall", ".", "Termios", "\n", "if", "err", ":=", "Tcgetattr", "(", "fd", ",", "&", "attr", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", "Tcsetattr", "(", "fd", ",", "TCSADRAIN", ",", "&", "attr", ")", "\n", "}" ]
// Tcdrain waits until all output written to the object referred to by fd has been transmitted.
[ "Tcdrain", "waits", "until", "all", "output", "written", "to", "the", "object", "referred", "to", "by", "fd", "has", "been", "transmitted", "." ]
aa71e9d9e942418fbb97d80895dcea70efed297c
https://github.com/pkg/term/blob/aa71e9d9e942418fbb97d80895dcea70efed297c/termios/termios_linux.go#L53-L60
11,384
pkg/term
termios/termios_linux.go
Tiocoutq
func Tiocoutq(fd uintptr, argp *int) error { return ioctl(fd, syscall.TIOCOUTQ, uintptr(unsafe.Pointer(argp))) }
go
func Tiocoutq(fd uintptr, argp *int) error { return ioctl(fd, syscall.TIOCOUTQ, uintptr(unsafe.Pointer(argp))) }
[ "func", "Tiocoutq", "(", "fd", "uintptr", ",", "argp", "*", "int", ")", "error", "{", "return", "ioctl", "(", "fd", ",", "syscall", ".", "TIOCOUTQ", ",", "uintptr", "(", "unsafe", ".", "Pointer", "(", "argp", ")", ")", ")", "\n", "}" ]
// Tiocoutq return the number of bytes in the output buffer.
[ "Tiocoutq", "return", "the", "number", "of", "bytes", "in", "the", "output", "buffer", "." ]
aa71e9d9e942418fbb97d80895dcea70efed297c
https://github.com/pkg/term/blob/aa71e9d9e942418fbb97d80895dcea70efed297c/termios/termios_linux.go#L73-L75
11,385
pkg/term
termios/pty.go
Pty
func Pty() (*os.File, *os.File, error) { ptm, err := open_pty_master() if err != nil { return nil, nil, err } sname, err := Ptsname(ptm) if err != nil { return nil, nil, err } err = grantpt(ptm) if err != nil { return nil, nil, err } err = unlockpt(ptm) if err != nil { return nil, nil, err } pts, err := open_device(sname) if err != nil { return nil, nil, err } return os.NewFile(uintptr(ptm), "ptm"), os.NewFile(uintptr(pts), sname), nil }
go
func Pty() (*os.File, *os.File, error) { ptm, err := open_pty_master() if err != nil { return nil, nil, err } sname, err := Ptsname(ptm) if err != nil { return nil, nil, err } err = grantpt(ptm) if err != nil { return nil, nil, err } err = unlockpt(ptm) if err != nil { return nil, nil, err } pts, err := open_device(sname) if err != nil { return nil, nil, err } return os.NewFile(uintptr(ptm), "ptm"), os.NewFile(uintptr(pts), sname), nil }
[ "func", "Pty", "(", ")", "(", "*", "os", ".", "File", ",", "*", "os", ".", "File", ",", "error", ")", "{", "ptm", ",", "err", ":=", "open_pty_master", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "nil", ",", "err", "\n", "}", "\n\n", "sname", ",", "err", ":=", "Ptsname", "(", "ptm", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "nil", ",", "err", "\n", "}", "\n\n", "err", "=", "grantpt", "(", "ptm", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "nil", ",", "err", "\n", "}", "\n\n", "err", "=", "unlockpt", "(", "ptm", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "nil", ",", "err", "\n", "}", "\n\n", "pts", ",", "err", ":=", "open_device", "(", "sname", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "nil", ",", "err", "\n", "}", "\n", "return", "os", ".", "NewFile", "(", "uintptr", "(", "ptm", ")", ",", "\"", "\"", ")", ",", "os", ".", "NewFile", "(", "uintptr", "(", "pts", ")", ",", "sname", ")", ",", "nil", "\n", "}" ]
// Pty returns a UNIX 98 pseudoterminal device. // Pty returns a pair of fds representing the master and slave pair.
[ "Pty", "returns", "a", "UNIX", "98", "pseudoterminal", "device", ".", "Pty", "returns", "a", "pair", "of", "fds", "representing", "the", "master", "and", "slave", "pair", "." ]
aa71e9d9e942418fbb97d80895dcea70efed297c
https://github.com/pkg/term/blob/aa71e9d9e942418fbb97d80895dcea70efed297c/termios/pty.go#L19-L45
11,386
pkg/term
termios/termios_solaris.go
Cfgetispeed
func Cfgetispeed(attr *syscall.Termios) uint32 { solTermios := tiosToUnix(attr) return uint32(C.cfgetispeed((*C.termios_t)(unsafe.Pointer(solTermios)))) }
go
func Cfgetispeed(attr *syscall.Termios) uint32 { solTermios := tiosToUnix(attr) return uint32(C.cfgetispeed((*C.termios_t)(unsafe.Pointer(solTermios)))) }
[ "func", "Cfgetispeed", "(", "attr", "*", "syscall", ".", "Termios", ")", "uint32", "{", "solTermios", ":=", "tiosToUnix", "(", "attr", ")", "\n", "return", "uint32", "(", "C", ".", "cfgetispeed", "(", "(", "*", "C", ".", "termios_t", ")", "(", "unsafe", ".", "Pointer", "(", "solTermios", ")", ")", ")", ")", "\n", "}" ]
// Cfgetispeed returns the input baud rate stored in the termios structure.
[ "Cfgetispeed", "returns", "the", "input", "baud", "rate", "stored", "in", "the", "termios", "structure", "." ]
aa71e9d9e942418fbb97d80895dcea70efed297c
https://github.com/pkg/term/blob/aa71e9d9e942418fbb97d80895dcea70efed297c/termios/termios_solaris.go#L79-L82
11,387
pkg/term
termios/termios_solaris.go
Cfsetispeed
func Cfsetispeed(attr *syscall.Termios, speed uintptr) error { solTermios := tiosToUnix(attr) _, err := C.cfsetispeed((*C.termios_t)(unsafe.Pointer(solTermios)), C.speed_t(speed)) return err }
go
func Cfsetispeed(attr *syscall.Termios, speed uintptr) error { solTermios := tiosToUnix(attr) _, err := C.cfsetispeed((*C.termios_t)(unsafe.Pointer(solTermios)), C.speed_t(speed)) return err }
[ "func", "Cfsetispeed", "(", "attr", "*", "syscall", ".", "Termios", ",", "speed", "uintptr", ")", "error", "{", "solTermios", ":=", "tiosToUnix", "(", "attr", ")", "\n", "_", ",", "err", ":=", "C", ".", "cfsetispeed", "(", "(", "*", "C", ".", "termios_t", ")", "(", "unsafe", ".", "Pointer", "(", "solTermios", ")", ")", ",", "C", ".", "speed_t", "(", "speed", ")", ")", "\n", "return", "err", "\n", "}" ]
// Cfsetispeed sets the input baud rate stored in the termios structure.
[ "Cfsetispeed", "sets", "the", "input", "baud", "rate", "stored", "in", "the", "termios", "structure", "." ]
aa71e9d9e942418fbb97d80895dcea70efed297c
https://github.com/pkg/term/blob/aa71e9d9e942418fbb97d80895dcea70efed297c/termios/termios_solaris.go#L85-L89
11,388
pkg/term
termios/termios_solaris.go
Cfgetospeed
func Cfgetospeed(attr *syscall.Termios) uint32 { solTermios := tiosToUnix(attr) return uint32(C.cfgetospeed((*C.termios_t)(unsafe.Pointer(solTermios)))) }
go
func Cfgetospeed(attr *syscall.Termios) uint32 { solTermios := tiosToUnix(attr) return uint32(C.cfgetospeed((*C.termios_t)(unsafe.Pointer(solTermios)))) }
[ "func", "Cfgetospeed", "(", "attr", "*", "syscall", ".", "Termios", ")", "uint32", "{", "solTermios", ":=", "tiosToUnix", "(", "attr", ")", "\n", "return", "uint32", "(", "C", ".", "cfgetospeed", "(", "(", "*", "C", ".", "termios_t", ")", "(", "unsafe", ".", "Pointer", "(", "solTermios", ")", ")", ")", ")", "\n", "}" ]
// Cfgetospeed returns the output baud rate stored in the termios structure.
[ "Cfgetospeed", "returns", "the", "output", "baud", "rate", "stored", "in", "the", "termios", "structure", "." ]
aa71e9d9e942418fbb97d80895dcea70efed297c
https://github.com/pkg/term/blob/aa71e9d9e942418fbb97d80895dcea70efed297c/termios/termios_solaris.go#L92-L95
11,389
pkg/term
termios/termios_solaris.go
Cfsetospeed
func Cfsetospeed(attr *syscall.Termios, speed uintptr) error { solTermios := tiosToUnix(attr) _, err := C.cfsetospeed((*C.termios_t)(unsafe.Pointer(solTermios)), C.speed_t(speed)) return err }
go
func Cfsetospeed(attr *syscall.Termios, speed uintptr) error { solTermios := tiosToUnix(attr) _, err := C.cfsetospeed((*C.termios_t)(unsafe.Pointer(solTermios)), C.speed_t(speed)) return err }
[ "func", "Cfsetospeed", "(", "attr", "*", "syscall", ".", "Termios", ",", "speed", "uintptr", ")", "error", "{", "solTermios", ":=", "tiosToUnix", "(", "attr", ")", "\n", "_", ",", "err", ":=", "C", ".", "cfsetospeed", "(", "(", "*", "C", ".", "termios_t", ")", "(", "unsafe", ".", "Pointer", "(", "solTermios", ")", ")", ",", "C", ".", "speed_t", "(", "speed", ")", ")", "\n", "return", "err", "\n", "}" ]
// Cfsetospeed sets the output baud rate stored in the termios structure.
[ "Cfsetospeed", "sets", "the", "output", "baud", "rate", "stored", "in", "the", "termios", "structure", "." ]
aa71e9d9e942418fbb97d80895dcea70efed297c
https://github.com/pkg/term/blob/aa71e9d9e942418fbb97d80895dcea70efed297c/termios/termios_solaris.go#L98-L102
11,390
pkg/term
termios/termios_bsd.go
Tcsendbreak
func Tcsendbreak(fd, duration uintptr) error { if err := ioctl(fd, syscall.TIOCSBRK, 0); err != nil { return err } time.Sleep(4 / 10 * time.Second) return ioctl(fd, syscall.TIOCCBRK, 0) }
go
func Tcsendbreak(fd, duration uintptr) error { if err := ioctl(fd, syscall.TIOCSBRK, 0); err != nil { return err } time.Sleep(4 / 10 * time.Second) return ioctl(fd, syscall.TIOCCBRK, 0) }
[ "func", "Tcsendbreak", "(", "fd", ",", "duration", "uintptr", ")", "error", "{", "if", "err", ":=", "ioctl", "(", "fd", ",", "syscall", ".", "TIOCSBRK", ",", "0", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "time", ".", "Sleep", "(", "4", "/", "10", "*", "time", ".", "Second", ")", "\n", "return", "ioctl", "(", "fd", ",", "syscall", ".", "TIOCCBRK", ",", "0", ")", "\n", "}" ]
// Tcsendbreak function transmits a continuous stream of zero-valued bits for // four-tenths of a second to the terminal referenced by fildes. The duration // parameter is ignored in this implementation.
[ "Tcsendbreak", "function", "transmits", "a", "continuous", "stream", "of", "zero", "-", "valued", "bits", "for", "four", "-", "tenths", "of", "a", "second", "to", "the", "terminal", "referenced", "by", "fildes", ".", "The", "duration", "parameter", "is", "ignored", "in", "this", "implementation", "." ]
aa71e9d9e942418fbb97d80895dcea70efed297c
https://github.com/pkg/term/blob/aa71e9d9e942418fbb97d80895dcea70efed297c/termios/termios_bsd.go#L46-L52
11,391
pkg/term
termios/termios_bsd.go
Tcflush
func Tcflush(fd, which uintptr) error { var com int switch which { case syscall.TCIFLUSH: com = FREAD case syscall.TCOFLUSH: com = FWRITE case syscall.TCIOFLUSH: com = FREAD | FWRITE default: return syscall.EINVAL } return ioctl(fd, syscall.TIOCFLUSH, uintptr(unsafe.Pointer(&com))) }
go
func Tcflush(fd, which uintptr) error { var com int switch which { case syscall.TCIFLUSH: com = FREAD case syscall.TCOFLUSH: com = FWRITE case syscall.TCIOFLUSH: com = FREAD | FWRITE default: return syscall.EINVAL } return ioctl(fd, syscall.TIOCFLUSH, uintptr(unsafe.Pointer(&com))) }
[ "func", "Tcflush", "(", "fd", ",", "which", "uintptr", ")", "error", "{", "var", "com", "int", "\n", "switch", "which", "{", "case", "syscall", ".", "TCIFLUSH", ":", "com", "=", "FREAD", "\n", "case", "syscall", ".", "TCOFLUSH", ":", "com", "=", "FWRITE", "\n", "case", "syscall", ".", "TCIOFLUSH", ":", "com", "=", "FREAD", "|", "FWRITE", "\n", "default", ":", "return", "syscall", ".", "EINVAL", "\n", "}", "\n", "return", "ioctl", "(", "fd", ",", "syscall", ".", "TIOCFLUSH", ",", "uintptr", "(", "unsafe", ".", "Pointer", "(", "&", "com", ")", ")", ")", "\n", "}" ]
// Tcflush discards data written to the object referred to by fd but not transmitted, or data received but not read, depending on the value of which.
[ "Tcflush", "discards", "data", "written", "to", "the", "object", "referred", "to", "by", "fd", "but", "not", "transmitted", "or", "data", "received", "but", "not", "read", "depending", "on", "the", "value", "of", "which", "." ]
aa71e9d9e942418fbb97d80895dcea70efed297c
https://github.com/pkg/term/blob/aa71e9d9e942418fbb97d80895dcea70efed297c/termios/termios_bsd.go#L60-L73
11,392
pkg/term
term.go
Buffered
func (t *Term) Buffered() (int, error) { var n int err := termios.Tiocoutq(uintptr(t.fd), &n) return n, err }
go
func (t *Term) Buffered() (int, error) { var n int err := termios.Tiocoutq(uintptr(t.fd), &n) return n, err }
[ "func", "(", "t", "*", "Term", ")", "Buffered", "(", ")", "(", "int", ",", "error", ")", "{", "var", "n", "int", "\n", "err", ":=", "termios", ".", "Tiocoutq", "(", "uintptr", "(", "t", ".", "fd", ")", ",", "&", "n", ")", "\n", "return", "n", ",", "err", "\n", "}" ]
// Buffered returns the number of bytes that have been written into the current buffer.
[ "Buffered", "returns", "the", "number", "of", "bytes", "that", "have", "been", "written", "into", "the", "current", "buffer", "." ]
aa71e9d9e942418fbb97d80895dcea70efed297c
https://github.com/pkg/term/blob/aa71e9d9e942418fbb97d80895dcea70efed297c/term.go#L75-L79
11,393
multiformats/go-multihash
opts/opts.go
SetupFlags
func SetupFlags(f *flag.FlagSet) *Options { // TODO: add arg for adding opt prefix and/or overriding opts o := new(Options) algoStr := "one of: " + strings.Join(FlagValues.Algorithms, ", ") f.StringVar(&o.Algorithm, "algorithm", "sha2-256", algoStr) f.StringVar(&o.Algorithm, "a", "sha2-256", algoStr+" (shorthand)") encStr := "one of: " + strings.Join(FlagValues.Encodings, ", ") f.StringVar(&o.Encoding, "encoding", "base58", encStr) f.StringVar(&o.Encoding, "e", "base58", encStr+" (shorthand)") lengthStr := "checksums length in bits (truncate). -1 is default" f.IntVar(&o.Length, "length", -1, lengthStr) f.IntVar(&o.Length, "l", -1, lengthStr+" (shorthand)") return o }
go
func SetupFlags(f *flag.FlagSet) *Options { // TODO: add arg for adding opt prefix and/or overriding opts o := new(Options) algoStr := "one of: " + strings.Join(FlagValues.Algorithms, ", ") f.StringVar(&o.Algorithm, "algorithm", "sha2-256", algoStr) f.StringVar(&o.Algorithm, "a", "sha2-256", algoStr+" (shorthand)") encStr := "one of: " + strings.Join(FlagValues.Encodings, ", ") f.StringVar(&o.Encoding, "encoding", "base58", encStr) f.StringVar(&o.Encoding, "e", "base58", encStr+" (shorthand)") lengthStr := "checksums length in bits (truncate). -1 is default" f.IntVar(&o.Length, "length", -1, lengthStr) f.IntVar(&o.Length, "l", -1, lengthStr+" (shorthand)") return o }
[ "func", "SetupFlags", "(", "f", "*", "flag", ".", "FlagSet", ")", "*", "Options", "{", "// TODO: add arg for adding opt prefix and/or overriding opts", "o", ":=", "new", "(", "Options", ")", "\n", "algoStr", ":=", "\"", "\"", "+", "strings", ".", "Join", "(", "FlagValues", ".", "Algorithms", ",", "\"", "\"", ")", "\n", "f", ".", "StringVar", "(", "&", "o", ".", "Algorithm", ",", "\"", "\"", ",", "\"", "\"", ",", "algoStr", ")", "\n", "f", ".", "StringVar", "(", "&", "o", ".", "Algorithm", ",", "\"", "\"", ",", "\"", "\"", ",", "algoStr", "+", "\"", "\"", ")", "\n\n", "encStr", ":=", "\"", "\"", "+", "strings", ".", "Join", "(", "FlagValues", ".", "Encodings", ",", "\"", "\"", ")", "\n", "f", ".", "StringVar", "(", "&", "o", ".", "Encoding", ",", "\"", "\"", ",", "\"", "\"", ",", "encStr", ")", "\n", "f", ".", "StringVar", "(", "&", "o", ".", "Encoding", ",", "\"", "\"", ",", "\"", "\"", ",", "encStr", "+", "\"", "\"", ")", "\n\n", "lengthStr", ":=", "\"", "\"", "\n", "f", ".", "IntVar", "(", "&", "o", ".", "Length", ",", "\"", "\"", ",", "-", "1", ",", "lengthStr", ")", "\n", "f", ".", "IntVar", "(", "&", "o", ".", "Length", ",", "\"", "\"", ",", "-", "1", ",", "lengthStr", "+", "\"", "\"", ")", "\n", "return", "o", "\n", "}" ]
// SetupFlags adds multihash related options to given flagset.
[ "SetupFlags", "adds", "multihash", "related", "options", "to", "given", "flagset", "." ]
c242156eec223a58ac13b8c114a2b31e87bbf558
https://github.com/multiformats/go-multihash/blob/c242156eec223a58ac13b8c114a2b31e87bbf558/opts/opts.go#L64-L80
11,394
multiformats/go-multihash
opts/opts.go
ParseError
func (o *Options) ParseError() error { if !strIn(o.Encoding, FlagValues.Encodings) { return fmt.Errorf("encoding '%s' not %s", o.Encoding, FlagValues.Encodings) } if !strIn(o.Algorithm, FlagValues.Algorithms) { return fmt.Errorf("algorithm '%s' not %s", o.Algorithm, FlagValues.Algorithms) } var found bool o.AlgorithmCode, found = mh.Names[o.Algorithm] if !found { return fmt.Errorf("algorithm '%s' not found (lib error, pls report).", o.Algorithm) } if o.Length >= 0 { if o.Length%8 != 0 { return fmt.Errorf("length must be multiple of 8") } o.Length = o.Length / 8 if o.Length > mh.DefaultLengths[o.AlgorithmCode] { o.Length = mh.DefaultLengths[o.AlgorithmCode] } } return nil }
go
func (o *Options) ParseError() error { if !strIn(o.Encoding, FlagValues.Encodings) { return fmt.Errorf("encoding '%s' not %s", o.Encoding, FlagValues.Encodings) } if !strIn(o.Algorithm, FlagValues.Algorithms) { return fmt.Errorf("algorithm '%s' not %s", o.Algorithm, FlagValues.Algorithms) } var found bool o.AlgorithmCode, found = mh.Names[o.Algorithm] if !found { return fmt.Errorf("algorithm '%s' not found (lib error, pls report).", o.Algorithm) } if o.Length >= 0 { if o.Length%8 != 0 { return fmt.Errorf("length must be multiple of 8") } o.Length = o.Length / 8 if o.Length > mh.DefaultLengths[o.AlgorithmCode] { o.Length = mh.DefaultLengths[o.AlgorithmCode] } } return nil }
[ "func", "(", "o", "*", "Options", ")", "ParseError", "(", ")", "error", "{", "if", "!", "strIn", "(", "o", ".", "Encoding", ",", "FlagValues", ".", "Encodings", ")", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "o", ".", "Encoding", ",", "FlagValues", ".", "Encodings", ")", "\n", "}", "\n\n", "if", "!", "strIn", "(", "o", ".", "Algorithm", ",", "FlagValues", ".", "Algorithms", ")", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "o", ".", "Algorithm", ",", "FlagValues", ".", "Algorithms", ")", "\n", "}", "\n\n", "var", "found", "bool", "\n", "o", ".", "AlgorithmCode", ",", "found", "=", "mh", ".", "Names", "[", "o", ".", "Algorithm", "]", "\n", "if", "!", "found", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "o", ".", "Algorithm", ")", "\n", "}", "\n\n", "if", "o", ".", "Length", ">=", "0", "{", "if", "o", ".", "Length", "%", "8", "!=", "0", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n", "o", ".", "Length", "=", "o", ".", "Length", "/", "8", "\n\n", "if", "o", ".", "Length", ">", "mh", ".", "DefaultLengths", "[", "o", ".", "AlgorithmCode", "]", "{", "o", ".", "Length", "=", "mh", ".", "DefaultLengths", "[", "o", ".", "AlgorithmCode", "]", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// ParseError checks the parsed options for errors.
[ "ParseError", "checks", "the", "parsed", "options", "for", "errors", "." ]
c242156eec223a58ac13b8c114a2b31e87bbf558
https://github.com/multiformats/go-multihash/blob/c242156eec223a58ac13b8c114a2b31e87bbf558/opts/opts.go#L92-L118
11,395
multiformats/go-multihash
opts/opts.go
strIn
func strIn(a string, set []string) bool { for _, s := range set { if s == a { return true } } return false }
go
func strIn(a string, set []string) bool { for _, s := range set { if s == a { return true } } return false }
[ "func", "strIn", "(", "a", "string", ",", "set", "[", "]", "string", ")", "bool", "{", "for", "_", ",", "s", ":=", "range", "set", "{", "if", "s", "==", "a", "{", "return", "true", "\n", "}", "\n", "}", "\n", "return", "false", "\n", "}" ]
// strIn checks wither string a is in set.
[ "strIn", "checks", "wither", "string", "a", "is", "in", "set", "." ]
c242156eec223a58ac13b8c114a2b31e87bbf558
https://github.com/multiformats/go-multihash/blob/c242156eec223a58ac13b8c114a2b31e87bbf558/opts/opts.go#L121-L128
11,396
multiformats/go-multihash
opts/opts.go
Check
func (o *Options) Check(r io.Reader, h1 mh.Multihash) error { h2, err := o.Multihash(r) if err != nil { return err } if !bytes.Equal(h1, h2) { return fmt.Errorf("computed checksum did not match") } return nil }
go
func (o *Options) Check(r io.Reader, h1 mh.Multihash) error { h2, err := o.Multihash(r) if err != nil { return err } if !bytes.Equal(h1, h2) { return fmt.Errorf("computed checksum did not match") } return nil }
[ "func", "(", "o", "*", "Options", ")", "Check", "(", "r", "io", ".", "Reader", ",", "h1", "mh", ".", "Multihash", ")", "error", "{", "h2", ",", "err", ":=", "o", ".", "Multihash", "(", "r", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "if", "!", "bytes", ".", "Equal", "(", "h1", ",", "h2", ")", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// Check reads all the data in r, calculates its multihash, // and checks it matches h1
[ "Check", "reads", "all", "the", "data", "in", "r", "calculates", "its", "multihash", "and", "checks", "it", "matches", "h1" ]
c242156eec223a58ac13b8c114a2b31e87bbf558
https://github.com/multiformats/go-multihash/blob/c242156eec223a58ac13b8c114a2b31e87bbf558/opts/opts.go#L132-L143
11,397
multiformats/go-multihash
opts/opts.go
Multihash
func (o *Options) Multihash(r io.Reader) (mh.Multihash, error) { b, err := ioutil.ReadAll(r) if err != nil { return nil, err } return mh.Sum(b, o.AlgorithmCode, o.Length) }
go
func (o *Options) Multihash(r io.Reader) (mh.Multihash, error) { b, err := ioutil.ReadAll(r) if err != nil { return nil, err } return mh.Sum(b, o.AlgorithmCode, o.Length) }
[ "func", "(", "o", "*", "Options", ")", "Multihash", "(", "r", "io", ".", "Reader", ")", "(", "mh", ".", "Multihash", ",", "error", ")", "{", "b", ",", "err", ":=", "ioutil", ".", "ReadAll", "(", "r", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "mh", ".", "Sum", "(", "b", ",", "o", ".", "AlgorithmCode", ",", "o", ".", "Length", ")", "\n", "}" ]
// Multihash reads all the data in r and calculates its multihash.
[ "Multihash", "reads", "all", "the", "data", "in", "r", "and", "calculates", "its", "multihash", "." ]
c242156eec223a58ac13b8c114a2b31e87bbf558
https://github.com/multiformats/go-multihash/blob/c242156eec223a58ac13b8c114a2b31e87bbf558/opts/opts.go#L146-L153
11,398
multiformats/go-multihash
multihash.go
FromHexString
func FromHexString(s string) (Multihash, error) { b, err := hex.DecodeString(s) if err != nil { return Multihash{}, err } return Cast(b) }
go
func FromHexString(s string) (Multihash, error) { b, err := hex.DecodeString(s) if err != nil { return Multihash{}, err } return Cast(b) }
[ "func", "FromHexString", "(", "s", "string", ")", "(", "Multihash", ",", "error", ")", "{", "b", ",", "err", ":=", "hex", ".", "DecodeString", "(", "s", ")", "\n", "if", "err", "!=", "nil", "{", "return", "Multihash", "{", "}", ",", "err", "\n", "}", "\n\n", "return", "Cast", "(", "b", ")", "\n", "}" ]
// FromHexString parses a hex-encoded multihash.
[ "FromHexString", "parses", "a", "hex", "-", "encoded", "multihash", "." ]
c242156eec223a58ac13b8c114a2b31e87bbf558
https://github.com/multiformats/go-multihash/blob/c242156eec223a58ac13b8c114a2b31e87bbf558/multihash.go#L194-L201
11,399
multiformats/go-multihash
multihash.go
FromB58String
func FromB58String(s string) (m Multihash, err error) { b, err := b58.Decode(s) if err != nil { return Multihash{}, ErrInvalidMultihash } return Cast(b) }
go
func FromB58String(s string) (m Multihash, err error) { b, err := b58.Decode(s) if err != nil { return Multihash{}, ErrInvalidMultihash } return Cast(b) }
[ "func", "FromB58String", "(", "s", "string", ")", "(", "m", "Multihash", ",", "err", "error", ")", "{", "b", ",", "err", ":=", "b58", ".", "Decode", "(", "s", ")", "\n", "if", "err", "!=", "nil", "{", "return", "Multihash", "{", "}", ",", "ErrInvalidMultihash", "\n", "}", "\n\n", "return", "Cast", "(", "b", ")", "\n", "}" ]
// FromB58String parses a B58-encoded multihash.
[ "FromB58String", "parses", "a", "B58", "-", "encoded", "multihash", "." ]
c242156eec223a58ac13b8c114a2b31e87bbf558
https://github.com/multiformats/go-multihash/blob/c242156eec223a58ac13b8c114a2b31e87bbf558/multihash.go#L209-L216