repo
stringlengths
5
67
path
stringlengths
4
218
func_name
stringlengths
0
151
original_string
stringlengths
52
373k
language
stringclasses
6 values
code
stringlengths
52
373k
code_tokens
listlengths
10
512
docstring
stringlengths
3
47.2k
docstring_tokens
listlengths
3
234
sha
stringlengths
40
40
url
stringlengths
85
339
partition
stringclasses
3 values
tsuru/tsuru
builder/builder.go
GetForProvisioner
func GetForProvisioner(p provision.Provisioner) (Builder, error) { builder, err := get(p.GetName()) if err != nil { if _, ok := p.(provision.BuilderDeployDockerClient); ok { return get("docker") } else if _, ok := p.(provision.BuilderDeployKubeClient); ok { return get("kubernetes") } } return builder, e...
go
func GetForProvisioner(p provision.Provisioner) (Builder, error) { builder, err := get(p.GetName()) if err != nil { if _, ok := p.(provision.BuilderDeployDockerClient); ok { return get("docker") } else if _, ok := p.(provision.BuilderDeployKubeClient); ok { return get("kubernetes") } } return builder, e...
[ "func", "GetForProvisioner", "(", "p", "provision", ".", "Provisioner", ")", "(", "Builder", ",", "error", ")", "{", "builder", ",", "err", ":=", "get", "(", "p", ".", "GetName", "(", ")", ")", "\n", "if", "err", "!=", "nil", "{", "if", "_", ",", ...
// GetForProvisioner gets the builder required by the provisioner.
[ "GetForProvisioner", "gets", "the", "builder", "required", "by", "the", "provisioner", "." ]
2f7fd515c5dc25a58aec80f0e497c49e49581b3e
https://github.com/tsuru/tsuru/blob/2f7fd515c5dc25a58aec80f0e497c49e49581b3e/builder/builder.go#L55-L65
test
tsuru/tsuru
builder/builder.go
get
func get(name string) (Builder, error) { b, ok := builders[name] if !ok { return nil, errors.Errorf("unknown builder: %q", name) } return b, nil }
go
func get(name string) (Builder, error) { b, ok := builders[name] if !ok { return nil, errors.Errorf("unknown builder: %q", name) } return b, nil }
[ "func", "get", "(", "name", "string", ")", "(", "Builder", ",", "error", ")", "{", "b", ",", "ok", ":=", "builders", "[", "name", "]", "\n", "if", "!", "ok", "{", "return", "nil", ",", "errors", ".", "Errorf", "(", "\"unknown builder: %q\"", ",", "...
// get gets the named builder from the registry.
[ "get", "gets", "the", "named", "builder", "from", "the", "registry", "." ]
2f7fd515c5dc25a58aec80f0e497c49e49581b3e
https://github.com/tsuru/tsuru/blob/2f7fd515c5dc25a58aec80f0e497c49e49581b3e/builder/builder.go#L68-L74
test
tsuru/tsuru
builder/builder.go
Registry
func Registry() ([]Builder, error) { registry := make([]Builder, 0, len(builders)) for _, b := range builders { registry = append(registry, b) } return registry, nil }
go
func Registry() ([]Builder, error) { registry := make([]Builder, 0, len(builders)) for _, b := range builders { registry = append(registry, b) } return registry, nil }
[ "func", "Registry", "(", ")", "(", "[", "]", "Builder", ",", "error", ")", "{", "registry", ":=", "make", "(", "[", "]", "Builder", ",", "0", ",", "len", "(", "builders", ")", ")", "\n", "for", "_", ",", "b", ":=", "range", "builders", "{", "re...
// Registry returns the list of registered builders.
[ "Registry", "returns", "the", "list", "of", "registered", "builders", "." ]
2f7fd515c5dc25a58aec80f0e497c49e49581b3e
https://github.com/tsuru/tsuru/blob/2f7fd515c5dc25a58aec80f0e497c49e49581b3e/builder/builder.go#L77-L83
test
tsuru/tsuru
provision/docker/nodecontainer/queue.go
RegisterQueueTask
func RegisterQueueTask(p DockerProvisioner) error { q, err := queue.Queue() if err != nil { return err } return q.RegisterTask(&runBs{provisioner: p}) }
go
func RegisterQueueTask(p DockerProvisioner) error { q, err := queue.Queue() if err != nil { return err } return q.RegisterTask(&runBs{provisioner: p}) }
[ "func", "RegisterQueueTask", "(", "p", "DockerProvisioner", ")", "error", "{", "q", ",", "err", ":=", "queue", ".", "Queue", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", "q", ".", "RegisterTask", "(", "&"...
// RegisterQueueTask registers the internal bs queue task for later execution.
[ "RegisterQueueTask", "registers", "the", "internal", "bs", "queue", "task", "for", "later", "execution", "." ]
2f7fd515c5dc25a58aec80f0e497c49e49581b3e
https://github.com/tsuru/tsuru/blob/2f7fd515c5dc25a58aec80f0e497c49e49581b3e/provision/docker/nodecontainer/queue.go#L20-L26
test
tsuru/tsuru
provision/kubernetes/pkg/client/informers/externalversions/tsuru/v1/interface.go
Apps
func (v *version) Apps() AppInformer { return &appInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} }
go
func (v *version) Apps() AppInformer { return &appInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} }
[ "func", "(", "v", "*", "version", ")", "Apps", "(", ")", "AppInformer", "{", "return", "&", "appInformer", "{", "factory", ":", "v", ".", "factory", ",", "namespace", ":", "v", ".", "namespace", ",", "tweakListOptions", ":", "v", ".", "tweakListOptions",...
// Apps returns a AppInformer.
[ "Apps", "returns", "a", "AppInformer", "." ]
2f7fd515c5dc25a58aec80f0e497c49e49581b3e
https://github.com/tsuru/tsuru/blob/2f7fd515c5dc25a58aec80f0e497c49e49581b3e/provision/kubernetes/pkg/client/informers/externalversions/tsuru/v1/interface.go#L33-L35
test
tsuru/tsuru
provision/kubernetes/pkg/apis/tsuru/v1/zz_generated.deepcopy.go
DeepCopy
func (in *App) DeepCopy() *App { if in == nil { return nil } out := new(App) in.DeepCopyInto(out) return out }
go
func (in *App) DeepCopy() *App { if in == nil { return nil } out := new(App) in.DeepCopyInto(out) return out }
[ "func", "(", "in", "*", "App", ")", "DeepCopy", "(", ")", "*", "App", "{", "if", "in", "==", "nil", "{", "return", "nil", "\n", "}", "\n", "out", ":=", "new", "(", "App", ")", "\n", "in", ".", "DeepCopyInto", "(", "out", ")", "\n", "return", ...
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new App.
[ "DeepCopy", "is", "an", "autogenerated", "deepcopy", "function", "copying", "the", "receiver", "creating", "a", "new", "App", "." ]
2f7fd515c5dc25a58aec80f0e497c49e49581b3e
https://github.com/tsuru/tsuru/blob/2f7fd515c5dc25a58aec80f0e497c49e49581b3e/provision/kubernetes/pkg/apis/tsuru/v1/zz_generated.deepcopy.go#L25-L32
test
tsuru/tsuru
provision/kubernetes/pkg/apis/tsuru/v1/zz_generated.deepcopy.go
DeepCopy
func (in *AppList) DeepCopy() *AppList { if in == nil { return nil } out := new(AppList) in.DeepCopyInto(out) return out }
go
func (in *AppList) DeepCopy() *AppList { if in == nil { return nil } out := new(AppList) in.DeepCopyInto(out) return out }
[ "func", "(", "in", "*", "AppList", ")", "DeepCopy", "(", ")", "*", "AppList", "{", "if", "in", "==", "nil", "{", "return", "nil", "\n", "}", "\n", "out", ":=", "new", "(", "AppList", ")", "\n", "in", ".", "DeepCopyInto", "(", "out", ")", "\n", ...
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AppList.
[ "DeepCopy", "is", "an", "autogenerated", "deepcopy", "function", "copying", "the", "receiver", "creating", "a", "new", "AppList", "." ]
2f7fd515c5dc25a58aec80f0e497c49e49581b3e
https://github.com/tsuru/tsuru/blob/2f7fd515c5dc25a58aec80f0e497c49e49581b3e/provision/kubernetes/pkg/apis/tsuru/v1/zz_generated.deepcopy.go#L58-L65
test
tsuru/tsuru
provision/kubernetes/pkg/apis/tsuru/v1/zz_generated.deepcopy.go
DeepCopy
func (in *AppSpec) DeepCopy() *AppSpec { if in == nil { return nil } out := new(AppSpec) in.DeepCopyInto(out) return out }
go
func (in *AppSpec) DeepCopy() *AppSpec { if in == nil { return nil } out := new(AppSpec) in.DeepCopyInto(out) return out }
[ "func", "(", "in", "*", "AppSpec", ")", "DeepCopy", "(", ")", "*", "AppSpec", "{", "if", "in", "==", "nil", "{", "return", "nil", "\n", "}", "\n", "out", ":=", "new", "(", "AppSpec", ")", "\n", "in", ".", "DeepCopyInto", "(", "out", ")", "\n", ...
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AppSpec.
[ "DeepCopy", "is", "an", "autogenerated", "deepcopy", "function", "copying", "the", "receiver", "creating", "a", "new", "AppSpec", "." ]
2f7fd515c5dc25a58aec80f0e497c49e49581b3e
https://github.com/tsuru/tsuru/blob/2f7fd515c5dc25a58aec80f0e497c49e49581b3e/provision/kubernetes/pkg/apis/tsuru/v1/zz_generated.deepcopy.go#L106-L113
test
tsuru/tsuru
app/writer.go
Write
func (w *LogWriter) Write(data []byte) (int, error) { w.finLk.RLock() defer w.finLk.RUnlock() if w.closed { return len(data), nil } if w.msgCh == nil { return len(data), w.write(data) } copied := make([]byte, len(data)) copy(copied, data) w.msgCh <- copied return len(data), nil }
go
func (w *LogWriter) Write(data []byte) (int, error) { w.finLk.RLock() defer w.finLk.RUnlock() if w.closed { return len(data), nil } if w.msgCh == nil { return len(data), w.write(data) } copied := make([]byte, len(data)) copy(copied, data) w.msgCh <- copied return len(data), nil }
[ "func", "(", "w", "*", "LogWriter", ")", "Write", "(", "data", "[", "]", "byte", ")", "(", "int", ",", "error", ")", "{", "w", ".", "finLk", ".", "RLock", "(", ")", "\n", "defer", "w", ".", "finLk", ".", "RUnlock", "(", ")", "\n", "if", "w", ...
// Write writes and logs the data.
[ "Write", "writes", "and", "logs", "the", "data", "." ]
2f7fd515c5dc25a58aec80f0e497c49e49581b3e
https://github.com/tsuru/tsuru/blob/2f7fd515c5dc25a58aec80f0e497c49e49581b3e/app/writer.go#L64-L77
test
tsuru/tsuru
auth/native/native.go
ResetPassword
func (s NativeScheme) ResetPassword(user *auth.User, resetToken string) error { if resetToken == "" { return auth.ErrInvalidToken } conn, err := db.Conn() if err != nil { return err } defer conn.Close() passToken, err := getPasswordToken(resetToken) if err != nil { return err } if passToken.UserEmail !=...
go
func (s NativeScheme) ResetPassword(user *auth.User, resetToken string) error { if resetToken == "" { return auth.ErrInvalidToken } conn, err := db.Conn() if err != nil { return err } defer conn.Close() passToken, err := getPasswordToken(resetToken) if err != nil { return err } if passToken.UserEmail !=...
[ "func", "(", "s", "NativeScheme", ")", "ResetPassword", "(", "user", "*", "auth", ".", "User", ",", "resetToken", "string", ")", "error", "{", "if", "resetToken", "==", "\"\"", "{", "return", "auth", ".", "ErrInvalidToken", "\n", "}", "\n", "conn", ",", ...
// ResetPassword actually resets the password of the user. It needs the token // string. The new password will be a random string, that will be then sent to // the user email.
[ "ResetPassword", "actually", "resets", "the", "password", "of", "the", "user", ".", "It", "needs", "the", "token", "string", ".", "The", "new", "password", "will", "be", "a", "random", "string", "that", "will", "be", "then", "sent", "to", "the", "user", ...
2f7fd515c5dc25a58aec80f0e497c49e49581b3e
https://github.com/tsuru/tsuru/blob/2f7fd515c5dc25a58aec80f0e497c49e49581b3e/auth/native/native.go#L112-L135
test
tsuru/tsuru
provision/kubernetes/pkg/apis/tsuru/v1/register.go
addKnownTypes
func addKnownTypes(scheme *runtime.Scheme) error { scheme.AddKnownTypes(SchemeGroupVersion, &App{}, &AppList{}, ) scheme.AddKnownTypes(SchemeGroupVersion, &metav1.Status{}, ) metav1.AddToGroupVersion(scheme, SchemeGroupVersion) return nil }
go
func addKnownTypes(scheme *runtime.Scheme) error { scheme.AddKnownTypes(SchemeGroupVersion, &App{}, &AppList{}, ) scheme.AddKnownTypes(SchemeGroupVersion, &metav1.Status{}, ) metav1.AddToGroupVersion(scheme, SchemeGroupVersion) return nil }
[ "func", "addKnownTypes", "(", "scheme", "*", "runtime", ".", "Scheme", ")", "error", "{", "scheme", ".", "AddKnownTypes", "(", "SchemeGroupVersion", ",", "&", "App", "{", "}", ",", "&", "AppList", "{", "}", ",", ")", "\n", "scheme", ".", "AddKnownTypes",...
// Adds the list of known types to the given scheme.
[ "Adds", "the", "list", "of", "known", "types", "to", "the", "given", "scheme", "." ]
2f7fd515c5dc25a58aec80f0e497c49e49581b3e
https://github.com/tsuru/tsuru/blob/2f7fd515c5dc25a58aec80f0e497c49e49581b3e/provision/kubernetes/pkg/apis/tsuru/v1/register.go#L34-L45
test
tsuru/tsuru
api/shutdown/shutdown.go
Register
func Register(s Shutdownable) { lock.Lock() defer lock.Unlock() registered = append(registered, s) }
go
func Register(s Shutdownable) { lock.Lock() defer lock.Unlock() registered = append(registered, s) }
[ "func", "Register", "(", "s", "Shutdownable", ")", "{", "lock", ".", "Lock", "(", ")", "\n", "defer", "lock", ".", "Unlock", "(", ")", "\n", "registered", "=", "append", "(", "registered", ",", "s", ")", "\n", "}" ]
// Register registers an item as shutdownable
[ "Register", "registers", "an", "item", "as", "shutdownable" ]
2f7fd515c5dc25a58aec80f0e497c49e49581b3e
https://github.com/tsuru/tsuru/blob/2f7fd515c5dc25a58aec80f0e497c49e49581b3e/api/shutdown/shutdown.go#L26-L30
test
tsuru/tsuru
api/shutdown/shutdown.go
Do
func Do(ctx context.Context, w io.Writer) error { lock.Lock() defer lock.Unlock() done := make(chan bool) wg := sync.WaitGroup{} for _, h := range registered { wg.Add(1) go func(h Shutdownable) { defer wg.Done() var name string if _, ok := h.(fmt.Stringer); ok { name = fmt.Sprintf("%s", h) } el...
go
func Do(ctx context.Context, w io.Writer) error { lock.Lock() defer lock.Unlock() done := make(chan bool) wg := sync.WaitGroup{} for _, h := range registered { wg.Add(1) go func(h Shutdownable) { defer wg.Done() var name string if _, ok := h.(fmt.Stringer); ok { name = fmt.Sprintf("%s", h) } el...
[ "func", "Do", "(", "ctx", "context", ".", "Context", ",", "w", "io", ".", "Writer", ")", "error", "{", "lock", ".", "Lock", "(", ")", "\n", "defer", "lock", ".", "Unlock", "(", ")", "\n", "done", ":=", "make", "(", "chan", "bool", ")", "\n", "w...
// Do shutdowns All registered Shutdownable items
[ "Do", "shutdowns", "All", "registered", "Shutdownable", "items" ]
2f7fd515c5dc25a58aec80f0e497c49e49581b3e
https://github.com/tsuru/tsuru/blob/2f7fd515c5dc25a58aec80f0e497c49e49581b3e/api/shutdown/shutdown.go#L33-L67
test
tsuru/tsuru
app/image/platform.go
ListImagesOrDefault
func (s *platformImageService) ListImagesOrDefault(platformName string) ([]string, error) { imgs, err := s.ListImages(platformName) if err != nil && err == imageTypes.ErrPlatformImageNotFound { return []string{platformBasicImageName(platformName)}, nil } return imgs, err }
go
func (s *platformImageService) ListImagesOrDefault(platformName string) ([]string, error) { imgs, err := s.ListImages(platformName) if err != nil && err == imageTypes.ErrPlatformImageNotFound { return []string{platformBasicImageName(platformName)}, nil } return imgs, err }
[ "func", "(", "s", "*", "platformImageService", ")", "ListImagesOrDefault", "(", "platformName", "string", ")", "(", "[", "]", "string", ",", "error", ")", "{", "imgs", ",", "err", ":=", "s", ".", "ListImages", "(", "platformName", ")", "\n", "if", "err",...
// PlatformListImagesOrDefault returns basicImageName when platform is empty // for backwards compatibility
[ "PlatformListImagesOrDefault", "returns", "basicImageName", "when", "platform", "is", "empty", "for", "backwards", "compatibility" ]
2f7fd515c5dc25a58aec80f0e497c49e49581b3e
https://github.com/tsuru/tsuru/blob/2f7fd515c5dc25a58aec80f0e497c49e49581b3e/app/image/platform.go#L81-L87
test
tsuru/tsuru
provision/kubernetes/migrate/migrate.go
MigrateAppsCRDs
func MigrateAppsCRDs() error { config.Set("kubernetes:use-pool-namespaces", false) defer config.Unset("kubernetes:use-pool-namespaces") prov := kubernetes.GetProvisioner() pools, err := pool.ListAllPools() if err != nil { return errors.Wrap(err, "failed to list pools") } var kubePools []string for _, p := ran...
go
func MigrateAppsCRDs() error { config.Set("kubernetes:use-pool-namespaces", false) defer config.Unset("kubernetes:use-pool-namespaces") prov := kubernetes.GetProvisioner() pools, err := pool.ListAllPools() if err != nil { return errors.Wrap(err, "failed to list pools") } var kubePools []string for _, p := ran...
[ "func", "MigrateAppsCRDs", "(", ")", "error", "{", "config", ".", "Set", "(", "\"kubernetes:use-pool-namespaces\"", ",", "false", ")", "\n", "defer", "config", ".", "Unset", "(", "\"kubernetes:use-pool-namespaces\"", ")", "\n", "prov", ":=", "kubernetes", ".", "...
// MigrateAppsCRDs creates the necessary CRDs for every application // on a Kubernetes cluster. This is done by re-provisioning the App // on the cluster.
[ "MigrateAppsCRDs", "creates", "the", "necessary", "CRDs", "for", "every", "application", "on", "a", "Kubernetes", "cluster", ".", "This", "is", "done", "by", "re", "-", "provisioning", "the", "App", "on", "the", "cluster", "." ]
2f7fd515c5dc25a58aec80f0e497c49e49581b3e
https://github.com/tsuru/tsuru/blob/2f7fd515c5dc25a58aec80f0e497c49e49581b3e/provision/kubernetes/migrate/migrate.go#L15-L41
test
tsuru/tsuru
migration/migration.go
Register
func Register(name string, fn MigrateFunc) error { return register(name, false, fn) }
go
func Register(name string, fn MigrateFunc) error { return register(name, false, fn) }
[ "func", "Register", "(", "name", "string", ",", "fn", "MigrateFunc", ")", "error", "{", "return", "register", "(", "name", ",", "false", ",", "fn", ")", "\n", "}" ]
// Register register a new migration for later execution with the Run // functions.
[ "Register", "register", "a", "new", "migration", "for", "later", "execution", "with", "the", "Run", "functions", "." ]
2f7fd515c5dc25a58aec80f0e497c49e49581b3e
https://github.com/tsuru/tsuru/blob/2f7fd515c5dc25a58aec80f0e497c49e49581b3e/migration/migration.go#L65-L67
test
tsuru/tsuru
migration/migration.go
RegisterOptional
func RegisterOptional(name string, fn MigrateFunc) error { return register(name, true, fn) }
go
func RegisterOptional(name string, fn MigrateFunc) error { return register(name, true, fn) }
[ "func", "RegisterOptional", "(", "name", "string", ",", "fn", "MigrateFunc", ")", "error", "{", "return", "register", "(", "name", ",", "true", ",", "fn", ")", "\n", "}" ]
// RegisterOptional register a new migration that will not run automatically // when calling the Run funcition.
[ "RegisterOptional", "register", "a", "new", "migration", "that", "will", "not", "run", "automatically", "when", "calling", "the", "Run", "funcition", "." ]
2f7fd515c5dc25a58aec80f0e497c49e49581b3e
https://github.com/tsuru/tsuru/blob/2f7fd515c5dc25a58aec80f0e497c49e49581b3e/migration/migration.go#L71-L73
test
tsuru/tsuru
migration/migration.go
Run
func Run(args RunArgs) error { if args.Name != "" { return runOptional(args) } if args.Force { return ErrCannotForceMandatory } return run(args) }
go
func Run(args RunArgs) error { if args.Name != "" { return runOptional(args) } if args.Force { return ErrCannotForceMandatory } return run(args) }
[ "func", "Run", "(", "args", "RunArgs", ")", "error", "{", "if", "args", ".", "Name", "!=", "\"\"", "{", "return", "runOptional", "(", "args", ")", "\n", "}", "\n", "if", "args", ".", "Force", "{", "return", "ErrCannotForceMandatory", "\n", "}", "\n", ...
// Run runs all registered non optional migrations if no ".Name" is informed. // Migrations are executed in the order that they were registered. If ".Name" // is informed, an optional migration with the given name is executed.
[ "Run", "runs", "all", "registered", "non", "optional", "migrations", "if", "no", ".", "Name", "is", "informed", ".", "Migrations", "are", "executed", "in", "the", "order", "that", "they", "were", "registered", ".", "If", ".", "Name", "is", "informed", "an"...
2f7fd515c5dc25a58aec80f0e497c49e49581b3e
https://github.com/tsuru/tsuru/blob/2f7fd515c5dc25a58aec80f0e497c49e49581b3e/migration/migration.go#L88-L96
test
tsuru/tsuru
app/app.go
Units
func (app *App) Units() ([]provision.Unit, error) { prov, err := app.getProvisioner() if err != nil { return []provision.Unit{}, err } units, err := prov.Units(app) if units == nil { // This is unusual but was done because previously this method didn't // return an error. This ensures we always return an emp...
go
func (app *App) Units() ([]provision.Unit, error) { prov, err := app.getProvisioner() if err != nil { return []provision.Unit{}, err } units, err := prov.Units(app) if units == nil { // This is unusual but was done because previously this method didn't // return an error. This ensures we always return an emp...
[ "func", "(", "app", "*", "App", ")", "Units", "(", ")", "(", "[", "]", "provision", ".", "Unit", ",", "error", ")", "{", "prov", ",", "err", ":=", "app", ".", "getProvisioner", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "[", "]", ...
// Units returns the list of units.
[ "Units", "returns", "the", "list", "of", "units", "." ]
2f7fd515c5dc25a58aec80f0e497c49e49581b3e
https://github.com/tsuru/tsuru/blob/2f7fd515c5dc25a58aec80f0e497c49e49581b3e/app/app.go#L181-L194
test
tsuru/tsuru
app/app.go
MarshalJSON
func (app *App) MarshalJSON() ([]byte, error) { repo, _ := repository.Manager().GetRepository(app.Name) result := make(map[string]interface{}) result["name"] = app.Name result["platform"] = app.Platform if version := app.GetPlatformVersion(); version != "latest" { result["platform"] = fmt.Sprintf("%s:%s", app.Pl...
go
func (app *App) MarshalJSON() ([]byte, error) { repo, _ := repository.Manager().GetRepository(app.Name) result := make(map[string]interface{}) result["name"] = app.Name result["platform"] = app.Platform if version := app.GetPlatformVersion(); version != "latest" { result["platform"] = fmt.Sprintf("%s:%s", app.Pl...
[ "func", "(", "app", "*", "App", ")", "MarshalJSON", "(", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "repo", ",", "_", ":=", "repository", ".", "Manager", "(", ")", ".", "GetRepository", "(", "app", ".", "Name", ")", "\n", "result", ":=",...
// MarshalJSON marshals the app in json format.
[ "MarshalJSON", "marshals", "the", "app", "in", "json", "format", "." ]
2f7fd515c5dc25a58aec80f0e497c49e49581b3e
https://github.com/tsuru/tsuru/blob/2f7fd515c5dc25a58aec80f0e497c49e49581b3e/app/app.go#L197-L243
test
tsuru/tsuru
app/app.go
AcquireApplicationLockWait
func AcquireApplicationLockWait(appName string, owner string, reason string, timeout time.Duration) (bool, error) { timeoutChan := time.After(timeout) for { appLock := appTypes.AppLock{ Locked: true, Reason: reason, Owner: owner, AcquireDate: time.Now().In(time.UTC), } conn, err := d...
go
func AcquireApplicationLockWait(appName string, owner string, reason string, timeout time.Duration) (bool, error) { timeoutChan := time.After(timeout) for { appLock := appTypes.AppLock{ Locked: true, Reason: reason, Owner: owner, AcquireDate: time.Now().In(time.UTC), } conn, err := d...
[ "func", "AcquireApplicationLockWait", "(", "appName", "string", ",", "owner", "string", ",", "reason", "string", ",", "timeout", "time", ".", "Duration", ")", "(", "bool", ",", "error", ")", "{", "timeoutChan", ":=", "time", ".", "After", "(", "timeout", "...
// Same as AcquireApplicationLock but it keeps trying to acquire the lock // until timeout is reached.
[ "Same", "as", "AcquireApplicationLock", "but", "it", "keeps", "trying", "to", "acquire", "the", "lock", "until", "timeout", "is", "reached", "." ]
2f7fd515c5dc25a58aec80f0e497c49e49581b3e
https://github.com/tsuru/tsuru/blob/2f7fd515c5dc25a58aec80f0e497c49e49581b3e/app/app.go#L264-L291
test
tsuru/tsuru
app/app.go
ReleaseApplicationLock
func ReleaseApplicationLock(appName string) { var err error retries := 3 for i := 0; i < retries; i++ { err = releaseApplicationLockOnce(appName) if err == nil { return } time.Sleep(time.Second * time.Duration(i+1)) } log.Error(err) }
go
func ReleaseApplicationLock(appName string) { var err error retries := 3 for i := 0; i < retries; i++ { err = releaseApplicationLockOnce(appName) if err == nil { return } time.Sleep(time.Second * time.Duration(i+1)) } log.Error(err) }
[ "func", "ReleaseApplicationLock", "(", "appName", "string", ")", "{", "var", "err", "error", "\n", "retries", ":=", "3", "\n", "for", "i", ":=", "0", ";", "i", "<", "retries", ";", "i", "++", "{", "err", "=", "releaseApplicationLockOnce", "(", "appName",...
// ReleaseApplicationLock releases a lock hold on an app, currently it's called // by a middleware, however, ideally, it should be called individually by each // handler since they might be doing operations in background.
[ "ReleaseApplicationLock", "releases", "a", "lock", "hold", "on", "an", "app", "currently", "it", "s", "called", "by", "a", "middleware", "however", "ideally", "it", "should", "be", "called", "individually", "by", "each", "handler", "since", "they", "might", "b...
2f7fd515c5dc25a58aec80f0e497c49e49581b3e
https://github.com/tsuru/tsuru/blob/2f7fd515c5dc25a58aec80f0e497c49e49581b3e/app/app.go#L335-L346
test
tsuru/tsuru
app/app.go
GetByName
func GetByName(name string) (*App, error) { var app App conn, err := db.Conn() if err != nil { return nil, err } defer conn.Close() err = conn.Apps().Find(bson.M{"name": name}).One(&app) if err == mgo.ErrNotFound { return nil, appTypes.ErrAppNotFound } return &app, err }
go
func GetByName(name string) (*App, error) { var app App conn, err := db.Conn() if err != nil { return nil, err } defer conn.Close() err = conn.Apps().Find(bson.M{"name": name}).One(&app) if err == mgo.ErrNotFound { return nil, appTypes.ErrAppNotFound } return &app, err }
[ "func", "GetByName", "(", "name", "string", ")", "(", "*", "App", ",", "error", ")", "{", "var", "app", "App", "\n", "conn", ",", "err", ":=", "db", ".", "Conn", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", ...
// GetByName queries the database to find an app identified by the given // name.
[ "GetByName", "queries", "the", "database", "to", "find", "an", "app", "identified", "by", "the", "given", "name", "." ]
2f7fd515c5dc25a58aec80f0e497c49e49581b3e
https://github.com/tsuru/tsuru/blob/2f7fd515c5dc25a58aec80f0e497c49e49581b3e/app/app.go#L363-L375
test
tsuru/tsuru
app/app.go
AddUnits
func (app *App) AddUnits(n uint, process string, w io.Writer) error { if n == 0 { return errors.New("Cannot add zero units.") } units, err := app.Units() if err != nil { return err } for _, u := range units { if (u.Status == provision.StatusAsleep) || (u.Status == provision.StatusStopped) { return errors...
go
func (app *App) AddUnits(n uint, process string, w io.Writer) error { if n == 0 { return errors.New("Cannot add zero units.") } units, err := app.Units() if err != nil { return err } for _, u := range units { if (u.Status == provision.StatusAsleep) || (u.Status == provision.StatusStopped) { return errors...
[ "func", "(", "app", "*", "App", ")", "AddUnits", "(", "n", "uint", ",", "process", "string", ",", "w", "io", ".", "Writer", ")", "error", "{", "if", "n", "==", "0", "{", "return", "errors", ".", "New", "(", "\"Cannot add zero units.\"", ")", "\n", ...
// AddUnits creates n new units within the provisioner, saves new units in the // database and enqueues the apprc serialization.
[ "AddUnits", "creates", "n", "new", "units", "within", "the", "provisioner", "saves", "new", "units", "in", "the", "database", "and", "enqueues", "the", "apprc", "serialization", "." ]
2f7fd515c5dc25a58aec80f0e497c49e49581b3e
https://github.com/tsuru/tsuru/blob/2f7fd515c5dc25a58aec80f0e497c49e49581b3e/app/app.go#L823-L847
test
tsuru/tsuru
app/app.go
SetUnitStatus
func (app *App) SetUnitStatus(unitName string, status provision.Status) error { units, err := app.Units() if err != nil { return err } for _, unit := range units { if strings.HasPrefix(unit.ID, unitName) { prov, err := app.getProvisioner() if err != nil { return err } unitProv, ok := prov.(provi...
go
func (app *App) SetUnitStatus(unitName string, status provision.Status) error { units, err := app.Units() if err != nil { return err } for _, unit := range units { if strings.HasPrefix(unit.ID, unitName) { prov, err := app.getProvisioner() if err != nil { return err } unitProv, ok := prov.(provi...
[ "func", "(", "app", "*", "App", ")", "SetUnitStatus", "(", "unitName", "string", ",", "status", "provision", ".", "Status", ")", "error", "{", "units", ",", "err", ":=", "app", ".", "Units", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", ...
// SetUnitStatus changes the status of the given unit.
[ "SetUnitStatus", "changes", "the", "status", "of", "the", "given", "unit", "." ]
2f7fd515c5dc25a58aec80f0e497c49e49581b3e
https://github.com/tsuru/tsuru/blob/2f7fd515c5dc25a58aec80f0e497c49e49581b3e/app/app.go#L886-L905
test
tsuru/tsuru
app/app.go
UpdateNodeStatus
func UpdateNodeStatus(nodeData provision.NodeStatusData) ([]UpdateUnitsResult, error) { node, findNodeErr := findNodeForNodeData(nodeData) var nodeAddresses []string if findNodeErr == nil { nodeAddresses = []string{node.Address()} } else { nodeAddresses = nodeData.Addrs } if healer.HealerInstance != nil { e...
go
func UpdateNodeStatus(nodeData provision.NodeStatusData) ([]UpdateUnitsResult, error) { node, findNodeErr := findNodeForNodeData(nodeData) var nodeAddresses []string if findNodeErr == nil { nodeAddresses = []string{node.Address()} } else { nodeAddresses = nodeData.Addrs } if healer.HealerInstance != nil { e...
[ "func", "UpdateNodeStatus", "(", "nodeData", "provision", ".", "NodeStatusData", ")", "(", "[", "]", "UpdateUnitsResult", ",", "error", ")", "{", "node", ",", "findNodeErr", ":=", "findNodeForNodeData", "(", "nodeData", ")", "\n", "var", "nodeAddresses", "[", ...
// UpdateNodeStatus updates the status of the given node and its units, // returning a map which units were found during the update.
[ "UpdateNodeStatus", "updates", "the", "status", "of", "the", "given", "node", "and", "its", "units", "returning", "a", "map", "which", "units", "were", "found", "during", "the", "update", "." ]
2f7fd515c5dc25a58aec80f0e497c49e49581b3e
https://github.com/tsuru/tsuru/blob/2f7fd515c5dc25a58aec80f0e497c49e49581b3e/app/app.go#L942-L983
test
tsuru/tsuru
app/app.go
available
func (app *App) available() bool { units, err := app.Units() if err != nil { return false } for _, unit := range units { if unit.Available() { return true } } return false }
go
func (app *App) available() bool { units, err := app.Units() if err != nil { return false } for _, unit := range units { if unit.Available() { return true } } return false }
[ "func", "(", "app", "*", "App", ")", "available", "(", ")", "bool", "{", "units", ",", "err", ":=", "app", ".", "Units", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "false", "\n", "}", "\n", "for", "_", ",", "unit", ":=", "range", ...
// available returns true if at least one of N units is started or unreachable.
[ "available", "returns", "true", "if", "at", "least", "one", "of", "N", "units", "is", "started", "or", "unreachable", "." ]
2f7fd515c5dc25a58aec80f0e497c49e49581b3e
https://github.com/tsuru/tsuru/blob/2f7fd515c5dc25a58aec80f0e497c49e49581b3e/app/app.go#L986-L997
test
tsuru/tsuru
app/app.go
Grant
func (app *App) Grant(team *authTypes.Team) error { if _, found := app.findTeam(team); found { return ErrAlreadyHaveAccess } app.Teams = append(app.Teams, team.Name) conn, err := db.Conn() if err != nil { return err } defer conn.Close() err = conn.Apps().Update(bson.M{"name": app.Name}, bson.M{"$addToSet": ...
go
func (app *App) Grant(team *authTypes.Team) error { if _, found := app.findTeam(team); found { return ErrAlreadyHaveAccess } app.Teams = append(app.Teams, team.Name) conn, err := db.Conn() if err != nil { return err } defer conn.Close() err = conn.Apps().Update(bson.M{"name": app.Name}, bson.M{"$addToSet": ...
[ "func", "(", "app", "*", "App", ")", "Grant", "(", "team", "*", "authTypes", ".", "Team", ")", "error", "{", "if", "_", ",", "found", ":=", "app", ".", "findTeam", "(", "team", ")", ";", "found", "{", "return", "ErrAlreadyHaveAccess", "\n", "}", "\...
// Grant allows a team to have access to an app. It returns an error if the // team already have access to the app.
[ "Grant", "allows", "a", "team", "to", "have", "access", "to", "an", "app", ".", "It", "returns", "an", "error", "if", "the", "team", "already", "have", "access", "to", "the", "app", "." ]
2f7fd515c5dc25a58aec80f0e497c49e49581b3e
https://github.com/tsuru/tsuru/blob/2f7fd515c5dc25a58aec80f0e497c49e49581b3e/app/app.go#L1010-L1040
test
tsuru/tsuru
app/app.go
Revoke
func (app *App) Revoke(team *authTypes.Team) error { if len(app.Teams) == 1 { return ErrCannotOrphanApp } index, found := app.findTeam(team) if !found { return ErrNoAccess } last := len(app.Teams) - 1 app.Teams[index] = app.Teams[last] app.Teams = app.Teams[:last] conn, err := db.Conn() if err != nil { ...
go
func (app *App) Revoke(team *authTypes.Team) error { if len(app.Teams) == 1 { return ErrCannotOrphanApp } index, found := app.findTeam(team) if !found { return ErrNoAccess } last := len(app.Teams) - 1 app.Teams[index] = app.Teams[last] app.Teams = app.Teams[:last] conn, err := db.Conn() if err != nil { ...
[ "func", "(", "app", "*", "App", ")", "Revoke", "(", "team", "*", "authTypes", ".", "Team", ")", "error", "{", "if", "len", "(", "app", ".", "Teams", ")", "==", "1", "{", "return", "ErrCannotOrphanApp", "\n", "}", "\n", "index", ",", "found", ":=", ...
// Revoke removes the access from a team. It returns an error if the team do // not have access to the app.
[ "Revoke", "removes", "the", "access", "from", "a", "team", ".", "It", "returns", "an", "error", "if", "the", "team", "do", "not", "have", "access", "to", "the", "app", "." ]
2f7fd515c5dc25a58aec80f0e497c49e49581b3e
https://github.com/tsuru/tsuru/blob/2f7fd515c5dc25a58aec80f0e497c49e49581b3e/app/app.go#L1044-L1094
test
tsuru/tsuru
app/app.go
GetTeams
func (app *App) GetTeams() []authTypes.Team { t, _ := servicemanager.Team.FindByNames(app.Teams) return t }
go
func (app *App) GetTeams() []authTypes.Team { t, _ := servicemanager.Team.FindByNames(app.Teams) return t }
[ "func", "(", "app", "*", "App", ")", "GetTeams", "(", ")", "[", "]", "authTypes", ".", "Team", "{", "t", ",", "_", ":=", "servicemanager", ".", "Team", ".", "FindByNames", "(", "app", ".", "Teams", ")", "\n", "return", "t", "\n", "}" ]
// GetTeams returns a slice of teams that have access to the app.
[ "GetTeams", "returns", "a", "slice", "of", "teams", "that", "have", "access", "to", "the", "app", "." ]
2f7fd515c5dc25a58aec80f0e497c49e49581b3e
https://github.com/tsuru/tsuru/blob/2f7fd515c5dc25a58aec80f0e497c49e49581b3e/app/app.go#L1097-L1100
test
tsuru/tsuru
app/app.go
setEnv
func (app *App) setEnv(env bind.EnvVar) { if app.Env == nil { app.Env = make(map[string]bind.EnvVar) } app.Env[env.Name] = env if env.Public { app.Log(fmt.Sprintf("setting env %s with value %s", env.Name, env.Value), "tsuru", "api") } }
go
func (app *App) setEnv(env bind.EnvVar) { if app.Env == nil { app.Env = make(map[string]bind.EnvVar) } app.Env[env.Name] = env if env.Public { app.Log(fmt.Sprintf("setting env %s with value %s", env.Name, env.Value), "tsuru", "api") } }
[ "func", "(", "app", "*", "App", ")", "setEnv", "(", "env", "bind", ".", "EnvVar", ")", "{", "if", "app", ".", "Env", "==", "nil", "{", "app", ".", "Env", "=", "make", "(", "map", "[", "string", "]", "bind", ".", "EnvVar", ")", "\n", "}", "\n"...
// setEnv sets the given environment variable in the app.
[ "setEnv", "sets", "the", "given", "environment", "variable", "in", "the", "app", "." ]
2f7fd515c5dc25a58aec80f0e497c49e49581b3e
https://github.com/tsuru/tsuru/blob/2f7fd515c5dc25a58aec80f0e497c49e49581b3e/app/app.go#L1153-L1161
test
tsuru/tsuru
app/app.go
getEnv
func (app *App) getEnv(name string) (bind.EnvVar, error) { if env, ok := app.Env[name]; ok { return env, nil } return bind.EnvVar{}, errors.New("Environment variable not declared for this app.") }
go
func (app *App) getEnv(name string) (bind.EnvVar, error) { if env, ok := app.Env[name]; ok { return env, nil } return bind.EnvVar{}, errors.New("Environment variable not declared for this app.") }
[ "func", "(", "app", "*", "App", ")", "getEnv", "(", "name", "string", ")", "(", "bind", ".", "EnvVar", ",", "error", ")", "{", "if", "env", ",", "ok", ":=", "app", ".", "Env", "[", "name", "]", ";", "ok", "{", "return", "env", ",", "nil", "\n...
// getEnv returns the environment variable if it's declared in the app. It will // return an error if the variable is not defined in this app.
[ "getEnv", "returns", "the", "environment", "variable", "if", "it", "s", "declared", "in", "the", "app", ".", "It", "will", "return", "an", "error", "if", "the", "variable", "is", "not", "defined", "in", "this", "app", "." ]
2f7fd515c5dc25a58aec80f0e497c49e49581b3e
https://github.com/tsuru/tsuru/blob/2f7fd515c5dc25a58aec80f0e497c49e49581b3e/app/app.go#L1165-L1170
test
tsuru/tsuru
app/app.go
validateNew
func (app *App) validateNew() error { if app.Name == InternalAppName || !validation.ValidateName(app.Name) { msg := "Invalid app name, your app should have at most 40 " + "characters, containing only lower case letters, numbers or dashes, " + "starting with a letter." return &tsuruErrors.ValidationError{Mess...
go
func (app *App) validateNew() error { if app.Name == InternalAppName || !validation.ValidateName(app.Name) { msg := "Invalid app name, your app should have at most 40 " + "characters, containing only lower case letters, numbers or dashes, " + "starting with a letter." return &tsuruErrors.ValidationError{Mess...
[ "func", "(", "app", "*", "App", ")", "validateNew", "(", ")", "error", "{", "if", "app", ".", "Name", "==", "InternalAppName", "||", "!", "validation", ".", "ValidateName", "(", "app", ".", "Name", ")", "{", "msg", ":=", "\"Invalid app name, your app shoul...
// validateNew checks app name format, pool and plan
[ "validateNew", "checks", "app", "name", "format", "pool", "and", "plan" ]
2f7fd515c5dc25a58aec80f0e497c49e49581b3e
https://github.com/tsuru/tsuru/blob/2f7fd515c5dc25a58aec80f0e497c49e49581b3e/app/app.go#L1173-L1181
test
tsuru/tsuru
app/app.go
validate
func (app *App) validate() error { err := app.validatePool() if err != nil { return err } return app.validatePlan() }
go
func (app *App) validate() error { err := app.validatePool() if err != nil { return err } return app.validatePlan() }
[ "func", "(", "app", "*", "App", ")", "validate", "(", ")", "error", "{", "err", ":=", "app", ".", "validatePool", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", "app", ".", "validatePlan", "(", ")", "\n...
// validate checks app pool and plan
[ "validate", "checks", "app", "pool", "and", "plan" ]
2f7fd515c5dc25a58aec80f0e497c49e49581b3e
https://github.com/tsuru/tsuru/blob/2f7fd515c5dc25a58aec80f0e497c49e49581b3e/app/app.go#L1184-L1190
test
tsuru/tsuru
app/app.go
InstanceEnvs
func (app *App) InstanceEnvs(serviceName, instanceName string) map[string]bind.EnvVar { envs := make(map[string]bind.EnvVar) for _, env := range app.ServiceEnvs { if env.ServiceName == serviceName && env.InstanceName == instanceName { envs[env.Name] = env.EnvVar } } return envs }
go
func (app *App) InstanceEnvs(serviceName, instanceName string) map[string]bind.EnvVar { envs := make(map[string]bind.EnvVar) for _, env := range app.ServiceEnvs { if env.ServiceName == serviceName && env.InstanceName == instanceName { envs[env.Name] = env.EnvVar } } return envs }
[ "func", "(", "app", "*", "App", ")", "InstanceEnvs", "(", "serviceName", ",", "instanceName", "string", ")", "map", "[", "string", "]", "bind", ".", "EnvVar", "{", "envs", ":=", "make", "(", "map", "[", "string", "]", "bind", ".", "EnvVar", ")", "\n"...
// InstanceEnvs returns a map of environment variables that belongs to the // given service and service instance.
[ "InstanceEnvs", "returns", "a", "map", "of", "environment", "variables", "that", "belongs", "to", "the", "given", "service", "and", "service", "instance", "." ]
2f7fd515c5dc25a58aec80f0e497c49e49581b3e
https://github.com/tsuru/tsuru/blob/2f7fd515c5dc25a58aec80f0e497c49e49581b3e/app/app.go#L1282-L1290
test
tsuru/tsuru
app/app.go
Run
func (app *App) Run(cmd string, w io.Writer, args provision.RunArgs) error { if !args.Isolated && !app.available() { return errors.New("App must be available to run non-isolated commands") } app.Log(fmt.Sprintf("running '%s'", cmd), "tsuru", "api") logWriter := LogWriter{App: app, Source: "app-run"} logWriter.As...
go
func (app *App) Run(cmd string, w io.Writer, args provision.RunArgs) error { if !args.Isolated && !app.available() { return errors.New("App must be available to run non-isolated commands") } app.Log(fmt.Sprintf("running '%s'", cmd), "tsuru", "api") logWriter := LogWriter{App: app, Source: "app-run"} logWriter.As...
[ "func", "(", "app", "*", "App", ")", "Run", "(", "cmd", "string", ",", "w", "io", ".", "Writer", ",", "args", "provision", ".", "RunArgs", ")", "error", "{", "if", "!", "args", ".", "Isolated", "&&", "!", "app", ".", "available", "(", ")", "{", ...
// Run executes the command in app units, sourcing apprc before running the // command.
[ "Run", "executes", "the", "command", "in", "app", "units", "sourcing", "apprc", "before", "running", "the", "command", "." ]
2f7fd515c5dc25a58aec80f0e497c49e49581b3e
https://github.com/tsuru/tsuru/blob/2f7fd515c5dc25a58aec80f0e497c49e49581b3e/app/app.go#L1294-L1303
test
tsuru/tsuru
app/app.go
GetUnits
func (app *App) GetUnits() ([]bind.Unit, error) { provUnits, err := app.Units() if err != nil { return nil, err } units := make([]bind.Unit, len(provUnits)) for i := range provUnits { units[i] = &provUnits[i] } return units, nil }
go
func (app *App) GetUnits() ([]bind.Unit, error) { provUnits, err := app.Units() if err != nil { return nil, err } units := make([]bind.Unit, len(provUnits)) for i := range provUnits { units[i] = &provUnits[i] } return units, nil }
[ "func", "(", "app", "*", "App", ")", "GetUnits", "(", ")", "(", "[", "]", "bind", ".", "Unit", ",", "error", ")", "{", "provUnits", ",", "err", ":=", "app", ".", "Units", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "e...
// GetUnits returns the internal list of units converted to bind.Unit.
[ "GetUnits", "returns", "the", "internal", "list", "of", "units", "converted", "to", "bind", ".", "Unit", "." ]
2f7fd515c5dc25a58aec80f0e497c49e49581b3e
https://github.com/tsuru/tsuru/blob/2f7fd515c5dc25a58aec80f0e497c49e49581b3e/app/app.go#L1431-L1441
test
tsuru/tsuru
app/app.go
GetUUID
func (app *App) GetUUID() (string, error) { if app.UUID != "" { return app.UUID, nil } uuidV4, err := uuid.NewV4() if err != nil { return "", errors.WithMessage(err, "failed to generate uuid v4") } conn, err := db.Conn() if err != nil { return "", err } defer conn.Close() err = conn.Apps().Update(bson.M...
go
func (app *App) GetUUID() (string, error) { if app.UUID != "" { return app.UUID, nil } uuidV4, err := uuid.NewV4() if err != nil { return "", errors.WithMessage(err, "failed to generate uuid v4") } conn, err := db.Conn() if err != nil { return "", err } defer conn.Close() err = conn.Apps().Update(bson.M...
[ "func", "(", "app", "*", "App", ")", "GetUUID", "(", ")", "(", "string", ",", "error", ")", "{", "if", "app", ".", "UUID", "!=", "\"\"", "{", "return", "app", ".", "UUID", ",", "nil", "\n", "}", "\n", "uuidV4", ",", "err", ":=", "uuid", ".", ...
// GetUUID returns the app v4 UUID. An UUID will be generated // if it does not exist.
[ "GetUUID", "returns", "the", "app", "v4", "UUID", ".", "An", "UUID", "will", "be", "generated", "if", "it", "does", "not", "exist", "." ]
2f7fd515c5dc25a58aec80f0e497c49e49581b3e
https://github.com/tsuru/tsuru/blob/2f7fd515c5dc25a58aec80f0e497c49e49581b3e/app/app.go#L1450-L1469
test
tsuru/tsuru
app/app.go
Envs
func (app *App) Envs() map[string]bind.EnvVar { mergedEnvs := make(map[string]bind.EnvVar, len(app.Env)+len(app.ServiceEnvs)+1) for _, e := range app.Env { mergedEnvs[e.Name] = e } for _, e := range app.ServiceEnvs { mergedEnvs[e.Name] = e.EnvVar } mergedEnvs[TsuruServicesEnvVar] = serviceEnvsFromEnvVars(app....
go
func (app *App) Envs() map[string]bind.EnvVar { mergedEnvs := make(map[string]bind.EnvVar, len(app.Env)+len(app.ServiceEnvs)+1) for _, e := range app.Env { mergedEnvs[e.Name] = e } for _, e := range app.ServiceEnvs { mergedEnvs[e.Name] = e.EnvVar } mergedEnvs[TsuruServicesEnvVar] = serviceEnvsFromEnvVars(app....
[ "func", "(", "app", "*", "App", ")", "Envs", "(", ")", "map", "[", "string", "]", "bind", ".", "EnvVar", "{", "mergedEnvs", ":=", "make", "(", "map", "[", "string", "]", "bind", ".", "EnvVar", ",", "len", "(", "app", ".", "Env", ")", "+", "len"...
// Envs returns a map representing the apps environment variables.
[ "Envs", "returns", "a", "map", "representing", "the", "apps", "environment", "variables", "." ]
2f7fd515c5dc25a58aec80f0e497c49e49581b3e
https://github.com/tsuru/tsuru/blob/2f7fd515c5dc25a58aec80f0e497c49e49581b3e/app/app.go#L1554-L1564
test
tsuru/tsuru
app/app.go
SetEnvs
func (app *App) SetEnvs(setEnvs bind.SetEnvArgs) error { if len(setEnvs.Envs) == 0 { return nil } for _, env := range setEnvs.Envs { err := validateEnv(env.Name) if err != nil { return err } } if setEnvs.Writer != nil { fmt.Fprintf(setEnvs.Writer, "---- Setting %d new environment variables ----\n", le...
go
func (app *App) SetEnvs(setEnvs bind.SetEnvArgs) error { if len(setEnvs.Envs) == 0 { return nil } for _, env := range setEnvs.Envs { err := validateEnv(env.Name) if err != nil { return err } } if setEnvs.Writer != nil { fmt.Fprintf(setEnvs.Writer, "---- Setting %d new environment variables ----\n", le...
[ "func", "(", "app", "*", "App", ")", "SetEnvs", "(", "setEnvs", "bind", ".", "SetEnvArgs", ")", "error", "{", "if", "len", "(", "setEnvs", ".", "Envs", ")", "==", "0", "{", "return", "nil", "\n", "}", "\n", "for", "_", ",", "env", ":=", "range", ...
// SetEnvs saves a list of environment variables in the app.
[ "SetEnvs", "saves", "a", "list", "of", "environment", "variables", "in", "the", "app", "." ]
2f7fd515c5dc25a58aec80f0e497c49e49581b3e
https://github.com/tsuru/tsuru/blob/2f7fd515c5dc25a58aec80f0e497c49e49581b3e/app/app.go#L1567-L1596
test
tsuru/tsuru
app/app.go
UnsetEnvs
func (app *App) UnsetEnvs(unsetEnvs bind.UnsetEnvArgs) error { if len(unsetEnvs.VariableNames) == 0 { return nil } if unsetEnvs.Writer != nil { fmt.Fprintf(unsetEnvs.Writer, "---- Unsetting %d environment variables ----\n", len(unsetEnvs.VariableNames)) } for _, name := range unsetEnvs.VariableNames { delete...
go
func (app *App) UnsetEnvs(unsetEnvs bind.UnsetEnvArgs) error { if len(unsetEnvs.VariableNames) == 0 { return nil } if unsetEnvs.Writer != nil { fmt.Fprintf(unsetEnvs.Writer, "---- Unsetting %d environment variables ----\n", len(unsetEnvs.VariableNames)) } for _, name := range unsetEnvs.VariableNames { delete...
[ "func", "(", "app", "*", "App", ")", "UnsetEnvs", "(", "unsetEnvs", "bind", ".", "UnsetEnvArgs", ")", "error", "{", "if", "len", "(", "unsetEnvs", ".", "VariableNames", ")", "==", "0", "{", "return", "nil", "\n", "}", "\n", "if", "unsetEnvs", ".", "W...
// UnsetEnvs removes environment variables from an app, serializing the // remaining list of environment variables to all units of the app.
[ "UnsetEnvs", "removes", "environment", "variables", "from", "an", "app", "serializing", "the", "remaining", "list", "of", "environment", "variables", "to", "all", "units", "of", "the", "app", "." ]
2f7fd515c5dc25a58aec80f0e497c49e49581b3e
https://github.com/tsuru/tsuru/blob/2f7fd515c5dc25a58aec80f0e497c49e49581b3e/app/app.go#L1600-L1623
test
tsuru/tsuru
app/app.go
AddCName
func (app *App) AddCName(cnames ...string) error { actions := []*action.Action{ &validateNewCNames, &setNewCNamesToProvisioner, &saveCNames, &updateApp, } err := action.NewPipeline(actions...).Execute(app, cnames) rebuild.RoutesRebuildOrEnqueue(app.Name) return err }
go
func (app *App) AddCName(cnames ...string) error { actions := []*action.Action{ &validateNewCNames, &setNewCNamesToProvisioner, &saveCNames, &updateApp, } err := action.NewPipeline(actions...).Execute(app, cnames) rebuild.RoutesRebuildOrEnqueue(app.Name) return err }
[ "func", "(", "app", "*", "App", ")", "AddCName", "(", "cnames", "...", "string", ")", "error", "{", "actions", ":=", "[", "]", "*", "action", ".", "Action", "{", "&", "validateNewCNames", ",", "&", "setNewCNamesToProvisioner", ",", "&", "saveCNames", ","...
// AddCName adds a CName to app. It updates the attribute, // calls the SetCName function on the provisioner and saves // the app in the database, returning an error when it cannot save the change // in the database or add the CName on the provisioner.
[ "AddCName", "adds", "a", "CName", "to", "app", ".", "It", "updates", "the", "attribute", "calls", "the", "SetCName", "function", "on", "the", "provisioner", "and", "saves", "the", "app", "in", "the", "database", "returning", "an", "error", "when", "it", "c...
2f7fd515c5dc25a58aec80f0e497c49e49581b3e
https://github.com/tsuru/tsuru/blob/2f7fd515c5dc25a58aec80f0e497c49e49581b3e/app/app.go#L1644-L1654
test
tsuru/tsuru
app/app.go
Log
func (app *App) Log(message, source, unit string) error { messages := strings.Split(message, "\n") logs := make([]interface{}, 0, len(messages)) for _, msg := range messages { if msg != "" { l := Applog{ Date: time.Now().In(time.UTC), Message: msg, Source: source, AppName: app.Name, Unit...
go
func (app *App) Log(message, source, unit string) error { messages := strings.Split(message, "\n") logs := make([]interface{}, 0, len(messages)) for _, msg := range messages { if msg != "" { l := Applog{ Date: time.Now().In(time.UTC), Message: msg, Source: source, AppName: app.Name, Unit...
[ "func", "(", "app", "*", "App", ")", "Log", "(", "message", ",", "source", ",", "unit", "string", ")", "error", "{", "messages", ":=", "strings", ".", "Split", "(", "message", ",", "\"\\n\"", ")", "\n", "\\n", "\n", "logs", ":=", "make", "(", "[", ...
// Log adds a log message to the app. Specifying a good source is good so the // user can filter where the message come from.
[ "Log", "adds", "a", "log", "message", "to", "the", "app", ".", "Specifying", "a", "good", "source", "is", "good", "so", "the", "user", "can", "filter", "where", "the", "message", "come", "from", "." ]
2f7fd515c5dc25a58aec80f0e497c49e49581b3e
https://github.com/tsuru/tsuru/blob/2f7fd515c5dc25a58aec80f0e497c49e49581b3e/app/app.go#L1754-L1778
test
tsuru/tsuru
app/app.go
LastLogs
func (app *App) LastLogs(lines int, filterLog Applog) ([]Applog, error) { return app.lastLogs(lines, filterLog, false) }
go
func (app *App) LastLogs(lines int, filterLog Applog) ([]Applog, error) { return app.lastLogs(lines, filterLog, false) }
[ "func", "(", "app", "*", "App", ")", "LastLogs", "(", "lines", "int", ",", "filterLog", "Applog", ")", "(", "[", "]", "Applog", ",", "error", ")", "{", "return", "app", ".", "lastLogs", "(", "lines", ",", "filterLog", ",", "false", ")", "\n", "}" ]
// LastLogs returns a list of the last `lines` log of the app, matching the // fields in the log instance received as an example.
[ "LastLogs", "returns", "a", "list", "of", "the", "last", "lines", "log", "of", "the", "app", "matching", "the", "fields", "in", "the", "log", "instance", "received", "as", "an", "example", "." ]
2f7fd515c5dc25a58aec80f0e497c49e49581b3e
https://github.com/tsuru/tsuru/blob/2f7fd515c5dc25a58aec80f0e497c49e49581b3e/app/app.go#L1782-L1784
test
tsuru/tsuru
app/app.go
List
func List(filter *Filter) ([]App, error) { apps := []App{} query := filter.Query() conn, err := db.Conn() if err != nil { return nil, err } err = conn.Apps().Find(query).All(&apps) conn.Close() if err != nil { return nil, err } if filter != nil && len(filter.Statuses) > 0 { appsProvisionerMap := make(ma...
go
func List(filter *Filter) ([]App, error) { apps := []App{} query := filter.Query() conn, err := db.Conn() if err != nil { return nil, err } err = conn.Apps().Find(query).All(&apps) conn.Close() if err != nil { return nil, err } if filter != nil && len(filter.Statuses) > 0 { appsProvisionerMap := make(ma...
[ "func", "List", "(", "filter", "*", "Filter", ")", "(", "[", "]", "App", ",", "error", ")", "{", "apps", ":=", "[", "]", "App", "{", "}", "\n", "query", ":=", "filter", ".", "Query", "(", ")", "\n", "conn", ",", "err", ":=", "db", ".", "Conn"...
// List returns the list of apps filtered through the filter parameter.
[ "List", "returns", "the", "list", "of", "apps", "filtered", "through", "the", "filter", "parameter", "." ]
2f7fd515c5dc25a58aec80f0e497c49e49581b3e
https://github.com/tsuru/tsuru/blob/2f7fd515c5dc25a58aec80f0e497c49e49581b3e/app/app.go#L1975-L2022
test
tsuru/tsuru
app/app.go
Swap
func Swap(app1, app2 *App, cnameOnly bool) error { a1Routers := app1.GetRouters() a2Routers := app2.GetRouters() if len(a1Routers) != 1 || len(a2Routers) != 1 { return errors.New("swapping apps with multiple routers is not supported") } r1, err := router.Get(a1Routers[0].Name) if err != nil { return err } r...
go
func Swap(app1, app2 *App, cnameOnly bool) error { a1Routers := app1.GetRouters() a2Routers := app2.GetRouters() if len(a1Routers) != 1 || len(a2Routers) != 1 { return errors.New("swapping apps with multiple routers is not supported") } r1, err := router.Get(a1Routers[0].Name) if err != nil { return err } r...
[ "func", "Swap", "(", "app1", ",", "app2", "*", "App", ",", "cnameOnly", "bool", ")", "error", "{", "a1Routers", ":=", "app1", ".", "GetRouters", "(", ")", "\n", "a2Routers", ":=", "app2", ".", "GetRouters", "(", ")", "\n", "if", "len", "(", "a1Router...
// Swap calls the Router.Swap and updates the app.CName in the database.
[ "Swap", "calls", "the", "Router", ".", "Swap", "and", "updates", "the", "app", ".", "CName", "in", "the", "database", "." ]
2f7fd515c5dc25a58aec80f0e497c49e49581b3e
https://github.com/tsuru/tsuru/blob/2f7fd515c5dc25a58aec80f0e497c49e49581b3e/app/app.go#L2063-L2104
test
tsuru/tsuru
app/app.go
Start
func (app *App) Start(w io.Writer, process string) error { w = app.withLogWriter(w) msg := fmt.Sprintf("\n ---> Starting the process %q", process) if process == "" { msg = fmt.Sprintf("\n ---> Starting the app %q", app.Name) } fmt.Fprintf(w, "%s\n", msg) prov, err := app.getProvisioner() if err != nil { retu...
go
func (app *App) Start(w io.Writer, process string) error { w = app.withLogWriter(w) msg := fmt.Sprintf("\n ---> Starting the process %q", process) if process == "" { msg = fmt.Sprintf("\n ---> Starting the app %q", app.Name) } fmt.Fprintf(w, "%s\n", msg) prov, err := app.getProvisioner() if err != nil { retu...
[ "func", "(", "app", "*", "App", ")", "Start", "(", "w", "io", ".", "Writer", ",", "process", "string", ")", "error", "{", "w", "=", "app", ".", "withLogWriter", "(", "w", ")", "\n", "msg", ":=", "fmt", ".", "Sprintf", "(", "\"\\n -", ",", "\\n", ...
// Start starts the app calling the provisioner.Start method and // changing the units state to StatusStarted.
[ "Start", "starts", "the", "app", "calling", "the", "provisioner", ".", "Start", "method", "and", "changing", "the", "units", "state", "to", "StatusStarted", "." ]
2f7fd515c5dc25a58aec80f0e497c49e49581b3e
https://github.com/tsuru/tsuru/blob/2f7fd515c5dc25a58aec80f0e497c49e49581b3e/app/app.go#L2108-L2126
test
tsuru/tsuru
storage/driver.go
GetDbDriver
func GetDbDriver(name string) (*DbDriver, error) { driver, ok := dbDrivers[name] if !ok { return nil, errors.Errorf("Unknown database driver: %q.", name) } return &driver, nil }
go
func GetDbDriver(name string) (*DbDriver, error) { driver, ok := dbDrivers[name] if !ok { return nil, errors.Errorf("Unknown database driver: %q.", name) } return &driver, nil }
[ "func", "GetDbDriver", "(", "name", "string", ")", "(", "*", "DbDriver", ",", "error", ")", "{", "driver", ",", "ok", ":=", "dbDrivers", "[", "name", "]", "\n", "if", "!", "ok", "{", "return", "nil", ",", "errors", ".", "Errorf", "(", "\"Unknown data...
// GetDbDriver returns the DB driver that was registered with a specific name
[ "GetDbDriver", "returns", "the", "DB", "driver", "that", "was", "registered", "with", "a", "specific", "name" ]
2f7fd515c5dc25a58aec80f0e497c49e49581b3e
https://github.com/tsuru/tsuru/blob/2f7fd515c5dc25a58aec80f0e497c49e49581b3e/storage/driver.go#L50-L56
test
tsuru/tsuru
storage/driver.go
GetCurrentDbDriver
func GetCurrentDbDriver() (*DbDriver, error) { driverLock.RLock() if currentDbDriver != nil { driverLock.RUnlock() return currentDbDriver, nil } driverLock.RUnlock() driverLock.Lock() defer driverLock.Unlock() if currentDbDriver != nil { return currentDbDriver, nil } dbDriverName, err := config.GetString...
go
func GetCurrentDbDriver() (*DbDriver, error) { driverLock.RLock() if currentDbDriver != nil { driverLock.RUnlock() return currentDbDriver, nil } driverLock.RUnlock() driverLock.Lock() defer driverLock.Unlock() if currentDbDriver != nil { return currentDbDriver, nil } dbDriverName, err := config.GetString...
[ "func", "GetCurrentDbDriver", "(", ")", "(", "*", "DbDriver", ",", "error", ")", "{", "driverLock", ".", "RLock", "(", ")", "\n", "if", "currentDbDriver", "!=", "nil", "{", "driverLock", ".", "RUnlock", "(", ")", "\n", "return", "currentDbDriver", ",", "...
// GetCurrentDbDriver returns the DB driver specified in the configuration file. // If this configuration was omitted, it returns the default DB driver
[ "GetCurrentDbDriver", "returns", "the", "DB", "driver", "specified", "in", "the", "configuration", "file", ".", "If", "this", "configuration", "was", "omitted", "it", "returns", "the", "default", "DB", "driver" ]
2f7fd515c5dc25a58aec80f0e497c49e49581b3e
https://github.com/tsuru/tsuru/blob/2f7fd515c5dc25a58aec80f0e497c49e49581b3e/storage/driver.go#L60-L81
test
tsuru/tsuru
provision/kubernetes/pkg/client/clientset/versioned/clientset.go
NewForConfig
func NewForConfig(c *rest.Config) (*Clientset, error) { configShallowCopy := *c if configShallowCopy.RateLimiter == nil && configShallowCopy.QPS > 0 { configShallowCopy.RateLimiter = flowcontrol.NewTokenBucketRateLimiter(configShallowCopy.QPS, configShallowCopy.Burst) } var cs Clientset var err error cs.tsuruV1...
go
func NewForConfig(c *rest.Config) (*Clientset, error) { configShallowCopy := *c if configShallowCopy.RateLimiter == nil && configShallowCopy.QPS > 0 { configShallowCopy.RateLimiter = flowcontrol.NewTokenBucketRateLimiter(configShallowCopy.QPS, configShallowCopy.Burst) } var cs Clientset var err error cs.tsuruV1...
[ "func", "NewForConfig", "(", "c", "*", "rest", ".", "Config", ")", "(", "*", "Clientset", ",", "error", ")", "{", "configShallowCopy", ":=", "*", "c", "\n", "if", "configShallowCopy", ".", "RateLimiter", "==", "nil", "&&", "configShallowCopy", ".", "QPS", ...
// NewForConfig creates a new Clientset for the given config.
[ "NewForConfig", "creates", "a", "new", "Clientset", "for", "the", "given", "config", "." ]
2f7fd515c5dc25a58aec80f0e497c49e49581b3e
https://github.com/tsuru/tsuru/blob/2f7fd515c5dc25a58aec80f0e497c49e49581b3e/provision/kubernetes/pkg/client/clientset/versioned/clientset.go#L51-L69
test
tsuru/tsuru
provision/docker/provisioner.go
GetAppFromUnitID
func (p *dockerProvisioner) GetAppFromUnitID(unitID string) (provision.App, error) { cnt, err := p.GetContainer(unitID) if err != nil { return nil, err } a, err := app.GetByName(cnt.AppName) if err != nil { return nil, err } return a, nil }
go
func (p *dockerProvisioner) GetAppFromUnitID(unitID string) (provision.App, error) { cnt, err := p.GetContainer(unitID) if err != nil { return nil, err } a, err := app.GetByName(cnt.AppName) if err != nil { return nil, err } return a, nil }
[ "func", "(", "p", "*", "dockerProvisioner", ")", "GetAppFromUnitID", "(", "unitID", "string", ")", "(", "provision", ".", "App", ",", "error", ")", "{", "cnt", ",", "err", ":=", "p", ".", "GetContainer", "(", "unitID", ")", "\n", "if", "err", "!=", "...
// GetAppFromUnitID returns app from unit id
[ "GetAppFromUnitID", "returns", "app", "from", "unit", "id" ]
2f7fd515c5dc25a58aec80f0e497c49e49581b3e
https://github.com/tsuru/tsuru/blob/2f7fd515c5dc25a58aec80f0e497c49e49581b3e/provision/docker/provisioner.go#L760-L770
test
tsuru/tsuru
action/action.go
NewPipeline
func NewPipeline(actions ...*Action) *Pipeline { // Actions are usually global functions, copying them // guarantees each copy has an isolated Result. newActions := make([]*Action, len(actions)) for i, action := range actions { newAction := &Action{ Name: action.Name, Forward: action.Forward, Back...
go
func NewPipeline(actions ...*Action) *Pipeline { // Actions are usually global functions, copying them // guarantees each copy has an isolated Result. newActions := make([]*Action, len(actions)) for i, action := range actions { newAction := &Action{ Name: action.Name, Forward: action.Forward, Back...
[ "func", "NewPipeline", "(", "actions", "...", "*", "Action", ")", "*", "Pipeline", "{", "newActions", ":=", "make", "(", "[", "]", "*", "Action", ",", "len", "(", "actions", ")", ")", "\n", "for", "i", ",", "action", ":=", "range", "actions", "{", ...
// NewPipeline creates a new pipeline instance with the given list of actions.
[ "NewPipeline", "creates", "a", "new", "pipeline", "instance", "with", "the", "given", "list", "of", "actions", "." ]
2f7fd515c5dc25a58aec80f0e497c49e49581b3e
https://github.com/tsuru/tsuru/blob/2f7fd515c5dc25a58aec80f0e497c49e49581b3e/action/action.go#L98-L114
test
tsuru/tsuru
action/action.go
Result
func (p *Pipeline) Result() Result { action := p.actions[len(p.actions)-1] action.rMutex.Lock() defer action.rMutex.Unlock() return action.result }
go
func (p *Pipeline) Result() Result { action := p.actions[len(p.actions)-1] action.rMutex.Lock() defer action.rMutex.Unlock() return action.result }
[ "func", "(", "p", "*", "Pipeline", ")", "Result", "(", ")", "Result", "{", "action", ":=", "p", ".", "actions", "[", "len", "(", "p", ".", "actions", ")", "-", "1", "]", "\n", "action", ".", "rMutex", ".", "Lock", "(", ")", "\n", "defer", "acti...
// Result returns the result of the last action.
[ "Result", "returns", "the", "result", "of", "the", "last", "action", "." ]
2f7fd515c5dc25a58aec80f0e497c49e49581b3e
https://github.com/tsuru/tsuru/blob/2f7fd515c5dc25a58aec80f0e497c49e49581b3e/action/action.go#L117-L122
test
ant0ine/go-json-rest
rest/request.go
DecodeJsonPayload
func (r *Request) DecodeJsonPayload(v interface{}) error { content, err := ioutil.ReadAll(r.Body) r.Body.Close() if err != nil { return err } if len(content) == 0 { return ErrJsonPayloadEmpty } err = json.Unmarshal(content, v) if err != nil { return err } return nil }
go
func (r *Request) DecodeJsonPayload(v interface{}) error { content, err := ioutil.ReadAll(r.Body) r.Body.Close() if err != nil { return err } if len(content) == 0 { return ErrJsonPayloadEmpty } err = json.Unmarshal(content, v) if err != nil { return err } return nil }
[ "func", "(", "r", "*", "Request", ")", "DecodeJsonPayload", "(", "v", "interface", "{", "}", ")", "error", "{", "content", ",", "err", ":=", "ioutil", ".", "ReadAll", "(", "r", ".", "Body", ")", "\n", "r", ".", "Body", ".", "Close", "(", ")", "\n...
// DecodeJsonPayload reads the request body and decodes the JSON using json.Unmarshal.
[ "DecodeJsonPayload", "reads", "the", "request", "body", "and", "decodes", "the", "JSON", "using", "json", ".", "Unmarshal", "." ]
ebb33769ae013bd5f518a8bac348c310dea768b8
https://github.com/ant0ine/go-json-rest/blob/ebb33769ae013bd5f518a8bac348c310dea768b8/rest/request.go#L34-L48
test
ant0ine/go-json-rest
rest/request.go
UrlFor
func (r *Request) UrlFor(path string, queryParams map[string][]string) *url.URL { baseUrl := r.BaseUrl() baseUrl.Path = path if queryParams != nil { query := url.Values{} for k, v := range queryParams { for _, vv := range v { query.Add(k, vv) } } baseUrl.RawQuery = query.Encode() } return baseUrl...
go
func (r *Request) UrlFor(path string, queryParams map[string][]string) *url.URL { baseUrl := r.BaseUrl() baseUrl.Path = path if queryParams != nil { query := url.Values{} for k, v := range queryParams { for _, vv := range v { query.Add(k, vv) } } baseUrl.RawQuery = query.Encode() } return baseUrl...
[ "func", "(", "r", "*", "Request", ")", "UrlFor", "(", "path", "string", ",", "queryParams", "map", "[", "string", "]", "[", "]", "string", ")", "*", "url", ".", "URL", "{", "baseUrl", ":=", "r", ".", "BaseUrl", "(", ")", "\n", "baseUrl", ".", "Pa...
// UrlFor returns the URL object from UriBase with the Path set to path, and the query // string built with queryParams.
[ "UrlFor", "returns", "the", "URL", "object", "from", "UriBase", "with", "the", "Path", "set", "to", "path", "and", "the", "query", "string", "built", "with", "queryParams", "." ]
ebb33769ae013bd5f518a8bac348c310dea768b8
https://github.com/ant0ine/go-json-rest/blob/ebb33769ae013bd5f518a8bac348c310dea768b8/rest/request.go#L77-L90
test
ant0ine/go-json-rest
rest/request.go
GetCorsInfo
func (r *Request) GetCorsInfo() *CorsInfo { origin := r.Header.Get("Origin") var originUrl *url.URL var isCors bool if origin == "" { isCors = false } else if origin == "null" { isCors = true } else { var err error originUrl, err = url.ParseRequestURI(origin) isCors = err == nil && r.Host != originUr...
go
func (r *Request) GetCorsInfo() *CorsInfo { origin := r.Header.Get("Origin") var originUrl *url.URL var isCors bool if origin == "" { isCors = false } else if origin == "null" { isCors = true } else { var err error originUrl, err = url.ParseRequestURI(origin) isCors = err == nil && r.Host != originUr...
[ "func", "(", "r", "*", "Request", ")", "GetCorsInfo", "(", ")", "*", "CorsInfo", "{", "origin", ":=", "r", ".", "Header", ".", "Get", "(", "\"Origin\"", ")", "\n", "var", "originUrl", "*", "url", ".", "URL", "\n", "var", "isCors", "bool", "\n", "if...
// GetCorsInfo derives CorsInfo from Request.
[ "GetCorsInfo", "derives", "CorsInfo", "from", "Request", "." ]
ebb33769ae013bd5f518a8bac348c310dea768b8
https://github.com/ant0ine/go-json-rest/blob/ebb33769ae013bd5f518a8bac348c310dea768b8/rest/request.go#L107-L148
test
ant0ine/go-json-rest
rest/cors.go
MiddlewareFunc
func (mw *CorsMiddleware) MiddlewareFunc(handler HandlerFunc) HandlerFunc { // precompute as much as possible at init time mw.allowedMethods = map[string]bool{} normedMethods := []string{} for _, allowedMethod := range mw.AllowedMethods { normed := strings.ToUpper(allowedMethod) mw.allowedMethods[normed] = tr...
go
func (mw *CorsMiddleware) MiddlewareFunc(handler HandlerFunc) HandlerFunc { // precompute as much as possible at init time mw.allowedMethods = map[string]bool{} normedMethods := []string{} for _, allowedMethod := range mw.AllowedMethods { normed := strings.ToUpper(allowedMethod) mw.allowedMethods[normed] = tr...
[ "func", "(", "mw", "*", "CorsMiddleware", ")", "MiddlewareFunc", "(", "handler", "HandlerFunc", ")", "HandlerFunc", "{", "mw", ".", "allowedMethods", "=", "map", "[", "string", "]", "bool", "{", "}", "\n", "normedMethods", ":=", "[", "]", "string", "{", ...
// MiddlewareFunc makes CorsMiddleware implement the Middleware interface.
[ "MiddlewareFunc", "makes", "CorsMiddleware", "implement", "the", "Middleware", "interface", "." ]
ebb33769ae013bd5f518a8bac348c310dea768b8
https://github.com/ant0ine/go-json-rest/blob/ebb33769ae013bd5f518a8bac348c310dea768b8/rest/cors.go#L53-L135
test
ant0ine/go-json-rest
rest/recorder.go
MiddlewareFunc
func (mw *RecorderMiddleware) MiddlewareFunc(h HandlerFunc) HandlerFunc { return func(w ResponseWriter, r *Request) { writer := &recorderResponseWriter{w, 0, false, 0} // call the handler h(writer, r) r.Env["STATUS_CODE"] = writer.statusCode r.Env["BYTES_WRITTEN"] = writer.bytesWritten } }
go
func (mw *RecorderMiddleware) MiddlewareFunc(h HandlerFunc) HandlerFunc { return func(w ResponseWriter, r *Request) { writer := &recorderResponseWriter{w, 0, false, 0} // call the handler h(writer, r) r.Env["STATUS_CODE"] = writer.statusCode r.Env["BYTES_WRITTEN"] = writer.bytesWritten } }
[ "func", "(", "mw", "*", "RecorderMiddleware", ")", "MiddlewareFunc", "(", "h", "HandlerFunc", ")", "HandlerFunc", "{", "return", "func", "(", "w", "ResponseWriter", ",", "r", "*", "Request", ")", "{", "writer", ":=", "&", "recorderResponseWriter", "{", "w", ...
// MiddlewareFunc makes RecorderMiddleware implement the Middleware interface.
[ "MiddlewareFunc", "makes", "RecorderMiddleware", "implement", "the", "Middleware", "interface", "." ]
ebb33769ae013bd5f518a8bac348c310dea768b8
https://github.com/ant0ine/go-json-rest/blob/ebb33769ae013bd5f518a8bac348c310dea768b8/rest/recorder.go#L16-L27
test
ant0ine/go-json-rest
rest/recorder.go
WriteHeader
func (w *recorderResponseWriter) WriteHeader(code int) { w.ResponseWriter.WriteHeader(code) if w.wroteHeader { return } w.statusCode = code w.wroteHeader = true }
go
func (w *recorderResponseWriter) WriteHeader(code int) { w.ResponseWriter.WriteHeader(code) if w.wroteHeader { return } w.statusCode = code w.wroteHeader = true }
[ "func", "(", "w", "*", "recorderResponseWriter", ")", "WriteHeader", "(", "code", "int", ")", "{", "w", ".", "ResponseWriter", ".", "WriteHeader", "(", "code", ")", "\n", "if", "w", ".", "wroteHeader", "{", "return", "\n", "}", "\n", "w", ".", "statusC...
// Record the status code.
[ "Record", "the", "status", "code", "." ]
ebb33769ae013bd5f518a8bac348c310dea768b8
https://github.com/ant0ine/go-json-rest/blob/ebb33769ae013bd5f518a8bac348c310dea768b8/rest/recorder.go#L45-L52
test
ant0ine/go-json-rest
rest/router.go
MakeRouter
func MakeRouter(routes ...*Route) (App, error) { r := &router{ Routes: routes, } err := r.start() if err != nil { return nil, err } return r, nil }
go
func MakeRouter(routes ...*Route) (App, error) { r := &router{ Routes: routes, } err := r.start() if err != nil { return nil, err } return r, nil }
[ "func", "MakeRouter", "(", "routes", "...", "*", "Route", ")", "(", "App", ",", "error", ")", "{", "r", ":=", "&", "router", "{", "Routes", ":", "routes", ",", "}", "\n", "err", ":=", "r", ".", "start", "(", ")", "\n", "if", "err", "!=", "nil",...
// MakeRouter returns the router app. Given a set of Routes, it dispatches the request to the // HandlerFunc of the first route that matches. The order of the Routes matters.
[ "MakeRouter", "returns", "the", "router", "app", ".", "Given", "a", "set", "of", "Routes", "it", "dispatches", "the", "request", "to", "the", "HandlerFunc", "of", "the", "first", "route", "that", "matches", ".", "The", "order", "of", "the", "Routes", "matt...
ebb33769ae013bd5f518a8bac348c310dea768b8
https://github.com/ant0ine/go-json-rest/blob/ebb33769ae013bd5f518a8bac348c310dea768b8/rest/router.go#L21-L30
test
ant0ine/go-json-rest
rest/router.go
AppFunc
func (rt *router) AppFunc() HandlerFunc { return func(writer ResponseWriter, request *Request) { // find the route route, params, pathMatched := rt.findRouteFromURL(request.Method, request.URL) if route == nil { if pathMatched { // no route found, but path was matched: 405 Method Not Allowed Error(w...
go
func (rt *router) AppFunc() HandlerFunc { return func(writer ResponseWriter, request *Request) { // find the route route, params, pathMatched := rt.findRouteFromURL(request.Method, request.URL) if route == nil { if pathMatched { // no route found, but path was matched: 405 Method Not Allowed Error(w...
[ "func", "(", "rt", "*", "router", ")", "AppFunc", "(", ")", "HandlerFunc", "{", "return", "func", "(", "writer", "ResponseWriter", ",", "request", "*", "Request", ")", "{", "route", ",", "params", ",", "pathMatched", ":=", "rt", ".", "findRouteFromURL", ...
// Handle the REST routing and run the user code.
[ "Handle", "the", "REST", "routing", "and", "run", "the", "user", "code", "." ]
ebb33769ae013bd5f518a8bac348c310dea768b8
https://github.com/ant0ine/go-json-rest/blob/ebb33769ae013bd5f518a8bac348c310dea768b8/rest/router.go#L33-L58
test
ant0ine/go-json-rest
rest/router.go
escapedPath
func escapedPath(urlObj *url.URL) string { // the escape method of url.URL should be public // that would avoid this split. parts := strings.SplitN(urlObj.RequestURI(), "?", 2) return parts[0] }
go
func escapedPath(urlObj *url.URL) string { // the escape method of url.URL should be public // that would avoid this split. parts := strings.SplitN(urlObj.RequestURI(), "?", 2) return parts[0] }
[ "func", "escapedPath", "(", "urlObj", "*", "url", ".", "URL", ")", "string", "{", "parts", ":=", "strings", ".", "SplitN", "(", "urlObj", ".", "RequestURI", "(", ")", ",", "\"?\"", ",", "2", ")", "\n", "return", "parts", "[", "0", "]", "\n", "}" ]
// This is run for each new request, perf is important.
[ "This", "is", "run", "for", "each", "new", "request", "perf", "is", "important", "." ]
ebb33769ae013bd5f518a8bac348c310dea768b8
https://github.com/ant0ine/go-json-rest/blob/ebb33769ae013bd5f518a8bac348c310dea768b8/rest/router.go#L61-L66
test
ant0ine/go-json-rest
rest/router.go
escapedPathExp
func escapedPathExp(pathExp string) (string, error) { // PathExp validation if pathExp == "" { return "", errors.New("empty PathExp") } if pathExp[0] != '/' { return "", errors.New("PathExp must start with /") } if strings.Contains(pathExp, "?") { return "", errors.New("PathExp must not contain the query s...
go
func escapedPathExp(pathExp string) (string, error) { // PathExp validation if pathExp == "" { return "", errors.New("empty PathExp") } if pathExp[0] != '/' { return "", errors.New("PathExp must start with /") } if strings.Contains(pathExp, "?") { return "", errors.New("PathExp must not contain the query s...
[ "func", "escapedPathExp", "(", "pathExp", "string", ")", "(", "string", ",", "error", ")", "{", "if", "pathExp", "==", "\"\"", "{", "return", "\"\"", ",", "errors", ".", "New", "(", "\"empty PathExp\"", ")", "\n", "}", "\n", "if", "pathExp", "[", "0", ...
// This is run at init time only.
[ "This", "is", "run", "at", "init", "time", "only", "." ]
ebb33769ae013bd5f518a8bac348c310dea768b8
https://github.com/ant0ine/go-json-rest/blob/ebb33769ae013bd5f518a8bac348c310dea768b8/rest/router.go#L73-L102
test
ant0ine/go-json-rest
rest/router.go
start
func (rt *router) start() error { rt.trie = trie.New() rt.index = map[*Route]int{} for i, route := range rt.Routes { // work with the PathExp urlencoded. pathExp, err := escapedPathExp(route.PathExp) if err != nil { return err } // insert in the Trie err = rt.trie.AddRoute( strings.ToUpper(rout...
go
func (rt *router) start() error { rt.trie = trie.New() rt.index = map[*Route]int{} for i, route := range rt.Routes { // work with the PathExp urlencoded. pathExp, err := escapedPathExp(route.PathExp) if err != nil { return err } // insert in the Trie err = rt.trie.AddRoute( strings.ToUpper(rout...
[ "func", "(", "rt", "*", "router", ")", "start", "(", ")", "error", "{", "rt", ".", "trie", "=", "trie", ".", "New", "(", ")", "\n", "rt", ".", "index", "=", "map", "[", "*", "Route", "]", "int", "{", "}", "\n", "for", "i", ",", "route", ":=...
// This validates the Routes and prepares the Trie data structure. // It must be called once the Routes are defined and before trying to find Routes. // The order matters, if multiple Routes match, the first defined will be used.
[ "This", "validates", "the", "Routes", "and", "prepares", "the", "Trie", "data", "structure", ".", "It", "must", "be", "called", "once", "the", "Routes", "are", "defined", "and", "before", "trying", "to", "find", "Routes", ".", "The", "order", "matters", "i...
ebb33769ae013bd5f518a8bac348c310dea768b8
https://github.com/ant0ine/go-json-rest/blob/ebb33769ae013bd5f518a8bac348c310dea768b8/rest/router.go#L107-L139
test
ant0ine/go-json-rest
rest/router.go
ofFirstDefinedRoute
func (rt *router) ofFirstDefinedRoute(matches []*trie.Match) *trie.Match { minIndex := -1 var bestMatch *trie.Match for _, result := range matches { route := result.Route.(*Route) routeIndex := rt.index[route] if minIndex == -1 || routeIndex < minIndex { minIndex = routeIndex bestMatch = result } } ...
go
func (rt *router) ofFirstDefinedRoute(matches []*trie.Match) *trie.Match { minIndex := -1 var bestMatch *trie.Match for _, result := range matches { route := result.Route.(*Route) routeIndex := rt.index[route] if minIndex == -1 || routeIndex < minIndex { minIndex = routeIndex bestMatch = result } } ...
[ "func", "(", "rt", "*", "router", ")", "ofFirstDefinedRoute", "(", "matches", "[", "]", "*", "trie", ".", "Match", ")", "*", "trie", ".", "Match", "{", "minIndex", ":=", "-", "1", "\n", "var", "bestMatch", "*", "trie", ".", "Match", "\n", "for", "_...
// return the result that has the route defined the earliest
[ "return", "the", "result", "that", "has", "the", "route", "defined", "the", "earliest" ]
ebb33769ae013bd5f518a8bac348c310dea768b8
https://github.com/ant0ine/go-json-rest/blob/ebb33769ae013bd5f518a8bac348c310dea768b8/rest/router.go#L142-L156
test
ant0ine/go-json-rest
rest/router.go
findRouteFromURL
func (rt *router) findRouteFromURL(httpMethod string, urlObj *url.URL) (*Route, map[string]string, bool) { // lookup the routes in the Trie matches, pathMatched := rt.trie.FindRoutesAndPathMatched( strings.ToUpper(httpMethod), // work with the httpMethod in uppercase escapedPath(urlObj), // work with the...
go
func (rt *router) findRouteFromURL(httpMethod string, urlObj *url.URL) (*Route, map[string]string, bool) { // lookup the routes in the Trie matches, pathMatched := rt.trie.FindRoutesAndPathMatched( strings.ToUpper(httpMethod), // work with the httpMethod in uppercase escapedPath(urlObj), // work with the...
[ "func", "(", "rt", "*", "router", ")", "findRouteFromURL", "(", "httpMethod", "string", ",", "urlObj", "*", "url", ".", "URL", ")", "(", "*", "Route", ",", "map", "[", "string", "]", "string", ",", "bool", ")", "{", "matches", ",", "pathMatched", ":=...
// Return the first matching Route and the corresponding parameters for a given URL object.
[ "Return", "the", "first", "matching", "Route", "and", "the", "corresponding", "parameters", "for", "a", "given", "URL", "object", "." ]
ebb33769ae013bd5f518a8bac348c310dea768b8
https://github.com/ant0ine/go-json-rest/blob/ebb33769ae013bd5f518a8bac348c310dea768b8/rest/router.go#L159-L181
test
ant0ine/go-json-rest
rest/content_type_checker.go
MiddlewareFunc
func (mw *ContentTypeCheckerMiddleware) MiddlewareFunc(handler HandlerFunc) HandlerFunc { return func(w ResponseWriter, r *Request) { mediatype, params, _ := mime.ParseMediaType(r.Header.Get("Content-Type")) charset, ok := params["charset"] if !ok { charset = "UTF-8" } // per net/http doc, means that t...
go
func (mw *ContentTypeCheckerMiddleware) MiddlewareFunc(handler HandlerFunc) HandlerFunc { return func(w ResponseWriter, r *Request) { mediatype, params, _ := mime.ParseMediaType(r.Header.Get("Content-Type")) charset, ok := params["charset"] if !ok { charset = "UTF-8" } // per net/http doc, means that t...
[ "func", "(", "mw", "*", "ContentTypeCheckerMiddleware", ")", "MiddlewareFunc", "(", "handler", "HandlerFunc", ")", "HandlerFunc", "{", "return", "func", "(", "w", "ResponseWriter", ",", "r", "*", "Request", ")", "{", "mediatype", ",", "params", ",", "_", ":=...
// MiddlewareFunc makes ContentTypeCheckerMiddleware implement the Middleware interface.
[ "MiddlewareFunc", "makes", "ContentTypeCheckerMiddleware", "implement", "the", "Middleware", "interface", "." ]
ebb33769ae013bd5f518a8bac348c310dea768b8
https://github.com/ant0ine/go-json-rest/blob/ebb33769ae013bd5f518a8bac348c310dea768b8/rest/content_type_checker.go#L16-L40
test
ant0ine/go-json-rest
rest/response.go
CloseNotify
func (w *responseWriter) CloseNotify() <-chan bool { notifier := w.ResponseWriter.(http.CloseNotifier) return notifier.CloseNotify() }
go
func (w *responseWriter) CloseNotify() <-chan bool { notifier := w.ResponseWriter.(http.CloseNotifier) return notifier.CloseNotify() }
[ "func", "(", "w", "*", "responseWriter", ")", "CloseNotify", "(", ")", "<-", "chan", "bool", "{", "notifier", ":=", "w", ".", "ResponseWriter", ".", "(", "http", ".", "CloseNotifier", ")", "\n", "return", "notifier", ".", "CloseNotify", "(", ")", "\n", ...
// Provided in order to implement the http.CloseNotifier interface.
[ "Provided", "in", "order", "to", "implement", "the", "http", ".", "CloseNotifier", "interface", "." ]
ebb33769ae013bd5f518a8bac348c310dea768b8
https://github.com/ant0ine/go-json-rest/blob/ebb33769ae013bd5f518a8bac348c310dea768b8/rest/response.go#L118-L121
test
ant0ine/go-json-rest
rest/access_log_apache.go
MiddlewareFunc
func (mw *AccessLogApacheMiddleware) MiddlewareFunc(h HandlerFunc) HandlerFunc { // set the default Logger if mw.Logger == nil { mw.Logger = log.New(os.Stderr, "", 0) } // set default format if mw.Format == "" { mw.Format = DefaultLogFormat } mw.convertFormat() return func(w ResponseWriter, r *Request) ...
go
func (mw *AccessLogApacheMiddleware) MiddlewareFunc(h HandlerFunc) HandlerFunc { // set the default Logger if mw.Logger == nil { mw.Logger = log.New(os.Stderr, "", 0) } // set default format if mw.Format == "" { mw.Format = DefaultLogFormat } mw.convertFormat() return func(w ResponseWriter, r *Request) ...
[ "func", "(", "mw", "*", "AccessLogApacheMiddleware", ")", "MiddlewareFunc", "(", "h", "HandlerFunc", ")", "HandlerFunc", "{", "if", "mw", ".", "Logger", "==", "nil", "{", "mw", ".", "Logger", "=", "log", ".", "New", "(", "os", ".", "Stderr", ",", "\"\"...
// MiddlewareFunc makes AccessLogApacheMiddleware implement the Middleware interface.
[ "MiddlewareFunc", "makes", "AccessLogApacheMiddleware", "implement", "the", "Middleware", "interface", "." ]
ebb33769ae013bd5f518a8bac348c310dea768b8
https://github.com/ant0ine/go-json-rest/blob/ebb33769ae013bd5f518a8bac348c310dea768b8/rest/access_log_apache.go#L71-L94
test
ant0ine/go-json-rest
rest/access_log_apache.go
executeTextTemplate
func (mw *AccessLogApacheMiddleware) executeTextTemplate(util *accessLogUtil) string { buf := bytes.NewBufferString("") err := mw.textTemplate.Execute(buf, util) if err != nil { panic(err) } return buf.String() }
go
func (mw *AccessLogApacheMiddleware) executeTextTemplate(util *accessLogUtil) string { buf := bytes.NewBufferString("") err := mw.textTemplate.Execute(buf, util) if err != nil { panic(err) } return buf.String() }
[ "func", "(", "mw", "*", "AccessLogApacheMiddleware", ")", "executeTextTemplate", "(", "util", "*", "accessLogUtil", ")", "string", "{", "buf", ":=", "bytes", ".", "NewBufferString", "(", "\"\"", ")", "\n", "err", ":=", "mw", ".", "textTemplate", ".", "Execut...
// Execute the text template with the data derived from the request, and return a string.
[ "Execute", "the", "text", "template", "with", "the", "data", "derived", "from", "the", "request", "and", "return", "a", "string", "." ]
ebb33769ae013bd5f518a8bac348c310dea768b8
https://github.com/ant0ine/go-json-rest/blob/ebb33769ae013bd5f518a8bac348c310dea768b8/rest/access_log_apache.go#L158-L165
test
ant0ine/go-json-rest
rest/access_log_apache.go
RemoteUser
func (u *accessLogUtil) RemoteUser() string { if u.R.Env["REMOTE_USER"] != nil { return u.R.Env["REMOTE_USER"].(string) } return "" }
go
func (u *accessLogUtil) RemoteUser() string { if u.R.Env["REMOTE_USER"] != nil { return u.R.Env["REMOTE_USER"].(string) } return "" }
[ "func", "(", "u", "*", "accessLogUtil", ")", "RemoteUser", "(", ")", "string", "{", "if", "u", ".", "R", ".", "Env", "[", "\"REMOTE_USER\"", "]", "!=", "nil", "{", "return", "u", ".", "R", ".", "Env", "[", "\"REMOTE_USER\"", "]", ".", "(", "string"...
// As stored by the auth middlewares.
[ "As", "stored", "by", "the", "auth", "middlewares", "." ]
ebb33769ae013bd5f518a8bac348c310dea768b8
https://github.com/ant0ine/go-json-rest/blob/ebb33769ae013bd5f518a8bac348c310dea768b8/rest/access_log_apache.go#L175-L180
test
ant0ine/go-json-rest
rest/access_log_apache.go
ApacheQueryString
func (u *accessLogUtil) ApacheQueryString() string { if u.R.URL.RawQuery != "" { return "?" + u.R.URL.RawQuery } return "" }
go
func (u *accessLogUtil) ApacheQueryString() string { if u.R.URL.RawQuery != "" { return "?" + u.R.URL.RawQuery } return "" }
[ "func", "(", "u", "*", "accessLogUtil", ")", "ApacheQueryString", "(", ")", "string", "{", "if", "u", ".", "R", ".", "URL", ".", "RawQuery", "!=", "\"\"", "{", "return", "\"?\"", "+", "u", ".", "R", ".", "URL", ".", "RawQuery", "\n", "}", "\n", "...
// If qs exists then return it with a leadin "?", apache log style.
[ "If", "qs", "exists", "then", "return", "it", "with", "a", "leadin", "?", "apache", "log", "style", "." ]
ebb33769ae013bd5f518a8bac348c310dea768b8
https://github.com/ant0ine/go-json-rest/blob/ebb33769ae013bd5f518a8bac348c310dea768b8/rest/access_log_apache.go#L183-L188
test
ant0ine/go-json-rest
rest/access_log_apache.go
StartTime
func (u *accessLogUtil) StartTime() *time.Time { if u.R.Env["START_TIME"] != nil { return u.R.Env["START_TIME"].(*time.Time) } return nil }
go
func (u *accessLogUtil) StartTime() *time.Time { if u.R.Env["START_TIME"] != nil { return u.R.Env["START_TIME"].(*time.Time) } return nil }
[ "func", "(", "u", "*", "accessLogUtil", ")", "StartTime", "(", ")", "*", "time", ".", "Time", "{", "if", "u", ".", "R", ".", "Env", "[", "\"START_TIME\"", "]", "!=", "nil", "{", "return", "u", ".", "R", ".", "Env", "[", "\"START_TIME\"", "]", "."...
// When the request entered the timer middleware.
[ "When", "the", "request", "entered", "the", "timer", "middleware", "." ]
ebb33769ae013bd5f518a8bac348c310dea768b8
https://github.com/ant0ine/go-json-rest/blob/ebb33769ae013bd5f518a8bac348c310dea768b8/rest/access_log_apache.go#L191-L196
test
ant0ine/go-json-rest
rest/access_log_apache.go
ApacheRemoteAddr
func (u *accessLogUtil) ApacheRemoteAddr() string { remoteAddr := u.R.RemoteAddr if remoteAddr != "" { if ip, _, err := net.SplitHostPort(remoteAddr); err == nil { return ip } } return "" }
go
func (u *accessLogUtil) ApacheRemoteAddr() string { remoteAddr := u.R.RemoteAddr if remoteAddr != "" { if ip, _, err := net.SplitHostPort(remoteAddr); err == nil { return ip } } return "" }
[ "func", "(", "u", "*", "accessLogUtil", ")", "ApacheRemoteAddr", "(", ")", "string", "{", "remoteAddr", ":=", "u", ".", "R", ".", "RemoteAddr", "\n", "if", "remoteAddr", "!=", "\"\"", "{", "if", "ip", ",", "_", ",", "err", ":=", "net", ".", "SplitHos...
// If remoteAddr is set then return is without the port number, apache log style.
[ "If", "remoteAddr", "is", "set", "then", "return", "is", "without", "the", "port", "number", "apache", "log", "style", "." ]
ebb33769ae013bd5f518a8bac348c310dea768b8
https://github.com/ant0ine/go-json-rest/blob/ebb33769ae013bd5f518a8bac348c310dea768b8/rest/access_log_apache.go#L199-L207
test
ant0ine/go-json-rest
rest/access_log_apache.go
ResponseTime
func (u *accessLogUtil) ResponseTime() *time.Duration { if u.R.Env["ELAPSED_TIME"] != nil { return u.R.Env["ELAPSED_TIME"].(*time.Duration) } return nil }
go
func (u *accessLogUtil) ResponseTime() *time.Duration { if u.R.Env["ELAPSED_TIME"] != nil { return u.R.Env["ELAPSED_TIME"].(*time.Duration) } return nil }
[ "func", "(", "u", "*", "accessLogUtil", ")", "ResponseTime", "(", ")", "*", "time", ".", "Duration", "{", "if", "u", ".", "R", ".", "Env", "[", "\"ELAPSED_TIME\"", "]", "!=", "nil", "{", "return", "u", ".", "R", ".", "Env", "[", "\"ELAPSED_TIME\"", ...
// As mesured by the timer middleware.
[ "As", "mesured", "by", "the", "timer", "middleware", "." ]
ebb33769ae013bd5f518a8bac348c310dea768b8
https://github.com/ant0ine/go-json-rest/blob/ebb33769ae013bd5f518a8bac348c310dea768b8/rest/access_log_apache.go#L218-L223
test
ant0ine/go-json-rest
rest/json_indent.go
MiddlewareFunc
func (mw *JsonIndentMiddleware) MiddlewareFunc(handler HandlerFunc) HandlerFunc { if mw.Indent == "" { mw.Indent = " " } return func(w ResponseWriter, r *Request) { writer := &jsonIndentResponseWriter{w, false, mw.Prefix, mw.Indent} // call the wrapped handler handler(writer, r) } }
go
func (mw *JsonIndentMiddleware) MiddlewareFunc(handler HandlerFunc) HandlerFunc { if mw.Indent == "" { mw.Indent = " " } return func(w ResponseWriter, r *Request) { writer := &jsonIndentResponseWriter{w, false, mw.Prefix, mw.Indent} // call the wrapped handler handler(writer, r) } }
[ "func", "(", "mw", "*", "JsonIndentMiddleware", ")", "MiddlewareFunc", "(", "handler", "HandlerFunc", ")", "HandlerFunc", "{", "if", "mw", ".", "Indent", "==", "\"\"", "{", "mw", ".", "Indent", "=", "\" \"", "\n", "}", "\n", "return", "func", "(", "w", ...
// MiddlewareFunc makes JsonIndentMiddleware implement the Middleware interface.
[ "MiddlewareFunc", "makes", "JsonIndentMiddleware", "implement", "the", "Middleware", "interface", "." ]
ebb33769ae013bd5f518a8bac348c310dea768b8
https://github.com/ant0ine/go-json-rest/blob/ebb33769ae013bd5f518a8bac348c310dea768b8/rest/json_indent.go#L25-L37
test
ant0ine/go-json-rest
rest/json_indent.go
EncodeJson
func (w *jsonIndentResponseWriter) EncodeJson(v interface{}) ([]byte, error) { b, err := json.MarshalIndent(v, w.prefix, w.indent) if err != nil { return nil, err } return b, nil }
go
func (w *jsonIndentResponseWriter) EncodeJson(v interface{}) ([]byte, error) { b, err := json.MarshalIndent(v, w.prefix, w.indent) if err != nil { return nil, err } return b, nil }
[ "func", "(", "w", "*", "jsonIndentResponseWriter", ")", "EncodeJson", "(", "v", "interface", "{", "}", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "b", ",", "err", ":=", "json", ".", "MarshalIndent", "(", "v", ",", "w", ".", "prefix", ",", ...
// Replace the parent EncodeJson to provide indentation.
[ "Replace", "the", "parent", "EncodeJson", "to", "provide", "indentation", "." ]
ebb33769ae013bd5f518a8bac348c310dea768b8
https://github.com/ant0ine/go-json-rest/blob/ebb33769ae013bd5f518a8bac348c310dea768b8/rest/json_indent.go#L54-L60
test
ant0ine/go-json-rest
rest/json_indent.go
WriteHeader
func (w *jsonIndentResponseWriter) WriteHeader(code int) { w.ResponseWriter.WriteHeader(code) w.wroteHeader = true }
go
func (w *jsonIndentResponseWriter) WriteHeader(code int) { w.ResponseWriter.WriteHeader(code) w.wroteHeader = true }
[ "func", "(", "w", "*", "jsonIndentResponseWriter", ")", "WriteHeader", "(", "code", "int", ")", "{", "w", ".", "ResponseWriter", ".", "WriteHeader", "(", "code", ")", "\n", "w", ".", "wroteHeader", "=", "true", "\n", "}" ]
// Call the parent WriteHeader.
[ "Call", "the", "parent", "WriteHeader", "." ]
ebb33769ae013bd5f518a8bac348c310dea768b8
https://github.com/ant0ine/go-json-rest/blob/ebb33769ae013bd5f518a8bac348c310dea768b8/rest/json_indent.go#L77-L80
test
ant0ine/go-json-rest
rest/route.go
MakePath
func (route *Route) MakePath(pathParams map[string]string) string { path := route.PathExp for paramName, paramValue := range pathParams { paramPlaceholder := ":" + paramName relaxedPlaceholder := "#" + paramName splatPlaceholder := "*" + paramName r := strings.NewReplacer(paramPlaceholder, paramValue, splatPl...
go
func (route *Route) MakePath(pathParams map[string]string) string { path := route.PathExp for paramName, paramValue := range pathParams { paramPlaceholder := ":" + paramName relaxedPlaceholder := "#" + paramName splatPlaceholder := "*" + paramName r := strings.NewReplacer(paramPlaceholder, paramValue, splatPl...
[ "func", "(", "route", "*", "Route", ")", "MakePath", "(", "pathParams", "map", "[", "string", "]", "string", ")", "string", "{", "path", ":=", "route", ".", "PathExp", "\n", "for", "paramName", ",", "paramValue", ":=", "range", "pathParams", "{", "paramP...
// MakePath generates the path corresponding to this Route and the provided path parameters. // This is used for reverse route resolution.
[ "MakePath", "generates", "the", "path", "corresponding", "to", "this", "Route", "and", "the", "provided", "path", "parameters", ".", "This", "is", "used", "for", "reverse", "route", "resolution", "." ]
ebb33769ae013bd5f518a8bac348c310dea768b8
https://github.com/ant0ine/go-json-rest/blob/ebb33769ae013bd5f518a8bac348c310dea768b8/rest/route.go#L28-L38
test
ant0ine/go-json-rest
rest/recover.go
MiddlewareFunc
func (mw *RecoverMiddleware) MiddlewareFunc(h HandlerFunc) HandlerFunc { // set the default Logger if mw.Logger == nil { mw.Logger = log.New(os.Stderr, "", 0) } return func(w ResponseWriter, r *Request) { // catch user code's panic, and convert to http response defer func() { if reco := recover(); reco ...
go
func (mw *RecoverMiddleware) MiddlewareFunc(h HandlerFunc) HandlerFunc { // set the default Logger if mw.Logger == nil { mw.Logger = log.New(os.Stderr, "", 0) } return func(w ResponseWriter, r *Request) { // catch user code's panic, and convert to http response defer func() { if reco := recover(); reco ...
[ "func", "(", "mw", "*", "RecoverMiddleware", ")", "MiddlewareFunc", "(", "h", "HandlerFunc", ")", "HandlerFunc", "{", "if", "mw", ".", "Logger", "==", "nil", "{", "mw", ".", "Logger", "=", "log", ".", "New", "(", "os", ".", "Stderr", ",", "\"\"", ","...
// MiddlewareFunc makes RecoverMiddleware implement the Middleware interface.
[ "MiddlewareFunc", "makes", "RecoverMiddleware", "implement", "the", "Middleware", "interface", "." ]
ebb33769ae013bd5f518a8bac348c310dea768b8
https://github.com/ant0ine/go-json-rest/blob/ebb33769ae013bd5f518a8bac348c310dea768b8/rest/recover.go#L29-L59
test
ant0ine/go-json-rest
rest/middleware.go
WrapMiddlewares
func WrapMiddlewares(middlewares []Middleware, handler HandlerFunc) HandlerFunc { wrapped := handler for i := len(middlewares) - 1; i >= 0; i-- { wrapped = middlewares[i].MiddlewareFunc(wrapped) } return wrapped }
go
func WrapMiddlewares(middlewares []Middleware, handler HandlerFunc) HandlerFunc { wrapped := handler for i := len(middlewares) - 1; i >= 0; i-- { wrapped = middlewares[i].MiddlewareFunc(wrapped) } return wrapped }
[ "func", "WrapMiddlewares", "(", "middlewares", "[", "]", "Middleware", ",", "handler", "HandlerFunc", ")", "HandlerFunc", "{", "wrapped", ":=", "handler", "\n", "for", "i", ":=", "len", "(", "middlewares", ")", "-", "1", ";", "i", ">=", "0", ";", "i", ...
// WrapMiddlewares calls the MiddlewareFunc methods in the reverse order and returns an HandlerFunc // ready to be executed. This can be used to wrap a set of middlewares, post routing, on a per Route // basis.
[ "WrapMiddlewares", "calls", "the", "MiddlewareFunc", "methods", "in", "the", "reverse", "order", "and", "returns", "an", "HandlerFunc", "ready", "to", "be", "executed", ".", "This", "can", "be", "used", "to", "wrap", "a", "set", "of", "middlewares", "post", ...
ebb33769ae013bd5f518a8bac348c310dea768b8
https://github.com/ant0ine/go-json-rest/blob/ebb33769ae013bd5f518a8bac348c310dea768b8/rest/middleware.go#L43-L49
test
ant0ine/go-json-rest
rest/gzip.go
MiddlewareFunc
func (mw *GzipMiddleware) MiddlewareFunc(h HandlerFunc) HandlerFunc { return func(w ResponseWriter, r *Request) { // gzip support enabled canGzip := strings.Contains(r.Header.Get("Accept-Encoding"), "gzip") // client accepts gzip ? writer := &gzipResponseWriter{w, false, canGzip, nil} defer func() { // ne...
go
func (mw *GzipMiddleware) MiddlewareFunc(h HandlerFunc) HandlerFunc { return func(w ResponseWriter, r *Request) { // gzip support enabled canGzip := strings.Contains(r.Header.Get("Accept-Encoding"), "gzip") // client accepts gzip ? writer := &gzipResponseWriter{w, false, canGzip, nil} defer func() { // ne...
[ "func", "(", "mw", "*", "GzipMiddleware", ")", "MiddlewareFunc", "(", "h", "HandlerFunc", ")", "HandlerFunc", "{", "return", "func", "(", "w", "ResponseWriter", ",", "r", "*", "Request", ")", "{", "canGzip", ":=", "strings", ".", "Contains", "(", "r", "....
// MiddlewareFunc makes GzipMiddleware implement the Middleware interface.
[ "MiddlewareFunc", "makes", "GzipMiddleware", "implement", "the", "Middleware", "interface", "." ]
ebb33769ae013bd5f518a8bac348c310dea768b8
https://github.com/ant0ine/go-json-rest/blob/ebb33769ae013bd5f518a8bac348c310dea768b8/rest/gzip.go#L18-L33
test
ant0ine/go-json-rest
rest/gzip.go
WriteHeader
func (w *gzipResponseWriter) WriteHeader(code int) { // Always set the Vary header, even if this particular request // is not gzipped. w.Header().Add("Vary", "Accept-Encoding") if w.canGzip { w.Header().Set("Content-Encoding", "gzip") } w.ResponseWriter.WriteHeader(code) w.wroteHeader = true }
go
func (w *gzipResponseWriter) WriteHeader(code int) { // Always set the Vary header, even if this particular request // is not gzipped. w.Header().Add("Vary", "Accept-Encoding") if w.canGzip { w.Header().Set("Content-Encoding", "gzip") } w.ResponseWriter.WriteHeader(code) w.wroteHeader = true }
[ "func", "(", "w", "*", "gzipResponseWriter", ")", "WriteHeader", "(", "code", "int", ")", "{", "w", ".", "Header", "(", ")", ".", "Add", "(", "\"Vary\"", ",", "\"Accept-Encoding\"", ")", "\n", "if", "w", ".", "canGzip", "{", "w", ".", "Header", "(", ...
// Set the right headers for gzip encoded responses.
[ "Set", "the", "right", "headers", "for", "gzip", "encoded", "responses", "." ]
ebb33769ae013bd5f518a8bac348c310dea768b8
https://github.com/ant0ine/go-json-rest/blob/ebb33769ae013bd5f518a8bac348c310dea768b8/rest/gzip.go#L51-L63
test
ant0ine/go-json-rest
rest/gzip.go
Hijack
func (w *gzipResponseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error) { hijacker := w.ResponseWriter.(http.Hijacker) return hijacker.Hijack() }
go
func (w *gzipResponseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error) { hijacker := w.ResponseWriter.(http.Hijacker) return hijacker.Hijack() }
[ "func", "(", "w", "*", "gzipResponseWriter", ")", "Hijack", "(", ")", "(", "net", ".", "Conn", ",", "*", "bufio", ".", "ReadWriter", ",", "error", ")", "{", "hijacker", ":=", "w", ".", "ResponseWriter", ".", "(", "http", ".", "Hijacker", ")", "\n", ...
// Provided in order to implement the http.Hijacker interface.
[ "Provided", "in", "order", "to", "implement", "the", "http", ".", "Hijacker", "interface", "." ]
ebb33769ae013bd5f518a8bac348c310dea768b8
https://github.com/ant0ine/go-json-rest/blob/ebb33769ae013bd5f518a8bac348c310dea768b8/rest/gzip.go#L96-L99
test
ant0ine/go-json-rest
rest/gzip.go
Write
func (w *gzipResponseWriter) Write(b []byte) (int, error) { if !w.wroteHeader { w.WriteHeader(http.StatusOK) } writer := w.ResponseWriter.(http.ResponseWriter) if w.canGzip { // Write can be called multiple times for a given response. // (see the streaming example: // https://github.com/ant0ine/go-json-r...
go
func (w *gzipResponseWriter) Write(b []byte) (int, error) { if !w.wroteHeader { w.WriteHeader(http.StatusOK) } writer := w.ResponseWriter.(http.ResponseWriter) if w.canGzip { // Write can be called multiple times for a given response. // (see the streaming example: // https://github.com/ant0ine/go-json-r...
[ "func", "(", "w", "*", "gzipResponseWriter", ")", "Write", "(", "b", "[", "]", "byte", ")", "(", "int", ",", "error", ")", "{", "if", "!", "w", ".", "wroteHeader", "{", "w", ".", "WriteHeader", "(", "http", ".", "StatusOK", ")", "\n", "}", "\n", ...
// Make sure the local WriteHeader is called, and encode the payload if necessary. // Provided in order to implement the http.ResponseWriter interface.
[ "Make", "sure", "the", "local", "WriteHeader", "is", "called", "and", "encode", "the", "payload", "if", "necessary", ".", "Provided", "in", "order", "to", "implement", "the", "http", ".", "ResponseWriter", "interface", "." ]
ebb33769ae013bd5f518a8bac348c310dea768b8
https://github.com/ant0ine/go-json-rest/blob/ebb33769ae013bd5f518a8bac348c310dea768b8/rest/gzip.go#L103-L132
test
ant0ine/go-json-rest
rest/auth_basic.go
MiddlewareFunc
func (mw *AuthBasicMiddleware) MiddlewareFunc(handler HandlerFunc) HandlerFunc { if mw.Realm == "" { log.Fatal("Realm is required") } if mw.Authenticator == nil { log.Fatal("Authenticator is required") } if mw.Authorizator == nil { mw.Authorizator = func(userId string, request *Request) bool { return t...
go
func (mw *AuthBasicMiddleware) MiddlewareFunc(handler HandlerFunc) HandlerFunc { if mw.Realm == "" { log.Fatal("Realm is required") } if mw.Authenticator == nil { log.Fatal("Authenticator is required") } if mw.Authorizator == nil { mw.Authorizator = func(userId string, request *Request) bool { return t...
[ "func", "(", "mw", "*", "AuthBasicMiddleware", ")", "MiddlewareFunc", "(", "handler", "HandlerFunc", ")", "HandlerFunc", "{", "if", "mw", ".", "Realm", "==", "\"\"", "{", "log", ".", "Fatal", "(", "\"Realm is required\"", ")", "\n", "}", "\n", "if", "mw", ...
// MiddlewareFunc makes AuthBasicMiddleware implement the Middleware interface.
[ "MiddlewareFunc", "makes", "AuthBasicMiddleware", "implement", "the", "Middleware", "interface", "." ]
ebb33769ae013bd5f518a8bac348c310dea768b8
https://github.com/ant0ine/go-json-rest/blob/ebb33769ae013bd5f518a8bac348c310dea768b8/rest/auth_basic.go#L30-L75
test
ant0ine/go-json-rest
rest/trie/impl.go
printDebug
func (n *node) printDebug(level int) { level++ // *splat branch if n.SplatChild != nil { printFPadding(level, "*splat\n") n.SplatChild.printDebug(level) } // :param branch if n.ParamChild != nil { printFPadding(level, ":param\n") n.ParamChild.printDebug(level) } // #param branch if n.RelaxedChild != ni...
go
func (n *node) printDebug(level int) { level++ // *splat branch if n.SplatChild != nil { printFPadding(level, "*splat\n") n.SplatChild.printDebug(level) } // :param branch if n.ParamChild != nil { printFPadding(level, ":param\n") n.ParamChild.printDebug(level) } // #param branch if n.RelaxedChild != ni...
[ "func", "(", "n", "*", "node", ")", "printDebug", "(", "level", "int", ")", "{", "level", "++", "\n", "if", "n", ".", "SplatChild", "!=", "nil", "{", "printFPadding", "(", "level", ",", "\"*splat\\n\"", ")", "\n", "\\n", "\n", "}", "\n", "n", ".", ...
// Private function for now
[ "Private", "function", "for", "now" ]
ebb33769ae013bd5f518a8bac348c310dea768b8
https://github.com/ant0ine/go-json-rest/blob/ebb33769ae013bd5f518a8bac348c310dea768b8/rest/trie/impl.go#L217-L239
test
ant0ine/go-json-rest
rest/trie/impl.go
AddRoute
func (t *Trie) AddRoute(httpMethod, pathExp string, route interface{}) error { return t.root.addRoute(httpMethod, pathExp, route, []string{}) }
go
func (t *Trie) AddRoute(httpMethod, pathExp string, route interface{}) error { return t.root.addRoute(httpMethod, pathExp, route, []string{}) }
[ "func", "(", "t", "*", "Trie", ")", "AddRoute", "(", "httpMethod", ",", "pathExp", "string", ",", "route", "interface", "{", "}", ")", "error", "{", "return", "t", ".", "root", ".", "addRoute", "(", "httpMethod", ",", "pathExp", ",", "route", ",", "[...
// Insert the route in the Trie following or creating the nodes corresponding to the path.
[ "Insert", "the", "route", "in", "the", "Trie", "following", "or", "creating", "the", "nodes", "corresponding", "to", "the", "path", "." ]
ebb33769ae013bd5f518a8bac348c310dea768b8
https://github.com/ant0ine/go-json-rest/blob/ebb33769ae013bd5f518a8bac348c310dea768b8/rest/trie/impl.go#L349-L351
test
ant0ine/go-json-rest
rest/trie/impl.go
printDebug
func (t *Trie) printDebug() { fmt.Print("<trie>\n") t.root.printDebug(0) fmt.Print("</trie>\n") }
go
func (t *Trie) printDebug() { fmt.Print("<trie>\n") t.root.printDebug(0) fmt.Print("</trie>\n") }
[ "func", "(", "t", "*", "Trie", ")", "printDebug", "(", ")", "{", "fmt", ".", "Print", "(", "\"<trie>\\n\"", ")", "\n", "\\n", "\n", "t", ".", "root", ".", "printDebug", "(", "0", ")", "\n", "}" ]
// Private function for now.
[ "Private", "function", "for", "now", "." ]
ebb33769ae013bd5f518a8bac348c310dea768b8
https://github.com/ant0ine/go-json-rest/blob/ebb33769ae013bd5f518a8bac348c310dea768b8/rest/trie/impl.go#L359-L363
test
ant0ine/go-json-rest
rest/trie/impl.go
FindRoutes
func (t *Trie) FindRoutes(httpMethod, path string) []*Match { context := newFindContext() matches := []*Match{} context.matchFunc = func(httpMethod, path string, node *node) { if node.HttpMethodToRoute[httpMethod] != nil { // path and method match, found a route ! matches = append( matches, &Match{ ...
go
func (t *Trie) FindRoutes(httpMethod, path string) []*Match { context := newFindContext() matches := []*Match{} context.matchFunc = func(httpMethod, path string, node *node) { if node.HttpMethodToRoute[httpMethod] != nil { // path and method match, found a route ! matches = append( matches, &Match{ ...
[ "func", "(", "t", "*", "Trie", ")", "FindRoutes", "(", "httpMethod", ",", "path", "string", ")", "[", "]", "*", "Match", "{", "context", ":=", "newFindContext", "(", ")", "\n", "matches", ":=", "[", "]", "*", "Match", "{", "}", "\n", "context", "."...
// Given a path and an http method, return all the matching routes.
[ "Given", "a", "path", "and", "an", "http", "method", "return", "all", "the", "matching", "routes", "." ]
ebb33769ae013bd5f518a8bac348c310dea768b8
https://github.com/ant0ine/go-json-rest/blob/ebb33769ae013bd5f518a8bac348c310dea768b8/rest/trie/impl.go#L366-L383
test
ant0ine/go-json-rest
rest/trie/impl.go
FindRoutesAndPathMatched
func (t *Trie) FindRoutesAndPathMatched(httpMethod, path string) ([]*Match, bool) { context := newFindContext() pathMatched := false matches := []*Match{} context.matchFunc = func(httpMethod, path string, node *node) { pathMatched = true if node.HttpMethodToRoute[httpMethod] != nil { // path and method match...
go
func (t *Trie) FindRoutesAndPathMatched(httpMethod, path string) ([]*Match, bool) { context := newFindContext() pathMatched := false matches := []*Match{} context.matchFunc = func(httpMethod, path string, node *node) { pathMatched = true if node.HttpMethodToRoute[httpMethod] != nil { // path and method match...
[ "func", "(", "t", "*", "Trie", ")", "FindRoutesAndPathMatched", "(", "httpMethod", ",", "path", "string", ")", "(", "[", "]", "*", "Match", ",", "bool", ")", "{", "context", ":=", "newFindContext", "(", ")", "\n", "pathMatched", ":=", "false", "\n", "m...
// Same as FindRoutes, but return in addition a boolean indicating if the path was matched. // Useful to return 405
[ "Same", "as", "FindRoutes", "but", "return", "in", "addition", "a", "boolean", "indicating", "if", "the", "path", "was", "matched", ".", "Useful", "to", "return", "405" ]
ebb33769ae013bd5f518a8bac348c310dea768b8
https://github.com/ant0ine/go-json-rest/blob/ebb33769ae013bd5f518a8bac348c310dea768b8/rest/trie/impl.go#L387-L406
test
ant0ine/go-json-rest
rest/trie/impl.go
FindRoutesForPath
func (t *Trie) FindRoutesForPath(path string) []*Match { context := newFindContext() matches := []*Match{} context.matchFunc = func(httpMethod, path string, node *node) { params := context.paramsAsMap() for _, route := range node.HttpMethodToRoute { matches = append( matches, &Match{ Route: rout...
go
func (t *Trie) FindRoutesForPath(path string) []*Match { context := newFindContext() matches := []*Match{} context.matchFunc = func(httpMethod, path string, node *node) { params := context.paramsAsMap() for _, route := range node.HttpMethodToRoute { matches = append( matches, &Match{ Route: rout...
[ "func", "(", "t", "*", "Trie", ")", "FindRoutesForPath", "(", "path", "string", ")", "[", "]", "*", "Match", "{", "context", ":=", "newFindContext", "(", ")", "\n", "matches", ":=", "[", "]", "*", "Match", "{", "}", "\n", "context", ".", "matchFunc",...
// Given a path, and whatever the http method, return all the matching routes.
[ "Given", "a", "path", "and", "whatever", "the", "http", "method", "return", "all", "the", "matching", "routes", "." ]
ebb33769ae013bd5f518a8bac348c310dea768b8
https://github.com/ant0ine/go-json-rest/blob/ebb33769ae013bd5f518a8bac348c310dea768b8/rest/trie/impl.go#L409-L426
test
ant0ine/go-json-rest
rest/api.go
Use
func (api *Api) Use(middlewares ...Middleware) { api.stack = append(api.stack, middlewares...) }
go
func (api *Api) Use(middlewares ...Middleware) { api.stack = append(api.stack, middlewares...) }
[ "func", "(", "api", "*", "Api", ")", "Use", "(", "middlewares", "...", "Middleware", ")", "{", "api", ".", "stack", "=", "append", "(", "api", ".", "stack", ",", "middlewares", "...", ")", "\n", "}" ]
// Use pushes one or multiple middlewares to the stack for middlewares // maintained in the Api object.
[ "Use", "pushes", "one", "or", "multiple", "middlewares", "to", "the", "stack", "for", "middlewares", "maintained", "in", "the", "Api", "object", "." ]
ebb33769ae013bd5f518a8bac348c310dea768b8
https://github.com/ant0ine/go-json-rest/blob/ebb33769ae013bd5f518a8bac348c310dea768b8/rest/api.go#L23-L25
test
ant0ine/go-json-rest
rest/api.go
MakeHandler
func (api *Api) MakeHandler() http.Handler { var appFunc HandlerFunc if api.app != nil { appFunc = api.app.AppFunc() } else { appFunc = func(w ResponseWriter, r *Request) {} } return http.HandlerFunc( adapterFunc( WrapMiddlewares(api.stack, appFunc), ), ) }
go
func (api *Api) MakeHandler() http.Handler { var appFunc HandlerFunc if api.app != nil { appFunc = api.app.AppFunc() } else { appFunc = func(w ResponseWriter, r *Request) {} } return http.HandlerFunc( adapterFunc( WrapMiddlewares(api.stack, appFunc), ), ) }
[ "func", "(", "api", "*", "Api", ")", "MakeHandler", "(", ")", "http", ".", "Handler", "{", "var", "appFunc", "HandlerFunc", "\n", "if", "api", ".", "app", "!=", "nil", "{", "appFunc", "=", "api", ".", "app", ".", "AppFunc", "(", ")", "\n", "}", "...
// MakeHandler wraps all the Middlewares of the stack and the App together, and returns an // http.Handler ready to be used. If the Middleware stack is empty the App is used directly. If the // App is nil, a HandlerFunc that does nothing is used instead.
[ "MakeHandler", "wraps", "all", "the", "Middlewares", "of", "the", "stack", "and", "the", "App", "together", "and", "returns", "an", "http", ".", "Handler", "ready", "to", "be", "used", ".", "If", "the", "Middleware", "stack", "is", "empty", "the", "App", ...
ebb33769ae013bd5f518a8bac348c310dea768b8
https://github.com/ant0ine/go-json-rest/blob/ebb33769ae013bd5f518a8bac348c310dea768b8/rest/api.go#L35-L47
test
ant0ine/go-json-rest
rest/powered_by.go
MiddlewareFunc
func (mw *PoweredByMiddleware) MiddlewareFunc(h HandlerFunc) HandlerFunc { poweredBy := xPoweredByDefault if mw.XPoweredBy != "" { poweredBy = mw.XPoweredBy } return func(w ResponseWriter, r *Request) { w.Header().Add("X-Powered-By", poweredBy) // call the handler h(w, r) } }
go
func (mw *PoweredByMiddleware) MiddlewareFunc(h HandlerFunc) HandlerFunc { poweredBy := xPoweredByDefault if mw.XPoweredBy != "" { poweredBy = mw.XPoweredBy } return func(w ResponseWriter, r *Request) { w.Header().Add("X-Powered-By", poweredBy) // call the handler h(w, r) } }
[ "func", "(", "mw", "*", "PoweredByMiddleware", ")", "MiddlewareFunc", "(", "h", "HandlerFunc", ")", "HandlerFunc", "{", "poweredBy", ":=", "xPoweredByDefault", "\n", "if", "mw", ".", "XPoweredBy", "!=", "\"\"", "{", "poweredBy", "=", "mw", ".", "XPoweredBy", ...
// MiddlewareFunc makes PoweredByMiddleware implement the Middleware interface.
[ "MiddlewareFunc", "makes", "PoweredByMiddleware", "implement", "the", "Middleware", "interface", "." ]
ebb33769ae013bd5f518a8bac348c310dea768b8
https://github.com/ant0ine/go-json-rest/blob/ebb33769ae013bd5f518a8bac348c310dea768b8/rest/powered_by.go#L14-L29
test
ant0ine/go-json-rest
rest/status.go
MiddlewareFunc
func (mw *StatusMiddleware) MiddlewareFunc(h HandlerFunc) HandlerFunc { mw.start = time.Now() mw.pid = os.Getpid() mw.responseCounts = map[string]int{} mw.totalResponseTime = time.Time{} return func(w ResponseWriter, r *Request) { // call the handler h(w, r) if r.Env["STATUS_CODE"] == nil { log.Fatal(...
go
func (mw *StatusMiddleware) MiddlewareFunc(h HandlerFunc) HandlerFunc { mw.start = time.Now() mw.pid = os.Getpid() mw.responseCounts = map[string]int{} mw.totalResponseTime = time.Time{} return func(w ResponseWriter, r *Request) { // call the handler h(w, r) if r.Env["STATUS_CODE"] == nil { log.Fatal(...
[ "func", "(", "mw", "*", "StatusMiddleware", ")", "MiddlewareFunc", "(", "h", "HandlerFunc", ")", "HandlerFunc", "{", "mw", ".", "start", "=", "time", ".", "Now", "(", ")", "\n", "mw", ".", "pid", "=", "os", ".", "Getpid", "(", ")", "\n", "mw", ".",...
// MiddlewareFunc makes StatusMiddleware implement the Middleware interface.
[ "MiddlewareFunc", "makes", "StatusMiddleware", "implement", "the", "Middleware", "interface", "." ]
ebb33769ae013bd5f518a8bac348c310dea768b8
https://github.com/ant0ine/go-json-rest/blob/ebb33769ae013bd5f518a8bac348c310dea768b8/rest/status.go#L23-L52
test
ant0ine/go-json-rest
rest/status.go
GetStatus
func (mw *StatusMiddleware) GetStatus() *Status { mw.lock.RLock() now := time.Now() uptime := now.Sub(mw.start) totalCount := 0 for _, count := range mw.responseCounts { totalCount += count } totalResponseTime := mw.totalResponseTime.Sub(time.Time{}) averageResponseTime := time.Duration(0) if totalCoun...
go
func (mw *StatusMiddleware) GetStatus() *Status { mw.lock.RLock() now := time.Now() uptime := now.Sub(mw.start) totalCount := 0 for _, count := range mw.responseCounts { totalCount += count } totalResponseTime := mw.totalResponseTime.Sub(time.Time{}) averageResponseTime := time.Duration(0) if totalCoun...
[ "func", "(", "mw", "*", "StatusMiddleware", ")", "GetStatus", "(", ")", "*", "Status", "{", "mw", ".", "lock", ".", "RLock", "(", ")", "\n", "now", ":=", "time", ".", "Now", "(", ")", "\n", "uptime", ":=", "now", ".", "Sub", "(", "mw", ".", "st...
// GetStatus computes and returns a Status object based on the request informations accumulated // since the start of the process.
[ "GetStatus", "computes", "and", "returns", "a", "Status", "object", "based", "on", "the", "request", "informations", "accumulated", "since", "the", "start", "of", "the", "process", "." ]
ebb33769ae013bd5f518a8bac348c310dea768b8
https://github.com/ant0ine/go-json-rest/blob/ebb33769ae013bd5f518a8bac348c310dea768b8/rest/status.go#L91-L129
test
ant0ine/go-json-rest
rest/jsonp.go
MiddlewareFunc
func (mw *JsonpMiddleware) MiddlewareFunc(h HandlerFunc) HandlerFunc { if mw.CallbackNameKey == "" { mw.CallbackNameKey = "callback" } return func(w ResponseWriter, r *Request) { callbackName := r.URL.Query().Get(mw.CallbackNameKey) // TODO validate the callbackName ? if callbackName != "" { // the cl...
go
func (mw *JsonpMiddleware) MiddlewareFunc(h HandlerFunc) HandlerFunc { if mw.CallbackNameKey == "" { mw.CallbackNameKey = "callback" } return func(w ResponseWriter, r *Request) { callbackName := r.URL.Query().Get(mw.CallbackNameKey) // TODO validate the callbackName ? if callbackName != "" { // the cl...
[ "func", "(", "mw", "*", "JsonpMiddleware", ")", "MiddlewareFunc", "(", "h", "HandlerFunc", ")", "HandlerFunc", "{", "if", "mw", ".", "CallbackNameKey", "==", "\"\"", "{", "mw", ".", "CallbackNameKey", "=", "\"callback\"", "\n", "}", "\n", "return", "func", ...
// MiddlewareFunc returns a HandlerFunc that implements the middleware.
[ "MiddlewareFunc", "returns", "a", "HandlerFunc", "that", "implements", "the", "middleware", "." ]
ebb33769ae013bd5f518a8bac348c310dea768b8
https://github.com/ant0ine/go-json-rest/blob/ebb33769ae013bd5f518a8bac348c310dea768b8/rest/jsonp.go#L20-L42
test
ant0ine/go-json-rest
rest/jsonp.go
Flush
func (w *jsonpResponseWriter) Flush() { if !w.wroteHeader { w.WriteHeader(http.StatusOK) } flusher := w.ResponseWriter.(http.Flusher) flusher.Flush() }
go
func (w *jsonpResponseWriter) Flush() { if !w.wroteHeader { w.WriteHeader(http.StatusOK) } flusher := w.ResponseWriter.(http.Flusher) flusher.Flush() }
[ "func", "(", "w", "*", "jsonpResponseWriter", ")", "Flush", "(", ")", "{", "if", "!", "w", ".", "wroteHeader", "{", "w", ".", "WriteHeader", "(", "http", ".", "StatusOK", ")", "\n", "}", "\n", "flusher", ":=", "w", ".", "ResponseWriter", ".", "(", ...
// Make sure the local WriteHeader is called, and call the parent Flush. // Provided in order to implement the http.Flusher interface.
[ "Make", "sure", "the", "local", "WriteHeader", "is", "called", "and", "call", "the", "parent", "Flush", ".", "Provided", "in", "order", "to", "implement", "the", "http", ".", "Flusher", "interface", "." ]
ebb33769ae013bd5f518a8bac348c310dea768b8
https://github.com/ant0ine/go-json-rest/blob/ebb33769ae013bd5f518a8bac348c310dea768b8/rest/jsonp.go#L84-L90
test
ant0ine/go-json-rest
rest/access_log_json.go
MiddlewareFunc
func (mw *AccessLogJsonMiddleware) MiddlewareFunc(h HandlerFunc) HandlerFunc { // set the default Logger if mw.Logger == nil { mw.Logger = log.New(os.Stderr, "", 0) } return func(w ResponseWriter, r *Request) { // call the handler h(w, r) mw.Logger.Printf("%s", makeAccessLogJsonRecord(r).asJson()) } }
go
func (mw *AccessLogJsonMiddleware) MiddlewareFunc(h HandlerFunc) HandlerFunc { // set the default Logger if mw.Logger == nil { mw.Logger = log.New(os.Stderr, "", 0) } return func(w ResponseWriter, r *Request) { // call the handler h(w, r) mw.Logger.Printf("%s", makeAccessLogJsonRecord(r).asJson()) } }
[ "func", "(", "mw", "*", "AccessLogJsonMiddleware", ")", "MiddlewareFunc", "(", "h", "HandlerFunc", ")", "HandlerFunc", "{", "if", "mw", ".", "Logger", "==", "nil", "{", "mw", ".", "Logger", "=", "log", ".", "New", "(", "os", ".", "Stderr", ",", "\"\"",...
// MiddlewareFunc makes AccessLogJsonMiddleware implement the Middleware interface.
[ "MiddlewareFunc", "makes", "AccessLogJsonMiddleware", "implement", "the", "Middleware", "interface", "." ]
ebb33769ae013bd5f518a8bac348c310dea768b8
https://github.com/ant0ine/go-json-rest/blob/ebb33769ae013bd5f518a8bac348c310dea768b8/rest/access_log_json.go#L21-L35
test