id
int32 0
167k
| repo
stringlengths 5
54
| path
stringlengths 4
155
| func_name
stringlengths 1
118
| original_string
stringlengths 52
85.5k
| language
stringclasses 1
value | code
stringlengths 52
85.5k
| code_tokens
listlengths 21
1.41k
| docstring
stringlengths 6
2.61k
| docstring_tokens
listlengths 3
215
| sha
stringlengths 40
40
| url
stringlengths 85
252
|
|---|---|---|---|---|---|---|---|---|---|---|---|
19,300
|
mafredri/cdp
|
protocol/target/command.go
|
NewCreateTargetArgs
|
func NewCreateTargetArgs(url string) *CreateTargetArgs {
args := new(CreateTargetArgs)
args.URL = url
return args
}
|
go
|
func NewCreateTargetArgs(url string) *CreateTargetArgs {
args := new(CreateTargetArgs)
args.URL = url
return args
}
|
[
"func",
"NewCreateTargetArgs",
"(",
"url",
"string",
")",
"*",
"CreateTargetArgs",
"{",
"args",
":=",
"new",
"(",
"CreateTargetArgs",
")",
"\n",
"args",
".",
"URL",
"=",
"url",
"\n",
"return",
"args",
"\n",
"}"
] |
// NewCreateTargetArgs initializes CreateTargetArgs with the required arguments.
|
[
"NewCreateTargetArgs",
"initializes",
"CreateTargetArgs",
"with",
"the",
"required",
"arguments",
"."
] |
a3cd6cc58c0b7537b9614e7fa5da84bdd3c18514
|
https://github.com/mafredri/cdp/blob/a3cd6cc58c0b7537b9614e7fa5da84bdd3c18514/protocol/target/command.go#L116-L120
|
19,301
|
mafredri/cdp
|
protocol/target/command.go
|
SetBrowserContextID
|
func (a *CreateTargetArgs) SetBrowserContextID(browserContextID BrowserContextID) *CreateTargetArgs {
a.BrowserContextID = &browserContextID
return a
}
|
go
|
func (a *CreateTargetArgs) SetBrowserContextID(browserContextID BrowserContextID) *CreateTargetArgs {
a.BrowserContextID = &browserContextID
return a
}
|
[
"func",
"(",
"a",
"*",
"CreateTargetArgs",
")",
"SetBrowserContextID",
"(",
"browserContextID",
"BrowserContextID",
")",
"*",
"CreateTargetArgs",
"{",
"a",
".",
"BrowserContextID",
"=",
"&",
"browserContextID",
"\n",
"return",
"a",
"\n",
"}"
] |
// SetBrowserContextID sets the BrowserContextID optional argument.
// The browser context to create the page in.
|
[
"SetBrowserContextID",
"sets",
"the",
"BrowserContextID",
"optional",
"argument",
".",
"The",
"browser",
"context",
"to",
"create",
"the",
"page",
"in",
"."
] |
a3cd6cc58c0b7537b9614e7fa5da84bdd3c18514
|
https://github.com/mafredri/cdp/blob/a3cd6cc58c0b7537b9614e7fa5da84bdd3c18514/protocol/target/command.go#L138-L141
|
19,302
|
mafredri/cdp
|
protocol/target/command.go
|
SetSessionID
|
func (a *DetachFromTargetArgs) SetSessionID(sessionID SessionID) *DetachFromTargetArgs {
a.SessionID = &sessionID
return a
}
|
go
|
func (a *DetachFromTargetArgs) SetSessionID(sessionID SessionID) *DetachFromTargetArgs {
a.SessionID = &sessionID
return a
}
|
[
"func",
"(",
"a",
"*",
"DetachFromTargetArgs",
")",
"SetSessionID",
"(",
"sessionID",
"SessionID",
")",
"*",
"DetachFromTargetArgs",
"{",
"a",
".",
"SessionID",
"=",
"&",
"sessionID",
"\n",
"return",
"a",
"\n",
"}"
] |
// SetSessionID sets the SessionID optional argument. Session to
// detach.
|
[
"SetSessionID",
"sets",
"the",
"SessionID",
"optional",
"argument",
".",
"Session",
"to",
"detach",
"."
] |
a3cd6cc58c0b7537b9614e7fa5da84bdd3c18514
|
https://github.com/mafredri/cdp/blob/a3cd6cc58c0b7537b9614e7fa5da84bdd3c18514/protocol/target/command.go#L177-L180
|
19,303
|
mafredri/cdp
|
protocol/target/command.go
|
NewDisposeBrowserContextArgs
|
func NewDisposeBrowserContextArgs(browserContextID BrowserContextID) *DisposeBrowserContextArgs {
args := new(DisposeBrowserContextArgs)
args.BrowserContextID = browserContextID
return args
}
|
go
|
func NewDisposeBrowserContextArgs(browserContextID BrowserContextID) *DisposeBrowserContextArgs {
args := new(DisposeBrowserContextArgs)
args.BrowserContextID = browserContextID
return args
}
|
[
"func",
"NewDisposeBrowserContextArgs",
"(",
"browserContextID",
"BrowserContextID",
")",
"*",
"DisposeBrowserContextArgs",
"{",
"args",
":=",
"new",
"(",
"DisposeBrowserContextArgs",
")",
"\n",
"args",
".",
"BrowserContextID",
"=",
"browserContextID",
"\n",
"return",
"args",
"\n",
"}"
] |
// NewDisposeBrowserContextArgs initializes DisposeBrowserContextArgs with the required arguments.
|
[
"NewDisposeBrowserContextArgs",
"initializes",
"DisposeBrowserContextArgs",
"with",
"the",
"required",
"arguments",
"."
] |
a3cd6cc58c0b7537b9614e7fa5da84bdd3c18514
|
https://github.com/mafredri/cdp/blob/a3cd6cc58c0b7537b9614e7fa5da84bdd3c18514/protocol/target/command.go#L196-L200
|
19,304
|
mafredri/cdp
|
protocol/target/command.go
|
SetTargetID
|
func (a *GetTargetInfoArgs) SetTargetID(targetID ID) *GetTargetInfoArgs {
a.TargetID = &targetID
return a
}
|
go
|
func (a *GetTargetInfoArgs) SetTargetID(targetID ID) *GetTargetInfoArgs {
a.TargetID = &targetID
return a
}
|
[
"func",
"(",
"a",
"*",
"GetTargetInfoArgs",
")",
"SetTargetID",
"(",
"targetID",
"ID",
")",
"*",
"GetTargetInfoArgs",
"{",
"a",
".",
"TargetID",
"=",
"&",
"targetID",
"\n",
"return",
"a",
"\n",
"}"
] |
// SetTargetID sets the TargetID optional argument.
|
[
"SetTargetID",
"sets",
"the",
"TargetID",
"optional",
"argument",
"."
] |
a3cd6cc58c0b7537b9614e7fa5da84bdd3c18514
|
https://github.com/mafredri/cdp/blob/a3cd6cc58c0b7537b9614e7fa5da84bdd3c18514/protocol/target/command.go#L215-L218
|
19,305
|
mafredri/cdp
|
protocol/target/command.go
|
NewSendMessageToTargetArgs
|
func NewSendMessageToTargetArgs(message string) *SendMessageToTargetArgs {
args := new(SendMessageToTargetArgs)
args.Message = message
return args
}
|
go
|
func NewSendMessageToTargetArgs(message string) *SendMessageToTargetArgs {
args := new(SendMessageToTargetArgs)
args.Message = message
return args
}
|
[
"func",
"NewSendMessageToTargetArgs",
"(",
"message",
"string",
")",
"*",
"SendMessageToTargetArgs",
"{",
"args",
":=",
"new",
"(",
"SendMessageToTargetArgs",
")",
"\n",
"args",
".",
"Message",
"=",
"message",
"\n",
"return",
"args",
"\n",
"}"
] |
// NewSendMessageToTargetArgs initializes SendMessageToTargetArgs with the required arguments.
|
[
"NewSendMessageToTargetArgs",
"initializes",
"SendMessageToTargetArgs",
"with",
"the",
"required",
"arguments",
"."
] |
a3cd6cc58c0b7537b9614e7fa5da84bdd3c18514
|
https://github.com/mafredri/cdp/blob/a3cd6cc58c0b7537b9614e7fa5da84bdd3c18514/protocol/target/command.go#L241-L245
|
19,306
|
mafredri/cdp
|
protocol/target/command.go
|
SetSessionID
|
func (a *SendMessageToTargetArgs) SetSessionID(sessionID SessionID) *SendMessageToTargetArgs {
a.SessionID = &sessionID
return a
}
|
go
|
func (a *SendMessageToTargetArgs) SetSessionID(sessionID SessionID) *SendMessageToTargetArgs {
a.SessionID = &sessionID
return a
}
|
[
"func",
"(",
"a",
"*",
"SendMessageToTargetArgs",
")",
"SetSessionID",
"(",
"sessionID",
"SessionID",
")",
"*",
"SendMessageToTargetArgs",
"{",
"a",
".",
"SessionID",
"=",
"&",
"sessionID",
"\n",
"return",
"a",
"\n",
"}"
] |
// SetSessionID sets the SessionID optional argument. Identifier of
// the session.
|
[
"SetSessionID",
"sets",
"the",
"SessionID",
"optional",
"argument",
".",
"Identifier",
"of",
"the",
"session",
"."
] |
a3cd6cc58c0b7537b9614e7fa5da84bdd3c18514
|
https://github.com/mafredri/cdp/blob/a3cd6cc58c0b7537b9614e7fa5da84bdd3c18514/protocol/target/command.go#L249-L252
|
19,307
|
mafredri/cdp
|
protocol/target/command.go
|
NewSetAutoAttachArgs
|
func NewSetAutoAttachArgs(autoAttach bool, waitForDebuggerOnStart bool) *SetAutoAttachArgs {
args := new(SetAutoAttachArgs)
args.AutoAttach = autoAttach
args.WaitForDebuggerOnStart = waitForDebuggerOnStart
return args
}
|
go
|
func NewSetAutoAttachArgs(autoAttach bool, waitForDebuggerOnStart bool) *SetAutoAttachArgs {
args := new(SetAutoAttachArgs)
args.AutoAttach = autoAttach
args.WaitForDebuggerOnStart = waitForDebuggerOnStart
return args
}
|
[
"func",
"NewSetAutoAttachArgs",
"(",
"autoAttach",
"bool",
",",
"waitForDebuggerOnStart",
"bool",
")",
"*",
"SetAutoAttachArgs",
"{",
"args",
":=",
"new",
"(",
"SetAutoAttachArgs",
")",
"\n",
"args",
".",
"AutoAttach",
"=",
"autoAttach",
"\n",
"args",
".",
"WaitForDebuggerOnStart",
"=",
"waitForDebuggerOnStart",
"\n",
"return",
"args",
"\n",
"}"
] |
// NewSetAutoAttachArgs initializes SetAutoAttachArgs with the required arguments.
|
[
"NewSetAutoAttachArgs",
"initializes",
"SetAutoAttachArgs",
"with",
"the",
"required",
"arguments",
"."
] |
a3cd6cc58c0b7537b9614e7fa5da84bdd3c18514
|
https://github.com/mafredri/cdp/blob/a3cd6cc58c0b7537b9614e7fa5da84bdd3c18514/protocol/target/command.go#L274-L279
|
19,308
|
mafredri/cdp
|
protocol/target/command.go
|
NewSetDiscoverTargetsArgs
|
func NewSetDiscoverTargetsArgs(discover bool) *SetDiscoverTargetsArgs {
args := new(SetDiscoverTargetsArgs)
args.Discover = discover
return args
}
|
go
|
func NewSetDiscoverTargetsArgs(discover bool) *SetDiscoverTargetsArgs {
args := new(SetDiscoverTargetsArgs)
args.Discover = discover
return args
}
|
[
"func",
"NewSetDiscoverTargetsArgs",
"(",
"discover",
"bool",
")",
"*",
"SetDiscoverTargetsArgs",
"{",
"args",
":=",
"new",
"(",
"SetDiscoverTargetsArgs",
")",
"\n",
"args",
".",
"Discover",
"=",
"discover",
"\n",
"return",
"args",
"\n",
"}"
] |
// NewSetDiscoverTargetsArgs initializes SetDiscoverTargetsArgs with the required arguments.
|
[
"NewSetDiscoverTargetsArgs",
"initializes",
"SetDiscoverTargetsArgs",
"with",
"the",
"required",
"arguments",
"."
] |
a3cd6cc58c0b7537b9614e7fa5da84bdd3c18514
|
https://github.com/mafredri/cdp/blob/a3cd6cc58c0b7537b9614e7fa5da84bdd3c18514/protocol/target/command.go#L297-L301
|
19,309
|
mafredri/cdp
|
protocol/target/command.go
|
NewSetRemoteLocationsArgs
|
func NewSetRemoteLocationsArgs(locations []RemoteLocation) *SetRemoteLocationsArgs {
args := new(SetRemoteLocationsArgs)
args.Locations = locations
return args
}
|
go
|
func NewSetRemoteLocationsArgs(locations []RemoteLocation) *SetRemoteLocationsArgs {
args := new(SetRemoteLocationsArgs)
args.Locations = locations
return args
}
|
[
"func",
"NewSetRemoteLocationsArgs",
"(",
"locations",
"[",
"]",
"RemoteLocation",
")",
"*",
"SetRemoteLocationsArgs",
"{",
"args",
":=",
"new",
"(",
"SetRemoteLocationsArgs",
")",
"\n",
"args",
".",
"Locations",
"=",
"locations",
"\n",
"return",
"args",
"\n",
"}"
] |
// NewSetRemoteLocationsArgs initializes SetRemoteLocationsArgs with the required arguments.
|
[
"NewSetRemoteLocationsArgs",
"initializes",
"SetRemoteLocationsArgs",
"with",
"the",
"required",
"arguments",
"."
] |
a3cd6cc58c0b7537b9614e7fa5da84bdd3c18514
|
https://github.com/mafredri/cdp/blob/a3cd6cc58c0b7537b9614e7fa5da84bdd3c18514/protocol/target/command.go#L309-L313
|
19,310
|
mafredri/cdp
|
protocol/database/command.go
|
NewExecuteSQLArgs
|
func NewExecuteSQLArgs(databaseID ID, query string) *ExecuteSQLArgs {
args := new(ExecuteSQLArgs)
args.DatabaseID = databaseID
args.Query = query
return args
}
|
go
|
func NewExecuteSQLArgs(databaseID ID, query string) *ExecuteSQLArgs {
args := new(ExecuteSQLArgs)
args.DatabaseID = databaseID
args.Query = query
return args
}
|
[
"func",
"NewExecuteSQLArgs",
"(",
"databaseID",
"ID",
",",
"query",
"string",
")",
"*",
"ExecuteSQLArgs",
"{",
"args",
":=",
"new",
"(",
"ExecuteSQLArgs",
")",
"\n",
"args",
".",
"DatabaseID",
"=",
"databaseID",
"\n",
"args",
".",
"Query",
"=",
"query",
"\n",
"return",
"args",
"\n",
"}"
] |
// NewExecuteSQLArgs initializes ExecuteSQLArgs with the required arguments.
|
[
"NewExecuteSQLArgs",
"initializes",
"ExecuteSQLArgs",
"with",
"the",
"required",
"arguments",
"."
] |
a3cd6cc58c0b7537b9614e7fa5da84bdd3c18514
|
https://github.com/mafredri/cdp/blob/a3cd6cc58c0b7537b9614e7fa5da84bdd3c18514/protocol/database/command.go#L16-L21
|
19,311
|
mafredri/cdp
|
protocol/database/command.go
|
NewGetDatabaseTableNamesArgs
|
func NewGetDatabaseTableNamesArgs(databaseID ID) *GetDatabaseTableNamesArgs {
args := new(GetDatabaseTableNamesArgs)
args.DatabaseID = databaseID
return args
}
|
go
|
func NewGetDatabaseTableNamesArgs(databaseID ID) *GetDatabaseTableNamesArgs {
args := new(GetDatabaseTableNamesArgs)
args.DatabaseID = databaseID
return args
}
|
[
"func",
"NewGetDatabaseTableNamesArgs",
"(",
"databaseID",
"ID",
")",
"*",
"GetDatabaseTableNamesArgs",
"{",
"args",
":=",
"new",
"(",
"GetDatabaseTableNamesArgs",
")",
"\n",
"args",
".",
"DatabaseID",
"=",
"databaseID",
"\n",
"return",
"args",
"\n",
"}"
] |
// NewGetDatabaseTableNamesArgs initializes GetDatabaseTableNamesArgs with the required arguments.
|
[
"NewGetDatabaseTableNamesArgs",
"initializes",
"GetDatabaseTableNamesArgs",
"with",
"the",
"required",
"arguments",
"."
] |
a3cd6cc58c0b7537b9614e7fa5da84bdd3c18514
|
https://github.com/mafredri/cdp/blob/a3cd6cc58c0b7537b9614e7fa5da84bdd3c18514/protocol/database/command.go#L36-L40
|
19,312
|
mafredri/cdp
|
protocol/target/domain.go
|
AttachToTarget
|
func (d *domainClient) AttachToTarget(ctx context.Context, args *AttachToTargetArgs) (reply *AttachToTargetReply, err error) {
reply = new(AttachToTargetReply)
if args != nil {
err = rpcc.Invoke(ctx, "Target.attachToTarget", args, reply, d.conn)
} else {
err = rpcc.Invoke(ctx, "Target.attachToTarget", nil, reply, d.conn)
}
if err != nil {
err = &internal.OpError{Domain: "Target", Op: "AttachToTarget", Err: err}
}
return
}
|
go
|
func (d *domainClient) AttachToTarget(ctx context.Context, args *AttachToTargetArgs) (reply *AttachToTargetReply, err error) {
reply = new(AttachToTargetReply)
if args != nil {
err = rpcc.Invoke(ctx, "Target.attachToTarget", args, reply, d.conn)
} else {
err = rpcc.Invoke(ctx, "Target.attachToTarget", nil, reply, d.conn)
}
if err != nil {
err = &internal.OpError{Domain: "Target", Op: "AttachToTarget", Err: err}
}
return
}
|
[
"func",
"(",
"d",
"*",
"domainClient",
")",
"AttachToTarget",
"(",
"ctx",
"context",
".",
"Context",
",",
"args",
"*",
"AttachToTargetArgs",
")",
"(",
"reply",
"*",
"AttachToTargetReply",
",",
"err",
"error",
")",
"{",
"reply",
"=",
"new",
"(",
"AttachToTargetReply",
")",
"\n",
"if",
"args",
"!=",
"nil",
"{",
"err",
"=",
"rpcc",
".",
"Invoke",
"(",
"ctx",
",",
"\"",
"\"",
",",
"args",
",",
"reply",
",",
"d",
".",
"conn",
")",
"\n",
"}",
"else",
"{",
"err",
"=",
"rpcc",
".",
"Invoke",
"(",
"ctx",
",",
"\"",
"\"",
",",
"nil",
",",
"reply",
",",
"d",
".",
"conn",
")",
"\n",
"}",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"err",
"=",
"&",
"internal",
".",
"OpError",
"{",
"Domain",
":",
"\"",
"\"",
",",
"Op",
":",
"\"",
"\"",
",",
"Err",
":",
"err",
"}",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] |
// AttachToTarget invokes the Target method. Attaches to the target with given
// id.
|
[
"AttachToTarget",
"invokes",
"the",
"Target",
"method",
".",
"Attaches",
"to",
"the",
"target",
"with",
"given",
"id",
"."
] |
a3cd6cc58c0b7537b9614e7fa5da84bdd3c18514
|
https://github.com/mafredri/cdp/blob/a3cd6cc58c0b7537b9614e7fa5da84bdd3c18514/protocol/target/domain.go#L38-L49
|
19,313
|
mafredri/cdp
|
protocol/target/domain.go
|
CloseTarget
|
func (d *domainClient) CloseTarget(ctx context.Context, args *CloseTargetArgs) (reply *CloseTargetReply, err error) {
reply = new(CloseTargetReply)
if args != nil {
err = rpcc.Invoke(ctx, "Target.closeTarget", args, reply, d.conn)
} else {
err = rpcc.Invoke(ctx, "Target.closeTarget", nil, reply, d.conn)
}
if err != nil {
err = &internal.OpError{Domain: "Target", Op: "CloseTarget", Err: err}
}
return
}
|
go
|
func (d *domainClient) CloseTarget(ctx context.Context, args *CloseTargetArgs) (reply *CloseTargetReply, err error) {
reply = new(CloseTargetReply)
if args != nil {
err = rpcc.Invoke(ctx, "Target.closeTarget", args, reply, d.conn)
} else {
err = rpcc.Invoke(ctx, "Target.closeTarget", nil, reply, d.conn)
}
if err != nil {
err = &internal.OpError{Domain: "Target", Op: "CloseTarget", Err: err}
}
return
}
|
[
"func",
"(",
"d",
"*",
"domainClient",
")",
"CloseTarget",
"(",
"ctx",
"context",
".",
"Context",
",",
"args",
"*",
"CloseTargetArgs",
")",
"(",
"reply",
"*",
"CloseTargetReply",
",",
"err",
"error",
")",
"{",
"reply",
"=",
"new",
"(",
"CloseTargetReply",
")",
"\n",
"if",
"args",
"!=",
"nil",
"{",
"err",
"=",
"rpcc",
".",
"Invoke",
"(",
"ctx",
",",
"\"",
"\"",
",",
"args",
",",
"reply",
",",
"d",
".",
"conn",
")",
"\n",
"}",
"else",
"{",
"err",
"=",
"rpcc",
".",
"Invoke",
"(",
"ctx",
",",
"\"",
"\"",
",",
"nil",
",",
"reply",
",",
"d",
".",
"conn",
")",
"\n",
"}",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"err",
"=",
"&",
"internal",
".",
"OpError",
"{",
"Domain",
":",
"\"",
"\"",
",",
"Op",
":",
"\"",
"\"",
",",
"Err",
":",
"err",
"}",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] |
// CloseTarget invokes the Target method. Closes the target. If the target is
// a page that gets closed too.
|
[
"CloseTarget",
"invokes",
"the",
"Target",
"method",
".",
"Closes",
"the",
"target",
".",
"If",
"the",
"target",
"is",
"a",
"page",
"that",
"gets",
"closed",
"too",
"."
] |
a3cd6cc58c0b7537b9614e7fa5da84bdd3c18514
|
https://github.com/mafredri/cdp/blob/a3cd6cc58c0b7537b9614e7fa5da84bdd3c18514/protocol/target/domain.go#L64-L75
|
19,314
|
mafredri/cdp
|
protocol/target/domain.go
|
CreateTarget
|
func (d *domainClient) CreateTarget(ctx context.Context, args *CreateTargetArgs) (reply *CreateTargetReply, err error) {
reply = new(CreateTargetReply)
if args != nil {
err = rpcc.Invoke(ctx, "Target.createTarget", args, reply, d.conn)
} else {
err = rpcc.Invoke(ctx, "Target.createTarget", nil, reply, d.conn)
}
if err != nil {
err = &internal.OpError{Domain: "Target", Op: "CreateTarget", Err: err}
}
return
}
|
go
|
func (d *domainClient) CreateTarget(ctx context.Context, args *CreateTargetArgs) (reply *CreateTargetReply, err error) {
reply = new(CreateTargetReply)
if args != nil {
err = rpcc.Invoke(ctx, "Target.createTarget", args, reply, d.conn)
} else {
err = rpcc.Invoke(ctx, "Target.createTarget", nil, reply, d.conn)
}
if err != nil {
err = &internal.OpError{Domain: "Target", Op: "CreateTarget", Err: err}
}
return
}
|
[
"func",
"(",
"d",
"*",
"domainClient",
")",
"CreateTarget",
"(",
"ctx",
"context",
".",
"Context",
",",
"args",
"*",
"CreateTargetArgs",
")",
"(",
"reply",
"*",
"CreateTargetReply",
",",
"err",
"error",
")",
"{",
"reply",
"=",
"new",
"(",
"CreateTargetReply",
")",
"\n",
"if",
"args",
"!=",
"nil",
"{",
"err",
"=",
"rpcc",
".",
"Invoke",
"(",
"ctx",
",",
"\"",
"\"",
",",
"args",
",",
"reply",
",",
"d",
".",
"conn",
")",
"\n",
"}",
"else",
"{",
"err",
"=",
"rpcc",
".",
"Invoke",
"(",
"ctx",
",",
"\"",
"\"",
",",
"nil",
",",
"reply",
",",
"d",
".",
"conn",
")",
"\n",
"}",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"err",
"=",
"&",
"internal",
".",
"OpError",
"{",
"Domain",
":",
"\"",
"\"",
",",
"Op",
":",
"\"",
"\"",
",",
"Err",
":",
"err",
"}",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] |
// CreateTarget invokes the Target method. Creates a new page.
|
[
"CreateTarget",
"invokes",
"the",
"Target",
"method",
".",
"Creates",
"a",
"new",
"page",
"."
] |
a3cd6cc58c0b7537b9614e7fa5da84bdd3c18514
|
https://github.com/mafredri/cdp/blob/a3cd6cc58c0b7537b9614e7fa5da84bdd3c18514/protocol/target/domain.go#L123-L134
|
19,315
|
mafredri/cdp
|
protocol/target/domain.go
|
GetTargetInfo
|
func (d *domainClient) GetTargetInfo(ctx context.Context, args *GetTargetInfoArgs) (reply *GetTargetInfoReply, err error) {
reply = new(GetTargetInfoReply)
if args != nil {
err = rpcc.Invoke(ctx, "Target.getTargetInfo", args, reply, d.conn)
} else {
err = rpcc.Invoke(ctx, "Target.getTargetInfo", nil, reply, d.conn)
}
if err != nil {
err = &internal.OpError{Domain: "Target", Op: "GetTargetInfo", Err: err}
}
return
}
|
go
|
func (d *domainClient) GetTargetInfo(ctx context.Context, args *GetTargetInfoArgs) (reply *GetTargetInfoReply, err error) {
reply = new(GetTargetInfoReply)
if args != nil {
err = rpcc.Invoke(ctx, "Target.getTargetInfo", args, reply, d.conn)
} else {
err = rpcc.Invoke(ctx, "Target.getTargetInfo", nil, reply, d.conn)
}
if err != nil {
err = &internal.OpError{Domain: "Target", Op: "GetTargetInfo", Err: err}
}
return
}
|
[
"func",
"(",
"d",
"*",
"domainClient",
")",
"GetTargetInfo",
"(",
"ctx",
"context",
".",
"Context",
",",
"args",
"*",
"GetTargetInfoArgs",
")",
"(",
"reply",
"*",
"GetTargetInfoReply",
",",
"err",
"error",
")",
"{",
"reply",
"=",
"new",
"(",
"GetTargetInfoReply",
")",
"\n",
"if",
"args",
"!=",
"nil",
"{",
"err",
"=",
"rpcc",
".",
"Invoke",
"(",
"ctx",
",",
"\"",
"\"",
",",
"args",
",",
"reply",
",",
"d",
".",
"conn",
")",
"\n",
"}",
"else",
"{",
"err",
"=",
"rpcc",
".",
"Invoke",
"(",
"ctx",
",",
"\"",
"\"",
",",
"nil",
",",
"reply",
",",
"d",
".",
"conn",
")",
"\n",
"}",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"err",
"=",
"&",
"internal",
".",
"OpError",
"{",
"Domain",
":",
"\"",
"\"",
",",
"Op",
":",
"\"",
"\"",
",",
"Err",
":",
"err",
"}",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] |
// GetTargetInfo invokes the Target method. Returns information about a
// target.
|
[
"GetTargetInfo",
"invokes",
"the",
"Target",
"method",
".",
"Returns",
"information",
"about",
"a",
"target",
"."
] |
a3cd6cc58c0b7537b9614e7fa5da84bdd3c18514
|
https://github.com/mafredri/cdp/blob/a3cd6cc58c0b7537b9614e7fa5da84bdd3c18514/protocol/target/domain.go#L166-L177
|
19,316
|
mitchellh/cli
|
ui_mock.go
|
NewMockUi
|
func NewMockUi() *MockUi {
m := new(MockUi)
m.once.Do(m.init)
return m
}
|
go
|
func NewMockUi() *MockUi {
m := new(MockUi)
m.once.Do(m.init)
return m
}
|
[
"func",
"NewMockUi",
"(",
")",
"*",
"MockUi",
"{",
"m",
":=",
"new",
"(",
"MockUi",
")",
"\n",
"m",
".",
"once",
".",
"Do",
"(",
"m",
".",
"init",
")",
"\n",
"return",
"m",
"\n",
"}"
] |
// NewMockUi returns a fully initialized MockUi instance
// which is safe for concurrent use.
|
[
"NewMockUi",
"returns",
"a",
"fully",
"initialized",
"MockUi",
"instance",
"which",
"is",
"safe",
"for",
"concurrent",
"use",
"."
] |
3d22a244be8aa6fb16ac24af0e195c08b7d973aa
|
https://github.com/mitchellh/cli/blob/3d22a244be8aa6fb16ac24af0e195c08b7d973aa/ui_mock.go#L12-L16
|
19,317
|
mitchellh/cli
|
help.go
|
FilteredHelpFunc
|
func FilteredHelpFunc(include []string, f HelpFunc) HelpFunc {
return func(commands map[string]CommandFactory) string {
set := make(map[string]struct{})
for _, k := range include {
set[k] = struct{}{}
}
filtered := make(map[string]CommandFactory)
for k, f := range commands {
if _, ok := set[k]; ok {
filtered[k] = f
}
}
return f(filtered)
}
}
|
go
|
func FilteredHelpFunc(include []string, f HelpFunc) HelpFunc {
return func(commands map[string]CommandFactory) string {
set := make(map[string]struct{})
for _, k := range include {
set[k] = struct{}{}
}
filtered := make(map[string]CommandFactory)
for k, f := range commands {
if _, ok := set[k]; ok {
filtered[k] = f
}
}
return f(filtered)
}
}
|
[
"func",
"FilteredHelpFunc",
"(",
"include",
"[",
"]",
"string",
",",
"f",
"HelpFunc",
")",
"HelpFunc",
"{",
"return",
"func",
"(",
"commands",
"map",
"[",
"string",
"]",
"CommandFactory",
")",
"string",
"{",
"set",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"struct",
"{",
"}",
")",
"\n",
"for",
"_",
",",
"k",
":=",
"range",
"include",
"{",
"set",
"[",
"k",
"]",
"=",
"struct",
"{",
"}",
"{",
"}",
"\n",
"}",
"\n\n",
"filtered",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"CommandFactory",
")",
"\n",
"for",
"k",
",",
"f",
":=",
"range",
"commands",
"{",
"if",
"_",
",",
"ok",
":=",
"set",
"[",
"k",
"]",
";",
"ok",
"{",
"filtered",
"[",
"k",
"]",
"=",
"f",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"f",
"(",
"filtered",
")",
"\n",
"}",
"\n",
"}"
] |
// FilteredHelpFunc will filter the commands to only include the keys
// in the include parameter.
|
[
"FilteredHelpFunc",
"will",
"filter",
"the",
"commands",
"to",
"only",
"include",
"the",
"keys",
"in",
"the",
"include",
"parameter",
"."
] |
3d22a244be8aa6fb16ac24af0e195c08b7d973aa
|
https://github.com/mitchellh/cli/blob/3d22a244be8aa6fb16ac24af0e195c08b7d973aa/help.go#L63-L79
|
19,318
|
mitchellh/cli
|
cli.go
|
NewCLI
|
func NewCLI(app, version string) *CLI {
return &CLI{
Name: app,
Version: version,
HelpFunc: BasicHelpFunc(app),
Autocomplete: true,
}
}
|
go
|
func NewCLI(app, version string) *CLI {
return &CLI{
Name: app,
Version: version,
HelpFunc: BasicHelpFunc(app),
Autocomplete: true,
}
}
|
[
"func",
"NewCLI",
"(",
"app",
",",
"version",
"string",
")",
"*",
"CLI",
"{",
"return",
"&",
"CLI",
"{",
"Name",
":",
"app",
",",
"Version",
":",
"version",
",",
"HelpFunc",
":",
"BasicHelpFunc",
"(",
"app",
")",
",",
"Autocomplete",
":",
"true",
",",
"}",
"\n\n",
"}"
] |
// NewClI returns a new CLI instance with sensible defaults.
|
[
"NewClI",
"returns",
"a",
"new",
"CLI",
"instance",
"with",
"sensible",
"defaults",
"."
] |
3d22a244be8aa6fb16ac24af0e195c08b7d973aa
|
https://github.com/mitchellh/cli/blob/3d22a244be8aa6fb16ac24af0e195c08b7d973aa/cli.go#L145-L153
|
19,319
|
mitchellh/cli
|
cli.go
|
IsHelp
|
func (c *CLI) IsHelp() bool {
c.once.Do(c.init)
return c.isHelp
}
|
go
|
func (c *CLI) IsHelp() bool {
c.once.Do(c.init)
return c.isHelp
}
|
[
"func",
"(",
"c",
"*",
"CLI",
")",
"IsHelp",
"(",
")",
"bool",
"{",
"c",
".",
"once",
".",
"Do",
"(",
"c",
".",
"init",
")",
"\n",
"return",
"c",
".",
"isHelp",
"\n",
"}"
] |
// IsHelp returns whether or not the help flag is present within the
// arguments.
|
[
"IsHelp",
"returns",
"whether",
"or",
"not",
"the",
"help",
"flag",
"is",
"present",
"within",
"the",
"arguments",
"."
] |
3d22a244be8aa6fb16ac24af0e195c08b7d973aa
|
https://github.com/mitchellh/cli/blob/3d22a244be8aa6fb16ac24af0e195c08b7d973aa/cli.go#L157-L160
|
19,320
|
mitchellh/cli
|
cli.go
|
IsVersion
|
func (c *CLI) IsVersion() bool {
c.once.Do(c.init)
return c.isVersion
}
|
go
|
func (c *CLI) IsVersion() bool {
c.once.Do(c.init)
return c.isVersion
}
|
[
"func",
"(",
"c",
"*",
"CLI",
")",
"IsVersion",
"(",
")",
"bool",
"{",
"c",
".",
"once",
".",
"Do",
"(",
"c",
".",
"init",
")",
"\n",
"return",
"c",
".",
"isVersion",
"\n",
"}"
] |
// IsVersion returns whether or not the version flag is present within the
// arguments.
|
[
"IsVersion",
"returns",
"whether",
"or",
"not",
"the",
"version",
"flag",
"is",
"present",
"within",
"the",
"arguments",
"."
] |
3d22a244be8aa6fb16ac24af0e195c08b7d973aa
|
https://github.com/mitchellh/cli/blob/3d22a244be8aa6fb16ac24af0e195c08b7d973aa/cli.go#L164-L167
|
19,321
|
mitchellh/cli
|
cli.go
|
Run
|
func (c *CLI) Run() (int, error) {
c.once.Do(c.init)
// If this is a autocompletion request, satisfy it. This must be called
// first before anything else since its possible to be autocompleting
// -help or -version or other flags and we want to show completions
// and not actually write the help or version.
if c.Autocomplete && c.autocomplete.Complete() {
return 0, nil
}
// Just show the version and exit if instructed.
if c.IsVersion() && c.Version != "" {
c.HelpWriter.Write([]byte(c.Version + "\n"))
return 0, nil
}
// Just print the help when only '-h' or '--help' is passed.
if c.IsHelp() && c.Subcommand() == "" {
c.HelpWriter.Write([]byte(c.HelpFunc(c.helpCommands(c.Subcommand())) + "\n"))
return 0, nil
}
// If we're attempting to install or uninstall autocomplete then handle
if c.Autocomplete {
// Autocomplete requires the "Name" to be set so that we know what
// command to setup the autocomplete on.
if c.Name == "" {
return 1, fmt.Errorf(
"internal error: CLI.Name must be specified for autocomplete to work")
}
// If both install and uninstall flags are specified, then error
if c.isAutocompleteInstall && c.isAutocompleteUninstall {
return 1, fmt.Errorf(
"Either the autocomplete install or uninstall flag may " +
"be specified, but not both.")
}
// If the install flag is specified, perform the install or uninstall
if c.isAutocompleteInstall {
if err := c.autocompleteInstaller.Install(c.Name); err != nil {
return 1, err
}
return 0, nil
}
if c.isAutocompleteUninstall {
if err := c.autocompleteInstaller.Uninstall(c.Name); err != nil {
return 1, err
}
return 0, nil
}
}
// Attempt to get the factory function for creating the command
// implementation. If the command is invalid or blank, it is an error.
raw, ok := c.commandTree.Get(c.Subcommand())
if !ok {
c.HelpWriter.Write([]byte(c.HelpFunc(c.helpCommands(c.subcommandParent())) + "\n"))
return 127, nil
}
command, err := raw.(CommandFactory)()
if err != nil {
return 1, err
}
// If we've been instructed to just print the help, then print it
if c.IsHelp() {
c.commandHelp(command)
return 0, nil
}
// If there is an invalid flag, then error
if len(c.topFlags) > 0 {
c.HelpWriter.Write([]byte(
"Invalid flags before the subcommand. If these flags are for\n" +
"the subcommand, please put them after the subcommand.\n\n"))
c.commandHelp(command)
return 1, nil
}
code := command.Run(c.SubcommandArgs())
if code == RunResultHelp {
// Requesting help
c.commandHelp(command)
return 1, nil
}
return code, nil
}
|
go
|
func (c *CLI) Run() (int, error) {
c.once.Do(c.init)
// If this is a autocompletion request, satisfy it. This must be called
// first before anything else since its possible to be autocompleting
// -help or -version or other flags and we want to show completions
// and not actually write the help or version.
if c.Autocomplete && c.autocomplete.Complete() {
return 0, nil
}
// Just show the version and exit if instructed.
if c.IsVersion() && c.Version != "" {
c.HelpWriter.Write([]byte(c.Version + "\n"))
return 0, nil
}
// Just print the help when only '-h' or '--help' is passed.
if c.IsHelp() && c.Subcommand() == "" {
c.HelpWriter.Write([]byte(c.HelpFunc(c.helpCommands(c.Subcommand())) + "\n"))
return 0, nil
}
// If we're attempting to install or uninstall autocomplete then handle
if c.Autocomplete {
// Autocomplete requires the "Name" to be set so that we know what
// command to setup the autocomplete on.
if c.Name == "" {
return 1, fmt.Errorf(
"internal error: CLI.Name must be specified for autocomplete to work")
}
// If both install and uninstall flags are specified, then error
if c.isAutocompleteInstall && c.isAutocompleteUninstall {
return 1, fmt.Errorf(
"Either the autocomplete install or uninstall flag may " +
"be specified, but not both.")
}
// If the install flag is specified, perform the install or uninstall
if c.isAutocompleteInstall {
if err := c.autocompleteInstaller.Install(c.Name); err != nil {
return 1, err
}
return 0, nil
}
if c.isAutocompleteUninstall {
if err := c.autocompleteInstaller.Uninstall(c.Name); err != nil {
return 1, err
}
return 0, nil
}
}
// Attempt to get the factory function for creating the command
// implementation. If the command is invalid or blank, it is an error.
raw, ok := c.commandTree.Get(c.Subcommand())
if !ok {
c.HelpWriter.Write([]byte(c.HelpFunc(c.helpCommands(c.subcommandParent())) + "\n"))
return 127, nil
}
command, err := raw.(CommandFactory)()
if err != nil {
return 1, err
}
// If we've been instructed to just print the help, then print it
if c.IsHelp() {
c.commandHelp(command)
return 0, nil
}
// If there is an invalid flag, then error
if len(c.topFlags) > 0 {
c.HelpWriter.Write([]byte(
"Invalid flags before the subcommand. If these flags are for\n" +
"the subcommand, please put them after the subcommand.\n\n"))
c.commandHelp(command)
return 1, nil
}
code := command.Run(c.SubcommandArgs())
if code == RunResultHelp {
// Requesting help
c.commandHelp(command)
return 1, nil
}
return code, nil
}
|
[
"func",
"(",
"c",
"*",
"CLI",
")",
"Run",
"(",
")",
"(",
"int",
",",
"error",
")",
"{",
"c",
".",
"once",
".",
"Do",
"(",
"c",
".",
"init",
")",
"\n\n",
"// If this is a autocompletion request, satisfy it. This must be called",
"// first before anything else since its possible to be autocompleting",
"// -help or -version or other flags and we want to show completions",
"// and not actually write the help or version.",
"if",
"c",
".",
"Autocomplete",
"&&",
"c",
".",
"autocomplete",
".",
"Complete",
"(",
")",
"{",
"return",
"0",
",",
"nil",
"\n",
"}",
"\n\n",
"// Just show the version and exit if instructed.",
"if",
"c",
".",
"IsVersion",
"(",
")",
"&&",
"c",
".",
"Version",
"!=",
"\"",
"\"",
"{",
"c",
".",
"HelpWriter",
".",
"Write",
"(",
"[",
"]",
"byte",
"(",
"c",
".",
"Version",
"+",
"\"",
"\\n",
"\"",
")",
")",
"\n",
"return",
"0",
",",
"nil",
"\n",
"}",
"\n\n",
"// Just print the help when only '-h' or '--help' is passed.",
"if",
"c",
".",
"IsHelp",
"(",
")",
"&&",
"c",
".",
"Subcommand",
"(",
")",
"==",
"\"",
"\"",
"{",
"c",
".",
"HelpWriter",
".",
"Write",
"(",
"[",
"]",
"byte",
"(",
"c",
".",
"HelpFunc",
"(",
"c",
".",
"helpCommands",
"(",
"c",
".",
"Subcommand",
"(",
")",
")",
")",
"+",
"\"",
"\\n",
"\"",
")",
")",
"\n",
"return",
"0",
",",
"nil",
"\n",
"}",
"\n\n",
"// If we're attempting to install or uninstall autocomplete then handle",
"if",
"c",
".",
"Autocomplete",
"{",
"// Autocomplete requires the \"Name\" to be set so that we know what",
"// command to setup the autocomplete on.",
"if",
"c",
".",
"Name",
"==",
"\"",
"\"",
"{",
"return",
"1",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// If both install and uninstall flags are specified, then error",
"if",
"c",
".",
"isAutocompleteInstall",
"&&",
"c",
".",
"isAutocompleteUninstall",
"{",
"return",
"1",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
"+",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// If the install flag is specified, perform the install or uninstall",
"if",
"c",
".",
"isAutocompleteInstall",
"{",
"if",
"err",
":=",
"c",
".",
"autocompleteInstaller",
".",
"Install",
"(",
"c",
".",
"Name",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"1",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"0",
",",
"nil",
"\n",
"}",
"\n\n",
"if",
"c",
".",
"isAutocompleteUninstall",
"{",
"if",
"err",
":=",
"c",
".",
"autocompleteInstaller",
".",
"Uninstall",
"(",
"c",
".",
"Name",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"1",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"0",
",",
"nil",
"\n",
"}",
"\n",
"}",
"\n\n",
"// Attempt to get the factory function for creating the command",
"// implementation. If the command is invalid or blank, it is an error.",
"raw",
",",
"ok",
":=",
"c",
".",
"commandTree",
".",
"Get",
"(",
"c",
".",
"Subcommand",
"(",
")",
")",
"\n",
"if",
"!",
"ok",
"{",
"c",
".",
"HelpWriter",
".",
"Write",
"(",
"[",
"]",
"byte",
"(",
"c",
".",
"HelpFunc",
"(",
"c",
".",
"helpCommands",
"(",
"c",
".",
"subcommandParent",
"(",
")",
")",
")",
"+",
"\"",
"\\n",
"\"",
")",
")",
"\n",
"return",
"127",
",",
"nil",
"\n",
"}",
"\n\n",
"command",
",",
"err",
":=",
"raw",
".",
"(",
"CommandFactory",
")",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"1",
",",
"err",
"\n",
"}",
"\n\n",
"// If we've been instructed to just print the help, then print it",
"if",
"c",
".",
"IsHelp",
"(",
")",
"{",
"c",
".",
"commandHelp",
"(",
"command",
")",
"\n",
"return",
"0",
",",
"nil",
"\n",
"}",
"\n\n",
"// If there is an invalid flag, then error",
"if",
"len",
"(",
"c",
".",
"topFlags",
")",
">",
"0",
"{",
"c",
".",
"HelpWriter",
".",
"Write",
"(",
"[",
"]",
"byte",
"(",
"\"",
"\\n",
"\"",
"+",
"\"",
"\\n",
"\\n",
"\"",
")",
")",
"\n",
"c",
".",
"commandHelp",
"(",
"command",
")",
"\n",
"return",
"1",
",",
"nil",
"\n",
"}",
"\n\n",
"code",
":=",
"command",
".",
"Run",
"(",
"c",
".",
"SubcommandArgs",
"(",
")",
")",
"\n",
"if",
"code",
"==",
"RunResultHelp",
"{",
"// Requesting help",
"c",
".",
"commandHelp",
"(",
"command",
")",
"\n",
"return",
"1",
",",
"nil",
"\n",
"}",
"\n\n",
"return",
"code",
",",
"nil",
"\n",
"}"
] |
// Run runs the actual CLI based on the arguments given.
|
[
"Run",
"runs",
"the",
"actual",
"CLI",
"based",
"on",
"the",
"arguments",
"given",
"."
] |
3d22a244be8aa6fb16ac24af0e195c08b7d973aa
|
https://github.com/mitchellh/cli/blob/3d22a244be8aa6fb16ac24af0e195c08b7d973aa/cli.go#L170-L263
|
19,322
|
mitchellh/cli
|
cli.go
|
SubcommandArgs
|
func (c *CLI) SubcommandArgs() []string {
c.once.Do(c.init)
return c.subcommandArgs
}
|
go
|
func (c *CLI) SubcommandArgs() []string {
c.once.Do(c.init)
return c.subcommandArgs
}
|
[
"func",
"(",
"c",
"*",
"CLI",
")",
"SubcommandArgs",
"(",
")",
"[",
"]",
"string",
"{",
"c",
".",
"once",
".",
"Do",
"(",
"c",
".",
"init",
")",
"\n",
"return",
"c",
".",
"subcommandArgs",
"\n",
"}"
] |
// SubcommandArgs returns the arguments that will be passed to the
// subcommand.
|
[
"SubcommandArgs",
"returns",
"the",
"arguments",
"that",
"will",
"be",
"passed",
"to",
"the",
"subcommand",
"."
] |
3d22a244be8aa6fb16ac24af0e195c08b7d973aa
|
https://github.com/mitchellh/cli/blob/3d22a244be8aa6fb16ac24af0e195c08b7d973aa/cli.go#L275-L278
|
19,323
|
mitchellh/cli
|
cli.go
|
subcommandParent
|
func (c *CLI) subcommandParent() string {
// Get the subcommand, if it is "" alread just return
sub := c.Subcommand()
if sub == "" {
return sub
}
// Clear any trailing spaces and find the last space
sub = strings.TrimRight(sub, " ")
idx := strings.LastIndex(sub, " ")
if idx == -1 {
// No space means our parent is root
return ""
}
return sub[:idx]
}
|
go
|
func (c *CLI) subcommandParent() string {
// Get the subcommand, if it is "" alread just return
sub := c.Subcommand()
if sub == "" {
return sub
}
// Clear any trailing spaces and find the last space
sub = strings.TrimRight(sub, " ")
idx := strings.LastIndex(sub, " ")
if idx == -1 {
// No space means our parent is root
return ""
}
return sub[:idx]
}
|
[
"func",
"(",
"c",
"*",
"CLI",
")",
"subcommandParent",
"(",
")",
"string",
"{",
"// Get the subcommand, if it is \"\" alread just return",
"sub",
":=",
"c",
".",
"Subcommand",
"(",
")",
"\n",
"if",
"sub",
"==",
"\"",
"\"",
"{",
"return",
"sub",
"\n",
"}",
"\n\n",
"// Clear any trailing spaces and find the last space",
"sub",
"=",
"strings",
".",
"TrimRight",
"(",
"sub",
",",
"\"",
"\"",
")",
"\n",
"idx",
":=",
"strings",
".",
"LastIndex",
"(",
"sub",
",",
"\"",
"\"",
")",
"\n\n",
"if",
"idx",
"==",
"-",
"1",
"{",
"// No space means our parent is root",
"return",
"\"",
"\"",
"\n",
"}",
"\n\n",
"return",
"sub",
"[",
":",
"idx",
"]",
"\n",
"}"
] |
// subcommandParent returns the parent of this subcommand, if there is one.
// If there isn't on, "" is returned.
|
[
"subcommandParent",
"returns",
"the",
"parent",
"of",
"this",
"subcommand",
"if",
"there",
"is",
"one",
".",
"If",
"there",
"isn",
"t",
"on",
"is",
"returned",
"."
] |
3d22a244be8aa6fb16ac24af0e195c08b7d973aa
|
https://github.com/mitchellh/cli/blob/3d22a244be8aa6fb16ac24af0e195c08b7d973aa/cli.go#L282-L299
|
19,324
|
mitchellh/cli
|
cli.go
|
helpCommands
|
func (c *CLI) helpCommands(prefix string) map[string]CommandFactory {
// If our prefix isn't empty, make sure it ends in ' '
if prefix != "" && prefix[len(prefix)-1] != ' ' {
prefix += " "
}
// Get all the subkeys of this command
var keys []string
c.commandTree.WalkPrefix(prefix, func(k string, raw interface{}) bool {
// Ignore any sub-sub keys, i.e. "foo bar baz" when we want "foo bar"
if !strings.Contains(k[len(prefix):], " ") {
keys = append(keys, k)
}
return false
})
// For each of the keys return that in the map
result := make(map[string]CommandFactory, len(keys))
for _, k := range keys {
raw, ok := c.commandTree.Get(k)
if !ok {
// We just got it via WalkPrefix above, so we just panic
panic("not found: " + k)
}
// If this is a hidden command, don't show it
if _, ok := c.commandHidden[k]; ok {
continue
}
result[k] = raw.(CommandFactory)
}
return result
}
|
go
|
func (c *CLI) helpCommands(prefix string) map[string]CommandFactory {
// If our prefix isn't empty, make sure it ends in ' '
if prefix != "" && prefix[len(prefix)-1] != ' ' {
prefix += " "
}
// Get all the subkeys of this command
var keys []string
c.commandTree.WalkPrefix(prefix, func(k string, raw interface{}) bool {
// Ignore any sub-sub keys, i.e. "foo bar baz" when we want "foo bar"
if !strings.Contains(k[len(prefix):], " ") {
keys = append(keys, k)
}
return false
})
// For each of the keys return that in the map
result := make(map[string]CommandFactory, len(keys))
for _, k := range keys {
raw, ok := c.commandTree.Get(k)
if !ok {
// We just got it via WalkPrefix above, so we just panic
panic("not found: " + k)
}
// If this is a hidden command, don't show it
if _, ok := c.commandHidden[k]; ok {
continue
}
result[k] = raw.(CommandFactory)
}
return result
}
|
[
"func",
"(",
"c",
"*",
"CLI",
")",
"helpCommands",
"(",
"prefix",
"string",
")",
"map",
"[",
"string",
"]",
"CommandFactory",
"{",
"// If our prefix isn't empty, make sure it ends in ' '",
"if",
"prefix",
"!=",
"\"",
"\"",
"&&",
"prefix",
"[",
"len",
"(",
"prefix",
")",
"-",
"1",
"]",
"!=",
"' '",
"{",
"prefix",
"+=",
"\"",
"\"",
"\n",
"}",
"\n\n",
"// Get all the subkeys of this command",
"var",
"keys",
"[",
"]",
"string",
"\n",
"c",
".",
"commandTree",
".",
"WalkPrefix",
"(",
"prefix",
",",
"func",
"(",
"k",
"string",
",",
"raw",
"interface",
"{",
"}",
")",
"bool",
"{",
"// Ignore any sub-sub keys, i.e. \"foo bar baz\" when we want \"foo bar\"",
"if",
"!",
"strings",
".",
"Contains",
"(",
"k",
"[",
"len",
"(",
"prefix",
")",
":",
"]",
",",
"\"",
"\"",
")",
"{",
"keys",
"=",
"append",
"(",
"keys",
",",
"k",
")",
"\n",
"}",
"\n\n",
"return",
"false",
"\n",
"}",
")",
"\n\n",
"// For each of the keys return that in the map",
"result",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"CommandFactory",
",",
"len",
"(",
"keys",
")",
")",
"\n",
"for",
"_",
",",
"k",
":=",
"range",
"keys",
"{",
"raw",
",",
"ok",
":=",
"c",
".",
"commandTree",
".",
"Get",
"(",
"k",
")",
"\n",
"if",
"!",
"ok",
"{",
"// We just got it via WalkPrefix above, so we just panic",
"panic",
"(",
"\"",
"\"",
"+",
"k",
")",
"\n",
"}",
"\n\n",
"// If this is a hidden command, don't show it",
"if",
"_",
",",
"ok",
":=",
"c",
".",
"commandHidden",
"[",
"k",
"]",
";",
"ok",
"{",
"continue",
"\n",
"}",
"\n\n",
"result",
"[",
"k",
"]",
"=",
"raw",
".",
"(",
"CommandFactory",
")",
"\n",
"}",
"\n\n",
"return",
"result",
"\n",
"}"
] |
// helpCommands returns the subcommands for the HelpFunc argument.
// This will only contain immediate subcommands.
|
[
"helpCommands",
"returns",
"the",
"subcommands",
"for",
"the",
"HelpFunc",
"argument",
".",
"This",
"will",
"only",
"contain",
"immediate",
"subcommands",
"."
] |
3d22a244be8aa6fb16ac24af0e195c08b7d973aa
|
https://github.com/mitchellh/cli/blob/3d22a244be8aa6fb16ac24af0e195c08b7d973aa/cli.go#L574-L609
|
19,325
|
bitly/go-hostpool
|
hostpool.go
|
New
|
func New(hosts []string) HostPool {
p := &standardHostPool{
hosts: make(map[string]*hostEntry, len(hosts)),
hostList: make([]*hostEntry, len(hosts)),
initialRetryDelay: time.Duration(30) * time.Second,
maxRetryInterval: time.Duration(900) * time.Second,
}
for i, h := range hosts {
e := &hostEntry{
host: h,
retryDelay: p.initialRetryDelay,
}
p.hosts[h] = e
p.hostList[i] = e
}
return p
}
|
go
|
func New(hosts []string) HostPool {
p := &standardHostPool{
hosts: make(map[string]*hostEntry, len(hosts)),
hostList: make([]*hostEntry, len(hosts)),
initialRetryDelay: time.Duration(30) * time.Second,
maxRetryInterval: time.Duration(900) * time.Second,
}
for i, h := range hosts {
e := &hostEntry{
host: h,
retryDelay: p.initialRetryDelay,
}
p.hosts[h] = e
p.hostList[i] = e
}
return p
}
|
[
"func",
"New",
"(",
"hosts",
"[",
"]",
"string",
")",
"HostPool",
"{",
"p",
":=",
"&",
"standardHostPool",
"{",
"hosts",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"hostEntry",
",",
"len",
"(",
"hosts",
")",
")",
",",
"hostList",
":",
"make",
"(",
"[",
"]",
"*",
"hostEntry",
",",
"len",
"(",
"hosts",
")",
")",
",",
"initialRetryDelay",
":",
"time",
".",
"Duration",
"(",
"30",
")",
"*",
"time",
".",
"Second",
",",
"maxRetryInterval",
":",
"time",
".",
"Duration",
"(",
"900",
")",
"*",
"time",
".",
"Second",
",",
"}",
"\n\n",
"for",
"i",
",",
"h",
":=",
"range",
"hosts",
"{",
"e",
":=",
"&",
"hostEntry",
"{",
"host",
":",
"h",
",",
"retryDelay",
":",
"p",
".",
"initialRetryDelay",
",",
"}",
"\n",
"p",
".",
"hosts",
"[",
"h",
"]",
"=",
"e",
"\n",
"p",
".",
"hostList",
"[",
"i",
"]",
"=",
"e",
"\n",
"}",
"\n\n",
"return",
"p",
"\n",
"}"
] |
// Construct a basic HostPool using the hostnames provided
|
[
"Construct",
"a",
"basic",
"HostPool",
"using",
"the",
"hostnames",
"provided"
] |
a3a6125de9329587178a9792dc8f4bc98e620d2d
|
https://github.com/bitly/go-hostpool/blob/a3a6125de9329587178a9792dc8f4bc98e620d2d/hostpool.go#L71-L89
|
19,326
|
bitly/go-hostpool
|
hostpool.go
|
Get
|
func (p *standardHostPool) Get() HostPoolResponse {
p.Lock()
defer p.Unlock()
host := p.getRoundRobin()
return &standardHostPoolResponse{host: host, pool: p}
}
|
go
|
func (p *standardHostPool) Get() HostPoolResponse {
p.Lock()
defer p.Unlock()
host := p.getRoundRobin()
return &standardHostPoolResponse{host: host, pool: p}
}
|
[
"func",
"(",
"p",
"*",
"standardHostPool",
")",
"Get",
"(",
")",
"HostPoolResponse",
"{",
"p",
".",
"Lock",
"(",
")",
"\n",
"defer",
"p",
".",
"Unlock",
"(",
")",
"\n",
"host",
":=",
"p",
".",
"getRoundRobin",
"(",
")",
"\n",
"return",
"&",
"standardHostPoolResponse",
"{",
"host",
":",
"host",
",",
"pool",
":",
"p",
"}",
"\n",
"}"
] |
// return an entry from the HostPool
|
[
"return",
"an",
"entry",
"from",
"the",
"HostPool"
] |
a3a6125de9329587178a9792dc8f4bc98e620d2d
|
https://github.com/bitly/go-hostpool/blob/a3a6125de9329587178a9792dc8f4bc98e620d2d/hostpool.go#L114-L119
|
19,327
|
bitly/go-hostpool
|
hostpool.go
|
doResetAll
|
func (p *standardHostPool) doResetAll() {
for _, h := range p.hosts {
h.dead = false
}
}
|
go
|
func (p *standardHostPool) doResetAll() {
for _, h := range p.hosts {
h.dead = false
}
}
|
[
"func",
"(",
"p",
"*",
"standardHostPool",
")",
"doResetAll",
"(",
")",
"{",
"for",
"_",
",",
"h",
":=",
"range",
"p",
".",
"hosts",
"{",
"h",
".",
"dead",
"=",
"false",
"\n",
"}",
"\n",
"}"
] |
// this actually performs the logic to reset,
// and should only be called when the lock has
// already been acquired
|
[
"this",
"actually",
"performs",
"the",
"logic",
"to",
"reset",
"and",
"should",
"only",
"be",
"called",
"when",
"the",
"lock",
"has",
"already",
"been",
"acquired"
] |
a3a6125de9329587178a9792dc8f4bc98e620d2d
|
https://github.com/bitly/go-hostpool/blob/a3a6125de9329587178a9792dc8f4bc98e620d2d/hostpool.go#L155-L159
|
19,328
|
SermoDigital/jose
|
jwt/jwt.go
|
SetClaim
|
func (v *Validator) SetClaim(claim string, val interface{}) {
v.expect()
v.Expected.Set(claim, val)
}
|
go
|
func (v *Validator) SetClaim(claim string, val interface{}) {
v.expect()
v.Expected.Set(claim, val)
}
|
[
"func",
"(",
"v",
"*",
"Validator",
")",
"SetClaim",
"(",
"claim",
"string",
",",
"val",
"interface",
"{",
"}",
")",
"{",
"v",
".",
"expect",
"(",
")",
"\n",
"v",
".",
"Expected",
".",
"Set",
"(",
"claim",
",",
"val",
")",
"\n",
"}"
] |
// SetClaim sets the claim with the given val.
|
[
"SetClaim",
"sets",
"the",
"claim",
"with",
"the",
"given",
"val",
"."
] |
803625baeddc3526d01d321b5066029f53eafc81
|
https://github.com/SermoDigital/jose/blob/803625baeddc3526d01d321b5066029f53eafc81/jwt/jwt.go#L86-L89
|
19,329
|
SermoDigital/jose
|
header.go
|
Get
|
func (h Header) Get(key string) interface{} {
if h == nil {
return nil
}
return h[key]
}
|
go
|
func (h Header) Get(key string) interface{} {
if h == nil {
return nil
}
return h[key]
}
|
[
"func",
"(",
"h",
"Header",
")",
"Get",
"(",
"key",
"string",
")",
"interface",
"{",
"}",
"{",
"if",
"h",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"h",
"[",
"key",
"]",
"\n",
"}"
] |
// Get retrieves the value corresponding with key from the Header.
|
[
"Get",
"retrieves",
"the",
"value",
"corresponding",
"with",
"key",
"from",
"the",
"Header",
"."
] |
803625baeddc3526d01d321b5066029f53eafc81
|
https://github.com/SermoDigital/jose/blob/803625baeddc3526d01d321b5066029f53eafc81/header.go#L10-L15
|
19,330
|
SermoDigital/jose
|
header.go
|
Has
|
func (h Header) Has(key string) bool {
_, ok := h[key]
return ok
}
|
go
|
func (h Header) Has(key string) bool {
_, ok := h[key]
return ok
}
|
[
"func",
"(",
"h",
"Header",
")",
"Has",
"(",
"key",
"string",
")",
"bool",
"{",
"_",
",",
"ok",
":=",
"h",
"[",
"key",
"]",
"\n",
"return",
"ok",
"\n",
"}"
] |
// Has returns true if a value for the given key exists inside the Header.
|
[
"Has",
"returns",
"true",
"if",
"a",
"value",
"for",
"the",
"given",
"key",
"exists",
"inside",
"the",
"Header",
"."
] |
803625baeddc3526d01d321b5066029f53eafc81
|
https://github.com/SermoDigital/jose/blob/803625baeddc3526d01d321b5066029f53eafc81/header.go#L28-L31
|
19,331
|
SermoDigital/jose
|
header.go
|
MarshalJSON
|
func (h Header) MarshalJSON() ([]byte, error) {
if len(h) == 0 {
return nil, nil
}
b, err := json.Marshal(map[string]interface{}(h))
if err != nil {
return nil, err
}
return EncodeEscape(b), nil
}
|
go
|
func (h Header) MarshalJSON() ([]byte, error) {
if len(h) == 0 {
return nil, nil
}
b, err := json.Marshal(map[string]interface{}(h))
if err != nil {
return nil, err
}
return EncodeEscape(b), nil
}
|
[
"func",
"(",
"h",
"Header",
")",
"MarshalJSON",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"if",
"len",
"(",
"h",
")",
"==",
"0",
"{",
"return",
"nil",
",",
"nil",
"\n",
"}",
"\n",
"b",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"(",
"h",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"EncodeEscape",
"(",
"b",
")",
",",
"nil",
"\n",
"}"
] |
// MarshalJSON implements json.Marshaler for Header.
|
[
"MarshalJSON",
"implements",
"json",
".",
"Marshaler",
"for",
"Header",
"."
] |
803625baeddc3526d01d321b5066029f53eafc81
|
https://github.com/SermoDigital/jose/blob/803625baeddc3526d01d321b5066029f53eafc81/header.go#L34-L43
|
19,332
|
SermoDigital/jose
|
header.go
|
UnmarshalJSON
|
func (h *Header) UnmarshalJSON(b []byte) error {
if b == nil {
return nil
}
b, err := DecodeEscaped(b)
if err != nil {
return err
}
return json.Unmarshal(b, (*map[string]interface{})(h))
}
|
go
|
func (h *Header) UnmarshalJSON(b []byte) error {
if b == nil {
return nil
}
b, err := DecodeEscaped(b)
if err != nil {
return err
}
return json.Unmarshal(b, (*map[string]interface{})(h))
}
|
[
"func",
"(",
"h",
"*",
"Header",
")",
"UnmarshalJSON",
"(",
"b",
"[",
"]",
"byte",
")",
"error",
"{",
"if",
"b",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"b",
",",
"err",
":=",
"DecodeEscaped",
"(",
"b",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"json",
".",
"Unmarshal",
"(",
"b",
",",
"(",
"*",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"(",
"h",
")",
")",
"\n",
"}"
] |
// UnmarshalJSON implements json.Unmarshaler for Header.
|
[
"UnmarshalJSON",
"implements",
"json",
".",
"Unmarshaler",
"for",
"Header",
"."
] |
803625baeddc3526d01d321b5066029f53eafc81
|
https://github.com/SermoDigital/jose/blob/803625baeddc3526d01d321b5066029f53eafc81/header.go#L51-L60
|
19,333
|
SermoDigital/jose
|
header.go
|
Get
|
func (p Protected) Get(key string) interface{} {
if p == nil {
return nil
}
return p[key]
}
|
go
|
func (p Protected) Get(key string) interface{} {
if p == nil {
return nil
}
return p[key]
}
|
[
"func",
"(",
"p",
"Protected",
")",
"Get",
"(",
"key",
"string",
")",
"interface",
"{",
"}",
"{",
"if",
"p",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"p",
"[",
"key",
"]",
"\n",
"}"
] |
// Get retrieves the value corresponding with key from the Protected Header.
|
[
"Get",
"retrieves",
"the",
"value",
"corresponding",
"with",
"key",
"from",
"the",
"Protected",
"Header",
"."
] |
803625baeddc3526d01d321b5066029f53eafc81
|
https://github.com/SermoDigital/jose/blob/803625baeddc3526d01d321b5066029f53eafc81/header.go#L67-L72
|
19,334
|
SermoDigital/jose
|
header.go
|
Has
|
func (p Protected) Has(key string) bool {
_, ok := p[key]
return ok
}
|
go
|
func (p Protected) Has(key string) bool {
_, ok := p[key]
return ok
}
|
[
"func",
"(",
"p",
"Protected",
")",
"Has",
"(",
"key",
"string",
")",
"bool",
"{",
"_",
",",
"ok",
":=",
"p",
"[",
"key",
"]",
"\n",
"return",
"ok",
"\n",
"}"
] |
// Has returns true if a value for the given key exists inside the Protected
// Header.
|
[
"Has",
"returns",
"true",
"if",
"a",
"value",
"for",
"the",
"given",
"key",
"exists",
"inside",
"the",
"Protected",
"Header",
"."
] |
803625baeddc3526d01d321b5066029f53eafc81
|
https://github.com/SermoDigital/jose/blob/803625baeddc3526d01d321b5066029f53eafc81/header.go#L86-L89
|
19,335
|
SermoDigital/jose
|
header.go
|
MarshalJSON
|
func (p Protected) MarshalJSON() ([]byte, error) {
b, err := json.Marshal(map[string]interface{}(p))
if err != nil {
return nil, err
}
return EncodeEscape(b), nil
}
|
go
|
func (p Protected) MarshalJSON() ([]byte, error) {
b, err := json.Marshal(map[string]interface{}(p))
if err != nil {
return nil, err
}
return EncodeEscape(b), nil
}
|
[
"func",
"(",
"p",
"Protected",
")",
"MarshalJSON",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"b",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"(",
"p",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"EncodeEscape",
"(",
"b",
")",
",",
"nil",
"\n",
"}"
] |
// MarshalJSON implements json.Marshaler for Protected.
|
[
"MarshalJSON",
"implements",
"json",
".",
"Marshaler",
"for",
"Protected",
"."
] |
803625baeddc3526d01d321b5066029f53eafc81
|
https://github.com/SermoDigital/jose/blob/803625baeddc3526d01d321b5066029f53eafc81/header.go#L92-L98
|
19,336
|
SermoDigital/jose
|
header.go
|
Base64
|
func (p Protected) Base64() ([]byte, error) {
b, err := json.Marshal(map[string]interface{}(p))
if err != nil {
return nil, err
}
return Base64Encode(b), nil
}
|
go
|
func (p Protected) Base64() ([]byte, error) {
b, err := json.Marshal(map[string]interface{}(p))
if err != nil {
return nil, err
}
return Base64Encode(b), nil
}
|
[
"func",
"(",
"p",
"Protected",
")",
"Base64",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"b",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"(",
"p",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"Base64Encode",
"(",
"b",
")",
",",
"nil",
"\n",
"}"
] |
// Base64 implements the Encoder interface.
|
[
"Base64",
"implements",
"the",
"Encoder",
"interface",
"."
] |
803625baeddc3526d01d321b5066029f53eafc81
|
https://github.com/SermoDigital/jose/blob/803625baeddc3526d01d321b5066029f53eafc81/header.go#L101-L107
|
19,337
|
SermoDigital/jose
|
header.go
|
UnmarshalJSON
|
func (p *Protected) UnmarshalJSON(b []byte) error {
var h Header
if err := h.UnmarshalJSON(b); err != nil {
return err
}
*p = Protected(h)
return nil
}
|
go
|
func (p *Protected) UnmarshalJSON(b []byte) error {
var h Header
if err := h.UnmarshalJSON(b); err != nil {
return err
}
*p = Protected(h)
return nil
}
|
[
"func",
"(",
"p",
"*",
"Protected",
")",
"UnmarshalJSON",
"(",
"b",
"[",
"]",
"byte",
")",
"error",
"{",
"var",
"h",
"Header",
"\n",
"if",
"err",
":=",
"h",
".",
"UnmarshalJSON",
"(",
"b",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"*",
"p",
"=",
"Protected",
"(",
"h",
")",
"\n",
"return",
"nil",
"\n",
"}"
] |
// UnmarshalJSON implements json.Unmarshaler for Protected.
|
[
"UnmarshalJSON",
"implements",
"json",
".",
"Unmarshaler",
"for",
"Protected",
"."
] |
803625baeddc3526d01d321b5066029f53eafc81
|
https://github.com/SermoDigital/jose/blob/803625baeddc3526d01d321b5066029f53eafc81/header.go#L110-L117
|
19,338
|
SermoDigital/jose
|
jwt/claims.go
|
MarshalJSON
|
func (c Claims) MarshalJSON() ([]byte, error) {
if c == nil || len(c) == 0 {
return nil, nil
}
return json.Marshal(map[string]interface{}(c))
}
|
go
|
func (c Claims) MarshalJSON() ([]byte, error) {
if c == nil || len(c) == 0 {
return nil, nil
}
return json.Marshal(map[string]interface{}(c))
}
|
[
"func",
"(",
"c",
"Claims",
")",
"MarshalJSON",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"if",
"c",
"==",
"nil",
"||",
"len",
"(",
"c",
")",
"==",
"0",
"{",
"return",
"nil",
",",
"nil",
"\n",
"}",
"\n",
"return",
"json",
".",
"Marshal",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"(",
"c",
")",
")",
"\n",
"}"
] |
// MarshalJSON implements json.Marshaler for Claims.
|
[
"MarshalJSON",
"implements",
"json",
".",
"Marshaler",
"for",
"Claims",
"."
] |
803625baeddc3526d01d321b5066029f53eafc81
|
https://github.com/SermoDigital/jose/blob/803625baeddc3526d01d321b5066029f53eafc81/jwt/claims.go#L56-L61
|
19,339
|
SermoDigital/jose
|
jwt/claims.go
|
Base64
|
func (c Claims) Base64() ([]byte, error) {
b, err := c.MarshalJSON()
if err != nil {
return nil, err
}
return jose.Base64Encode(b), nil
}
|
go
|
func (c Claims) Base64() ([]byte, error) {
b, err := c.MarshalJSON()
if err != nil {
return nil, err
}
return jose.Base64Encode(b), nil
}
|
[
"func",
"(",
"c",
"Claims",
")",
"Base64",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"b",
",",
"err",
":=",
"c",
".",
"MarshalJSON",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"jose",
".",
"Base64Encode",
"(",
"b",
")",
",",
"nil",
"\n",
"}"
] |
// Base64 implements the jose.Encoder interface.
|
[
"Base64",
"implements",
"the",
"jose",
".",
"Encoder",
"interface",
"."
] |
803625baeddc3526d01d321b5066029f53eafc81
|
https://github.com/SermoDigital/jose/blob/803625baeddc3526d01d321b5066029f53eafc81/jwt/claims.go#L64-L70
|
19,340
|
SermoDigital/jose
|
jwt/claims.go
|
SetTime
|
func (c Claims) SetTime(key string, t time.Time) {
c.Set(key, t.Unix())
}
|
go
|
func (c Claims) SetTime(key string, t time.Time) {
c.Set(key, t.Unix())
}
|
[
"func",
"(",
"c",
"Claims",
")",
"SetTime",
"(",
"key",
"string",
",",
"t",
"time",
".",
"Time",
")",
"{",
"c",
".",
"Set",
"(",
"key",
",",
"t",
".",
"Unix",
"(",
")",
")",
"\n",
"}"
] |
// SetTime stores a UNIX time for the given key.
|
[
"SetTime",
"stores",
"a",
"UNIX",
"time",
"for",
"the",
"given",
"key",
"."
] |
803625baeddc3526d01d321b5066029f53eafc81
|
https://github.com/SermoDigital/jose/blob/803625baeddc3526d01d321b5066029f53eafc81/jwt/claims.go#L267-L269
|
19,341
|
SermoDigital/jose
|
crypto/signature.go
|
UnmarshalJSON
|
func (s *Signature) UnmarshalJSON(b []byte) error {
dec, err := jose.DecodeEscaped(b)
if err != nil {
return err
}
*s = Signature(dec)
return nil
}
|
go
|
func (s *Signature) UnmarshalJSON(b []byte) error {
dec, err := jose.DecodeEscaped(b)
if err != nil {
return err
}
*s = Signature(dec)
return nil
}
|
[
"func",
"(",
"s",
"*",
"Signature",
")",
"UnmarshalJSON",
"(",
"b",
"[",
"]",
"byte",
")",
"error",
"{",
"dec",
",",
"err",
":=",
"jose",
".",
"DecodeEscaped",
"(",
"b",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"*",
"s",
"=",
"Signature",
"(",
"dec",
")",
"\n",
"return",
"nil",
"\n",
"}"
] |
// UnmarshalJSON implements json.Unmarshaler for signature.
|
[
"UnmarshalJSON",
"implements",
"json",
".",
"Unmarshaler",
"for",
"signature",
"."
] |
803625baeddc3526d01d321b5066029f53eafc81
|
https://github.com/SermoDigital/jose/blob/803625baeddc3526d01d321b5066029f53eafc81/crypto/signature.go#L23-L30
|
19,342
|
SermoDigital/jose
|
jws/jws_serialize.go
|
sign
|
func (j *jws) sign(keys ...interface{}) error {
if err := j.cache(); err != nil {
return err
}
if len(keys) < 1 ||
len(keys) > 1 && len(keys) != len(j.sb) {
return ErrNotEnoughKeys
}
if len(keys) == 1 {
k := keys[0]
keys = make([]interface{}, len(j.sb))
for i := range keys {
keys[i] = k
}
}
for i := range j.sb {
if err := j.sb[i].cache(); err != nil {
return err
}
raw := format(j.sb[i].Protected, j.plcache)
sig, err := j.sb[i].method.Sign(raw, keys[i])
if err != nil {
return err
}
j.sb[i].Signature = sig
}
return nil
}
|
go
|
func (j *jws) sign(keys ...interface{}) error {
if err := j.cache(); err != nil {
return err
}
if len(keys) < 1 ||
len(keys) > 1 && len(keys) != len(j.sb) {
return ErrNotEnoughKeys
}
if len(keys) == 1 {
k := keys[0]
keys = make([]interface{}, len(j.sb))
for i := range keys {
keys[i] = k
}
}
for i := range j.sb {
if err := j.sb[i].cache(); err != nil {
return err
}
raw := format(j.sb[i].Protected, j.plcache)
sig, err := j.sb[i].method.Sign(raw, keys[i])
if err != nil {
return err
}
j.sb[i].Signature = sig
}
return nil
}
|
[
"func",
"(",
"j",
"*",
"jws",
")",
"sign",
"(",
"keys",
"...",
"interface",
"{",
"}",
")",
"error",
"{",
"if",
"err",
":=",
"j",
".",
"cache",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"keys",
")",
"<",
"1",
"||",
"len",
"(",
"keys",
")",
">",
"1",
"&&",
"len",
"(",
"keys",
")",
"!=",
"len",
"(",
"j",
".",
"sb",
")",
"{",
"return",
"ErrNotEnoughKeys",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"keys",
")",
"==",
"1",
"{",
"k",
":=",
"keys",
"[",
"0",
"]",
"\n",
"keys",
"=",
"make",
"(",
"[",
"]",
"interface",
"{",
"}",
",",
"len",
"(",
"j",
".",
"sb",
")",
")",
"\n",
"for",
"i",
":=",
"range",
"keys",
"{",
"keys",
"[",
"i",
"]",
"=",
"k",
"\n",
"}",
"\n",
"}",
"\n\n",
"for",
"i",
":=",
"range",
"j",
".",
"sb",
"{",
"if",
"err",
":=",
"j",
".",
"sb",
"[",
"i",
"]",
".",
"cache",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"raw",
":=",
"format",
"(",
"j",
".",
"sb",
"[",
"i",
"]",
".",
"Protected",
",",
"j",
".",
"plcache",
")",
"\n",
"sig",
",",
"err",
":=",
"j",
".",
"sb",
"[",
"i",
"]",
".",
"method",
".",
"Sign",
"(",
"raw",
",",
"keys",
"[",
"i",
"]",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"j",
".",
"sb",
"[",
"i",
"]",
".",
"Signature",
"=",
"sig",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// sign signs each index of j's sb member.
|
[
"sign",
"signs",
"each",
"index",
"of",
"j",
"s",
"sb",
"member",
"."
] |
803625baeddc3526d01d321b5066029f53eafc81
|
https://github.com/SermoDigital/jose/blob/803625baeddc3526d01d321b5066029f53eafc81/jws/jws_serialize.go#L68-L100
|
19,343
|
SermoDigital/jose
|
jws/jws_serialize.go
|
cache
|
func (j *jws) cache() (err error) {
if !j.clean {
j.plcache, err = j.payload.Base64()
j.clean = err == nil
}
return err
}
|
go
|
func (j *jws) cache() (err error) {
if !j.clean {
j.plcache, err = j.payload.Base64()
j.clean = err == nil
}
return err
}
|
[
"func",
"(",
"j",
"*",
"jws",
")",
"cache",
"(",
")",
"(",
"err",
"error",
")",
"{",
"if",
"!",
"j",
".",
"clean",
"{",
"j",
".",
"plcache",
",",
"err",
"=",
"j",
".",
"payload",
".",
"Base64",
"(",
")",
"\n",
"j",
".",
"clean",
"=",
"err",
"==",
"nil",
"\n",
"}",
"\n",
"return",
"err",
"\n",
"}"
] |
// cache marshals the payload, but only if it's changed since the last cache.
|
[
"cache",
"marshals",
"the",
"payload",
"but",
"only",
"if",
"it",
"s",
"changed",
"since",
"the",
"last",
"cache",
"."
] |
803625baeddc3526d01d321b5066029f53eafc81
|
https://github.com/SermoDigital/jose/blob/803625baeddc3526d01d321b5066029f53eafc81/jws/jws_serialize.go#L103-L109
|
19,344
|
SermoDigital/jose
|
jws/jws_serialize.go
|
cache
|
func (s *sigHead) cache() (err error) {
if !s.clean {
s.Protected, err = s.protected.Base64()
if err != nil {
return err
}
s.Unprotected, err = s.unprotected.Base64()
if err != nil {
return err
}
}
s.clean = true
return nil
}
|
go
|
func (s *sigHead) cache() (err error) {
if !s.clean {
s.Protected, err = s.protected.Base64()
if err != nil {
return err
}
s.Unprotected, err = s.unprotected.Base64()
if err != nil {
return err
}
}
s.clean = true
return nil
}
|
[
"func",
"(",
"s",
"*",
"sigHead",
")",
"cache",
"(",
")",
"(",
"err",
"error",
")",
"{",
"if",
"!",
"s",
".",
"clean",
"{",
"s",
".",
"Protected",
",",
"err",
"=",
"s",
".",
"protected",
".",
"Base64",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"s",
".",
"Unprotected",
",",
"err",
"=",
"s",
".",
"unprotected",
".",
"Base64",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"s",
".",
"clean",
"=",
"true",
"\n",
"return",
"nil",
"\n",
"}"
] |
// cache marshals the protected and unprotected headers, but only if
// they've changed since their last cache.
|
[
"cache",
"marshals",
"the",
"protected",
"and",
"unprotected",
"headers",
"but",
"only",
"if",
"they",
"ve",
"changed",
"since",
"their",
"last",
"cache",
"."
] |
803625baeddc3526d01d321b5066029f53eafc81
|
https://github.com/SermoDigital/jose/blob/803625baeddc3526d01d321b5066029f53eafc81/jws/jws_serialize.go#L113-L126
|
19,345
|
SermoDigital/jose
|
jws/jws_validate.go
|
VerifyCallback
|
func (j *jws) VerifyCallback(fn VerifyCallback, methods []crypto.SigningMethod, o *SigningOpts) error {
keys, err := fn(j)
if err != nil {
return err
}
return j.VerifyMulti(keys, methods, o)
}
|
go
|
func (j *jws) VerifyCallback(fn VerifyCallback, methods []crypto.SigningMethod, o *SigningOpts) error {
keys, err := fn(j)
if err != nil {
return err
}
return j.VerifyMulti(keys, methods, o)
}
|
[
"func",
"(",
"j",
"*",
"jws",
")",
"VerifyCallback",
"(",
"fn",
"VerifyCallback",
",",
"methods",
"[",
"]",
"crypto",
".",
"SigningMethod",
",",
"o",
"*",
"SigningOpts",
")",
"error",
"{",
"keys",
",",
"err",
":=",
"fn",
"(",
"j",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"j",
".",
"VerifyMulti",
"(",
"keys",
",",
"methods",
",",
"o",
")",
"\n",
"}"
] |
// VerifyCallback validates the current JWS' signature as-is. It
// accepts a callback function that can be used to access header
// parameters to lookup needed information. For example, looking
// up the "kid" parameter.
// The return slice must be a slice of keys used in the verification
// of the JWS.
|
[
"VerifyCallback",
"validates",
"the",
"current",
"JWS",
"signature",
"as",
"-",
"is",
".",
"It",
"accepts",
"a",
"callback",
"function",
"that",
"can",
"be",
"used",
"to",
"access",
"header",
"parameters",
"to",
"lookup",
"needed",
"information",
".",
"For",
"example",
"looking",
"up",
"the",
"kid",
"parameter",
".",
"The",
"return",
"slice",
"must",
"be",
"a",
"slice",
"of",
"keys",
"used",
"in",
"the",
"verification",
"of",
"the",
"JWS",
"."
] |
803625baeddc3526d01d321b5066029f53eafc81
|
https://github.com/SermoDigital/jose/blob/803625baeddc3526d01d321b5066029f53eafc81/jws/jws_validate.go#L22-L28
|
19,346
|
SermoDigital/jose
|
jws/jws_validate.go
|
Error
|
func (m *MultiError) Error() string {
var s string
var n int
for _, err := range *m {
if err != nil {
if n == 0 {
s = err.Error()
}
n++
}
}
switch n {
case 0:
return ""
case 1:
return s
case 2:
return s + " and 1 other error"
}
return fmt.Sprintf("%s (and %d other errors)", s, n-1)
}
|
go
|
func (m *MultiError) Error() string {
var s string
var n int
for _, err := range *m {
if err != nil {
if n == 0 {
s = err.Error()
}
n++
}
}
switch n {
case 0:
return ""
case 1:
return s
case 2:
return s + " and 1 other error"
}
return fmt.Sprintf("%s (and %d other errors)", s, n-1)
}
|
[
"func",
"(",
"m",
"*",
"MultiError",
")",
"Error",
"(",
")",
"string",
"{",
"var",
"s",
"string",
"\n",
"var",
"n",
"int",
"\n",
"for",
"_",
",",
"err",
":=",
"range",
"*",
"m",
"{",
"if",
"err",
"!=",
"nil",
"{",
"if",
"n",
"==",
"0",
"{",
"s",
"=",
"err",
".",
"Error",
"(",
")",
"\n",
"}",
"\n",
"n",
"++",
"\n",
"}",
"\n",
"}",
"\n",
"switch",
"n",
"{",
"case",
"0",
":",
"return",
"\"",
"\"",
"\n",
"case",
"1",
":",
"return",
"s",
"\n",
"case",
"2",
":",
"return",
"s",
"+",
"\"",
"\"",
"\n",
"}",
"\n",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"s",
",",
"n",
"-",
"1",
")",
"\n",
"}"
] |
// Errors implements the error interface.
|
[
"Errors",
"implements",
"the",
"error",
"interface",
"."
] |
803625baeddc3526d01d321b5066029f53eafc81
|
https://github.com/SermoDigital/jose/blob/803625baeddc3526d01d321b5066029f53eafc81/jws/jws_validate.go#L40-L60
|
19,347
|
SermoDigital/jose
|
jws/jws_validate.go
|
VerifyMulti
|
func (j *jws) VerifyMulti(keys []interface{}, methods []crypto.SigningMethod, o *SigningOpts) error {
// Catch a simple mistake. Parameter o is irrelevant in this scenario.
if len(keys) == 1 &&
len(methods) == 1 &&
len(j.sb) == 1 {
return j.Verify(keys[0], methods[0])
}
if len(j.sb) != len(methods) {
return ErrNotEnoughMethods
}
if len(keys) < 1 ||
len(keys) > 1 && len(keys) != len(j.sb) {
return ErrNotEnoughKeys
}
// TODO do this better.
if len(keys) == 1 {
k := keys[0]
keys = make([]interface{}, len(methods))
for i := range keys {
keys[i] = k
}
}
var o2 SigningOpts
if o == nil {
o = new(SigningOpts)
}
var m MultiError
for i := range j.sb {
err := j.sb[i].verify(j.plcache, keys[i], methods[i])
if err != nil {
m = append(m, err)
} else {
o2.Inc()
if o.Needs(i) {
o.ptr++
o2.Append(i)
}
}
}
err := o.Validate(&o2)
if err != nil {
m = append(m, err)
}
if len(m) == 0 {
return nil
}
return &m
}
|
go
|
func (j *jws) VerifyMulti(keys []interface{}, methods []crypto.SigningMethod, o *SigningOpts) error {
// Catch a simple mistake. Parameter o is irrelevant in this scenario.
if len(keys) == 1 &&
len(methods) == 1 &&
len(j.sb) == 1 {
return j.Verify(keys[0], methods[0])
}
if len(j.sb) != len(methods) {
return ErrNotEnoughMethods
}
if len(keys) < 1 ||
len(keys) > 1 && len(keys) != len(j.sb) {
return ErrNotEnoughKeys
}
// TODO do this better.
if len(keys) == 1 {
k := keys[0]
keys = make([]interface{}, len(methods))
for i := range keys {
keys[i] = k
}
}
var o2 SigningOpts
if o == nil {
o = new(SigningOpts)
}
var m MultiError
for i := range j.sb {
err := j.sb[i].verify(j.plcache, keys[i], methods[i])
if err != nil {
m = append(m, err)
} else {
o2.Inc()
if o.Needs(i) {
o.ptr++
o2.Append(i)
}
}
}
err := o.Validate(&o2)
if err != nil {
m = append(m, err)
}
if len(m) == 0 {
return nil
}
return &m
}
|
[
"func",
"(",
"j",
"*",
"jws",
")",
"VerifyMulti",
"(",
"keys",
"[",
"]",
"interface",
"{",
"}",
",",
"methods",
"[",
"]",
"crypto",
".",
"SigningMethod",
",",
"o",
"*",
"SigningOpts",
")",
"error",
"{",
"// Catch a simple mistake. Parameter o is irrelevant in this scenario.",
"if",
"len",
"(",
"keys",
")",
"==",
"1",
"&&",
"len",
"(",
"methods",
")",
"==",
"1",
"&&",
"len",
"(",
"j",
".",
"sb",
")",
"==",
"1",
"{",
"return",
"j",
".",
"Verify",
"(",
"keys",
"[",
"0",
"]",
",",
"methods",
"[",
"0",
"]",
")",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"j",
".",
"sb",
")",
"!=",
"len",
"(",
"methods",
")",
"{",
"return",
"ErrNotEnoughMethods",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"keys",
")",
"<",
"1",
"||",
"len",
"(",
"keys",
")",
">",
"1",
"&&",
"len",
"(",
"keys",
")",
"!=",
"len",
"(",
"j",
".",
"sb",
")",
"{",
"return",
"ErrNotEnoughKeys",
"\n",
"}",
"\n\n",
"// TODO do this better.",
"if",
"len",
"(",
"keys",
")",
"==",
"1",
"{",
"k",
":=",
"keys",
"[",
"0",
"]",
"\n",
"keys",
"=",
"make",
"(",
"[",
"]",
"interface",
"{",
"}",
",",
"len",
"(",
"methods",
")",
")",
"\n",
"for",
"i",
":=",
"range",
"keys",
"{",
"keys",
"[",
"i",
"]",
"=",
"k",
"\n",
"}",
"\n",
"}",
"\n\n",
"var",
"o2",
"SigningOpts",
"\n",
"if",
"o",
"==",
"nil",
"{",
"o",
"=",
"new",
"(",
"SigningOpts",
")",
"\n",
"}",
"\n\n",
"var",
"m",
"MultiError",
"\n",
"for",
"i",
":=",
"range",
"j",
".",
"sb",
"{",
"err",
":=",
"j",
".",
"sb",
"[",
"i",
"]",
".",
"verify",
"(",
"j",
".",
"plcache",
",",
"keys",
"[",
"i",
"]",
",",
"methods",
"[",
"i",
"]",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"m",
"=",
"append",
"(",
"m",
",",
"err",
")",
"\n",
"}",
"else",
"{",
"o2",
".",
"Inc",
"(",
")",
"\n",
"if",
"o",
".",
"Needs",
"(",
"i",
")",
"{",
"o",
".",
"ptr",
"++",
"\n",
"o2",
".",
"Append",
"(",
"i",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"err",
":=",
"o",
".",
"Validate",
"(",
"&",
"o2",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"m",
"=",
"append",
"(",
"m",
",",
"err",
")",
"\n",
"}",
"\n",
"if",
"len",
"(",
"m",
")",
"==",
"0",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"&",
"m",
"\n",
"}"
] |
// VerifyMulti verifies the current JWS as-is. Since it's meant to be
// called after parsing a stream of bytes into a JWS, it doesn't do any
// internal parsing like the Sign, Flat, Compact, or General methods do.
|
[
"VerifyMulti",
"verifies",
"the",
"current",
"JWS",
"as",
"-",
"is",
".",
"Since",
"it",
"s",
"meant",
"to",
"be",
"called",
"after",
"parsing",
"a",
"stream",
"of",
"bytes",
"into",
"a",
"JWS",
"it",
"doesn",
"t",
"do",
"any",
"internal",
"parsing",
"like",
"the",
"Sign",
"Flat",
"Compact",
"or",
"General",
"methods",
"do",
"."
] |
803625baeddc3526d01d321b5066029f53eafc81
|
https://github.com/SermoDigital/jose/blob/803625baeddc3526d01d321b5066029f53eafc81/jws/jws_validate.go#L69-L123
|
19,348
|
SermoDigital/jose
|
jws/jws_validate.go
|
Append
|
func (s *SigningOpts) Append(x int) {
s.Indices = append(s.Indices, x)
}
|
go
|
func (s *SigningOpts) Append(x int) {
s.Indices = append(s.Indices, x)
}
|
[
"func",
"(",
"s",
"*",
"SigningOpts",
")",
"Append",
"(",
"x",
"int",
")",
"{",
"s",
".",
"Indices",
"=",
"append",
"(",
"s",
".",
"Indices",
",",
"x",
")",
"\n",
"}"
] |
// Append appends x to s' Indices member.
|
[
"Append",
"appends",
"x",
"to",
"s",
"Indices",
"member",
"."
] |
803625baeddc3526d01d321b5066029f53eafc81
|
https://github.com/SermoDigital/jose/blob/803625baeddc3526d01d321b5066029f53eafc81/jws/jws_validate.go#L151-L153
|
19,349
|
SermoDigital/jose
|
jws/jws_validate.go
|
Needs
|
func (s *SigningOpts) Needs(x int) bool {
return s.ptr < len(s.Indices) && s.Indices[s.ptr] == x
}
|
go
|
func (s *SigningOpts) Needs(x int) bool {
return s.ptr < len(s.Indices) && s.Indices[s.ptr] == x
}
|
[
"func",
"(",
"s",
"*",
"SigningOpts",
")",
"Needs",
"(",
"x",
"int",
")",
"bool",
"{",
"return",
"s",
".",
"ptr",
"<",
"len",
"(",
"s",
".",
"Indices",
")",
"&&",
"s",
".",
"Indices",
"[",
"s",
".",
"ptr",
"]",
"==",
"x",
"\n",
"}"
] |
// Needs returns true if x resides inside s' Indices member
// for the given index. It's used to match two SigningOpts Indices members.
|
[
"Needs",
"returns",
"true",
"if",
"x",
"resides",
"inside",
"s",
"Indices",
"member",
"for",
"the",
"given",
"index",
".",
"It",
"s",
"used",
"to",
"match",
"two",
"SigningOpts",
"Indices",
"members",
"."
] |
803625baeddc3526d01d321b5066029f53eafc81
|
https://github.com/SermoDigital/jose/blob/803625baeddc3526d01d321b5066029f53eafc81/jws/jws_validate.go#L157-L159
|
19,350
|
SermoDigital/jose
|
jws/jws_validate.go
|
Validate
|
func (s *SigningOpts) Validate(have *SigningOpts) error {
if have.Number < s.Number ||
(s.Indices != nil &&
!eq(s.Indices, have.Indices)) {
return ErrNotEnoughValidSignatures
}
return nil
}
|
go
|
func (s *SigningOpts) Validate(have *SigningOpts) error {
if have.Number < s.Number ||
(s.Indices != nil &&
!eq(s.Indices, have.Indices)) {
return ErrNotEnoughValidSignatures
}
return nil
}
|
[
"func",
"(",
"s",
"*",
"SigningOpts",
")",
"Validate",
"(",
"have",
"*",
"SigningOpts",
")",
"error",
"{",
"if",
"have",
".",
"Number",
"<",
"s",
".",
"Number",
"||",
"(",
"s",
".",
"Indices",
"!=",
"nil",
"&&",
"!",
"eq",
"(",
"s",
".",
"Indices",
",",
"have",
".",
"Indices",
")",
")",
"{",
"return",
"ErrNotEnoughValidSignatures",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// Validate returns any errors found while validating the
// provided SigningOpts. The receiver validates |have|.
// It'll return an error if the passed SigningOpts' Number member is less
// than s' or if the passed SigningOpts' Indices slice isn't equal to s'.
|
[
"Validate",
"returns",
"any",
"errors",
"found",
"while",
"validating",
"the",
"provided",
"SigningOpts",
".",
"The",
"receiver",
"validates",
"|have|",
".",
"It",
"ll",
"return",
"an",
"error",
"if",
"the",
"passed",
"SigningOpts",
"Number",
"member",
"is",
"less",
"than",
"s",
"or",
"if",
"the",
"passed",
"SigningOpts",
"Indices",
"slice",
"isn",
"t",
"equal",
"to",
"s",
"."
] |
803625baeddc3526d01d321b5066029f53eafc81
|
https://github.com/SermoDigital/jose/blob/803625baeddc3526d01d321b5066029f53eafc81/jws/jws_validate.go#L168-L175
|
19,351
|
SermoDigital/jose
|
jws/jws_validate.go
|
Verify
|
func (j *jws) Verify(key interface{}, method crypto.SigningMethod) error {
if len(j.sb) < 1 {
return ErrCannotValidate
}
return j.sb[0].verify(j.plcache, key, method)
}
|
go
|
func (j *jws) Verify(key interface{}, method crypto.SigningMethod) error {
if len(j.sb) < 1 {
return ErrCannotValidate
}
return j.sb[0].verify(j.plcache, key, method)
}
|
[
"func",
"(",
"j",
"*",
"jws",
")",
"Verify",
"(",
"key",
"interface",
"{",
"}",
",",
"method",
"crypto",
".",
"SigningMethod",
")",
"error",
"{",
"if",
"len",
"(",
"j",
".",
"sb",
")",
"<",
"1",
"{",
"return",
"ErrCannotValidate",
"\n",
"}",
"\n",
"return",
"j",
".",
"sb",
"[",
"0",
"]",
".",
"verify",
"(",
"j",
".",
"plcache",
",",
"key",
",",
"method",
")",
"\n",
"}"
] |
// Verify verifies the current JWS as-is. Refer to verifyMulti
// for more information.
|
[
"Verify",
"verifies",
"the",
"current",
"JWS",
"as",
"-",
"is",
".",
"Refer",
"to",
"verifyMulti",
"for",
"more",
"information",
"."
] |
803625baeddc3526d01d321b5066029f53eafc81
|
https://github.com/SermoDigital/jose/blob/803625baeddc3526d01d321b5066029f53eafc81/jws/jws_validate.go#L191-L196
|
19,352
|
SermoDigital/jose
|
crypto/none.go
|
Verify
|
func (_ *SigningMethodNone) Verify(_ []byte, _ Signature, _ interface{}) error {
return nil
}
|
go
|
func (_ *SigningMethodNone) Verify(_ []byte, _ Signature, _ interface{}) error {
return nil
}
|
[
"func",
"(",
"_",
"*",
"SigningMethodNone",
")",
"Verify",
"(",
"_",
"[",
"]",
"byte",
",",
"_",
"Signature",
",",
"_",
"interface",
"{",
"}",
")",
"error",
"{",
"return",
"nil",
"\n",
"}"
] |
// Verify helps implement the SigningMethod interface.
|
[
"Verify",
"helps",
"implement",
"the",
"SigningMethod",
"interface",
"."
] |
803625baeddc3526d01d321b5066029f53eafc81
|
https://github.com/SermoDigital/jose/blob/803625baeddc3526d01d321b5066029f53eafc81/crypto/none.go#L47-L49
|
19,353
|
SermoDigital/jose
|
crypto/none.go
|
Sign
|
func (_ *SigningMethodNone) Sign(_ []byte, _ interface{}) (Signature, error) {
return nil, nil
}
|
go
|
func (_ *SigningMethodNone) Sign(_ []byte, _ interface{}) (Signature, error) {
return nil, nil
}
|
[
"func",
"(",
"_",
"*",
"SigningMethodNone",
")",
"Sign",
"(",
"_",
"[",
"]",
"byte",
",",
"_",
"interface",
"{",
"}",
")",
"(",
"Signature",
",",
"error",
")",
"{",
"return",
"nil",
",",
"nil",
"\n",
"}"
] |
// Sign helps implement the SigningMethod interface.
|
[
"Sign",
"helps",
"implement",
"the",
"SigningMethod",
"interface",
"."
] |
803625baeddc3526d01d321b5066029f53eafc81
|
https://github.com/SermoDigital/jose/blob/803625baeddc3526d01d321b5066029f53eafc81/crypto/none.go#L52-L54
|
19,354
|
SermoDigital/jose
|
base64.go
|
Base64Decode
|
func Base64Decode(b []byte) ([]byte, error) {
buf := make([]byte, base64.RawURLEncoding.DecodedLen(len(b)))
n, err := base64.RawURLEncoding.Decode(buf, b)
return buf[:n], err
}
|
go
|
func Base64Decode(b []byte) ([]byte, error) {
buf := make([]byte, base64.RawURLEncoding.DecodedLen(len(b)))
n, err := base64.RawURLEncoding.Decode(buf, b)
return buf[:n], err
}
|
[
"func",
"Base64Decode",
"(",
"b",
"[",
"]",
"byte",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"buf",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"base64",
".",
"RawURLEncoding",
".",
"DecodedLen",
"(",
"len",
"(",
"b",
")",
")",
")",
"\n",
"n",
",",
"err",
":=",
"base64",
".",
"RawURLEncoding",
".",
"Decode",
"(",
"buf",
",",
"b",
")",
"\n",
"return",
"buf",
"[",
":",
"n",
"]",
",",
"err",
"\n",
"}"
] |
// Base64Decode decodes a base64-encoded byte slice.
|
[
"Base64Decode",
"decodes",
"a",
"base64",
"-",
"encoded",
"byte",
"slice",
"."
] |
803625baeddc3526d01d321b5066029f53eafc81
|
https://github.com/SermoDigital/jose/blob/803625baeddc3526d01d321b5066029f53eafc81/base64.go#L13-L17
|
19,355
|
SermoDigital/jose
|
base64.go
|
Base64Encode
|
func Base64Encode(b []byte) []byte {
buf := make([]byte, base64.RawURLEncoding.EncodedLen(len(b)))
base64.RawURLEncoding.Encode(buf, b)
return buf
}
|
go
|
func Base64Encode(b []byte) []byte {
buf := make([]byte, base64.RawURLEncoding.EncodedLen(len(b)))
base64.RawURLEncoding.Encode(buf, b)
return buf
}
|
[
"func",
"Base64Encode",
"(",
"b",
"[",
"]",
"byte",
")",
"[",
"]",
"byte",
"{",
"buf",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"base64",
".",
"RawURLEncoding",
".",
"EncodedLen",
"(",
"len",
"(",
"b",
")",
")",
")",
"\n",
"base64",
".",
"RawURLEncoding",
".",
"Encode",
"(",
"buf",
",",
"b",
")",
"\n",
"return",
"buf",
"\n",
"}"
] |
// Base64Encode encodes a byte slice.
|
[
"Base64Encode",
"encodes",
"a",
"byte",
"slice",
"."
] |
803625baeddc3526d01d321b5066029f53eafc81
|
https://github.com/SermoDigital/jose/blob/803625baeddc3526d01d321b5066029f53eafc81/base64.go#L20-L24
|
19,356
|
SermoDigital/jose
|
jws/rawbase64.go
|
MarshalJSON
|
func (r rawBase64) MarshalJSON() ([]byte, error) {
buf := make([]byte, len(r)+2)
buf[0] = '"'
copy(buf[1:], r)
buf[len(buf)-1] = '"'
return buf, nil
}
|
go
|
func (r rawBase64) MarshalJSON() ([]byte, error) {
buf := make([]byte, len(r)+2)
buf[0] = '"'
copy(buf[1:], r)
buf[len(buf)-1] = '"'
return buf, nil
}
|
[
"func",
"(",
"r",
"rawBase64",
")",
"MarshalJSON",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"buf",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"len",
"(",
"r",
")",
"+",
"2",
")",
"\n",
"buf",
"[",
"0",
"]",
"=",
"'\"'",
"\n",
"copy",
"(",
"buf",
"[",
"1",
":",
"]",
",",
"r",
")",
"\n",
"buf",
"[",
"len",
"(",
"buf",
")",
"-",
"1",
"]",
"=",
"'\"'",
"\n",
"return",
"buf",
",",
"nil",
"\n",
"}"
] |
// MarshalJSON implements json.Marshaler for rawBase64.
|
[
"MarshalJSON",
"implements",
"json",
".",
"Marshaler",
"for",
"rawBase64",
"."
] |
803625baeddc3526d01d321b5066029f53eafc81
|
https://github.com/SermoDigital/jose/blob/803625baeddc3526d01d321b5066029f53eafc81/jws/rawbase64.go#L8-L14
|
19,357
|
SermoDigital/jose
|
jws/rawbase64.go
|
UnmarshalJSON
|
func (r *rawBase64) UnmarshalJSON(b []byte) error {
if len(b) > 1 && b[0] == '"' && b[len(b)-1] == '"' {
b = b[1 : len(b)-1]
}
*r = rawBase64(b)
return nil
}
|
go
|
func (r *rawBase64) UnmarshalJSON(b []byte) error {
if len(b) > 1 && b[0] == '"' && b[len(b)-1] == '"' {
b = b[1 : len(b)-1]
}
*r = rawBase64(b)
return nil
}
|
[
"func",
"(",
"r",
"*",
"rawBase64",
")",
"UnmarshalJSON",
"(",
"b",
"[",
"]",
"byte",
")",
"error",
"{",
"if",
"len",
"(",
"b",
")",
">",
"1",
"&&",
"b",
"[",
"0",
"]",
"==",
"'\"'",
"&&",
"b",
"[",
"len",
"(",
"b",
")",
"-",
"1",
"]",
"==",
"'\"'",
"{",
"b",
"=",
"b",
"[",
"1",
":",
"len",
"(",
"b",
")",
"-",
"1",
"]",
"\n",
"}",
"\n",
"*",
"r",
"=",
"rawBase64",
"(",
"b",
")",
"\n",
"return",
"nil",
"\n",
"}"
] |
// MarshalJSON implements json.Unmarshaler for rawBase64.
|
[
"MarshalJSON",
"implements",
"json",
".",
"Unmarshaler",
"for",
"rawBase64",
"."
] |
803625baeddc3526d01d321b5066029f53eafc81
|
https://github.com/SermoDigital/jose/blob/803625baeddc3526d01d321b5066029f53eafc81/jws/rawbase64.go#L17-L23
|
19,358
|
SermoDigital/jose
|
jws/signing_methods.go
|
RegisterSigningMethod
|
func RegisterSigningMethod(sm crypto.SigningMethod) {
alg := sm.Alg()
if GetSigningMethod(alg) != nil {
panic("jose/jws: cannot duplicate signing methods")
}
if !sm.Hasher().Available() {
panic("jose/jws: specific hash is unavailable")
}
mu.Lock()
signingMethods[alg] = sm
mu.Unlock()
}
|
go
|
func RegisterSigningMethod(sm crypto.SigningMethod) {
alg := sm.Alg()
if GetSigningMethod(alg) != nil {
panic("jose/jws: cannot duplicate signing methods")
}
if !sm.Hasher().Available() {
panic("jose/jws: specific hash is unavailable")
}
mu.Lock()
signingMethods[alg] = sm
mu.Unlock()
}
|
[
"func",
"RegisterSigningMethod",
"(",
"sm",
"crypto",
".",
"SigningMethod",
")",
"{",
"alg",
":=",
"sm",
".",
"Alg",
"(",
")",
"\n",
"if",
"GetSigningMethod",
"(",
"alg",
")",
"!=",
"nil",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"!",
"sm",
".",
"Hasher",
"(",
")",
".",
"Available",
"(",
")",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"mu",
".",
"Lock",
"(",
")",
"\n",
"signingMethods",
"[",
"alg",
"]",
"=",
"sm",
"\n",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"}"
] |
// RegisterSigningMethod registers the crypto.SigningMethod in the global map.
// This is typically done inside the caller's init function.
|
[
"RegisterSigningMethod",
"registers",
"the",
"crypto",
".",
"SigningMethod",
"in",
"the",
"global",
"map",
".",
"This",
"is",
"typically",
"done",
"inside",
"the",
"caller",
"s",
"init",
"function",
"."
] |
803625baeddc3526d01d321b5066029f53eafc81
|
https://github.com/SermoDigital/jose/blob/803625baeddc3526d01d321b5066029f53eafc81/jws/signing_methods.go#L35-L48
|
19,359
|
SermoDigital/jose
|
jws/signing_methods.go
|
RemoveSigningMethod
|
func RemoveSigningMethod(sm crypto.SigningMethod) {
mu.Lock()
delete(signingMethods, sm.Alg())
mu.Unlock()
}
|
go
|
func RemoveSigningMethod(sm crypto.SigningMethod) {
mu.Lock()
delete(signingMethods, sm.Alg())
mu.Unlock()
}
|
[
"func",
"RemoveSigningMethod",
"(",
"sm",
"crypto",
".",
"SigningMethod",
")",
"{",
"mu",
".",
"Lock",
"(",
")",
"\n",
"delete",
"(",
"signingMethods",
",",
"sm",
".",
"Alg",
"(",
")",
")",
"\n",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"}"
] |
// RemoveSigningMethod removes the crypto.SigningMethod from the global map.
|
[
"RemoveSigningMethod",
"removes",
"the",
"crypto",
".",
"SigningMethod",
"from",
"the",
"global",
"map",
"."
] |
803625baeddc3526d01d321b5066029f53eafc81
|
https://github.com/SermoDigital/jose/blob/803625baeddc3526d01d321b5066029f53eafc81/jws/signing_methods.go#L51-L55
|
19,360
|
SermoDigital/jose
|
jws/signing_methods.go
|
GetSigningMethod
|
func GetSigningMethod(alg string) (method crypto.SigningMethod) {
mu.RLock()
method = signingMethods[alg]
mu.RUnlock()
return method
}
|
go
|
func GetSigningMethod(alg string) (method crypto.SigningMethod) {
mu.RLock()
method = signingMethods[alg]
mu.RUnlock()
return method
}
|
[
"func",
"GetSigningMethod",
"(",
"alg",
"string",
")",
"(",
"method",
"crypto",
".",
"SigningMethod",
")",
"{",
"mu",
".",
"RLock",
"(",
")",
"\n",
"method",
"=",
"signingMethods",
"[",
"alg",
"]",
"\n",
"mu",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"method",
"\n",
"}"
] |
// GetSigningMethod retrieves a crypto.SigningMethod from the global map.
|
[
"GetSigningMethod",
"retrieves",
"a",
"crypto",
".",
"SigningMethod",
"from",
"the",
"global",
"map",
"."
] |
803625baeddc3526d01d321b5066029f53eafc81
|
https://github.com/SermoDigital/jose/blob/803625baeddc3526d01d321b5066029f53eafc81/jws/signing_methods.go#L58-L63
|
19,361
|
SermoDigital/jose
|
jws/jwt.go
|
NewJWT
|
func NewJWT(claims Claims, method crypto.SigningMethod) jwt.JWT {
j, ok := New(claims, method).(*jws)
if !ok {
panic("jws.NewJWT: runtime panic: New(...).(*jws) != true")
}
j.sb[0].protected.Set("typ", "JWT")
j.isJWT = true
return j
}
|
go
|
func NewJWT(claims Claims, method crypto.SigningMethod) jwt.JWT {
j, ok := New(claims, method).(*jws)
if !ok {
panic("jws.NewJWT: runtime panic: New(...).(*jws) != true")
}
j.sb[0].protected.Set("typ", "JWT")
j.isJWT = true
return j
}
|
[
"func",
"NewJWT",
"(",
"claims",
"Claims",
",",
"method",
"crypto",
".",
"SigningMethod",
")",
"jwt",
".",
"JWT",
"{",
"j",
",",
"ok",
":=",
"New",
"(",
"claims",
",",
"method",
")",
".",
"(",
"*",
"jws",
")",
"\n",
"if",
"!",
"ok",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"j",
".",
"sb",
"[",
"0",
"]",
".",
"protected",
".",
"Set",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"j",
".",
"isJWT",
"=",
"true",
"\n",
"return",
"j",
"\n",
"}"
] |
// NewJWT creates a new JWT with the given claims.
|
[
"NewJWT",
"creates",
"a",
"new",
"JWT",
"with",
"the",
"given",
"claims",
"."
] |
803625baeddc3526d01d321b5066029f53eafc81
|
https://github.com/SermoDigital/jose/blob/803625baeddc3526d01d321b5066029f53eafc81/jws/jwt.go#L13-L21
|
19,362
|
SermoDigital/jose
|
jws/jwt.go
|
Serialize
|
func (j *jws) Serialize(key interface{}) ([]byte, error) {
if j.isJWT {
return j.Compact(key)
}
return nil, ErrIsNotJWT
}
|
go
|
func (j *jws) Serialize(key interface{}) ([]byte, error) {
if j.isJWT {
return j.Compact(key)
}
return nil, ErrIsNotJWT
}
|
[
"func",
"(",
"j",
"*",
"jws",
")",
"Serialize",
"(",
"key",
"interface",
"{",
"}",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"if",
"j",
".",
"isJWT",
"{",
"return",
"j",
".",
"Compact",
"(",
"key",
")",
"\n",
"}",
"\n",
"return",
"nil",
",",
"ErrIsNotJWT",
"\n",
"}"
] |
// Serialize helps implements jwt.JWT.
|
[
"Serialize",
"helps",
"implements",
"jwt",
".",
"JWT",
"."
] |
803625baeddc3526d01d321b5066029f53eafc81
|
https://github.com/SermoDigital/jose/blob/803625baeddc3526d01d321b5066029f53eafc81/jws/jwt.go#L24-L29
|
19,363
|
SermoDigital/jose
|
jws/jwt.go
|
Claims
|
func (j *jws) Claims() jwt.Claims {
if j.isJWT {
if c, ok := j.payload.v.(Claims); ok {
return jwt.Claims(c)
}
}
return nil
}
|
go
|
func (j *jws) Claims() jwt.Claims {
if j.isJWT {
if c, ok := j.payload.v.(Claims); ok {
return jwt.Claims(c)
}
}
return nil
}
|
[
"func",
"(",
"j",
"*",
"jws",
")",
"Claims",
"(",
")",
"jwt",
".",
"Claims",
"{",
"if",
"j",
".",
"isJWT",
"{",
"if",
"c",
",",
"ok",
":=",
"j",
".",
"payload",
".",
"v",
".",
"(",
"Claims",
")",
";",
"ok",
"{",
"return",
"jwt",
".",
"Claims",
"(",
"c",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// Claims helps implements jwt.JWT.
|
[
"Claims",
"helps",
"implements",
"jwt",
".",
"JWT",
"."
] |
803625baeddc3526d01d321b5066029f53eafc81
|
https://github.com/SermoDigital/jose/blob/803625baeddc3526d01d321b5066029f53eafc81/jws/jwt.go#L32-L39
|
19,364
|
SermoDigital/jose
|
jws/jwt.go
|
ParseJWTFromRequest
|
func ParseJWTFromRequest(req *http.Request) (jwt.JWT, error) {
if b, ok := fromHeader(req); ok {
return ParseJWT(b)
}
if b, ok := fromForm(req); ok {
return ParseJWT(b)
}
return nil, ErrNoTokenInRequest
}
|
go
|
func ParseJWTFromRequest(req *http.Request) (jwt.JWT, error) {
if b, ok := fromHeader(req); ok {
return ParseJWT(b)
}
if b, ok := fromForm(req); ok {
return ParseJWT(b)
}
return nil, ErrNoTokenInRequest
}
|
[
"func",
"ParseJWTFromRequest",
"(",
"req",
"*",
"http",
".",
"Request",
")",
"(",
"jwt",
".",
"JWT",
",",
"error",
")",
"{",
"if",
"b",
",",
"ok",
":=",
"fromHeader",
"(",
"req",
")",
";",
"ok",
"{",
"return",
"ParseJWT",
"(",
"b",
")",
"\n",
"}",
"\n",
"if",
"b",
",",
"ok",
":=",
"fromForm",
"(",
"req",
")",
";",
"ok",
"{",
"return",
"ParseJWT",
"(",
"b",
")",
"\n",
"}",
"\n",
"return",
"nil",
",",
"ErrNoTokenInRequest",
"\n",
"}"
] |
// ParseJWTFromRequest tries to find the JWT in an http.Request.
// This method will call ParseMultipartForm if there's no token in the header.
|
[
"ParseJWTFromRequest",
"tries",
"to",
"find",
"the",
"JWT",
"in",
"an",
"http",
".",
"Request",
".",
"This",
"method",
"will",
"call",
"ParseMultipartForm",
"if",
"there",
"s",
"no",
"token",
"in",
"the",
"header",
"."
] |
803625baeddc3526d01d321b5066029f53eafc81
|
https://github.com/SermoDigital/jose/blob/803625baeddc3526d01d321b5066029f53eafc81/jws/jwt.go#L43-L51
|
19,365
|
SermoDigital/jose
|
jws/jwt.go
|
NewValidator
|
func NewValidator(c Claims, exp, nbf time.Duration, fn func(Claims) error) *jwt.Validator {
return &jwt.Validator{
Expected: jwt.Claims(c),
EXP: exp,
NBF: nbf,
Fn: Conv(fn),
}
}
|
go
|
func NewValidator(c Claims, exp, nbf time.Duration, fn func(Claims) error) *jwt.Validator {
return &jwt.Validator{
Expected: jwt.Claims(c),
EXP: exp,
NBF: nbf,
Fn: Conv(fn),
}
}
|
[
"func",
"NewValidator",
"(",
"c",
"Claims",
",",
"exp",
",",
"nbf",
"time",
".",
"Duration",
",",
"fn",
"func",
"(",
"Claims",
")",
"error",
")",
"*",
"jwt",
".",
"Validator",
"{",
"return",
"&",
"jwt",
".",
"Validator",
"{",
"Expected",
":",
"jwt",
".",
"Claims",
"(",
"c",
")",
",",
"EXP",
":",
"exp",
",",
"NBF",
":",
"nbf",
",",
"Fn",
":",
"Conv",
"(",
"fn",
")",
",",
"}",
"\n",
"}"
] |
// NewValidator returns a jwt.Validator.
|
[
"NewValidator",
"returns",
"a",
"jwt",
".",
"Validator",
"."
] |
803625baeddc3526d01d321b5066029f53eafc81
|
https://github.com/SermoDigital/jose/blob/803625baeddc3526d01d321b5066029f53eafc81/jws/jwt.go#L106-L113
|
19,366
|
SermoDigital/jose
|
crypto/ecdsa_utils.go
|
ParseECPrivateKeyFromPEM
|
func ParseECPrivateKeyFromPEM(key []byte) (*ecdsa.PrivateKey, error) {
block, _ := pem.Decode(key)
if block == nil {
return nil, ErrKeyMustBePEMEncoded
}
return x509.ParseECPrivateKey(block.Bytes)
}
|
go
|
func ParseECPrivateKeyFromPEM(key []byte) (*ecdsa.PrivateKey, error) {
block, _ := pem.Decode(key)
if block == nil {
return nil, ErrKeyMustBePEMEncoded
}
return x509.ParseECPrivateKey(block.Bytes)
}
|
[
"func",
"ParseECPrivateKeyFromPEM",
"(",
"key",
"[",
"]",
"byte",
")",
"(",
"*",
"ecdsa",
".",
"PrivateKey",
",",
"error",
")",
"{",
"block",
",",
"_",
":=",
"pem",
".",
"Decode",
"(",
"key",
")",
"\n",
"if",
"block",
"==",
"nil",
"{",
"return",
"nil",
",",
"ErrKeyMustBePEMEncoded",
"\n",
"}",
"\n",
"return",
"x509",
".",
"ParseECPrivateKey",
"(",
"block",
".",
"Bytes",
")",
"\n",
"}"
] |
// ParseECPrivateKeyFromPEM will parse a PEM encoded EC Private
// Key Structure.
|
[
"ParseECPrivateKeyFromPEM",
"will",
"parse",
"a",
"PEM",
"encoded",
"EC",
"Private",
"Key",
"Structure",
"."
] |
803625baeddc3526d01d321b5066029f53eafc81
|
https://github.com/SermoDigital/jose/blob/803625baeddc3526d01d321b5066029f53eafc81/crypto/ecdsa_utils.go#L18-L24
|
19,367
|
SermoDigital/jose
|
crypto/ecdsa_utils.go
|
ParseECPublicKeyFromPEM
|
func ParseECPublicKeyFromPEM(key []byte) (*ecdsa.PublicKey, error) {
block, _ := pem.Decode(key)
if block == nil {
return nil, ErrKeyMustBePEMEncoded
}
parsedKey, err := x509.ParsePKIXPublicKey(block.Bytes)
if err != nil {
cert, err := x509.ParseCertificate(block.Bytes)
if err != nil {
return nil, err
}
parsedKey = cert.PublicKey
}
pkey, ok := parsedKey.(*ecdsa.PublicKey)
if !ok {
return nil, ErrNotECPublicKey
}
return pkey, nil
}
|
go
|
func ParseECPublicKeyFromPEM(key []byte) (*ecdsa.PublicKey, error) {
block, _ := pem.Decode(key)
if block == nil {
return nil, ErrKeyMustBePEMEncoded
}
parsedKey, err := x509.ParsePKIXPublicKey(block.Bytes)
if err != nil {
cert, err := x509.ParseCertificate(block.Bytes)
if err != nil {
return nil, err
}
parsedKey = cert.PublicKey
}
pkey, ok := parsedKey.(*ecdsa.PublicKey)
if !ok {
return nil, ErrNotECPublicKey
}
return pkey, nil
}
|
[
"func",
"ParseECPublicKeyFromPEM",
"(",
"key",
"[",
"]",
"byte",
")",
"(",
"*",
"ecdsa",
".",
"PublicKey",
",",
"error",
")",
"{",
"block",
",",
"_",
":=",
"pem",
".",
"Decode",
"(",
"key",
")",
"\n",
"if",
"block",
"==",
"nil",
"{",
"return",
"nil",
",",
"ErrKeyMustBePEMEncoded",
"\n",
"}",
"\n\n",
"parsedKey",
",",
"err",
":=",
"x509",
".",
"ParsePKIXPublicKey",
"(",
"block",
".",
"Bytes",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"cert",
",",
"err",
":=",
"x509",
".",
"ParseCertificate",
"(",
"block",
".",
"Bytes",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"parsedKey",
"=",
"cert",
".",
"PublicKey",
"\n",
"}",
"\n\n",
"pkey",
",",
"ok",
":=",
"parsedKey",
".",
"(",
"*",
"ecdsa",
".",
"PublicKey",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
",",
"ErrNotECPublicKey",
"\n",
"}",
"\n",
"return",
"pkey",
",",
"nil",
"\n",
"}"
] |
// ParseECPublicKeyFromPEM will parse a PEM encoded PKCS1 or PKCS8 public key
|
[
"ParseECPublicKeyFromPEM",
"will",
"parse",
"a",
"PEM",
"encoded",
"PKCS1",
"or",
"PKCS8",
"public",
"key"
] |
803625baeddc3526d01d321b5066029f53eafc81
|
https://github.com/SermoDigital/jose/blob/803625baeddc3526d01d321b5066029f53eafc81/crypto/ecdsa_utils.go#L27-L48
|
19,368
|
SermoDigital/jose
|
jws/jws.go
|
ProtectedAt
|
func (j *jws) ProtectedAt(i int) jose.Protected {
return j.sb[i].protected
}
|
go
|
func (j *jws) ProtectedAt(i int) jose.Protected {
return j.sb[i].protected
}
|
[
"func",
"(",
"j",
"*",
"jws",
")",
"ProtectedAt",
"(",
"i",
"int",
")",
"jose",
".",
"Protected",
"{",
"return",
"j",
".",
"sb",
"[",
"i",
"]",
".",
"protected",
"\n",
"}"
] |
// Protected returns the JWS' Protected Header.
// i represents the index of the Protected Header.
// Left empty, it defaults to 0.
|
[
"Protected",
"returns",
"the",
"JWS",
"Protected",
"Header",
".",
"i",
"represents",
"the",
"index",
"of",
"the",
"Protected",
"Header",
".",
"Left",
"empty",
"it",
"defaults",
"to",
"0",
"."
] |
803625baeddc3526d01d321b5066029f53eafc81
|
https://github.com/SermoDigital/jose/blob/803625baeddc3526d01d321b5066029f53eafc81/jws/jws.go#L98-L100
|
19,369
|
SermoDigital/jose
|
jws/jws.go
|
HeaderAt
|
func (j *jws) HeaderAt(i int) jose.Header {
return j.sb[i].unprotected
}
|
go
|
func (j *jws) HeaderAt(i int) jose.Header {
return j.sb[i].unprotected
}
|
[
"func",
"(",
"j",
"*",
"jws",
")",
"HeaderAt",
"(",
"i",
"int",
")",
"jose",
".",
"Header",
"{",
"return",
"j",
".",
"sb",
"[",
"i",
"]",
".",
"unprotected",
"\n",
"}"
] |
// HeaderAt returns the JWS' unprotected Header.
// |i| is the index of the unprotected Header.
|
[
"HeaderAt",
"returns",
"the",
"JWS",
"unprotected",
"Header",
".",
"|i|",
"is",
"the",
"index",
"of",
"the",
"unprotected",
"Header",
"."
] |
803625baeddc3526d01d321b5066029f53eafc81
|
https://github.com/SermoDigital/jose/blob/803625baeddc3526d01d321b5066029f53eafc81/jws/jws.go#L109-L111
|
19,370
|
SermoDigital/jose
|
jws/jws.go
|
New
|
func New(content interface{}, methods ...crypto.SigningMethod) JWS {
sb := make([]sigHead, len(methods))
for i := range methods {
sb[i] = sigHead{
protected: jose.Protected{
"alg": methods[i].Alg(),
},
unprotected: jose.Header{},
method: methods[i],
}
}
return &jws{
payload: &payload{v: content},
sb: sb,
}
}
|
go
|
func New(content interface{}, methods ...crypto.SigningMethod) JWS {
sb := make([]sigHead, len(methods))
for i := range methods {
sb[i] = sigHead{
protected: jose.Protected{
"alg": methods[i].Alg(),
},
unprotected: jose.Header{},
method: methods[i],
}
}
return &jws{
payload: &payload{v: content},
sb: sb,
}
}
|
[
"func",
"New",
"(",
"content",
"interface",
"{",
"}",
",",
"methods",
"...",
"crypto",
".",
"SigningMethod",
")",
"JWS",
"{",
"sb",
":=",
"make",
"(",
"[",
"]",
"sigHead",
",",
"len",
"(",
"methods",
")",
")",
"\n",
"for",
"i",
":=",
"range",
"methods",
"{",
"sb",
"[",
"i",
"]",
"=",
"sigHead",
"{",
"protected",
":",
"jose",
".",
"Protected",
"{",
"\"",
"\"",
":",
"methods",
"[",
"i",
"]",
".",
"Alg",
"(",
")",
",",
"}",
",",
"unprotected",
":",
"jose",
".",
"Header",
"{",
"}",
",",
"method",
":",
"methods",
"[",
"i",
"]",
",",
"}",
"\n",
"}",
"\n",
"return",
"&",
"jws",
"{",
"payload",
":",
"&",
"payload",
"{",
"v",
":",
"content",
"}",
",",
"sb",
":",
"sb",
",",
"}",
"\n",
"}"
] |
// New creates a JWS with the provided crypto.SigningMethods.
|
[
"New",
"creates",
"a",
"JWS",
"with",
"the",
"provided",
"crypto",
".",
"SigningMethods",
"."
] |
803625baeddc3526d01d321b5066029f53eafc81
|
https://github.com/SermoDigital/jose/blob/803625baeddc3526d01d321b5066029f53eafc81/jws/jws.go#L139-L154
|
19,371
|
SermoDigital/jose
|
jws/jws.go
|
ParseFromHeader
|
func ParseFromHeader(req *http.Request, format Format, u ...json.Unmarshaler) (JWS, error) {
if b, ok := fromHeader(req); ok {
return parseJumpTable[format](b, u...)
}
return nil, ErrNoTokenInRequest
}
|
go
|
func ParseFromHeader(req *http.Request, format Format, u ...json.Unmarshaler) (JWS, error) {
if b, ok := fromHeader(req); ok {
return parseJumpTable[format](b, u...)
}
return nil, ErrNoTokenInRequest
}
|
[
"func",
"ParseFromHeader",
"(",
"req",
"*",
"http",
".",
"Request",
",",
"format",
"Format",
",",
"u",
"...",
"json",
".",
"Unmarshaler",
")",
"(",
"JWS",
",",
"error",
")",
"{",
"if",
"b",
",",
"ok",
":=",
"fromHeader",
"(",
"req",
")",
";",
"ok",
"{",
"return",
"parseJumpTable",
"[",
"format",
"]",
"(",
"b",
",",
"u",
"...",
")",
"\n",
"}",
"\n",
"return",
"nil",
",",
"ErrNoTokenInRequest",
"\n",
"}"
] |
// ParseFromHeader tries to find the JWS in an http.Request header.
|
[
"ParseFromHeader",
"tries",
"to",
"find",
"the",
"JWS",
"in",
"an",
"http",
".",
"Request",
"header",
"."
] |
803625baeddc3526d01d321b5066029f53eafc81
|
https://github.com/SermoDigital/jose/blob/803625baeddc3526d01d321b5066029f53eafc81/jws/jws.go#L434-L439
|
19,372
|
SermoDigital/jose
|
jws/jws.go
|
ParseFromForm
|
func ParseFromForm(req *http.Request, format Format, u ...json.Unmarshaler) (JWS, error) {
if b, ok := fromForm(req); ok {
return parseJumpTable[format](b, u...)
}
return nil, ErrNoTokenInRequest
}
|
go
|
func ParseFromForm(req *http.Request, format Format, u ...json.Unmarshaler) (JWS, error) {
if b, ok := fromForm(req); ok {
return parseJumpTable[format](b, u...)
}
return nil, ErrNoTokenInRequest
}
|
[
"func",
"ParseFromForm",
"(",
"req",
"*",
"http",
".",
"Request",
",",
"format",
"Format",
",",
"u",
"...",
"json",
".",
"Unmarshaler",
")",
"(",
"JWS",
",",
"error",
")",
"{",
"if",
"b",
",",
"ok",
":=",
"fromForm",
"(",
"req",
")",
";",
"ok",
"{",
"return",
"parseJumpTable",
"[",
"format",
"]",
"(",
"b",
",",
"u",
"...",
")",
"\n",
"}",
"\n",
"return",
"nil",
",",
"ErrNoTokenInRequest",
"\n",
"}"
] |
// ParseFromForm tries to find the JWS in an http.Request form request.
|
[
"ParseFromForm",
"tries",
"to",
"find",
"the",
"JWS",
"in",
"an",
"http",
".",
"Request",
"form",
"request",
"."
] |
803625baeddc3526d01d321b5066029f53eafc81
|
https://github.com/SermoDigital/jose/blob/803625baeddc3526d01d321b5066029f53eafc81/jws/jws.go#L442-L447
|
19,373
|
SermoDigital/jose
|
jws/jws.go
|
ParseFromRequest
|
func ParseFromRequest(req *http.Request, format Format, u ...json.Unmarshaler) (JWS, error) {
token, err := ParseFromHeader(req, format, u...)
if err == nil {
return token, nil
}
token, err = ParseFromForm(req, format, u...)
if err == nil {
return token, nil
}
return nil, err
}
|
go
|
func ParseFromRequest(req *http.Request, format Format, u ...json.Unmarshaler) (JWS, error) {
token, err := ParseFromHeader(req, format, u...)
if err == nil {
return token, nil
}
token, err = ParseFromForm(req, format, u...)
if err == nil {
return token, nil
}
return nil, err
}
|
[
"func",
"ParseFromRequest",
"(",
"req",
"*",
"http",
".",
"Request",
",",
"format",
"Format",
",",
"u",
"...",
"json",
".",
"Unmarshaler",
")",
"(",
"JWS",
",",
"error",
")",
"{",
"token",
",",
"err",
":=",
"ParseFromHeader",
"(",
"req",
",",
"format",
",",
"u",
"...",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"return",
"token",
",",
"nil",
"\n",
"}",
"\n\n",
"token",
",",
"err",
"=",
"ParseFromForm",
"(",
"req",
",",
"format",
",",
"u",
"...",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"return",
"token",
",",
"nil",
"\n",
"}",
"\n\n",
"return",
"nil",
",",
"err",
"\n",
"}"
] |
// ParseFromRequest tries to find the JWS in an http.Request.
// This method will call ParseMultipartForm if there's no token in the header.
|
[
"ParseFromRequest",
"tries",
"to",
"find",
"the",
"JWS",
"in",
"an",
"http",
".",
"Request",
".",
"This",
"method",
"will",
"call",
"ParseMultipartForm",
"if",
"there",
"s",
"no",
"token",
"in",
"the",
"header",
"."
] |
803625baeddc3526d01d321b5066029f53eafc81
|
https://github.com/SermoDigital/jose/blob/803625baeddc3526d01d321b5066029f53eafc81/jws/jws.go#L451-L463
|
19,374
|
SermoDigital/jose
|
jws/jws.go
|
checkHeaders
|
func checkHeaders(a, b jose.Header) error {
if len(a)+len(b) == 0 {
return ErrTwoEmptyHeaders
}
for key := range a {
if b.Has(key) && !IgnoreDupes {
return ErrDuplicateHeaderParameter
}
}
return nil
}
|
go
|
func checkHeaders(a, b jose.Header) error {
if len(a)+len(b) == 0 {
return ErrTwoEmptyHeaders
}
for key := range a {
if b.Has(key) && !IgnoreDupes {
return ErrDuplicateHeaderParameter
}
}
return nil
}
|
[
"func",
"checkHeaders",
"(",
"a",
",",
"b",
"jose",
".",
"Header",
")",
"error",
"{",
"if",
"len",
"(",
"a",
")",
"+",
"len",
"(",
"b",
")",
"==",
"0",
"{",
"return",
"ErrTwoEmptyHeaders",
"\n",
"}",
"\n",
"for",
"key",
":=",
"range",
"a",
"{",
"if",
"b",
".",
"Has",
"(",
"key",
")",
"&&",
"!",
"IgnoreDupes",
"{",
"return",
"ErrDuplicateHeaderParameter",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// checkHeaders returns an error per the constraints described in
// IgnoreDupes' comment.
|
[
"checkHeaders",
"returns",
"an",
"error",
"per",
"the",
"constraints",
"described",
"in",
"IgnoreDupes",
"comment",
"."
] |
803625baeddc3526d01d321b5066029f53eafc81
|
https://github.com/SermoDigital/jose/blob/803625baeddc3526d01d321b5066029f53eafc81/jws/jws.go#L478-L488
|
19,375
|
SermoDigital/jose
|
jws/payload.go
|
MarshalJSON
|
func (p *payload) MarshalJSON() ([]byte, error) {
b, err := json.Marshal(p.v)
if err != nil {
return nil, err
}
return jose.EncodeEscape(b), nil
}
|
go
|
func (p *payload) MarshalJSON() ([]byte, error) {
b, err := json.Marshal(p.v)
if err != nil {
return nil, err
}
return jose.EncodeEscape(b), nil
}
|
[
"func",
"(",
"p",
"*",
"payload",
")",
"MarshalJSON",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"b",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"p",
".",
"v",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"jose",
".",
"EncodeEscape",
"(",
"b",
")",
",",
"nil",
"\n",
"}"
] |
// MarshalJSON implements json.Marshaler for payload.
|
[
"MarshalJSON",
"implements",
"json",
".",
"Marshaler",
"for",
"payload",
"."
] |
803625baeddc3526d01d321b5066029f53eafc81
|
https://github.com/SermoDigital/jose/blob/803625baeddc3526d01d321b5066029f53eafc81/jws/payload.go#L17-L23
|
19,376
|
SermoDigital/jose
|
jws/payload.go
|
Base64
|
func (p *payload) Base64() ([]byte, error) {
b, err := json.Marshal(p.v)
if err != nil {
return nil, err
}
return jose.Base64Encode(b), nil
}
|
go
|
func (p *payload) Base64() ([]byte, error) {
b, err := json.Marshal(p.v)
if err != nil {
return nil, err
}
return jose.Base64Encode(b), nil
}
|
[
"func",
"(",
"p",
"*",
"payload",
")",
"Base64",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"b",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"p",
".",
"v",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"jose",
".",
"Base64Encode",
"(",
"b",
")",
",",
"nil",
"\n",
"}"
] |
// Base64 implements jose.Encoder.
|
[
"Base64",
"implements",
"jose",
".",
"Encoder",
"."
] |
803625baeddc3526d01d321b5066029f53eafc81
|
https://github.com/SermoDigital/jose/blob/803625baeddc3526d01d321b5066029f53eafc81/jws/payload.go#L26-L32
|
19,377
|
SermoDigital/jose
|
jws/payload.go
|
UnmarshalJSON
|
func (p *payload) UnmarshalJSON(b []byte) error {
b2, err := jose.DecodeEscaped(b)
if err != nil {
return err
}
if p.u != nil {
err := p.u.UnmarshalJSON(b2)
p.v = p.u
return err
}
return json.Unmarshal(b2, &p.v)
}
|
go
|
func (p *payload) UnmarshalJSON(b []byte) error {
b2, err := jose.DecodeEscaped(b)
if err != nil {
return err
}
if p.u != nil {
err := p.u.UnmarshalJSON(b2)
p.v = p.u
return err
}
return json.Unmarshal(b2, &p.v)
}
|
[
"func",
"(",
"p",
"*",
"payload",
")",
"UnmarshalJSON",
"(",
"b",
"[",
"]",
"byte",
")",
"error",
"{",
"b2",
",",
"err",
":=",
"jose",
".",
"DecodeEscaped",
"(",
"b",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"p",
".",
"u",
"!=",
"nil",
"{",
"err",
":=",
"p",
".",
"u",
".",
"UnmarshalJSON",
"(",
"b2",
")",
"\n",
"p",
".",
"v",
"=",
"p",
".",
"u",
"\n",
"return",
"err",
"\n",
"}",
"\n",
"return",
"json",
".",
"Unmarshal",
"(",
"b2",
",",
"&",
"p",
".",
"v",
")",
"\n",
"}"
] |
// MarshalJSON implements json.Unmarshaler for payload.
|
[
"MarshalJSON",
"implements",
"json",
".",
"Unmarshaler",
"for",
"payload",
"."
] |
803625baeddc3526d01d321b5066029f53eafc81
|
https://github.com/SermoDigital/jose/blob/803625baeddc3526d01d321b5066029f53eafc81/jws/payload.go#L35-L46
|
19,378
|
SermoDigital/jose
|
jws/claims.go
|
Del
|
func (c Claims) Del(key string) {
jwt.Claims(c).Del(key)
}
|
go
|
func (c Claims) Del(key string) {
jwt.Claims(c).Del(key)
}
|
[
"func",
"(",
"c",
"Claims",
")",
"Del",
"(",
"key",
"string",
")",
"{",
"jwt",
".",
"Claims",
"(",
"c",
")",
".",
"Del",
"(",
"key",
")",
"\n",
"}"
] |
// Del removes the value that corresponds with key from the Claims.
|
[
"Del",
"removes",
"the",
"value",
"that",
"corresponds",
"with",
"key",
"from",
"the",
"Claims",
"."
] |
803625baeddc3526d01d321b5066029f53eafc81
|
https://github.com/SermoDigital/jose/blob/803625baeddc3526d01d321b5066029f53eafc81/jws/claims.go#L25-L27
|
19,379
|
SermoDigital/jose
|
jws/claims.go
|
UnmarshalJSON
|
func (c *Claims) UnmarshalJSON(b []byte) error {
if b == nil {
return nil
}
b, err := jose.DecodeEscaped(b)
if err != nil {
return err
}
// Since json.Unmarshal calls UnmarshalJSON,
// calling json.Unmarshal on *p would be infinitely recursive
// A temp variable is needed because &map[string]interface{}(*p) is
// invalid Go.
tmp := map[string]interface{}(*c)
if err = json.Unmarshal(b, &tmp); err != nil {
return err
}
*c = Claims(tmp)
return nil
}
|
go
|
func (c *Claims) UnmarshalJSON(b []byte) error {
if b == nil {
return nil
}
b, err := jose.DecodeEscaped(b)
if err != nil {
return err
}
// Since json.Unmarshal calls UnmarshalJSON,
// calling json.Unmarshal on *p would be infinitely recursive
// A temp variable is needed because &map[string]interface{}(*p) is
// invalid Go.
tmp := map[string]interface{}(*c)
if err = json.Unmarshal(b, &tmp); err != nil {
return err
}
*c = Claims(tmp)
return nil
}
|
[
"func",
"(",
"c",
"*",
"Claims",
")",
"UnmarshalJSON",
"(",
"b",
"[",
"]",
"byte",
")",
"error",
"{",
"if",
"b",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"b",
",",
"err",
":=",
"jose",
".",
"DecodeEscaped",
"(",
"b",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"// Since json.Unmarshal calls UnmarshalJSON,",
"// calling json.Unmarshal on *p would be infinitely recursive",
"// A temp variable is needed because &map[string]interface{}(*p) is",
"// invalid Go.",
"tmp",
":=",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"(",
"*",
"c",
")",
"\n",
"if",
"err",
"=",
"json",
".",
"Unmarshal",
"(",
"b",
",",
"&",
"tmp",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"*",
"c",
"=",
"Claims",
"(",
"tmp",
")",
"\n",
"return",
"nil",
"\n",
"}"
] |
// UnmarshalJSON implements json.Unmarshaler for Claims.
|
[
"UnmarshalJSON",
"implements",
"json",
".",
"Unmarshaler",
"for",
"Claims",
"."
] |
803625baeddc3526d01d321b5066029f53eafc81
|
https://github.com/SermoDigital/jose/blob/803625baeddc3526d01d321b5066029f53eafc81/jws/claims.go#L45-L66
|
19,380
|
go-ole/go-ole
|
variant.go
|
NewVariant
|
func NewVariant(vt VT, val int64) VARIANT {
return VARIANT{VT: vt, Val: val}
}
|
go
|
func NewVariant(vt VT, val int64) VARIANT {
return VARIANT{VT: vt, Val: val}
}
|
[
"func",
"NewVariant",
"(",
"vt",
"VT",
",",
"val",
"int64",
")",
"VARIANT",
"{",
"return",
"VARIANT",
"{",
"VT",
":",
"vt",
",",
"Val",
":",
"val",
"}",
"\n",
"}"
] |
// NewVariant returns new variant based on type and value.
|
[
"NewVariant",
"returns",
"new",
"variant",
"based",
"on",
"type",
"and",
"value",
"."
] |
97b6244175ae18ea6eef668034fd6565847501c9
|
https://github.com/go-ole/go-ole/blob/97b6244175ae18ea6eef668034fd6565847501c9/variant.go#L6-L8
|
19,381
|
go-ole/go-ole
|
variant.go
|
ToIUnknown
|
func (v *VARIANT) ToIUnknown() *IUnknown {
if v.VT != VT_UNKNOWN {
return nil
}
return (*IUnknown)(unsafe.Pointer(uintptr(v.Val)))
}
|
go
|
func (v *VARIANT) ToIUnknown() *IUnknown {
if v.VT != VT_UNKNOWN {
return nil
}
return (*IUnknown)(unsafe.Pointer(uintptr(v.Val)))
}
|
[
"func",
"(",
"v",
"*",
"VARIANT",
")",
"ToIUnknown",
"(",
")",
"*",
"IUnknown",
"{",
"if",
"v",
".",
"VT",
"!=",
"VT_UNKNOWN",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"(",
"*",
"IUnknown",
")",
"(",
"unsafe",
".",
"Pointer",
"(",
"uintptr",
"(",
"v",
".",
"Val",
")",
")",
")",
"\n",
"}"
] |
// ToIUnknown converts Variant to Unknown object.
|
[
"ToIUnknown",
"converts",
"Variant",
"to",
"Unknown",
"object",
"."
] |
97b6244175ae18ea6eef668034fd6565847501c9
|
https://github.com/go-ole/go-ole/blob/97b6244175ae18ea6eef668034fd6565847501c9/variant.go#L11-L16
|
19,382
|
go-ole/go-ole
|
variant.go
|
ToIDispatch
|
func (v *VARIANT) ToIDispatch() *IDispatch {
if v.VT != VT_DISPATCH {
return nil
}
return (*IDispatch)(unsafe.Pointer(uintptr(v.Val)))
}
|
go
|
func (v *VARIANT) ToIDispatch() *IDispatch {
if v.VT != VT_DISPATCH {
return nil
}
return (*IDispatch)(unsafe.Pointer(uintptr(v.Val)))
}
|
[
"func",
"(",
"v",
"*",
"VARIANT",
")",
"ToIDispatch",
"(",
")",
"*",
"IDispatch",
"{",
"if",
"v",
".",
"VT",
"!=",
"VT_DISPATCH",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"(",
"*",
"IDispatch",
")",
"(",
"unsafe",
".",
"Pointer",
"(",
"uintptr",
"(",
"v",
".",
"Val",
")",
")",
")",
"\n",
"}"
] |
// ToIDispatch converts variant to dispatch object.
|
[
"ToIDispatch",
"converts",
"variant",
"to",
"dispatch",
"object",
"."
] |
97b6244175ae18ea6eef668034fd6565847501c9
|
https://github.com/go-ole/go-ole/blob/97b6244175ae18ea6eef668034fd6565847501c9/variant.go#L19-L24
|
19,383
|
go-ole/go-ole
|
variant.go
|
ToArray
|
func (v *VARIANT) ToArray() *SafeArrayConversion {
if v.VT != VT_SAFEARRAY {
if v.VT&VT_ARRAY == 0 {
return nil
}
}
var safeArray *SafeArray = (*SafeArray)(unsafe.Pointer(uintptr(v.Val)))
return &SafeArrayConversion{safeArray}
}
|
go
|
func (v *VARIANT) ToArray() *SafeArrayConversion {
if v.VT != VT_SAFEARRAY {
if v.VT&VT_ARRAY == 0 {
return nil
}
}
var safeArray *SafeArray = (*SafeArray)(unsafe.Pointer(uintptr(v.Val)))
return &SafeArrayConversion{safeArray}
}
|
[
"func",
"(",
"v",
"*",
"VARIANT",
")",
"ToArray",
"(",
")",
"*",
"SafeArrayConversion",
"{",
"if",
"v",
".",
"VT",
"!=",
"VT_SAFEARRAY",
"{",
"if",
"v",
".",
"VT",
"&",
"VT_ARRAY",
"==",
"0",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"}",
"\n",
"var",
"safeArray",
"*",
"SafeArray",
"=",
"(",
"*",
"SafeArray",
")",
"(",
"unsafe",
".",
"Pointer",
"(",
"uintptr",
"(",
"v",
".",
"Val",
")",
")",
")",
"\n",
"return",
"&",
"SafeArrayConversion",
"{",
"safeArray",
"}",
"\n",
"}"
] |
// ToArray converts variant to SafeArray helper.
|
[
"ToArray",
"converts",
"variant",
"to",
"SafeArray",
"helper",
"."
] |
97b6244175ae18ea6eef668034fd6565847501c9
|
https://github.com/go-ole/go-ole/blob/97b6244175ae18ea6eef668034fd6565847501c9/variant.go#L27-L35
|
19,384
|
go-ole/go-ole
|
variant.go
|
ToString
|
func (v *VARIANT) ToString() string {
if v.VT != VT_BSTR {
return ""
}
return BstrToString(*(**uint16)(unsafe.Pointer(&v.Val)))
}
|
go
|
func (v *VARIANT) ToString() string {
if v.VT != VT_BSTR {
return ""
}
return BstrToString(*(**uint16)(unsafe.Pointer(&v.Val)))
}
|
[
"func",
"(",
"v",
"*",
"VARIANT",
")",
"ToString",
"(",
")",
"string",
"{",
"if",
"v",
".",
"VT",
"!=",
"VT_BSTR",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n",
"return",
"BstrToString",
"(",
"*",
"(",
"*",
"*",
"uint16",
")",
"(",
"unsafe",
".",
"Pointer",
"(",
"&",
"v",
".",
"Val",
")",
")",
")",
"\n",
"}"
] |
// ToString converts variant to Go string.
|
[
"ToString",
"converts",
"variant",
"to",
"Go",
"string",
"."
] |
97b6244175ae18ea6eef668034fd6565847501c9
|
https://github.com/go-ole/go-ole/blob/97b6244175ae18ea6eef668034fd6565847501c9/variant.go#L38-L43
|
19,385
|
go-ole/go-ole
|
guid.go
|
IsEqualGUID
|
func IsEqualGUID(guid1 *GUID, guid2 *GUID) bool {
return guid1.Data1 == guid2.Data1 &&
guid1.Data2 == guid2.Data2 &&
guid1.Data3 == guid2.Data3 &&
guid1.Data4[0] == guid2.Data4[0] &&
guid1.Data4[1] == guid2.Data4[1] &&
guid1.Data4[2] == guid2.Data4[2] &&
guid1.Data4[3] == guid2.Data4[3] &&
guid1.Data4[4] == guid2.Data4[4] &&
guid1.Data4[5] == guid2.Data4[5] &&
guid1.Data4[6] == guid2.Data4[6] &&
guid1.Data4[7] == guid2.Data4[7]
}
|
go
|
func IsEqualGUID(guid1 *GUID, guid2 *GUID) bool {
return guid1.Data1 == guid2.Data1 &&
guid1.Data2 == guid2.Data2 &&
guid1.Data3 == guid2.Data3 &&
guid1.Data4[0] == guid2.Data4[0] &&
guid1.Data4[1] == guid2.Data4[1] &&
guid1.Data4[2] == guid2.Data4[2] &&
guid1.Data4[3] == guid2.Data4[3] &&
guid1.Data4[4] == guid2.Data4[4] &&
guid1.Data4[5] == guid2.Data4[5] &&
guid1.Data4[6] == guid2.Data4[6] &&
guid1.Data4[7] == guid2.Data4[7]
}
|
[
"func",
"IsEqualGUID",
"(",
"guid1",
"*",
"GUID",
",",
"guid2",
"*",
"GUID",
")",
"bool",
"{",
"return",
"guid1",
".",
"Data1",
"==",
"guid2",
".",
"Data1",
"&&",
"guid1",
".",
"Data2",
"==",
"guid2",
".",
"Data2",
"&&",
"guid1",
".",
"Data3",
"==",
"guid2",
".",
"Data3",
"&&",
"guid1",
".",
"Data4",
"[",
"0",
"]",
"==",
"guid2",
".",
"Data4",
"[",
"0",
"]",
"&&",
"guid1",
".",
"Data4",
"[",
"1",
"]",
"==",
"guid2",
".",
"Data4",
"[",
"1",
"]",
"&&",
"guid1",
".",
"Data4",
"[",
"2",
"]",
"==",
"guid2",
".",
"Data4",
"[",
"2",
"]",
"&&",
"guid1",
".",
"Data4",
"[",
"3",
"]",
"==",
"guid2",
".",
"Data4",
"[",
"3",
"]",
"&&",
"guid1",
".",
"Data4",
"[",
"4",
"]",
"==",
"guid2",
".",
"Data4",
"[",
"4",
"]",
"&&",
"guid1",
".",
"Data4",
"[",
"5",
"]",
"==",
"guid2",
".",
"Data4",
"[",
"5",
"]",
"&&",
"guid1",
".",
"Data4",
"[",
"6",
"]",
"==",
"guid2",
".",
"Data4",
"[",
"6",
"]",
"&&",
"guid1",
".",
"Data4",
"[",
"7",
"]",
"==",
"guid2",
".",
"Data4",
"[",
"7",
"]",
"\n",
"}"
] |
// IsEqualGUID compares two GUID.
//
// Not constant time comparison.
|
[
"IsEqualGUID",
"compares",
"two",
"GUID",
".",
"Not",
"constant",
"time",
"comparison",
"."
] |
97b6244175ae18ea6eef668034fd6565847501c9
|
https://github.com/go-ole/go-ole/blob/97b6244175ae18ea6eef668034fd6565847501c9/guid.go#L272-L284
|
19,386
|
go-ole/go-ole
|
com.go
|
coInitializeEx
|
func coInitializeEx(coinit uint32) (err error) {
// http://msdn.microsoft.com/en-us/library/windows/desktop/ms695279(v=vs.85).aspx
// Suggests that the first parameter is not only optional but should always be NULL.
hr, _, _ := procCoInitializeEx.Call(uintptr(0), uintptr(coinit))
if hr != 0 {
err = NewError(hr)
}
return
}
|
go
|
func coInitializeEx(coinit uint32) (err error) {
// http://msdn.microsoft.com/en-us/library/windows/desktop/ms695279(v=vs.85).aspx
// Suggests that the first parameter is not only optional but should always be NULL.
hr, _, _ := procCoInitializeEx.Call(uintptr(0), uintptr(coinit))
if hr != 0 {
err = NewError(hr)
}
return
}
|
[
"func",
"coInitializeEx",
"(",
"coinit",
"uint32",
")",
"(",
"err",
"error",
")",
"{",
"// http://msdn.microsoft.com/en-us/library/windows/desktop/ms695279(v=vs.85).aspx",
"// Suggests that the first parameter is not only optional but should always be NULL.",
"hr",
",",
"_",
",",
"_",
":=",
"procCoInitializeEx",
".",
"Call",
"(",
"uintptr",
"(",
"0",
")",
",",
"uintptr",
"(",
"coinit",
")",
")",
"\n",
"if",
"hr",
"!=",
"0",
"{",
"err",
"=",
"NewError",
"(",
"hr",
")",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] |
// coInitializeEx initializes COM library with concurrency model.
|
[
"coInitializeEx",
"initializes",
"COM",
"library",
"with",
"concurrency",
"model",
"."
] |
97b6244175ae18ea6eef668034fd6565847501c9
|
https://github.com/go-ole/go-ole/blob/97b6244175ae18ea6eef668034fd6565847501c9/com.go#L61-L69
|
19,387
|
go-ole/go-ole
|
com.go
|
CoInitializeEx
|
func CoInitializeEx(p uintptr, coinit uint32) (err error) {
// Avoid any variable not used errors.
p = uintptr(0)
return coInitializeEx(coinit)
}
|
go
|
func CoInitializeEx(p uintptr, coinit uint32) (err error) {
// Avoid any variable not used errors.
p = uintptr(0)
return coInitializeEx(coinit)
}
|
[
"func",
"CoInitializeEx",
"(",
"p",
"uintptr",
",",
"coinit",
"uint32",
")",
"(",
"err",
"error",
")",
"{",
"// Avoid any variable not used errors.",
"p",
"=",
"uintptr",
"(",
"0",
")",
"\n",
"return",
"coInitializeEx",
"(",
"coinit",
")",
"\n",
"}"
] |
// CoInitializeEx initializes COM library with concurrency model.
|
[
"CoInitializeEx",
"initializes",
"COM",
"library",
"with",
"concurrency",
"model",
"."
] |
97b6244175ae18ea6eef668034fd6565847501c9
|
https://github.com/go-ole/go-ole/blob/97b6244175ae18ea6eef668034fd6565847501c9/com.go#L88-L92
|
19,388
|
go-ole/go-ole
|
com.go
|
CLSIDFromString
|
func CLSIDFromString(str string) (clsid *GUID, err error) {
var guid GUID
lpsz := uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(str)))
hr, _, _ := procCLSIDFromString.Call(lpsz, uintptr(unsafe.Pointer(&guid)))
if hr != 0 {
err = NewError(hr)
}
clsid = &guid
return
}
|
go
|
func CLSIDFromString(str string) (clsid *GUID, err error) {
var guid GUID
lpsz := uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(str)))
hr, _, _ := procCLSIDFromString.Call(lpsz, uintptr(unsafe.Pointer(&guid)))
if hr != 0 {
err = NewError(hr)
}
clsid = &guid
return
}
|
[
"func",
"CLSIDFromString",
"(",
"str",
"string",
")",
"(",
"clsid",
"*",
"GUID",
",",
"err",
"error",
")",
"{",
"var",
"guid",
"GUID",
"\n",
"lpsz",
":=",
"uintptr",
"(",
"unsafe",
".",
"Pointer",
"(",
"syscall",
".",
"StringToUTF16Ptr",
"(",
"str",
")",
")",
")",
"\n",
"hr",
",",
"_",
",",
"_",
":=",
"procCLSIDFromString",
".",
"Call",
"(",
"lpsz",
",",
"uintptr",
"(",
"unsafe",
".",
"Pointer",
"(",
"&",
"guid",
")",
")",
")",
"\n",
"if",
"hr",
"!=",
"0",
"{",
"err",
"=",
"NewError",
"(",
"hr",
")",
"\n",
"}",
"\n",
"clsid",
"=",
"&",
"guid",
"\n",
"return",
"\n",
"}"
] |
// CLSIDFromString retrieves Class ID from string representation.
//
// This is technically the string version of the GUID and will convert the
// string to object.
//
// CLSIDFromString in Windows API.
|
[
"CLSIDFromString",
"retrieves",
"Class",
"ID",
"from",
"string",
"representation",
".",
"This",
"is",
"technically",
"the",
"string",
"version",
"of",
"the",
"GUID",
"and",
"will",
"convert",
"the",
"string",
"to",
"object",
".",
"CLSIDFromString",
"in",
"Windows",
"API",
"."
] |
97b6244175ae18ea6eef668034fd6565847501c9
|
https://github.com/go-ole/go-ole/blob/97b6244175ae18ea6eef668034fd6565847501c9/com.go#L134-L143
|
19,389
|
go-ole/go-ole
|
com.go
|
StringFromCLSID
|
func StringFromCLSID(clsid *GUID) (str string, err error) {
var p *uint16
hr, _, _ := procStringFromCLSID.Call(uintptr(unsafe.Pointer(clsid)), uintptr(unsafe.Pointer(&p)))
if hr != 0 {
err = NewError(hr)
}
str = LpOleStrToString(p)
return
}
|
go
|
func StringFromCLSID(clsid *GUID) (str string, err error) {
var p *uint16
hr, _, _ := procStringFromCLSID.Call(uintptr(unsafe.Pointer(clsid)), uintptr(unsafe.Pointer(&p)))
if hr != 0 {
err = NewError(hr)
}
str = LpOleStrToString(p)
return
}
|
[
"func",
"StringFromCLSID",
"(",
"clsid",
"*",
"GUID",
")",
"(",
"str",
"string",
",",
"err",
"error",
")",
"{",
"var",
"p",
"*",
"uint16",
"\n",
"hr",
",",
"_",
",",
"_",
":=",
"procStringFromCLSID",
".",
"Call",
"(",
"uintptr",
"(",
"unsafe",
".",
"Pointer",
"(",
"clsid",
")",
")",
",",
"uintptr",
"(",
"unsafe",
".",
"Pointer",
"(",
"&",
"p",
")",
")",
")",
"\n",
"if",
"hr",
"!=",
"0",
"{",
"err",
"=",
"NewError",
"(",
"hr",
")",
"\n",
"}",
"\n",
"str",
"=",
"LpOleStrToString",
"(",
"p",
")",
"\n",
"return",
"\n",
"}"
] |
// StringFromCLSID returns GUID formated string from GUID object.
|
[
"StringFromCLSID",
"returns",
"GUID",
"formated",
"string",
"from",
"GUID",
"object",
"."
] |
97b6244175ae18ea6eef668034fd6565847501c9
|
https://github.com/go-ole/go-ole/blob/97b6244175ae18ea6eef668034fd6565847501c9/com.go#L146-L154
|
19,390
|
go-ole/go-ole
|
com.go
|
IIDFromString
|
func IIDFromString(progId string) (clsid *GUID, err error) {
var guid GUID
lpsz := uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(progId)))
hr, _, _ := procIIDFromString.Call(lpsz, uintptr(unsafe.Pointer(&guid)))
if hr != 0 {
err = NewError(hr)
}
clsid = &guid
return
}
|
go
|
func IIDFromString(progId string) (clsid *GUID, err error) {
var guid GUID
lpsz := uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(progId)))
hr, _, _ := procIIDFromString.Call(lpsz, uintptr(unsafe.Pointer(&guid)))
if hr != 0 {
err = NewError(hr)
}
clsid = &guid
return
}
|
[
"func",
"IIDFromString",
"(",
"progId",
"string",
")",
"(",
"clsid",
"*",
"GUID",
",",
"err",
"error",
")",
"{",
"var",
"guid",
"GUID",
"\n",
"lpsz",
":=",
"uintptr",
"(",
"unsafe",
".",
"Pointer",
"(",
"syscall",
".",
"StringToUTF16Ptr",
"(",
"progId",
")",
")",
")",
"\n",
"hr",
",",
"_",
",",
"_",
":=",
"procIIDFromString",
".",
"Call",
"(",
"lpsz",
",",
"uintptr",
"(",
"unsafe",
".",
"Pointer",
"(",
"&",
"guid",
")",
")",
")",
"\n",
"if",
"hr",
"!=",
"0",
"{",
"err",
"=",
"NewError",
"(",
"hr",
")",
"\n",
"}",
"\n",
"clsid",
"=",
"&",
"guid",
"\n",
"return",
"\n",
"}"
] |
// IIDFromString returns GUID from program ID.
|
[
"IIDFromString",
"returns",
"GUID",
"from",
"program",
"ID",
"."
] |
97b6244175ae18ea6eef668034fd6565847501c9
|
https://github.com/go-ole/go-ole/blob/97b6244175ae18ea6eef668034fd6565847501c9/com.go#L157-L166
|
19,391
|
go-ole/go-ole
|
com.go
|
StringFromIID
|
func StringFromIID(iid *GUID) (str string, err error) {
var p *uint16
hr, _, _ := procStringFromIID.Call(uintptr(unsafe.Pointer(iid)), uintptr(unsafe.Pointer(&p)))
if hr != 0 {
err = NewError(hr)
}
str = LpOleStrToString(p)
return
}
|
go
|
func StringFromIID(iid *GUID) (str string, err error) {
var p *uint16
hr, _, _ := procStringFromIID.Call(uintptr(unsafe.Pointer(iid)), uintptr(unsafe.Pointer(&p)))
if hr != 0 {
err = NewError(hr)
}
str = LpOleStrToString(p)
return
}
|
[
"func",
"StringFromIID",
"(",
"iid",
"*",
"GUID",
")",
"(",
"str",
"string",
",",
"err",
"error",
")",
"{",
"var",
"p",
"*",
"uint16",
"\n",
"hr",
",",
"_",
",",
"_",
":=",
"procStringFromIID",
".",
"Call",
"(",
"uintptr",
"(",
"unsafe",
".",
"Pointer",
"(",
"iid",
")",
")",
",",
"uintptr",
"(",
"unsafe",
".",
"Pointer",
"(",
"&",
"p",
")",
")",
")",
"\n",
"if",
"hr",
"!=",
"0",
"{",
"err",
"=",
"NewError",
"(",
"hr",
")",
"\n",
"}",
"\n",
"str",
"=",
"LpOleStrToString",
"(",
"p",
")",
"\n",
"return",
"\n",
"}"
] |
// StringFromIID returns GUID formatted string from GUID object.
|
[
"StringFromIID",
"returns",
"GUID",
"formatted",
"string",
"from",
"GUID",
"object",
"."
] |
97b6244175ae18ea6eef668034fd6565847501c9
|
https://github.com/go-ole/go-ole/blob/97b6244175ae18ea6eef668034fd6565847501c9/com.go#L169-L177
|
19,392
|
go-ole/go-ole
|
com.go
|
GetActiveObject
|
func GetActiveObject(clsid *GUID, iid *GUID) (unk *IUnknown, err error) {
if iid == nil {
iid = IID_IUnknown
}
hr, _, _ := procGetActiveObject.Call(
uintptr(unsafe.Pointer(clsid)),
uintptr(unsafe.Pointer(iid)),
uintptr(unsafe.Pointer(&unk)))
if hr != 0 {
err = NewError(hr)
}
return
}
|
go
|
func GetActiveObject(clsid *GUID, iid *GUID) (unk *IUnknown, err error) {
if iid == nil {
iid = IID_IUnknown
}
hr, _, _ := procGetActiveObject.Call(
uintptr(unsafe.Pointer(clsid)),
uintptr(unsafe.Pointer(iid)),
uintptr(unsafe.Pointer(&unk)))
if hr != 0 {
err = NewError(hr)
}
return
}
|
[
"func",
"GetActiveObject",
"(",
"clsid",
"*",
"GUID",
",",
"iid",
"*",
"GUID",
")",
"(",
"unk",
"*",
"IUnknown",
",",
"err",
"error",
")",
"{",
"if",
"iid",
"==",
"nil",
"{",
"iid",
"=",
"IID_IUnknown",
"\n",
"}",
"\n",
"hr",
",",
"_",
",",
"_",
":=",
"procGetActiveObject",
".",
"Call",
"(",
"uintptr",
"(",
"unsafe",
".",
"Pointer",
"(",
"clsid",
")",
")",
",",
"uintptr",
"(",
"unsafe",
".",
"Pointer",
"(",
"iid",
")",
")",
",",
"uintptr",
"(",
"unsafe",
".",
"Pointer",
"(",
"&",
"unk",
")",
")",
")",
"\n",
"if",
"hr",
"!=",
"0",
"{",
"err",
"=",
"NewError",
"(",
"hr",
")",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] |
// GetActiveObject retrieves pointer to active object.
|
[
"GetActiveObject",
"retrieves",
"pointer",
"to",
"active",
"object",
"."
] |
97b6244175ae18ea6eef668034fd6565847501c9
|
https://github.com/go-ole/go-ole/blob/97b6244175ae18ea6eef668034fd6565847501c9/com.go#L197-L209
|
19,393
|
go-ole/go-ole
|
com.go
|
GetObject
|
func GetObject(programID string, bindOpts *BindOpts, iid *GUID) (unk *IUnknown, err error) {
if bindOpts != nil {
bindOpts.CbStruct = uint32(unsafe.Sizeof(BindOpts{}))
}
if iid == nil {
iid = IID_IUnknown
}
hr, _, _ := procCoGetObject.Call(
uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(programID))),
uintptr(unsafe.Pointer(bindOpts)),
uintptr(unsafe.Pointer(iid)),
uintptr(unsafe.Pointer(&unk)))
if hr != 0 {
err = NewError(hr)
}
return
}
|
go
|
func GetObject(programID string, bindOpts *BindOpts, iid *GUID) (unk *IUnknown, err error) {
if bindOpts != nil {
bindOpts.CbStruct = uint32(unsafe.Sizeof(BindOpts{}))
}
if iid == nil {
iid = IID_IUnknown
}
hr, _, _ := procCoGetObject.Call(
uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(programID))),
uintptr(unsafe.Pointer(bindOpts)),
uintptr(unsafe.Pointer(iid)),
uintptr(unsafe.Pointer(&unk)))
if hr != 0 {
err = NewError(hr)
}
return
}
|
[
"func",
"GetObject",
"(",
"programID",
"string",
",",
"bindOpts",
"*",
"BindOpts",
",",
"iid",
"*",
"GUID",
")",
"(",
"unk",
"*",
"IUnknown",
",",
"err",
"error",
")",
"{",
"if",
"bindOpts",
"!=",
"nil",
"{",
"bindOpts",
".",
"CbStruct",
"=",
"uint32",
"(",
"unsafe",
".",
"Sizeof",
"(",
"BindOpts",
"{",
"}",
")",
")",
"\n",
"}",
"\n",
"if",
"iid",
"==",
"nil",
"{",
"iid",
"=",
"IID_IUnknown",
"\n",
"}",
"\n",
"hr",
",",
"_",
",",
"_",
":=",
"procCoGetObject",
".",
"Call",
"(",
"uintptr",
"(",
"unsafe",
".",
"Pointer",
"(",
"syscall",
".",
"StringToUTF16Ptr",
"(",
"programID",
")",
")",
")",
",",
"uintptr",
"(",
"unsafe",
".",
"Pointer",
"(",
"bindOpts",
")",
")",
",",
"uintptr",
"(",
"unsafe",
".",
"Pointer",
"(",
"iid",
")",
")",
",",
"uintptr",
"(",
"unsafe",
".",
"Pointer",
"(",
"&",
"unk",
")",
")",
")",
"\n",
"if",
"hr",
"!=",
"0",
"{",
"err",
"=",
"NewError",
"(",
"hr",
")",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] |
// GetObject retrieves pointer to active object.
|
[
"GetObject",
"retrieves",
"pointer",
"to",
"active",
"object",
"."
] |
97b6244175ae18ea6eef668034fd6565847501c9
|
https://github.com/go-ole/go-ole/blob/97b6244175ae18ea6eef668034fd6565847501c9/com.go#L219-L235
|
19,394
|
go-ole/go-ole
|
com.go
|
VariantInit
|
func VariantInit(v *VARIANT) (err error) {
hr, _, _ := procVariantInit.Call(uintptr(unsafe.Pointer(v)))
if hr != 0 {
err = NewError(hr)
}
return
}
|
go
|
func VariantInit(v *VARIANT) (err error) {
hr, _, _ := procVariantInit.Call(uintptr(unsafe.Pointer(v)))
if hr != 0 {
err = NewError(hr)
}
return
}
|
[
"func",
"VariantInit",
"(",
"v",
"*",
"VARIANT",
")",
"(",
"err",
"error",
")",
"{",
"hr",
",",
"_",
",",
"_",
":=",
"procVariantInit",
".",
"Call",
"(",
"uintptr",
"(",
"unsafe",
".",
"Pointer",
"(",
"v",
")",
")",
")",
"\n",
"if",
"hr",
"!=",
"0",
"{",
"err",
"=",
"NewError",
"(",
"hr",
")",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] |
// VariantInit initializes variant.
|
[
"VariantInit",
"initializes",
"variant",
"."
] |
97b6244175ae18ea6eef668034fd6565847501c9
|
https://github.com/go-ole/go-ole/blob/97b6244175ae18ea6eef668034fd6565847501c9/com.go#L238-L244
|
19,395
|
go-ole/go-ole
|
com.go
|
VariantClear
|
func VariantClear(v *VARIANT) (err error) {
hr, _, _ := procVariantClear.Call(uintptr(unsafe.Pointer(v)))
if hr != 0 {
err = NewError(hr)
}
return
}
|
go
|
func VariantClear(v *VARIANT) (err error) {
hr, _, _ := procVariantClear.Call(uintptr(unsafe.Pointer(v)))
if hr != 0 {
err = NewError(hr)
}
return
}
|
[
"func",
"VariantClear",
"(",
"v",
"*",
"VARIANT",
")",
"(",
"err",
"error",
")",
"{",
"hr",
",",
"_",
",",
"_",
":=",
"procVariantClear",
".",
"Call",
"(",
"uintptr",
"(",
"unsafe",
".",
"Pointer",
"(",
"v",
")",
")",
")",
"\n",
"if",
"hr",
"!=",
"0",
"{",
"err",
"=",
"NewError",
"(",
"hr",
")",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] |
// VariantClear clears value in Variant settings to VT_EMPTY.
|
[
"VariantClear",
"clears",
"value",
"in",
"Variant",
"settings",
"to",
"VT_EMPTY",
"."
] |
97b6244175ae18ea6eef668034fd6565847501c9
|
https://github.com/go-ole/go-ole/blob/97b6244175ae18ea6eef668034fd6565847501c9/com.go#L247-L253
|
19,396
|
go-ole/go-ole
|
com.go
|
SysAllocString
|
func SysAllocString(v string) (ss *int16) {
pss, _, _ := procSysAllocString.Call(uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(v))))
ss = (*int16)(unsafe.Pointer(pss))
return
}
|
go
|
func SysAllocString(v string) (ss *int16) {
pss, _, _ := procSysAllocString.Call(uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(v))))
ss = (*int16)(unsafe.Pointer(pss))
return
}
|
[
"func",
"SysAllocString",
"(",
"v",
"string",
")",
"(",
"ss",
"*",
"int16",
")",
"{",
"pss",
",",
"_",
",",
"_",
":=",
"procSysAllocString",
".",
"Call",
"(",
"uintptr",
"(",
"unsafe",
".",
"Pointer",
"(",
"syscall",
".",
"StringToUTF16Ptr",
"(",
"v",
")",
")",
")",
")",
"\n",
"ss",
"=",
"(",
"*",
"int16",
")",
"(",
"unsafe",
".",
"Pointer",
"(",
"pss",
")",
")",
"\n",
"return",
"\n",
"}"
] |
// SysAllocString allocates memory for string and copies string into memory.
|
[
"SysAllocString",
"allocates",
"memory",
"for",
"string",
"and",
"copies",
"string",
"into",
"memory",
"."
] |
97b6244175ae18ea6eef668034fd6565847501c9
|
https://github.com/go-ole/go-ole/blob/97b6244175ae18ea6eef668034fd6565847501c9/com.go#L256-L260
|
19,397
|
go-ole/go-ole
|
com.go
|
SysAllocStringLen
|
func SysAllocStringLen(v string) (ss *int16) {
utf16 := utf16.Encode([]rune(v + "\x00"))
ptr := &utf16[0]
pss, _, _ := procSysAllocStringLen.Call(uintptr(unsafe.Pointer(ptr)), uintptr(len(utf16)-1))
ss = (*int16)(unsafe.Pointer(pss))
return
}
|
go
|
func SysAllocStringLen(v string) (ss *int16) {
utf16 := utf16.Encode([]rune(v + "\x00"))
ptr := &utf16[0]
pss, _, _ := procSysAllocStringLen.Call(uintptr(unsafe.Pointer(ptr)), uintptr(len(utf16)-1))
ss = (*int16)(unsafe.Pointer(pss))
return
}
|
[
"func",
"SysAllocStringLen",
"(",
"v",
"string",
")",
"(",
"ss",
"*",
"int16",
")",
"{",
"utf16",
":=",
"utf16",
".",
"Encode",
"(",
"[",
"]",
"rune",
"(",
"v",
"+",
"\"",
"\\x00",
"\"",
")",
")",
"\n",
"ptr",
":=",
"&",
"utf16",
"[",
"0",
"]",
"\n\n",
"pss",
",",
"_",
",",
"_",
":=",
"procSysAllocStringLen",
".",
"Call",
"(",
"uintptr",
"(",
"unsafe",
".",
"Pointer",
"(",
"ptr",
")",
")",
",",
"uintptr",
"(",
"len",
"(",
"utf16",
")",
"-",
"1",
")",
")",
"\n",
"ss",
"=",
"(",
"*",
"int16",
")",
"(",
"unsafe",
".",
"Pointer",
"(",
"pss",
")",
")",
"\n",
"return",
"\n",
"}"
] |
// SysAllocStringLen copies up to length of given string returning pointer.
|
[
"SysAllocStringLen",
"copies",
"up",
"to",
"length",
"of",
"given",
"string",
"returning",
"pointer",
"."
] |
97b6244175ae18ea6eef668034fd6565847501c9
|
https://github.com/go-ole/go-ole/blob/97b6244175ae18ea6eef668034fd6565847501c9/com.go#L263-L270
|
19,398
|
go-ole/go-ole
|
com.go
|
SysFreeString
|
func SysFreeString(v *int16) (err error) {
hr, _, _ := procSysFreeString.Call(uintptr(unsafe.Pointer(v)))
if hr != 0 {
err = NewError(hr)
}
return
}
|
go
|
func SysFreeString(v *int16) (err error) {
hr, _, _ := procSysFreeString.Call(uintptr(unsafe.Pointer(v)))
if hr != 0 {
err = NewError(hr)
}
return
}
|
[
"func",
"SysFreeString",
"(",
"v",
"*",
"int16",
")",
"(",
"err",
"error",
")",
"{",
"hr",
",",
"_",
",",
"_",
":=",
"procSysFreeString",
".",
"Call",
"(",
"uintptr",
"(",
"unsafe",
".",
"Pointer",
"(",
"v",
")",
")",
")",
"\n",
"if",
"hr",
"!=",
"0",
"{",
"err",
"=",
"NewError",
"(",
"hr",
")",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] |
// SysFreeString frees string system memory. This must be called with SysAllocString.
|
[
"SysFreeString",
"frees",
"string",
"system",
"memory",
".",
"This",
"must",
"be",
"called",
"with",
"SysAllocString",
"."
] |
97b6244175ae18ea6eef668034fd6565847501c9
|
https://github.com/go-ole/go-ole/blob/97b6244175ae18ea6eef668034fd6565847501c9/com.go#L273-L279
|
19,399
|
go-ole/go-ole
|
com.go
|
SysStringLen
|
func SysStringLen(v *int16) uint32 {
l, _, _ := procSysStringLen.Call(uintptr(unsafe.Pointer(v)))
return uint32(l)
}
|
go
|
func SysStringLen(v *int16) uint32 {
l, _, _ := procSysStringLen.Call(uintptr(unsafe.Pointer(v)))
return uint32(l)
}
|
[
"func",
"SysStringLen",
"(",
"v",
"*",
"int16",
")",
"uint32",
"{",
"l",
",",
"_",
",",
"_",
":=",
"procSysStringLen",
".",
"Call",
"(",
"uintptr",
"(",
"unsafe",
".",
"Pointer",
"(",
"v",
")",
")",
")",
"\n",
"return",
"uint32",
"(",
"l",
")",
"\n",
"}"
] |
// SysStringLen is the length of the system allocated string.
|
[
"SysStringLen",
"is",
"the",
"length",
"of",
"the",
"system",
"allocated",
"string",
"."
] |
97b6244175ae18ea6eef668034fd6565847501c9
|
https://github.com/go-ole/go-ole/blob/97b6244175ae18ea6eef668034fd6565847501c9/com.go#L282-L285
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.