repo
stringlengths 5
54
| path
stringlengths 4
155
| func_name
stringlengths 1
118
| original_string
stringlengths 52
85.5k
| language
stringclasses 1
value | code
stringlengths 52
85.5k
| code_tokens
sequence | docstring
stringlengths 6
2.61k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 85
252
| partition
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|---|---|
moby/buildkit | client/workers.go | ListWorkers | func (c *Client) ListWorkers(ctx context.Context, opts ...ListWorkersOption) ([]*WorkerInfo, error) {
info := &ListWorkersInfo{}
for _, o := range opts {
o.SetListWorkersOption(info)
}
req := &controlapi.ListWorkersRequest{Filter: info.Filter}
resp, err := c.controlClient().ListWorkers(ctx, req)
if err != nil {
return nil, errors.Wrap(err, "failed to list workers")
}
var wi []*WorkerInfo
for _, w := range resp.Record {
wi = append(wi, &WorkerInfo{
ID: w.ID,
Labels: w.Labels,
Platforms: pb.ToSpecPlatforms(w.Platforms),
GCPolicy: fromAPIGCPolicy(w.GCPolicy),
})
}
return wi, nil
} | go | func (c *Client) ListWorkers(ctx context.Context, opts ...ListWorkersOption) ([]*WorkerInfo, error) {
info := &ListWorkersInfo{}
for _, o := range opts {
o.SetListWorkersOption(info)
}
req := &controlapi.ListWorkersRequest{Filter: info.Filter}
resp, err := c.controlClient().ListWorkers(ctx, req)
if err != nil {
return nil, errors.Wrap(err, "failed to list workers")
}
var wi []*WorkerInfo
for _, w := range resp.Record {
wi = append(wi, &WorkerInfo{
ID: w.ID,
Labels: w.Labels,
Platforms: pb.ToSpecPlatforms(w.Platforms),
GCPolicy: fromAPIGCPolicy(w.GCPolicy),
})
}
return wi, nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"ListWorkers",
"(",
"ctx",
"context",
".",
"Context",
",",
"opts",
"...",
"ListWorkersOption",
")",
"(",
"[",
"]",
"*",
"WorkerInfo",
",",
"error",
")",
"{",
"info",
":=",
"&",
"ListWorkersInfo",
"{",
"}",
"\n",
"for",
"_",
",",
"o",
":=",
"range",
"opts",
"{",
"o",
".",
"SetListWorkersOption",
"(",
"info",
")",
"\n",
"}",
"\n\n",
"req",
":=",
"&",
"controlapi",
".",
"ListWorkersRequest",
"{",
"Filter",
":",
"info",
".",
"Filter",
"}",
"\n",
"resp",
",",
"err",
":=",
"c",
".",
"controlClient",
"(",
")",
".",
"ListWorkers",
"(",
"ctx",
",",
"req",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"var",
"wi",
"[",
"]",
"*",
"WorkerInfo",
"\n\n",
"for",
"_",
",",
"w",
":=",
"range",
"resp",
".",
"Record",
"{",
"wi",
"=",
"append",
"(",
"wi",
",",
"&",
"WorkerInfo",
"{",
"ID",
":",
"w",
".",
"ID",
",",
"Labels",
":",
"w",
".",
"Labels",
",",
"Platforms",
":",
"pb",
".",
"ToSpecPlatforms",
"(",
"w",
".",
"Platforms",
")",
",",
"GCPolicy",
":",
"fromAPIGCPolicy",
"(",
"w",
".",
"GCPolicy",
")",
",",
"}",
")",
"\n",
"}",
"\n\n",
"return",
"wi",
",",
"nil",
"\n",
"}"
] | // ListWorkers lists all active workers | [
"ListWorkers",
"lists",
"all",
"active",
"workers"
] | 89851c6c69bca875dd64b5e9d5d6ec60ff437d74 | https://github.com/moby/buildkit/blob/89851c6c69bca875dd64b5e9d5d6ec60ff437d74/client/workers.go#L23-L47 | train |
moby/buildkit | frontend/dockerfile/instructions/commands.go | NewLabelCommand | func NewLabelCommand(k string, v string, NoExp bool) *LabelCommand {
kvp := KeyValuePair{Key: k, Value: v}
c := "LABEL "
c += kvp.String()
nc := withNameAndCode{code: c, name: "label"}
cmd := &LabelCommand{
withNameAndCode: nc,
Labels: KeyValuePairs{
kvp,
},
noExpand: NoExp,
}
return cmd
} | go | func NewLabelCommand(k string, v string, NoExp bool) *LabelCommand {
kvp := KeyValuePair{Key: k, Value: v}
c := "LABEL "
c += kvp.String()
nc := withNameAndCode{code: c, name: "label"}
cmd := &LabelCommand{
withNameAndCode: nc,
Labels: KeyValuePairs{
kvp,
},
noExpand: NoExp,
}
return cmd
} | [
"func",
"NewLabelCommand",
"(",
"k",
"string",
",",
"v",
"string",
",",
"NoExp",
"bool",
")",
"*",
"LabelCommand",
"{",
"kvp",
":=",
"KeyValuePair",
"{",
"Key",
":",
"k",
",",
"Value",
":",
"v",
"}",
"\n",
"c",
":=",
"\"",
"\"",
"\n",
"c",
"+=",
"kvp",
".",
"String",
"(",
")",
"\n",
"nc",
":=",
"withNameAndCode",
"{",
"code",
":",
"c",
",",
"name",
":",
"\"",
"\"",
"}",
"\n",
"cmd",
":=",
"&",
"LabelCommand",
"{",
"withNameAndCode",
":",
"nc",
",",
"Labels",
":",
"KeyValuePairs",
"{",
"kvp",
",",
"}",
",",
"noExpand",
":",
"NoExp",
",",
"}",
"\n",
"return",
"cmd",
"\n",
"}"
] | // NewLabelCommand creates a new 'LABEL' command | [
"NewLabelCommand",
"creates",
"a",
"new",
"LABEL",
"command"
] | 89851c6c69bca875dd64b5e9d5d6ec60ff437d74 | https://github.com/moby/buildkit/blob/89851c6c69bca875dd64b5e9d5d6ec60ff437d74/frontend/dockerfile/instructions/commands.go#L126-L139 | train |
moby/buildkit | frontend/dockerfile/instructions/commands.go | Sources | func (s SourcesAndDest) Sources() []string {
res := make([]string, len(s)-1)
copy(res, s[:len(s)-1])
return res
} | go | func (s SourcesAndDest) Sources() []string {
res := make([]string, len(s)-1)
copy(res, s[:len(s)-1])
return res
} | [
"func",
"(",
"s",
"SourcesAndDest",
")",
"Sources",
"(",
")",
"[",
"]",
"string",
"{",
"res",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"len",
"(",
"s",
")",
"-",
"1",
")",
"\n",
"copy",
"(",
"res",
",",
"s",
"[",
":",
"len",
"(",
"s",
")",
"-",
"1",
"]",
")",
"\n",
"return",
"res",
"\n",
"}"
] | // Sources list the source paths | [
"Sources",
"list",
"the",
"source",
"paths"
] | 89851c6c69bca875dd64b5e9d5d6ec60ff437d74 | https://github.com/moby/buildkit/blob/89851c6c69bca875dd64b5e9d5d6ec60ff437d74/frontend/dockerfile/instructions/commands.go#L163-L167 | train |
moby/buildkit | frontend/dockerfile/instructions/commands.go | CheckPlatform | func (c *StopSignalCommand) CheckPlatform(platform string) error {
if platform == "windows" {
return errors.New("The daemon on this platform does not support the command stopsignal")
}
return nil
} | go | func (c *StopSignalCommand) CheckPlatform(platform string) error {
if platform == "windows" {
return errors.New("The daemon on this platform does not support the command stopsignal")
}
return nil
} | [
"func",
"(",
"c",
"*",
"StopSignalCommand",
")",
"CheckPlatform",
"(",
"platform",
"string",
")",
"error",
"{",
"if",
"platform",
"==",
"\"",
"\"",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // CheckPlatform checks that the command is supported in the target platform | [
"CheckPlatform",
"checks",
"that",
"the",
"command",
"is",
"supported",
"in",
"the",
"target",
"platform"
] | 89851c6c69bca875dd64b5e9d5d6ec60ff437d74 | https://github.com/moby/buildkit/blob/89851c6c69bca875dd64b5e9d5d6ec60ff437d74/frontend/dockerfile/instructions/commands.go#L354-L359 | train |
moby/buildkit | frontend/dockerfile/instructions/commands.go | AddCommand | func (s *Stage) AddCommand(cmd Command) {
// todo: validate cmd type
s.Commands = append(s.Commands, cmd)
} | go | func (s *Stage) AddCommand(cmd Command) {
// todo: validate cmd type
s.Commands = append(s.Commands, cmd)
} | [
"func",
"(",
"s",
"*",
"Stage",
")",
"AddCommand",
"(",
"cmd",
"Command",
")",
"{",
"// todo: validate cmd type",
"s",
".",
"Commands",
"=",
"append",
"(",
"s",
".",
"Commands",
",",
"cmd",
")",
"\n",
"}"
] | // AddCommand to the stage | [
"AddCommand",
"to",
"the",
"stage"
] | 89851c6c69bca875dd64b5e9d5d6ec60ff437d74 | https://github.com/moby/buildkit/blob/89851c6c69bca875dd64b5e9d5d6ec60ff437d74/frontend/dockerfile/instructions/commands.go#L406-L409 | train |
moby/buildkit | frontend/dockerfile/instructions/commands.go | IsCurrentStage | func IsCurrentStage(s []Stage, name string) bool {
if len(s) == 0 {
return false
}
return s[len(s)-1].Name == name
} | go | func IsCurrentStage(s []Stage, name string) bool {
if len(s) == 0 {
return false
}
return s[len(s)-1].Name == name
} | [
"func",
"IsCurrentStage",
"(",
"s",
"[",
"]",
"Stage",
",",
"name",
"string",
")",
"bool",
"{",
"if",
"len",
"(",
"s",
")",
"==",
"0",
"{",
"return",
"false",
"\n",
"}",
"\n",
"return",
"s",
"[",
"len",
"(",
"s",
")",
"-",
"1",
"]",
".",
"Name",
"==",
"name",
"\n",
"}"
] | // IsCurrentStage check if the stage name is the current stage | [
"IsCurrentStage",
"check",
"if",
"the",
"stage",
"name",
"is",
"the",
"current",
"stage"
] | 89851c6c69bca875dd64b5e9d5d6ec60ff437d74 | https://github.com/moby/buildkit/blob/89851c6c69bca875dd64b5e9d5d6ec60ff437d74/frontend/dockerfile/instructions/commands.go#L412-L417 | train |
moby/buildkit | frontend/dockerfile/instructions/commands.go | CurrentStage | func CurrentStage(s []Stage) (*Stage, error) {
if len(s) == 0 {
return nil, errors.New("No build stage in current context")
}
return &s[len(s)-1], nil
} | go | func CurrentStage(s []Stage) (*Stage, error) {
if len(s) == 0 {
return nil, errors.New("No build stage in current context")
}
return &s[len(s)-1], nil
} | [
"func",
"CurrentStage",
"(",
"s",
"[",
"]",
"Stage",
")",
"(",
"*",
"Stage",
",",
"error",
")",
"{",
"if",
"len",
"(",
"s",
")",
"==",
"0",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"&",
"s",
"[",
"len",
"(",
"s",
")",
"-",
"1",
"]",
",",
"nil",
"\n",
"}"
] | // CurrentStage return the last stage in a slice | [
"CurrentStage",
"return",
"the",
"last",
"stage",
"in",
"a",
"slice"
] | 89851c6c69bca875dd64b5e9d5d6ec60ff437d74 | https://github.com/moby/buildkit/blob/89851c6c69bca875dd64b5e9d5d6ec60ff437d74/frontend/dockerfile/instructions/commands.go#L420-L425 | train |
moby/buildkit | frontend/dockerfile/instructions/commands.go | HasStage | func HasStage(s []Stage, name string) (int, bool) {
for i, stage := range s {
// Stage name is case-insensitive by design
if strings.EqualFold(stage.Name, name) {
return i, true
}
}
return -1, false
} | go | func HasStage(s []Stage, name string) (int, bool) {
for i, stage := range s {
// Stage name is case-insensitive by design
if strings.EqualFold(stage.Name, name) {
return i, true
}
}
return -1, false
} | [
"func",
"HasStage",
"(",
"s",
"[",
"]",
"Stage",
",",
"name",
"string",
")",
"(",
"int",
",",
"bool",
")",
"{",
"for",
"i",
",",
"stage",
":=",
"range",
"s",
"{",
"// Stage name is case-insensitive by design",
"if",
"strings",
".",
"EqualFold",
"(",
"stage",
".",
"Name",
",",
"name",
")",
"{",
"return",
"i",
",",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"-",
"1",
",",
"false",
"\n",
"}"
] | // HasStage looks for the presence of a given stage name | [
"HasStage",
"looks",
"for",
"the",
"presence",
"of",
"a",
"given",
"stage",
"name"
] | 89851c6c69bca875dd64b5e9d5d6ec60ff437d74 | https://github.com/moby/buildkit/blob/89851c6c69bca875dd64b5e9d5d6ec60ff437d74/frontend/dockerfile/instructions/commands.go#L428-L436 | train |
moby/buildkit | frontend/dockerfile/instructions/support.go | handleJSONArgs | func handleJSONArgs(args []string, attributes map[string]bool) []string {
if len(args) == 0 {
return []string{}
}
if attributes != nil && attributes["json"] {
return args
}
// literal string command, not an exec array
return []string{strings.Join(args, " ")}
} | go | func handleJSONArgs(args []string, attributes map[string]bool) []string {
if len(args) == 0 {
return []string{}
}
if attributes != nil && attributes["json"] {
return args
}
// literal string command, not an exec array
return []string{strings.Join(args, " ")}
} | [
"func",
"handleJSONArgs",
"(",
"args",
"[",
"]",
"string",
",",
"attributes",
"map",
"[",
"string",
"]",
"bool",
")",
"[",
"]",
"string",
"{",
"if",
"len",
"(",
"args",
")",
"==",
"0",
"{",
"return",
"[",
"]",
"string",
"{",
"}",
"\n",
"}",
"\n\n",
"if",
"attributes",
"!=",
"nil",
"&&",
"attributes",
"[",
"\"",
"\"",
"]",
"{",
"return",
"args",
"\n",
"}",
"\n\n",
"// literal string command, not an exec array",
"return",
"[",
"]",
"string",
"{",
"strings",
".",
"Join",
"(",
"args",
",",
"\"",
"\"",
")",
"}",
"\n",
"}"
] | // handleJSONArgs parses command passed to CMD, ENTRYPOINT, RUN and SHELL instruction in Dockerfile
// for exec form it returns untouched args slice
// for shell form it returns concatenated args as the first element of a slice | [
"handleJSONArgs",
"parses",
"command",
"passed",
"to",
"CMD",
"ENTRYPOINT",
"RUN",
"and",
"SHELL",
"instruction",
"in",
"Dockerfile",
"for",
"exec",
"form",
"it",
"returns",
"untouched",
"args",
"slice",
"for",
"shell",
"form",
"it",
"returns",
"concatenated",
"args",
"as",
"the",
"first",
"element",
"of",
"a",
"slice"
] | 89851c6c69bca875dd64b5e9d5d6ec60ff437d74 | https://github.com/moby/buildkit/blob/89851c6c69bca875dd64b5e9d5d6ec60ff437d74/frontend/dockerfile/instructions/support.go#L8-L19 | train |
moby/buildkit | client/client.go | New | func New(ctx context.Context, address string, opts ...ClientOpt) (*Client, error) {
gopts := []grpc.DialOption{}
needDialer := true
needWithInsecure := true
for _, o := range opts {
if _, ok := o.(*withFailFast); ok {
gopts = append(gopts, grpc.FailOnNonTempDialError(true))
}
if credInfo, ok := o.(*withCredentials); ok {
opt, err := loadCredentials(credInfo)
if err != nil {
return nil, err
}
gopts = append(gopts, opt)
needWithInsecure = false
}
if wt, ok := o.(*withTracer); ok {
gopts = append(gopts,
grpc.WithUnaryInterceptor(otgrpc.OpenTracingClientInterceptor(wt.tracer, otgrpc.LogPayloads())),
grpc.WithStreamInterceptor(otgrpc.OpenTracingStreamClientInterceptor(wt.tracer)))
}
if wd, ok := o.(*withDialer); ok {
gopts = append(gopts, grpc.WithDialer(wd.dialer))
needDialer = false
}
}
if needDialer {
dialFn, err := resolveDialer(address)
if err != nil {
return nil, err
}
// TODO(AkihiroSuda): use WithContextDialer (requires grpc 1.19)
// https://github.com/grpc/grpc-go/commit/40cb5618f475e7b9d61aa7920ae4b04ef9bbaf89
gopts = append(gopts, grpc.WithDialer(dialFn))
}
if needWithInsecure {
gopts = append(gopts, grpc.WithInsecure())
}
if address == "" {
address = appdefaults.Address
}
conn, err := grpc.DialContext(ctx, address, gopts...)
if err != nil {
return nil, errors.Wrapf(err, "failed to dial %q . make sure buildkitd is running", address)
}
c := &Client{
conn: conn,
}
return c, nil
} | go | func New(ctx context.Context, address string, opts ...ClientOpt) (*Client, error) {
gopts := []grpc.DialOption{}
needDialer := true
needWithInsecure := true
for _, o := range opts {
if _, ok := o.(*withFailFast); ok {
gopts = append(gopts, grpc.FailOnNonTempDialError(true))
}
if credInfo, ok := o.(*withCredentials); ok {
opt, err := loadCredentials(credInfo)
if err != nil {
return nil, err
}
gopts = append(gopts, opt)
needWithInsecure = false
}
if wt, ok := o.(*withTracer); ok {
gopts = append(gopts,
grpc.WithUnaryInterceptor(otgrpc.OpenTracingClientInterceptor(wt.tracer, otgrpc.LogPayloads())),
grpc.WithStreamInterceptor(otgrpc.OpenTracingStreamClientInterceptor(wt.tracer)))
}
if wd, ok := o.(*withDialer); ok {
gopts = append(gopts, grpc.WithDialer(wd.dialer))
needDialer = false
}
}
if needDialer {
dialFn, err := resolveDialer(address)
if err != nil {
return nil, err
}
// TODO(AkihiroSuda): use WithContextDialer (requires grpc 1.19)
// https://github.com/grpc/grpc-go/commit/40cb5618f475e7b9d61aa7920ae4b04ef9bbaf89
gopts = append(gopts, grpc.WithDialer(dialFn))
}
if needWithInsecure {
gopts = append(gopts, grpc.WithInsecure())
}
if address == "" {
address = appdefaults.Address
}
conn, err := grpc.DialContext(ctx, address, gopts...)
if err != nil {
return nil, errors.Wrapf(err, "failed to dial %q . make sure buildkitd is running", address)
}
c := &Client{
conn: conn,
}
return c, nil
} | [
"func",
"New",
"(",
"ctx",
"context",
".",
"Context",
",",
"address",
"string",
",",
"opts",
"...",
"ClientOpt",
")",
"(",
"*",
"Client",
",",
"error",
")",
"{",
"gopts",
":=",
"[",
"]",
"grpc",
".",
"DialOption",
"{",
"}",
"\n",
"needDialer",
":=",
"true",
"\n",
"needWithInsecure",
":=",
"true",
"\n",
"for",
"_",
",",
"o",
":=",
"range",
"opts",
"{",
"if",
"_",
",",
"ok",
":=",
"o",
".",
"(",
"*",
"withFailFast",
")",
";",
"ok",
"{",
"gopts",
"=",
"append",
"(",
"gopts",
",",
"grpc",
".",
"FailOnNonTempDialError",
"(",
"true",
")",
")",
"\n",
"}",
"\n",
"if",
"credInfo",
",",
"ok",
":=",
"o",
".",
"(",
"*",
"withCredentials",
")",
";",
"ok",
"{",
"opt",
",",
"err",
":=",
"loadCredentials",
"(",
"credInfo",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"gopts",
"=",
"append",
"(",
"gopts",
",",
"opt",
")",
"\n",
"needWithInsecure",
"=",
"false",
"\n",
"}",
"\n",
"if",
"wt",
",",
"ok",
":=",
"o",
".",
"(",
"*",
"withTracer",
")",
";",
"ok",
"{",
"gopts",
"=",
"append",
"(",
"gopts",
",",
"grpc",
".",
"WithUnaryInterceptor",
"(",
"otgrpc",
".",
"OpenTracingClientInterceptor",
"(",
"wt",
".",
"tracer",
",",
"otgrpc",
".",
"LogPayloads",
"(",
")",
")",
")",
",",
"grpc",
".",
"WithStreamInterceptor",
"(",
"otgrpc",
".",
"OpenTracingStreamClientInterceptor",
"(",
"wt",
".",
"tracer",
")",
")",
")",
"\n",
"}",
"\n",
"if",
"wd",
",",
"ok",
":=",
"o",
".",
"(",
"*",
"withDialer",
")",
";",
"ok",
"{",
"gopts",
"=",
"append",
"(",
"gopts",
",",
"grpc",
".",
"WithDialer",
"(",
"wd",
".",
"dialer",
")",
")",
"\n",
"needDialer",
"=",
"false",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"needDialer",
"{",
"dialFn",
",",
"err",
":=",
"resolveDialer",
"(",
"address",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"// TODO(AkihiroSuda): use WithContextDialer (requires grpc 1.19)",
"// https://github.com/grpc/grpc-go/commit/40cb5618f475e7b9d61aa7920ae4b04ef9bbaf89",
"gopts",
"=",
"append",
"(",
"gopts",
",",
"grpc",
".",
"WithDialer",
"(",
"dialFn",
")",
")",
"\n",
"}",
"\n",
"if",
"needWithInsecure",
"{",
"gopts",
"=",
"append",
"(",
"gopts",
",",
"grpc",
".",
"WithInsecure",
"(",
")",
")",
"\n",
"}",
"\n",
"if",
"address",
"==",
"\"",
"\"",
"{",
"address",
"=",
"appdefaults",
".",
"Address",
"\n",
"}",
"\n",
"conn",
",",
"err",
":=",
"grpc",
".",
"DialContext",
"(",
"ctx",
",",
"address",
",",
"gopts",
"...",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Wrapf",
"(",
"err",
",",
"\"",
"\"",
",",
"address",
")",
"\n",
"}",
"\n",
"c",
":=",
"&",
"Client",
"{",
"conn",
":",
"conn",
",",
"}",
"\n",
"return",
"c",
",",
"nil",
"\n",
"}"
] | // New returns a new buildkit client. Address can be empty for the system-default address. | [
"New",
"returns",
"a",
"new",
"buildkit",
"client",
".",
"Address",
"can",
"be",
"empty",
"for",
"the",
"system",
"-",
"default",
"address",
"."
] | 89851c6c69bca875dd64b5e9d5d6ec60ff437d74 | https://github.com/moby/buildkit/blob/89851c6c69bca875dd64b5e9d5d6ec60ff437d74/client/client.go#L28-L77 | train |
revel/revel | logger/init.go | initAllLog | func initAllLog(c *CompositeMultiHandler, basePath string, config *config.Context) {
if config != nil {
extraLogFlag := config.BoolDefault(SPECIAL_USE_FLAG, false)
if output, found := config.String("log.all.output"); found {
// Set all output for the specified handler
if extraLogFlag {
log.Printf("Adding standard handler for levels to >%s< ", output)
}
initHandlerFor(c, output, basePath, NewLogOptions(config, true, nil, LvlAllList...))
}
}
} | go | func initAllLog(c *CompositeMultiHandler, basePath string, config *config.Context) {
if config != nil {
extraLogFlag := config.BoolDefault(SPECIAL_USE_FLAG, false)
if output, found := config.String("log.all.output"); found {
// Set all output for the specified handler
if extraLogFlag {
log.Printf("Adding standard handler for levels to >%s< ", output)
}
initHandlerFor(c, output, basePath, NewLogOptions(config, true, nil, LvlAllList...))
}
}
} | [
"func",
"initAllLog",
"(",
"c",
"*",
"CompositeMultiHandler",
",",
"basePath",
"string",
",",
"config",
"*",
"config",
".",
"Context",
")",
"{",
"if",
"config",
"!=",
"nil",
"{",
"extraLogFlag",
":=",
"config",
".",
"BoolDefault",
"(",
"SPECIAL_USE_FLAG",
",",
"false",
")",
"\n",
"if",
"output",
",",
"found",
":=",
"config",
".",
"String",
"(",
"\"",
"\"",
")",
";",
"found",
"{",
"// Set all output for the specified handler",
"if",
"extraLogFlag",
"{",
"log",
".",
"Printf",
"(",
"\"",
"\"",
",",
"output",
")",
"\n",
"}",
"\n",
"initHandlerFor",
"(",
"c",
",",
"output",
",",
"basePath",
",",
"NewLogOptions",
"(",
"config",
",",
"true",
",",
"nil",
",",
"LvlAllList",
"...",
")",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // Init the log.all configuration options | [
"Init",
"the",
"log",
".",
"all",
"configuration",
"options"
] | a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e | https://github.com/revel/revel/blob/a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e/logger/init.go#L47-L58 | train |
revel/revel | logger/init.go | initLogLevels | func initLogLevels(c *CompositeMultiHandler, basePath string, config *config.Context) {
for _, name := range []string{"debug", "info", "warn", "error", "crit",
"trace", // TODO trace is deprecated
} {
if config != nil {
extraLogFlag := config.BoolDefault(SPECIAL_USE_FLAG, false)
output, found := config.String("log." + name + ".output")
if found {
if extraLogFlag {
log.Printf("Adding standard handler %s output %s", name, output)
}
initHandlerFor(c, output, basePath, NewLogOptions(config, true, nil, toLevel[name]))
}
// Gets the list of options with said prefix
} else {
initHandlerFor(c, "stderr", basePath, NewLogOptions(config, true, nil, toLevel[name]))
}
}
} | go | func initLogLevels(c *CompositeMultiHandler, basePath string, config *config.Context) {
for _, name := range []string{"debug", "info", "warn", "error", "crit",
"trace", // TODO trace is deprecated
} {
if config != nil {
extraLogFlag := config.BoolDefault(SPECIAL_USE_FLAG, false)
output, found := config.String("log." + name + ".output")
if found {
if extraLogFlag {
log.Printf("Adding standard handler %s output %s", name, output)
}
initHandlerFor(c, output, basePath, NewLogOptions(config, true, nil, toLevel[name]))
}
// Gets the list of options with said prefix
} else {
initHandlerFor(c, "stderr", basePath, NewLogOptions(config, true, nil, toLevel[name]))
}
}
} | [
"func",
"initLogLevels",
"(",
"c",
"*",
"CompositeMultiHandler",
",",
"basePath",
"string",
",",
"config",
"*",
"config",
".",
"Context",
")",
"{",
"for",
"_",
",",
"name",
":=",
"range",
"[",
"]",
"string",
"{",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"// TODO trace is deprecated",
"}",
"{",
"if",
"config",
"!=",
"nil",
"{",
"extraLogFlag",
":=",
"config",
".",
"BoolDefault",
"(",
"SPECIAL_USE_FLAG",
",",
"false",
")",
"\n",
"output",
",",
"found",
":=",
"config",
".",
"String",
"(",
"\"",
"\"",
"+",
"name",
"+",
"\"",
"\"",
")",
"\n",
"if",
"found",
"{",
"if",
"extraLogFlag",
"{",
"log",
".",
"Printf",
"(",
"\"",
"\"",
",",
"name",
",",
"output",
")",
"\n",
"}",
"\n",
"initHandlerFor",
"(",
"c",
",",
"output",
",",
"basePath",
",",
"NewLogOptions",
"(",
"config",
",",
"true",
",",
"nil",
",",
"toLevel",
"[",
"name",
"]",
")",
")",
"\n",
"}",
"\n",
"// Gets the list of options with said prefix",
"}",
"else",
"{",
"initHandlerFor",
"(",
"c",
",",
"\"",
"\"",
",",
"basePath",
",",
"NewLogOptions",
"(",
"config",
",",
"true",
",",
"nil",
",",
"toLevel",
"[",
"name",
"]",
")",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // Init the log.error, log.warn etc configuration options | [
"Init",
"the",
"log",
".",
"error",
"log",
".",
"warn",
"etc",
"configuration",
"options"
] | a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e | https://github.com/revel/revel/blob/a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e/logger/init.go#L98-L116 | train |
revel/revel | logger/init.go | initRequestLog | func initRequestLog(c *CompositeMultiHandler, basePath string, config *config.Context) {
// Request logging to a separate output handler
// This takes the InfoHandlers and adds a MatchAbHandler handler to it to direct
// context with the word "section=requestlog" to that handler.
// Note if request logging is not enabled the MatchAbHandler will not be added and the
// request log messages will be sent out the INFO handler
outputRequest := "stdout"
if config != nil {
outputRequest = config.StringDefault("log.request.output", "")
}
oldInfo := c.InfoHandler
c.InfoHandler = nil
if outputRequest != "" {
initHandlerFor(c, outputRequest, basePath, NewLogOptions(config, false, nil, LvlInfo))
}
if c.InfoHandler != nil || oldInfo != nil {
if c.InfoHandler == nil {
c.InfoHandler = oldInfo
} else {
c.InfoHandler = MatchAbHandler("section", "requestlog", c.InfoHandler, oldInfo)
}
}
} | go | func initRequestLog(c *CompositeMultiHandler, basePath string, config *config.Context) {
// Request logging to a separate output handler
// This takes the InfoHandlers and adds a MatchAbHandler handler to it to direct
// context with the word "section=requestlog" to that handler.
// Note if request logging is not enabled the MatchAbHandler will not be added and the
// request log messages will be sent out the INFO handler
outputRequest := "stdout"
if config != nil {
outputRequest = config.StringDefault("log.request.output", "")
}
oldInfo := c.InfoHandler
c.InfoHandler = nil
if outputRequest != "" {
initHandlerFor(c, outputRequest, basePath, NewLogOptions(config, false, nil, LvlInfo))
}
if c.InfoHandler != nil || oldInfo != nil {
if c.InfoHandler == nil {
c.InfoHandler = oldInfo
} else {
c.InfoHandler = MatchAbHandler("section", "requestlog", c.InfoHandler, oldInfo)
}
}
} | [
"func",
"initRequestLog",
"(",
"c",
"*",
"CompositeMultiHandler",
",",
"basePath",
"string",
",",
"config",
"*",
"config",
".",
"Context",
")",
"{",
"// Request logging to a separate output handler",
"// This takes the InfoHandlers and adds a MatchAbHandler handler to it to direct",
"// context with the word \"section=requestlog\" to that handler.",
"// Note if request logging is not enabled the MatchAbHandler will not be added and the",
"// request log messages will be sent out the INFO handler",
"outputRequest",
":=",
"\"",
"\"",
"\n",
"if",
"config",
"!=",
"nil",
"{",
"outputRequest",
"=",
"config",
".",
"StringDefault",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"oldInfo",
":=",
"c",
".",
"InfoHandler",
"\n",
"c",
".",
"InfoHandler",
"=",
"nil",
"\n",
"if",
"outputRequest",
"!=",
"\"",
"\"",
"{",
"initHandlerFor",
"(",
"c",
",",
"outputRequest",
",",
"basePath",
",",
"NewLogOptions",
"(",
"config",
",",
"false",
",",
"nil",
",",
"LvlInfo",
")",
")",
"\n",
"}",
"\n",
"if",
"c",
".",
"InfoHandler",
"!=",
"nil",
"||",
"oldInfo",
"!=",
"nil",
"{",
"if",
"c",
".",
"InfoHandler",
"==",
"nil",
"{",
"c",
".",
"InfoHandler",
"=",
"oldInfo",
"\n",
"}",
"else",
"{",
"c",
".",
"InfoHandler",
"=",
"MatchAbHandler",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"c",
".",
"InfoHandler",
",",
"oldInfo",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // Init the request log options | [
"Init",
"the",
"request",
"log",
"options"
] | a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e | https://github.com/revel/revel/blob/a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e/logger/init.go#L119-L141 | train |
revel/revel | intercept.go | Invoke | func (i Interception) Invoke(val reflect.Value, target *reflect.Value) reflect.Value {
var arg reflect.Value
if i.function == nil {
// If it's an InterceptorMethod, then we have to pass in the target type.
arg = *target
} else {
// If it's an InterceptorFunc, then the type must be *Controller.
// We can find that by following the embedded types up the chain.
for val.Type() != controllerPtrType {
if val.Kind() == reflect.Ptr {
val = val.Elem()
}
val = val.Field(0)
}
arg = val
}
vals := i.callable.Call([]reflect.Value{arg})
return vals[0]
} | go | func (i Interception) Invoke(val reflect.Value, target *reflect.Value) reflect.Value {
var arg reflect.Value
if i.function == nil {
// If it's an InterceptorMethod, then we have to pass in the target type.
arg = *target
} else {
// If it's an InterceptorFunc, then the type must be *Controller.
// We can find that by following the embedded types up the chain.
for val.Type() != controllerPtrType {
if val.Kind() == reflect.Ptr {
val = val.Elem()
}
val = val.Field(0)
}
arg = val
}
vals := i.callable.Call([]reflect.Value{arg})
return vals[0]
} | [
"func",
"(",
"i",
"Interception",
")",
"Invoke",
"(",
"val",
"reflect",
".",
"Value",
",",
"target",
"*",
"reflect",
".",
"Value",
")",
"reflect",
".",
"Value",
"{",
"var",
"arg",
"reflect",
".",
"Value",
"\n",
"if",
"i",
".",
"function",
"==",
"nil",
"{",
"// If it's an InterceptorMethod, then we have to pass in the target type.",
"arg",
"=",
"*",
"target",
"\n",
"}",
"else",
"{",
"// If it's an InterceptorFunc, then the type must be *Controller.",
"// We can find that by following the embedded types up the chain.",
"for",
"val",
".",
"Type",
"(",
")",
"!=",
"controllerPtrType",
"{",
"if",
"val",
".",
"Kind",
"(",
")",
"==",
"reflect",
".",
"Ptr",
"{",
"val",
"=",
"val",
".",
"Elem",
"(",
")",
"\n",
"}",
"\n",
"val",
"=",
"val",
".",
"Field",
"(",
"0",
")",
"\n",
"}",
"\n",
"arg",
"=",
"val",
"\n",
"}",
"\n\n",
"vals",
":=",
"i",
".",
"callable",
".",
"Call",
"(",
"[",
"]",
"reflect",
".",
"Value",
"{",
"arg",
"}",
")",
"\n",
"return",
"vals",
"[",
"0",
"]",
"\n",
"}"
] | // Invoke performs the given interception.
// val is a pointer to the App Controller. | [
"Invoke",
"performs",
"the",
"given",
"interception",
".",
"val",
"is",
"a",
"pointer",
"to",
"the",
"App",
"Controller",
"."
] | a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e | https://github.com/revel/revel/blob/a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e/intercept.go#L72-L91 | train |
revel/revel | template_engine.go | RegisterTemplateLoader | func RegisterTemplateLoader(key string, loader func(loader *TemplateLoader) (TemplateEngine, error)) (err error) {
if _, found := templateLoaderMap[key]; found {
err = fmt.Errorf("Template loader %s already exists", key)
}
templateLog.Debug("Registered template engine loaded", "name", key)
templateLoaderMap[key] = loader
return
} | go | func RegisterTemplateLoader(key string, loader func(loader *TemplateLoader) (TemplateEngine, error)) (err error) {
if _, found := templateLoaderMap[key]; found {
err = fmt.Errorf("Template loader %s already exists", key)
}
templateLog.Debug("Registered template engine loaded", "name", key)
templateLoaderMap[key] = loader
return
} | [
"func",
"RegisterTemplateLoader",
"(",
"key",
"string",
",",
"loader",
"func",
"(",
"loader",
"*",
"TemplateLoader",
")",
"(",
"TemplateEngine",
",",
"error",
")",
")",
"(",
"err",
"error",
")",
"{",
"if",
"_",
",",
"found",
":=",
"templateLoaderMap",
"[",
"key",
"]",
";",
"found",
"{",
"err",
"=",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"key",
")",
"\n",
"}",
"\n",
"templateLog",
".",
"Debug",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"key",
")",
"\n",
"templateLoaderMap",
"[",
"key",
"]",
"=",
"loader",
"\n",
"return",
"\n",
"}"
] | // Allow for templates to be registered during init but not initialized until application has been started | [
"Allow",
"for",
"templates",
"to",
"be",
"registered",
"during",
"init",
"but",
"not",
"initialized",
"until",
"application",
"has",
"been",
"started"
] | a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e | https://github.com/revel/revel/blob/a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e/template_engine.go#L41-L48 | train |
revel/revel | template_engine.go | CreateTemplateEngine | func (loader *TemplateLoader) CreateTemplateEngine(templateEngineName string) (TemplateEngine, error) {
if "" == templateEngineName {
templateEngineName = GO_TEMPLATE
}
factory := templateLoaderMap[templateEngineName]
if nil == factory {
fmt.Printf("registered factories %#v\n %s \n", templateLoaderMap, templateEngineName)
return nil, errors.New("Unknown template engine name - " + templateEngineName + ".")
}
templateEngine, err := factory(loader)
if nil != err {
return nil, errors.New("Failed to init template engine (" + templateEngineName + "), " + err.Error())
}
templateLog.Debug("CreateTemplateEngine: init templates", "name", templateEngineName)
return templateEngine, nil
} | go | func (loader *TemplateLoader) CreateTemplateEngine(templateEngineName string) (TemplateEngine, error) {
if "" == templateEngineName {
templateEngineName = GO_TEMPLATE
}
factory := templateLoaderMap[templateEngineName]
if nil == factory {
fmt.Printf("registered factories %#v\n %s \n", templateLoaderMap, templateEngineName)
return nil, errors.New("Unknown template engine name - " + templateEngineName + ".")
}
templateEngine, err := factory(loader)
if nil != err {
return nil, errors.New("Failed to init template engine (" + templateEngineName + "), " + err.Error())
}
templateLog.Debug("CreateTemplateEngine: init templates", "name", templateEngineName)
return templateEngine, nil
} | [
"func",
"(",
"loader",
"*",
"TemplateLoader",
")",
"CreateTemplateEngine",
"(",
"templateEngineName",
"string",
")",
"(",
"TemplateEngine",
",",
"error",
")",
"{",
"if",
"\"",
"\"",
"==",
"templateEngineName",
"{",
"templateEngineName",
"=",
"GO_TEMPLATE",
"\n",
"}",
"\n",
"factory",
":=",
"templateLoaderMap",
"[",
"templateEngineName",
"]",
"\n",
"if",
"nil",
"==",
"factory",
"{",
"fmt",
".",
"Printf",
"(",
"\"",
"\\n",
"\\n",
"\"",
",",
"templateLoaderMap",
",",
"templateEngineName",
")",
"\n",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
"+",
"templateEngineName",
"+",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"templateEngine",
",",
"err",
":=",
"factory",
"(",
"loader",
")",
"\n",
"if",
"nil",
"!=",
"err",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
"+",
"templateEngineName",
"+",
"\"",
"\"",
"+",
"err",
".",
"Error",
"(",
")",
")",
"\n",
"}",
"\n\n",
"templateLog",
".",
"Debug",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"templateEngineName",
")",
"\n",
"return",
"templateEngine",
",",
"nil",
"\n",
"}"
] | // Sets the template name from Config
// Sets the template API methods for parsing and storing templates before rendering | [
"Sets",
"the",
"template",
"name",
"from",
"Config",
"Sets",
"the",
"template",
"API",
"methods",
"for",
"parsing",
"and",
"storing",
"templates",
"before",
"rendering"
] | a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e | https://github.com/revel/revel/blob/a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e/template_engine.go#L52-L68 | train |
revel/revel | template_engine.go | initializeEngines | func (loader *TemplateLoader) initializeEngines(runtimeLoader *templateRuntime, templateEngineNameList string) (err *Error) {
// Walk through the template loader's paths and build up a template set.
if templateEngineNameList == "" {
templateEngineNameList = GO_TEMPLATE
}
runtimeLoader.templatesAndEngineList = []TemplateEngine{}
for _, engine := range strings.Split(templateEngineNameList, ",") {
engine := strings.TrimSpace(strings.ToLower(engine))
if templateLoader, err := loader.CreateTemplateEngine(engine); err != nil {
runtimeLoader.compileError = &Error{
Title: "Panic (Template Loader)",
Description: err.Error(),
}
return runtimeLoader.compileError
} else {
// Always assign a default engine, switch it if it is specified in the config
runtimeLoader.templatesAndEngineList = append(runtimeLoader.templatesAndEngineList, templateLoader)
}
}
return
} | go | func (loader *TemplateLoader) initializeEngines(runtimeLoader *templateRuntime, templateEngineNameList string) (err *Error) {
// Walk through the template loader's paths and build up a template set.
if templateEngineNameList == "" {
templateEngineNameList = GO_TEMPLATE
}
runtimeLoader.templatesAndEngineList = []TemplateEngine{}
for _, engine := range strings.Split(templateEngineNameList, ",") {
engine := strings.TrimSpace(strings.ToLower(engine))
if templateLoader, err := loader.CreateTemplateEngine(engine); err != nil {
runtimeLoader.compileError = &Error{
Title: "Panic (Template Loader)",
Description: err.Error(),
}
return runtimeLoader.compileError
} else {
// Always assign a default engine, switch it if it is specified in the config
runtimeLoader.templatesAndEngineList = append(runtimeLoader.templatesAndEngineList, templateLoader)
}
}
return
} | [
"func",
"(",
"loader",
"*",
"TemplateLoader",
")",
"initializeEngines",
"(",
"runtimeLoader",
"*",
"templateRuntime",
",",
"templateEngineNameList",
"string",
")",
"(",
"err",
"*",
"Error",
")",
"{",
"// Walk through the template loader's paths and build up a template set.",
"if",
"templateEngineNameList",
"==",
"\"",
"\"",
"{",
"templateEngineNameList",
"=",
"GO_TEMPLATE",
"\n\n",
"}",
"\n",
"runtimeLoader",
".",
"templatesAndEngineList",
"=",
"[",
"]",
"TemplateEngine",
"{",
"}",
"\n",
"for",
"_",
",",
"engine",
":=",
"range",
"strings",
".",
"Split",
"(",
"templateEngineNameList",
",",
"\"",
"\"",
")",
"{",
"engine",
":=",
"strings",
".",
"TrimSpace",
"(",
"strings",
".",
"ToLower",
"(",
"engine",
")",
")",
"\n\n",
"if",
"templateLoader",
",",
"err",
":=",
"loader",
".",
"CreateTemplateEngine",
"(",
"engine",
")",
";",
"err",
"!=",
"nil",
"{",
"runtimeLoader",
".",
"compileError",
"=",
"&",
"Error",
"{",
"Title",
":",
"\"",
"\"",
",",
"Description",
":",
"err",
".",
"Error",
"(",
")",
",",
"}",
"\n",
"return",
"runtimeLoader",
".",
"compileError",
"\n",
"}",
"else",
"{",
"// Always assign a default engine, switch it if it is specified in the config",
"runtimeLoader",
".",
"templatesAndEngineList",
"=",
"append",
"(",
"runtimeLoader",
".",
"templatesAndEngineList",
",",
"templateLoader",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] | // Passing in a comma delimited list of engine names to be used with this loader to parse the template files | [
"Passing",
"in",
"a",
"comma",
"delimited",
"list",
"of",
"engine",
"names",
"to",
"be",
"used",
"with",
"this",
"loader",
"to",
"parse",
"the",
"template",
"files"
] | a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e | https://github.com/revel/revel/blob/a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e/template_engine.go#L71-L93 | train |
revel/revel | module.go | init | func init() {
AddInitEventHandler(func(typeOf Event, value interface{}) (responseOf EventResponse) {
if typeOf == REVEL_BEFORE_MODULES_LOADED {
Modules = []*Module{appModule}
appModule.Path = filepath.ToSlash(AppPath)
appModule.ImportPath = filepath.ToSlash(AppPath)
}
return
})
} | go | func init() {
AddInitEventHandler(func(typeOf Event, value interface{}) (responseOf EventResponse) {
if typeOf == REVEL_BEFORE_MODULES_LOADED {
Modules = []*Module{appModule}
appModule.Path = filepath.ToSlash(AppPath)
appModule.ImportPath = filepath.ToSlash(AppPath)
}
return
})
} | [
"func",
"init",
"(",
")",
"{",
"AddInitEventHandler",
"(",
"func",
"(",
"typeOf",
"Event",
",",
"value",
"interface",
"{",
"}",
")",
"(",
"responseOf",
"EventResponse",
")",
"{",
"if",
"typeOf",
"==",
"REVEL_BEFORE_MODULES_LOADED",
"{",
"Modules",
"=",
"[",
"]",
"*",
"Module",
"{",
"appModule",
"}",
"\n",
"appModule",
".",
"Path",
"=",
"filepath",
".",
"ToSlash",
"(",
"AppPath",
")",
"\n",
"appModule",
".",
"ImportPath",
"=",
"filepath",
".",
"ToSlash",
"(",
"AppPath",
")",
"\n",
"}",
"\n\n",
"return",
"\n",
"}",
")",
"\n",
"}"
] | // Called on startup to make a callback so that modules can be initialized through the `RegisterModuleInit` function | [
"Called",
"on",
"startup",
"to",
"make",
"a",
"callback",
"so",
"that",
"modules",
"can",
"be",
"initialized",
"through",
"the",
"RegisterModuleInit",
"function"
] | a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e | https://github.com/revel/revel/blob/a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e/module.go#L48-L58 | train |
revel/revel | module.go | ControllerByName | func (m *Module) ControllerByName(name, action string) (ctype *ControllerType) {
comparison := name
if strings.Index(name, namespaceSeperator) < 0 {
comparison = m.Namespace() + name
}
for _, c := range m.ControllerTypeList {
if c.Name() == comparison {
ctype = c
break
}
}
return
} | go | func (m *Module) ControllerByName(name, action string) (ctype *ControllerType) {
comparison := name
if strings.Index(name, namespaceSeperator) < 0 {
comparison = m.Namespace() + name
}
for _, c := range m.ControllerTypeList {
if c.Name() == comparison {
ctype = c
break
}
}
return
} | [
"func",
"(",
"m",
"*",
"Module",
")",
"ControllerByName",
"(",
"name",
",",
"action",
"string",
")",
"(",
"ctype",
"*",
"ControllerType",
")",
"{",
"comparison",
":=",
"name",
"\n",
"if",
"strings",
".",
"Index",
"(",
"name",
",",
"namespaceSeperator",
")",
"<",
"0",
"{",
"comparison",
"=",
"m",
".",
"Namespace",
"(",
")",
"+",
"name",
"\n",
"}",
"\n",
"for",
"_",
",",
"c",
":=",
"range",
"m",
".",
"ControllerTypeList",
"{",
"if",
"c",
".",
"Name",
"(",
")",
"==",
"comparison",
"{",
"ctype",
"=",
"c",
"\n",
"break",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] | // Returns the named controller and action that is in this module | [
"Returns",
"the",
"named",
"controller",
"and",
"action",
"that",
"is",
"in",
"this",
"module"
] | a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e | https://github.com/revel/revel/blob/a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e/module.go#L67-L79 | train |
revel/revel | module.go | AddController | func (m *Module) AddController(ct *ControllerType) {
m.ControllerTypeList = append(m.ControllerTypeList, ct)
} | go | func (m *Module) AddController(ct *ControllerType) {
m.ControllerTypeList = append(m.ControllerTypeList, ct)
} | [
"func",
"(",
"m",
"*",
"Module",
")",
"AddController",
"(",
"ct",
"*",
"ControllerType",
")",
"{",
"m",
".",
"ControllerTypeList",
"=",
"append",
"(",
"m",
".",
"ControllerTypeList",
",",
"ct",
")",
"\n",
"}"
] | // Adds the controller type to this module | [
"Adds",
"the",
"controller",
"type",
"to",
"this",
"module"
] | a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e | https://github.com/revel/revel/blob/a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e/module.go#L82-L84 | train |
revel/revel | module.go | ModuleFromPath | func ModuleFromPath(path string, addGopathToPath bool) (module *Module) {
path = filepath.ToSlash(path)
gopathList := filepath.SplitList(build.Default.GOPATH)
// Strip away the vendor folder
if i := strings.Index(path, "/vendor/"); i > 0 {
path = path[i+len("vendor/"):]
}
// See if the path exists in the module based
for i := range Modules {
if addGopathToPath {
for _, gopath := range gopathList {
if strings.Contains(filepath.ToSlash(filepath.Clean(filepath.Join(gopath, "src", path))), Modules[i].Path) {
module = Modules[i]
break
}
}
} else {
if strings.Contains(path, Modules[i].ImportPath) {
module = Modules[i]
break
}
}
if module != nil {
break
}
}
// Default to the app module if not found
if module == nil {
module = appModule
}
return
} | go | func ModuleFromPath(path string, addGopathToPath bool) (module *Module) {
path = filepath.ToSlash(path)
gopathList := filepath.SplitList(build.Default.GOPATH)
// Strip away the vendor folder
if i := strings.Index(path, "/vendor/"); i > 0 {
path = path[i+len("vendor/"):]
}
// See if the path exists in the module based
for i := range Modules {
if addGopathToPath {
for _, gopath := range gopathList {
if strings.Contains(filepath.ToSlash(filepath.Clean(filepath.Join(gopath, "src", path))), Modules[i].Path) {
module = Modules[i]
break
}
}
} else {
if strings.Contains(path, Modules[i].ImportPath) {
module = Modules[i]
break
}
}
if module != nil {
break
}
}
// Default to the app module if not found
if module == nil {
module = appModule
}
return
} | [
"func",
"ModuleFromPath",
"(",
"path",
"string",
",",
"addGopathToPath",
"bool",
")",
"(",
"module",
"*",
"Module",
")",
"{",
"path",
"=",
"filepath",
".",
"ToSlash",
"(",
"path",
")",
"\n",
"gopathList",
":=",
"filepath",
".",
"SplitList",
"(",
"build",
".",
"Default",
".",
"GOPATH",
")",
"\n",
"// Strip away the vendor folder",
"if",
"i",
":=",
"strings",
".",
"Index",
"(",
"path",
",",
"\"",
"\"",
")",
";",
"i",
">",
"0",
"{",
"path",
"=",
"path",
"[",
"i",
"+",
"len",
"(",
"\"",
"\"",
")",
":",
"]",
"\n",
"}",
"\n\n",
"// See if the path exists in the module based",
"for",
"i",
":=",
"range",
"Modules",
"{",
"if",
"addGopathToPath",
"{",
"for",
"_",
",",
"gopath",
":=",
"range",
"gopathList",
"{",
"if",
"strings",
".",
"Contains",
"(",
"filepath",
".",
"ToSlash",
"(",
"filepath",
".",
"Clean",
"(",
"filepath",
".",
"Join",
"(",
"gopath",
",",
"\"",
"\"",
",",
"path",
")",
")",
")",
",",
"Modules",
"[",
"i",
"]",
".",
"Path",
")",
"{",
"module",
"=",
"Modules",
"[",
"i",
"]",
"\n",
"break",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"else",
"{",
"if",
"strings",
".",
"Contains",
"(",
"path",
",",
"Modules",
"[",
"i",
"]",
".",
"ImportPath",
")",
"{",
"module",
"=",
"Modules",
"[",
"i",
"]",
"\n",
"break",
"\n",
"}",
"\n\n",
"}",
"\n\n",
"if",
"module",
"!=",
"nil",
"{",
"break",
"\n",
"}",
"\n",
"}",
"\n",
"// Default to the app module if not found",
"if",
"module",
"==",
"nil",
"{",
"module",
"=",
"appModule",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] | // Based on the full path given return the relevant module
// Only to be used on initialization | [
"Based",
"on",
"the",
"full",
"path",
"given",
"return",
"the",
"relevant",
"module",
"Only",
"to",
"be",
"used",
"on",
"initialization"
] | a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e | https://github.com/revel/revel/blob/a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e/module.go#L88-L122 | train |
revel/revel | module.go | ModuleByName | func ModuleByName(name string) (*Module, bool) {
// If the name ends with the namespace separator remove it
if name[len(name)-1] == []byte(namespaceSeperator)[0] {
name = name[:len(name)-1]
}
name = strings.ToLower(name)
if name == strings.ToLower(appModule.Name) {
return appModule, true
}
for _, module := range Modules {
if strings.ToLower(module.Name) == name {
return module, true
}
}
return nil, false
} | go | func ModuleByName(name string) (*Module, bool) {
// If the name ends with the namespace separator remove it
if name[len(name)-1] == []byte(namespaceSeperator)[0] {
name = name[:len(name)-1]
}
name = strings.ToLower(name)
if name == strings.ToLower(appModule.Name) {
return appModule, true
}
for _, module := range Modules {
if strings.ToLower(module.Name) == name {
return module, true
}
}
return nil, false
} | [
"func",
"ModuleByName",
"(",
"name",
"string",
")",
"(",
"*",
"Module",
",",
"bool",
")",
"{",
"// If the name ends with the namespace separator remove it",
"if",
"name",
"[",
"len",
"(",
"name",
")",
"-",
"1",
"]",
"==",
"[",
"]",
"byte",
"(",
"namespaceSeperator",
")",
"[",
"0",
"]",
"{",
"name",
"=",
"name",
"[",
":",
"len",
"(",
"name",
")",
"-",
"1",
"]",
"\n",
"}",
"\n",
"name",
"=",
"strings",
".",
"ToLower",
"(",
"name",
")",
"\n",
"if",
"name",
"==",
"strings",
".",
"ToLower",
"(",
"appModule",
".",
"Name",
")",
"{",
"return",
"appModule",
",",
"true",
"\n",
"}",
"\n",
"for",
"_",
",",
"module",
":=",
"range",
"Modules",
"{",
"if",
"strings",
".",
"ToLower",
"(",
"module",
".",
"Name",
")",
"==",
"name",
"{",
"return",
"module",
",",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
",",
"false",
"\n",
"}"
] | // ModuleByName returns the module of the given name, if loaded, case insensitive. | [
"ModuleByName",
"returns",
"the",
"module",
"of",
"the",
"given",
"name",
"if",
"loaded",
"case",
"insensitive",
"."
] | a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e | https://github.com/revel/revel/blob/a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e/module.go#L125-L140 | train |
revel/revel | module.go | loadModules | func loadModules() {
keys := []string{}
for _, key := range Config.Options("module.") {
keys = append(keys, key)
}
// Reorder module order by key name, a poor mans sort but at least it is consistent
sort.Strings(keys)
for _, key := range keys {
moduleLog.Debug("Sorted keys", "keys", key)
}
for _, key := range keys {
moduleImportPath := Config.StringDefault(key, "")
if moduleImportPath == "" {
continue
}
modulePath, err := ResolveImportPath(moduleImportPath)
if err != nil {
moduleLog.Error("Failed to load module. Import of path failed", "modulePath", moduleImportPath, "error", err)
}
// Drop anything between module.???.<name of module>
subKey := key[len("module."):]
if index := strings.Index(subKey, "."); index > -1 {
subKey = subKey[index+1:]
}
addModule(subKey, moduleImportPath, modulePath)
}
// Modules loaded, now show module path
for key, callback := range appModule.initializedModules {
if m := ModuleFromPath(key, false); m != nil {
callback(m)
} else {
RevelLog.Error("Callback for non registered module initializing with application module", "modulePath", key)
callback(appModule)
}
}
} | go | func loadModules() {
keys := []string{}
for _, key := range Config.Options("module.") {
keys = append(keys, key)
}
// Reorder module order by key name, a poor mans sort but at least it is consistent
sort.Strings(keys)
for _, key := range keys {
moduleLog.Debug("Sorted keys", "keys", key)
}
for _, key := range keys {
moduleImportPath := Config.StringDefault(key, "")
if moduleImportPath == "" {
continue
}
modulePath, err := ResolveImportPath(moduleImportPath)
if err != nil {
moduleLog.Error("Failed to load module. Import of path failed", "modulePath", moduleImportPath, "error", err)
}
// Drop anything between module.???.<name of module>
subKey := key[len("module."):]
if index := strings.Index(subKey, "."); index > -1 {
subKey = subKey[index+1:]
}
addModule(subKey, moduleImportPath, modulePath)
}
// Modules loaded, now show module path
for key, callback := range appModule.initializedModules {
if m := ModuleFromPath(key, false); m != nil {
callback(m)
} else {
RevelLog.Error("Callback for non registered module initializing with application module", "modulePath", key)
callback(appModule)
}
}
} | [
"func",
"loadModules",
"(",
")",
"{",
"keys",
":=",
"[",
"]",
"string",
"{",
"}",
"\n",
"for",
"_",
",",
"key",
":=",
"range",
"Config",
".",
"Options",
"(",
"\"",
"\"",
")",
"{",
"keys",
"=",
"append",
"(",
"keys",
",",
"key",
")",
"\n",
"}",
"\n\n",
"// Reorder module order by key name, a poor mans sort but at least it is consistent",
"sort",
".",
"Strings",
"(",
"keys",
")",
"\n",
"for",
"_",
",",
"key",
":=",
"range",
"keys",
"{",
"moduleLog",
".",
"Debug",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"key",
")",
"\n\n",
"}",
"\n",
"for",
"_",
",",
"key",
":=",
"range",
"keys",
"{",
"moduleImportPath",
":=",
"Config",
".",
"StringDefault",
"(",
"key",
",",
"\"",
"\"",
")",
"\n",
"if",
"moduleImportPath",
"==",
"\"",
"\"",
"{",
"continue",
"\n",
"}",
"\n\n",
"modulePath",
",",
"err",
":=",
"ResolveImportPath",
"(",
"moduleImportPath",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"moduleLog",
".",
"Error",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"moduleImportPath",
",",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"// Drop anything between module.???.<name of module>",
"subKey",
":=",
"key",
"[",
"len",
"(",
"\"",
"\"",
")",
":",
"]",
"\n",
"if",
"index",
":=",
"strings",
".",
"Index",
"(",
"subKey",
",",
"\"",
"\"",
")",
";",
"index",
">",
"-",
"1",
"{",
"subKey",
"=",
"subKey",
"[",
"index",
"+",
"1",
":",
"]",
"\n",
"}",
"\n",
"addModule",
"(",
"subKey",
",",
"moduleImportPath",
",",
"modulePath",
")",
"\n",
"}",
"\n\n",
"// Modules loaded, now show module path",
"for",
"key",
",",
"callback",
":=",
"range",
"appModule",
".",
"initializedModules",
"{",
"if",
"m",
":=",
"ModuleFromPath",
"(",
"key",
",",
"false",
")",
";",
"m",
"!=",
"nil",
"{",
"callback",
"(",
"m",
")",
"\n",
"}",
"else",
"{",
"RevelLog",
".",
"Error",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"key",
")",
"\n",
"callback",
"(",
"appModule",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // Loads the modules specified in the config | [
"Loads",
"the",
"modules",
"specified",
"in",
"the",
"config"
] | a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e | https://github.com/revel/revel/blob/a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e/module.go#L143-L182 | train |
revel/revel | module.go | addModule | func addModule(name, importPath, modulePath string) {
if _, found := ModuleByName(name); found {
moduleLog.Panic("Attempt to import duplicate module %s path %s aborting startup", "name", name, "path", modulePath)
}
Modules = append(Modules, &Module{Name: name,
ImportPath: filepath.ToSlash(importPath),
Path: filepath.ToSlash(modulePath),
Log: RootLog.New("module", name)})
if codePath := filepath.Join(modulePath, "app"); DirExists(codePath) {
CodePaths = append(CodePaths, codePath)
if viewsPath := filepath.Join(modulePath, "app", "views"); DirExists(viewsPath) {
TemplatePaths = append(TemplatePaths, viewsPath)
}
}
moduleLog.Debug("Loaded module ", "module", filepath.Base(modulePath))
// Hack: There is presently no way for the testrunner module to add the
// "test" subdirectory to the CodePaths. So this does it instead.
if importPath == Config.StringDefault("module.testrunner", "github.com/revel/modules/testrunner") {
joinedPath := filepath.Join(BasePath, "tests")
moduleLog.Debug("Found testrunner module, adding `tests` path ", "path", joinedPath)
CodePaths = append(CodePaths, joinedPath)
}
if testsPath := filepath.Join(modulePath, "tests"); DirExists(testsPath) {
moduleLog.Debug("Found tests path ", "path", testsPath)
CodePaths = append(CodePaths, testsPath)
}
} | go | func addModule(name, importPath, modulePath string) {
if _, found := ModuleByName(name); found {
moduleLog.Panic("Attempt to import duplicate module %s path %s aborting startup", "name", name, "path", modulePath)
}
Modules = append(Modules, &Module{Name: name,
ImportPath: filepath.ToSlash(importPath),
Path: filepath.ToSlash(modulePath),
Log: RootLog.New("module", name)})
if codePath := filepath.Join(modulePath, "app"); DirExists(codePath) {
CodePaths = append(CodePaths, codePath)
if viewsPath := filepath.Join(modulePath, "app", "views"); DirExists(viewsPath) {
TemplatePaths = append(TemplatePaths, viewsPath)
}
}
moduleLog.Debug("Loaded module ", "module", filepath.Base(modulePath))
// Hack: There is presently no way for the testrunner module to add the
// "test" subdirectory to the CodePaths. So this does it instead.
if importPath == Config.StringDefault("module.testrunner", "github.com/revel/modules/testrunner") {
joinedPath := filepath.Join(BasePath, "tests")
moduleLog.Debug("Found testrunner module, adding `tests` path ", "path", joinedPath)
CodePaths = append(CodePaths, joinedPath)
}
if testsPath := filepath.Join(modulePath, "tests"); DirExists(testsPath) {
moduleLog.Debug("Found tests path ", "path", testsPath)
CodePaths = append(CodePaths, testsPath)
}
} | [
"func",
"addModule",
"(",
"name",
",",
"importPath",
",",
"modulePath",
"string",
")",
"{",
"if",
"_",
",",
"found",
":=",
"ModuleByName",
"(",
"name",
")",
";",
"found",
"{",
"moduleLog",
".",
"Panic",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"name",
",",
"\"",
"\"",
",",
"modulePath",
")",
"\n",
"}",
"\n",
"Modules",
"=",
"append",
"(",
"Modules",
",",
"&",
"Module",
"{",
"Name",
":",
"name",
",",
"ImportPath",
":",
"filepath",
".",
"ToSlash",
"(",
"importPath",
")",
",",
"Path",
":",
"filepath",
".",
"ToSlash",
"(",
"modulePath",
")",
",",
"Log",
":",
"RootLog",
".",
"New",
"(",
"\"",
"\"",
",",
"name",
")",
"}",
")",
"\n",
"if",
"codePath",
":=",
"filepath",
".",
"Join",
"(",
"modulePath",
",",
"\"",
"\"",
")",
";",
"DirExists",
"(",
"codePath",
")",
"{",
"CodePaths",
"=",
"append",
"(",
"CodePaths",
",",
"codePath",
")",
"\n",
"if",
"viewsPath",
":=",
"filepath",
".",
"Join",
"(",
"modulePath",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
";",
"DirExists",
"(",
"viewsPath",
")",
"{",
"TemplatePaths",
"=",
"append",
"(",
"TemplatePaths",
",",
"viewsPath",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"moduleLog",
".",
"Debug",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"filepath",
".",
"Base",
"(",
"modulePath",
")",
")",
"\n\n",
"// Hack: There is presently no way for the testrunner module to add the",
"// \"test\" subdirectory to the CodePaths. So this does it instead.",
"if",
"importPath",
"==",
"Config",
".",
"StringDefault",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
"{",
"joinedPath",
":=",
"filepath",
".",
"Join",
"(",
"BasePath",
",",
"\"",
"\"",
")",
"\n",
"moduleLog",
".",
"Debug",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"joinedPath",
")",
"\n",
"CodePaths",
"=",
"append",
"(",
"CodePaths",
",",
"joinedPath",
")",
"\n",
"}",
"\n",
"if",
"testsPath",
":=",
"filepath",
".",
"Join",
"(",
"modulePath",
",",
"\"",
"\"",
")",
";",
"DirExists",
"(",
"testsPath",
")",
"{",
"moduleLog",
".",
"Debug",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"testsPath",
")",
"\n",
"CodePaths",
"=",
"append",
"(",
"CodePaths",
",",
"testsPath",
")",
"\n",
"}",
"\n",
"}"
] | // called by `loadModules`, creates a new `Module` instance and appends it to the `Modules` list | [
"called",
"by",
"loadModules",
"creates",
"a",
"new",
"Module",
"instance",
"and",
"appends",
"it",
"to",
"the",
"Modules",
"list"
] | a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e | https://github.com/revel/revel/blob/a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e/module.go#L185-L213 | train |
revel/revel | template.go | TemplateOutputArgs | func TemplateOutputArgs(templatePath string, args map[string]interface{}) (data []byte, err error) {
// Get the Template.
lang, _ := args[CurrentLocaleViewArg].(string)
template, err := MainTemplateLoader.TemplateLang(templatePath, lang)
if err != nil {
return nil, err
}
tr := &RenderTemplateResult{
Template: template,
ViewArgs: args,
}
b, err := tr.ToBytes()
if err != nil {
return nil, err
}
return b.Bytes(), nil
} | go | func TemplateOutputArgs(templatePath string, args map[string]interface{}) (data []byte, err error) {
// Get the Template.
lang, _ := args[CurrentLocaleViewArg].(string)
template, err := MainTemplateLoader.TemplateLang(templatePath, lang)
if err != nil {
return nil, err
}
tr := &RenderTemplateResult{
Template: template,
ViewArgs: args,
}
b, err := tr.ToBytes()
if err != nil {
return nil, err
}
return b.Bytes(), nil
} | [
"func",
"TemplateOutputArgs",
"(",
"templatePath",
"string",
",",
"args",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"(",
"data",
"[",
"]",
"byte",
",",
"err",
"error",
")",
"{",
"// Get the Template.",
"lang",
",",
"_",
":=",
"args",
"[",
"CurrentLocaleViewArg",
"]",
".",
"(",
"string",
")",
"\n",
"template",
",",
"err",
":=",
"MainTemplateLoader",
".",
"TemplateLang",
"(",
"templatePath",
",",
"lang",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"tr",
":=",
"&",
"RenderTemplateResult",
"{",
"Template",
":",
"template",
",",
"ViewArgs",
":",
"args",
",",
"}",
"\n",
"b",
",",
"err",
":=",
"tr",
".",
"ToBytes",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"b",
".",
"Bytes",
"(",
")",
",",
"nil",
"\n",
"}"
] | // TemplateOutputArgs returns the result of the template rendered using the passed in arguments. | [
"TemplateOutputArgs",
"returns",
"the",
"result",
"of",
"the",
"template",
"rendered",
"using",
"the",
"passed",
"in",
"arguments",
"."
] | a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e | https://github.com/revel/revel/blob/a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e/template.go#L54-L70 | train |
revel/revel | template.go | Template | func (loader *TemplateLoader) Template(name string) (tmpl Template, err error) {
runtimeLoader := loader.runtimeLoader.Load().(*templateRuntime)
return runtimeLoader.TemplateLang(name, "")
} | go | func (loader *TemplateLoader) Template(name string) (tmpl Template, err error) {
runtimeLoader := loader.runtimeLoader.Load().(*templateRuntime)
return runtimeLoader.TemplateLang(name, "")
} | [
"func",
"(",
"loader",
"*",
"TemplateLoader",
")",
"Template",
"(",
"name",
"string",
")",
"(",
"tmpl",
"Template",
",",
"err",
"error",
")",
"{",
"runtimeLoader",
":=",
"loader",
".",
"runtimeLoader",
".",
"Load",
"(",
")",
".",
"(",
"*",
"templateRuntime",
")",
"\n",
"return",
"runtimeLoader",
".",
"TemplateLang",
"(",
"name",
",",
"\"",
"\"",
")",
"\n",
"}"
] | // DEPRECATED Use TemplateLang, will be removed in future release | [
"DEPRECATED",
"Use",
"TemplateLang",
"will",
"be",
"removed",
"in",
"future",
"release"
] | a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e | https://github.com/revel/revel/blob/a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e/template.go#L94-L97 | train |
revel/revel | template.go | findAndAddTemplate | func (runtimeLoader *templateRuntime) findAndAddTemplate(path, fullSrcDir, basePath string) (fileBytes []byte, err error) {
templateName := filepath.ToSlash(path[len(fullSrcDir)+1:])
// Convert template names to use forward slashes, even on Windows.
if os.PathSeparator == '\\' {
templateName = strings.Replace(templateName, `\`, `/`, -1) // `
}
// Check to see if template was found
if place, found := runtimeLoader.TemplatePaths[templateName]; found {
templateLog.Debug("findAndAddTemplate: Not Loading, template is already exists: ", "name", templateName, "old",
place, "new", path)
return
}
fileBytes, err = ioutil.ReadFile(path)
if err != nil {
templateLog.Error("findAndAddTemplate: Failed reading file:", "path", path, "error", err)
return
}
// Parse template file and replace the "_LOCAL_|" in the template with the module name
// allow for namespaces to be renamed "_LOCAL_(.*?)|"
if module := ModuleFromPath(path, false); module != nil {
fileBytes = namespaceReplace(fileBytes, module)
}
// if we have an engine picked for this template process it now
baseTemplate := NewBaseTemplate(templateName, path, basePath, fileBytes)
// Try to find a default engine for the file
for _, engine := range runtimeLoader.templatesAndEngineList {
if engine.Handles(baseTemplate) {
_, err = runtimeLoader.loadIntoEngine(engine, baseTemplate)
return
}
}
// Try all engines available
var defaultError error
for _, engine := range runtimeLoader.templatesAndEngineList {
if loaded, loaderr := runtimeLoader.loadIntoEngine(engine, baseTemplate); loaded {
return
} else {
templateLog.Debugf("findAndAddTemplate: Engine '%s' unable to compile %s %s", engine.Name(), path, loaderr.Error())
if defaultError == nil {
defaultError = loaderr
}
}
}
// Assign the error from the first parser
err = defaultError
// No engines could be found return the err
if err == nil {
err = fmt.Errorf("Failed to parse template file using engines %s", path)
}
return
} | go | func (runtimeLoader *templateRuntime) findAndAddTemplate(path, fullSrcDir, basePath string) (fileBytes []byte, err error) {
templateName := filepath.ToSlash(path[len(fullSrcDir)+1:])
// Convert template names to use forward slashes, even on Windows.
if os.PathSeparator == '\\' {
templateName = strings.Replace(templateName, `\`, `/`, -1) // `
}
// Check to see if template was found
if place, found := runtimeLoader.TemplatePaths[templateName]; found {
templateLog.Debug("findAndAddTemplate: Not Loading, template is already exists: ", "name", templateName, "old",
place, "new", path)
return
}
fileBytes, err = ioutil.ReadFile(path)
if err != nil {
templateLog.Error("findAndAddTemplate: Failed reading file:", "path", path, "error", err)
return
}
// Parse template file and replace the "_LOCAL_|" in the template with the module name
// allow for namespaces to be renamed "_LOCAL_(.*?)|"
if module := ModuleFromPath(path, false); module != nil {
fileBytes = namespaceReplace(fileBytes, module)
}
// if we have an engine picked for this template process it now
baseTemplate := NewBaseTemplate(templateName, path, basePath, fileBytes)
// Try to find a default engine for the file
for _, engine := range runtimeLoader.templatesAndEngineList {
if engine.Handles(baseTemplate) {
_, err = runtimeLoader.loadIntoEngine(engine, baseTemplate)
return
}
}
// Try all engines available
var defaultError error
for _, engine := range runtimeLoader.templatesAndEngineList {
if loaded, loaderr := runtimeLoader.loadIntoEngine(engine, baseTemplate); loaded {
return
} else {
templateLog.Debugf("findAndAddTemplate: Engine '%s' unable to compile %s %s", engine.Name(), path, loaderr.Error())
if defaultError == nil {
defaultError = loaderr
}
}
}
// Assign the error from the first parser
err = defaultError
// No engines could be found return the err
if err == nil {
err = fmt.Errorf("Failed to parse template file using engines %s", path)
}
return
} | [
"func",
"(",
"runtimeLoader",
"*",
"templateRuntime",
")",
"findAndAddTemplate",
"(",
"path",
",",
"fullSrcDir",
",",
"basePath",
"string",
")",
"(",
"fileBytes",
"[",
"]",
"byte",
",",
"err",
"error",
")",
"{",
"templateName",
":=",
"filepath",
".",
"ToSlash",
"(",
"path",
"[",
"len",
"(",
"fullSrcDir",
")",
"+",
"1",
":",
"]",
")",
"\n",
"// Convert template names to use forward slashes, even on Windows.",
"if",
"os",
".",
"PathSeparator",
"==",
"'\\\\'",
"{",
"templateName",
"=",
"strings",
".",
"Replace",
"(",
"templateName",
",",
"`\\`",
",",
"`/`",
",",
"-",
"1",
")",
"// `",
"\n",
"}",
"\n\n",
"// Check to see if template was found",
"if",
"place",
",",
"found",
":=",
"runtimeLoader",
".",
"TemplatePaths",
"[",
"templateName",
"]",
";",
"found",
"{",
"templateLog",
".",
"Debug",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"templateName",
",",
"\"",
"\"",
",",
"place",
",",
"\"",
"\"",
",",
"path",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"fileBytes",
",",
"err",
"=",
"ioutil",
".",
"ReadFile",
"(",
"path",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"templateLog",
".",
"Error",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"path",
",",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"\n",
"}",
"\n",
"// Parse template file and replace the \"_LOCAL_|\" in the template with the module name",
"// allow for namespaces to be renamed \"_LOCAL_(.*?)|\"",
"if",
"module",
":=",
"ModuleFromPath",
"(",
"path",
",",
"false",
")",
";",
"module",
"!=",
"nil",
"{",
"fileBytes",
"=",
"namespaceReplace",
"(",
"fileBytes",
",",
"module",
")",
"\n",
"}",
"\n\n",
"// if we have an engine picked for this template process it now",
"baseTemplate",
":=",
"NewBaseTemplate",
"(",
"templateName",
",",
"path",
",",
"basePath",
",",
"fileBytes",
")",
"\n\n",
"// Try to find a default engine for the file",
"for",
"_",
",",
"engine",
":=",
"range",
"runtimeLoader",
".",
"templatesAndEngineList",
"{",
"if",
"engine",
".",
"Handles",
"(",
"baseTemplate",
")",
"{",
"_",
",",
"err",
"=",
"runtimeLoader",
".",
"loadIntoEngine",
"(",
"engine",
",",
"baseTemplate",
")",
"\n",
"return",
"\n",
"}",
"\n",
"}",
"\n\n",
"// Try all engines available",
"var",
"defaultError",
"error",
"\n",
"for",
"_",
",",
"engine",
":=",
"range",
"runtimeLoader",
".",
"templatesAndEngineList",
"{",
"if",
"loaded",
",",
"loaderr",
":=",
"runtimeLoader",
".",
"loadIntoEngine",
"(",
"engine",
",",
"baseTemplate",
")",
";",
"loaded",
"{",
"return",
"\n",
"}",
"else",
"{",
"templateLog",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"engine",
".",
"Name",
"(",
")",
",",
"path",
",",
"loaderr",
".",
"Error",
"(",
")",
")",
"\n",
"if",
"defaultError",
"==",
"nil",
"{",
"defaultError",
"=",
"loaderr",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"// Assign the error from the first parser",
"err",
"=",
"defaultError",
"\n\n",
"// No engines could be found return the err",
"if",
"err",
"==",
"nil",
"{",
"err",
"=",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"path",
")",
"\n",
"}",
"\n\n",
"return",
"\n",
"}"
] | // Checks to see if template exists in templatePaths, if so it is skipped (templates are imported in order
// reads the template file into memory, replaces namespace keys with module (if found | [
"Checks",
"to",
"see",
"if",
"template",
"exists",
"in",
"templatePaths",
"if",
"so",
"it",
"is",
"skipped",
"(",
"templates",
"are",
"imported",
"in",
"order",
"reads",
"the",
"template",
"file",
"into",
"memory",
"replaces",
"namespace",
"keys",
"with",
"module",
"(",
"if",
"found"
] | a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e | https://github.com/revel/revel/blob/a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e/template.go#L258-L316 | train |
revel/revel | field.go | Flash | func (f *Field) Flash() string {
v, _ := f.viewArgs["flash"].(map[string]string)[f.Name]
return v
} | go | func (f *Field) Flash() string {
v, _ := f.viewArgs["flash"].(map[string]string)[f.Name]
return v
} | [
"func",
"(",
"f",
"*",
"Field",
")",
"Flash",
"(",
")",
"string",
"{",
"v",
",",
"_",
":=",
"f",
".",
"viewArgs",
"[",
"\"",
"\"",
"]",
".",
"(",
"map",
"[",
"string",
"]",
"string",
")",
"[",
"f",
".",
"Name",
"]",
"\n",
"return",
"v",
"\n",
"}"
] | // Flash returns the flashed value of this Field. | [
"Flash",
"returns",
"the",
"flashed",
"value",
"of",
"this",
"Field",
"."
] | a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e | https://github.com/revel/revel/blob/a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e/field.go#L37-L40 | train |
revel/revel | field.go | Options | func (f *Field) Options() []string {
if f.viewArgs["options"] == nil {
return nil
}
v, _ := f.viewArgs["options"].(map[string][]string)[f.Name]
return v
} | go | func (f *Field) Options() []string {
if f.viewArgs["options"] == nil {
return nil
}
v, _ := f.viewArgs["options"].(map[string][]string)[f.Name]
return v
} | [
"func",
"(",
"f",
"*",
"Field",
")",
"Options",
"(",
")",
"[",
"]",
"string",
"{",
"if",
"f",
".",
"viewArgs",
"[",
"\"",
"\"",
"]",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"v",
",",
"_",
":=",
"f",
".",
"viewArgs",
"[",
"\"",
"\"",
"]",
".",
"(",
"map",
"[",
"string",
"]",
"[",
"]",
"string",
")",
"[",
"f",
".",
"Name",
"]",
"\n",
"return",
"v",
"\n",
"}"
] | // Options returns the option list of this Field. | [
"Options",
"returns",
"the",
"option",
"list",
"of",
"this",
"Field",
"."
] | a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e | https://github.com/revel/revel/blob/a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e/field.go#L43-L49 | train |
revel/revel | field.go | FlashArray | func (f *Field) FlashArray() []string {
v := f.Flash()
if v == "" {
return []string{}
}
return strings.Split(v, ",")
} | go | func (f *Field) FlashArray() []string {
v := f.Flash()
if v == "" {
return []string{}
}
return strings.Split(v, ",")
} | [
"func",
"(",
"f",
"*",
"Field",
")",
"FlashArray",
"(",
")",
"[",
"]",
"string",
"{",
"v",
":=",
"f",
".",
"Flash",
"(",
")",
"\n",
"if",
"v",
"==",
"\"",
"\"",
"{",
"return",
"[",
"]",
"string",
"{",
"}",
"\n",
"}",
"\n",
"return",
"strings",
".",
"Split",
"(",
"v",
",",
"\"",
"\"",
")",
"\n",
"}"
] | // FlashArray returns the flashed value of this Field as a list split on comma. | [
"FlashArray",
"returns",
"the",
"flashed",
"value",
"of",
"this",
"Field",
"as",
"a",
"list",
"split",
"on",
"comma",
"."
] | a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e | https://github.com/revel/revel/blob/a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e/field.go#L52-L58 | train |
revel/revel | field.go | Value | func (f *Field) Value() interface{} {
pieces := strings.Split(f.Name, ".")
answer, ok := f.viewArgs[pieces[0]]
if !ok {
return ""
}
val := reflect.ValueOf(answer)
for i := 1; i < len(pieces); i++ {
if val.Kind() == reflect.Ptr {
val = val.Elem()
}
val = val.FieldByName(pieces[i])
if !val.IsValid() {
return ""
}
}
return val.Interface()
} | go | func (f *Field) Value() interface{} {
pieces := strings.Split(f.Name, ".")
answer, ok := f.viewArgs[pieces[0]]
if !ok {
return ""
}
val := reflect.ValueOf(answer)
for i := 1; i < len(pieces); i++ {
if val.Kind() == reflect.Ptr {
val = val.Elem()
}
val = val.FieldByName(pieces[i])
if !val.IsValid() {
return ""
}
}
return val.Interface()
} | [
"func",
"(",
"f",
"*",
"Field",
")",
"Value",
"(",
")",
"interface",
"{",
"}",
"{",
"pieces",
":=",
"strings",
".",
"Split",
"(",
"f",
".",
"Name",
",",
"\"",
"\"",
")",
"\n",
"answer",
",",
"ok",
":=",
"f",
".",
"viewArgs",
"[",
"pieces",
"[",
"0",
"]",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n\n",
"val",
":=",
"reflect",
".",
"ValueOf",
"(",
"answer",
")",
"\n",
"for",
"i",
":=",
"1",
";",
"i",
"<",
"len",
"(",
"pieces",
")",
";",
"i",
"++",
"{",
"if",
"val",
".",
"Kind",
"(",
")",
"==",
"reflect",
".",
"Ptr",
"{",
"val",
"=",
"val",
".",
"Elem",
"(",
")",
"\n",
"}",
"\n",
"val",
"=",
"val",
".",
"FieldByName",
"(",
"pieces",
"[",
"i",
"]",
")",
"\n",
"if",
"!",
"val",
".",
"IsValid",
"(",
")",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"val",
".",
"Interface",
"(",
")",
"\n",
"}"
] | // Value returns the current value of this Field. | [
"Value",
"returns",
"the",
"current",
"value",
"of",
"this",
"Field",
"."
] | a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e | https://github.com/revel/revel/blob/a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e/field.go#L61-L80 | train |
revel/revel | field.go | ErrorClass | func (f *Field) ErrorClass() string {
if f.Error != nil {
if errorClass, ok := f.viewArgs["ERROR_CLASS"]; ok {
return errorClass.(string)
}
return ErrorCSSClass
}
return ""
} | go | func (f *Field) ErrorClass() string {
if f.Error != nil {
if errorClass, ok := f.viewArgs["ERROR_CLASS"]; ok {
return errorClass.(string)
}
return ErrorCSSClass
}
return ""
} | [
"func",
"(",
"f",
"*",
"Field",
")",
"ErrorClass",
"(",
")",
"string",
"{",
"if",
"f",
".",
"Error",
"!=",
"nil",
"{",
"if",
"errorClass",
",",
"ok",
":=",
"f",
".",
"viewArgs",
"[",
"\"",
"\"",
"]",
";",
"ok",
"{",
"return",
"errorClass",
".",
"(",
"string",
")",
"\n",
"}",
"\n",
"return",
"ErrorCSSClass",
"\n",
"}",
"\n",
"return",
"\"",
"\"",
"\n",
"}"
] | // ErrorClass returns ErrorCSSClass if this field has a validation error, else empty string. | [
"ErrorClass",
"returns",
"ErrorCSSClass",
"if",
"this",
"field",
"has",
"a",
"validation",
"error",
"else",
"empty",
"string",
"."
] | a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e | https://github.com/revel/revel/blob/a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e/field.go#L83-L91 | train |
revel/revel | field.go | ShortName | func (f *Field) ShortName() string {
name := f.Name
if i := strings.LastIndex(name, "."); i > 0 {
name = name[i+1:]
}
return f.Translate(name)
} | go | func (f *Field) ShortName() string {
name := f.Name
if i := strings.LastIndex(name, "."); i > 0 {
name = name[i+1:]
}
return f.Translate(name)
} | [
"func",
"(",
"f",
"*",
"Field",
")",
"ShortName",
"(",
")",
"string",
"{",
"name",
":=",
"f",
".",
"Name",
"\n",
"if",
"i",
":=",
"strings",
".",
"LastIndex",
"(",
"name",
",",
"\"",
"\"",
")",
";",
"i",
">",
"0",
"{",
"name",
"=",
"name",
"[",
"i",
"+",
"1",
":",
"]",
"\n",
"}",
"\n",
"return",
"f",
".",
"Translate",
"(",
"name",
")",
"\n",
"}"
] | // Get the short name and translate it | [
"Get",
"the",
"short",
"name",
"and",
"translate",
"it"
] | a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e | https://github.com/revel/revel/blob/a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e/field.go#L94-L100 | train |
revel/revel | field.go | Translate | func (f *Field) Translate(text string, args ...interface{}) string {
if f.controller != nil {
text = f.controller.Message(text, args...)
}
return text
} | go | func (f *Field) Translate(text string, args ...interface{}) string {
if f.controller != nil {
text = f.controller.Message(text, args...)
}
return text
} | [
"func",
"(",
"f",
"*",
"Field",
")",
"Translate",
"(",
"text",
"string",
",",
"args",
"...",
"interface",
"{",
"}",
")",
"string",
"{",
"if",
"f",
".",
"controller",
"!=",
"nil",
"{",
"text",
"=",
"f",
".",
"controller",
".",
"Message",
"(",
"text",
",",
"args",
"...",
")",
"\n",
"}",
"\n",
"return",
"text",
"\n",
"}"
] | // Translate the text | [
"Translate",
"the",
"text"
] | a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e | https://github.com/revel/revel/blob/a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e/field.go#L103-L108 | train |
revel/revel | binder.go | ValueBinder | func ValueBinder(f func(value string, typ reflect.Type) reflect.Value) func(*Params, string, reflect.Type) reflect.Value {
return func(params *Params, name string, typ reflect.Type) reflect.Value {
vals, ok := params.Values[name]
if !ok || len(vals) == 0 {
return reflect.Zero(typ)
}
return f(vals[0], typ)
}
} | go | func ValueBinder(f func(value string, typ reflect.Type) reflect.Value) func(*Params, string, reflect.Type) reflect.Value {
return func(params *Params, name string, typ reflect.Type) reflect.Value {
vals, ok := params.Values[name]
if !ok || len(vals) == 0 {
return reflect.Zero(typ)
}
return f(vals[0], typ)
}
} | [
"func",
"ValueBinder",
"(",
"f",
"func",
"(",
"value",
"string",
",",
"typ",
"reflect",
".",
"Type",
")",
"reflect",
".",
"Value",
")",
"func",
"(",
"*",
"Params",
",",
"string",
",",
"reflect",
".",
"Type",
")",
"reflect",
".",
"Value",
"{",
"return",
"func",
"(",
"params",
"*",
"Params",
",",
"name",
"string",
",",
"typ",
"reflect",
".",
"Type",
")",
"reflect",
".",
"Value",
"{",
"vals",
",",
"ok",
":=",
"params",
".",
"Values",
"[",
"name",
"]",
"\n",
"if",
"!",
"ok",
"||",
"len",
"(",
"vals",
")",
"==",
"0",
"{",
"return",
"reflect",
".",
"Zero",
"(",
"typ",
")",
"\n",
"}",
"\n",
"return",
"f",
"(",
"vals",
"[",
"0",
"]",
",",
"typ",
")",
"\n",
"}",
"\n",
"}"
] | // ValueBinder is adapter for easily making one-key-value binders. | [
"ValueBinder",
"is",
"adapter",
"for",
"easily",
"making",
"one",
"-",
"key",
"-",
"value",
"binders",
"."
] | a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e | https://github.com/revel/revel/blob/a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e/binder.go#L50-L58 | train |
revel/revel | binder.go | getMultipartFile | func getMultipartFile(params *Params, name string) multipart.File {
for _, fileHeader := range params.Files[name] {
file, err := fileHeader.Open()
if err == nil {
return file
}
binderLog.Warn("getMultipartFile: Failed to open uploaded file", "name", name, "error", err)
}
return nil
} | go | func getMultipartFile(params *Params, name string) multipart.File {
for _, fileHeader := range params.Files[name] {
file, err := fileHeader.Open()
if err == nil {
return file
}
binderLog.Warn("getMultipartFile: Failed to open uploaded file", "name", name, "error", err)
}
return nil
} | [
"func",
"getMultipartFile",
"(",
"params",
"*",
"Params",
",",
"name",
"string",
")",
"multipart",
".",
"File",
"{",
"for",
"_",
",",
"fileHeader",
":=",
"range",
"params",
".",
"Files",
"[",
"name",
"]",
"{",
"file",
",",
"err",
":=",
"fileHeader",
".",
"Open",
"(",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"return",
"file",
"\n",
"}",
"\n",
"binderLog",
".",
"Warn",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"name",
",",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // Helper that returns an upload of the given name, or nil. | [
"Helper",
"that",
"returns",
"an",
"upload",
"of",
"the",
"given",
"name",
"or",
"nil",
"."
] | a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e | https://github.com/revel/revel/blob/a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e/binder.go#L353-L362 | train |
revel/revel | binder.go | Bind | func Bind(params *Params, name string, typ reflect.Type) reflect.Value {
if binder, found := binderForType(typ); found {
return binder.Bind(params, name, typ)
}
return reflect.Zero(typ)
} | go | func Bind(params *Params, name string, typ reflect.Type) reflect.Value {
if binder, found := binderForType(typ); found {
return binder.Bind(params, name, typ)
}
return reflect.Zero(typ)
} | [
"func",
"Bind",
"(",
"params",
"*",
"Params",
",",
"name",
"string",
",",
"typ",
"reflect",
".",
"Type",
")",
"reflect",
".",
"Value",
"{",
"if",
"binder",
",",
"found",
":=",
"binderForType",
"(",
"typ",
")",
";",
"found",
"{",
"return",
"binder",
".",
"Bind",
"(",
"params",
",",
"name",
",",
"typ",
")",
"\n",
"}",
"\n",
"return",
"reflect",
".",
"Zero",
"(",
"typ",
")",
"\n",
"}"
] | // Bind takes the name and type of the desired parameter and constructs it
// from one or more values from Params.
// Returns the zero value of the type upon any sort of failure. | [
"Bind",
"takes",
"the",
"name",
"and",
"type",
"of",
"the",
"desired",
"parameter",
"and",
"constructs",
"it",
"from",
"one",
"or",
"more",
"values",
"from",
"Params",
".",
"Returns",
"the",
"zero",
"value",
"of",
"the",
"type",
"upon",
"any",
"sort",
"of",
"failure",
"."
] | a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e | https://github.com/revel/revel/blob/a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e/binder.go#L468-L473 | train |
revel/revel | params.go | ParseParams | func ParseParams(params *Params, req *Request) {
params.Query = req.GetQuery()
// Parse the body depending on the content type.
switch req.ContentType {
case "application/x-www-form-urlencoded":
// Typical form.
var err error
if params.Form, err = req.GetForm(); err != nil {
paramsLogger.Warn("ParseParams: Error parsing request body", "error", err)
}
case "multipart/form-data":
// Multipart form.
if mp, err := req.GetMultipartForm(); err != nil {
paramsLogger.Warn("ParseParams: parsing request body:", "error", err)
} else {
params.Form = mp.GetValues()
params.Files = mp.GetFiles()
}
case "application/json":
fallthrough
case "text/json":
if body := req.GetBody(); body != nil {
if content, err := ioutil.ReadAll(body); err == nil {
// We wont bind it until we determine what we are binding too
params.JSON = content
} else {
paramsLogger.Error("ParseParams: Failed to ready request body bytes", "error", err)
}
} else {
paramsLogger.Info("ParseParams: Json post received with empty body")
}
}
params.Values = params.calcValues()
} | go | func ParseParams(params *Params, req *Request) {
params.Query = req.GetQuery()
// Parse the body depending on the content type.
switch req.ContentType {
case "application/x-www-form-urlencoded":
// Typical form.
var err error
if params.Form, err = req.GetForm(); err != nil {
paramsLogger.Warn("ParseParams: Error parsing request body", "error", err)
}
case "multipart/form-data":
// Multipart form.
if mp, err := req.GetMultipartForm(); err != nil {
paramsLogger.Warn("ParseParams: parsing request body:", "error", err)
} else {
params.Form = mp.GetValues()
params.Files = mp.GetFiles()
}
case "application/json":
fallthrough
case "text/json":
if body := req.GetBody(); body != nil {
if content, err := ioutil.ReadAll(body); err == nil {
// We wont bind it until we determine what we are binding too
params.JSON = content
} else {
paramsLogger.Error("ParseParams: Failed to ready request body bytes", "error", err)
}
} else {
paramsLogger.Info("ParseParams: Json post received with empty body")
}
}
params.Values = params.calcValues()
} | [
"func",
"ParseParams",
"(",
"params",
"*",
"Params",
",",
"req",
"*",
"Request",
")",
"{",
"params",
".",
"Query",
"=",
"req",
".",
"GetQuery",
"(",
")",
"\n\n",
"// Parse the body depending on the content type.",
"switch",
"req",
".",
"ContentType",
"{",
"case",
"\"",
"\"",
":",
"// Typical form.",
"var",
"err",
"error",
"\n",
"if",
"params",
".",
"Form",
",",
"err",
"=",
"req",
".",
"GetForm",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"paramsLogger",
".",
"Warn",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"case",
"\"",
"\"",
":",
"// Multipart form.",
"if",
"mp",
",",
"err",
":=",
"req",
".",
"GetMultipartForm",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"paramsLogger",
".",
"Warn",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"else",
"{",
"params",
".",
"Form",
"=",
"mp",
".",
"GetValues",
"(",
")",
"\n",
"params",
".",
"Files",
"=",
"mp",
".",
"GetFiles",
"(",
")",
"\n",
"}",
"\n",
"case",
"\"",
"\"",
":",
"fallthrough",
"\n",
"case",
"\"",
"\"",
":",
"if",
"body",
":=",
"req",
".",
"GetBody",
"(",
")",
";",
"body",
"!=",
"nil",
"{",
"if",
"content",
",",
"err",
":=",
"ioutil",
".",
"ReadAll",
"(",
"body",
")",
";",
"err",
"==",
"nil",
"{",
"// We wont bind it until we determine what we are binding too",
"params",
".",
"JSON",
"=",
"content",
"\n",
"}",
"else",
"{",
"paramsLogger",
".",
"Error",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"}",
"else",
"{",
"paramsLogger",
".",
"Info",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"params",
".",
"Values",
"=",
"params",
".",
"calcValues",
"(",
")",
"\n",
"}"
] | // ParseParams parses the `http.Request` params into `revel.Controller.Params` | [
"ParseParams",
"parses",
"the",
"http",
".",
"Request",
"params",
"into",
"revel",
".",
"Controller",
".",
"Params"
] | a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e | https://github.com/revel/revel/blob/a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e/params.go#L43-L79 | train |
revel/revel | params.go | Bind | func (p *Params) Bind(dest interface{}, name string) {
value := reflect.ValueOf(dest)
if value.Kind() != reflect.Ptr {
paramsLogger.Panic("Bind: revel/params: non-pointer passed to Bind: " + name)
}
value = value.Elem()
if !value.CanSet() {
paramsLogger.Panic("Bind: revel/params: non-settable variable passed to Bind: " + name)
}
// Remove the json from the Params, this will stop the binder from attempting
// to use the json data to populate the destination interface. We do not want
// to do this on a named bind directly against the param, it is ok to happen when
// the action is invoked.
jsonData := p.JSON
p.JSON = nil
value.Set(Bind(p, name, value.Type()))
p.JSON = jsonData
} | go | func (p *Params) Bind(dest interface{}, name string) {
value := reflect.ValueOf(dest)
if value.Kind() != reflect.Ptr {
paramsLogger.Panic("Bind: revel/params: non-pointer passed to Bind: " + name)
}
value = value.Elem()
if !value.CanSet() {
paramsLogger.Panic("Bind: revel/params: non-settable variable passed to Bind: " + name)
}
// Remove the json from the Params, this will stop the binder from attempting
// to use the json data to populate the destination interface. We do not want
// to do this on a named bind directly against the param, it is ok to happen when
// the action is invoked.
jsonData := p.JSON
p.JSON = nil
value.Set(Bind(p, name, value.Type()))
p.JSON = jsonData
} | [
"func",
"(",
"p",
"*",
"Params",
")",
"Bind",
"(",
"dest",
"interface",
"{",
"}",
",",
"name",
"string",
")",
"{",
"value",
":=",
"reflect",
".",
"ValueOf",
"(",
"dest",
")",
"\n",
"if",
"value",
".",
"Kind",
"(",
")",
"!=",
"reflect",
".",
"Ptr",
"{",
"paramsLogger",
".",
"Panic",
"(",
"\"",
"\"",
"+",
"name",
")",
"\n",
"}",
"\n",
"value",
"=",
"value",
".",
"Elem",
"(",
")",
"\n",
"if",
"!",
"value",
".",
"CanSet",
"(",
")",
"{",
"paramsLogger",
".",
"Panic",
"(",
"\"",
"\"",
"+",
"name",
")",
"\n",
"}",
"\n\n",
"// Remove the json from the Params, this will stop the binder from attempting",
"// to use the json data to populate the destination interface. We do not want",
"// to do this on a named bind directly against the param, it is ok to happen when",
"// the action is invoked.",
"jsonData",
":=",
"p",
".",
"JSON",
"\n",
"p",
".",
"JSON",
"=",
"nil",
"\n",
"value",
".",
"Set",
"(",
"Bind",
"(",
"p",
",",
"name",
",",
"value",
".",
"Type",
"(",
")",
")",
")",
"\n",
"p",
".",
"JSON",
"=",
"jsonData",
"\n",
"}"
] | // Bind looks for the named parameter, converts it to the requested type, and
// writes it into "dest", which must be settable. If the value can not be
// parsed, "dest" is set to the zero value. | [
"Bind",
"looks",
"for",
"the",
"named",
"parameter",
"converts",
"it",
"to",
"the",
"requested",
"type",
"and",
"writes",
"it",
"into",
"dest",
"which",
"must",
"be",
"settable",
".",
"If",
"the",
"value",
"can",
"not",
"be",
"parsed",
"dest",
"is",
"set",
"to",
"the",
"zero",
"value",
"."
] | a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e | https://github.com/revel/revel/blob/a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e/params.go#L84-L102 | train |
revel/revel | params.go | BindJSON | func (p *Params) BindJSON(dest interface{}) error {
value := reflect.ValueOf(dest)
if value.Kind() != reflect.Ptr {
paramsLogger.Warn("BindJSON: Not a pointer")
return errors.New("BindJSON not a pointer")
}
if err := json.Unmarshal(p.JSON, dest); err != nil {
paramsLogger.Warn("BindJSON: Unable to unmarshal request:", "error", err)
return err
}
return nil
} | go | func (p *Params) BindJSON(dest interface{}) error {
value := reflect.ValueOf(dest)
if value.Kind() != reflect.Ptr {
paramsLogger.Warn("BindJSON: Not a pointer")
return errors.New("BindJSON not a pointer")
}
if err := json.Unmarshal(p.JSON, dest); err != nil {
paramsLogger.Warn("BindJSON: Unable to unmarshal request:", "error", err)
return err
}
return nil
} | [
"func",
"(",
"p",
"*",
"Params",
")",
"BindJSON",
"(",
"dest",
"interface",
"{",
"}",
")",
"error",
"{",
"value",
":=",
"reflect",
".",
"ValueOf",
"(",
"dest",
")",
"\n",
"if",
"value",
".",
"Kind",
"(",
")",
"!=",
"reflect",
".",
"Ptr",
"{",
"paramsLogger",
".",
"Warn",
"(",
"\"",
"\"",
")",
"\n",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"err",
":=",
"json",
".",
"Unmarshal",
"(",
"p",
".",
"JSON",
",",
"dest",
")",
";",
"err",
"!=",
"nil",
"{",
"paramsLogger",
".",
"Warn",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // Bind binds the JSON data to the dest. | [
"Bind",
"binds",
"the",
"JSON",
"data",
"to",
"the",
"dest",
"."
] | a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e | https://github.com/revel/revel/blob/a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e/params.go#L105-L116 | train |
revel/revel | params.go | calcValues | func (p *Params) calcValues() url.Values {
numParams := len(p.Query) + len(p.Fixed) + len(p.Route) + len(p.Form)
// If there were no params, return an empty map.
if numParams == 0 {
return make(url.Values, 0)
}
// If only one of the param sources has anything, return that directly.
switch numParams {
case len(p.Query):
return p.Query
case len(p.Route):
return p.Route
case len(p.Fixed):
return p.Fixed
case len(p.Form):
return p.Form
}
// Copy everything into a param map,
// order of priority is least to most trusted
values := make(url.Values, numParams)
// ?query string parameters are first
for k, v := range p.Query {
values[k] = append(values[k], v...)
}
// form parameters append
for k, v := range p.Form {
values[k] = append(values[k], v...)
}
// :/path parameters overwrite
for k, v := range p.Route {
values[k] = v
}
// fixed route parameters overwrite
for k, v := range p.Fixed {
values[k] = v
}
return values
} | go | func (p *Params) calcValues() url.Values {
numParams := len(p.Query) + len(p.Fixed) + len(p.Route) + len(p.Form)
// If there were no params, return an empty map.
if numParams == 0 {
return make(url.Values, 0)
}
// If only one of the param sources has anything, return that directly.
switch numParams {
case len(p.Query):
return p.Query
case len(p.Route):
return p.Route
case len(p.Fixed):
return p.Fixed
case len(p.Form):
return p.Form
}
// Copy everything into a param map,
// order of priority is least to most trusted
values := make(url.Values, numParams)
// ?query string parameters are first
for k, v := range p.Query {
values[k] = append(values[k], v...)
}
// form parameters append
for k, v := range p.Form {
values[k] = append(values[k], v...)
}
// :/path parameters overwrite
for k, v := range p.Route {
values[k] = v
}
// fixed route parameters overwrite
for k, v := range p.Fixed {
values[k] = v
}
return values
} | [
"func",
"(",
"p",
"*",
"Params",
")",
"calcValues",
"(",
")",
"url",
".",
"Values",
"{",
"numParams",
":=",
"len",
"(",
"p",
".",
"Query",
")",
"+",
"len",
"(",
"p",
".",
"Fixed",
")",
"+",
"len",
"(",
"p",
".",
"Route",
")",
"+",
"len",
"(",
"p",
".",
"Form",
")",
"\n\n",
"// If there were no params, return an empty map.",
"if",
"numParams",
"==",
"0",
"{",
"return",
"make",
"(",
"url",
".",
"Values",
",",
"0",
")",
"\n",
"}",
"\n\n",
"// If only one of the param sources has anything, return that directly.",
"switch",
"numParams",
"{",
"case",
"len",
"(",
"p",
".",
"Query",
")",
":",
"return",
"p",
".",
"Query",
"\n",
"case",
"len",
"(",
"p",
".",
"Route",
")",
":",
"return",
"p",
".",
"Route",
"\n",
"case",
"len",
"(",
"p",
".",
"Fixed",
")",
":",
"return",
"p",
".",
"Fixed",
"\n",
"case",
"len",
"(",
"p",
".",
"Form",
")",
":",
"return",
"p",
".",
"Form",
"\n",
"}",
"\n\n",
"// Copy everything into a param map,",
"// order of priority is least to most trusted",
"values",
":=",
"make",
"(",
"url",
".",
"Values",
",",
"numParams",
")",
"\n\n",
"// ?query string parameters are first",
"for",
"k",
",",
"v",
":=",
"range",
"p",
".",
"Query",
"{",
"values",
"[",
"k",
"]",
"=",
"append",
"(",
"values",
"[",
"k",
"]",
",",
"v",
"...",
")",
"\n",
"}",
"\n\n",
"// form parameters append",
"for",
"k",
",",
"v",
":=",
"range",
"p",
".",
"Form",
"{",
"values",
"[",
"k",
"]",
"=",
"append",
"(",
"values",
"[",
"k",
"]",
",",
"v",
"...",
")",
"\n",
"}",
"\n\n",
"// :/path parameters overwrite",
"for",
"k",
",",
"v",
":=",
"range",
"p",
".",
"Route",
"{",
"values",
"[",
"k",
"]",
"=",
"v",
"\n",
"}",
"\n\n",
"// fixed route parameters overwrite",
"for",
"k",
",",
"v",
":=",
"range",
"p",
".",
"Fixed",
"{",
"values",
"[",
"k",
"]",
"=",
"v",
"\n",
"}",
"\n\n",
"return",
"values",
"\n",
"}"
] | // calcValues returns a unified view of the component param maps. | [
"calcValues",
"returns",
"a",
"unified",
"view",
"of",
"the",
"component",
"param",
"maps",
"."
] | a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e | https://github.com/revel/revel/blob/a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e/params.go#L119-L164 | train |
revel/revel | router.go | NewRoute | func NewRoute(moduleSource *Module, method, path, action, fixedArgs, routesPath string, line int) (r *Route) {
// Handle fixed arguments
argsReader := strings.NewReader(string(namespaceReplace([]byte(fixedArgs), moduleSource)))
csvReader := csv.NewReader(argsReader)
csvReader.TrimLeadingSpace = true
fargs, err := csvReader.Read()
if err != nil && err != io.EOF {
routerLog.Error("NewRoute: Invalid fixed parameters for string ", "error", err, "fixedargs", fixedArgs)
}
r = &Route{
ModuleSource: moduleSource,
Method: strings.ToUpper(method),
Path: path,
Action: string(namespaceReplace([]byte(action), moduleSource)),
FixedParams: fargs,
TreePath: treePath(strings.ToUpper(method), path),
routesPath: routesPath,
line: line,
}
// URL pattern
if !strings.HasPrefix(r.Path, "/") {
routerLog.Error("NewRoute: Absolute URL required.")
return
}
// Ignore the not found status code
if action != httpStatusCode {
routerLog.Debugf("NewRoute: New splitActionPath path:%s action:%s", path, action)
pathData, found := splitActionPath(&ActionPathData{ModuleSource: moduleSource, Route: r}, r.Action, false)
if found {
if pathData.TypeOfController != nil {
// Assign controller type to avoid looking it up based on name
r.TypeOfController = pathData.TypeOfController
// Create the fixed parameters
if l := len(pathData.Route.FixedParams); l > 0 && len(pathData.FixedParamsByName) == 0 {
methodType := pathData.TypeOfController.Method(pathData.MethodName)
if methodType != nil {
pathData.FixedParamsByName = make(map[string]string, l)
for i, argValue := range pathData.Route.FixedParams {
Unbind(pathData.FixedParamsByName, methodType.Args[i].Name, argValue)
}
} else {
routerLog.Panicf("NewRoute: Method %s not found for controller %s", pathData.MethodName, pathData.ControllerName)
}
}
}
r.ControllerNamespace = pathData.ControllerNamespace
r.ControllerName = pathData.ControllerName
r.ModuleSource = pathData.ModuleSource
r.MethodName = pathData.MethodName
// The same action path could be used for multiple routes (like the Static.Serve)
} else {
routerLog.Panicf("NewRoute: Failed to find controller for route path action %s \n%#v\n", path+"?"+r.Action, actionPathCacheMap)
}
}
return
} | go | func NewRoute(moduleSource *Module, method, path, action, fixedArgs, routesPath string, line int) (r *Route) {
// Handle fixed arguments
argsReader := strings.NewReader(string(namespaceReplace([]byte(fixedArgs), moduleSource)))
csvReader := csv.NewReader(argsReader)
csvReader.TrimLeadingSpace = true
fargs, err := csvReader.Read()
if err != nil && err != io.EOF {
routerLog.Error("NewRoute: Invalid fixed parameters for string ", "error", err, "fixedargs", fixedArgs)
}
r = &Route{
ModuleSource: moduleSource,
Method: strings.ToUpper(method),
Path: path,
Action: string(namespaceReplace([]byte(action), moduleSource)),
FixedParams: fargs,
TreePath: treePath(strings.ToUpper(method), path),
routesPath: routesPath,
line: line,
}
// URL pattern
if !strings.HasPrefix(r.Path, "/") {
routerLog.Error("NewRoute: Absolute URL required.")
return
}
// Ignore the not found status code
if action != httpStatusCode {
routerLog.Debugf("NewRoute: New splitActionPath path:%s action:%s", path, action)
pathData, found := splitActionPath(&ActionPathData{ModuleSource: moduleSource, Route: r}, r.Action, false)
if found {
if pathData.TypeOfController != nil {
// Assign controller type to avoid looking it up based on name
r.TypeOfController = pathData.TypeOfController
// Create the fixed parameters
if l := len(pathData.Route.FixedParams); l > 0 && len(pathData.FixedParamsByName) == 0 {
methodType := pathData.TypeOfController.Method(pathData.MethodName)
if methodType != nil {
pathData.FixedParamsByName = make(map[string]string, l)
for i, argValue := range pathData.Route.FixedParams {
Unbind(pathData.FixedParamsByName, methodType.Args[i].Name, argValue)
}
} else {
routerLog.Panicf("NewRoute: Method %s not found for controller %s", pathData.MethodName, pathData.ControllerName)
}
}
}
r.ControllerNamespace = pathData.ControllerNamespace
r.ControllerName = pathData.ControllerName
r.ModuleSource = pathData.ModuleSource
r.MethodName = pathData.MethodName
// The same action path could be used for multiple routes (like the Static.Serve)
} else {
routerLog.Panicf("NewRoute: Failed to find controller for route path action %s \n%#v\n", path+"?"+r.Action, actionPathCacheMap)
}
}
return
} | [
"func",
"NewRoute",
"(",
"moduleSource",
"*",
"Module",
",",
"method",
",",
"path",
",",
"action",
",",
"fixedArgs",
",",
"routesPath",
"string",
",",
"line",
"int",
")",
"(",
"r",
"*",
"Route",
")",
"{",
"// Handle fixed arguments",
"argsReader",
":=",
"strings",
".",
"NewReader",
"(",
"string",
"(",
"namespaceReplace",
"(",
"[",
"]",
"byte",
"(",
"fixedArgs",
")",
",",
"moduleSource",
")",
")",
")",
"\n",
"csvReader",
":=",
"csv",
".",
"NewReader",
"(",
"argsReader",
")",
"\n",
"csvReader",
".",
"TrimLeadingSpace",
"=",
"true",
"\n",
"fargs",
",",
"err",
":=",
"csvReader",
".",
"Read",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"&&",
"err",
"!=",
"io",
".",
"EOF",
"{",
"routerLog",
".",
"Error",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"err",
",",
"\"",
"\"",
",",
"fixedArgs",
")",
"\n",
"}",
"\n\n",
"r",
"=",
"&",
"Route",
"{",
"ModuleSource",
":",
"moduleSource",
",",
"Method",
":",
"strings",
".",
"ToUpper",
"(",
"method",
")",
",",
"Path",
":",
"path",
",",
"Action",
":",
"string",
"(",
"namespaceReplace",
"(",
"[",
"]",
"byte",
"(",
"action",
")",
",",
"moduleSource",
")",
")",
",",
"FixedParams",
":",
"fargs",
",",
"TreePath",
":",
"treePath",
"(",
"strings",
".",
"ToUpper",
"(",
"method",
")",
",",
"path",
")",
",",
"routesPath",
":",
"routesPath",
",",
"line",
":",
"line",
",",
"}",
"\n\n",
"// URL pattern",
"if",
"!",
"strings",
".",
"HasPrefix",
"(",
"r",
".",
"Path",
",",
"\"",
"\"",
")",
"{",
"routerLog",
".",
"Error",
"(",
"\"",
"\"",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"// Ignore the not found status code",
"if",
"action",
"!=",
"httpStatusCode",
"{",
"routerLog",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"path",
",",
"action",
")",
"\n",
"pathData",
",",
"found",
":=",
"splitActionPath",
"(",
"&",
"ActionPathData",
"{",
"ModuleSource",
":",
"moduleSource",
",",
"Route",
":",
"r",
"}",
",",
"r",
".",
"Action",
",",
"false",
")",
"\n",
"if",
"found",
"{",
"if",
"pathData",
".",
"TypeOfController",
"!=",
"nil",
"{",
"// Assign controller type to avoid looking it up based on name",
"r",
".",
"TypeOfController",
"=",
"pathData",
".",
"TypeOfController",
"\n",
"// Create the fixed parameters",
"if",
"l",
":=",
"len",
"(",
"pathData",
".",
"Route",
".",
"FixedParams",
")",
";",
"l",
">",
"0",
"&&",
"len",
"(",
"pathData",
".",
"FixedParamsByName",
")",
"==",
"0",
"{",
"methodType",
":=",
"pathData",
".",
"TypeOfController",
".",
"Method",
"(",
"pathData",
".",
"MethodName",
")",
"\n",
"if",
"methodType",
"!=",
"nil",
"{",
"pathData",
".",
"FixedParamsByName",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"string",
",",
"l",
")",
"\n",
"for",
"i",
",",
"argValue",
":=",
"range",
"pathData",
".",
"Route",
".",
"FixedParams",
"{",
"Unbind",
"(",
"pathData",
".",
"FixedParamsByName",
",",
"methodType",
".",
"Args",
"[",
"i",
"]",
".",
"Name",
",",
"argValue",
")",
"\n",
"}",
"\n",
"}",
"else",
"{",
"routerLog",
".",
"Panicf",
"(",
"\"",
"\"",
",",
"pathData",
".",
"MethodName",
",",
"pathData",
".",
"ControllerName",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"r",
".",
"ControllerNamespace",
"=",
"pathData",
".",
"ControllerNamespace",
"\n",
"r",
".",
"ControllerName",
"=",
"pathData",
".",
"ControllerName",
"\n",
"r",
".",
"ModuleSource",
"=",
"pathData",
".",
"ModuleSource",
"\n",
"r",
".",
"MethodName",
"=",
"pathData",
".",
"MethodName",
"\n\n",
"// The same action path could be used for multiple routes (like the Static.Serve)",
"}",
"else",
"{",
"routerLog",
".",
"Panicf",
"(",
"\"",
"\\n",
"\\n",
"\"",
",",
"path",
"+",
"\"",
"\"",
"+",
"r",
".",
"Action",
",",
"actionPathCacheMap",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] | // NewRoute prepares the route to be used in matching. | [
"NewRoute",
"prepares",
"the",
"route",
"to",
"be",
"used",
"in",
"matching",
"."
] | a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e | https://github.com/revel/revel/blob/a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e/router.go#L91-L150 | train |
revel/revel | router.go | Refresh | func (router *Router) Refresh() (err *Error) {
RaiseEvent(ROUTE_REFRESH_REQUESTED, nil)
router.Routes, err = parseRoutesFile(appModule, router.path, "", true)
RaiseEvent(ROUTE_REFRESH_COMPLETED, nil)
if err != nil {
return
}
err = router.updateTree()
return
} | go | func (router *Router) Refresh() (err *Error) {
RaiseEvent(ROUTE_REFRESH_REQUESTED, nil)
router.Routes, err = parseRoutesFile(appModule, router.path, "", true)
RaiseEvent(ROUTE_REFRESH_COMPLETED, nil)
if err != nil {
return
}
err = router.updateTree()
return
} | [
"func",
"(",
"router",
"*",
"Router",
")",
"Refresh",
"(",
")",
"(",
"err",
"*",
"Error",
")",
"{",
"RaiseEvent",
"(",
"ROUTE_REFRESH_REQUESTED",
",",
"nil",
")",
"\n",
"router",
".",
"Routes",
",",
"err",
"=",
"parseRoutesFile",
"(",
"appModule",
",",
"router",
".",
"path",
",",
"\"",
"\"",
",",
"true",
")",
"\n",
"RaiseEvent",
"(",
"ROUTE_REFRESH_COMPLETED",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"err",
"=",
"router",
".",
"updateTree",
"(",
")",
"\n",
"return",
"\n",
"}"
] | // Refresh re-reads the routes file and re-calculates the routing table.
// Returns an error if a specified action could not be found. | [
"Refresh",
"re",
"-",
"reads",
"the",
"routes",
"file",
"and",
"re",
"-",
"calculates",
"the",
"routing",
"table",
".",
"Returns",
"an",
"error",
"if",
"a",
"specified",
"action",
"could",
"not",
"be",
"found",
"."
] | a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e | https://github.com/revel/revel/blob/a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e/router.go#L249-L258 | train |
revel/revel | router.go | parseRoutesFile | func parseRoutesFile(moduleSource *Module, routesPath, joinedPath string, validate bool) ([]*Route, *Error) {
contentBytes, err := ioutil.ReadFile(routesPath)
if err != nil {
return nil, &Error{
Title: "Failed to load routes file",
Description: err.Error(),
}
}
return parseRoutes(moduleSource, routesPath, joinedPath, string(contentBytes), validate)
} | go | func parseRoutesFile(moduleSource *Module, routesPath, joinedPath string, validate bool) ([]*Route, *Error) {
contentBytes, err := ioutil.ReadFile(routesPath)
if err != nil {
return nil, &Error{
Title: "Failed to load routes file",
Description: err.Error(),
}
}
return parseRoutes(moduleSource, routesPath, joinedPath, string(contentBytes), validate)
} | [
"func",
"parseRoutesFile",
"(",
"moduleSource",
"*",
"Module",
",",
"routesPath",
",",
"joinedPath",
"string",
",",
"validate",
"bool",
")",
"(",
"[",
"]",
"*",
"Route",
",",
"*",
"Error",
")",
"{",
"contentBytes",
",",
"err",
":=",
"ioutil",
".",
"ReadFile",
"(",
"routesPath",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"&",
"Error",
"{",
"Title",
":",
"\"",
"\"",
",",
"Description",
":",
"err",
".",
"Error",
"(",
")",
",",
"}",
"\n",
"}",
"\n",
"return",
"parseRoutes",
"(",
"moduleSource",
",",
"routesPath",
",",
"joinedPath",
",",
"string",
"(",
"contentBytes",
")",
",",
"validate",
")",
"\n",
"}"
] | // parseRoutesFile reads the given routes file and returns the contained routes. | [
"parseRoutesFile",
"reads",
"the",
"given",
"routes",
"file",
"and",
"returns",
"the",
"contained",
"routes",
"."
] | a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e | https://github.com/revel/revel/blob/a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e/router.go#L429-L438 | train |
revel/revel | router.go | parseRoutes | func parseRoutes(moduleSource *Module, routesPath, joinedPath, content string, validate bool) ([]*Route, *Error) {
var routes []*Route
// For each line..
for n, line := range strings.Split(content, "\n") {
line = strings.TrimSpace(line)
if len(line) == 0 || line[0] == '#' {
continue
}
const modulePrefix = "module:"
// Handle included routes from modules.
// e.g. "module:testrunner" imports all routes from that module.
if strings.HasPrefix(line, modulePrefix) {
moduleRoutes, err := getModuleRoutes(line[len(modulePrefix):], joinedPath, validate)
if err != nil {
return nil, routeError(err, routesPath, content, n)
}
routes = append(routes, moduleRoutes...)
continue
}
// A single route
method, path, action, fixedArgs, found := parseRouteLine(line)
if !found {
continue
}
// this will avoid accidental double forward slashes in a route.
// this also avoids pathtree freaking out and causing a runtime panic
// because of the double slashes
if strings.HasSuffix(joinedPath, "/") && strings.HasPrefix(path, "/") {
joinedPath = joinedPath[0 : len(joinedPath)-1]
}
path = strings.Join([]string{AppRoot, joinedPath, path}, "")
// This will import the module routes under the path described in the
// routes file (joinedPath param). e.g. "* /jobs module:jobs" -> all
// routes' paths will have the path /jobs prepended to them.
// See #282 for more info
if method == "*" && strings.HasPrefix(action, modulePrefix) {
moduleRoutes, err := getModuleRoutes(action[len(modulePrefix):], path, validate)
if err != nil {
return nil, routeError(err, routesPath, content, n)
}
routes = append(routes, moduleRoutes...)
continue
}
route := NewRoute(moduleSource, method, path, action, fixedArgs, routesPath, n)
routes = append(routes, route)
if validate {
if err := validateRoute(route); err != nil {
return nil, routeError(err, routesPath, content, n)
}
}
}
return routes, nil
} | go | func parseRoutes(moduleSource *Module, routesPath, joinedPath, content string, validate bool) ([]*Route, *Error) {
var routes []*Route
// For each line..
for n, line := range strings.Split(content, "\n") {
line = strings.TrimSpace(line)
if len(line) == 0 || line[0] == '#' {
continue
}
const modulePrefix = "module:"
// Handle included routes from modules.
// e.g. "module:testrunner" imports all routes from that module.
if strings.HasPrefix(line, modulePrefix) {
moduleRoutes, err := getModuleRoutes(line[len(modulePrefix):], joinedPath, validate)
if err != nil {
return nil, routeError(err, routesPath, content, n)
}
routes = append(routes, moduleRoutes...)
continue
}
// A single route
method, path, action, fixedArgs, found := parseRouteLine(line)
if !found {
continue
}
// this will avoid accidental double forward slashes in a route.
// this also avoids pathtree freaking out and causing a runtime panic
// because of the double slashes
if strings.HasSuffix(joinedPath, "/") && strings.HasPrefix(path, "/") {
joinedPath = joinedPath[0 : len(joinedPath)-1]
}
path = strings.Join([]string{AppRoot, joinedPath, path}, "")
// This will import the module routes under the path described in the
// routes file (joinedPath param). e.g. "* /jobs module:jobs" -> all
// routes' paths will have the path /jobs prepended to them.
// See #282 for more info
if method == "*" && strings.HasPrefix(action, modulePrefix) {
moduleRoutes, err := getModuleRoutes(action[len(modulePrefix):], path, validate)
if err != nil {
return nil, routeError(err, routesPath, content, n)
}
routes = append(routes, moduleRoutes...)
continue
}
route := NewRoute(moduleSource, method, path, action, fixedArgs, routesPath, n)
routes = append(routes, route)
if validate {
if err := validateRoute(route); err != nil {
return nil, routeError(err, routesPath, content, n)
}
}
}
return routes, nil
} | [
"func",
"parseRoutes",
"(",
"moduleSource",
"*",
"Module",
",",
"routesPath",
",",
"joinedPath",
",",
"content",
"string",
",",
"validate",
"bool",
")",
"(",
"[",
"]",
"*",
"Route",
",",
"*",
"Error",
")",
"{",
"var",
"routes",
"[",
"]",
"*",
"Route",
"\n\n",
"// For each line..",
"for",
"n",
",",
"line",
":=",
"range",
"strings",
".",
"Split",
"(",
"content",
",",
"\"",
"\\n",
"\"",
")",
"{",
"line",
"=",
"strings",
".",
"TrimSpace",
"(",
"line",
")",
"\n",
"if",
"len",
"(",
"line",
")",
"==",
"0",
"||",
"line",
"[",
"0",
"]",
"==",
"'#'",
"{",
"continue",
"\n",
"}",
"\n\n",
"const",
"modulePrefix",
"=",
"\"",
"\"",
"\n\n",
"// Handle included routes from modules.",
"// e.g. \"module:testrunner\" imports all routes from that module.",
"if",
"strings",
".",
"HasPrefix",
"(",
"line",
",",
"modulePrefix",
")",
"{",
"moduleRoutes",
",",
"err",
":=",
"getModuleRoutes",
"(",
"line",
"[",
"len",
"(",
"modulePrefix",
")",
":",
"]",
",",
"joinedPath",
",",
"validate",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"routeError",
"(",
"err",
",",
"routesPath",
",",
"content",
",",
"n",
")",
"\n",
"}",
"\n",
"routes",
"=",
"append",
"(",
"routes",
",",
"moduleRoutes",
"...",
")",
"\n",
"continue",
"\n",
"}",
"\n\n",
"// A single route",
"method",
",",
"path",
",",
"action",
",",
"fixedArgs",
",",
"found",
":=",
"parseRouteLine",
"(",
"line",
")",
"\n",
"if",
"!",
"found",
"{",
"continue",
"\n",
"}",
"\n\n",
"// this will avoid accidental double forward slashes in a route.",
"// this also avoids pathtree freaking out and causing a runtime panic",
"// because of the double slashes",
"if",
"strings",
".",
"HasSuffix",
"(",
"joinedPath",
",",
"\"",
"\"",
")",
"&&",
"strings",
".",
"HasPrefix",
"(",
"path",
",",
"\"",
"\"",
")",
"{",
"joinedPath",
"=",
"joinedPath",
"[",
"0",
":",
"len",
"(",
"joinedPath",
")",
"-",
"1",
"]",
"\n",
"}",
"\n",
"path",
"=",
"strings",
".",
"Join",
"(",
"[",
"]",
"string",
"{",
"AppRoot",
",",
"joinedPath",
",",
"path",
"}",
",",
"\"",
"\"",
")",
"\n\n",
"// This will import the module routes under the path described in the",
"// routes file (joinedPath param). e.g. \"* /jobs module:jobs\" -> all",
"// routes' paths will have the path /jobs prepended to them.",
"// See #282 for more info",
"if",
"method",
"==",
"\"",
"\"",
"&&",
"strings",
".",
"HasPrefix",
"(",
"action",
",",
"modulePrefix",
")",
"{",
"moduleRoutes",
",",
"err",
":=",
"getModuleRoutes",
"(",
"action",
"[",
"len",
"(",
"modulePrefix",
")",
":",
"]",
",",
"path",
",",
"validate",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"routeError",
"(",
"err",
",",
"routesPath",
",",
"content",
",",
"n",
")",
"\n",
"}",
"\n",
"routes",
"=",
"append",
"(",
"routes",
",",
"moduleRoutes",
"...",
")",
"\n",
"continue",
"\n",
"}",
"\n\n",
"route",
":=",
"NewRoute",
"(",
"moduleSource",
",",
"method",
",",
"path",
",",
"action",
",",
"fixedArgs",
",",
"routesPath",
",",
"n",
")",
"\n",
"routes",
"=",
"append",
"(",
"routes",
",",
"route",
")",
"\n\n",
"if",
"validate",
"{",
"if",
"err",
":=",
"validateRoute",
"(",
"route",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"routeError",
"(",
"err",
",",
"routesPath",
",",
"content",
",",
"n",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"routes",
",",
"nil",
"\n",
"}"
] | // parseRoutes reads the content of a routes file into the routing table. | [
"parseRoutes",
"reads",
"the",
"content",
"of",
"a",
"routes",
"file",
"into",
"the",
"routing",
"table",
"."
] | a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e | https://github.com/revel/revel/blob/a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e/router.go#L441-L502 | train |
revel/revel | router.go | validateRoute | func validateRoute(route *Route) error {
// Skip 404s
if route.Action == httpStatusCode {
return nil
}
// Skip variable routes.
if route.ControllerName[0] == ':' || route.MethodName[0] == ':' {
return nil
}
// Precheck to see if controller exists
if _, found := controllers[route.ControllerNamespace+route.ControllerName]; !found {
// Scan through controllers to find module
for _, c := range controllers {
controllerName := strings.ToLower(c.Type.Name())
if controllerName == route.ControllerName {
route.ControllerNamespace = c.ModuleSource.Name + namespaceSeperator
routerLog.Warn("validateRoute: Matched empty namespace route for %s to this namespace %s for the route %s", controllerName, c.ModuleSource.Name, route.Path)
}
}
}
// TODO need to check later
// does it do only validation or validation and instantiate the controller.
var c Controller
return c.SetTypeAction(route.ControllerNamespace+route.ControllerName, route.MethodName, route.TypeOfController)
} | go | func validateRoute(route *Route) error {
// Skip 404s
if route.Action == httpStatusCode {
return nil
}
// Skip variable routes.
if route.ControllerName[0] == ':' || route.MethodName[0] == ':' {
return nil
}
// Precheck to see if controller exists
if _, found := controllers[route.ControllerNamespace+route.ControllerName]; !found {
// Scan through controllers to find module
for _, c := range controllers {
controllerName := strings.ToLower(c.Type.Name())
if controllerName == route.ControllerName {
route.ControllerNamespace = c.ModuleSource.Name + namespaceSeperator
routerLog.Warn("validateRoute: Matched empty namespace route for %s to this namespace %s for the route %s", controllerName, c.ModuleSource.Name, route.Path)
}
}
}
// TODO need to check later
// does it do only validation or validation and instantiate the controller.
var c Controller
return c.SetTypeAction(route.ControllerNamespace+route.ControllerName, route.MethodName, route.TypeOfController)
} | [
"func",
"validateRoute",
"(",
"route",
"*",
"Route",
")",
"error",
"{",
"// Skip 404s",
"if",
"route",
".",
"Action",
"==",
"httpStatusCode",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"// Skip variable routes.",
"if",
"route",
".",
"ControllerName",
"[",
"0",
"]",
"==",
"':'",
"||",
"route",
".",
"MethodName",
"[",
"0",
"]",
"==",
"':'",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"// Precheck to see if controller exists",
"if",
"_",
",",
"found",
":=",
"controllers",
"[",
"route",
".",
"ControllerNamespace",
"+",
"route",
".",
"ControllerName",
"]",
";",
"!",
"found",
"{",
"// Scan through controllers to find module",
"for",
"_",
",",
"c",
":=",
"range",
"controllers",
"{",
"controllerName",
":=",
"strings",
".",
"ToLower",
"(",
"c",
".",
"Type",
".",
"Name",
"(",
")",
")",
"\n",
"if",
"controllerName",
"==",
"route",
".",
"ControllerName",
"{",
"route",
".",
"ControllerNamespace",
"=",
"c",
".",
"ModuleSource",
".",
"Name",
"+",
"namespaceSeperator",
"\n",
"routerLog",
".",
"Warn",
"(",
"\"",
"\"",
",",
"controllerName",
",",
"c",
".",
"ModuleSource",
".",
"Name",
",",
"route",
".",
"Path",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"// TODO need to check later",
"// does it do only validation or validation and instantiate the controller.",
"var",
"c",
"Controller",
"\n",
"return",
"c",
".",
"SetTypeAction",
"(",
"route",
".",
"ControllerNamespace",
"+",
"route",
".",
"ControllerName",
",",
"route",
".",
"MethodName",
",",
"route",
".",
"TypeOfController",
")",
"\n",
"}"
] | // validateRoute checks that every specified action exists. | [
"validateRoute",
"checks",
"that",
"every",
"specified",
"action",
"exists",
"."
] | a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e | https://github.com/revel/revel/blob/a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e/router.go#L505-L532 | train |
revel/revel | router.go | routeError | func routeError(err error, routesPath, content string, n int) *Error {
if revelError, ok := err.(*Error); ok {
return revelError
}
// Load the route file content if necessary
if content == "" {
if contentBytes, er := ioutil.ReadFile(routesPath); er != nil {
routerLog.Error("routeError: Failed to read route file ", "file", routesPath, "error", er)
} else {
content = string(contentBytes)
}
}
return &Error{
Title: "Route validation error",
Description: err.Error(),
Path: routesPath,
Line: n + 1,
SourceLines: strings.Split(content, "\n"),
Stack: fmt.Sprintf("%s", logger.NewCallStack()),
}
} | go | func routeError(err error, routesPath, content string, n int) *Error {
if revelError, ok := err.(*Error); ok {
return revelError
}
// Load the route file content if necessary
if content == "" {
if contentBytes, er := ioutil.ReadFile(routesPath); er != nil {
routerLog.Error("routeError: Failed to read route file ", "file", routesPath, "error", er)
} else {
content = string(contentBytes)
}
}
return &Error{
Title: "Route validation error",
Description: err.Error(),
Path: routesPath,
Line: n + 1,
SourceLines: strings.Split(content, "\n"),
Stack: fmt.Sprintf("%s", logger.NewCallStack()),
}
} | [
"func",
"routeError",
"(",
"err",
"error",
",",
"routesPath",
",",
"content",
"string",
",",
"n",
"int",
")",
"*",
"Error",
"{",
"if",
"revelError",
",",
"ok",
":=",
"err",
".",
"(",
"*",
"Error",
")",
";",
"ok",
"{",
"return",
"revelError",
"\n",
"}",
"\n",
"// Load the route file content if necessary",
"if",
"content",
"==",
"\"",
"\"",
"{",
"if",
"contentBytes",
",",
"er",
":=",
"ioutil",
".",
"ReadFile",
"(",
"routesPath",
")",
";",
"er",
"!=",
"nil",
"{",
"routerLog",
".",
"Error",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"routesPath",
",",
"\"",
"\"",
",",
"er",
")",
"\n",
"}",
"else",
"{",
"content",
"=",
"string",
"(",
"contentBytes",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"&",
"Error",
"{",
"Title",
":",
"\"",
"\"",
",",
"Description",
":",
"err",
".",
"Error",
"(",
")",
",",
"Path",
":",
"routesPath",
",",
"Line",
":",
"n",
"+",
"1",
",",
"SourceLines",
":",
"strings",
".",
"Split",
"(",
"content",
",",
"\"",
"\\n",
"\"",
")",
",",
"Stack",
":",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"logger",
".",
"NewCallStack",
"(",
")",
")",
",",
"}",
"\n",
"}"
] | // routeError adds context to a simple error message. | [
"routeError",
"adds",
"context",
"to",
"a",
"simple",
"error",
"message",
"."
] | a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e | https://github.com/revel/revel/blob/a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e/router.go#L535-L555 | train |
revel/revel | router.go | getModuleRoutes | func getModuleRoutes(moduleName, joinedPath string, validate bool) (routes []*Route, err *Error) {
// Look up the module. It may be not found due to the common case of e.g. the
// testrunner module being active only in dev mode.
module, found := ModuleByName(moduleName)
if !found {
routerLog.Debug("getModuleRoutes: Skipping routes for inactive module", "module", moduleName)
return nil, nil
}
routePath := filepath.Join(module.Path, "conf", "routes")
if _, e := os.Stat(routePath); e == nil {
routes, err = parseRoutesFile(module, routePath, joinedPath, validate)
}
if err == nil {
for _, route := range routes {
route.ModuleSource = module
}
}
return routes, err
} | go | func getModuleRoutes(moduleName, joinedPath string, validate bool) (routes []*Route, err *Error) {
// Look up the module. It may be not found due to the common case of e.g. the
// testrunner module being active only in dev mode.
module, found := ModuleByName(moduleName)
if !found {
routerLog.Debug("getModuleRoutes: Skipping routes for inactive module", "module", moduleName)
return nil, nil
}
routePath := filepath.Join(module.Path, "conf", "routes")
if _, e := os.Stat(routePath); e == nil {
routes, err = parseRoutesFile(module, routePath, joinedPath, validate)
}
if err == nil {
for _, route := range routes {
route.ModuleSource = module
}
}
return routes, err
} | [
"func",
"getModuleRoutes",
"(",
"moduleName",
",",
"joinedPath",
"string",
",",
"validate",
"bool",
")",
"(",
"routes",
"[",
"]",
"*",
"Route",
",",
"err",
"*",
"Error",
")",
"{",
"// Look up the module. It may be not found due to the common case of e.g. the",
"// testrunner module being active only in dev mode.",
"module",
",",
"found",
":=",
"ModuleByName",
"(",
"moduleName",
")",
"\n",
"if",
"!",
"found",
"{",
"routerLog",
".",
"Debug",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"moduleName",
")",
"\n",
"return",
"nil",
",",
"nil",
"\n",
"}",
"\n",
"routePath",
":=",
"filepath",
".",
"Join",
"(",
"module",
".",
"Path",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"if",
"_",
",",
"e",
":=",
"os",
".",
"Stat",
"(",
"routePath",
")",
";",
"e",
"==",
"nil",
"{",
"routes",
",",
"err",
"=",
"parseRoutesFile",
"(",
"module",
",",
"routePath",
",",
"joinedPath",
",",
"validate",
")",
"\n",
"}",
"\n",
"if",
"err",
"==",
"nil",
"{",
"for",
"_",
",",
"route",
":=",
"range",
"routes",
"{",
"route",
".",
"ModuleSource",
"=",
"module",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"routes",
",",
"err",
"\n",
"}"
] | // getModuleRoutes loads the routes file for the given module and returns the
// list of routes. | [
"getModuleRoutes",
"loads",
"the",
"routes",
"file",
"for",
"the",
"given",
"module",
"and",
"returns",
"the",
"list",
"of",
"routes",
"."
] | a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e | https://github.com/revel/revel/blob/a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e/router.go#L559-L578 | train |
revel/revel | router.go | HTTPMethodOverride | func HTTPMethodOverride(c *Controller, fc []Filter) {
// An array of HTTP verbs allowed.
verbs := []string{"POST", "PUT", "PATCH", "DELETE"}
method := strings.ToUpper(c.Request.Method)
if method == "POST" {
param := ""
if f, err := c.Request.GetForm(); err == nil {
param = strings.ToUpper(f.Get("_method"))
}
if len(param) > 0 {
override := false
// Check if param is allowed
for _, verb := range verbs {
if verb == param {
override = true
break
}
}
if override {
c.Request.Method = param
} else {
c.Response.Status = 405
c.Result = c.RenderError(&Error{
Title: "Method not allowed",
Description: "Method " + param + " is not allowed (valid: " + strings.Join(verbs, ", ") + ")",
})
return
}
}
}
fc[0](c, fc[1:]) // Execute the next filter stage.
} | go | func HTTPMethodOverride(c *Controller, fc []Filter) {
// An array of HTTP verbs allowed.
verbs := []string{"POST", "PUT", "PATCH", "DELETE"}
method := strings.ToUpper(c.Request.Method)
if method == "POST" {
param := ""
if f, err := c.Request.GetForm(); err == nil {
param = strings.ToUpper(f.Get("_method"))
}
if len(param) > 0 {
override := false
// Check if param is allowed
for _, verb := range verbs {
if verb == param {
override = true
break
}
}
if override {
c.Request.Method = param
} else {
c.Response.Status = 405
c.Result = c.RenderError(&Error{
Title: "Method not allowed",
Description: "Method " + param + " is not allowed (valid: " + strings.Join(verbs, ", ") + ")",
})
return
}
}
}
fc[0](c, fc[1:]) // Execute the next filter stage.
} | [
"func",
"HTTPMethodOverride",
"(",
"c",
"*",
"Controller",
",",
"fc",
"[",
"]",
"Filter",
")",
"{",
"// An array of HTTP verbs allowed.",
"verbs",
":=",
"[",
"]",
"string",
"{",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
"}",
"\n\n",
"method",
":=",
"strings",
".",
"ToUpper",
"(",
"c",
".",
"Request",
".",
"Method",
")",
"\n\n",
"if",
"method",
"==",
"\"",
"\"",
"{",
"param",
":=",
"\"",
"\"",
"\n",
"if",
"f",
",",
"err",
":=",
"c",
".",
"Request",
".",
"GetForm",
"(",
")",
";",
"err",
"==",
"nil",
"{",
"param",
"=",
"strings",
".",
"ToUpper",
"(",
"f",
".",
"Get",
"(",
"\"",
"\"",
")",
")",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"param",
")",
">",
"0",
"{",
"override",
":=",
"false",
"\n",
"// Check if param is allowed",
"for",
"_",
",",
"verb",
":=",
"range",
"verbs",
"{",
"if",
"verb",
"==",
"param",
"{",
"override",
"=",
"true",
"\n",
"break",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"override",
"{",
"c",
".",
"Request",
".",
"Method",
"=",
"param",
"\n",
"}",
"else",
"{",
"c",
".",
"Response",
".",
"Status",
"=",
"405",
"\n",
"c",
".",
"Result",
"=",
"c",
".",
"RenderError",
"(",
"&",
"Error",
"{",
"Title",
":",
"\"",
"\"",
",",
"Description",
":",
"\"",
"\"",
"+",
"param",
"+",
"\"",
"\"",
"+",
"strings",
".",
"Join",
"(",
"verbs",
",",
"\"",
"\"",
")",
"+",
"\"",
"\"",
",",
"}",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"}",
"\n",
"}",
"\n\n",
"fc",
"[",
"0",
"]",
"(",
"c",
",",
"fc",
"[",
"1",
":",
"]",
")",
"// Execute the next filter stage.",
"\n",
"}"
] | // HTTPMethodOverride overrides allowed http methods via form or browser param | [
"HTTPMethodOverride",
"overrides",
"allowed",
"http",
"methods",
"via",
"form",
"or",
"browser",
"param"
] | a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e | https://github.com/revel/revel/blob/a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e/router.go#L796-L833 | train |
revel/revel | cache/inmemory.go | convertTypeToUint64 | func (c InMemoryCache) convertTypeToUint64(key string) (newValue uint64, err error) {
v, found := c.cache.Get(key)
if !found {
return newValue, ErrCacheMiss
}
switch v.(type) {
case int:
newValue = uint64(v.(int))
case int8:
newValue = uint64(v.(int8))
case int16:
newValue = uint64(v.(int16))
case int32:
newValue = uint64(v.(int32))
case int64:
newValue = uint64(v.(int64))
case uint:
newValue = uint64(v.(uint))
case uintptr:
newValue = uint64(v.(uintptr))
case uint8:
newValue = uint64(v.(uint8))
case uint16:
newValue = uint64(v.(uint16))
case uint32:
newValue = uint64(v.(uint32))
case uint64:
newValue = uint64(v.(uint64))
case float32:
newValue = uint64(v.(float32))
case float64:
newValue = uint64(v.(float64))
default:
err = ErrInvalidValue
}
return
} | go | func (c InMemoryCache) convertTypeToUint64(key string) (newValue uint64, err error) {
v, found := c.cache.Get(key)
if !found {
return newValue, ErrCacheMiss
}
switch v.(type) {
case int:
newValue = uint64(v.(int))
case int8:
newValue = uint64(v.(int8))
case int16:
newValue = uint64(v.(int16))
case int32:
newValue = uint64(v.(int32))
case int64:
newValue = uint64(v.(int64))
case uint:
newValue = uint64(v.(uint))
case uintptr:
newValue = uint64(v.(uintptr))
case uint8:
newValue = uint64(v.(uint8))
case uint16:
newValue = uint64(v.(uint16))
case uint32:
newValue = uint64(v.(uint32))
case uint64:
newValue = uint64(v.(uint64))
case float32:
newValue = uint64(v.(float32))
case float64:
newValue = uint64(v.(float64))
default:
err = ErrInvalidValue
}
return
} | [
"func",
"(",
"c",
"InMemoryCache",
")",
"convertTypeToUint64",
"(",
"key",
"string",
")",
"(",
"newValue",
"uint64",
",",
"err",
"error",
")",
"{",
"v",
",",
"found",
":=",
"c",
".",
"cache",
".",
"Get",
"(",
"key",
")",
"\n",
"if",
"!",
"found",
"{",
"return",
"newValue",
",",
"ErrCacheMiss",
"\n",
"}",
"\n\n",
"switch",
"v",
".",
"(",
"type",
")",
"{",
"case",
"int",
":",
"newValue",
"=",
"uint64",
"(",
"v",
".",
"(",
"int",
")",
")",
"\n",
"case",
"int8",
":",
"newValue",
"=",
"uint64",
"(",
"v",
".",
"(",
"int8",
")",
")",
"\n",
"case",
"int16",
":",
"newValue",
"=",
"uint64",
"(",
"v",
".",
"(",
"int16",
")",
")",
"\n",
"case",
"int32",
":",
"newValue",
"=",
"uint64",
"(",
"v",
".",
"(",
"int32",
")",
")",
"\n",
"case",
"int64",
":",
"newValue",
"=",
"uint64",
"(",
"v",
".",
"(",
"int64",
")",
")",
"\n",
"case",
"uint",
":",
"newValue",
"=",
"uint64",
"(",
"v",
".",
"(",
"uint",
")",
")",
"\n",
"case",
"uintptr",
":",
"newValue",
"=",
"uint64",
"(",
"v",
".",
"(",
"uintptr",
")",
")",
"\n",
"case",
"uint8",
":",
"newValue",
"=",
"uint64",
"(",
"v",
".",
"(",
"uint8",
")",
")",
"\n",
"case",
"uint16",
":",
"newValue",
"=",
"uint64",
"(",
"v",
".",
"(",
"uint16",
")",
")",
"\n",
"case",
"uint32",
":",
"newValue",
"=",
"uint64",
"(",
"v",
".",
"(",
"uint32",
")",
")",
"\n",
"case",
"uint64",
":",
"newValue",
"=",
"uint64",
"(",
"v",
".",
"(",
"uint64",
")",
")",
"\n",
"case",
"float32",
":",
"newValue",
"=",
"uint64",
"(",
"v",
".",
"(",
"float32",
")",
")",
"\n",
"case",
"float64",
":",
"newValue",
"=",
"uint64",
"(",
"v",
".",
"(",
"float64",
")",
")",
"\n",
"default",
":",
"err",
"=",
"ErrInvalidValue",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] | // Fetches and returns the converted type to a uint64 | [
"Fetches",
"and",
"returns",
"the",
"converted",
"type",
"to",
"a",
"uint64"
] | a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e | https://github.com/revel/revel/blob/a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e/cache/inmemory.go#L126-L163 | train |
revel/revel | cache/serialization.go | Deserialize | func Deserialize(byt []byte, ptr interface{}) (err error) {
if data, ok := ptr.(*[]byte); ok {
*data = byt
return
}
if v := reflect.ValueOf(ptr); v.Kind() == reflect.Ptr {
switch p := v.Elem(); p.Kind() {
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
var i int64
i, err = strconv.ParseInt(string(byt), 10, 64)
if err != nil {
cacheLog.Error("Deserialize: failed to parse int", "value", string(byt), "error", err)
} else {
p.SetInt(i)
}
return
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
var i uint64
i, err = strconv.ParseUint(string(byt), 10, 64)
if err != nil {
cacheLog.Error("Deserialize: failed to parse uint", "value", string(byt), "error", err)
} else {
p.SetUint(i)
}
return
}
}
b := bytes.NewBuffer(byt)
decoder := gob.NewDecoder(b)
if err = decoder.Decode(ptr); err != nil {
cacheLog.Error("Deserialize: glob decoding failed", "error", err)
return
}
return
} | go | func Deserialize(byt []byte, ptr interface{}) (err error) {
if data, ok := ptr.(*[]byte); ok {
*data = byt
return
}
if v := reflect.ValueOf(ptr); v.Kind() == reflect.Ptr {
switch p := v.Elem(); p.Kind() {
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
var i int64
i, err = strconv.ParseInt(string(byt), 10, 64)
if err != nil {
cacheLog.Error("Deserialize: failed to parse int", "value", string(byt), "error", err)
} else {
p.SetInt(i)
}
return
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
var i uint64
i, err = strconv.ParseUint(string(byt), 10, 64)
if err != nil {
cacheLog.Error("Deserialize: failed to parse uint", "value", string(byt), "error", err)
} else {
p.SetUint(i)
}
return
}
}
b := bytes.NewBuffer(byt)
decoder := gob.NewDecoder(b)
if err = decoder.Decode(ptr); err != nil {
cacheLog.Error("Deserialize: glob decoding failed", "error", err)
return
}
return
} | [
"func",
"Deserialize",
"(",
"byt",
"[",
"]",
"byte",
",",
"ptr",
"interface",
"{",
"}",
")",
"(",
"err",
"error",
")",
"{",
"if",
"data",
",",
"ok",
":=",
"ptr",
".",
"(",
"*",
"[",
"]",
"byte",
")",
";",
"ok",
"{",
"*",
"data",
"=",
"byt",
"\n",
"return",
"\n",
"}",
"\n\n",
"if",
"v",
":=",
"reflect",
".",
"ValueOf",
"(",
"ptr",
")",
";",
"v",
".",
"Kind",
"(",
")",
"==",
"reflect",
".",
"Ptr",
"{",
"switch",
"p",
":=",
"v",
".",
"Elem",
"(",
")",
";",
"p",
".",
"Kind",
"(",
")",
"{",
"case",
"reflect",
".",
"Int",
",",
"reflect",
".",
"Int8",
",",
"reflect",
".",
"Int16",
",",
"reflect",
".",
"Int32",
",",
"reflect",
".",
"Int64",
":",
"var",
"i",
"int64",
"\n",
"i",
",",
"err",
"=",
"strconv",
".",
"ParseInt",
"(",
"string",
"(",
"byt",
")",
",",
"10",
",",
"64",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"cacheLog",
".",
"Error",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"string",
"(",
"byt",
")",
",",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"else",
"{",
"p",
".",
"SetInt",
"(",
"i",
")",
"\n",
"}",
"\n",
"return",
"\n\n",
"case",
"reflect",
".",
"Uint",
",",
"reflect",
".",
"Uint8",
",",
"reflect",
".",
"Uint16",
",",
"reflect",
".",
"Uint32",
",",
"reflect",
".",
"Uint64",
":",
"var",
"i",
"uint64",
"\n",
"i",
",",
"err",
"=",
"strconv",
".",
"ParseUint",
"(",
"string",
"(",
"byt",
")",
",",
"10",
",",
"64",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"cacheLog",
".",
"Error",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"string",
"(",
"byt",
")",
",",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"else",
"{",
"p",
".",
"SetUint",
"(",
"i",
")",
"\n",
"}",
"\n",
"return",
"\n",
"}",
"\n",
"}",
"\n\n",
"b",
":=",
"bytes",
".",
"NewBuffer",
"(",
"byt",
")",
"\n",
"decoder",
":=",
"gob",
".",
"NewDecoder",
"(",
"b",
")",
"\n",
"if",
"err",
"=",
"decoder",
".",
"Decode",
"(",
"ptr",
")",
";",
"err",
"!=",
"nil",
"{",
"cacheLog",
".",
"Error",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] | // Deserialize transforms bytes produced by Serialize back into a Go object,
// storing it into "ptr", which must be a pointer to the value type. | [
"Deserialize",
"transforms",
"bytes",
"produced",
"by",
"Serialize",
"back",
"into",
"a",
"Go",
"object",
"storing",
"it",
"into",
"ptr",
"which",
"must",
"be",
"a",
"pointer",
"to",
"the",
"value",
"type",
"."
] | a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e | https://github.com/revel/revel/blob/a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e/cache/serialization.go#L41-L78 | train |
revel/revel | controller.go | NewController | func NewController(context ServerContext) *Controller {
c := NewControllerEmpty()
c.SetController(context)
return c
} | go | func NewController(context ServerContext) *Controller {
c := NewControllerEmpty()
c.SetController(context)
return c
} | [
"func",
"NewController",
"(",
"context",
"ServerContext",
")",
"*",
"Controller",
"{",
"c",
":=",
"NewControllerEmpty",
"(",
")",
"\n",
"c",
".",
"SetController",
"(",
"context",
")",
"\n",
"return",
"c",
"\n",
"}"
] | // New controller, creates a new instance wrapping the request and response in it | [
"New",
"controller",
"creates",
"a",
"new",
"instance",
"wrapping",
"the",
"request",
"and",
"response",
"in",
"it"
] | a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e | https://github.com/revel/revel/blob/a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e/controller.go#L58-L62 | train |
revel/revel | controller.go | SetController | func (c *Controller) SetController(context ServerContext) {
c.Request.SetRequest(context.GetRequest())
c.Response.SetResponse(context.GetResponse())
c.Request.controller = c
c.Params = new(Params)
c.Args = map[string]interface{}{}
c.ViewArgs = map[string]interface{}{
"RunMode": RunMode,
"DevMode": DevMode,
}
} | go | func (c *Controller) SetController(context ServerContext) {
c.Request.SetRequest(context.GetRequest())
c.Response.SetResponse(context.GetResponse())
c.Request.controller = c
c.Params = new(Params)
c.Args = map[string]interface{}{}
c.ViewArgs = map[string]interface{}{
"RunMode": RunMode,
"DevMode": DevMode,
}
} | [
"func",
"(",
"c",
"*",
"Controller",
")",
"SetController",
"(",
"context",
"ServerContext",
")",
"{",
"c",
".",
"Request",
".",
"SetRequest",
"(",
"context",
".",
"GetRequest",
"(",
")",
")",
"\n",
"c",
".",
"Response",
".",
"SetResponse",
"(",
"context",
".",
"GetResponse",
"(",
")",
")",
"\n",
"c",
".",
"Request",
".",
"controller",
"=",
"c",
"\n",
"c",
".",
"Params",
"=",
"new",
"(",
"Params",
")",
"\n",
"c",
".",
"Args",
"=",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"}",
"\n",
"c",
".",
"ViewArgs",
"=",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"\"",
"\"",
":",
"RunMode",
",",
"\"",
"\"",
":",
"DevMode",
",",
"}",
"\n\n",
"}"
] | // Sets the request and the response for the controller | [
"Sets",
"the",
"request",
"and",
"the",
"response",
"for",
"the",
"controller"
] | a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e | https://github.com/revel/revel/blob/a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e/controller.go#L65-L77 | train |
revel/revel | controller.go | FlashParams | func (c *Controller) FlashParams() {
for key, vals := range c.Params.Values {
c.Flash.Out[key] = strings.Join(vals, ",")
}
} | go | func (c *Controller) FlashParams() {
for key, vals := range c.Params.Values {
c.Flash.Out[key] = strings.Join(vals, ",")
}
} | [
"func",
"(",
"c",
"*",
"Controller",
")",
"FlashParams",
"(",
")",
"{",
"for",
"key",
",",
"vals",
":=",
"range",
"c",
".",
"Params",
".",
"Values",
"{",
"c",
".",
"Flash",
".",
"Out",
"[",
"key",
"]",
"=",
"strings",
".",
"Join",
"(",
"vals",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}"
] | // FlashParams serializes the contents of Controller.Params to the Flash
// cookie. | [
"FlashParams",
"serializes",
"the",
"contents",
"of",
"Controller",
".",
"Params",
"to",
"the",
"Flash",
"cookie",
"."
] | a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e | https://github.com/revel/revel/blob/a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e/controller.go#L118-L122 | train |
revel/revel | controller.go | RenderTemplate | func (c *Controller) RenderTemplate(templatePath string) Result {
c.setStatusIfNil(http.StatusOK)
// Get the Template.
lang, _ := c.ViewArgs[CurrentLocaleViewArg].(string)
template, err := MainTemplateLoader.TemplateLang(templatePath, lang)
if err != nil {
return c.RenderError(err)
}
return &RenderTemplateResult{
Template: template,
ViewArgs: c.ViewArgs,
}
} | go | func (c *Controller) RenderTemplate(templatePath string) Result {
c.setStatusIfNil(http.StatusOK)
// Get the Template.
lang, _ := c.ViewArgs[CurrentLocaleViewArg].(string)
template, err := MainTemplateLoader.TemplateLang(templatePath, lang)
if err != nil {
return c.RenderError(err)
}
return &RenderTemplateResult{
Template: template,
ViewArgs: c.ViewArgs,
}
} | [
"func",
"(",
"c",
"*",
"Controller",
")",
"RenderTemplate",
"(",
"templatePath",
"string",
")",
"Result",
"{",
"c",
".",
"setStatusIfNil",
"(",
"http",
".",
"StatusOK",
")",
"\n\n",
"// Get the Template.",
"lang",
",",
"_",
":=",
"c",
".",
"ViewArgs",
"[",
"CurrentLocaleViewArg",
"]",
".",
"(",
"string",
")",
"\n",
"template",
",",
"err",
":=",
"MainTemplateLoader",
".",
"TemplateLang",
"(",
"templatePath",
",",
"lang",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"c",
".",
"RenderError",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"return",
"&",
"RenderTemplateResult",
"{",
"Template",
":",
"template",
",",
"ViewArgs",
":",
"c",
".",
"ViewArgs",
",",
"}",
"\n",
"}"
] | // RenderTemplate method does less magical way to render a template.
// Renders the given template, using the current ViewArgs. | [
"RenderTemplate",
"method",
"does",
"less",
"magical",
"way",
"to",
"render",
"a",
"template",
".",
"Renders",
"the",
"given",
"template",
"using",
"the",
"current",
"ViewArgs",
"."
] | a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e | https://github.com/revel/revel/blob/a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e/controller.go#L199-L213 | train |
revel/revel | controller.go | TemplateOutput | func (c *Controller) TemplateOutput(templatePath string) (data []byte, err error) {
return TemplateOutputArgs(templatePath, c.ViewArgs)
} | go | func (c *Controller) TemplateOutput(templatePath string) (data []byte, err error) {
return TemplateOutputArgs(templatePath, c.ViewArgs)
} | [
"func",
"(",
"c",
"*",
"Controller",
")",
"TemplateOutput",
"(",
"templatePath",
"string",
")",
"(",
"data",
"[",
"]",
"byte",
",",
"err",
"error",
")",
"{",
"return",
"TemplateOutputArgs",
"(",
"templatePath",
",",
"c",
".",
"ViewArgs",
")",
"\n",
"}"
] | // TemplateOutput returns the result of the template rendered using the controllers ViewArgs. | [
"TemplateOutput",
"returns",
"the",
"result",
"of",
"the",
"template",
"rendered",
"using",
"the",
"controllers",
"ViewArgs",
"."
] | a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e | https://github.com/revel/revel/blob/a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e/controller.go#L216-L218 | train |
revel/revel | controller.go | RenderText | func (c *Controller) RenderText(text string, objs ...interface{}) Result {
c.setStatusIfNil(http.StatusOK)
finalText := text
if len(objs) > 0 {
finalText = fmt.Sprintf(text, objs...)
}
return &RenderTextResult{finalText}
} | go | func (c *Controller) RenderText(text string, objs ...interface{}) Result {
c.setStatusIfNil(http.StatusOK)
finalText := text
if len(objs) > 0 {
finalText = fmt.Sprintf(text, objs...)
}
return &RenderTextResult{finalText}
} | [
"func",
"(",
"c",
"*",
"Controller",
")",
"RenderText",
"(",
"text",
"string",
",",
"objs",
"...",
"interface",
"{",
"}",
")",
"Result",
"{",
"c",
".",
"setStatusIfNil",
"(",
"http",
".",
"StatusOK",
")",
"\n\n",
"finalText",
":=",
"text",
"\n",
"if",
"len",
"(",
"objs",
")",
">",
"0",
"{",
"finalText",
"=",
"fmt",
".",
"Sprintf",
"(",
"text",
",",
"objs",
"...",
")",
"\n",
"}",
"\n",
"return",
"&",
"RenderTextResult",
"{",
"finalText",
"}",
"\n",
"}"
] | // RenderText renders plaintext in response, printf style. | [
"RenderText",
"renders",
"plaintext",
"in",
"response",
"printf",
"style",
"."
] | a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e | https://github.com/revel/revel/blob/a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e/controller.go#L242-L250 | train |
revel/revel | controller.go | RenderHTML | func (c *Controller) RenderHTML(html string) Result {
c.setStatusIfNil(http.StatusOK)
return &RenderHTMLResult{html}
} | go | func (c *Controller) RenderHTML(html string) Result {
c.setStatusIfNil(http.StatusOK)
return &RenderHTMLResult{html}
} | [
"func",
"(",
"c",
"*",
"Controller",
")",
"RenderHTML",
"(",
"html",
"string",
")",
"Result",
"{",
"c",
".",
"setStatusIfNil",
"(",
"http",
".",
"StatusOK",
")",
"\n\n",
"return",
"&",
"RenderHTMLResult",
"{",
"html",
"}",
"\n",
"}"
] | // RenderHTML renders html in response | [
"RenderHTML",
"renders",
"html",
"in",
"response"
] | a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e | https://github.com/revel/revel/blob/a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e/controller.go#L253-L257 | train |
revel/revel | controller.go | Todo | func (c *Controller) Todo() Result {
c.Response.Status = http.StatusNotImplemented
controllerLog.Debug("Todo: Not implemented function", "action", c.Action)
return c.RenderError(&Error{
Title: "TODO",
Description: "This action is not implemented",
})
} | go | func (c *Controller) Todo() Result {
c.Response.Status = http.StatusNotImplemented
controllerLog.Debug("Todo: Not implemented function", "action", c.Action)
return c.RenderError(&Error{
Title: "TODO",
Description: "This action is not implemented",
})
} | [
"func",
"(",
"c",
"*",
"Controller",
")",
"Todo",
"(",
")",
"Result",
"{",
"c",
".",
"Response",
".",
"Status",
"=",
"http",
".",
"StatusNotImplemented",
"\n",
"controllerLog",
".",
"Debug",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"c",
".",
"Action",
")",
"\n",
"return",
"c",
".",
"RenderError",
"(",
"&",
"Error",
"{",
"Title",
":",
"\"",
"\"",
",",
"Description",
":",
"\"",
"\"",
",",
"}",
")",
"\n",
"}"
] | // Todo returns an HTTP 501 Not Implemented "todo" indicating that the
// action isn't done yet. | [
"Todo",
"returns",
"an",
"HTTP",
"501",
"Not",
"Implemented",
"todo",
"indicating",
"that",
"the",
"action",
"isn",
"t",
"done",
"yet",
"."
] | a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e | https://github.com/revel/revel/blob/a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e/controller.go#L261-L268 | train |
revel/revel | controller.go | NotFound | func (c *Controller) NotFound(msg string, objs ...interface{}) Result {
finalText := msg
if len(objs) > 0 {
finalText = fmt.Sprintf(msg, objs...)
}
c.Response.Status = http.StatusNotFound
return c.RenderError(&Error{
Title: "Not Found",
Description: finalText,
})
} | go | func (c *Controller) NotFound(msg string, objs ...interface{}) Result {
finalText := msg
if len(objs) > 0 {
finalText = fmt.Sprintf(msg, objs...)
}
c.Response.Status = http.StatusNotFound
return c.RenderError(&Error{
Title: "Not Found",
Description: finalText,
})
} | [
"func",
"(",
"c",
"*",
"Controller",
")",
"NotFound",
"(",
"msg",
"string",
",",
"objs",
"...",
"interface",
"{",
"}",
")",
"Result",
"{",
"finalText",
":=",
"msg",
"\n",
"if",
"len",
"(",
"objs",
")",
">",
"0",
"{",
"finalText",
"=",
"fmt",
".",
"Sprintf",
"(",
"msg",
",",
"objs",
"...",
")",
"\n",
"}",
"\n",
"c",
".",
"Response",
".",
"Status",
"=",
"http",
".",
"StatusNotFound",
"\n",
"return",
"c",
".",
"RenderError",
"(",
"&",
"Error",
"{",
"Title",
":",
"\"",
"\"",
",",
"Description",
":",
"finalText",
",",
"}",
")",
"\n",
"}"
] | // NotFound returns an HTTP 404 Not Found response whose body is the
// formatted string of msg and objs. | [
"NotFound",
"returns",
"an",
"HTTP",
"404",
"Not",
"Found",
"response",
"whose",
"body",
"is",
"the",
"formatted",
"string",
"of",
"msg",
"and",
"objs",
"."
] | a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e | https://github.com/revel/revel/blob/a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e/controller.go#L272-L282 | train |
revel/revel | controller.go | RenderFileName | func (c *Controller) RenderFileName(filename string, delivery ContentDisposition) Result {
f, err := os.Open(filename)
if err != nil {
c.Log.Errorf("Cant open file: %v", err)
return c.RenderError(err)
}
return c.RenderFile(f, delivery)
} | go | func (c *Controller) RenderFileName(filename string, delivery ContentDisposition) Result {
f, err := os.Open(filename)
if err != nil {
c.Log.Errorf("Cant open file: %v", err)
return c.RenderError(err)
}
return c.RenderFile(f, delivery)
} | [
"func",
"(",
"c",
"*",
"Controller",
")",
"RenderFileName",
"(",
"filename",
"string",
",",
"delivery",
"ContentDisposition",
")",
"Result",
"{",
"f",
",",
"err",
":=",
"os",
".",
"Open",
"(",
"filename",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"c",
".",
"Log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"c",
".",
"RenderError",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"c",
".",
"RenderFile",
"(",
"f",
",",
"delivery",
")",
"\n",
"}"
] | // RenderFileName returns a file indicated by the path as provided via the filename.
// It can be either displayed inline or downloaded as an attachment.
// The name and size are taken from the file info. | [
"RenderFileName",
"returns",
"a",
"file",
"indicated",
"by",
"the",
"path",
"as",
"provided",
"via",
"the",
"filename",
".",
"It",
"can",
"be",
"either",
"displayed",
"inline",
"or",
"downloaded",
"as",
"an",
"attachment",
".",
"The",
"name",
"and",
"size",
"are",
"taken",
"from",
"the",
"file",
"info",
"."
] | a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e | https://github.com/revel/revel/blob/a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e/controller.go#L301-L308 | train |
revel/revel | controller.go | RenderFile | func (c *Controller) RenderFile(file *os.File, delivery ContentDisposition) Result {
c.setStatusIfNil(http.StatusOK)
var (
modtime = time.Now()
fileInfo, err = file.Stat()
)
if err != nil {
controllerLog.Error("RenderFile: error", "error", err)
}
if fileInfo != nil {
modtime = fileInfo.ModTime()
}
return c.RenderBinary(file, filepath.Base(file.Name()), delivery, modtime)
} | go | func (c *Controller) RenderFile(file *os.File, delivery ContentDisposition) Result {
c.setStatusIfNil(http.StatusOK)
var (
modtime = time.Now()
fileInfo, err = file.Stat()
)
if err != nil {
controllerLog.Error("RenderFile: error", "error", err)
}
if fileInfo != nil {
modtime = fileInfo.ModTime()
}
return c.RenderBinary(file, filepath.Base(file.Name()), delivery, modtime)
} | [
"func",
"(",
"c",
"*",
"Controller",
")",
"RenderFile",
"(",
"file",
"*",
"os",
".",
"File",
",",
"delivery",
"ContentDisposition",
")",
"Result",
"{",
"c",
".",
"setStatusIfNil",
"(",
"http",
".",
"StatusOK",
")",
"\n\n",
"var",
"(",
"modtime",
"=",
"time",
".",
"Now",
"(",
")",
"\n",
"fileInfo",
",",
"err",
"=",
"file",
".",
"Stat",
"(",
")",
"\n",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"controllerLog",
".",
"Error",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"if",
"fileInfo",
"!=",
"nil",
"{",
"modtime",
"=",
"fileInfo",
".",
"ModTime",
"(",
")",
"\n",
"}",
"\n",
"return",
"c",
".",
"RenderBinary",
"(",
"file",
",",
"filepath",
".",
"Base",
"(",
"file",
".",
"Name",
"(",
")",
")",
",",
"delivery",
",",
"modtime",
")",
"\n",
"}"
] | // RenderFile returns a file, either displayed inline or downloaded
// as an attachment. The name and size are taken from the file info. | [
"RenderFile",
"returns",
"a",
"file",
"either",
"displayed",
"inline",
"or",
"downloaded",
"as",
"an",
"attachment",
".",
"The",
"name",
"and",
"size",
"are",
"taken",
"from",
"the",
"file",
"info",
"."
] | a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e | https://github.com/revel/revel/blob/a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e/controller.go#L312-L326 | train |
revel/revel | controller.go | Stats | func (c *Controller) Stats() map[string]interface{} {
result := CurrentEngine.Stats()
if RevelConfig.Controller.Reuse {
result["revel-controllers"] = RevelConfig.Controller.Stack.String()
for key, appStack := range RevelConfig.Controller.CachedMap {
result["app-" + key] = appStack.String()
}
}
return result
} | go | func (c *Controller) Stats() map[string]interface{} {
result := CurrentEngine.Stats()
if RevelConfig.Controller.Reuse {
result["revel-controllers"] = RevelConfig.Controller.Stack.String()
for key, appStack := range RevelConfig.Controller.CachedMap {
result["app-" + key] = appStack.String()
}
}
return result
} | [
"func",
"(",
"c",
"*",
"Controller",
")",
"Stats",
"(",
")",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"result",
":=",
"CurrentEngine",
".",
"Stats",
"(",
")",
"\n",
"if",
"RevelConfig",
".",
"Controller",
".",
"Reuse",
"{",
"result",
"[",
"\"",
"\"",
"]",
"=",
"RevelConfig",
".",
"Controller",
".",
"Stack",
".",
"String",
"(",
")",
"\n",
"for",
"key",
",",
"appStack",
":=",
"range",
"RevelConfig",
".",
"Controller",
".",
"CachedMap",
"{",
"result",
"[",
"\"",
"\"",
"+",
"key",
"]",
"=",
"appStack",
".",
"String",
"(",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"result",
"\n",
"}"
] | // This stats returns some interesting stats based on what is cached in memory
// and what is available directly | [
"This",
"stats",
"returns",
"some",
"interesting",
"stats",
"based",
"on",
"what",
"is",
"cached",
"in",
"memory",
"and",
"what",
"is",
"available",
"directly"
] | a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e | https://github.com/revel/revel/blob/a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e/controller.go#L363-L372 | train |
revel/revel | controller.go | Message | func (c *Controller) Message(message string, args ...interface{}) string {
return MessageFunc(c.Request.Locale, message, args...)
} | go | func (c *Controller) Message(message string, args ...interface{}) string {
return MessageFunc(c.Request.Locale, message, args...)
} | [
"func",
"(",
"c",
"*",
"Controller",
")",
"Message",
"(",
"message",
"string",
",",
"args",
"...",
"interface",
"{",
"}",
")",
"string",
"{",
"return",
"MessageFunc",
"(",
"c",
".",
"Request",
".",
"Locale",
",",
"message",
",",
"args",
"...",
")",
"\n",
"}"
] | // Message performs a lookup for the given message name using the given
// arguments using the current language defined for this controller.
//
// The current language is set by the i18n plugin. | [
"Message",
"performs",
"a",
"lookup",
"for",
"the",
"given",
"message",
"name",
"using",
"the",
"given",
"arguments",
"using",
"the",
"current",
"language",
"defined",
"for",
"this",
"controller",
".",
"The",
"current",
"language",
"is",
"set",
"by",
"the",
"i18n",
"plugin",
"."
] | a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e | https://github.com/revel/revel/blob/a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e/controller.go#L378-L380 | train |
revel/revel | controller.go | SetTypeAction | func (c *Controller) SetTypeAction(controllerName, methodName string, typeOfController *ControllerType) error {
// Look up the controller and method types.
if typeOfController == nil {
if c.Type = ControllerTypeByName(controllerName, anyModule); c.Type == nil {
return errors.New("revel/controller: failed to find controller " + controllerName)
}
} else {
c.Type = typeOfController
}
// Note method name is case insensitive search
if c.MethodType = c.Type.Method(methodName); c.MethodType == nil {
return errors.New("revel/controller: failed to find action " + controllerName + "." + methodName)
}
c.Name, c.MethodName = c.Type.Type.Name(), c.MethodType.Name
c.Action = c.Name + "." + c.MethodName
// Update Logger with controller and namespace
if c.Log != nil {
c.Log = c.Log.New("action", c.Action, "namespace", c.Type.Namespace)
}
if RevelConfig.Controller.Reuse {
if _, ok := RevelConfig.Controller.CachedMap[c.Name]; !ok {
// Create a new stack for this controller
localType := c.Type.Type
RevelConfig.Controller.CachedMap[c.Name] = utils.NewStackLock(
RevelConfig.Controller.CachedStackSize,
RevelConfig.Controller.CachedStackMaxSize,
func() interface{} {
return reflect.New(localType).Interface()
})
}
// Instantiate the controller.
c.AppController = RevelConfig.Controller.CachedMap[c.Name].Pop()
} else {
c.AppController = reflect.New(c.Type.Type).Interface()
}
c.setAppControllerFields()
return nil
} | go | func (c *Controller) SetTypeAction(controllerName, methodName string, typeOfController *ControllerType) error {
// Look up the controller and method types.
if typeOfController == nil {
if c.Type = ControllerTypeByName(controllerName, anyModule); c.Type == nil {
return errors.New("revel/controller: failed to find controller " + controllerName)
}
} else {
c.Type = typeOfController
}
// Note method name is case insensitive search
if c.MethodType = c.Type.Method(methodName); c.MethodType == nil {
return errors.New("revel/controller: failed to find action " + controllerName + "." + methodName)
}
c.Name, c.MethodName = c.Type.Type.Name(), c.MethodType.Name
c.Action = c.Name + "." + c.MethodName
// Update Logger with controller and namespace
if c.Log != nil {
c.Log = c.Log.New("action", c.Action, "namespace", c.Type.Namespace)
}
if RevelConfig.Controller.Reuse {
if _, ok := RevelConfig.Controller.CachedMap[c.Name]; !ok {
// Create a new stack for this controller
localType := c.Type.Type
RevelConfig.Controller.CachedMap[c.Name] = utils.NewStackLock(
RevelConfig.Controller.CachedStackSize,
RevelConfig.Controller.CachedStackMaxSize,
func() interface{} {
return reflect.New(localType).Interface()
})
}
// Instantiate the controller.
c.AppController = RevelConfig.Controller.CachedMap[c.Name].Pop()
} else {
c.AppController = reflect.New(c.Type.Type).Interface()
}
c.setAppControllerFields()
return nil
} | [
"func",
"(",
"c",
"*",
"Controller",
")",
"SetTypeAction",
"(",
"controllerName",
",",
"methodName",
"string",
",",
"typeOfController",
"*",
"ControllerType",
")",
"error",
"{",
"// Look up the controller and method types.",
"if",
"typeOfController",
"==",
"nil",
"{",
"if",
"c",
".",
"Type",
"=",
"ControllerTypeByName",
"(",
"controllerName",
",",
"anyModule",
")",
";",
"c",
".",
"Type",
"==",
"nil",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
"+",
"controllerName",
")",
"\n",
"}",
"\n",
"}",
"else",
"{",
"c",
".",
"Type",
"=",
"typeOfController",
"\n",
"}",
"\n\n",
"// Note method name is case insensitive search",
"if",
"c",
".",
"MethodType",
"=",
"c",
".",
"Type",
".",
"Method",
"(",
"methodName",
")",
";",
"c",
".",
"MethodType",
"==",
"nil",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
"+",
"controllerName",
"+",
"\"",
"\"",
"+",
"methodName",
")",
"\n",
"}",
"\n\n",
"c",
".",
"Name",
",",
"c",
".",
"MethodName",
"=",
"c",
".",
"Type",
".",
"Type",
".",
"Name",
"(",
")",
",",
"c",
".",
"MethodType",
".",
"Name",
"\n",
"c",
".",
"Action",
"=",
"c",
".",
"Name",
"+",
"\"",
"\"",
"+",
"c",
".",
"MethodName",
"\n\n",
"// Update Logger with controller and namespace",
"if",
"c",
".",
"Log",
"!=",
"nil",
"{",
"c",
".",
"Log",
"=",
"c",
".",
"Log",
".",
"New",
"(",
"\"",
"\"",
",",
"c",
".",
"Action",
",",
"\"",
"\"",
",",
"c",
".",
"Type",
".",
"Namespace",
")",
"\n",
"}",
"\n\n",
"if",
"RevelConfig",
".",
"Controller",
".",
"Reuse",
"{",
"if",
"_",
",",
"ok",
":=",
"RevelConfig",
".",
"Controller",
".",
"CachedMap",
"[",
"c",
".",
"Name",
"]",
";",
"!",
"ok",
"{",
"// Create a new stack for this controller",
"localType",
":=",
"c",
".",
"Type",
".",
"Type",
"\n",
"RevelConfig",
".",
"Controller",
".",
"CachedMap",
"[",
"c",
".",
"Name",
"]",
"=",
"utils",
".",
"NewStackLock",
"(",
"RevelConfig",
".",
"Controller",
".",
"CachedStackSize",
",",
"RevelConfig",
".",
"Controller",
".",
"CachedStackMaxSize",
",",
"func",
"(",
")",
"interface",
"{",
"}",
"{",
"return",
"reflect",
".",
"New",
"(",
"localType",
")",
".",
"Interface",
"(",
")",
"\n",
"}",
")",
"\n",
"}",
"\n",
"// Instantiate the controller.",
"c",
".",
"AppController",
"=",
"RevelConfig",
".",
"Controller",
".",
"CachedMap",
"[",
"c",
".",
"Name",
"]",
".",
"Pop",
"(",
")",
"\n",
"}",
"else",
"{",
"c",
".",
"AppController",
"=",
"reflect",
".",
"New",
"(",
"c",
".",
"Type",
".",
"Type",
")",
".",
"Interface",
"(",
")",
"\n",
"}",
"\n",
"c",
".",
"setAppControllerFields",
"(",
")",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // SetAction sets the assigns the Controller type, sets the action and initializes the controller | [
"SetAction",
"sets",
"the",
"assigns",
"the",
"Controller",
"type",
"sets",
"the",
"action",
"and",
"initializes",
"the",
"controller"
] | a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e | https://github.com/revel/revel/blob/a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e/controller.go#L390-L433 | train |
revel/revel | controller.go | RegisterController | func RegisterController(c interface{}, methods []*MethodType) {
// De-star the controller type
// (e.g. given TypeOf((*Application)(nil)), want TypeOf(Application))
elem := reflect.TypeOf(c).Elem()
// De-star all of the method arg types too.
for _, m := range methods {
m.lowerName = strings.ToLower(m.Name)
for _, arg := range m.Args {
arg.Type = arg.Type.Elem()
}
}
// Fetch module for controller, if none found controller must be part of the app
controllerModule := ModuleFromPath(elem.PkgPath(), true)
controllerType := AddControllerType(controllerModule, elem, methods)
controllerLog.Debug("RegisterController:Registered controller", "controller", controllerType.Name())
} | go | func RegisterController(c interface{}, methods []*MethodType) {
// De-star the controller type
// (e.g. given TypeOf((*Application)(nil)), want TypeOf(Application))
elem := reflect.TypeOf(c).Elem()
// De-star all of the method arg types too.
for _, m := range methods {
m.lowerName = strings.ToLower(m.Name)
for _, arg := range m.Args {
arg.Type = arg.Type.Elem()
}
}
// Fetch module for controller, if none found controller must be part of the app
controllerModule := ModuleFromPath(elem.PkgPath(), true)
controllerType := AddControllerType(controllerModule, elem, methods)
controllerLog.Debug("RegisterController:Registered controller", "controller", controllerType.Name())
} | [
"func",
"RegisterController",
"(",
"c",
"interface",
"{",
"}",
",",
"methods",
"[",
"]",
"*",
"MethodType",
")",
"{",
"// De-star the controller type",
"// (e.g. given TypeOf((*Application)(nil)), want TypeOf(Application))",
"elem",
":=",
"reflect",
".",
"TypeOf",
"(",
"c",
")",
".",
"Elem",
"(",
")",
"\n\n",
"// De-star all of the method arg types too.",
"for",
"_",
",",
"m",
":=",
"range",
"methods",
"{",
"m",
".",
"lowerName",
"=",
"strings",
".",
"ToLower",
"(",
"m",
".",
"Name",
")",
"\n",
"for",
"_",
",",
"arg",
":=",
"range",
"m",
".",
"Args",
"{",
"arg",
".",
"Type",
"=",
"arg",
".",
"Type",
".",
"Elem",
"(",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"// Fetch module for controller, if none found controller must be part of the app",
"controllerModule",
":=",
"ModuleFromPath",
"(",
"elem",
".",
"PkgPath",
"(",
")",
",",
"true",
")",
"\n\n",
"controllerType",
":=",
"AddControllerType",
"(",
"controllerModule",
",",
"elem",
",",
"methods",
")",
"\n\n",
"controllerLog",
".",
"Debug",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"controllerType",
".",
"Name",
"(",
")",
")",
"\n",
"}"
] | // RegisterController registers a Controller and its Methods with Revel. | [
"RegisterController",
"registers",
"a",
"Controller",
"and",
"its",
"Methods",
"with",
"Revel",
"."
] | a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e | https://github.com/revel/revel/blob/a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e/controller.go#L527-L546 | train |
revel/revel | revel_hooks.go | Run | func (r RevelHooks) Run() {
serverLogger.Infof("There is %d hooks need to run ...", len(r))
sort.Sort(r)
for i, hook := range r {
utilLog.Infof("Run the %d hook ...", i+1)
hook.f()
}
} | go | func (r RevelHooks) Run() {
serverLogger.Infof("There is %d hooks need to run ...", len(r))
sort.Sort(r)
for i, hook := range r {
utilLog.Infof("Run the %d hook ...", i+1)
hook.f()
}
} | [
"func",
"(",
"r",
"RevelHooks",
")",
"Run",
"(",
")",
"{",
"serverLogger",
".",
"Infof",
"(",
"\"",
"\"",
",",
"len",
"(",
"r",
")",
")",
"\n",
"sort",
".",
"Sort",
"(",
"r",
")",
"\n",
"for",
"i",
",",
"hook",
":=",
"range",
"r",
"{",
"utilLog",
".",
"Infof",
"(",
"\"",
"\"",
",",
"i",
"+",
"1",
")",
"\n",
"hook",
".",
"f",
"(",
")",
"\n",
"}",
"\n",
"}"
] | // Called to run the hooks | [
"Called",
"to",
"run",
"the",
"hooks"
] | a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e | https://github.com/revel/revel/blob/a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e/revel_hooks.go#L27-L34 | train |
revel/revel | revel_hooks.go | Add | func (r RevelHooks) Add(fn func(), order ...int) RevelHooks {
o := 1
if len(order) > 0 {
o = order[0]
}
return append(r, RevelHook{order: o, f: fn})
} | go | func (r RevelHooks) Add(fn func(), order ...int) RevelHooks {
o := 1
if len(order) > 0 {
o = order[0]
}
return append(r, RevelHook{order: o, f: fn})
} | [
"func",
"(",
"r",
"RevelHooks",
")",
"Add",
"(",
"fn",
"func",
"(",
")",
",",
"order",
"...",
"int",
")",
"RevelHooks",
"{",
"o",
":=",
"1",
"\n",
"if",
"len",
"(",
"order",
")",
">",
"0",
"{",
"o",
"=",
"order",
"[",
"0",
"]",
"\n",
"}",
"\n",
"return",
"append",
"(",
"r",
",",
"RevelHook",
"{",
"order",
":",
"o",
",",
"f",
":",
"fn",
"}",
")",
"\n",
"}"
] | // Adds a new function hook, using the order | [
"Adds",
"a",
"new",
"function",
"hook",
"using",
"the",
"order"
] | a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e | https://github.com/revel/revel/blob/a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e/revel_hooks.go#L37-L43 | train |
revel/revel | before_after_filter.go | BeforeAfterFilter | func BeforeAfterFilter(c *Controller, fc []Filter) {
defer func() {
if resultValue := beforeAfterFilterInvoke(FINALLY, c); resultValue != nil && !resultValue.IsNil() {
c.Result = resultValue.Interface().(Result)
}
}()
defer func() {
if err := recover(); err != nil {
if resultValue := beforeAfterFilterInvoke(PANIC, c); resultValue != nil && !resultValue.IsNil() {
c.Result = resultValue.Interface().(Result)
}
panic(err)
}
}()
if resultValue := beforeAfterFilterInvoke(BEFORE, c); resultValue != nil && !resultValue.IsNil() {
c.Result = resultValue.Interface().(Result)
}
fc[0](c, fc[1:])
if resultValue := beforeAfterFilterInvoke(AFTER, c); resultValue != nil && !resultValue.IsNil() {
c.Result = resultValue.Interface().(Result)
}
} | go | func BeforeAfterFilter(c *Controller, fc []Filter) {
defer func() {
if resultValue := beforeAfterFilterInvoke(FINALLY, c); resultValue != nil && !resultValue.IsNil() {
c.Result = resultValue.Interface().(Result)
}
}()
defer func() {
if err := recover(); err != nil {
if resultValue := beforeAfterFilterInvoke(PANIC, c); resultValue != nil && !resultValue.IsNil() {
c.Result = resultValue.Interface().(Result)
}
panic(err)
}
}()
if resultValue := beforeAfterFilterInvoke(BEFORE, c); resultValue != nil && !resultValue.IsNil() {
c.Result = resultValue.Interface().(Result)
}
fc[0](c, fc[1:])
if resultValue := beforeAfterFilterInvoke(AFTER, c); resultValue != nil && !resultValue.IsNil() {
c.Result = resultValue.Interface().(Result)
}
} | [
"func",
"BeforeAfterFilter",
"(",
"c",
"*",
"Controller",
",",
"fc",
"[",
"]",
"Filter",
")",
"{",
"defer",
"func",
"(",
")",
"{",
"if",
"resultValue",
":=",
"beforeAfterFilterInvoke",
"(",
"FINALLY",
",",
"c",
")",
";",
"resultValue",
"!=",
"nil",
"&&",
"!",
"resultValue",
".",
"IsNil",
"(",
")",
"{",
"c",
".",
"Result",
"=",
"resultValue",
".",
"Interface",
"(",
")",
".",
"(",
"Result",
")",
"\n",
"}",
"\n",
"}",
"(",
")",
"\n",
"defer",
"func",
"(",
")",
"{",
"if",
"err",
":=",
"recover",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"if",
"resultValue",
":=",
"beforeAfterFilterInvoke",
"(",
"PANIC",
",",
"c",
")",
";",
"resultValue",
"!=",
"nil",
"&&",
"!",
"resultValue",
".",
"IsNil",
"(",
")",
"{",
"c",
".",
"Result",
"=",
"resultValue",
".",
"Interface",
"(",
")",
".",
"(",
"Result",
")",
"\n",
"}",
"\n",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n",
"}",
"(",
")",
"\n",
"if",
"resultValue",
":=",
"beforeAfterFilterInvoke",
"(",
"BEFORE",
",",
"c",
")",
";",
"resultValue",
"!=",
"nil",
"&&",
"!",
"resultValue",
".",
"IsNil",
"(",
")",
"{",
"c",
".",
"Result",
"=",
"resultValue",
".",
"Interface",
"(",
")",
".",
"(",
"Result",
")",
"\n",
"}",
"\n",
"fc",
"[",
"0",
"]",
"(",
"c",
",",
"fc",
"[",
"1",
":",
"]",
")",
"\n",
"if",
"resultValue",
":=",
"beforeAfterFilterInvoke",
"(",
"AFTER",
",",
"c",
")",
";",
"resultValue",
"!=",
"nil",
"&&",
"!",
"resultValue",
".",
"IsNil",
"(",
")",
"{",
"c",
".",
"Result",
"=",
"resultValue",
".",
"Interface",
"(",
")",
".",
"(",
"Result",
")",
"\n",
"}",
"\n",
"}"
] | // Autocalls any defined before and after methods on the target controller
// If either calls returns a value then the result is returned | [
"Autocalls",
"any",
"defined",
"before",
"and",
"after",
"methods",
"on",
"the",
"target",
"controller",
"If",
"either",
"calls",
"returns",
"a",
"value",
"then",
"the",
"result",
"is",
"returned"
] | a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e | https://github.com/revel/revel/blob/a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e/before_after_filter.go#L9-L30 | train |
revel/revel | namespace.go | namespaceReplace | func namespaceReplace(fileBytes []byte, module *Module) []byte {
newBytes, lastIndex := &bytes.Buffer{}, 0
matches := namespaceReplacement.FindAllSubmatchIndex(fileBytes, -1)
for _, match := range matches {
// Write up to first bytes
newBytes.Write(fileBytes[lastIndex:match[0]])
// skip ahead index to match[1]
lastIndex = match[3]
if match[4] > 0 {
// This match includes the module name as imported by the module
// We could transform the module name if it is different..
// For now leave it the same
// so _LOCAL_.static| becomes static|
lastIndex++
} else {
// Inject the module name
newBytes.Write([]byte(module.Name))
}
}
// Write remainder of document
newBytes.Write(fileBytes[lastIndex:])
return newBytes.Bytes()
} | go | func namespaceReplace(fileBytes []byte, module *Module) []byte {
newBytes, lastIndex := &bytes.Buffer{}, 0
matches := namespaceReplacement.FindAllSubmatchIndex(fileBytes, -1)
for _, match := range matches {
// Write up to first bytes
newBytes.Write(fileBytes[lastIndex:match[0]])
// skip ahead index to match[1]
lastIndex = match[3]
if match[4] > 0 {
// This match includes the module name as imported by the module
// We could transform the module name if it is different..
// For now leave it the same
// so _LOCAL_.static| becomes static|
lastIndex++
} else {
// Inject the module name
newBytes.Write([]byte(module.Name))
}
}
// Write remainder of document
newBytes.Write(fileBytes[lastIndex:])
return newBytes.Bytes()
} | [
"func",
"namespaceReplace",
"(",
"fileBytes",
"[",
"]",
"byte",
",",
"module",
"*",
"Module",
")",
"[",
"]",
"byte",
"{",
"newBytes",
",",
"lastIndex",
":=",
"&",
"bytes",
".",
"Buffer",
"{",
"}",
",",
"0",
"\n",
"matches",
":=",
"namespaceReplacement",
".",
"FindAllSubmatchIndex",
"(",
"fileBytes",
",",
"-",
"1",
")",
"\n",
"for",
"_",
",",
"match",
":=",
"range",
"matches",
"{",
"// Write up to first bytes",
"newBytes",
".",
"Write",
"(",
"fileBytes",
"[",
"lastIndex",
":",
"match",
"[",
"0",
"]",
"]",
")",
"\n",
"// skip ahead index to match[1]",
"lastIndex",
"=",
"match",
"[",
"3",
"]",
"\n",
"if",
"match",
"[",
"4",
"]",
">",
"0",
"{",
"// This match includes the module name as imported by the module",
"// We could transform the module name if it is different..",
"// For now leave it the same",
"// so _LOCAL_.static| becomes static|",
"lastIndex",
"++",
"\n",
"}",
"else",
"{",
"// Inject the module name",
"newBytes",
".",
"Write",
"(",
"[",
"]",
"byte",
"(",
"module",
".",
"Name",
")",
")",
"\n",
"}",
"\n",
"}",
"\n",
"// Write remainder of document",
"newBytes",
".",
"Write",
"(",
"fileBytes",
"[",
"lastIndex",
":",
"]",
")",
"\n",
"return",
"newBytes",
".",
"Bytes",
"(",
")",
"\n",
"}"
] | // Function to replace the bytes data that may match the _LOCAL_ namespace specifier,
// the replacement will be the current module.Name | [
"Function",
"to",
"replace",
"the",
"bytes",
"data",
"that",
"may",
"match",
"the",
"_LOCAL_",
"namespace",
"specifier",
"the",
"replacement",
"will",
"be",
"the",
"current",
"module",
".",
"Name"
] | a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e | https://github.com/revel/revel/blob/a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e/namespace.go#L15-L37 | train |
revel/revel | session/session.go | ID | func (s Session) ID() string {
if sessionIDStr, ok := s[SessionIDKey]; ok {
return sessionIDStr.(string)
}
buffer := uuid.NewV4()
s[SessionIDKey] = hex.EncodeToString(buffer.Bytes())
return s[SessionIDKey].(string)
} | go | func (s Session) ID() string {
if sessionIDStr, ok := s[SessionIDKey]; ok {
return sessionIDStr.(string)
}
buffer := uuid.NewV4()
s[SessionIDKey] = hex.EncodeToString(buffer.Bytes())
return s[SessionIDKey].(string)
} | [
"func",
"(",
"s",
"Session",
")",
"ID",
"(",
")",
"string",
"{",
"if",
"sessionIDStr",
",",
"ok",
":=",
"s",
"[",
"SessionIDKey",
"]",
";",
"ok",
"{",
"return",
"sessionIDStr",
".",
"(",
"string",
")",
"\n",
"}",
"\n\n",
"buffer",
":=",
"uuid",
".",
"NewV4",
"(",
")",
"\n\n",
"s",
"[",
"SessionIDKey",
"]",
"=",
"hex",
".",
"EncodeToString",
"(",
"buffer",
".",
"Bytes",
"(",
")",
")",
"\n",
"return",
"s",
"[",
"SessionIDKey",
"]",
".",
"(",
"string",
")",
"\n",
"}"
] | // ID retrieves from the cookie or creates a time-based UUID identifying this
// session. | [
"ID",
"retrieves",
"from",
"the",
"cookie",
"or",
"creates",
"a",
"time",
"-",
"based",
"UUID",
"identifying",
"this",
"session",
"."
] | a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e | https://github.com/revel/revel/blob/a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e/session/session.go#L47-L56 | train |
revel/revel | session/session.go | SessionTimeoutExpiredOrMissing | func (s Session) SessionTimeoutExpiredOrMissing() bool {
if exp, present := s[TimestampKey]; !present {
return true
} else if exp == SessionValueName {
return false
} else if expInt, _ := strconv.Atoi(exp.(string)); int64(expInt) < time.Now().Unix() {
return true
}
return false
} | go | func (s Session) SessionTimeoutExpiredOrMissing() bool {
if exp, present := s[TimestampKey]; !present {
return true
} else if exp == SessionValueName {
return false
} else if expInt, _ := strconv.Atoi(exp.(string)); int64(expInt) < time.Now().Unix() {
return true
}
return false
} | [
"func",
"(",
"s",
"Session",
")",
"SessionTimeoutExpiredOrMissing",
"(",
")",
"bool",
"{",
"if",
"exp",
",",
"present",
":=",
"s",
"[",
"TimestampKey",
"]",
";",
"!",
"present",
"{",
"return",
"true",
"\n",
"}",
"else",
"if",
"exp",
"==",
"SessionValueName",
"{",
"return",
"false",
"\n",
"}",
"else",
"if",
"expInt",
",",
"_",
":=",
"strconv",
".",
"Atoi",
"(",
"exp",
".",
"(",
"string",
")",
")",
";",
"int64",
"(",
"expInt",
")",
"<",
"time",
".",
"Now",
"(",
")",
".",
"Unix",
"(",
")",
"{",
"return",
"true",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
] | // sessionTimeoutExpiredOrMissing returns a boolean of whether the session
// cookie is either not present or present but beyond its time to live; i.e.,
// whether there is not a valid session. | [
"sessionTimeoutExpiredOrMissing",
"returns",
"a",
"boolean",
"of",
"whether",
"the",
"session",
"cookie",
"is",
"either",
"not",
"present",
"or",
"present",
"but",
"beyond",
"its",
"time",
"to",
"live",
";",
"i",
".",
"e",
".",
"whether",
"there",
"is",
"not",
"a",
"valid",
"session",
"."
] | a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e | https://github.com/revel/revel/blob/a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e/session/session.go#L82-L91 | train |
revel/revel | session/session.go | Get | func (s Session) Get(key string) (newValue interface{}, err error) {
// First check to see if it is in the session
if v, found := s[key]; found {
return v, nil
}
return s.GetInto(key, nil, false)
} | go | func (s Session) Get(key string) (newValue interface{}, err error) {
// First check to see if it is in the session
if v, found := s[key]; found {
return v, nil
}
return s.GetInto(key, nil, false)
} | [
"func",
"(",
"s",
"Session",
")",
"Get",
"(",
"key",
"string",
")",
"(",
"newValue",
"interface",
"{",
"}",
",",
"err",
"error",
")",
"{",
"// First check to see if it is in the session",
"if",
"v",
",",
"found",
":=",
"s",
"[",
"key",
"]",
";",
"found",
"{",
"return",
"v",
",",
"nil",
"\n",
"}",
"\n",
"return",
"s",
".",
"GetInto",
"(",
"key",
",",
"nil",
",",
"false",
")",
"\n",
"}"
] | // Get an object or property from the session
// it may be embedded inside the session. | [
"Get",
"an",
"object",
"or",
"property",
"from",
"the",
"session",
"it",
"may",
"be",
"embedded",
"inside",
"the",
"session",
"."
] | a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e | https://github.com/revel/revel/blob/a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e/session/session.go#L98-L104 | train |
revel/revel | session/session.go | GetInto | func (s Session) GetInto(key string, target interface{}, force bool) (result interface{}, err error) {
if v, found := s[key]; found && !force {
return v, nil
}
splitKey := strings.Split(key, ".")
rootKey := splitKey[0]
// Force always recreates the object from the session data map
if force {
if target == nil {
if result, err = s.sessionDataFromMap(key); err != nil {
return
}
} else if result, err = s.sessionDataFromObject(rootKey, target); err != nil {
return
}
return s.getNestedProperty(splitKey, result)
}
// Attempt to find the key in the session, this is the most generalized form
v, found := s[rootKey]
if !found {
if target == nil {
// Try to fetch it from the session
if v, err = s.sessionDataFromMap(rootKey); err != nil {
return
}
} else if v, err = s.sessionDataFromObject(rootKey, target); err != nil {
return
}
}
return s.getNestedProperty(splitKey, v)
} | go | func (s Session) GetInto(key string, target interface{}, force bool) (result interface{}, err error) {
if v, found := s[key]; found && !force {
return v, nil
}
splitKey := strings.Split(key, ".")
rootKey := splitKey[0]
// Force always recreates the object from the session data map
if force {
if target == nil {
if result, err = s.sessionDataFromMap(key); err != nil {
return
}
} else if result, err = s.sessionDataFromObject(rootKey, target); err != nil {
return
}
return s.getNestedProperty(splitKey, result)
}
// Attempt to find the key in the session, this is the most generalized form
v, found := s[rootKey]
if !found {
if target == nil {
// Try to fetch it from the session
if v, err = s.sessionDataFromMap(rootKey); err != nil {
return
}
} else if v, err = s.sessionDataFromObject(rootKey, target); err != nil {
return
}
}
return s.getNestedProperty(splitKey, v)
} | [
"func",
"(",
"s",
"Session",
")",
"GetInto",
"(",
"key",
"string",
",",
"target",
"interface",
"{",
"}",
",",
"force",
"bool",
")",
"(",
"result",
"interface",
"{",
"}",
",",
"err",
"error",
")",
"{",
"if",
"v",
",",
"found",
":=",
"s",
"[",
"key",
"]",
";",
"found",
"&&",
"!",
"force",
"{",
"return",
"v",
",",
"nil",
"\n",
"}",
"\n",
"splitKey",
":=",
"strings",
".",
"Split",
"(",
"key",
",",
"\"",
"\"",
")",
"\n",
"rootKey",
":=",
"splitKey",
"[",
"0",
"]",
"\n\n",
"// Force always recreates the object from the session data map",
"if",
"force",
"{",
"if",
"target",
"==",
"nil",
"{",
"if",
"result",
",",
"err",
"=",
"s",
".",
"sessionDataFromMap",
"(",
"key",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"}",
"else",
"if",
"result",
",",
"err",
"=",
"s",
".",
"sessionDataFromObject",
"(",
"rootKey",
",",
"target",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"return",
"s",
".",
"getNestedProperty",
"(",
"splitKey",
",",
"result",
")",
"\n",
"}",
"\n\n",
"// Attempt to find the key in the session, this is the most generalized form",
"v",
",",
"found",
":=",
"s",
"[",
"rootKey",
"]",
"\n",
"if",
"!",
"found",
"{",
"if",
"target",
"==",
"nil",
"{",
"// Try to fetch it from the session",
"if",
"v",
",",
"err",
"=",
"s",
".",
"sessionDataFromMap",
"(",
"rootKey",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"}",
"else",
"if",
"v",
",",
"err",
"=",
"s",
".",
"sessionDataFromObject",
"(",
"rootKey",
",",
"target",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"s",
".",
"getNestedProperty",
"(",
"splitKey",
",",
"v",
")",
"\n",
"}"
] | // Get into the specified value.
// If value exists in the session it will just return the value | [
"Get",
"into",
"the",
"specified",
"value",
".",
"If",
"value",
"exists",
"in",
"the",
"session",
"it",
"will",
"just",
"return",
"the",
"value"
] | a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e | https://github.com/revel/revel/blob/a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e/session/session.go#L108-L143 | train |
revel/revel | session/session.go | GetDefault | func (s Session) GetDefault(key string, value interface{}, defaultValue interface{}) interface{} {
v, e := s.GetInto(key, value, false)
if e != nil {
v = defaultValue
}
return v
} | go | func (s Session) GetDefault(key string, value interface{}, defaultValue interface{}) interface{} {
v, e := s.GetInto(key, value, false)
if e != nil {
v = defaultValue
}
return v
} | [
"func",
"(",
"s",
"Session",
")",
"GetDefault",
"(",
"key",
"string",
",",
"value",
"interface",
"{",
"}",
",",
"defaultValue",
"interface",
"{",
"}",
")",
"interface",
"{",
"}",
"{",
"v",
",",
"e",
":=",
"s",
".",
"GetInto",
"(",
"key",
",",
"value",
",",
"false",
")",
"\n",
"if",
"e",
"!=",
"nil",
"{",
"v",
"=",
"defaultValue",
"\n",
"}",
"\n",
"return",
"v",
"\n",
"}"
] | // Returns the default value if the key is not found | [
"Returns",
"the",
"default",
"value",
"if",
"the",
"key",
"is",
"not",
"found"
] | a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e | https://github.com/revel/revel/blob/a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e/session/session.go#L146-L152 | train |
revel/revel | session/session.go | GetProperty | func (s Session) GetProperty(key string, value interface{}) (interface{}, error) {
// Capitalize the first letter
key = strings.Title(key)
sessionLog.Info("getProperty", "key", key, "value", value)
// For a map it is easy
if reflect.TypeOf(value).Kind() == reflect.Map {
val := reflect.ValueOf(value)
valueOf := val.MapIndex(reflect.ValueOf(key))
if valueOf == reflect.Zero(reflect.ValueOf(value).Type()) {
return nil, nil
}
//idx := val.MapIndex(reflect.ValueOf(key))
if !valueOf.IsValid() {
return nil, nil
}
return valueOf.Interface(), nil
}
objValue := s.reflectValue(value)
field := objValue.FieldByName(key)
if !field.IsValid() {
return nil, SESSION_VALUE_NOT_FOUND
}
return field.Interface(), nil
} | go | func (s Session) GetProperty(key string, value interface{}) (interface{}, error) {
// Capitalize the first letter
key = strings.Title(key)
sessionLog.Info("getProperty", "key", key, "value", value)
// For a map it is easy
if reflect.TypeOf(value).Kind() == reflect.Map {
val := reflect.ValueOf(value)
valueOf := val.MapIndex(reflect.ValueOf(key))
if valueOf == reflect.Zero(reflect.ValueOf(value).Type()) {
return nil, nil
}
//idx := val.MapIndex(reflect.ValueOf(key))
if !valueOf.IsValid() {
return nil, nil
}
return valueOf.Interface(), nil
}
objValue := s.reflectValue(value)
field := objValue.FieldByName(key)
if !field.IsValid() {
return nil, SESSION_VALUE_NOT_FOUND
}
return field.Interface(), nil
} | [
"func",
"(",
"s",
"Session",
")",
"GetProperty",
"(",
"key",
"string",
",",
"value",
"interface",
"{",
"}",
")",
"(",
"interface",
"{",
"}",
",",
"error",
")",
"{",
"// Capitalize the first letter",
"key",
"=",
"strings",
".",
"Title",
"(",
"key",
")",
"\n\n",
"sessionLog",
".",
"Info",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"key",
",",
"\"",
"\"",
",",
"value",
")",
"\n\n",
"// For a map it is easy",
"if",
"reflect",
".",
"TypeOf",
"(",
"value",
")",
".",
"Kind",
"(",
")",
"==",
"reflect",
".",
"Map",
"{",
"val",
":=",
"reflect",
".",
"ValueOf",
"(",
"value",
")",
"\n",
"valueOf",
":=",
"val",
".",
"MapIndex",
"(",
"reflect",
".",
"ValueOf",
"(",
"key",
")",
")",
"\n",
"if",
"valueOf",
"==",
"reflect",
".",
"Zero",
"(",
"reflect",
".",
"ValueOf",
"(",
"value",
")",
".",
"Type",
"(",
")",
")",
"{",
"return",
"nil",
",",
"nil",
"\n",
"}",
"\n",
"//idx := val.MapIndex(reflect.ValueOf(key))",
"if",
"!",
"valueOf",
".",
"IsValid",
"(",
")",
"{",
"return",
"nil",
",",
"nil",
"\n",
"}",
"\n\n",
"return",
"valueOf",
".",
"Interface",
"(",
")",
",",
"nil",
"\n",
"}",
"\n\n",
"objValue",
":=",
"s",
".",
"reflectValue",
"(",
"value",
")",
"\n",
"field",
":=",
"objValue",
".",
"FieldByName",
"(",
"key",
")",
"\n",
"if",
"!",
"field",
".",
"IsValid",
"(",
")",
"{",
"return",
"nil",
",",
"SESSION_VALUE_NOT_FOUND",
"\n",
"}",
"\n\n",
"return",
"field",
".",
"Interface",
"(",
")",
",",
"nil",
"\n",
"}"
] | // Extract the values from the session | [
"Extract",
"the",
"values",
"from",
"the",
"session"
] | a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e | https://github.com/revel/revel/blob/a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e/session/session.go#L155-L183 | train |
revel/revel | session/session.go | Del | func (s Session) Del(key string) {
sessionJsonMap := s.getSessionJsonMap()
delete(sessionJsonMap, key)
delete(s, key)
} | go | func (s Session) Del(key string) {
sessionJsonMap := s.getSessionJsonMap()
delete(sessionJsonMap, key)
delete(s, key)
} | [
"func",
"(",
"s",
"Session",
")",
"Del",
"(",
"key",
"string",
")",
"{",
"sessionJsonMap",
":=",
"s",
".",
"getSessionJsonMap",
"(",
")",
"\n",
"delete",
"(",
"sessionJsonMap",
",",
"key",
")",
"\n",
"delete",
"(",
"s",
",",
"key",
")",
"\n",
"}"
] | // Delete the key from the sessionObjects and Session | [
"Delete",
"the",
"key",
"from",
"the",
"sessionObjects",
"and",
"Session"
] | a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e | https://github.com/revel/revel/blob/a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e/session/session.go#L198-L202 | train |
revel/revel | session/session.go | Load | func (s Session) Load(data map[string]string) {
for key, value := range data {
if key == SessionObjectKeyName {
target := map[string]string{}
if err := json.Unmarshal([]byte(value), &target); err != nil {
sessionLog.Error("Unable to unmarshal session ", "key", SessionObjectKeyName, "error", err)
} else {
s[key] = target
}
} else {
s[key] = value
}
}
} | go | func (s Session) Load(data map[string]string) {
for key, value := range data {
if key == SessionObjectKeyName {
target := map[string]string{}
if err := json.Unmarshal([]byte(value), &target); err != nil {
sessionLog.Error("Unable to unmarshal session ", "key", SessionObjectKeyName, "error", err)
} else {
s[key] = target
}
} else {
s[key] = value
}
}
} | [
"func",
"(",
"s",
"Session",
")",
"Load",
"(",
"data",
"map",
"[",
"string",
"]",
"string",
")",
"{",
"for",
"key",
",",
"value",
":=",
"range",
"data",
"{",
"if",
"key",
"==",
"SessionObjectKeyName",
"{",
"target",
":=",
"map",
"[",
"string",
"]",
"string",
"{",
"}",
"\n",
"if",
"err",
":=",
"json",
".",
"Unmarshal",
"(",
"[",
"]",
"byte",
"(",
"value",
")",
",",
"&",
"target",
")",
";",
"err",
"!=",
"nil",
"{",
"sessionLog",
".",
"Error",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"SessionObjectKeyName",
",",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"else",
"{",
"s",
"[",
"key",
"]",
"=",
"target",
"\n",
"}",
"\n",
"}",
"else",
"{",
"s",
"[",
"key",
"]",
"=",
"value",
"\n",
"}",
"\n\n",
"}",
"\n",
"}"
] | // Set the session object from the loaded data | [
"Set",
"the",
"session",
"object",
"from",
"the",
"loaded",
"data"
] | a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e | https://github.com/revel/revel/blob/a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e/session/session.go#L258-L272 | train |
revel/revel | session/session.go | Empty | func (s Session) Empty() bool {
i := 0
for k := range s {
i++
if k == SessionObjectKeyName || k == SessionMapKeyName {
continue
}
}
return i == 0
} | go | func (s Session) Empty() bool {
i := 0
for k := range s {
i++
if k == SessionObjectKeyName || k == SessionMapKeyName {
continue
}
}
return i == 0
} | [
"func",
"(",
"s",
"Session",
")",
"Empty",
"(",
")",
"bool",
"{",
"i",
":=",
"0",
"\n",
"for",
"k",
":=",
"range",
"s",
"{",
"i",
"++",
"\n",
"if",
"k",
"==",
"SessionObjectKeyName",
"||",
"k",
"==",
"SessionMapKeyName",
"{",
"continue",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"i",
"==",
"0",
"\n",
"}"
] | // Checks to see if the session is empty | [
"Checks",
"to",
"see",
"if",
"the",
"session",
"is",
"empty"
] | a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e | https://github.com/revel/revel/blob/a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e/session/session.go#L275-L284 | train |
revel/revel | session/session.go | getNestedProperty | func (s Session) getNestedProperty(keys []string, newValue interface{}) (result interface{}, err error) {
for x := 1; x < len(keys); x++ {
newValue, err = s.GetProperty(keys[x], newValue)
if err != nil || newValue == nil {
return newValue, err
}
}
return newValue, nil
} | go | func (s Session) getNestedProperty(keys []string, newValue interface{}) (result interface{}, err error) {
for x := 1; x < len(keys); x++ {
newValue, err = s.GetProperty(keys[x], newValue)
if err != nil || newValue == nil {
return newValue, err
}
}
return newValue, nil
} | [
"func",
"(",
"s",
"Session",
")",
"getNestedProperty",
"(",
"keys",
"[",
"]",
"string",
",",
"newValue",
"interface",
"{",
"}",
")",
"(",
"result",
"interface",
"{",
"}",
",",
"err",
"error",
")",
"{",
"for",
"x",
":=",
"1",
";",
"x",
"<",
"len",
"(",
"keys",
")",
";",
"x",
"++",
"{",
"newValue",
",",
"err",
"=",
"s",
".",
"GetProperty",
"(",
"keys",
"[",
"x",
"]",
",",
"newValue",
")",
"\n",
"if",
"err",
"!=",
"nil",
"||",
"newValue",
"==",
"nil",
"{",
"return",
"newValue",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"newValue",
",",
"nil",
"\n",
"}"
] | // Starting at position 1 drill into the object | [
"Starting",
"at",
"position",
"1",
"drill",
"into",
"the",
"object"
] | a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e | https://github.com/revel/revel/blob/a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e/session/session.go#L299-L307 | train |
revel/revel | session/session.go | sessionDataFromMap | func (s Session) sessionDataFromMap(key string) (result interface{}, err error) {
var mapValue map[string]interface{}
uncastMapValue, found := s[SessionMapKeyName]
if !found {
mapValue = map[string]interface{}{}
s[SessionMapKeyName] = mapValue
} else if mapValue, found = uncastMapValue.(map[string]interface{}); !found {
// Unusual means that the value in the session was not expected
sessionLog.Errorf("Unusual means that the value in the session was not expected", "session", uncastMapValue)
mapValue = map[string]interface{}{}
s[SessionMapKeyName] = mapValue
}
// Try to extract the key from the map
result, found = mapValue[key]
if !found {
result, err = s.convertSessionData(key, nil)
if err == nil {
mapValue[key] = result
}
}
return
} | go | func (s Session) sessionDataFromMap(key string) (result interface{}, err error) {
var mapValue map[string]interface{}
uncastMapValue, found := s[SessionMapKeyName]
if !found {
mapValue = map[string]interface{}{}
s[SessionMapKeyName] = mapValue
} else if mapValue, found = uncastMapValue.(map[string]interface{}); !found {
// Unusual means that the value in the session was not expected
sessionLog.Errorf("Unusual means that the value in the session was not expected", "session", uncastMapValue)
mapValue = map[string]interface{}{}
s[SessionMapKeyName] = mapValue
}
// Try to extract the key from the map
result, found = mapValue[key]
if !found {
result, err = s.convertSessionData(key, nil)
if err == nil {
mapValue[key] = result
}
}
return
} | [
"func",
"(",
"s",
"Session",
")",
"sessionDataFromMap",
"(",
"key",
"string",
")",
"(",
"result",
"interface",
"{",
"}",
",",
"err",
"error",
")",
"{",
"var",
"mapValue",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"\n",
"uncastMapValue",
",",
"found",
":=",
"s",
"[",
"SessionMapKeyName",
"]",
"\n",
"if",
"!",
"found",
"{",
"mapValue",
"=",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"}",
"\n",
"s",
"[",
"SessionMapKeyName",
"]",
"=",
"mapValue",
"\n",
"}",
"else",
"if",
"mapValue",
",",
"found",
"=",
"uncastMapValue",
".",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
";",
"!",
"found",
"{",
"// Unusual means that the value in the session was not expected",
"sessionLog",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"uncastMapValue",
")",
"\n",
"mapValue",
"=",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"}",
"\n",
"s",
"[",
"SessionMapKeyName",
"]",
"=",
"mapValue",
"\n",
"}",
"\n\n",
"// Try to extract the key from the map",
"result",
",",
"found",
"=",
"mapValue",
"[",
"key",
"]",
"\n",
"if",
"!",
"found",
"{",
"result",
",",
"err",
"=",
"s",
".",
"convertSessionData",
"(",
"key",
",",
"nil",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"mapValue",
"[",
"key",
"]",
"=",
"result",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] | // Always converts the data from the session mapped objects into the target,
// it will store the results under the session key name SessionMapKeyName | [
"Always",
"converts",
"the",
"data",
"from",
"the",
"session",
"mapped",
"objects",
"into",
"the",
"target",
"it",
"will",
"store",
"the",
"results",
"under",
"the",
"session",
"key",
"name",
"SessionMapKeyName"
] | a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e | https://github.com/revel/revel/blob/a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e/session/session.go#L311-L333 | train |
revel/revel | session/session.go | sessionDataFromObject | func (s Session) sessionDataFromObject(key string, newValue interface{}) (result interface{}, err error) {
result, err = s.convertSessionData(key, newValue)
if err != nil {
return
}
s[key] = result
return
} | go | func (s Session) sessionDataFromObject(key string, newValue interface{}) (result interface{}, err error) {
result, err = s.convertSessionData(key, newValue)
if err != nil {
return
}
s[key] = result
return
} | [
"func",
"(",
"s",
"Session",
")",
"sessionDataFromObject",
"(",
"key",
"string",
",",
"newValue",
"interface",
"{",
"}",
")",
"(",
"result",
"interface",
"{",
"}",
",",
"err",
"error",
")",
"{",
"result",
",",
"err",
"=",
"s",
".",
"convertSessionData",
"(",
"key",
",",
"newValue",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"s",
"[",
"key",
"]",
"=",
"result",
"\n",
"return",
"\n",
"}"
] | // Unpack the object from the session map and store it in the session when done, if no error occurs | [
"Unpack",
"the",
"object",
"from",
"the",
"session",
"map",
"and",
"store",
"it",
"in",
"the",
"session",
"when",
"done",
"if",
"no",
"error",
"occurs"
] | a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e | https://github.com/revel/revel/blob/a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e/session/session.go#L336-L343 | train |
revel/revel | session/session.go | convertSessionData | func (s Session) convertSessionData(key string, target interface{}) (result interface{}, err error) {
sessionJsonMap := s.getSessionJsonMap()
v, found := sessionJsonMap[key]
if !found {
return target, SESSION_VALUE_NOT_FOUND
}
// Create a target if needed
if target == nil {
target = map[string]interface{}{}
if err := json.Unmarshal([]byte(v), &target); err != nil {
return target, err
}
} else if err := json.Unmarshal([]byte(v), target); err != nil {
return target, err
}
result = target
return
} | go | func (s Session) convertSessionData(key string, target interface{}) (result interface{}, err error) {
sessionJsonMap := s.getSessionJsonMap()
v, found := sessionJsonMap[key]
if !found {
return target, SESSION_VALUE_NOT_FOUND
}
// Create a target if needed
if target == nil {
target = map[string]interface{}{}
if err := json.Unmarshal([]byte(v), &target); err != nil {
return target, err
}
} else if err := json.Unmarshal([]byte(v), target); err != nil {
return target, err
}
result = target
return
} | [
"func",
"(",
"s",
"Session",
")",
"convertSessionData",
"(",
"key",
"string",
",",
"target",
"interface",
"{",
"}",
")",
"(",
"result",
"interface",
"{",
"}",
",",
"err",
"error",
")",
"{",
"sessionJsonMap",
":=",
"s",
".",
"getSessionJsonMap",
"(",
")",
"\n",
"v",
",",
"found",
":=",
"sessionJsonMap",
"[",
"key",
"]",
"\n",
"if",
"!",
"found",
"{",
"return",
"target",
",",
"SESSION_VALUE_NOT_FOUND",
"\n",
"}",
"\n\n",
"// Create a target if needed",
"if",
"target",
"==",
"nil",
"{",
"target",
"=",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"}",
"\n",
"if",
"err",
":=",
"json",
".",
"Unmarshal",
"(",
"[",
"]",
"byte",
"(",
"v",
")",
",",
"&",
"target",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"target",
",",
"err",
"\n",
"}",
"\n",
"}",
"else",
"if",
"err",
":=",
"json",
".",
"Unmarshal",
"(",
"[",
"]",
"byte",
"(",
"v",
")",
",",
"target",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"target",
",",
"err",
"\n",
"}",
"\n",
"result",
"=",
"target",
"\n",
"return",
"\n",
"}"
] | // Converts from the session json map into the target, | [
"Converts",
"from",
"the",
"session",
"json",
"map",
"into",
"the",
"target"
] | a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e | https://github.com/revel/revel/blob/a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e/session/session.go#L346-L364 | train |
revel/revel | http.go | NewResponse | func NewResponse(w ServerResponse) (r *Response) {
r = &Response{Out: OutResponse{Server: w, internalHeader: &RevelHeader{}}}
r.Out.response = r
return r
} | go | func NewResponse(w ServerResponse) (r *Response) {
r = &Response{Out: OutResponse{Server: w, internalHeader: &RevelHeader{}}}
r.Out.response = r
return r
} | [
"func",
"NewResponse",
"(",
"w",
"ServerResponse",
")",
"(",
"r",
"*",
"Response",
")",
"{",
"r",
"=",
"&",
"Response",
"{",
"Out",
":",
"OutResponse",
"{",
"Server",
":",
"w",
",",
"internalHeader",
":",
"&",
"RevelHeader",
"{",
"}",
"}",
"}",
"\n",
"r",
".",
"Out",
".",
"response",
"=",
"r",
"\n",
"return",
"r",
"\n",
"}"
] | // NewResponse wraps ServerResponse inside a Revel's Response and returns it | [
"NewResponse",
"wraps",
"ServerResponse",
"inside",
"a",
"Revel",
"s",
"Response",
"and",
"returns",
"it"
] | a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e | https://github.com/revel/revel/blob/a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e/http.go#L69-L73 | train |
revel/revel | http.go | NewRequest | func NewRequest(r ServerRequest) *Request {
req := &Request{Header: &RevelHeader{}}
if r != nil {
req.SetRequest(r)
}
return req
} | go | func NewRequest(r ServerRequest) *Request {
req := &Request{Header: &RevelHeader{}}
if r != nil {
req.SetRequest(r)
}
return req
} | [
"func",
"NewRequest",
"(",
"r",
"ServerRequest",
")",
"*",
"Request",
"{",
"req",
":=",
"&",
"Request",
"{",
"Header",
":",
"&",
"RevelHeader",
"{",
"}",
"}",
"\n",
"if",
"r",
"!=",
"nil",
"{",
"req",
".",
"SetRequest",
"(",
"r",
")",
"\n",
"}",
"\n",
"return",
"req",
"\n",
"}"
] | // NewRequest returns a Revel's HTTP request instance with given HTTP instance | [
"NewRequest",
"returns",
"a",
"Revel",
"s",
"HTTP",
"request",
"instance",
"with",
"given",
"HTTP",
"instance"
] | a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e | https://github.com/revel/revel/blob/a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e/http.go#L76-L82 | train |
revel/revel | http.go | GetRequestURI | func (req *Request) GetRequestURI() string {
uri, _ := req.GetValue(HTTP_REQUEST_URI).(string)
return uri
} | go | func (req *Request) GetRequestURI() string {
uri, _ := req.GetValue(HTTP_REQUEST_URI).(string)
return uri
} | [
"func",
"(",
"req",
"*",
"Request",
")",
"GetRequestURI",
"(",
")",
"string",
"{",
"uri",
",",
"_",
":=",
"req",
".",
"GetValue",
"(",
"HTTP_REQUEST_URI",
")",
".",
"(",
"string",
")",
"\n",
"return",
"uri",
"\n",
"}"
] | // Fetch the requested URI | [
"Fetch",
"the",
"requested",
"URI"
] | a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e | https://github.com/revel/revel/blob/a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e/http.go#L108-L111 | train |
revel/revel | http.go | GetQuery | func (req *Request) GetQuery() (v url.Values) {
v, _ = req.GetValue(ENGINE_PARAMETERS).(url.Values)
return
} | go | func (req *Request) GetQuery() (v url.Values) {
v, _ = req.GetValue(ENGINE_PARAMETERS).(url.Values)
return
} | [
"func",
"(",
"req",
"*",
"Request",
")",
"GetQuery",
"(",
")",
"(",
"v",
"url",
".",
"Values",
")",
"{",
"v",
",",
"_",
"=",
"req",
".",
"GetValue",
"(",
"ENGINE_PARAMETERS",
")",
".",
"(",
"url",
".",
"Values",
")",
"\n",
"return",
"\n",
"}"
] | // Fetch the query | [
"Fetch",
"the",
"query"
] | a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e | https://github.com/revel/revel/blob/a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e/http.go#L114-L117 | train |
revel/revel | http.go | GetPath | func (req *Request) GetPath() (path string) {
path, _ = req.GetValue(ENGINE_PATH).(string)
return
} | go | func (req *Request) GetPath() (path string) {
path, _ = req.GetValue(ENGINE_PATH).(string)
return
} | [
"func",
"(",
"req",
"*",
"Request",
")",
"GetPath",
"(",
")",
"(",
"path",
"string",
")",
"{",
"path",
",",
"_",
"=",
"req",
".",
"GetValue",
"(",
"ENGINE_PATH",
")",
".",
"(",
"string",
")",
"\n",
"return",
"\n",
"}"
] | // Fetch the path | [
"Fetch",
"the",
"path"
] | a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e | https://github.com/revel/revel/blob/a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e/http.go#L120-L123 | train |
revel/revel | http.go | GetBody | func (req *Request) GetBody() (body io.Reader) {
body, _ = req.GetValue(HTTP_BODY).(io.Reader)
return
} | go | func (req *Request) GetBody() (body io.Reader) {
body, _ = req.GetValue(HTTP_BODY).(io.Reader)
return
} | [
"func",
"(",
"req",
"*",
"Request",
")",
"GetBody",
"(",
")",
"(",
"body",
"io",
".",
"Reader",
")",
"{",
"body",
",",
"_",
"=",
"req",
".",
"GetValue",
"(",
"HTTP_BODY",
")",
".",
"(",
"io",
".",
"Reader",
")",
"\n",
"return",
"\n",
"}"
] | // Fetch the body | [
"Fetch",
"the",
"body"
] | a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e | https://github.com/revel/revel/blob/a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e/http.go#L126-L129 | train |
revel/revel | http.go | Context | func (req *Request) Context() (c context.Context) {
c, _ = req.GetValue(HTTP_REQUEST_CONTEXT).(context.Context)
return
} | go | func (req *Request) Context() (c context.Context) {
c, _ = req.GetValue(HTTP_REQUEST_CONTEXT).(context.Context)
return
} | [
"func",
"(",
"req",
"*",
"Request",
")",
"Context",
"(",
")",
"(",
"c",
"context",
".",
"Context",
")",
"{",
"c",
",",
"_",
"=",
"req",
".",
"GetValue",
"(",
"HTTP_REQUEST_CONTEXT",
")",
".",
"(",
"context",
".",
"Context",
")",
"\n",
"return",
"\n",
"}"
] | // Fetch the context | [
"Fetch",
"the",
"context"
] | a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e | https://github.com/revel/revel/blob/a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e/http.go#L132-L135 | train |
revel/revel | http.go | newMultipareForm | func newMultipareForm(s ServerMultipartForm) (f *MultipartForm) {
return &MultipartForm{File: s.GetFiles(), Value: s.GetValues(), origin: s}
} | go | func newMultipareForm(s ServerMultipartForm) (f *MultipartForm) {
return &MultipartForm{File: s.GetFiles(), Value: s.GetValues(), origin: s}
} | [
"func",
"newMultipareForm",
"(",
"s",
"ServerMultipartForm",
")",
"(",
"f",
"*",
"MultipartForm",
")",
"{",
"return",
"&",
"MultipartForm",
"{",
"File",
":",
"s",
".",
"GetFiles",
"(",
")",
",",
"Value",
":",
"s",
".",
"GetValues",
"(",
")",
",",
"origin",
":",
"s",
"}",
"\n",
"}"
] | // Deprecated for backwards compatibility only | [
"Deprecated",
"for",
"backwards",
"compatibility",
"only"
] | a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e | https://github.com/revel/revel/blob/a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e/http.go#L182-L184 | train |
revel/revel | http.go | GetMultipartForm | func (req *Request) GetMultipartForm() (ServerMultipartForm, error) {
if form, err := req.In.Get(HTTP_MULTIPART_FORM); err != nil {
return nil, err
} else if values, found := form.(ServerMultipartForm); found {
return values, nil
}
return nil, FORM_NOT_FOUND
} | go | func (req *Request) GetMultipartForm() (ServerMultipartForm, error) {
if form, err := req.In.Get(HTTP_MULTIPART_FORM); err != nil {
return nil, err
} else if values, found := form.(ServerMultipartForm); found {
return values, nil
}
return nil, FORM_NOT_FOUND
} | [
"func",
"(",
"req",
"*",
"Request",
")",
"GetMultipartForm",
"(",
")",
"(",
"ServerMultipartForm",
",",
"error",
")",
"{",
"if",
"form",
",",
"err",
":=",
"req",
".",
"In",
".",
"Get",
"(",
"HTTP_MULTIPART_FORM",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"else",
"if",
"values",
",",
"found",
":=",
"form",
".",
"(",
"ServerMultipartForm",
")",
";",
"found",
"{",
"return",
"values",
",",
"nil",
"\n",
"}",
"\n",
"return",
"nil",
",",
"FORM_NOT_FOUND",
"\n",
"}"
] | // Return a multipart form | [
"Return",
"a",
"multipart",
"form"
] | a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e | https://github.com/revel/revel/blob/a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e/http.go#L201-L208 | train |
revel/revel | http.go | SetResponse | func (resp *Response) SetResponse(r ServerResponse) {
resp.Out.Server = r
if h, e := r.Get(HTTP_SERVER_HEADER); e == nil {
resp.Out.internalHeader.Server, _ = h.(ServerHeader)
}
} | go | func (resp *Response) SetResponse(r ServerResponse) {
resp.Out.Server = r
if h, e := r.Get(HTTP_SERVER_HEADER); e == nil {
resp.Out.internalHeader.Server, _ = h.(ServerHeader)
}
} | [
"func",
"(",
"resp",
"*",
"Response",
")",
"SetResponse",
"(",
"r",
"ServerResponse",
")",
"{",
"resp",
".",
"Out",
".",
"Server",
"=",
"r",
"\n",
"if",
"h",
",",
"e",
":=",
"r",
".",
"Get",
"(",
"HTTP_SERVER_HEADER",
")",
";",
"e",
"==",
"nil",
"{",
"resp",
".",
"Out",
".",
"internalHeader",
".",
"Server",
",",
"_",
"=",
"h",
".",
"(",
"ServerHeader",
")",
"\n",
"}",
"\n",
"}"
] | // Set the server response | [
"Set",
"the",
"server",
"response"
] | a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e | https://github.com/revel/revel/blob/a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e/http.go#L226-L231 | train |
revel/revel | http.go | Destroy | func (resp *Response) Destroy() {
resp.Out.Destroy()
resp.Status = 0
resp.ContentType = ""
resp.writer = nil
} | go | func (resp *Response) Destroy() {
resp.Out.Destroy()
resp.Status = 0
resp.ContentType = ""
resp.writer = nil
} | [
"func",
"(",
"resp",
"*",
"Response",
")",
"Destroy",
"(",
")",
"{",
"resp",
".",
"Out",
".",
"Destroy",
"(",
")",
"\n",
"resp",
".",
"Status",
"=",
"0",
"\n",
"resp",
".",
"ContentType",
"=",
"\"",
"\"",
"\n",
"resp",
".",
"writer",
"=",
"nil",
"\n",
"}"
] | // Destroy the Response | [
"Destroy",
"the",
"Response"
] | a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e | https://github.com/revel/revel/blob/a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e/http.go#L245-L250 | train |
revel/revel | http.go | GetHttpHeader | func (req *Request) GetHttpHeader(key string) string {
return req.Header.Get(key)
} | go | func (req *Request) GetHttpHeader(key string) string {
return req.Header.Get(key)
} | [
"func",
"(",
"req",
"*",
"Request",
")",
"GetHttpHeader",
"(",
"key",
"string",
")",
"string",
"{",
"return",
"req",
".",
"Header",
".",
"Get",
"(",
"key",
")",
"\n",
"}"
] | // Return the httpheader for the key | [
"Return",
"the",
"httpheader",
"for",
"the",
"key"
] | a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e | https://github.com/revel/revel/blob/a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e/http.go#L263-L265 | train |
revel/revel | http.go | GetValue | func (r *Request) GetValue(key int) (value interface{}) {
value, _ = r.In.Get(key)
return
} | go | func (r *Request) GetValue(key int) (value interface{}) {
value, _ = r.In.Get(key)
return
} | [
"func",
"(",
"r",
"*",
"Request",
")",
"GetValue",
"(",
"key",
"int",
")",
"(",
"value",
"interface",
"{",
"}",
")",
"{",
"value",
",",
"_",
"=",
"r",
".",
"In",
".",
"Get",
"(",
"key",
")",
"\n",
"return",
"\n",
"}"
] | // Return the value from the server | [
"Return",
"the",
"value",
"from",
"the",
"server"
] | a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e | https://github.com/revel/revel/blob/a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e/http.go#L268-L271 | train |
revel/revel | http.go | GetWriter | func (resp *Response) GetWriter() (writer io.Writer) {
writer = resp.writer
if writer == nil {
if w, e := resp.Out.Server.Get(ENGINE_WRITER); e == nil {
writer, resp.writer = w.(io.Writer), w.(io.Writer)
}
}
return
} | go | func (resp *Response) GetWriter() (writer io.Writer) {
writer = resp.writer
if writer == nil {
if w, e := resp.Out.Server.Get(ENGINE_WRITER); e == nil {
writer, resp.writer = w.(io.Writer), w.(io.Writer)
}
}
return
} | [
"func",
"(",
"resp",
"*",
"Response",
")",
"GetWriter",
"(",
")",
"(",
"writer",
"io",
".",
"Writer",
")",
"{",
"writer",
"=",
"resp",
".",
"writer",
"\n",
"if",
"writer",
"==",
"nil",
"{",
"if",
"w",
",",
"e",
":=",
"resp",
".",
"Out",
".",
"Server",
".",
"Get",
"(",
"ENGINE_WRITER",
")",
";",
"e",
"==",
"nil",
"{",
"writer",
",",
"resp",
".",
"writer",
"=",
"w",
".",
"(",
"io",
".",
"Writer",
")",
",",
"w",
".",
"(",
"io",
".",
"Writer",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"\n",
"}"
] | // Return the writer | [
"Return",
"the",
"writer"
] | a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e | https://github.com/revel/revel/blob/a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e/http.go#L296-L305 | train |
revel/revel | http.go | SetWriter | func (resp *Response) SetWriter(writer io.Writer) bool {
resp.writer = writer
// Leave it up to the engine to flush and close the writer
return resp.Out.Server.Set(ENGINE_WRITER, writer)
} | go | func (resp *Response) SetWriter(writer io.Writer) bool {
resp.writer = writer
// Leave it up to the engine to flush and close the writer
return resp.Out.Server.Set(ENGINE_WRITER, writer)
} | [
"func",
"(",
"resp",
"*",
"Response",
")",
"SetWriter",
"(",
"writer",
"io",
".",
"Writer",
")",
"bool",
"{",
"resp",
".",
"writer",
"=",
"writer",
"\n",
"// Leave it up to the engine to flush and close the writer",
"return",
"resp",
".",
"Out",
".",
"Server",
".",
"Set",
"(",
"ENGINE_WRITER",
",",
"writer",
")",
"\n",
"}"
] | // Replace the writer | [
"Replace",
"the",
"writer"
] | a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e | https://github.com/revel/revel/blob/a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e/http.go#L308-L312 | train |
revel/revel | http.go | GetStreamWriter | func (resp *Response) GetStreamWriter() (writer StreamWriter) {
if w, e := resp.Out.Server.Get(HTTP_STREAM_WRITER); e == nil {
writer = w.(StreamWriter)
}
return
} | go | func (resp *Response) GetStreamWriter() (writer StreamWriter) {
if w, e := resp.Out.Server.Get(HTTP_STREAM_WRITER); e == nil {
writer = w.(StreamWriter)
}
return
} | [
"func",
"(",
"resp",
"*",
"Response",
")",
"GetStreamWriter",
"(",
")",
"(",
"writer",
"StreamWriter",
")",
"{",
"if",
"w",
",",
"e",
":=",
"resp",
".",
"Out",
".",
"Server",
".",
"Get",
"(",
"HTTP_STREAM_WRITER",
")",
";",
"e",
"==",
"nil",
"{",
"writer",
"=",
"w",
".",
"(",
"StreamWriter",
")",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] | // Passes full control to the response to the caller - terminates any initial writes | [
"Passes",
"full",
"control",
"to",
"the",
"response",
"to",
"the",
"caller",
"-",
"terminates",
"any",
"initial",
"writes"
] | a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e | https://github.com/revel/revel/blob/a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e/http.go#L315-L320 | train |
revel/revel | http.go | Write | func (o *OutResponse) Write(data []byte) (int, error) {
return o.response.GetWriter().Write(data)
} | go | func (o *OutResponse) Write(data []byte) (int, error) {
return o.response.GetWriter().Write(data)
} | [
"func",
"(",
"o",
"*",
"OutResponse",
")",
"Write",
"(",
"data",
"[",
"]",
"byte",
")",
"(",
"int",
",",
"error",
")",
"{",
"return",
"o",
".",
"response",
".",
"GetWriter",
"(",
")",
".",
"Write",
"(",
"data",
")",
"\n",
"}"
] | // Write the header out | [
"Write",
"the",
"header",
"out"
] | a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e | https://github.com/revel/revel/blob/a3d7a7c23ca885cc5036d3641ede49ce4a14ee2e/http.go#L328-L330 | train |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.