repo
stringlengths
5
54
path
stringlengths
4
155
func_name
stringlengths
1
118
original_string
stringlengths
52
85.5k
language
stringclasses
1 value
code
stringlengths
52
85.5k
code_tokens
list
docstring
stringlengths
6
2.61k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
85
252
partition
stringclasses
1 value
hprose/hprose-golang
io/reader.go
ReadSliceWithoutTag
func (r *Reader) ReadSliceWithoutTag() []reflect.Value { l := r.ReadCount() v := make([]reflect.Value, l) if !r.Simple { setReaderRef(r, nil) } for i := 0; i < l; i++ { v[i] = reflect.New(interfaceType).Elem() r.ReadValue(v[i]) } r.readByte() return v }
go
func (r *Reader) ReadSliceWithoutTag() []reflect.Value { l := r.ReadCount() v := make([]reflect.Value, l) if !r.Simple { setReaderRef(r, nil) } for i := 0; i < l; i++ { v[i] = reflect.New(interfaceType).Elem() r.ReadValue(v[i]) } r.readByte() return v }
[ "func", "(", "r", "*", "Reader", ")", "ReadSliceWithoutTag", "(", ")", "[", "]", "reflect", ".", "Value", "{", "l", ":=", "r", ".", "ReadCount", "(", ")", "\n", "v", ":=", "make", "(", "[", "]", "reflect", ".", "Value", ",", "l", ")", "\n", "if", "!", "r", ".", "Simple", "{", "setReaderRef", "(", "r", ",", "nil", ")", "\n", "}", "\n", "for", "i", ":=", "0", ";", "i", "<", "l", ";", "i", "++", "{", "v", "[", "i", "]", "=", "reflect", ".", "New", "(", "interfaceType", ")", ".", "Elem", "(", ")", "\n", "r", ".", "ReadValue", "(", "v", "[", "i", "]", ")", "\n", "}", "\n", "r", ".", "readByte", "(", ")", "\n", "return", "v", "\n", "}" ]
// ReadSliceWithoutTag from the reader
[ "ReadSliceWithoutTag", "from", "the", "reader" ]
6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74
https://github.com/hprose/hprose-golang/blob/6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74/io/reader.go#L288-L300
train
hprose/hprose-golang
io/reader.go
ReadSlice
func (r *Reader) ReadSlice(v []reflect.Value) { l := len(v) if !r.Simple { setReaderRef(r, nil) } for i := 0; i < l; i++ { r.ReadValue(v[i]) } r.readByte() }
go
func (r *Reader) ReadSlice(v []reflect.Value) { l := len(v) if !r.Simple { setReaderRef(r, nil) } for i := 0; i < l; i++ { r.ReadValue(v[i]) } r.readByte() }
[ "func", "(", "r", "*", "Reader", ")", "ReadSlice", "(", "v", "[", "]", "reflect", ".", "Value", ")", "{", "l", ":=", "len", "(", "v", ")", "\n", "if", "!", "r", ".", "Simple", "{", "setReaderRef", "(", "r", ",", "nil", ")", "\n", "}", "\n", "for", "i", ":=", "0", ";", "i", "<", "l", ";", "i", "++", "{", "r", ".", "ReadValue", "(", "v", "[", "i", "]", ")", "\n", "}", "\n", "r", ".", "readByte", "(", ")", "\n", "}" ]
// ReadSlice from the reader
[ "ReadSlice", "from", "the", "reader" ]
6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74
https://github.com/hprose/hprose-golang/blob/6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74/io/reader.go#L303-L312
train
hprose/hprose-golang
io/reader.go
readRef
func (r *Reader) readRef() interface{} { if r.Simple { panic(errors.New("reference unserialization can't support in simple mode")) } return readRef(r, r.readInt()) }
go
func (r *Reader) readRef() interface{} { if r.Simple { panic(errors.New("reference unserialization can't support in simple mode")) } return readRef(r, r.readInt()) }
[ "func", "(", "r", "*", "Reader", ")", "readRef", "(", ")", "interface", "{", "}", "{", "if", "r", ".", "Simple", "{", "panic", "(", "errors", ".", "New", "(", "\"", "\"", ")", ")", "\n", "}", "\n", "return", "readRef", "(", "r", ",", "r", ".", "readInt", "(", ")", ")", "\n", "}" ]
// private methods & functions
[ "private", "methods", "&", "functions" ]
6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74
https://github.com/hprose/hprose-golang/blob/6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74/io/reader.go#L337-L342
train
hprose/hprose-golang
rpc/fasthttp/fasthttp_service.go
InitFastHTTPContext
func (context *FastHTTPContext) InitFastHTTPContext( service rpc.Service, ctx *fasthttp.RequestCtx) { context.InitServiceContext(service) context.RequestCtx = ctx }
go
func (context *FastHTTPContext) InitFastHTTPContext( service rpc.Service, ctx *fasthttp.RequestCtx) { context.InitServiceContext(service) context.RequestCtx = ctx }
[ "func", "(", "context", "*", "FastHTTPContext", ")", "InitFastHTTPContext", "(", "service", "rpc", ".", "Service", ",", "ctx", "*", "fasthttp", ".", "RequestCtx", ")", "{", "context", ".", "InitServiceContext", "(", "service", ")", "\n", "context", ".", "RequestCtx", "=", "ctx", "\n", "}" ]
// InitFastHTTPContext initializes FastHTTPContext
[ "InitFastHTTPContext", "initializes", "FastHTTPContext" ]
6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74
https://github.com/hprose/hprose-golang/blob/6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74/rpc/fasthttp/fasthttp_service.go#L42-L46
train
hprose/hprose-golang
rpc/fasthttp/fasthttp_service.go
NewFastHTTPService
func NewFastHTTPService() (service *FastHTTPService) { service = new(FastHTTPService) service.InitBaseHTTPService() service.contextPool = sync.Pool{ New: func() interface{} { return new(FastHTTPContext) }, } service.FixArguments = fasthttpFixArguments return }
go
func NewFastHTTPService() (service *FastHTTPService) { service = new(FastHTTPService) service.InitBaseHTTPService() service.contextPool = sync.Pool{ New: func() interface{} { return new(FastHTTPContext) }, } service.FixArguments = fasthttpFixArguments return }
[ "func", "NewFastHTTPService", "(", ")", "(", "service", "*", "FastHTTPService", ")", "{", "service", "=", "new", "(", "FastHTTPService", ")", "\n", "service", ".", "InitBaseHTTPService", "(", ")", "\n", "service", ".", "contextPool", "=", "sync", ".", "Pool", "{", "New", ":", "func", "(", ")", "interface", "{", "}", "{", "return", "new", "(", "FastHTTPContext", ")", "}", ",", "}", "\n", "service", ".", "FixArguments", "=", "fasthttpFixArguments", "\n", "return", "\n", "}" ]
// NewFastHTTPService is the constructor of FastHTTPService
[ "NewFastHTTPService", "is", "the", "constructor", "of", "FastHTTPService" ]
6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74
https://github.com/hprose/hprose-golang/blob/6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74/rpc/fasthttp/fasthttp_service.go#L79-L87
train
hprose/hprose-golang
rpc/fasthttp/fasthttp_service.go
ServeFastHTTP
func (service *FastHTTPService) ServeFastHTTP(ctx *fasthttp.RequestCtx) { if service.clientAccessPolicyXMLHandler(ctx) || service.crossDomainXMLHandler(ctx) { return } context := service.acquireContext() context.InitFastHTTPContext(service, ctx) var resp []byte if err := service.sendHeader(context); err == nil { switch util.ByteString(ctx.Method()) { case "GET": if service.GET { resp = service.DoFunctionList(context) } else { ctx.SetStatusCode(403) } case "POST": resp = service.Handle(ctx.PostBody(), context) } } else { resp = service.EndError(err, context) } context.RequestCtx = nil service.releaseContext(context) ctx.Response.Header.Set("Content-Length", util.Itoa(len(resp))) ctx.SetBody(resp) }
go
func (service *FastHTTPService) ServeFastHTTP(ctx *fasthttp.RequestCtx) { if service.clientAccessPolicyXMLHandler(ctx) || service.crossDomainXMLHandler(ctx) { return } context := service.acquireContext() context.InitFastHTTPContext(service, ctx) var resp []byte if err := service.sendHeader(context); err == nil { switch util.ByteString(ctx.Method()) { case "GET": if service.GET { resp = service.DoFunctionList(context) } else { ctx.SetStatusCode(403) } case "POST": resp = service.Handle(ctx.PostBody(), context) } } else { resp = service.EndError(err, context) } context.RequestCtx = nil service.releaseContext(context) ctx.Response.Header.Set("Content-Length", util.Itoa(len(resp))) ctx.SetBody(resp) }
[ "func", "(", "service", "*", "FastHTTPService", ")", "ServeFastHTTP", "(", "ctx", "*", "fasthttp", ".", "RequestCtx", ")", "{", "if", "service", ".", "clientAccessPolicyXMLHandler", "(", "ctx", ")", "||", "service", ".", "crossDomainXMLHandler", "(", "ctx", ")", "{", "return", "\n", "}", "\n", "context", ":=", "service", ".", "acquireContext", "(", ")", "\n", "context", ".", "InitFastHTTPContext", "(", "service", ",", "ctx", ")", "\n", "var", "resp", "[", "]", "byte", "\n", "if", "err", ":=", "service", ".", "sendHeader", "(", "context", ")", ";", "err", "==", "nil", "{", "switch", "util", ".", "ByteString", "(", "ctx", ".", "Method", "(", ")", ")", "{", "case", "\"", "\"", ":", "if", "service", ".", "GET", "{", "resp", "=", "service", ".", "DoFunctionList", "(", "context", ")", "\n", "}", "else", "{", "ctx", ".", "SetStatusCode", "(", "403", ")", "\n", "}", "\n", "case", "\"", "\"", ":", "resp", "=", "service", ".", "Handle", "(", "ctx", ".", "PostBody", "(", ")", ",", "context", ")", "\n", "}", "\n", "}", "else", "{", "resp", "=", "service", ".", "EndError", "(", "err", ",", "context", ")", "\n", "}", "\n", "context", ".", "RequestCtx", "=", "nil", "\n", "service", ".", "releaseContext", "(", "context", ")", "\n", "ctx", ".", "Response", ".", "Header", ".", "Set", "(", "\"", "\"", ",", "util", ".", "Itoa", "(", "len", "(", "resp", ")", ")", ")", "\n", "ctx", ".", "SetBody", "(", "resp", ")", "\n", "}" ]
// ServeFastHTTP is the hprose fasthttp handler method
[ "ServeFastHTTP", "is", "the", "hprose", "fasthttp", "handler", "method" ]
6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74
https://github.com/hprose/hprose-golang/blob/6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74/rpc/fasthttp/fasthttp_service.go#L177-L203
train
hprose/hprose-golang
rpc/unix_service.go
ServeUnixConn
func (service *UnixService) ServeUnixConn(conn *net.UnixConn) { if service.TLSConfig != nil { tlsConn := tls.Server(conn, service.TLSConfig) tlsConn.Handshake() service.serveConn(tlsConn) } else { service.serveConn(conn) } }
go
func (service *UnixService) ServeUnixConn(conn *net.UnixConn) { if service.TLSConfig != nil { tlsConn := tls.Server(conn, service.TLSConfig) tlsConn.Handshake() service.serveConn(tlsConn) } else { service.serveConn(conn) } }
[ "func", "(", "service", "*", "UnixService", ")", "ServeUnixConn", "(", "conn", "*", "net", ".", "UnixConn", ")", "{", "if", "service", ".", "TLSConfig", "!=", "nil", "{", "tlsConn", ":=", "tls", ".", "Server", "(", "conn", ",", "service", ".", "TLSConfig", ")", "\n", "tlsConn", ".", "Handshake", "(", ")", "\n", "service", ".", "serveConn", "(", "tlsConn", ")", "\n", "}", "else", "{", "service", ".", "serveConn", "(", "conn", ")", "\n", "}", "\n", "}" ]
// ServeUnixConn runs on a single tcp connection. ServeUnixConn blocks, serving // the connection until the client hangs up. The caller typically invokes // ServeUnixConn in a go statement.
[ "ServeUnixConn", "runs", "on", "a", "single", "tcp", "connection", ".", "ServeUnixConn", "blocks", "serving", "the", "connection", "until", "the", "client", "hangs", "up", ".", "The", "caller", "typically", "invokes", "ServeUnixConn", "in", "a", "go", "statement", "." ]
6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74
https://github.com/hprose/hprose-golang/blob/6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74/rpc/unix_service.go#L43-L51
train
hprose/hprose-golang
rpc/unix_service.go
ServeUnix
func (service *UnixService) ServeUnix(listener *net.UnixListener) { service.workerPool.Start(); defer service.workerPool.Stop(); var tempDelay time.Duration // how long to sleep on accept failure for { conn, err := listener.AcceptUnix() if err != nil { tempDelay = nextTempDelay(err, service.Event, tempDelay) if tempDelay > 0 { continue } return } tempDelay = 0 service.workerPool.Go(func() { service.ServeUnixConn(conn) }); } }
go
func (service *UnixService) ServeUnix(listener *net.UnixListener) { service.workerPool.Start(); defer service.workerPool.Stop(); var tempDelay time.Duration // how long to sleep on accept failure for { conn, err := listener.AcceptUnix() if err != nil { tempDelay = nextTempDelay(err, service.Event, tempDelay) if tempDelay > 0 { continue } return } tempDelay = 0 service.workerPool.Go(func() { service.ServeUnixConn(conn) }); } }
[ "func", "(", "service", "*", "UnixService", ")", "ServeUnix", "(", "listener", "*", "net", ".", "UnixListener", ")", "{", "service", ".", "workerPool", ".", "Start", "(", ")", ";", "defer", "service", ".", "workerPool", ".", "Stop", "(", ")", ";", "var", "tempDelay", "time", ".", "Duration", "// how long to sleep on accept failure", "\n", "for", "{", "conn", ",", "err", ":=", "listener", ".", "AcceptUnix", "(", ")", "\n", "if", "err", "!=", "nil", "{", "tempDelay", "=", "nextTempDelay", "(", "err", ",", "service", ".", "Event", ",", "tempDelay", ")", "\n", "if", "tempDelay", ">", "0", "{", "continue", "\n", "}", "\n", "return", "\n", "}", "\n", "tempDelay", "=", "0", "\n", "service", ".", "workerPool", ".", "Go", "(", "func", "(", ")", "{", "service", ".", "ServeUnixConn", "(", "conn", ")", "\n", "}", ")", ";", "}", "\n", "}" ]
// ServeUnix runs on the UnixListener. ServeUnix blocks, serving the listener // until the server is stop. The caller typically invokes ServeUnix in a go // statement.
[ "ServeUnix", "runs", "on", "the", "UnixListener", ".", "ServeUnix", "blocks", "serving", "the", "listener", "until", "the", "server", "is", "stop", ".", "The", "caller", "typically", "invokes", "ServeUnix", "in", "a", "go", "statement", "." ]
6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74
https://github.com/hprose/hprose-golang/blob/6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74/rpc/unix_service.go#L63-L81
train
hprose/hprose-golang
io/byte_reader.go
NewByteReader
func NewByteReader(buf []byte) (reader *ByteReader) { reader = new(ByteReader) reader.buf = buf return }
go
func NewByteReader(buf []byte) (reader *ByteReader) { reader = new(ByteReader) reader.buf = buf return }
[ "func", "NewByteReader", "(", "buf", "[", "]", "byte", ")", "(", "reader", "*", "ByteReader", ")", "{", "reader", "=", "new", "(", "ByteReader", ")", "\n", "reader", ".", "buf", "=", "buf", "\n", "return", "\n", "}" ]
// NewByteReader is a constructor for ByteReader
[ "NewByteReader", "is", "a", "constructor", "for", "ByteReader" ]
6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74
https://github.com/hprose/hprose-golang/blob/6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74/io/byte_reader.go#L40-L44
train
hprose/hprose-golang
io/byte_reader.go
ReadByte
func (r *ByteReader) ReadByte() (byte, error) { if r.off >= len(r.buf) { return 0, io.EOF } return r.readByte(), nil }
go
func (r *ByteReader) ReadByte() (byte, error) { if r.off >= len(r.buf) { return 0, io.EOF } return r.readByte(), nil }
[ "func", "(", "r", "*", "ByteReader", ")", "ReadByte", "(", ")", "(", "byte", ",", "error", ")", "{", "if", "r", ".", "off", ">=", "len", "(", "r", ".", "buf", ")", "{", "return", "0", ",", "io", ".", "EOF", "\n", "}", "\n", "return", "r", ".", "readByte", "(", ")", ",", "nil", "\n", "}" ]
// ReadByte reads and returns a single byte. If no byte is available, // it returns error io.EOF.
[ "ReadByte", "reads", "and", "returns", "a", "single", "byte", ".", "If", "no", "byte", "is", "available", "it", "returns", "error", "io", ".", "EOF", "." ]
6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74
https://github.com/hprose/hprose-golang/blob/6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74/io/byte_reader.go#L54-L59
train
hprose/hprose-golang
io/byte_reader.go
Unread
func (r *ByteReader) Unread(n int) { if r.off >= n { r.off -= n } else { r.off = 0 } }
go
func (r *ByteReader) Unread(n int) { if r.off >= n { r.off -= n } else { r.off = 0 } }
[ "func", "(", "r", "*", "ByteReader", ")", "Unread", "(", "n", "int", ")", "{", "if", "r", ".", "off", ">=", "n", "{", "r", ".", "off", "-=", "n", "\n", "}", "else", "{", "r", ".", "off", "=", "0", "\n", "}", "\n", "}" ]
// Unread n bytes from the current position.
[ "Unread", "n", "bytes", "from", "the", "current", "position", "." ]
6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74
https://github.com/hprose/hprose-golang/blob/6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74/io/byte_reader.go#L82-L88
train
hprose/hprose-golang
io/byte_reader.go
Next
func (r *ByteReader) Next(n int) (data []byte) { p := r.off + n if p > len(r.buf) { p = len(r.buf) } data = r.buf[r.off:p] r.off = p return }
go
func (r *ByteReader) Next(n int) (data []byte) { p := r.off + n if p > len(r.buf) { p = len(r.buf) } data = r.buf[r.off:p] r.off = p return }
[ "func", "(", "r", "*", "ByteReader", ")", "Next", "(", "n", "int", ")", "(", "data", "[", "]", "byte", ")", "{", "p", ":=", "r", ".", "off", "+", "n", "\n", "if", "p", ">", "len", "(", "r", ".", "buf", ")", "{", "p", "=", "len", "(", "r", ".", "buf", ")", "\n", "}", "\n", "data", "=", "r", ".", "buf", "[", "r", ".", "off", ":", "p", "]", "\n", "r", ".", "off", "=", "p", "\n", "return", "\n", "}" ]
// Next returns a slice containing the next n bytes from the buffer, // advancing the buffer as if the bytes had been returned by Read. // If there are fewer than n bytes, Next returns the entire buffer. // The slice is only valid until the next call to a read or write method.
[ "Next", "returns", "a", "slice", "containing", "the", "next", "n", "bytes", "from", "the", "buffer", "advancing", "the", "buffer", "as", "if", "the", "bytes", "had", "been", "returned", "by", "Read", ".", "If", "there", "are", "fewer", "than", "n", "bytes", "Next", "returns", "the", "entire", "buffer", ".", "The", "slice", "is", "only", "valid", "until", "the", "next", "call", "to", "a", "read", "or", "write", "method", "." ]
6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74
https://github.com/hprose/hprose-golang/blob/6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74/io/byte_reader.go#L109-L117
train
hprose/hprose-golang
rpc/http_client.go
NewHTTPClient
func NewHTTPClient(uri ...string) (client *HTTPClient) { client = new(HTTPClient) client.InitBaseClient() client.limiter.InitLimiter() client.httpClient.Transport = &client.Transport client.Header = make(http.Header) client.DisableCompression = true client.DisableKeepAlives = false client.MaxIdleConnsPerHost = 10 client.httpClient.Jar = cookieJar if DisableGlobalCookie { client.httpClient.Jar, _ = cookiejar.New(nil) } client.SetURIList(uri) client.SendAndReceive = client.sendAndReceive return }
go
func NewHTTPClient(uri ...string) (client *HTTPClient) { client = new(HTTPClient) client.InitBaseClient() client.limiter.InitLimiter() client.httpClient.Transport = &client.Transport client.Header = make(http.Header) client.DisableCompression = true client.DisableKeepAlives = false client.MaxIdleConnsPerHost = 10 client.httpClient.Jar = cookieJar if DisableGlobalCookie { client.httpClient.Jar, _ = cookiejar.New(nil) } client.SetURIList(uri) client.SendAndReceive = client.sendAndReceive return }
[ "func", "NewHTTPClient", "(", "uri", "...", "string", ")", "(", "client", "*", "HTTPClient", ")", "{", "client", "=", "new", "(", "HTTPClient", ")", "\n", "client", ".", "InitBaseClient", "(", ")", "\n", "client", ".", "limiter", ".", "InitLimiter", "(", ")", "\n", "client", ".", "httpClient", ".", "Transport", "=", "&", "client", ".", "Transport", "\n", "client", ".", "Header", "=", "make", "(", "http", ".", "Header", ")", "\n", "client", ".", "DisableCompression", "=", "true", "\n", "client", ".", "DisableKeepAlives", "=", "false", "\n", "client", ".", "MaxIdleConnsPerHost", "=", "10", "\n", "client", ".", "httpClient", ".", "Jar", "=", "cookieJar", "\n", "if", "DisableGlobalCookie", "{", "client", ".", "httpClient", ".", "Jar", ",", "_", "=", "cookiejar", ".", "New", "(", "nil", ")", "\n", "}", "\n", "client", ".", "SetURIList", "(", "uri", ")", "\n", "client", ".", "SendAndReceive", "=", "client", ".", "sendAndReceive", "\n", "return", "\n", "}" ]
// NewHTTPClient is the constructor of HTTPClient
[ "NewHTTPClient", "is", "the", "constructor", "of", "HTTPClient" ]
6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74
https://github.com/hprose/hprose-golang/blob/6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74/rpc/http_client.go#L47-L63
train
hprose/hprose-golang
rpc/fasthttp/fasthttp_client.go
NewFastHTTPClient
func NewFastHTTPClient(uri ...string) (client *FastHTTPClient) { client = new(FastHTTPClient) client.InitBaseClient() client.limiter.InitLimiter() client.cookieManager = globalCookieManager if rpc.DisableGlobalCookie { client.cookieManager = newCookieManager() } client.compression = false client.keepAlive = true client.SetURIList(uri) client.SendAndReceive = client.sendAndReceive return }
go
func NewFastHTTPClient(uri ...string) (client *FastHTTPClient) { client = new(FastHTTPClient) client.InitBaseClient() client.limiter.InitLimiter() client.cookieManager = globalCookieManager if rpc.DisableGlobalCookie { client.cookieManager = newCookieManager() } client.compression = false client.keepAlive = true client.SetURIList(uri) client.SendAndReceive = client.sendAndReceive return }
[ "func", "NewFastHTTPClient", "(", "uri", "...", "string", ")", "(", "client", "*", "FastHTTPClient", ")", "{", "client", "=", "new", "(", "FastHTTPClient", ")", "\n", "client", ".", "InitBaseClient", "(", ")", "\n", "client", ".", "limiter", ".", "InitLimiter", "(", ")", "\n", "client", ".", "cookieManager", "=", "globalCookieManager", "\n", "if", "rpc", ".", "DisableGlobalCookie", "{", "client", ".", "cookieManager", "=", "newCookieManager", "(", ")", "\n", "}", "\n", "client", ".", "compression", "=", "false", "\n", "client", ".", "keepAlive", "=", "true", "\n", "client", ".", "SetURIList", "(", "uri", ")", "\n", "client", ".", "SendAndReceive", "=", "client", ".", "sendAndReceive", "\n", "return", "\n", "}" ]
// NewFastHTTPClient is the constructor of FastHTTPClient
[ "NewFastHTTPClient", "is", "the", "constructor", "of", "FastHTTPClient" ]
6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74
https://github.com/hprose/hprose-golang/blob/6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74/rpc/fasthttp/fasthttp_client.go#L97-L110
train
hprose/hprose-golang
rpc/limiter.go
Limit
func (limiter *Limiter) Limit() { for { if limiter.requestCount < limiter.MaxConcurrentRequests { break } limiter.Wait() } limiter.requestCount++ }
go
func (limiter *Limiter) Limit() { for { if limiter.requestCount < limiter.MaxConcurrentRequests { break } limiter.Wait() } limiter.requestCount++ }
[ "func", "(", "limiter", "*", "Limiter", ")", "Limit", "(", ")", "{", "for", "{", "if", "limiter", ".", "requestCount", "<", "limiter", ".", "MaxConcurrentRequests", "{", "break", "\n", "}", "\n", "limiter", ".", "Wait", "(", ")", "\n", "}", "\n", "limiter", ".", "requestCount", "++", "\n", "}" ]
// Limit the request
[ "Limit", "the", "request" ]
6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74
https://github.com/hprose/hprose-golang/blob/6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74/rpc/limiter.go#L38-L46
train
hprose/hprose-golang
rpc/limiter.go
Reset
func (limiter *Limiter) Reset() { limiter.requestCount = 0 for i := limiter.MaxConcurrentRequests; i > 0; i-- { limiter.Signal() } }
go
func (limiter *Limiter) Reset() { limiter.requestCount = 0 for i := limiter.MaxConcurrentRequests; i > 0; i-- { limiter.Signal() } }
[ "func", "(", "limiter", "*", "Limiter", ")", "Reset", "(", ")", "{", "limiter", ".", "requestCount", "=", "0", "\n", "for", "i", ":=", "limiter", ".", "MaxConcurrentRequests", ";", "i", ">", "0", ";", "i", "--", "{", "limiter", ".", "Signal", "(", ")", "\n", "}", "\n", "}" ]
// Reset the Limiter
[ "Reset", "the", "Limiter" ]
6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74
https://github.com/hprose/hprose-golang/blob/6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74/rpc/limiter.go#L55-L60
train
hprose/hprose-golang
rpc/basehttp_service.go
InitBaseHTTPService
func (service *BaseHTTPService) InitBaseHTTPService() { t := time.Now().UTC() rand.Seed(t.UnixNano()) service.InitBaseService() service.P3P = true service.GET = true service.CrossDomain = true service.AccessControlAllowOrigins = make(map[string]bool) service.LastModified = t.Format(time.RFC1123) service.Etag = `"` + strconv.FormatInt(rand.Int63(), 16) + `"` }
go
func (service *BaseHTTPService) InitBaseHTTPService() { t := time.Now().UTC() rand.Seed(t.UnixNano()) service.InitBaseService() service.P3P = true service.GET = true service.CrossDomain = true service.AccessControlAllowOrigins = make(map[string]bool) service.LastModified = t.Format(time.RFC1123) service.Etag = `"` + strconv.FormatInt(rand.Int63(), 16) + `"` }
[ "func", "(", "service", "*", "BaseHTTPService", ")", "InitBaseHTTPService", "(", ")", "{", "t", ":=", "time", ".", "Now", "(", ")", ".", "UTC", "(", ")", "\n", "rand", ".", "Seed", "(", "t", ".", "UnixNano", "(", ")", ")", "\n", "service", ".", "InitBaseService", "(", ")", "\n", "service", ".", "P3P", "=", "true", "\n", "service", ".", "GET", "=", "true", "\n", "service", ".", "CrossDomain", "=", "true", "\n", "service", ".", "AccessControlAllowOrigins", "=", "make", "(", "map", "[", "string", "]", "bool", ")", "\n", "service", ".", "LastModified", "=", "t", ".", "Format", "(", "time", ".", "RFC1123", ")", "\n", "service", ".", "Etag", "=", "`\"`", "+", "strconv", ".", "FormatInt", "(", "rand", ".", "Int63", "(", ")", ",", "16", ")", "+", "`\"`", "\n", "}" ]
// InitBaseHTTPService initializes BaseHTTPService
[ "InitBaseHTTPService", "initializes", "BaseHTTPService" ]
6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74
https://github.com/hprose/hprose-golang/blob/6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74/rpc/basehttp_service.go#L45-L55
train
hprose/hprose-golang
rpc/basehttp_service.go
AddAccessControlAllowOrigin
func (service *BaseHTTPService) AddAccessControlAllowOrigin(origins ...string) { for _, origin := range origins { service.AccessControlAllowOrigins[origin] = true } }
go
func (service *BaseHTTPService) AddAccessControlAllowOrigin(origins ...string) { for _, origin := range origins { service.AccessControlAllowOrigins[origin] = true } }
[ "func", "(", "service", "*", "BaseHTTPService", ")", "AddAccessControlAllowOrigin", "(", "origins", "...", "string", ")", "{", "for", "_", ",", "origin", ":=", "range", "origins", "{", "service", ".", "AccessControlAllowOrigins", "[", "origin", "]", "=", "true", "\n", "}", "\n", "}" ]
// AddAccessControlAllowOrigin add access control allow origin
[ "AddAccessControlAllowOrigin", "add", "access", "control", "allow", "origin" ]
6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74
https://github.com/hprose/hprose-golang/blob/6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74/rpc/basehttp_service.go#L58-L62
train
hprose/hprose-golang
rpc/basehttp_service.go
RemoveAccessControlAllowOrigin
func (service *BaseHTTPService) RemoveAccessControlAllowOrigin(origins ...string) { for _, origin := range origins { delete(service.AccessControlAllowOrigins, origin) } }
go
func (service *BaseHTTPService) RemoveAccessControlAllowOrigin(origins ...string) { for _, origin := range origins { delete(service.AccessControlAllowOrigins, origin) } }
[ "func", "(", "service", "*", "BaseHTTPService", ")", "RemoveAccessControlAllowOrigin", "(", "origins", "...", "string", ")", "{", "for", "_", ",", "origin", ":=", "range", "origins", "{", "delete", "(", "service", ".", "AccessControlAllowOrigins", ",", "origin", ")", "\n", "}", "\n", "}" ]
// RemoveAccessControlAllowOrigin remove access control allow origin
[ "RemoveAccessControlAllowOrigin", "remove", "access", "control", "allow", "origin" ]
6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74
https://github.com/hprose/hprose-golang/blob/6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74/rpc/basehttp_service.go#L65-L69
train
hprose/hprose-golang
rpc/basehttp_service.go
SetCrossDomainXMLFile
func (service *BaseHTTPService) SetCrossDomainXMLFile(filename string) { service.crossDomainXMLFile = filename service.crossDomainXMLContent, _ = ioutil.ReadFile(filename) }
go
func (service *BaseHTTPService) SetCrossDomainXMLFile(filename string) { service.crossDomainXMLFile = filename service.crossDomainXMLContent, _ = ioutil.ReadFile(filename) }
[ "func", "(", "service", "*", "BaseHTTPService", ")", "SetCrossDomainXMLFile", "(", "filename", "string", ")", "{", "service", ".", "crossDomainXMLFile", "=", "filename", "\n", "service", ".", "crossDomainXMLContent", ",", "_", "=", "ioutil", ".", "ReadFile", "(", "filename", ")", "\n", "}" ]
// SetCrossDomainXMLFile set the cross domain xml file
[ "SetCrossDomainXMLFile", "set", "the", "cross", "domain", "xml", "file" ]
6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74
https://github.com/hprose/hprose-golang/blob/6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74/rpc/basehttp_service.go#L92-L95
train
hprose/hprose-golang
rpc/basehttp_service.go
SetClientAccessPolicyXMLFile
func (service *BaseHTTPService) SetClientAccessPolicyXMLFile(filename string) { service.clientAccessPolicyXMLFile = filename service.clientAccessPolicyXMLContent, _ = ioutil.ReadFile(filename) }
go
func (service *BaseHTTPService) SetClientAccessPolicyXMLFile(filename string) { service.clientAccessPolicyXMLFile = filename service.clientAccessPolicyXMLContent, _ = ioutil.ReadFile(filename) }
[ "func", "(", "service", "*", "BaseHTTPService", ")", "SetClientAccessPolicyXMLFile", "(", "filename", "string", ")", "{", "service", ".", "clientAccessPolicyXMLFile", "=", "filename", "\n", "service", ".", "clientAccessPolicyXMLContent", ",", "_", "=", "ioutil", ".", "ReadFile", "(", "filename", ")", "\n", "}" ]
// SetClientAccessPolicyXMLFile set the client access policy xml file
[ "SetClientAccessPolicyXMLFile", "set", "the", "client", "access", "policy", "xml", "file" ]
6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74
https://github.com/hprose/hprose-golang/blob/6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74/rpc/basehttp_service.go#L98-L101
train
hprose/hprose-golang
rpc/basehttp_service.go
SetCrossDomainXMLContent
func (service *BaseHTTPService) SetCrossDomainXMLContent(content []byte) { service.crossDomainXMLFile = "" service.crossDomainXMLContent = content }
go
func (service *BaseHTTPService) SetCrossDomainXMLContent(content []byte) { service.crossDomainXMLFile = "" service.crossDomainXMLContent = content }
[ "func", "(", "service", "*", "BaseHTTPService", ")", "SetCrossDomainXMLContent", "(", "content", "[", "]", "byte", ")", "{", "service", ".", "crossDomainXMLFile", "=", "\"", "\"", "\n", "service", ".", "crossDomainXMLContent", "=", "content", "\n", "}" ]
// SetCrossDomainXMLContent set the cross domain xml content
[ "SetCrossDomainXMLContent", "set", "the", "cross", "domain", "xml", "content" ]
6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74
https://github.com/hprose/hprose-golang/blob/6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74/rpc/basehttp_service.go#L104-L107
train
hprose/hprose-golang
rpc/basehttp_service.go
SetClientAccessPolicyXMLContent
func (service *BaseHTTPService) SetClientAccessPolicyXMLContent(content []byte) { service.clientAccessPolicyXMLFile = "" service.clientAccessPolicyXMLContent = content }
go
func (service *BaseHTTPService) SetClientAccessPolicyXMLContent(content []byte) { service.clientAccessPolicyXMLFile = "" service.clientAccessPolicyXMLContent = content }
[ "func", "(", "service", "*", "BaseHTTPService", ")", "SetClientAccessPolicyXMLContent", "(", "content", "[", "]", "byte", ")", "{", "service", ".", "clientAccessPolicyXMLFile", "=", "\"", "\"", "\n", "service", ".", "clientAccessPolicyXMLContent", "=", "content", "\n", "}" ]
// SetClientAccessPolicyXMLContent set the client access policy xml content
[ "SetClientAccessPolicyXMLContent", "set", "the", "client", "access", "policy", "xml", "content" ]
6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74
https://github.com/hprose/hprose-golang/blob/6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74/rpc/basehttp_service.go#L110-L113
train
hprose/hprose-golang
io/byte_writer.go
NewByteWriter
func NewByteWriter(buf []byte) (w *ByteWriter) { w = new(ByteWriter) w.buf = buf return w }
go
func NewByteWriter(buf []byte) (w *ByteWriter) { w = new(ByteWriter) w.buf = buf return w }
[ "func", "NewByteWriter", "(", "buf", "[", "]", "byte", ")", "(", "w", "*", "ByteWriter", ")", "{", "w", "=", "new", "(", "ByteWriter", ")", "\n", "w", ".", "buf", "=", "buf", "\n", "return", "w", "\n", "}" ]
// NewByteWriter create a ByteWriter in append mode
[ "NewByteWriter", "create", "a", "ByteWriter", "in", "append", "mode" ]
6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74
https://github.com/hprose/hprose-golang/blob/6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74/io/byte_writer.go#L30-L34
train
hprose/hprose-golang
io/byte_writer.go
Grow
func (w *ByteWriter) Grow(n int) { if n < 0 { panic("BytesWriter: negative count") } p := w.grow(n) w.buf = w.buf[0:p] }
go
func (w *ByteWriter) Grow(n int) { if n < 0 { panic("BytesWriter: negative count") } p := w.grow(n) w.buf = w.buf[0:p] }
[ "func", "(", "w", "*", "ByteWriter", ")", "Grow", "(", "n", "int", ")", "{", "if", "n", "<", "0", "{", "panic", "(", "\"", "\"", ")", "\n", "}", "\n", "p", ":=", "w", ".", "grow", "(", "n", ")", "\n", "w", ".", "buf", "=", "w", ".", "buf", "[", "0", ":", "p", "]", "\n", "}" ]
// Grow the the byte slice capacity of this writer.
[ "Grow", "the", "the", "byte", "slice", "capacity", "of", "this", "writer", "." ]
6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74
https://github.com/hprose/hprose-golang/blob/6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74/io/byte_writer.go#L81-L87
train
hprose/hprose-golang
io/byte_writer.go
WriteByte
func (w *ByteWriter) WriteByte(c byte) error { p := w.grow(1) w.buf[p] = c return nil }
go
func (w *ByteWriter) WriteByte(c byte) error { p := w.grow(1) w.buf[p] = c return nil }
[ "func", "(", "w", "*", "ByteWriter", ")", "WriteByte", "(", "c", "byte", ")", "error", "{", "p", ":=", "w", ".", "grow", "(", "1", ")", "\n", "w", ".", "buf", "[", "p", "]", "=", "c", "\n", "return", "nil", "\n", "}" ]
// WriteByte c to the byte slice of this writer.
[ "WriteByte", "c", "to", "the", "byte", "slice", "of", "this", "writer", "." ]
6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74
https://github.com/hprose/hprose-golang/blob/6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74/io/byte_writer.go#L90-L94
train
hprose/hprose-golang
io/byte_writer.go
Write
func (w *ByteWriter) Write(b []byte) (int, error) { p := w.grow(len(b)) return copy(w.buf[p:], b), nil }
go
func (w *ByteWriter) Write(b []byte) (int, error) { p := w.grow(len(b)) return copy(w.buf[p:], b), nil }
[ "func", "(", "w", "*", "ByteWriter", ")", "Write", "(", "b", "[", "]", "byte", ")", "(", "int", ",", "error", ")", "{", "p", ":=", "w", ".", "grow", "(", "len", "(", "b", ")", ")", "\n", "return", "copy", "(", "w", ".", "buf", "[", "p", ":", "]", ",", "b", ")", ",", "nil", "\n", "}" ]
// Write the contents of b to the byte slice of this writer.
[ "Write", "the", "contents", "of", "b", "to", "the", "byte", "slice", "of", "this", "writer", "." ]
6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74
https://github.com/hprose/hprose-golang/blob/6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74/io/byte_writer.go#L97-L100
train
hprose/hprose-golang
rpc/unix_client.go
NewUnixClient
func NewUnixClient(uri ...string) (client *UnixClient) { client = new(UnixClient) client.initSocketClient() client.setCreateConn(client.createUnixConn) client.SetURIList(uri) return }
go
func NewUnixClient(uri ...string) (client *UnixClient) { client = new(UnixClient) client.initSocketClient() client.setCreateConn(client.createUnixConn) client.SetURIList(uri) return }
[ "func", "NewUnixClient", "(", "uri", "...", "string", ")", "(", "client", "*", "UnixClient", ")", "{", "client", "=", "new", "(", "UnixClient", ")", "\n", "client", ".", "initSocketClient", "(", ")", "\n", "client", ".", "setCreateConn", "(", "client", ".", "createUnixConn", ")", "\n", "client", ".", "SetURIList", "(", "uri", ")", "\n", "return", "\n", "}" ]
// NewUnixClient is the constructor of UnixClient
[ "NewUnixClient", "is", "the", "constructor", "of", "UnixClient" ]
6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74
https://github.com/hprose/hprose-golang/blob/6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74/rpc/unix_client.go#L34-L40
train
hprose/hprose-golang
rpc/unix_server.go
NewUnixServer
func NewUnixServer(uri string) (server *UnixServer) { if uri == "" { uri = "unix:/tmp/hprose.sock" } server = new(UnixServer) server.initSocketService() server.starter.server = server server.uri = uri return }
go
func NewUnixServer(uri string) (server *UnixServer) { if uri == "" { uri = "unix:/tmp/hprose.sock" } server = new(UnixServer) server.initSocketService() server.starter.server = server server.uri = uri return }
[ "func", "NewUnixServer", "(", "uri", "string", ")", "(", "server", "*", "UnixServer", ")", "{", "if", "uri", "==", "\"", "\"", "{", "uri", "=", "\"", "\"", "\n", "}", "\n", "server", "=", "new", "(", "UnixServer", ")", "\n", "server", ".", "initSocketService", "(", ")", "\n", "server", ".", "starter", ".", "server", "=", "server", "\n", "server", ".", "uri", "=", "uri", "\n", "return", "\n", "}" ]
// NewUnixServer is the constructor for UnixServer
[ "NewUnixServer", "is", "the", "constructor", "for", "UnixServer" ]
6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74
https://github.com/hprose/hprose-golang/blob/6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74/rpc/unix_server.go#L36-L45
train
hprose/hprose-golang
rpc/unix_server.go
Handle
func (server *UnixServer) Handle() (err error) { if server.listener != nil { return ErrServerIsAlreadyStarted } u, err := url.Parse(server.uri) if err != nil { return err } addr, err := net.ResolveUnixAddr(u.Scheme, u.Path) if err != nil { return err } if server.listener, err = net.ListenUnix(u.Scheme, addr); err != nil { return err } go server.ServeUnix(server.listener) return nil }
go
func (server *UnixServer) Handle() (err error) { if server.listener != nil { return ErrServerIsAlreadyStarted } u, err := url.Parse(server.uri) if err != nil { return err } addr, err := net.ResolveUnixAddr(u.Scheme, u.Path) if err != nil { return err } if server.listener, err = net.ListenUnix(u.Scheme, addr); err != nil { return err } go server.ServeUnix(server.listener) return nil }
[ "func", "(", "server", "*", "UnixServer", ")", "Handle", "(", ")", "(", "err", "error", ")", "{", "if", "server", ".", "listener", "!=", "nil", "{", "return", "ErrServerIsAlreadyStarted", "\n", "}", "\n", "u", ",", "err", ":=", "url", ".", "Parse", "(", "server", ".", "uri", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "addr", ",", "err", ":=", "net", ".", "ResolveUnixAddr", "(", "u", ".", "Scheme", ",", "u", ".", "Path", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "if", "server", ".", "listener", ",", "err", "=", "net", ".", "ListenUnix", "(", "u", ".", "Scheme", ",", "addr", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "go", "server", ".", "ServeUnix", "(", "server", ".", "listener", ")", "\n", "return", "nil", "\n", "}" ]
// Handle the hprose unix server
[ "Handle", "the", "hprose", "unix", "server" ]
6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74
https://github.com/hprose/hprose-golang/blob/6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74/rpc/unix_server.go#L56-L73
train
hprose/hprose-golang
rpc/unix_server.go
Close
func (server *UnixServer) Close() { if server.listener != nil { listener := server.listener server.listener = nil listener.Close() } }
go
func (server *UnixServer) Close() { if server.listener != nil { listener := server.listener server.listener = nil listener.Close() } }
[ "func", "(", "server", "*", "UnixServer", ")", "Close", "(", ")", "{", "if", "server", ".", "listener", "!=", "nil", "{", "listener", ":=", "server", ".", "listener", "\n", "server", ".", "listener", "=", "nil", "\n", "listener", ".", "Close", "(", ")", "\n", "}", "\n", "}" ]
// Close the hprose unix server
[ "Close", "the", "hprose", "unix", "server" ]
6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74
https://github.com/hprose/hprose-golang/blob/6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74/rpc/unix_server.go#L76-L82
train
hprose/hprose-golang
rpc/filter.go
Filter
func (fm *filterManager) Filter() Filter { fm.fmLocker.RLock() defer fm.fmLocker.RUnlock() if len(fm.filters) == 0 { return nil } return fm.filters[0] }
go
func (fm *filterManager) Filter() Filter { fm.fmLocker.RLock() defer fm.fmLocker.RUnlock() if len(fm.filters) == 0 { return nil } return fm.filters[0] }
[ "func", "(", "fm", "*", "filterManager", ")", "Filter", "(", ")", "Filter", "{", "fm", ".", "fmLocker", ".", "RLock", "(", ")", "\n", "defer", "fm", ".", "fmLocker", ".", "RUnlock", "(", ")", "\n", "if", "len", "(", "fm", ".", "filters", ")", "==", "0", "{", "return", "nil", "\n", "}", "\n", "return", "fm", ".", "filters", "[", "0", "]", "\n", "}" ]
// Filter return the first filter
[ "Filter", "return", "the", "first", "filter" ]
6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74
https://github.com/hprose/hprose-golang/blob/6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74/rpc/filter.go#L37-L44
train
hprose/hprose-golang
rpc/filter.go
NumFilter
func (fm *filterManager) NumFilter() int { fm.fmLocker.RLock() defer fm.fmLocker.RUnlock() return len(fm.filters) }
go
func (fm *filterManager) NumFilter() int { fm.fmLocker.RLock() defer fm.fmLocker.RUnlock() return len(fm.filters) }
[ "func", "(", "fm", "*", "filterManager", ")", "NumFilter", "(", ")", "int", "{", "fm", ".", "fmLocker", ".", "RLock", "(", ")", "\n", "defer", "fm", ".", "fmLocker", ".", "RUnlock", "(", ")", "\n", "return", "len", "(", "fm", ".", "filters", ")", "\n", "}" ]
// NumFilter return the filter count
[ "NumFilter", "return", "the", "filter", "count" ]
6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74
https://github.com/hprose/hprose-golang/blob/6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74/rpc/filter.go#L47-L51
train
hprose/hprose-golang
rpc/filter.go
FilterByIndex
func (fm *filterManager) FilterByIndex(index int) Filter { fm.fmLocker.RLock() defer fm.fmLocker.RUnlock() n := len(fm.filters) if index < 0 && index >= n { return nil } return fm.filters[index] }
go
func (fm *filterManager) FilterByIndex(index int) Filter { fm.fmLocker.RLock() defer fm.fmLocker.RUnlock() n := len(fm.filters) if index < 0 && index >= n { return nil } return fm.filters[index] }
[ "func", "(", "fm", "*", "filterManager", ")", "FilterByIndex", "(", "index", "int", ")", "Filter", "{", "fm", ".", "fmLocker", ".", "RLock", "(", ")", "\n", "defer", "fm", ".", "fmLocker", ".", "RUnlock", "(", ")", "\n", "n", ":=", "len", "(", "fm", ".", "filters", ")", "\n", "if", "index", "<", "0", "&&", "index", ">=", "n", "{", "return", "nil", "\n", "}", "\n", "return", "fm", ".", "filters", "[", "index", "]", "\n", "}" ]
// FilterByIndex return the filter by index
[ "FilterByIndex", "return", "the", "filter", "by", "index" ]
6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74
https://github.com/hprose/hprose-golang/blob/6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74/rpc/filter.go#L54-L62
train
hprose/hprose-golang
rpc/filter.go
AddFilter
func (fm *filterManager) AddFilter(filter ...Filter) { fm.fmLocker.Lock() fm.addFilter(filter...) fm.fmLocker.Unlock() }
go
func (fm *filterManager) AddFilter(filter ...Filter) { fm.fmLocker.Lock() fm.addFilter(filter...) fm.fmLocker.Unlock() }
[ "func", "(", "fm", "*", "filterManager", ")", "AddFilter", "(", "filter", "...", "Filter", ")", "{", "fm", ".", "fmLocker", ".", "Lock", "(", ")", "\n", "fm", ".", "addFilter", "(", "filter", "...", ")", "\n", "fm", ".", "fmLocker", ".", "Unlock", "(", ")", "\n", "}" ]
// AddFilter add the filter to this FilterManager
[ "AddFilter", "add", "the", "filter", "to", "this", "FilterManager" ]
6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74
https://github.com/hprose/hprose-golang/blob/6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74/rpc/filter.go#L79-L83
train
hprose/hprose-golang
rpc/filter.go
RemoveFilter
func (fm *filterManager) RemoveFilter(filter ...Filter) { for i := range filter { fm.removeFilter(filter[i]) } }
go
func (fm *filterManager) RemoveFilter(filter ...Filter) { for i := range filter { fm.removeFilter(filter[i]) } }
[ "func", "(", "fm", "*", "filterManager", ")", "RemoveFilter", "(", "filter", "...", "Filter", ")", "{", "for", "i", ":=", "range", "filter", "{", "fm", ".", "removeFilter", "(", "filter", "[", "i", "]", ")", "\n", "}", "\n", "}" ]
// RemoveFilter remove the filter from this FilterManager
[ "RemoveFilter", "remove", "the", "filter", "from", "this", "FilterManager" ]
6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74
https://github.com/hprose/hprose-golang/blob/6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74/rpc/filter.go#L111-L115
train
hprose/hprose-golang
io/struct_encoder.go
Register
func Register(proto interface{}, alias string, tag ...string) { structType := reflect.TypeOf(proto) if structType.Kind() == reflect.Ptr { structType = structType.Elem() } if structType.Kind() != reflect.Struct { panic("invalid type: " + structType.String()) } structTypesLocker.Lock() structTypes[alias] = structType structTypesLocker.Unlock() structTypeCacheLocker.Lock() cache := &structCache{Alias: alias} if len(tag) == 1 { cache.Tag = tag[0] } cache.Fields = getFields(structType, cache.Tag) initStructCacheData(cache) structTypeCache[(*emptyInterface)(unsafe.Pointer(&structType)).ptr] = cache structTypeCacheLocker.Unlock() }
go
func Register(proto interface{}, alias string, tag ...string) { structType := reflect.TypeOf(proto) if structType.Kind() == reflect.Ptr { structType = structType.Elem() } if structType.Kind() != reflect.Struct { panic("invalid type: " + structType.String()) } structTypesLocker.Lock() structTypes[alias] = structType structTypesLocker.Unlock() structTypeCacheLocker.Lock() cache := &structCache{Alias: alias} if len(tag) == 1 { cache.Tag = tag[0] } cache.Fields = getFields(structType, cache.Tag) initStructCacheData(cache) structTypeCache[(*emptyInterface)(unsafe.Pointer(&structType)).ptr] = cache structTypeCacheLocker.Unlock() }
[ "func", "Register", "(", "proto", "interface", "{", "}", ",", "alias", "string", ",", "tag", "...", "string", ")", "{", "structType", ":=", "reflect", ".", "TypeOf", "(", "proto", ")", "\n", "if", "structType", ".", "Kind", "(", ")", "==", "reflect", ".", "Ptr", "{", "structType", "=", "structType", ".", "Elem", "(", ")", "\n", "}", "\n", "if", "structType", ".", "Kind", "(", ")", "!=", "reflect", ".", "Struct", "{", "panic", "(", "\"", "\"", "+", "structType", ".", "String", "(", ")", ")", "\n", "}", "\n", "structTypesLocker", ".", "Lock", "(", ")", "\n", "structTypes", "[", "alias", "]", "=", "structType", "\n", "structTypesLocker", ".", "Unlock", "(", ")", "\n\n", "structTypeCacheLocker", ".", "Lock", "(", ")", "\n", "cache", ":=", "&", "structCache", "{", "Alias", ":", "alias", "}", "\n", "if", "len", "(", "tag", ")", "==", "1", "{", "cache", ".", "Tag", "=", "tag", "[", "0", "]", "\n", "}", "\n", "cache", ".", "Fields", "=", "getFields", "(", "structType", ",", "cache", ".", "Tag", ")", "\n", "initStructCacheData", "(", "cache", ")", "\n", "structTypeCache", "[", "(", "*", "emptyInterface", ")", "(", "unsafe", ".", "Pointer", "(", "&", "structType", ")", ")", ".", "ptr", "]", "=", "cache", "\n", "structTypeCacheLocker", ".", "Unlock", "(", ")", "\n", "}" ]
// Register the type of the proto with alias & tag.
[ "Register", "the", "type", "of", "the", "proto", "with", "alias", "&", "tag", "." ]
6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74
https://github.com/hprose/hprose-golang/blob/6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74/io/struct_encoder.go#L164-L185
train
hprose/hprose-golang
io/struct_encoder.go
GetStructType
func GetStructType(alias string) (structType reflect.Type) { structTypesLocker.RLock() structType = structTypes[alias] structTypesLocker.RUnlock() return structType }
go
func GetStructType(alias string) (structType reflect.Type) { structTypesLocker.RLock() structType = structTypes[alias] structTypesLocker.RUnlock() return structType }
[ "func", "GetStructType", "(", "alias", "string", ")", "(", "structType", "reflect", ".", "Type", ")", "{", "structTypesLocker", ".", "RLock", "(", ")", "\n", "structType", "=", "structTypes", "[", "alias", "]", "\n", "structTypesLocker", ".", "RUnlock", "(", ")", "\n", "return", "structType", "\n", "}" ]
// GetStructType by alias.
[ "GetStructType", "by", "alias", "." ]
6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74
https://github.com/hprose/hprose-golang/blob/6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74/io/struct_encoder.go#L188-L193
train
hprose/hprose-golang
io/byte_pool.go
AcquireBytes
func AcquireBytes(size int) []byte { if size < 1 { return nil } capacity := pow2roundup(int64(size)) if capacity > maxSize { return make([]byte, size, capacity) } if capacity < 512 { capacity = 512 } return bytePool[log2(capacity)-9].Get().([]byte)[:size] }
go
func AcquireBytes(size int) []byte { if size < 1 { return nil } capacity := pow2roundup(int64(size)) if capacity > maxSize { return make([]byte, size, capacity) } if capacity < 512 { capacity = 512 } return bytePool[log2(capacity)-9].Get().([]byte)[:size] }
[ "func", "AcquireBytes", "(", "size", "int", ")", "[", "]", "byte", "{", "if", "size", "<", "1", "{", "return", "nil", "\n", "}", "\n", "capacity", ":=", "pow2roundup", "(", "int64", "(", "size", ")", ")", "\n", "if", "capacity", ">", "maxSize", "{", "return", "make", "(", "[", "]", "byte", ",", "size", ",", "capacity", ")", "\n", "}", "\n", "if", "capacity", "<", "512", "{", "capacity", "=", "512", "\n", "}", "\n", "return", "bytePool", "[", "log2", "(", "capacity", ")", "-", "9", "]", ".", "Get", "(", ")", ".", "(", "[", "]", "byte", ")", "[", ":", "size", "]", "\n", "}" ]
// AcquireBytes from pool.
[ "AcquireBytes", "from", "pool", "." ]
6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74
https://github.com/hprose/hprose-golang/blob/6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74/io/byte_pool.go#L68-L80
train
hprose/hprose-golang
io/byte_pool.go
ReleaseBytes
func ReleaseBytes(bytes []byte) bool { capacity := int64(cap(bytes)) if capacity < 512 || capacity > maxSize || capacity != pow2roundup(capacity) { return false } bytePool[log2(capacity)-9].Put(bytes) return true }
go
func ReleaseBytes(bytes []byte) bool { capacity := int64(cap(bytes)) if capacity < 512 || capacity > maxSize || capacity != pow2roundup(capacity) { return false } bytePool[log2(capacity)-9].Put(bytes) return true }
[ "func", "ReleaseBytes", "(", "bytes", "[", "]", "byte", ")", "bool", "{", "capacity", ":=", "int64", "(", "cap", "(", "bytes", ")", ")", "\n", "if", "capacity", "<", "512", "||", "capacity", ">", "maxSize", "||", "capacity", "!=", "pow2roundup", "(", "capacity", ")", "{", "return", "false", "\n", "}", "\n", "bytePool", "[", "log2", "(", "capacity", ")", "-", "9", "]", ".", "Put", "(", "bytes", ")", "\n", "return", "true", "\n", "}" ]
// ReleaseBytes to pool.
[ "ReleaseBytes", "to", "pool", "." ]
6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74
https://github.com/hprose/hprose-golang/blob/6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74/io/byte_pool.go#L83-L90
train
hprose/hprose-golang
rpc/method.go
AddFunction
func (mm *methodManager) AddFunction( name string, function interface{}, option ...Options) { if name == "" { panic("name can't be empty") } if function == nil { panic("function can't be nil") } f, ok := function.(reflect.Value) if !ok { f = reflect.ValueOf(function) } if f.Kind() != reflect.Func { panic("function must be func or bound method") } var options Options if len(option) > 0 { options = option[0] } if options.NameSpace != "" && name != "*" { name = options.NameSpace + "_" + name } mm.mmLocker.Lock() if mm.RemoteMethods[strings.ToLower(name)] == nil { mm.MethodNames = append(mm.MethodNames, name) } mm.RemoteMethods[strings.ToLower(name)] = &Method{f, options} mm.mmLocker.Unlock() }
go
func (mm *methodManager) AddFunction( name string, function interface{}, option ...Options) { if name == "" { panic("name can't be empty") } if function == nil { panic("function can't be nil") } f, ok := function.(reflect.Value) if !ok { f = reflect.ValueOf(function) } if f.Kind() != reflect.Func { panic("function must be func or bound method") } var options Options if len(option) > 0 { options = option[0] } if options.NameSpace != "" && name != "*" { name = options.NameSpace + "_" + name } mm.mmLocker.Lock() if mm.RemoteMethods[strings.ToLower(name)] == nil { mm.MethodNames = append(mm.MethodNames, name) } mm.RemoteMethods[strings.ToLower(name)] = &Method{f, options} mm.mmLocker.Unlock() }
[ "func", "(", "mm", "*", "methodManager", ")", "AddFunction", "(", "name", "string", ",", "function", "interface", "{", "}", ",", "option", "...", "Options", ")", "{", "if", "name", "==", "\"", "\"", "{", "panic", "(", "\"", "\"", ")", "\n", "}", "\n", "if", "function", "==", "nil", "{", "panic", "(", "\"", "\"", ")", "\n", "}", "\n", "f", ",", "ok", ":=", "function", ".", "(", "reflect", ".", "Value", ")", "\n", "if", "!", "ok", "{", "f", "=", "reflect", ".", "ValueOf", "(", "function", ")", "\n", "}", "\n", "if", "f", ".", "Kind", "(", ")", "!=", "reflect", ".", "Func", "{", "panic", "(", "\"", "\"", ")", "\n", "}", "\n", "var", "options", "Options", "\n", "if", "len", "(", "option", ")", ">", "0", "{", "options", "=", "option", "[", "0", "]", "\n", "}", "\n", "if", "options", ".", "NameSpace", "!=", "\"", "\"", "&&", "name", "!=", "\"", "\"", "{", "name", "=", "options", ".", "NameSpace", "+", "\"", "\"", "+", "name", "\n", "}", "\n", "mm", ".", "mmLocker", ".", "Lock", "(", ")", "\n", "if", "mm", ".", "RemoteMethods", "[", "strings", ".", "ToLower", "(", "name", ")", "]", "==", "nil", "{", "mm", ".", "MethodNames", "=", "append", "(", "mm", ".", "MethodNames", ",", "name", ")", "\n", "}", "\n", "mm", ".", "RemoteMethods", "[", "strings", ".", "ToLower", "(", "name", ")", "]", "=", "&", "Method", "{", "f", ",", "options", "}", "\n", "mm", ".", "mmLocker", ".", "Unlock", "(", ")", "\n", "}" ]
// AddFunction publish a func or bound method // name is the method name // function is a func or bound method // option includes Mode, Simple, Oneway and NameSpace
[ "AddFunction", "publish", "a", "func", "or", "bound", "method", "name", "is", "the", "method", "name", "function", "is", "a", "func", "or", "bound", "method", "option", "includes", "Mode", "Simple", "Oneway", "and", "NameSpace" ]
6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74
https://github.com/hprose/hprose-golang/blob/6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74/rpc/method.go#L59-L87
train
hprose/hprose-golang
rpc/service_context.go
InitServiceContext
func (context *BaseServiceContext) InitServiceContext(service Service) { context.InitBaseContext() context.service = service context.method = nil context.isMissingMethod = false context.byRef = false }
go
func (context *BaseServiceContext) InitServiceContext(service Service) { context.InitBaseContext() context.service = service context.method = nil context.isMissingMethod = false context.byRef = false }
[ "func", "(", "context", "*", "BaseServiceContext", ")", "InitServiceContext", "(", "service", "Service", ")", "{", "context", ".", "InitBaseContext", "(", ")", "\n", "context", ".", "service", "=", "service", "\n", "context", ".", "method", "=", "nil", "\n", "context", ".", "isMissingMethod", "=", "false", "\n", "context", ".", "byRef", "=", "false", "\n", "}" ]
// InitServiceContext initializes BaseServiceContext
[ "InitServiceContext", "initializes", "BaseServiceContext" ]
6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74
https://github.com/hprose/hprose-golang/blob/6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74/rpc/service_context.go#L45-L51
train
hprose/hprose-golang
rpc/tcp_service.go
ServeTCPConn
func (service *TCPService) ServeTCPConn(conn *net.TCPConn) { conn.SetLinger(service.Linger) conn.SetNoDelay(service.NoDelay) conn.SetKeepAlive(service.KeepAlive) if service.KeepAlivePeriod > 0 { conn.SetKeepAlivePeriod(service.KeepAlivePeriod) } if service.TLSConfig != nil { tlsConn := tls.Server(conn, service.TLSConfig) tlsConn.Handshake() service.serveConn(tlsConn) } else { service.serveConn(conn) } }
go
func (service *TCPService) ServeTCPConn(conn *net.TCPConn) { conn.SetLinger(service.Linger) conn.SetNoDelay(service.NoDelay) conn.SetKeepAlive(service.KeepAlive) if service.KeepAlivePeriod > 0 { conn.SetKeepAlivePeriod(service.KeepAlivePeriod) } if service.TLSConfig != nil { tlsConn := tls.Server(conn, service.TLSConfig) tlsConn.Handshake() service.serveConn(tlsConn) } else { service.serveConn(conn) } }
[ "func", "(", "service", "*", "TCPService", ")", "ServeTCPConn", "(", "conn", "*", "net", ".", "TCPConn", ")", "{", "conn", ".", "SetLinger", "(", "service", ".", "Linger", ")", "\n", "conn", ".", "SetNoDelay", "(", "service", ".", "NoDelay", ")", "\n", "conn", ".", "SetKeepAlive", "(", "service", ".", "KeepAlive", ")", "\n", "if", "service", ".", "KeepAlivePeriod", ">", "0", "{", "conn", ".", "SetKeepAlivePeriod", "(", "service", ".", "KeepAlivePeriod", ")", "\n", "}", "\n", "if", "service", ".", "TLSConfig", "!=", "nil", "{", "tlsConn", ":=", "tls", ".", "Server", "(", "conn", ",", "service", ".", "TLSConfig", ")", "\n", "tlsConn", ".", "Handshake", "(", ")", "\n", "service", ".", "serveConn", "(", "tlsConn", ")", "\n", "}", "else", "{", "service", ".", "serveConn", "(", "conn", ")", "\n", "}", "\n", "}" ]
// ServeTCPConn runs on a single tcp connection. ServeTCPConn blocks, serving // the connection until the client hangs up. The caller typically invokes // ServeTCPConn in a go statement.
[ "ServeTCPConn", "runs", "on", "a", "single", "tcp", "connection", ".", "ServeTCPConn", "blocks", "serving", "the", "connection", "until", "the", "client", "hangs", "up", ".", "The", "caller", "typically", "invokes", "ServeTCPConn", "in", "a", "go", "statement", "." ]
6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74
https://github.com/hprose/hprose-golang/blob/6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74/rpc/tcp_service.go#L55-L69
train
hprose/hprose-golang
rpc/tcp_service.go
ServeTCP
func (service *TCPService) ServeTCP(listener *net.TCPListener) { service.workerPool.Start(); defer service.workerPool.Stop(); var tempDelay time.Duration // how long to sleep on accept failure for { conn, err := listener.AcceptTCP() if err != nil { tempDelay = nextTempDelay(err, service.Event, tempDelay) if tempDelay > 0 { continue } return } tempDelay = 0 service.workerPool.Go(func() { service.ServeTCPConn(conn) }); } }
go
func (service *TCPService) ServeTCP(listener *net.TCPListener) { service.workerPool.Start(); defer service.workerPool.Stop(); var tempDelay time.Duration // how long to sleep on accept failure for { conn, err := listener.AcceptTCP() if err != nil { tempDelay = nextTempDelay(err, service.Event, tempDelay) if tempDelay > 0 { continue } return } tempDelay = 0 service.workerPool.Go(func() { service.ServeTCPConn(conn) }); } }
[ "func", "(", "service", "*", "TCPService", ")", "ServeTCP", "(", "listener", "*", "net", ".", "TCPListener", ")", "{", "service", ".", "workerPool", ".", "Start", "(", ")", ";", "defer", "service", ".", "workerPool", ".", "Stop", "(", ")", ";", "var", "tempDelay", "time", ".", "Duration", "// how long to sleep on accept failure", "\n", "for", "{", "conn", ",", "err", ":=", "listener", ".", "AcceptTCP", "(", ")", "\n", "if", "err", "!=", "nil", "{", "tempDelay", "=", "nextTempDelay", "(", "err", ",", "service", ".", "Event", ",", "tempDelay", ")", "\n", "if", "tempDelay", ">", "0", "{", "continue", "\n", "}", "\n", "return", "\n", "}", "\n", "tempDelay", "=", "0", "\n", "service", ".", "workerPool", ".", "Go", "(", "func", "(", ")", "{", "service", ".", "ServeTCPConn", "(", "conn", ")", "\n", "}", ")", ";", "}", "\n", "}" ]
// ServeTCP runs on the TCPListener. ServeTCP blocks, serving the listener // until the server is stop. The caller typically invokes ServeTCP in a go // statement.
[ "ServeTCP", "runs", "on", "the", "TCPListener", ".", "ServeTCP", "blocks", "serving", "the", "listener", "until", "the", "server", "is", "stop", ".", "The", "caller", "typically", "invokes", "ServeTCP", "in", "a", "go", "statement", "." ]
6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74
https://github.com/hprose/hprose-golang/blob/6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74/rpc/tcp_service.go#L81-L99
train
hprose/hprose-golang
rpc/filter/jsonrpc/service_filter.go
InputFilter
func (filter ServiceFilter) InputFilter(data []byte, context rpc.Context) []byte { if (len(data) > 0) && (data[0] == '[' || data[0] == '{') { var requests []map[string]interface{} if data[0] == '[' { if err := json.Unmarshal(data, &requests); err != nil { return data } } else { requests = make([]map[string]interface{}, 1) if err := json.Unmarshal(data, &requests[0]); err != nil { return data } } writer := io.NewWriter(true) n := len(requests) responses := make([]map[string]interface{}, n) for i, request := range requests { responses[i] = createResponse(request) if method, ok := request["method"].(string); ok && method != "" { writer.WriteByte(io.TagCall) writer.WriteString(method) if params, ok := request["params"].([]interface{}); ok && params != nil && len(params) > 0 { writer.Serialize(params) } } } writer.WriteByte(io.TagEnd) data = writer.Bytes() context.SetInterface("jsonrpc", responses) } return data }
go
func (filter ServiceFilter) InputFilter(data []byte, context rpc.Context) []byte { if (len(data) > 0) && (data[0] == '[' || data[0] == '{') { var requests []map[string]interface{} if data[0] == '[' { if err := json.Unmarshal(data, &requests); err != nil { return data } } else { requests = make([]map[string]interface{}, 1) if err := json.Unmarshal(data, &requests[0]); err != nil { return data } } writer := io.NewWriter(true) n := len(requests) responses := make([]map[string]interface{}, n) for i, request := range requests { responses[i] = createResponse(request) if method, ok := request["method"].(string); ok && method != "" { writer.WriteByte(io.TagCall) writer.WriteString(method) if params, ok := request["params"].([]interface{}); ok && params != nil && len(params) > 0 { writer.Serialize(params) } } } writer.WriteByte(io.TagEnd) data = writer.Bytes() context.SetInterface("jsonrpc", responses) } return data }
[ "func", "(", "filter", "ServiceFilter", ")", "InputFilter", "(", "data", "[", "]", "byte", ",", "context", "rpc", ".", "Context", ")", "[", "]", "byte", "{", "if", "(", "len", "(", "data", ")", ">", "0", ")", "&&", "(", "data", "[", "0", "]", "==", "'['", "||", "data", "[", "0", "]", "==", "'{'", ")", "{", "var", "requests", "[", "]", "map", "[", "string", "]", "interface", "{", "}", "\n", "if", "data", "[", "0", "]", "==", "'['", "{", "if", "err", ":=", "json", ".", "Unmarshal", "(", "data", ",", "&", "requests", ")", ";", "err", "!=", "nil", "{", "return", "data", "\n", "}", "\n", "}", "else", "{", "requests", "=", "make", "(", "[", "]", "map", "[", "string", "]", "interface", "{", "}", ",", "1", ")", "\n", "if", "err", ":=", "json", ".", "Unmarshal", "(", "data", ",", "&", "requests", "[", "0", "]", ")", ";", "err", "!=", "nil", "{", "return", "data", "\n", "}", "\n", "}", "\n", "writer", ":=", "io", ".", "NewWriter", "(", "true", ")", "\n", "n", ":=", "len", "(", "requests", ")", "\n", "responses", ":=", "make", "(", "[", "]", "map", "[", "string", "]", "interface", "{", "}", ",", "n", ")", "\n", "for", "i", ",", "request", ":=", "range", "requests", "{", "responses", "[", "i", "]", "=", "createResponse", "(", "request", ")", "\n", "if", "method", ",", "ok", ":=", "request", "[", "\"", "\"", "]", ".", "(", "string", ")", ";", "ok", "&&", "method", "!=", "\"", "\"", "{", "writer", ".", "WriteByte", "(", "io", ".", "TagCall", ")", "\n", "writer", ".", "WriteString", "(", "method", ")", "\n", "if", "params", ",", "ok", ":=", "request", "[", "\"", "\"", "]", ".", "(", "[", "]", "interface", "{", "}", ")", ";", "ok", "&&", "params", "!=", "nil", "&&", "len", "(", "params", ")", ">", "0", "{", "writer", ".", "Serialize", "(", "params", ")", "\n", "}", "\n", "}", "\n", "}", "\n", "writer", ".", "WriteByte", "(", "io", ".", "TagEnd", ")", "\n", "data", "=", "writer", ".", "Bytes", "(", ")", "\n", "context", ".", "SetInterface", "(", "\"", "\"", ",", "responses", ")", "\n", "}", "\n", "return", "data", "\n", "}" ]
// InputFilter for JSONRPC Service
[ "InputFilter", "for", "JSONRPC", "Service" ]
6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74
https://github.com/hprose/hprose-golang/blob/6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74/rpc/filter/jsonrpc/service_filter.go#L52-L83
train
hprose/hprose-golang
rpc/filter/jsonrpc/service_filter.go
OutputFilter
func (filter ServiceFilter) OutputFilter(data []byte, context rpc.Context) []byte { responses, ok := context.GetInterface("jsonrpc").([]map[string]interface{}) if ok && responses != nil { reader := io.NewReader(data, false) reader.JSONCompatible = true tag, _ := reader.ReadByte() for _, response := range responses { if tag == io.TagResult { reader.Reset() var result interface{} reader.Unserialize(&result) response["result"] = result tag, _ = reader.ReadByte() } else if tag == io.TagError { reader.Reset() err := make(map[string]interface{}) err["code"] = -1 message := reader.ReadString() err["message"] = message tag, _ = reader.ReadByte() response["error"] = err } if tag == io.TagEnd { break } } if len(responses) == 1 { data, _ = json.Marshal(responses[0]) } else { data, _ = json.Marshal(responses) } } return data }
go
func (filter ServiceFilter) OutputFilter(data []byte, context rpc.Context) []byte { responses, ok := context.GetInterface("jsonrpc").([]map[string]interface{}) if ok && responses != nil { reader := io.NewReader(data, false) reader.JSONCompatible = true tag, _ := reader.ReadByte() for _, response := range responses { if tag == io.TagResult { reader.Reset() var result interface{} reader.Unserialize(&result) response["result"] = result tag, _ = reader.ReadByte() } else if tag == io.TagError { reader.Reset() err := make(map[string]interface{}) err["code"] = -1 message := reader.ReadString() err["message"] = message tag, _ = reader.ReadByte() response["error"] = err } if tag == io.TagEnd { break } } if len(responses) == 1 { data, _ = json.Marshal(responses[0]) } else { data, _ = json.Marshal(responses) } } return data }
[ "func", "(", "filter", "ServiceFilter", ")", "OutputFilter", "(", "data", "[", "]", "byte", ",", "context", "rpc", ".", "Context", ")", "[", "]", "byte", "{", "responses", ",", "ok", ":=", "context", ".", "GetInterface", "(", "\"", "\"", ")", ".", "(", "[", "]", "map", "[", "string", "]", "interface", "{", "}", ")", "\n", "if", "ok", "&&", "responses", "!=", "nil", "{", "reader", ":=", "io", ".", "NewReader", "(", "data", ",", "false", ")", "\n", "reader", ".", "JSONCompatible", "=", "true", "\n", "tag", ",", "_", ":=", "reader", ".", "ReadByte", "(", ")", "\n", "for", "_", ",", "response", ":=", "range", "responses", "{", "if", "tag", "==", "io", ".", "TagResult", "{", "reader", ".", "Reset", "(", ")", "\n", "var", "result", "interface", "{", "}", "\n", "reader", ".", "Unserialize", "(", "&", "result", ")", "\n", "response", "[", "\"", "\"", "]", "=", "result", "\n", "tag", ",", "_", "=", "reader", ".", "ReadByte", "(", ")", "\n", "}", "else", "if", "tag", "==", "io", ".", "TagError", "{", "reader", ".", "Reset", "(", ")", "\n", "err", ":=", "make", "(", "map", "[", "string", "]", "interface", "{", "}", ")", "\n", "err", "[", "\"", "\"", "]", "=", "-", "1", "\n", "message", ":=", "reader", ".", "ReadString", "(", ")", "\n", "err", "[", "\"", "\"", "]", "=", "message", "\n", "tag", ",", "_", "=", "reader", ".", "ReadByte", "(", ")", "\n", "response", "[", "\"", "\"", "]", "=", "err", "\n", "}", "\n", "if", "tag", "==", "io", ".", "TagEnd", "{", "break", "\n", "}", "\n", "}", "\n", "if", "len", "(", "responses", ")", "==", "1", "{", "data", ",", "_", "=", "json", ".", "Marshal", "(", "responses", "[", "0", "]", ")", "\n", "}", "else", "{", "data", ",", "_", "=", "json", ".", "Marshal", "(", "responses", ")", "\n", "}", "\n", "}", "\n", "return", "data", "\n", "}" ]
// OutputFilter for JSONRPC Service
[ "OutputFilter", "for", "JSONRPC", "Service" ]
6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74
https://github.com/hprose/hprose-golang/blob/6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74/rpc/filter/jsonrpc/service_filter.go#L86-L119
train
hprose/hprose-golang
io/raw_reader.go
NewRawReader
func NewRawReader(buf []byte) (reader *RawReader) { reader = new(RawReader) reader.buf = buf return }
go
func NewRawReader(buf []byte) (reader *RawReader) { reader = new(RawReader) reader.buf = buf return }
[ "func", "NewRawReader", "(", "buf", "[", "]", "byte", ")", "(", "reader", "*", "RawReader", ")", "{", "reader", "=", "new", "(", "RawReader", ")", "\n", "reader", ".", "buf", "=", "buf", "\n", "return", "\n", "}" ]
// NewRawReader is a constructor for RawReader
[ "NewRawReader", "is", "a", "constructor", "for", "RawReader" ]
6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74
https://github.com/hprose/hprose-golang/blob/6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74/io/raw_reader.go#L30-L34
train
hprose/hprose-golang
io/raw_reader.go
ReadRaw
func (r *RawReader) ReadRaw() (raw []byte) { w := new(ByteWriter) r.ReadRawTo(w) raw = w.Bytes() return }
go
func (r *RawReader) ReadRaw() (raw []byte) { w := new(ByteWriter) r.ReadRawTo(w) raw = w.Bytes() return }
[ "func", "(", "r", "*", "RawReader", ")", "ReadRaw", "(", ")", "(", "raw", "[", "]", "byte", ")", "{", "w", ":=", "new", "(", "ByteWriter", ")", "\n", "r", ".", "ReadRawTo", "(", "w", ")", "\n", "raw", "=", "w", ".", "Bytes", "(", ")", "\n", "return", "\n", "}" ]
// ReadRaw from stream
[ "ReadRaw", "from", "stream" ]
6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74
https://github.com/hprose/hprose-golang/blob/6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74/io/raw_reader.go#L37-L42
train
hprose/hprose-golang
io/raw_reader.go
ReadRawTo
func (r *RawReader) ReadRawTo(w *ByteWriter) { r.readRaw(w, r.readByte()) }
go
func (r *RawReader) ReadRawTo(w *ByteWriter) { r.readRaw(w, r.readByte()) }
[ "func", "(", "r", "*", "RawReader", ")", "ReadRawTo", "(", "w", "*", "ByteWriter", ")", "{", "r", ".", "readRaw", "(", "w", ",", "r", ".", "readByte", "(", ")", ")", "\n", "}" ]
// ReadRawTo buffer from stream
[ "ReadRawTo", "buffer", "from", "stream" ]
6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74
https://github.com/hprose/hprose-golang/blob/6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74/io/raw_reader.go#L45-L47
train
hprose/hprose-golang
rpc/http_service.go
InitHTTPContext
func (context *HTTPContext) InitHTTPContext( service Service, response http.ResponseWriter, request *http.Request) { context.InitServiceContext(service) context.Response = response context.Request = request }
go
func (context *HTTPContext) InitHTTPContext( service Service, response http.ResponseWriter, request *http.Request) { context.InitServiceContext(service) context.Response = response context.Request = request }
[ "func", "(", "context", "*", "HTTPContext", ")", "InitHTTPContext", "(", "service", "Service", ",", "response", "http", ".", "ResponseWriter", ",", "request", "*", "http", ".", "Request", ")", "{", "context", ".", "InitServiceContext", "(", "service", ")", "\n", "context", ".", "Response", "=", "response", "\n", "context", ".", "Request", "=", "request", "\n", "}" ]
// InitHTTPContext initializes HTTPContext
[ "InitHTTPContext", "initializes", "HTTPContext" ]
6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74
https://github.com/hprose/hprose-golang/blob/6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74/rpc/http_service.go#L41-L48
train
hprose/hprose-golang
rpc/http_service.go
InitHTTPService
func (service *HTTPService) InitHTTPService() { service.InitBaseHTTPService() service.contextPool = sync.Pool{ New: func() interface{} { return new(HTTPContext) }, } service.FixArguments = httpFixArguments }
go
func (service *HTTPService) InitHTTPService() { service.InitBaseHTTPService() service.contextPool = sync.Pool{ New: func() interface{} { return new(HTTPContext) }, } service.FixArguments = httpFixArguments }
[ "func", "(", "service", "*", "HTTPService", ")", "InitHTTPService", "(", ")", "{", "service", ".", "InitBaseHTTPService", "(", ")", "\n", "service", ".", "contextPool", "=", "sync", ".", "Pool", "{", "New", ":", "func", "(", ")", "interface", "{", "}", "{", "return", "new", "(", "HTTPContext", ")", "}", ",", "}", "\n", "service", ".", "FixArguments", "=", "httpFixArguments", "\n", "}" ]
// InitHTTPService initializes HTTPService
[ "InitHTTPService", "initializes", "HTTPService" ]
6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74
https://github.com/hprose/hprose-golang/blob/6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74/rpc/http_service.go#L88-L94
train
hprose/hprose-golang
rpc/client.go
CheckAddresses
func CheckAddresses(uriList []string, schemes []string) (scheme string) { count := len(uriList) if count < 1 { panic(ErrURIListEmpty) } u, err := url.Parse(uriList[0]) if err != nil { panic(err) } scheme = u.Scheme if sort.SearchStrings(schemes, scheme) == len(schemes) { panic(errors.New("This client desn't support " + scheme + " scheme.")) } for i := 1; i < count; i++ { u, err := url.Parse(uriList[i]) if err != nil { panic(err) } if scheme != u.Scheme { panic(ErrNotSupportMultpleProtocol) } } return }
go
func CheckAddresses(uriList []string, schemes []string) (scheme string) { count := len(uriList) if count < 1 { panic(ErrURIListEmpty) } u, err := url.Parse(uriList[0]) if err != nil { panic(err) } scheme = u.Scheme if sort.SearchStrings(schemes, scheme) == len(schemes) { panic(errors.New("This client desn't support " + scheme + " scheme.")) } for i := 1; i < count; i++ { u, err := url.Parse(uriList[i]) if err != nil { panic(err) } if scheme != u.Scheme { panic(ErrNotSupportMultpleProtocol) } } return }
[ "func", "CheckAddresses", "(", "uriList", "[", "]", "string", ",", "schemes", "[", "]", "string", ")", "(", "scheme", "string", ")", "{", "count", ":=", "len", "(", "uriList", ")", "\n", "if", "count", "<", "1", "{", "panic", "(", "ErrURIListEmpty", ")", "\n", "}", "\n", "u", ",", "err", ":=", "url", ".", "Parse", "(", "uriList", "[", "0", "]", ")", "\n", "if", "err", "!=", "nil", "{", "panic", "(", "err", ")", "\n", "}", "\n", "scheme", "=", "u", ".", "Scheme", "\n", "if", "sort", ".", "SearchStrings", "(", "schemes", ",", "scheme", ")", "==", "len", "(", "schemes", ")", "{", "panic", "(", "errors", ".", "New", "(", "\"", "\"", "+", "scheme", "+", "\"", "\"", ")", ")", "\n", "}", "\n", "for", "i", ":=", "1", ";", "i", "<", "count", ";", "i", "++", "{", "u", ",", "err", ":=", "url", ".", "Parse", "(", "uriList", "[", "i", "]", ")", "\n", "if", "err", "!=", "nil", "{", "panic", "(", "err", ")", "\n", "}", "\n", "if", "scheme", "!=", "u", ".", "Scheme", "{", "panic", "(", "ErrNotSupportMultpleProtocol", ")", "\n", "}", "\n", "}", "\n", "return", "\n", "}" ]
// CheckAddresses returns the uri scheme if the address is valid.
[ "CheckAddresses", "returns", "the", "uri", "scheme", "if", "the", "address", "is", "valid", "." ]
6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74
https://github.com/hprose/hprose-golang/blob/6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74/rpc/client.go#L111-L134
train
hprose/hprose-golang
rpc/client.go
RegisterClientFactory
func RegisterClientFactory(scheme string, newClient func(...string) Client) { clientFactories[strings.ToLower(scheme)] = newClient }
go
func RegisterClientFactory(scheme string, newClient func(...string) Client) { clientFactories[strings.ToLower(scheme)] = newClient }
[ "func", "RegisterClientFactory", "(", "scheme", "string", ",", "newClient", "func", "(", "...", "string", ")", "Client", ")", "{", "clientFactories", "[", "strings", ".", "ToLower", "(", "scheme", ")", "]", "=", "newClient", "\n", "}" ]
// RegisterClientFactory registers the default client factory
[ "RegisterClientFactory", "registers", "the", "default", "client", "factory" ]
6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74
https://github.com/hprose/hprose-golang/blob/6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74/rpc/client.go#L139-L141
train
hprose/hprose-golang
util/util.go
UTF16Length
func UTF16Length(str string) (n int) { length := len(str) n = length p := 0 for p < length { a := str[p] switch a >> 4 { case 0, 1, 2, 3, 4, 5, 6, 7: p++ case 12, 13: p += 2 n-- case 14: p += 3 n -= 2 case 15: if a&8 == 8 { return -1 } p += 4 n -= 2 default: return -1 } } return n }
go
func UTF16Length(str string) (n int) { length := len(str) n = length p := 0 for p < length { a := str[p] switch a >> 4 { case 0, 1, 2, 3, 4, 5, 6, 7: p++ case 12, 13: p += 2 n-- case 14: p += 3 n -= 2 case 15: if a&8 == 8 { return -1 } p += 4 n -= 2 default: return -1 } } return n }
[ "func", "UTF16Length", "(", "str", "string", ")", "(", "n", "int", ")", "{", "length", ":=", "len", "(", "str", ")", "\n", "n", "=", "length", "\n", "p", ":=", "0", "\n", "for", "p", "<", "length", "{", "a", ":=", "str", "[", "p", "]", "\n", "switch", "a", ">>", "4", "{", "case", "0", ",", "1", ",", "2", ",", "3", ",", "4", ",", "5", ",", "6", ",", "7", ":", "p", "++", "\n", "case", "12", ",", "13", ":", "p", "+=", "2", "\n", "n", "--", "\n", "case", "14", ":", "p", "+=", "3", "\n", "n", "-=", "2", "\n", "case", "15", ":", "if", "a", "&", "8", "==", "8", "{", "return", "-", "1", "\n", "}", "\n", "p", "+=", "4", "\n", "n", "-=", "2", "\n", "default", ":", "return", "-", "1", "\n", "}", "\n", "}", "\n", "return", "n", "\n", "}" ]
// UTF16Length return the UTF16 length of str. // str must be an UTF8 encode string, otherwise return -1.
[ "UTF16Length", "return", "the", "UTF16", "length", "of", "str", ".", "str", "must", "be", "an", "UTF8", "encode", "string", "otherwise", "return", "-", "1", "." ]
6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74
https://github.com/hprose/hprose-golang/blob/6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74/util/util.go#L242-L268
train
hprose/hprose-golang
util/util.go
StringByte
func StringByte(s string) []byte { sh := (*reflect.StringHeader)(unsafe.Pointer(&s)) bh := reflect.SliceHeader{ Data: sh.Data, Len: sh.Len, Cap: sh.Len, } return *(*[]byte)(unsafe.Pointer(&bh)) }
go
func StringByte(s string) []byte { sh := (*reflect.StringHeader)(unsafe.Pointer(&s)) bh := reflect.SliceHeader{ Data: sh.Data, Len: sh.Len, Cap: sh.Len, } return *(*[]byte)(unsafe.Pointer(&bh)) }
[ "func", "StringByte", "(", "s", "string", ")", "[", "]", "byte", "{", "sh", ":=", "(", "*", "reflect", ".", "StringHeader", ")", "(", "unsafe", ".", "Pointer", "(", "&", "s", ")", ")", "\n", "bh", ":=", "reflect", ".", "SliceHeader", "{", "Data", ":", "sh", ".", "Data", ",", "Len", ":", "sh", ".", "Len", ",", "Cap", ":", "sh", ".", "Len", ",", "}", "\n", "return", "*", "(", "*", "[", "]", "byte", ")", "(", "unsafe", ".", "Pointer", "(", "&", "bh", ")", ")", "\n", "}" ]
// StringByte converts string to string without memory allocation by block magic
[ "StringByte", "converts", "string", "to", "string", "without", "memory", "allocation", "by", "block", "magic" ]
6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74
https://github.com/hprose/hprose-golang/blob/6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74/util/util.go#L276-L284
train
hprose/hprose-golang
util/util.go
Itoa
func Itoa(i int) string { var buf [20]byte return ByteString(GetIntBytes(buf[:], int64(i))) }
go
func Itoa(i int) string { var buf [20]byte return ByteString(GetIntBytes(buf[:], int64(i))) }
[ "func", "Itoa", "(", "i", "int", ")", "string", "{", "var", "buf", "[", "20", "]", "byte", "\n", "return", "ByteString", "(", "GetIntBytes", "(", "buf", "[", ":", "]", ",", "int64", "(", "i", ")", ")", ")", "\n", "}" ]
// Itoa returns the string representation of i
[ "Itoa", "returns", "the", "string", "representation", "of", "i" ]
6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74
https://github.com/hprose/hprose-golang/blob/6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74/util/util.go#L287-L290
train
hprose/hprose-golang
util/util.go
UUIDv4
func UUIDv4() (uid string) { u := make([]byte, 16) rand.Read(u) u[6] = (u[6] & 0x0f) | 0x40 u[8] = (u[8] & 0x3f) | 0x80 uid = fmt.Sprintf("%x-%x-%x-%x-%x", u[0:4], u[4:6], u[6:8], u[8:10], u[10:]) return }
go
func UUIDv4() (uid string) { u := make([]byte, 16) rand.Read(u) u[6] = (u[6] & 0x0f) | 0x40 u[8] = (u[8] & 0x3f) | 0x80 uid = fmt.Sprintf("%x-%x-%x-%x-%x", u[0:4], u[4:6], u[6:8], u[8:10], u[10:]) return }
[ "func", "UUIDv4", "(", ")", "(", "uid", "string", ")", "{", "u", ":=", "make", "(", "[", "]", "byte", ",", "16", ")", "\n", "rand", ".", "Read", "(", "u", ")", "\n", "u", "[", "6", "]", "=", "(", "u", "[", "6", "]", "&", "0x0f", ")", "|", "0x40", "\n", "u", "[", "8", "]", "=", "(", "u", "[", "8", "]", "&", "0x3f", ")", "|", "0x80", "\n", "uid", "=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "u", "[", "0", ":", "4", "]", ",", "u", "[", "4", ":", "6", "]", ",", "u", "[", "6", ":", "8", "]", ",", "u", "[", "8", ":", "10", "]", ",", "u", "[", "10", ":", "]", ")", "\n", "return", "\n", "}" ]
// UUIDv4 returns a version 4 UUID string
[ "UUIDv4", "returns", "a", "version", "4", "UUID", "string" ]
6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74
https://github.com/hprose/hprose-golang/blob/6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74/util/util.go#L309-L316
train
hprose/hprose-golang
util/util.go
ToUint32
func ToUint32(b []byte) uint32 { return uint32(b[0])<<24 | uint32(b[1])<<16 | uint32(b[2])<<8 | uint32(b[3]) }
go
func ToUint32(b []byte) uint32 { return uint32(b[0])<<24 | uint32(b[1])<<16 | uint32(b[2])<<8 | uint32(b[3]) }
[ "func", "ToUint32", "(", "b", "[", "]", "byte", ")", "uint32", "{", "return", "uint32", "(", "b", "[", "0", "]", ")", "<<", "24", "|", "uint32", "(", "b", "[", "1", "]", ")", "<<", "16", "|", "uint32", "(", "b", "[", "2", "]", ")", "<<", "8", "|", "uint32", "(", "b", "[", "3", "]", ")", "\n", "}" ]
// ToUint32 translates 4 byte to uint32
[ "ToUint32", "translates", "4", "byte", "to", "uint32" ]
6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74
https://github.com/hprose/hprose-golang/blob/6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74/util/util.go#L319-L321
train
hprose/hprose-golang
util/util.go
FromUint32
func FromUint32(b []byte, i uint32) { b[0] = byte(i >> 24) b[1] = byte(i >> 16) b[2] = byte(i >> 8) b[3] = byte(i) }
go
func FromUint32(b []byte, i uint32) { b[0] = byte(i >> 24) b[1] = byte(i >> 16) b[2] = byte(i >> 8) b[3] = byte(i) }
[ "func", "FromUint32", "(", "b", "[", "]", "byte", ",", "i", "uint32", ")", "{", "b", "[", "0", "]", "=", "byte", "(", "i", ">>", "24", ")", "\n", "b", "[", "1", "]", "=", "byte", "(", "i", ">>", "16", ")", "\n", "b", "[", "2", "]", "=", "byte", "(", "i", ">>", "8", ")", "\n", "b", "[", "3", "]", "=", "byte", "(", "i", ")", "\n", "}" ]
// FromUint32 translates uint32 to 4 byte
[ "FromUint32", "translates", "uint32", "to", "4", "byte" ]
6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74
https://github.com/hprose/hprose-golang/blob/6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74/util/util.go#L324-L329
train
hprose/hprose-golang
util/util.go
LocalProxy
func LocalProxy(proxy, local interface{}) error { dstValue := reflect.ValueOf(proxy) srcValue := reflect.ValueOf(local) if dstValue.Kind() != reflect.Ptr { return errors.New("proxy must be a pointer") } dstValue = dstValue.Elem() t := dstValue.Type() et := t if et.Kind() == reflect.Ptr { et = et.Elem() } if et.Kind() != reflect.Struct { return errors.New("proxy must be a struct pointer or pointer to a struct pointer") } ptr := reflect.New(et) obj := ptr.Elem() count := obj.NumField() for i := 0; i < count; i++ { f := obj.Field(i) ft := f.Type() sf := et.Field(i) if f.CanSet() && ft.Kind() == reflect.Func { f.Set(srcValue.MethodByName(sf.Name)) } } if t.Kind() == reflect.Ptr { dstValue.Set(ptr) } else { dstValue.Set(obj) } return nil }
go
func LocalProxy(proxy, local interface{}) error { dstValue := reflect.ValueOf(proxy) srcValue := reflect.ValueOf(local) if dstValue.Kind() != reflect.Ptr { return errors.New("proxy must be a pointer") } dstValue = dstValue.Elem() t := dstValue.Type() et := t if et.Kind() == reflect.Ptr { et = et.Elem() } if et.Kind() != reflect.Struct { return errors.New("proxy must be a struct pointer or pointer to a struct pointer") } ptr := reflect.New(et) obj := ptr.Elem() count := obj.NumField() for i := 0; i < count; i++ { f := obj.Field(i) ft := f.Type() sf := et.Field(i) if f.CanSet() && ft.Kind() == reflect.Func { f.Set(srcValue.MethodByName(sf.Name)) } } if t.Kind() == reflect.Ptr { dstValue.Set(ptr) } else { dstValue.Set(obj) } return nil }
[ "func", "LocalProxy", "(", "proxy", ",", "local", "interface", "{", "}", ")", "error", "{", "dstValue", ":=", "reflect", ".", "ValueOf", "(", "proxy", ")", "\n", "srcValue", ":=", "reflect", ".", "ValueOf", "(", "local", ")", "\n", "if", "dstValue", ".", "Kind", "(", ")", "!=", "reflect", ".", "Ptr", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n", "dstValue", "=", "dstValue", ".", "Elem", "(", ")", "\n", "t", ":=", "dstValue", ".", "Type", "(", ")", "\n", "et", ":=", "t", "\n", "if", "et", ".", "Kind", "(", ")", "==", "reflect", ".", "Ptr", "{", "et", "=", "et", ".", "Elem", "(", ")", "\n", "}", "\n", "if", "et", ".", "Kind", "(", ")", "!=", "reflect", ".", "Struct", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n", "ptr", ":=", "reflect", ".", "New", "(", "et", ")", "\n", "obj", ":=", "ptr", ".", "Elem", "(", ")", "\n", "count", ":=", "obj", ".", "NumField", "(", ")", "\n", "for", "i", ":=", "0", ";", "i", "<", "count", ";", "i", "++", "{", "f", ":=", "obj", ".", "Field", "(", "i", ")", "\n", "ft", ":=", "f", ".", "Type", "(", ")", "\n", "sf", ":=", "et", ".", "Field", "(", "i", ")", "\n", "if", "f", ".", "CanSet", "(", ")", "&&", "ft", ".", "Kind", "(", ")", "==", "reflect", ".", "Func", "{", "f", ".", "Set", "(", "srcValue", ".", "MethodByName", "(", "sf", ".", "Name", ")", ")", "\n", "}", "\n", "}", "\n", "if", "t", ".", "Kind", "(", ")", "==", "reflect", ".", "Ptr", "{", "dstValue", ".", "Set", "(", "ptr", ")", "\n", "}", "else", "{", "dstValue", ".", "Set", "(", "obj", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// LocalProxy make a local object to a proxy struct
[ "LocalProxy", "make", "a", "local", "object", "to", "a", "proxy", "struct" ]
6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74
https://github.com/hprose/hprose-golang/blob/6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74/util/util.go#L332-L364
train
hprose/hprose-golang
rpc/context.go
GetInt
func (context *BaseContext) GetInt( key string, defaultValue ...int) int { if value, ok := context.userData[key]; ok { if value, ok := value.(int); ok { return value } } if len(defaultValue) > 0 { return defaultValue[0] } return 0 }
go
func (context *BaseContext) GetInt( key string, defaultValue ...int) int { if value, ok := context.userData[key]; ok { if value, ok := value.(int); ok { return value } } if len(defaultValue) > 0 { return defaultValue[0] } return 0 }
[ "func", "(", "context", "*", "BaseContext", ")", "GetInt", "(", "key", "string", ",", "defaultValue", "...", "int", ")", "int", "{", "if", "value", ",", "ok", ":=", "context", ".", "userData", "[", "key", "]", ";", "ok", "{", "if", "value", ",", "ok", ":=", "value", ".", "(", "int", ")", ";", "ok", "{", "return", "value", "\n", "}", "\n", "}", "\n", "if", "len", "(", "defaultValue", ")", ">", "0", "{", "return", "defaultValue", "[", "0", "]", "\n", "}", "\n", "return", "0", "\n", "}" ]
// GetInt from hprose context
[ "GetInt", "from", "hprose", "context" ]
6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74
https://github.com/hprose/hprose-golang/blob/6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74/rpc/context.go#L61-L72
train
hprose/hprose-golang
rpc/context.go
GetUInt
func (context *BaseContext) GetUInt( key string, defaultValue ...uint) uint { if value, ok := context.userData[key]; ok { if value, ok := value.(uint); ok { return value } } if len(defaultValue) > 0 { return defaultValue[0] } return 0 }
go
func (context *BaseContext) GetUInt( key string, defaultValue ...uint) uint { if value, ok := context.userData[key]; ok { if value, ok := value.(uint); ok { return value } } if len(defaultValue) > 0 { return defaultValue[0] } return 0 }
[ "func", "(", "context", "*", "BaseContext", ")", "GetUInt", "(", "key", "string", ",", "defaultValue", "...", "uint", ")", "uint", "{", "if", "value", ",", "ok", ":=", "context", ".", "userData", "[", "key", "]", ";", "ok", "{", "if", "value", ",", "ok", ":=", "value", ".", "(", "uint", ")", ";", "ok", "{", "return", "value", "\n", "}", "\n", "}", "\n", "if", "len", "(", "defaultValue", ")", ">", "0", "{", "return", "defaultValue", "[", "0", "]", "\n", "}", "\n", "return", "0", "\n", "}" ]
// GetUInt from hprose context
[ "GetUInt", "from", "hprose", "context" ]
6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74
https://github.com/hprose/hprose-golang/blob/6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74/rpc/context.go#L75-L86
train
hprose/hprose-golang
rpc/context.go
GetInt64
func (context *BaseContext) GetInt64( key string, defaultValue ...int64) int64 { if value, ok := context.userData[key]; ok { if value, ok := value.(int64); ok { return value } } if len(defaultValue) > 0 { return defaultValue[0] } return 0 }
go
func (context *BaseContext) GetInt64( key string, defaultValue ...int64) int64 { if value, ok := context.userData[key]; ok { if value, ok := value.(int64); ok { return value } } if len(defaultValue) > 0 { return defaultValue[0] } return 0 }
[ "func", "(", "context", "*", "BaseContext", ")", "GetInt64", "(", "key", "string", ",", "defaultValue", "...", "int64", ")", "int64", "{", "if", "value", ",", "ok", ":=", "context", ".", "userData", "[", "key", "]", ";", "ok", "{", "if", "value", ",", "ok", ":=", "value", ".", "(", "int64", ")", ";", "ok", "{", "return", "value", "\n", "}", "\n", "}", "\n", "if", "len", "(", "defaultValue", ")", ">", "0", "{", "return", "defaultValue", "[", "0", "]", "\n", "}", "\n", "return", "0", "\n", "}" ]
// GetInt64 from hprose context
[ "GetInt64", "from", "hprose", "context" ]
6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74
https://github.com/hprose/hprose-golang/blob/6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74/rpc/context.go#L89-L100
train
hprose/hprose-golang
rpc/context.go
GetUInt64
func (context *BaseContext) GetUInt64( key string, defaultValue ...uint64) uint64 { if value, ok := context.userData[key]; ok { if value, ok := value.(uint64); ok { return value } } if len(defaultValue) > 0 { return defaultValue[0] } return 0 }
go
func (context *BaseContext) GetUInt64( key string, defaultValue ...uint64) uint64 { if value, ok := context.userData[key]; ok { if value, ok := value.(uint64); ok { return value } } if len(defaultValue) > 0 { return defaultValue[0] } return 0 }
[ "func", "(", "context", "*", "BaseContext", ")", "GetUInt64", "(", "key", "string", ",", "defaultValue", "...", "uint64", ")", "uint64", "{", "if", "value", ",", "ok", ":=", "context", ".", "userData", "[", "key", "]", ";", "ok", "{", "if", "value", ",", "ok", ":=", "value", ".", "(", "uint64", ")", ";", "ok", "{", "return", "value", "\n", "}", "\n", "}", "\n", "if", "len", "(", "defaultValue", ")", ">", "0", "{", "return", "defaultValue", "[", "0", "]", "\n", "}", "\n", "return", "0", "\n", "}" ]
// GetUInt64 from hprose context
[ "GetUInt64", "from", "hprose", "context" ]
6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74
https://github.com/hprose/hprose-golang/blob/6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74/rpc/context.go#L103-L114
train
hprose/hprose-golang
rpc/context.go
GetFloat
func (context *BaseContext) GetFloat( key string, defaultValue ...float64) float64 { if value, ok := context.userData[key]; ok { if value, ok := value.(float64); ok { return value } } if len(defaultValue) > 0 { return defaultValue[0] } return 0 }
go
func (context *BaseContext) GetFloat( key string, defaultValue ...float64) float64 { if value, ok := context.userData[key]; ok { if value, ok := value.(float64); ok { return value } } if len(defaultValue) > 0 { return defaultValue[0] } return 0 }
[ "func", "(", "context", "*", "BaseContext", ")", "GetFloat", "(", "key", "string", ",", "defaultValue", "...", "float64", ")", "float64", "{", "if", "value", ",", "ok", ":=", "context", ".", "userData", "[", "key", "]", ";", "ok", "{", "if", "value", ",", "ok", ":=", "value", ".", "(", "float64", ")", ";", "ok", "{", "return", "value", "\n", "}", "\n", "}", "\n", "if", "len", "(", "defaultValue", ")", ">", "0", "{", "return", "defaultValue", "[", "0", "]", "\n", "}", "\n", "return", "0", "\n", "}" ]
// GetFloat from hprose context
[ "GetFloat", "from", "hprose", "context" ]
6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74
https://github.com/hprose/hprose-golang/blob/6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74/rpc/context.go#L117-L128
train
hprose/hprose-golang
rpc/context.go
GetBool
func (context *BaseContext) GetBool( key string, defaultValue ...bool) bool { if value, ok := context.userData[key]; ok { if value, ok := value.(bool); ok { return value } } if len(defaultValue) > 0 { return defaultValue[0] } return false }
go
func (context *BaseContext) GetBool( key string, defaultValue ...bool) bool { if value, ok := context.userData[key]; ok { if value, ok := value.(bool); ok { return value } } if len(defaultValue) > 0 { return defaultValue[0] } return false }
[ "func", "(", "context", "*", "BaseContext", ")", "GetBool", "(", "key", "string", ",", "defaultValue", "...", "bool", ")", "bool", "{", "if", "value", ",", "ok", ":=", "context", ".", "userData", "[", "key", "]", ";", "ok", "{", "if", "value", ",", "ok", ":=", "value", ".", "(", "bool", ")", ";", "ok", "{", "return", "value", "\n", "}", "\n", "}", "\n", "if", "len", "(", "defaultValue", ")", ">", "0", "{", "return", "defaultValue", "[", "0", "]", "\n", "}", "\n", "return", "false", "\n", "}" ]
// GetBool from hprose context
[ "GetBool", "from", "hprose", "context" ]
6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74
https://github.com/hprose/hprose-golang/blob/6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74/rpc/context.go#L131-L142
train
hprose/hprose-golang
rpc/context.go
GetString
func (context *BaseContext) GetString( key string, defaultValue ...string) string { if value, ok := context.userData[key]; ok { if value, ok := value.(string); ok { return value } } if len(defaultValue) > 0 { return defaultValue[0] } return "" }
go
func (context *BaseContext) GetString( key string, defaultValue ...string) string { if value, ok := context.userData[key]; ok { if value, ok := value.(string); ok { return value } } if len(defaultValue) > 0 { return defaultValue[0] } return "" }
[ "func", "(", "context", "*", "BaseContext", ")", "GetString", "(", "key", "string", ",", "defaultValue", "...", "string", ")", "string", "{", "if", "value", ",", "ok", ":=", "context", ".", "userData", "[", "key", "]", ";", "ok", "{", "if", "value", ",", "ok", ":=", "value", ".", "(", "string", ")", ";", "ok", "{", "return", "value", "\n", "}", "\n", "}", "\n", "if", "len", "(", "defaultValue", ")", ">", "0", "{", "return", "defaultValue", "[", "0", "]", "\n", "}", "\n", "return", "\"", "\"", "\n", "}" ]
// GetString from hprose context
[ "GetString", "from", "hprose", "context" ]
6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74
https://github.com/hprose/hprose-golang/blob/6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74/rpc/context.go#L145-L156
train
hprose/hprose-golang
rpc/context.go
GetInterface
func (context *BaseContext) GetInterface( key string, defaultValue ...interface{}) interface{} { if value, ok := context.userData[key]; ok { return value } if len(defaultValue) > 0 { return defaultValue[0] } return nil }
go
func (context *BaseContext) GetInterface( key string, defaultValue ...interface{}) interface{} { if value, ok := context.userData[key]; ok { return value } if len(defaultValue) > 0 { return defaultValue[0] } return nil }
[ "func", "(", "context", "*", "BaseContext", ")", "GetInterface", "(", "key", "string", ",", "defaultValue", "...", "interface", "{", "}", ")", "interface", "{", "}", "{", "if", "value", ",", "ok", ":=", "context", ".", "userData", "[", "key", "]", ";", "ok", "{", "return", "value", "\n", "}", "\n", "if", "len", "(", "defaultValue", ")", ">", "0", "{", "return", "defaultValue", "[", "0", "]", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// GetInterface from hprose context
[ "GetInterface", "from", "hprose", "context" ]
6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74
https://github.com/hprose/hprose-golang/blob/6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74/rpc/context.go#L159-L168
train
hprose/hprose-golang
rpc/context.go
Get
func (context *BaseContext) Get(key string) interface{} { if value, ok := context.userData[key]; ok { return value } return nil }
go
func (context *BaseContext) Get(key string) interface{} { if value, ok := context.userData[key]; ok { return value } return nil }
[ "func", "(", "context", "*", "BaseContext", ")", "Get", "(", "key", "string", ")", "interface", "{", "}", "{", "if", "value", ",", "ok", ":=", "context", ".", "userData", "[", "key", "]", ";", "ok", "{", "return", "value", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Get value from hprose context
[ "Get", "value", "from", "hprose", "context" ]
6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74
https://github.com/hprose/hprose-golang/blob/6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74/rpc/context.go#L171-L176
train
hprose/hprose-golang
rpc/context.go
SetInt
func (context *BaseContext) SetInt(key string, value int) { context.userData[key] = value }
go
func (context *BaseContext) SetInt(key string, value int) { context.userData[key] = value }
[ "func", "(", "context", "*", "BaseContext", ")", "SetInt", "(", "key", "string", ",", "value", "int", ")", "{", "context", ".", "userData", "[", "key", "]", "=", "value", "\n", "}" ]
// SetInt to hprose context
[ "SetInt", "to", "hprose", "context" ]
6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74
https://github.com/hprose/hprose-golang/blob/6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74/rpc/context.go#L179-L181
train
hprose/hprose-golang
rpc/context.go
SetUInt
func (context *BaseContext) SetUInt(key string, value uint) { context.userData[key] = value }
go
func (context *BaseContext) SetUInt(key string, value uint) { context.userData[key] = value }
[ "func", "(", "context", "*", "BaseContext", ")", "SetUInt", "(", "key", "string", ",", "value", "uint", ")", "{", "context", ".", "userData", "[", "key", "]", "=", "value", "\n", "}" ]
// SetUInt to hprose context
[ "SetUInt", "to", "hprose", "context" ]
6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74
https://github.com/hprose/hprose-golang/blob/6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74/rpc/context.go#L184-L186
train
hprose/hprose-golang
rpc/context.go
SetInt64
func (context *BaseContext) SetInt64(key string, value int64) { context.userData[key] = value }
go
func (context *BaseContext) SetInt64(key string, value int64) { context.userData[key] = value }
[ "func", "(", "context", "*", "BaseContext", ")", "SetInt64", "(", "key", "string", ",", "value", "int64", ")", "{", "context", ".", "userData", "[", "key", "]", "=", "value", "\n", "}" ]
// SetInt64 to hprose context
[ "SetInt64", "to", "hprose", "context" ]
6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74
https://github.com/hprose/hprose-golang/blob/6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74/rpc/context.go#L189-L191
train
hprose/hprose-golang
rpc/context.go
SetUInt64
func (context *BaseContext) SetUInt64(key string, value uint64) { context.userData[key] = value }
go
func (context *BaseContext) SetUInt64(key string, value uint64) { context.userData[key] = value }
[ "func", "(", "context", "*", "BaseContext", ")", "SetUInt64", "(", "key", "string", ",", "value", "uint64", ")", "{", "context", ".", "userData", "[", "key", "]", "=", "value", "\n", "}" ]
// SetUInt64 to hprose context
[ "SetUInt64", "to", "hprose", "context" ]
6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74
https://github.com/hprose/hprose-golang/blob/6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74/rpc/context.go#L194-L196
train
hprose/hprose-golang
rpc/context.go
SetFloat
func (context *BaseContext) SetFloat(key string, value float64) { context.userData[key] = value }
go
func (context *BaseContext) SetFloat(key string, value float64) { context.userData[key] = value }
[ "func", "(", "context", "*", "BaseContext", ")", "SetFloat", "(", "key", "string", ",", "value", "float64", ")", "{", "context", ".", "userData", "[", "key", "]", "=", "value", "\n", "}" ]
// SetFloat to hprose context
[ "SetFloat", "to", "hprose", "context" ]
6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74
https://github.com/hprose/hprose-golang/blob/6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74/rpc/context.go#L199-L201
train
hprose/hprose-golang
rpc/context.go
SetBool
func (context *BaseContext) SetBool(key string, value bool) { context.userData[key] = value }
go
func (context *BaseContext) SetBool(key string, value bool) { context.userData[key] = value }
[ "func", "(", "context", "*", "BaseContext", ")", "SetBool", "(", "key", "string", ",", "value", "bool", ")", "{", "context", ".", "userData", "[", "key", "]", "=", "value", "\n", "}" ]
// SetBool to hprose context
[ "SetBool", "to", "hprose", "context" ]
6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74
https://github.com/hprose/hprose-golang/blob/6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74/rpc/context.go#L204-L206
train
hprose/hprose-golang
rpc/context.go
SetString
func (context *BaseContext) SetString(key string, value string) { context.userData[key] = value }
go
func (context *BaseContext) SetString(key string, value string) { context.userData[key] = value }
[ "func", "(", "context", "*", "BaseContext", ")", "SetString", "(", "key", "string", ",", "value", "string", ")", "{", "context", ".", "userData", "[", "key", "]", "=", "value", "\n", "}" ]
// SetString to hprose context
[ "SetString", "to", "hprose", "context" ]
6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74
https://github.com/hprose/hprose-golang/blob/6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74/rpc/context.go#L209-L211
train
hprose/hprose-golang
rpc/context.go
SetInterface
func (context *BaseContext) SetInterface(key string, value interface{}) { context.userData[key] = value }
go
func (context *BaseContext) SetInterface(key string, value interface{}) { context.userData[key] = value }
[ "func", "(", "context", "*", "BaseContext", ")", "SetInterface", "(", "key", "string", ",", "value", "interface", "{", "}", ")", "{", "context", ".", "userData", "[", "key", "]", "=", "value", "\n", "}" ]
// SetInterface to hprose context
[ "SetInterface", "to", "hprose", "context" ]
6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74
https://github.com/hprose/hprose-golang/blob/6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74/rpc/context.go#L214-L216
train
hprose/hprose-golang
rpc/context.go
Set
func (context *BaseContext) Set(key string, value interface{}) { context.userData[key] = value }
go
func (context *BaseContext) Set(key string, value interface{}) { context.userData[key] = value }
[ "func", "(", "context", "*", "BaseContext", ")", "Set", "(", "key", "string", ",", "value", "interface", "{", "}", ")", "{", "context", ".", "userData", "[", "key", "]", "=", "value", "\n", "}" ]
// Set is an alias of SetInterface
[ "Set", "is", "an", "alias", "of", "SetInterface" ]
6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74
https://github.com/hprose/hprose-golang/blob/6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74/rpc/context.go#L219-L221
train
hprose/hprose-golang
rpc/filter/jsonrpc/client_filter.go
NewClientFilter
func NewClientFilter(version string) *ClientFilter { if version == "1.0" || version == "1.1" || version == "2.0" { return &ClientFilter{Version: version} } panic("version must be 1.0, 1.1 or 2.0 in string format.") }
go
func NewClientFilter(version string) *ClientFilter { if version == "1.0" || version == "1.1" || version == "2.0" { return &ClientFilter{Version: version} } panic("version must be 1.0, 1.1 or 2.0 in string format.") }
[ "func", "NewClientFilter", "(", "version", "string", ")", "*", "ClientFilter", "{", "if", "version", "==", "\"", "\"", "||", "version", "==", "\"", "\"", "||", "version", "==", "\"", "\"", "{", "return", "&", "ClientFilter", "{", "Version", ":", "version", "}", "\n", "}", "\n", "panic", "(", "\"", "\"", ")", "\n", "}" ]
// NewClientFilter is a constructor for JSONRPCClientFilter
[ "NewClientFilter", "is", "a", "constructor", "for", "JSONRPCClientFilter" ]
6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74
https://github.com/hprose/hprose-golang/blob/6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74/rpc/filter/jsonrpc/client_filter.go#L37-L42
train
hprose/hprose-golang
rpc/filter/jsonrpc/client_filter.go
InputFilter
func (filter *ClientFilter) InputFilter(data []byte, context rpc.Context) []byte { if context.GetBool("jsonrpc") { var response map[string]interface{} if err := json.Unmarshal(data, &response); err != nil { return data } err := response["error"] writer := io.NewWriter(true) if err != nil { e := err.(map[string]interface{}) writer.WriteByte(io.TagError) writer.WriteString(e["message"].(string)) } else { writer.WriteByte(io.TagResult) writer.Serialize(response["result"]) } writer.WriteByte(io.TagEnd) data = writer.Bytes() } return data }
go
func (filter *ClientFilter) InputFilter(data []byte, context rpc.Context) []byte { if context.GetBool("jsonrpc") { var response map[string]interface{} if err := json.Unmarshal(data, &response); err != nil { return data } err := response["error"] writer := io.NewWriter(true) if err != nil { e := err.(map[string]interface{}) writer.WriteByte(io.TagError) writer.WriteString(e["message"].(string)) } else { writer.WriteByte(io.TagResult) writer.Serialize(response["result"]) } writer.WriteByte(io.TagEnd) data = writer.Bytes() } return data }
[ "func", "(", "filter", "*", "ClientFilter", ")", "InputFilter", "(", "data", "[", "]", "byte", ",", "context", "rpc", ".", "Context", ")", "[", "]", "byte", "{", "if", "context", ".", "GetBool", "(", "\"", "\"", ")", "{", "var", "response", "map", "[", "string", "]", "interface", "{", "}", "\n", "if", "err", ":=", "json", ".", "Unmarshal", "(", "data", ",", "&", "response", ")", ";", "err", "!=", "nil", "{", "return", "data", "\n", "}", "\n", "err", ":=", "response", "[", "\"", "\"", "]", "\n", "writer", ":=", "io", ".", "NewWriter", "(", "true", ")", "\n", "if", "err", "!=", "nil", "{", "e", ":=", "err", ".", "(", "map", "[", "string", "]", "interface", "{", "}", ")", "\n", "writer", ".", "WriteByte", "(", "io", ".", "TagError", ")", "\n", "writer", ".", "WriteString", "(", "e", "[", "\"", "\"", "]", ".", "(", "string", ")", ")", "\n", "}", "else", "{", "writer", ".", "WriteByte", "(", "io", ".", "TagResult", ")", "\n", "writer", ".", "Serialize", "(", "response", "[", "\"", "\"", "]", ")", "\n", "}", "\n", "writer", ".", "WriteByte", "(", "io", ".", "TagEnd", ")", "\n", "data", "=", "writer", ".", "Bytes", "(", ")", "\n", "}", "\n", "return", "data", "\n", "}" ]
// InputFilter for JSONRPC Client
[ "InputFilter", "for", "JSONRPC", "Client" ]
6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74
https://github.com/hprose/hprose-golang/blob/6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74/rpc/filter/jsonrpc/client_filter.go#L45-L65
train
hprose/hprose-golang
rpc/filter/jsonrpc/client_filter.go
OutputFilter
func (filter *ClientFilter) OutputFilter(data []byte, context rpc.Context) []byte { if context.GetBool("jsonrpc") { request := make(map[string]interface{}) if filter.Version == "1.1" { request["version"] = "1.1" } else if filter.Version == "2.0" { request["jsonrpc"] = "2.0" } reader := io.NewReader(data, false) reader.JSONCompatible = true tag, _ := reader.ReadByte() if tag == io.TagCall { request["method"] = reader.ReadString() tag, _ = reader.ReadByte() if tag == io.TagList { reader.Reset() count := reader.ReadCount() params := make([]interface{}, count) for i := 0; i < count; i++ { reader.Unserialize(&params[i]) } request["params"] = params } } request["id"] = atomic.AddInt32(&filter.id, 1) data, _ = json.Marshal(request) } return data }
go
func (filter *ClientFilter) OutputFilter(data []byte, context rpc.Context) []byte { if context.GetBool("jsonrpc") { request := make(map[string]interface{}) if filter.Version == "1.1" { request["version"] = "1.1" } else if filter.Version == "2.0" { request["jsonrpc"] = "2.0" } reader := io.NewReader(data, false) reader.JSONCompatible = true tag, _ := reader.ReadByte() if tag == io.TagCall { request["method"] = reader.ReadString() tag, _ = reader.ReadByte() if tag == io.TagList { reader.Reset() count := reader.ReadCount() params := make([]interface{}, count) for i := 0; i < count; i++ { reader.Unserialize(&params[i]) } request["params"] = params } } request["id"] = atomic.AddInt32(&filter.id, 1) data, _ = json.Marshal(request) } return data }
[ "func", "(", "filter", "*", "ClientFilter", ")", "OutputFilter", "(", "data", "[", "]", "byte", ",", "context", "rpc", ".", "Context", ")", "[", "]", "byte", "{", "if", "context", ".", "GetBool", "(", "\"", "\"", ")", "{", "request", ":=", "make", "(", "map", "[", "string", "]", "interface", "{", "}", ")", "\n", "if", "filter", ".", "Version", "==", "\"", "\"", "{", "request", "[", "\"", "\"", "]", "=", "\"", "\"", "\n", "}", "else", "if", "filter", ".", "Version", "==", "\"", "\"", "{", "request", "[", "\"", "\"", "]", "=", "\"", "\"", "\n", "}", "\n", "reader", ":=", "io", ".", "NewReader", "(", "data", ",", "false", ")", "\n", "reader", ".", "JSONCompatible", "=", "true", "\n", "tag", ",", "_", ":=", "reader", ".", "ReadByte", "(", ")", "\n", "if", "tag", "==", "io", ".", "TagCall", "{", "request", "[", "\"", "\"", "]", "=", "reader", ".", "ReadString", "(", ")", "\n", "tag", ",", "_", "=", "reader", ".", "ReadByte", "(", ")", "\n", "if", "tag", "==", "io", ".", "TagList", "{", "reader", ".", "Reset", "(", ")", "\n", "count", ":=", "reader", ".", "ReadCount", "(", ")", "\n", "params", ":=", "make", "(", "[", "]", "interface", "{", "}", ",", "count", ")", "\n", "for", "i", ":=", "0", ";", "i", "<", "count", ";", "i", "++", "{", "reader", ".", "Unserialize", "(", "&", "params", "[", "i", "]", ")", "\n", "}", "\n", "request", "[", "\"", "\"", "]", "=", "params", "\n", "}", "\n", "}", "\n", "request", "[", "\"", "\"", "]", "=", "atomic", ".", "AddInt32", "(", "&", "filter", ".", "id", ",", "1", ")", "\n", "data", ",", "_", "=", "json", ".", "Marshal", "(", "request", ")", "\n", "}", "\n", "return", "data", "\n", "}" ]
// OutputFilter for JSONRPC Client
[ "OutputFilter", "for", "JSONRPC", "Client" ]
6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74
https://github.com/hprose/hprose-golang/blob/6c2a3b7138ea2c7dc4a8907d644f9f134e0fae74/rpc/filter/jsonrpc/client_filter.go#L68-L96
train
theupdateframework/notary
tuf/utils/x509.go
X509PublicKeyID
func X509PublicKeyID(certPubKey data.PublicKey) (string, error) { // Note that this only loads the first certificate from the public key cert, err := LoadCertFromPEM(certPubKey.Public()) if err != nil { return "", err } pubKeyBytes, err := x509.MarshalPKIXPublicKey(cert.PublicKey) if err != nil { return "", err } var key data.PublicKey switch certPubKey.Algorithm() { case data.ECDSAx509Key: key = data.NewECDSAPublicKey(pubKeyBytes) case data.RSAx509Key: key = data.NewRSAPublicKey(pubKeyBytes) } return key.ID(), nil }
go
func X509PublicKeyID(certPubKey data.PublicKey) (string, error) { // Note that this only loads the first certificate from the public key cert, err := LoadCertFromPEM(certPubKey.Public()) if err != nil { return "", err } pubKeyBytes, err := x509.MarshalPKIXPublicKey(cert.PublicKey) if err != nil { return "", err } var key data.PublicKey switch certPubKey.Algorithm() { case data.ECDSAx509Key: key = data.NewECDSAPublicKey(pubKeyBytes) case data.RSAx509Key: key = data.NewRSAPublicKey(pubKeyBytes) } return key.ID(), nil }
[ "func", "X509PublicKeyID", "(", "certPubKey", "data", ".", "PublicKey", ")", "(", "string", ",", "error", ")", "{", "// Note that this only loads the first certificate from the public key", "cert", ",", "err", ":=", "LoadCertFromPEM", "(", "certPubKey", ".", "Public", "(", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "err", "\n", "}", "\n", "pubKeyBytes", ",", "err", ":=", "x509", ".", "MarshalPKIXPublicKey", "(", "cert", ".", "PublicKey", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "err", "\n", "}", "\n\n", "var", "key", "data", ".", "PublicKey", "\n", "switch", "certPubKey", ".", "Algorithm", "(", ")", "{", "case", "data", ".", "ECDSAx509Key", ":", "key", "=", "data", ".", "NewECDSAPublicKey", "(", "pubKeyBytes", ")", "\n", "case", "data", ".", "RSAx509Key", ":", "key", "=", "data", ".", "NewRSAPublicKey", "(", "pubKeyBytes", ")", "\n", "}", "\n\n", "return", "key", ".", "ID", "(", ")", ",", "nil", "\n", "}" ]
// X509PublicKeyID returns a public key ID as a string, given a // data.PublicKey that contains an X509 Certificate
[ "X509PublicKeyID", "returns", "a", "public", "key", "ID", "as", "a", "string", "given", "a", "data", ".", "PublicKey", "that", "contains", "an", "X509", "Certificate" ]
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/tuf/utils/x509.go#L66-L86
train
theupdateframework/notary
tuf/utils/x509.go
CertToPEM
func CertToPEM(cert *x509.Certificate) []byte { pemCert := pem.EncodeToMemory(&pem.Block{Type: "CERTIFICATE", Bytes: cert.Raw}) return pemCert }
go
func CertToPEM(cert *x509.Certificate) []byte { pemCert := pem.EncodeToMemory(&pem.Block{Type: "CERTIFICATE", Bytes: cert.Raw}) return pemCert }
[ "func", "CertToPEM", "(", "cert", "*", "x509", ".", "Certificate", ")", "[", "]", "byte", "{", "pemCert", ":=", "pem", ".", "EncodeToMemory", "(", "&", "pem", ".", "Block", "{", "Type", ":", "\"", "\"", ",", "Bytes", ":", "cert", ".", "Raw", "}", ")", "\n\n", "return", "pemCert", "\n", "}" ]
// CertToPEM is a utility function returns a PEM encoded x509 Certificate
[ "CertToPEM", "is", "a", "utility", "function", "returns", "a", "PEM", "encoded", "x509", "Certificate" ]
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/tuf/utils/x509.go#L171-L175
train
theupdateframework/notary
tuf/utils/x509.go
CertChainToPEM
func CertChainToPEM(certChain []*x509.Certificate) ([]byte, error) { var pemBytes bytes.Buffer for _, cert := range certChain { if err := pem.Encode(&pemBytes, &pem.Block{Type: "CERTIFICATE", Bytes: cert.Raw}); err != nil { return nil, err } } return pemBytes.Bytes(), nil }
go
func CertChainToPEM(certChain []*x509.Certificate) ([]byte, error) { var pemBytes bytes.Buffer for _, cert := range certChain { if err := pem.Encode(&pemBytes, &pem.Block{Type: "CERTIFICATE", Bytes: cert.Raw}); err != nil { return nil, err } } return pemBytes.Bytes(), nil }
[ "func", "CertChainToPEM", "(", "certChain", "[", "]", "*", "x509", ".", "Certificate", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "var", "pemBytes", "bytes", ".", "Buffer", "\n", "for", "_", ",", "cert", ":=", "range", "certChain", "{", "if", "err", ":=", "pem", ".", "Encode", "(", "&", "pemBytes", ",", "&", "pem", ".", "Block", "{", "Type", ":", "\"", "\"", ",", "Bytes", ":", "cert", ".", "Raw", "}", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "}", "\n", "return", "pemBytes", ".", "Bytes", "(", ")", ",", "nil", "\n", "}" ]
// CertChainToPEM is a utility function returns a PEM encoded chain of x509 Certificates, in the order they are passed
[ "CertChainToPEM", "is", "a", "utility", "function", "returns", "a", "PEM", "encoded", "chain", "of", "x509", "Certificates", "in", "the", "order", "they", "are", "passed" ]
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/tuf/utils/x509.go#L178-L186
train
theupdateframework/notary
tuf/utils/x509.go
LoadCertFromFile
func LoadCertFromFile(filename string) (*x509.Certificate, error) { certs, err := LoadCertBundleFromFile(filename) if err != nil { return nil, err } return certs[0], nil }
go
func LoadCertFromFile(filename string) (*x509.Certificate, error) { certs, err := LoadCertBundleFromFile(filename) if err != nil { return nil, err } return certs[0], nil }
[ "func", "LoadCertFromFile", "(", "filename", "string", ")", "(", "*", "x509", ".", "Certificate", ",", "error", ")", "{", "certs", ",", "err", ":=", "LoadCertBundleFromFile", "(", "filename", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "certs", "[", "0", "]", ",", "nil", "\n", "}" ]
// LoadCertFromFile loads the first certificate from the file provided. The // data is expected to be PEM Encoded and contain one of more certificates // with PEM type "CERTIFICATE"
[ "LoadCertFromFile", "loads", "the", "first", "certificate", "from", "the", "file", "provided", ".", "The", "data", "is", "expected", "to", "be", "PEM", "Encoded", "and", "contain", "one", "of", "more", "certificates", "with", "PEM", "type", "CERTIFICATE" ]
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/tuf/utils/x509.go#L191-L197
train
theupdateframework/notary
tuf/utils/x509.go
GetLeafCerts
func GetLeafCerts(certs []*x509.Certificate) []*x509.Certificate { var leafCerts []*x509.Certificate for _, cert := range certs { if cert.IsCA { continue } leafCerts = append(leafCerts, cert) } return leafCerts }
go
func GetLeafCerts(certs []*x509.Certificate) []*x509.Certificate { var leafCerts []*x509.Certificate for _, cert := range certs { if cert.IsCA { continue } leafCerts = append(leafCerts, cert) } return leafCerts }
[ "func", "GetLeafCerts", "(", "certs", "[", "]", "*", "x509", ".", "Certificate", ")", "[", "]", "*", "x509", ".", "Certificate", "{", "var", "leafCerts", "[", "]", "*", "x509", ".", "Certificate", "\n", "for", "_", ",", "cert", ":=", "range", "certs", "{", "if", "cert", ".", "IsCA", "{", "continue", "\n", "}", "\n", "leafCerts", "=", "append", "(", "leafCerts", ",", "cert", ")", "\n", "}", "\n", "return", "leafCerts", "\n", "}" ]
// GetLeafCerts parses a list of x509 Certificates and returns all of them // that aren't CA
[ "GetLeafCerts", "parses", "a", "list", "of", "x509", "Certificates", "and", "returns", "all", "of", "them", "that", "aren", "t", "CA" ]
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/tuf/utils/x509.go#L239-L248
train
theupdateframework/notary
tuf/utils/x509.go
GetIntermediateCerts
func GetIntermediateCerts(certs []*x509.Certificate) []*x509.Certificate { var intCerts []*x509.Certificate for _, cert := range certs { if cert.IsCA { intCerts = append(intCerts, cert) } } return intCerts }
go
func GetIntermediateCerts(certs []*x509.Certificate) []*x509.Certificate { var intCerts []*x509.Certificate for _, cert := range certs { if cert.IsCA { intCerts = append(intCerts, cert) } } return intCerts }
[ "func", "GetIntermediateCerts", "(", "certs", "[", "]", "*", "x509", ".", "Certificate", ")", "[", "]", "*", "x509", ".", "Certificate", "{", "var", "intCerts", "[", "]", "*", "x509", ".", "Certificate", "\n", "for", "_", ",", "cert", ":=", "range", "certs", "{", "if", "cert", ".", "IsCA", "{", "intCerts", "=", "append", "(", "intCerts", ",", "cert", ")", "\n", "}", "\n", "}", "\n", "return", "intCerts", "\n", "}" ]
// GetIntermediateCerts parses a list of x509 Certificates and returns all of the // ones marked as a CA, to be used as intermediates
[ "GetIntermediateCerts", "parses", "a", "list", "of", "x509", "Certificates", "and", "returns", "all", "of", "the", "ones", "marked", "as", "a", "CA", "to", "be", "used", "as", "intermediates" ]
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/tuf/utils/x509.go#L252-L260
train
theupdateframework/notary
tuf/utils/x509.go
ParsePEMPublicKey
func ParsePEMPublicKey(pubKeyBytes []byte) (data.PublicKey, error) { pemBlock, _ := pem.Decode(pubKeyBytes) if pemBlock == nil { return nil, errors.New("no valid public key found") } switch pemBlock.Type { case "CERTIFICATE": cert, err := x509.ParseCertificate(pemBlock.Bytes) if err != nil { return nil, fmt.Errorf("could not parse provided certificate: %v", err) } err = ValidateCertificate(cert, true) if err != nil { return nil, fmt.Errorf("invalid certificate: %v", err) } return CertToKey(cert), nil case "PUBLIC KEY": keyType, err := keyTypeForPublicKey(pemBlock.Bytes) if err != nil { return nil, err } return data.NewPublicKey(keyType, pemBlock.Bytes), nil default: return nil, fmt.Errorf("unsupported PEM block type %q, expected CERTIFICATE or PUBLIC KEY", pemBlock.Type) } }
go
func ParsePEMPublicKey(pubKeyBytes []byte) (data.PublicKey, error) { pemBlock, _ := pem.Decode(pubKeyBytes) if pemBlock == nil { return nil, errors.New("no valid public key found") } switch pemBlock.Type { case "CERTIFICATE": cert, err := x509.ParseCertificate(pemBlock.Bytes) if err != nil { return nil, fmt.Errorf("could not parse provided certificate: %v", err) } err = ValidateCertificate(cert, true) if err != nil { return nil, fmt.Errorf("invalid certificate: %v", err) } return CertToKey(cert), nil case "PUBLIC KEY": keyType, err := keyTypeForPublicKey(pemBlock.Bytes) if err != nil { return nil, err } return data.NewPublicKey(keyType, pemBlock.Bytes), nil default: return nil, fmt.Errorf("unsupported PEM block type %q, expected CERTIFICATE or PUBLIC KEY", pemBlock.Type) } }
[ "func", "ParsePEMPublicKey", "(", "pubKeyBytes", "[", "]", "byte", ")", "(", "data", ".", "PublicKey", ",", "error", ")", "{", "pemBlock", ",", "_", ":=", "pem", ".", "Decode", "(", "pubKeyBytes", ")", "\n", "if", "pemBlock", "==", "nil", "{", "return", "nil", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "switch", "pemBlock", ".", "Type", "{", "case", "\"", "\"", ":", "cert", ",", "err", ":=", "x509", ".", "ParseCertificate", "(", "pemBlock", ".", "Bytes", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "err", "=", "ValidateCertificate", "(", "cert", ",", "true", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "return", "CertToKey", "(", "cert", ")", ",", "nil", "\n", "case", "\"", "\"", ":", "keyType", ",", "err", ":=", "keyTypeForPublicKey", "(", "pemBlock", ".", "Bytes", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "data", ".", "NewPublicKey", "(", "keyType", ",", "pemBlock", ".", "Bytes", ")", ",", "nil", "\n", "default", ":", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "pemBlock", ".", "Type", ")", "\n", "}", "\n", "}" ]
// ParsePEMPublicKey returns a data.PublicKey from a PEM encoded public key or certificate.
[ "ParsePEMPublicKey", "returns", "a", "data", ".", "PublicKey", "from", "a", "PEM", "encoded", "public", "key", "or", "certificate", "." ]
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/tuf/utils/x509.go#L263-L289
train
theupdateframework/notary
tuf/utils/x509.go
ValidateCertificate
func ValidateCertificate(c *x509.Certificate, checkExpiry bool) error { if (c.NotBefore).After(c.NotAfter) { return fmt.Errorf("certificate validity window is invalid") } // Can't have SHA1 sig algorithm if c.SignatureAlgorithm == x509.SHA1WithRSA || c.SignatureAlgorithm == x509.DSAWithSHA1 || c.SignatureAlgorithm == x509.ECDSAWithSHA1 { return fmt.Errorf("certificate with CN %s uses invalid SHA1 signature algorithm", c.Subject.CommonName) } // If we have an RSA key, make sure it's long enough if c.PublicKeyAlgorithm == x509.RSA { rsaKey, ok := c.PublicKey.(*rsa.PublicKey) if !ok { return fmt.Errorf("unable to parse RSA public key") } if rsaKey.N.BitLen() < notary.MinRSABitSize { return fmt.Errorf("RSA bit length is too short") } } if checkExpiry { now := time.Now() tomorrow := now.AddDate(0, 0, 1) // Give one day leeway on creation "before" time, check "after" against today if (tomorrow).Before(c.NotBefore) || now.After(c.NotAfter) { return data.ErrCertExpired{CN: c.Subject.CommonName} } // If this certificate is expiring within 6 months, put out a warning if (c.NotAfter).Before(time.Now().AddDate(0, 6, 0)) { logrus.Warnf("certificate with CN %s is near expiry", c.Subject.CommonName) } } return nil }
go
func ValidateCertificate(c *x509.Certificate, checkExpiry bool) error { if (c.NotBefore).After(c.NotAfter) { return fmt.Errorf("certificate validity window is invalid") } // Can't have SHA1 sig algorithm if c.SignatureAlgorithm == x509.SHA1WithRSA || c.SignatureAlgorithm == x509.DSAWithSHA1 || c.SignatureAlgorithm == x509.ECDSAWithSHA1 { return fmt.Errorf("certificate with CN %s uses invalid SHA1 signature algorithm", c.Subject.CommonName) } // If we have an RSA key, make sure it's long enough if c.PublicKeyAlgorithm == x509.RSA { rsaKey, ok := c.PublicKey.(*rsa.PublicKey) if !ok { return fmt.Errorf("unable to parse RSA public key") } if rsaKey.N.BitLen() < notary.MinRSABitSize { return fmt.Errorf("RSA bit length is too short") } } if checkExpiry { now := time.Now() tomorrow := now.AddDate(0, 0, 1) // Give one day leeway on creation "before" time, check "after" against today if (tomorrow).Before(c.NotBefore) || now.After(c.NotAfter) { return data.ErrCertExpired{CN: c.Subject.CommonName} } // If this certificate is expiring within 6 months, put out a warning if (c.NotAfter).Before(time.Now().AddDate(0, 6, 0)) { logrus.Warnf("certificate with CN %s is near expiry", c.Subject.CommonName) } } return nil }
[ "func", "ValidateCertificate", "(", "c", "*", "x509", ".", "Certificate", ",", "checkExpiry", "bool", ")", "error", "{", "if", "(", "c", ".", "NotBefore", ")", ".", "After", "(", "c", ".", "NotAfter", ")", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n", "// Can't have SHA1 sig algorithm", "if", "c", ".", "SignatureAlgorithm", "==", "x509", ".", "SHA1WithRSA", "||", "c", ".", "SignatureAlgorithm", "==", "x509", ".", "DSAWithSHA1", "||", "c", ".", "SignatureAlgorithm", "==", "x509", ".", "ECDSAWithSHA1", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "c", ".", "Subject", ".", "CommonName", ")", "\n", "}", "\n", "// If we have an RSA key, make sure it's long enough", "if", "c", ".", "PublicKeyAlgorithm", "==", "x509", ".", "RSA", "{", "rsaKey", ",", "ok", ":=", "c", ".", "PublicKey", ".", "(", "*", "rsa", ".", "PublicKey", ")", "\n", "if", "!", "ok", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n", "if", "rsaKey", ".", "N", ".", "BitLen", "(", ")", "<", "notary", ".", "MinRSABitSize", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n", "}", "\n", "if", "checkExpiry", "{", "now", ":=", "time", ".", "Now", "(", ")", "\n", "tomorrow", ":=", "now", ".", "AddDate", "(", "0", ",", "0", ",", "1", ")", "\n", "// Give one day leeway on creation \"before\" time, check \"after\" against today", "if", "(", "tomorrow", ")", ".", "Before", "(", "c", ".", "NotBefore", ")", "||", "now", ".", "After", "(", "c", ".", "NotAfter", ")", "{", "return", "data", ".", "ErrCertExpired", "{", "CN", ":", "c", ".", "Subject", ".", "CommonName", "}", "\n", "}", "\n", "// If this certificate is expiring within 6 months, put out a warning", "if", "(", "c", ".", "NotAfter", ")", ".", "Before", "(", "time", ".", "Now", "(", ")", ".", "AddDate", "(", "0", ",", "6", ",", "0", ")", ")", "{", "logrus", ".", "Warnf", "(", "\"", "\"", ",", "c", ".", "Subject", ".", "CommonName", ")", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// ValidateCertificate returns an error if the certificate is not valid for notary // Currently this is only ensuring the public key has a large enough modulus if RSA, // using a non SHA1 signature algorithm, and an optional time expiry check
[ "ValidateCertificate", "returns", "an", "error", "if", "the", "certificate", "is", "not", "valid", "for", "notary", "Currently", "this", "is", "only", "ensuring", "the", "public", "key", "has", "a", "large", "enough", "modulus", "if", "RSA", "using", "a", "non", "SHA1", "signature", "algorithm", "and", "an", "optional", "time", "expiry", "check" ]
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/tuf/utils/x509.go#L308-L339
train
theupdateframework/notary
tuf/utils/x509.go
GenerateKey
func GenerateKey(algorithm string) (data.PrivateKey, error) { switch algorithm { case data.ECDSAKey: return GenerateECDSAKey(rand.Reader) case data.ED25519Key: return GenerateED25519Key(rand.Reader) } return nil, fmt.Errorf("private key type not supported for key generation: %s", algorithm) }
go
func GenerateKey(algorithm string) (data.PrivateKey, error) { switch algorithm { case data.ECDSAKey: return GenerateECDSAKey(rand.Reader) case data.ED25519Key: return GenerateED25519Key(rand.Reader) } return nil, fmt.Errorf("private key type not supported for key generation: %s", algorithm) }
[ "func", "GenerateKey", "(", "algorithm", "string", ")", "(", "data", ".", "PrivateKey", ",", "error", ")", "{", "switch", "algorithm", "{", "case", "data", ".", "ECDSAKey", ":", "return", "GenerateECDSAKey", "(", "rand", ".", "Reader", ")", "\n", "case", "data", ".", "ED25519Key", ":", "return", "GenerateED25519Key", "(", "rand", ".", "Reader", ")", "\n", "}", "\n", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "algorithm", ")", "\n", "}" ]
// GenerateKey returns a new private key using the provided algorithm or an // error detailing why the key could not be generated
[ "GenerateKey", "returns", "a", "new", "private", "key", "using", "the", "provided", "algorithm", "or", "an", "error", "detailing", "why", "the", "key", "could", "not", "be", "generated" ]
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/tuf/utils/x509.go#L343-L351
train
theupdateframework/notary
tuf/utils/x509.go
RSAToPrivateKey
func RSAToPrivateKey(rsaPrivKey *rsa.PrivateKey) (data.PrivateKey, error) { // Get a DER-encoded representation of the PublicKey rsaPubBytes, err := x509.MarshalPKIXPublicKey(&rsaPrivKey.PublicKey) if err != nil { return nil, fmt.Errorf("failed to marshal public key: %v", err) } // Get a DER-encoded representation of the PrivateKey rsaPrivBytes := x509.MarshalPKCS1PrivateKey(rsaPrivKey) pubKey := data.NewRSAPublicKey(rsaPubBytes) return data.NewRSAPrivateKey(pubKey, rsaPrivBytes) }
go
func RSAToPrivateKey(rsaPrivKey *rsa.PrivateKey) (data.PrivateKey, error) { // Get a DER-encoded representation of the PublicKey rsaPubBytes, err := x509.MarshalPKIXPublicKey(&rsaPrivKey.PublicKey) if err != nil { return nil, fmt.Errorf("failed to marshal public key: %v", err) } // Get a DER-encoded representation of the PrivateKey rsaPrivBytes := x509.MarshalPKCS1PrivateKey(rsaPrivKey) pubKey := data.NewRSAPublicKey(rsaPubBytes) return data.NewRSAPrivateKey(pubKey, rsaPrivBytes) }
[ "func", "RSAToPrivateKey", "(", "rsaPrivKey", "*", "rsa", ".", "PrivateKey", ")", "(", "data", ".", "PrivateKey", ",", "error", ")", "{", "// Get a DER-encoded representation of the PublicKey", "rsaPubBytes", ",", "err", ":=", "x509", ".", "MarshalPKIXPublicKey", "(", "&", "rsaPrivKey", ".", "PublicKey", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "// Get a DER-encoded representation of the PrivateKey", "rsaPrivBytes", ":=", "x509", ".", "MarshalPKCS1PrivateKey", "(", "rsaPrivKey", ")", "\n\n", "pubKey", ":=", "data", ".", "NewRSAPublicKey", "(", "rsaPubBytes", ")", "\n", "return", "data", ".", "NewRSAPrivateKey", "(", "pubKey", ",", "rsaPrivBytes", ")", "\n", "}" ]
// RSAToPrivateKey converts an rsa.Private key to a TUF data.PrivateKey type
[ "RSAToPrivateKey", "converts", "an", "rsa", ".", "Private", "key", "to", "a", "TUF", "data", ".", "PrivateKey", "type" ]
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/tuf/utils/x509.go#L354-L366
train
theupdateframework/notary
tuf/utils/x509.go
GenerateECDSAKey
func GenerateECDSAKey(random io.Reader) (data.PrivateKey, error) { ecdsaPrivKey, err := ecdsa.GenerateKey(elliptic.P256(), random) if err != nil { return nil, err } tufPrivKey, err := ECDSAToPrivateKey(ecdsaPrivKey) if err != nil { return nil, err } logrus.Debugf("generated ECDSA key with keyID: %s", tufPrivKey.ID()) return tufPrivKey, nil }
go
func GenerateECDSAKey(random io.Reader) (data.PrivateKey, error) { ecdsaPrivKey, err := ecdsa.GenerateKey(elliptic.P256(), random) if err != nil { return nil, err } tufPrivKey, err := ECDSAToPrivateKey(ecdsaPrivKey) if err != nil { return nil, err } logrus.Debugf("generated ECDSA key with keyID: %s", tufPrivKey.ID()) return tufPrivKey, nil }
[ "func", "GenerateECDSAKey", "(", "random", "io", ".", "Reader", ")", "(", "data", ".", "PrivateKey", ",", "error", ")", "{", "ecdsaPrivKey", ",", "err", ":=", "ecdsa", ".", "GenerateKey", "(", "elliptic", ".", "P256", "(", ")", ",", "random", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "tufPrivKey", ",", "err", ":=", "ECDSAToPrivateKey", "(", "ecdsaPrivKey", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "logrus", ".", "Debugf", "(", "\"", "\"", ",", "tufPrivKey", ".", "ID", "(", ")", ")", "\n\n", "return", "tufPrivKey", ",", "nil", "\n", "}" ]
// GenerateECDSAKey generates an ECDSA Private key and returns a TUF PrivateKey
[ "GenerateECDSAKey", "generates", "an", "ECDSA", "Private", "key", "and", "returns", "a", "TUF", "PrivateKey" ]
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/tuf/utils/x509.go#L369-L383
train
theupdateframework/notary
tuf/utils/x509.go
GenerateED25519Key
func GenerateED25519Key(random io.Reader) (data.PrivateKey, error) { pub, priv, err := ed25519.GenerateKey(random) if err != nil { return nil, err } var serialized [ed25519.PublicKeySize + ed25519.PrivateKeySize]byte copy(serialized[:], pub[:]) copy(serialized[ed25519.PublicKeySize:], priv[:]) tufPrivKey, err := ED25519ToPrivateKey(serialized[:]) if err != nil { return nil, err } logrus.Debugf("generated ED25519 key with keyID: %s", tufPrivKey.ID()) return tufPrivKey, nil }
go
func GenerateED25519Key(random io.Reader) (data.PrivateKey, error) { pub, priv, err := ed25519.GenerateKey(random) if err != nil { return nil, err } var serialized [ed25519.PublicKeySize + ed25519.PrivateKeySize]byte copy(serialized[:], pub[:]) copy(serialized[ed25519.PublicKeySize:], priv[:]) tufPrivKey, err := ED25519ToPrivateKey(serialized[:]) if err != nil { return nil, err } logrus.Debugf("generated ED25519 key with keyID: %s", tufPrivKey.ID()) return tufPrivKey, nil }
[ "func", "GenerateED25519Key", "(", "random", "io", ".", "Reader", ")", "(", "data", ".", "PrivateKey", ",", "error", ")", "{", "pub", ",", "priv", ",", "err", ":=", "ed25519", ".", "GenerateKey", "(", "random", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "var", "serialized", "[", "ed25519", ".", "PublicKeySize", "+", "ed25519", ".", "PrivateKeySize", "]", "byte", "\n", "copy", "(", "serialized", "[", ":", "]", ",", "pub", "[", ":", "]", ")", "\n", "copy", "(", "serialized", "[", "ed25519", ".", "PublicKeySize", ":", "]", ",", "priv", "[", ":", "]", ")", "\n\n", "tufPrivKey", ",", "err", ":=", "ED25519ToPrivateKey", "(", "serialized", "[", ":", "]", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "logrus", ".", "Debugf", "(", "\"", "\"", ",", "tufPrivKey", ".", "ID", "(", ")", ")", "\n\n", "return", "tufPrivKey", ",", "nil", "\n", "}" ]
// GenerateED25519Key generates an ED25519 private key and returns a TUF // PrivateKey. The serialization format we use is just the public key bytes // followed by the private key bytes
[ "GenerateED25519Key", "generates", "an", "ED25519", "private", "key", "and", "returns", "a", "TUF", "PrivateKey", ".", "The", "serialization", "format", "we", "use", "is", "just", "the", "public", "key", "bytes", "followed", "by", "the", "private", "key", "bytes" ]
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/tuf/utils/x509.go#L388-L406
train
theupdateframework/notary
tuf/utils/x509.go
ECDSAToPrivateKey
func ECDSAToPrivateKey(ecdsaPrivKey *ecdsa.PrivateKey) (data.PrivateKey, error) { // Get a DER-encoded representation of the PublicKey ecdsaPubBytes, err := x509.MarshalPKIXPublicKey(&ecdsaPrivKey.PublicKey) if err != nil { return nil, fmt.Errorf("failed to marshal public key: %v", err) } // Get a DER-encoded representation of the PrivateKey ecdsaPrivKeyBytes, err := x509.MarshalECPrivateKey(ecdsaPrivKey) if err != nil { return nil, fmt.Errorf("failed to marshal private key: %v", err) } pubKey := data.NewECDSAPublicKey(ecdsaPubBytes) return data.NewECDSAPrivateKey(pubKey, ecdsaPrivKeyBytes) }
go
func ECDSAToPrivateKey(ecdsaPrivKey *ecdsa.PrivateKey) (data.PrivateKey, error) { // Get a DER-encoded representation of the PublicKey ecdsaPubBytes, err := x509.MarshalPKIXPublicKey(&ecdsaPrivKey.PublicKey) if err != nil { return nil, fmt.Errorf("failed to marshal public key: %v", err) } // Get a DER-encoded representation of the PrivateKey ecdsaPrivKeyBytes, err := x509.MarshalECPrivateKey(ecdsaPrivKey) if err != nil { return nil, fmt.Errorf("failed to marshal private key: %v", err) } pubKey := data.NewECDSAPublicKey(ecdsaPubBytes) return data.NewECDSAPrivateKey(pubKey, ecdsaPrivKeyBytes) }
[ "func", "ECDSAToPrivateKey", "(", "ecdsaPrivKey", "*", "ecdsa", ".", "PrivateKey", ")", "(", "data", ".", "PrivateKey", ",", "error", ")", "{", "// Get a DER-encoded representation of the PublicKey", "ecdsaPubBytes", ",", "err", ":=", "x509", ".", "MarshalPKIXPublicKey", "(", "&", "ecdsaPrivKey", ".", "PublicKey", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "// Get a DER-encoded representation of the PrivateKey", "ecdsaPrivKeyBytes", ",", "err", ":=", "x509", ".", "MarshalECPrivateKey", "(", "ecdsaPrivKey", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "pubKey", ":=", "data", ".", "NewECDSAPublicKey", "(", "ecdsaPubBytes", ")", "\n", "return", "data", ".", "NewECDSAPrivateKey", "(", "pubKey", ",", "ecdsaPrivKeyBytes", ")", "\n", "}" ]
// ECDSAToPrivateKey converts an ecdsa.Private key to a TUF data.PrivateKey type
[ "ECDSAToPrivateKey", "converts", "an", "ecdsa", ".", "Private", "key", "to", "a", "TUF", "data", ".", "PrivateKey", "type" ]
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/tuf/utils/x509.go#L409-L424
train
theupdateframework/notary
tuf/utils/x509.go
ED25519ToPrivateKey
func ED25519ToPrivateKey(privKeyBytes []byte) (data.PrivateKey, error) { if len(privKeyBytes) != ed25519.PublicKeySize+ed25519.PrivateKeySize { return nil, errors.New("malformed ed25519 private key") } pubKey := data.NewED25519PublicKey(privKeyBytes[:ed25519.PublicKeySize]) return data.NewED25519PrivateKey(*pubKey, privKeyBytes) }
go
func ED25519ToPrivateKey(privKeyBytes []byte) (data.PrivateKey, error) { if len(privKeyBytes) != ed25519.PublicKeySize+ed25519.PrivateKeySize { return nil, errors.New("malformed ed25519 private key") } pubKey := data.NewED25519PublicKey(privKeyBytes[:ed25519.PublicKeySize]) return data.NewED25519PrivateKey(*pubKey, privKeyBytes) }
[ "func", "ED25519ToPrivateKey", "(", "privKeyBytes", "[", "]", "byte", ")", "(", "data", ".", "PrivateKey", ",", "error", ")", "{", "if", "len", "(", "privKeyBytes", ")", "!=", "ed25519", ".", "PublicKeySize", "+", "ed25519", ".", "PrivateKeySize", "{", "return", "nil", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "pubKey", ":=", "data", ".", "NewED25519PublicKey", "(", "privKeyBytes", "[", ":", "ed25519", ".", "PublicKeySize", "]", ")", "\n", "return", "data", ".", "NewED25519PrivateKey", "(", "*", "pubKey", ",", "privKeyBytes", ")", "\n", "}" ]
// ED25519ToPrivateKey converts a serialized ED25519 key to a TUF // data.PrivateKey type
[ "ED25519ToPrivateKey", "converts", "a", "serialized", "ED25519", "key", "to", "a", "TUF", "data", ".", "PrivateKey", "type" ]
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/tuf/utils/x509.go#L428-L435
train
theupdateframework/notary
tuf/utils/x509.go
ExtractPrivateKeyAttributes
func ExtractPrivateKeyAttributes(pemBytes []byte) (data.RoleName, data.GUN, error) { return extractPrivateKeyAttributes(pemBytes, notary.FIPSEnabled()) }
go
func ExtractPrivateKeyAttributes(pemBytes []byte) (data.RoleName, data.GUN, error) { return extractPrivateKeyAttributes(pemBytes, notary.FIPSEnabled()) }
[ "func", "ExtractPrivateKeyAttributes", "(", "pemBytes", "[", "]", "byte", ")", "(", "data", ".", "RoleName", ",", "data", ".", "GUN", ",", "error", ")", "{", "return", "extractPrivateKeyAttributes", "(", "pemBytes", ",", "notary", ".", "FIPSEnabled", "(", ")", ")", "\n", "}" ]
// ExtractPrivateKeyAttributes extracts role and gun values from private key bytes
[ "ExtractPrivateKeyAttributes", "extracts", "role", "and", "gun", "values", "from", "private", "key", "bytes" ]
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/tuf/utils/x509.go#L438-L440
train
theupdateframework/notary
tuf/utils/x509.go
CertToKey
func CertToKey(cert *x509.Certificate) data.PublicKey { block := pem.Block{Type: "CERTIFICATE", Bytes: cert.Raw} pemdata := pem.EncodeToMemory(&block) switch cert.PublicKeyAlgorithm { case x509.RSA: return data.NewRSAx509PublicKey(pemdata) case x509.ECDSA: return data.NewECDSAx509PublicKey(pemdata) default: logrus.Debugf("Unknown key type parsed from certificate: %v", cert.PublicKeyAlgorithm) return nil } }
go
func CertToKey(cert *x509.Certificate) data.PublicKey { block := pem.Block{Type: "CERTIFICATE", Bytes: cert.Raw} pemdata := pem.EncodeToMemory(&block) switch cert.PublicKeyAlgorithm { case x509.RSA: return data.NewRSAx509PublicKey(pemdata) case x509.ECDSA: return data.NewECDSAx509PublicKey(pemdata) default: logrus.Debugf("Unknown key type parsed from certificate: %v", cert.PublicKeyAlgorithm) return nil } }
[ "func", "CertToKey", "(", "cert", "*", "x509", ".", "Certificate", ")", "data", ".", "PublicKey", "{", "block", ":=", "pem", ".", "Block", "{", "Type", ":", "\"", "\"", ",", "Bytes", ":", "cert", ".", "Raw", "}", "\n", "pemdata", ":=", "pem", ".", "EncodeToMemory", "(", "&", "block", ")", "\n\n", "switch", "cert", ".", "PublicKeyAlgorithm", "{", "case", "x509", ".", "RSA", ":", "return", "data", ".", "NewRSAx509PublicKey", "(", "pemdata", ")", "\n", "case", "x509", ".", "ECDSA", ":", "return", "data", ".", "NewECDSAx509PublicKey", "(", "pemdata", ")", "\n", "default", ":", "logrus", ".", "Debugf", "(", "\"", "\"", ",", "cert", ".", "PublicKeyAlgorithm", ")", "\n", "return", "nil", "\n", "}", "\n", "}" ]
// CertToKey transforms a single input certificate into its corresponding // PublicKey
[ "CertToKey", "transforms", "a", "single", "input", "certificate", "into", "its", "corresponding", "PublicKey" ]
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/tuf/utils/x509.go#L493-L506
train
theupdateframework/notary
tuf/utils/x509.go
CertsToKeys
func CertsToKeys(leafCerts map[string]*x509.Certificate, intCerts map[string][]*x509.Certificate) map[string]data.PublicKey { keys := make(map[string]data.PublicKey) for id, leafCert := range leafCerts { if key, err := CertBundleToKey(leafCert, intCerts[id]); err == nil { keys[key.ID()] = key } } return keys }
go
func CertsToKeys(leafCerts map[string]*x509.Certificate, intCerts map[string][]*x509.Certificate) map[string]data.PublicKey { keys := make(map[string]data.PublicKey) for id, leafCert := range leafCerts { if key, err := CertBundleToKey(leafCert, intCerts[id]); err == nil { keys[key.ID()] = key } } return keys }
[ "func", "CertsToKeys", "(", "leafCerts", "map", "[", "string", "]", "*", "x509", ".", "Certificate", ",", "intCerts", "map", "[", "string", "]", "[", "]", "*", "x509", ".", "Certificate", ")", "map", "[", "string", "]", "data", ".", "PublicKey", "{", "keys", ":=", "make", "(", "map", "[", "string", "]", "data", ".", "PublicKey", ")", "\n", "for", "id", ",", "leafCert", ":=", "range", "leafCerts", "{", "if", "key", ",", "err", ":=", "CertBundleToKey", "(", "leafCert", ",", "intCerts", "[", "id", "]", ")", ";", "err", "==", "nil", "{", "keys", "[", "key", ".", "ID", "(", ")", "]", "=", "key", "\n", "}", "\n", "}", "\n", "return", "keys", "\n", "}" ]
// CertsToKeys transforms each of the input certificate chains into its corresponding // PublicKey
[ "CertsToKeys", "transforms", "each", "of", "the", "input", "certificate", "chains", "into", "its", "corresponding", "PublicKey" ]
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/tuf/utils/x509.go#L510-L518
train
theupdateframework/notary
tuf/utils/x509.go
CertBundleToKey
func CertBundleToKey(leafCert *x509.Certificate, intCerts []*x509.Certificate) (data.PublicKey, error) { certBundle := []*x509.Certificate{leafCert} certBundle = append(certBundle, intCerts...) certChainPEM, err := CertChainToPEM(certBundle) if err != nil { return nil, err } var newKey data.PublicKey // Use the leaf cert's public key algorithm for typing switch leafCert.PublicKeyAlgorithm { case x509.RSA: newKey = data.NewRSAx509PublicKey(certChainPEM) case x509.ECDSA: newKey = data.NewECDSAx509PublicKey(certChainPEM) default: logrus.Debugf("Unknown key type parsed from certificate: %v", leafCert.PublicKeyAlgorithm) return nil, x509.ErrUnsupportedAlgorithm } return newKey, nil }
go
func CertBundleToKey(leafCert *x509.Certificate, intCerts []*x509.Certificate) (data.PublicKey, error) { certBundle := []*x509.Certificate{leafCert} certBundle = append(certBundle, intCerts...) certChainPEM, err := CertChainToPEM(certBundle) if err != nil { return nil, err } var newKey data.PublicKey // Use the leaf cert's public key algorithm for typing switch leafCert.PublicKeyAlgorithm { case x509.RSA: newKey = data.NewRSAx509PublicKey(certChainPEM) case x509.ECDSA: newKey = data.NewECDSAx509PublicKey(certChainPEM) default: logrus.Debugf("Unknown key type parsed from certificate: %v", leafCert.PublicKeyAlgorithm) return nil, x509.ErrUnsupportedAlgorithm } return newKey, nil }
[ "func", "CertBundleToKey", "(", "leafCert", "*", "x509", ".", "Certificate", ",", "intCerts", "[", "]", "*", "x509", ".", "Certificate", ")", "(", "data", ".", "PublicKey", ",", "error", ")", "{", "certBundle", ":=", "[", "]", "*", "x509", ".", "Certificate", "{", "leafCert", "}", "\n", "certBundle", "=", "append", "(", "certBundle", ",", "intCerts", "...", ")", "\n", "certChainPEM", ",", "err", ":=", "CertChainToPEM", "(", "certBundle", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "var", "newKey", "data", ".", "PublicKey", "\n", "// Use the leaf cert's public key algorithm for typing", "switch", "leafCert", ".", "PublicKeyAlgorithm", "{", "case", "x509", ".", "RSA", ":", "newKey", "=", "data", ".", "NewRSAx509PublicKey", "(", "certChainPEM", ")", "\n", "case", "x509", ".", "ECDSA", ":", "newKey", "=", "data", ".", "NewECDSAx509PublicKey", "(", "certChainPEM", ")", "\n", "default", ":", "logrus", ".", "Debugf", "(", "\"", "\"", ",", "leafCert", ".", "PublicKeyAlgorithm", ")", "\n", "return", "nil", ",", "x509", ".", "ErrUnsupportedAlgorithm", "\n", "}", "\n", "return", "newKey", ",", "nil", "\n", "}" ]
// CertBundleToKey creates a TUF key from a leaf certs and a list of // intermediates
[ "CertBundleToKey", "creates", "a", "TUF", "key", "from", "a", "leaf", "certs", "and", "a", "list", "of", "intermediates" ]
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/tuf/utils/x509.go#L522-L541
train
theupdateframework/notary
tuf/utils/x509.go
NewCertificate
func NewCertificate(commonName string, startTime, endTime time.Time) (*x509.Certificate, error) { serialNumberLimit := new(big.Int).Lsh(big.NewInt(1), 128) serialNumber, err := rand.Int(rand.Reader, serialNumberLimit) if err != nil { return nil, fmt.Errorf("failed to generate new certificate: %v", err) } return &x509.Certificate{ SerialNumber: serialNumber, Subject: pkix.Name{ CommonName: commonName, }, NotBefore: startTime, NotAfter: endTime, KeyUsage: x509.KeyUsageKeyEncipherment | x509.KeyUsageDigitalSignature, ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageCodeSigning}, BasicConstraintsValid: true, }, nil }
go
func NewCertificate(commonName string, startTime, endTime time.Time) (*x509.Certificate, error) { serialNumberLimit := new(big.Int).Lsh(big.NewInt(1), 128) serialNumber, err := rand.Int(rand.Reader, serialNumberLimit) if err != nil { return nil, fmt.Errorf("failed to generate new certificate: %v", err) } return &x509.Certificate{ SerialNumber: serialNumber, Subject: pkix.Name{ CommonName: commonName, }, NotBefore: startTime, NotAfter: endTime, KeyUsage: x509.KeyUsageKeyEncipherment | x509.KeyUsageDigitalSignature, ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageCodeSigning}, BasicConstraintsValid: true, }, nil }
[ "func", "NewCertificate", "(", "commonName", "string", ",", "startTime", ",", "endTime", "time", ".", "Time", ")", "(", "*", "x509", ".", "Certificate", ",", "error", ")", "{", "serialNumberLimit", ":=", "new", "(", "big", ".", "Int", ")", ".", "Lsh", "(", "big", ".", "NewInt", "(", "1", ")", ",", "128", ")", "\n\n", "serialNumber", ",", "err", ":=", "rand", ".", "Int", "(", "rand", ".", "Reader", ",", "serialNumberLimit", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "return", "&", "x509", ".", "Certificate", "{", "SerialNumber", ":", "serialNumber", ",", "Subject", ":", "pkix", ".", "Name", "{", "CommonName", ":", "commonName", ",", "}", ",", "NotBefore", ":", "startTime", ",", "NotAfter", ":", "endTime", ",", "KeyUsage", ":", "x509", ".", "KeyUsageKeyEncipherment", "|", "x509", ".", "KeyUsageDigitalSignature", ",", "ExtKeyUsage", ":", "[", "]", "x509", ".", "ExtKeyUsage", "{", "x509", ".", "ExtKeyUsageCodeSigning", "}", ",", "BasicConstraintsValid", ":", "true", ",", "}", ",", "nil", "\n", "}" ]
// NewCertificate returns an X509 Certificate following a template, given a Common Name and validity interval.
[ "NewCertificate", "returns", "an", "X509", "Certificate", "following", "a", "template", "given", "a", "Common", "Name", "and", "validity", "interval", "." ]
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/tuf/utils/x509.go#L544-L564
train