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,400
|
go-ole/go-ole
|
com.go
|
CreateDispTypeInfo
|
func CreateDispTypeInfo(idata *INTERFACEDATA) (pptinfo *IUnknown, err error) {
hr, _, _ := procCreateDispTypeInfo.Call(
uintptr(unsafe.Pointer(idata)),
uintptr(GetUserDefaultLCID()),
uintptr(unsafe.Pointer(&pptinfo)))
if hr != 0 {
err = NewError(hr)
}
return
}
|
go
|
func CreateDispTypeInfo(idata *INTERFACEDATA) (pptinfo *IUnknown, err error) {
hr, _, _ := procCreateDispTypeInfo.Call(
uintptr(unsafe.Pointer(idata)),
uintptr(GetUserDefaultLCID()),
uintptr(unsafe.Pointer(&pptinfo)))
if hr != 0 {
err = NewError(hr)
}
return
}
|
[
"func",
"CreateDispTypeInfo",
"(",
"idata",
"*",
"INTERFACEDATA",
")",
"(",
"pptinfo",
"*",
"IUnknown",
",",
"err",
"error",
")",
"{",
"hr",
",",
"_",
",",
"_",
":=",
"procCreateDispTypeInfo",
".",
"Call",
"(",
"uintptr",
"(",
"unsafe",
".",
"Pointer",
"(",
"idata",
")",
")",
",",
"uintptr",
"(",
"GetUserDefaultLCID",
"(",
")",
")",
",",
"uintptr",
"(",
"unsafe",
".",
"Pointer",
"(",
"&",
"pptinfo",
")",
")",
")",
"\n",
"if",
"hr",
"!=",
"0",
"{",
"err",
"=",
"NewError",
"(",
"hr",
")",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] |
// CreateDispTypeInfo provides default ITypeInfo implementation for IDispatch.
//
// This will not handle the full implementation of the interface.
|
[
"CreateDispTypeInfo",
"provides",
"default",
"ITypeInfo",
"implementation",
"for",
"IDispatch",
".",
"This",
"will",
"not",
"handle",
"the",
"full",
"implementation",
"of",
"the",
"interface",
"."
] |
97b6244175ae18ea6eef668034fd6565847501c9
|
https://github.com/go-ole/go-ole/blob/97b6244175ae18ea6eef668034fd6565847501c9/com.go#L307-L316
|
19,401
|
go-ole/go-ole
|
com.go
|
copyMemory
|
func copyMemory(dest unsafe.Pointer, src unsafe.Pointer, length uint32) {
procCopyMemory.Call(uintptr(dest), uintptr(src), uintptr(length))
}
|
go
|
func copyMemory(dest unsafe.Pointer, src unsafe.Pointer, length uint32) {
procCopyMemory.Call(uintptr(dest), uintptr(src), uintptr(length))
}
|
[
"func",
"copyMemory",
"(",
"dest",
"unsafe",
".",
"Pointer",
",",
"src",
"unsafe",
".",
"Pointer",
",",
"length",
"uint32",
")",
"{",
"procCopyMemory",
".",
"Call",
"(",
"uintptr",
"(",
"dest",
")",
",",
"uintptr",
"(",
"src",
")",
",",
"uintptr",
"(",
"length",
")",
")",
"\n",
"}"
] |
// copyMemory moves location of a block of memory.
|
[
"copyMemory",
"moves",
"location",
"of",
"a",
"block",
"of",
"memory",
"."
] |
97b6244175ae18ea6eef668034fd6565847501c9
|
https://github.com/go-ole/go-ole/blob/97b6244175ae18ea6eef668034fd6565847501c9/com.go#L319-L321
|
19,402
|
go-ole/go-ole
|
com.go
|
GetUserDefaultLCID
|
func GetUserDefaultLCID() (lcid uint32) {
ret, _, _ := procGetUserDefaultLCID.Call()
lcid = uint32(ret)
return
}
|
go
|
func GetUserDefaultLCID() (lcid uint32) {
ret, _, _ := procGetUserDefaultLCID.Call()
lcid = uint32(ret)
return
}
|
[
"func",
"GetUserDefaultLCID",
"(",
")",
"(",
"lcid",
"uint32",
")",
"{",
"ret",
",",
"_",
",",
"_",
":=",
"procGetUserDefaultLCID",
".",
"Call",
"(",
")",
"\n",
"lcid",
"=",
"uint32",
"(",
"ret",
")",
"\n",
"return",
"\n",
"}"
] |
// GetUserDefaultLCID retrieves current user default locale.
|
[
"GetUserDefaultLCID",
"retrieves",
"current",
"user",
"default",
"locale",
"."
] |
97b6244175ae18ea6eef668034fd6565847501c9
|
https://github.com/go-ole/go-ole/blob/97b6244175ae18ea6eef668034fd6565847501c9/com.go#L324-L328
|
19,403
|
go-ole/go-ole
|
com.go
|
DispatchMessage
|
func DispatchMessage(msg *Msg) (ret int32) {
r0, _, _ := procDispatchMessageW.Call(uintptr(unsafe.Pointer(msg)))
ret = int32(r0)
return
}
|
go
|
func DispatchMessage(msg *Msg) (ret int32) {
r0, _, _ := procDispatchMessageW.Call(uintptr(unsafe.Pointer(msg)))
ret = int32(r0)
return
}
|
[
"func",
"DispatchMessage",
"(",
"msg",
"*",
"Msg",
")",
"(",
"ret",
"int32",
")",
"{",
"r0",
",",
"_",
",",
"_",
":=",
"procDispatchMessageW",
".",
"Call",
"(",
"uintptr",
"(",
"unsafe",
".",
"Pointer",
"(",
"msg",
")",
")",
")",
"\n",
"ret",
"=",
"int32",
"(",
"r0",
")",
"\n",
"return",
"\n",
"}"
] |
// DispatchMessage to window procedure.
|
[
"DispatchMessage",
"to",
"window",
"procedure",
"."
] |
97b6244175ae18ea6eef668034fd6565847501c9
|
https://github.com/go-ole/go-ole/blob/97b6244175ae18ea6eef668034fd6565847501c9/com.go#L340-L344
|
19,404
|
go-ole/go-ole
|
variant_date_amd64.go
|
GetVariantDate
|
func GetVariantDate(value uint64) (time.Time, error) {
var st syscall.Systemtime
r, _, _ := procVariantTimeToSystemTime.Call(uintptr(value), uintptr(unsafe.Pointer(&st)))
if r != 0 {
return time.Date(int(st.Year), time.Month(st.Month), int(st.Day), int(st.Hour), int(st.Minute), int(st.Second), int(st.Milliseconds/1000), time.UTC), nil
}
return time.Now(), errors.New("Could not convert to time, passing current time.")
}
|
go
|
func GetVariantDate(value uint64) (time.Time, error) {
var st syscall.Systemtime
r, _, _ := procVariantTimeToSystemTime.Call(uintptr(value), uintptr(unsafe.Pointer(&st)))
if r != 0 {
return time.Date(int(st.Year), time.Month(st.Month), int(st.Day), int(st.Hour), int(st.Minute), int(st.Second), int(st.Milliseconds/1000), time.UTC), nil
}
return time.Now(), errors.New("Could not convert to time, passing current time.")
}
|
[
"func",
"GetVariantDate",
"(",
"value",
"uint64",
")",
"(",
"time",
".",
"Time",
",",
"error",
")",
"{",
"var",
"st",
"syscall",
".",
"Systemtime",
"\n",
"r",
",",
"_",
",",
"_",
":=",
"procVariantTimeToSystemTime",
".",
"Call",
"(",
"uintptr",
"(",
"value",
")",
",",
"uintptr",
"(",
"unsafe",
".",
"Pointer",
"(",
"&",
"st",
")",
")",
")",
"\n",
"if",
"r",
"!=",
"0",
"{",
"return",
"time",
".",
"Date",
"(",
"int",
"(",
"st",
".",
"Year",
")",
",",
"time",
".",
"Month",
"(",
"st",
".",
"Month",
")",
",",
"int",
"(",
"st",
".",
"Day",
")",
",",
"int",
"(",
"st",
".",
"Hour",
")",
",",
"int",
"(",
"st",
".",
"Minute",
")",
",",
"int",
"(",
"st",
".",
"Second",
")",
",",
"int",
"(",
"st",
".",
"Milliseconds",
"/",
"1000",
")",
",",
"time",
".",
"UTC",
")",
",",
"nil",
"\n",
"}",
"\n",
"return",
"time",
".",
"Now",
"(",
")",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}"
] |
// GetVariantDate converts COM Variant Time value to Go time.Time.
|
[
"GetVariantDate",
"converts",
"COM",
"Variant",
"Time",
"value",
"to",
"Go",
"time",
".",
"Time",
"."
] |
97b6244175ae18ea6eef668034fd6565847501c9
|
https://github.com/go-ole/go-ole/blob/97b6244175ae18ea6eef668034fd6565847501c9/variant_date_amd64.go#L13-L20
|
19,405
|
go-ole/go-ole
|
ole.go
|
String
|
func (e EXCEPINFO) String() string {
var src, desc, hlp string
if e.bstrSource == nil {
src = "<nil>"
} else {
src = BstrToString(e.bstrSource)
}
if e.bstrDescription == nil {
desc = "<nil>"
} else {
desc = BstrToString(e.bstrDescription)
}
if e.bstrHelpFile == nil {
hlp = "<nil>"
} else {
hlp = BstrToString(e.bstrHelpFile)
}
return fmt.Sprintf(
"wCode: %#x, bstrSource: %v, bstrDescription: %v, bstrHelpFile: %v, dwHelpContext: %#x, scode: %#x",
e.wCode, src, desc, hlp, e.dwHelpContext, e.scode,
)
}
|
go
|
func (e EXCEPINFO) String() string {
var src, desc, hlp string
if e.bstrSource == nil {
src = "<nil>"
} else {
src = BstrToString(e.bstrSource)
}
if e.bstrDescription == nil {
desc = "<nil>"
} else {
desc = BstrToString(e.bstrDescription)
}
if e.bstrHelpFile == nil {
hlp = "<nil>"
} else {
hlp = BstrToString(e.bstrHelpFile)
}
return fmt.Sprintf(
"wCode: %#x, bstrSource: %v, bstrDescription: %v, bstrHelpFile: %v, dwHelpContext: %#x, scode: %#x",
e.wCode, src, desc, hlp, e.dwHelpContext, e.scode,
)
}
|
[
"func",
"(",
"e",
"EXCEPINFO",
")",
"String",
"(",
")",
"string",
"{",
"var",
"src",
",",
"desc",
",",
"hlp",
"string",
"\n",
"if",
"e",
".",
"bstrSource",
"==",
"nil",
"{",
"src",
"=",
"\"",
"\"",
"\n",
"}",
"else",
"{",
"src",
"=",
"BstrToString",
"(",
"e",
".",
"bstrSource",
")",
"\n",
"}",
"\n\n",
"if",
"e",
".",
"bstrDescription",
"==",
"nil",
"{",
"desc",
"=",
"\"",
"\"",
"\n",
"}",
"else",
"{",
"desc",
"=",
"BstrToString",
"(",
"e",
".",
"bstrDescription",
")",
"\n",
"}",
"\n\n",
"if",
"e",
".",
"bstrHelpFile",
"==",
"nil",
"{",
"hlp",
"=",
"\"",
"\"",
"\n",
"}",
"else",
"{",
"hlp",
"=",
"BstrToString",
"(",
"e",
".",
"bstrHelpFile",
")",
"\n",
"}",
"\n\n",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"e",
".",
"wCode",
",",
"src",
",",
"desc",
",",
"hlp",
",",
"e",
".",
"dwHelpContext",
",",
"e",
".",
"scode",
",",
")",
"\n",
"}"
] |
// String convert EXCEPINFO to string.
|
[
"String",
"convert",
"EXCEPINFO",
"to",
"string",
"."
] |
97b6244175ae18ea6eef668034fd6565847501c9
|
https://github.com/go-ole/go-ole/blob/97b6244175ae18ea6eef668034fd6565847501c9/ole.go#L40-L64
|
19,406
|
go-ole/go-ole
|
ole.go
|
Error
|
func (e EXCEPINFO) Error() string {
if e.bstrDescription != nil {
return strings.TrimSpace(BstrToString(e.bstrDescription))
}
src := "Unknown"
if e.bstrSource != nil {
src = BstrToString(e.bstrSource)
}
code := e.scode
if e.wCode != 0 {
code = uint32(e.wCode)
}
return fmt.Sprintf("%v: %#x", src, code)
}
|
go
|
func (e EXCEPINFO) Error() string {
if e.bstrDescription != nil {
return strings.TrimSpace(BstrToString(e.bstrDescription))
}
src := "Unknown"
if e.bstrSource != nil {
src = BstrToString(e.bstrSource)
}
code := e.scode
if e.wCode != 0 {
code = uint32(e.wCode)
}
return fmt.Sprintf("%v: %#x", src, code)
}
|
[
"func",
"(",
"e",
"EXCEPINFO",
")",
"Error",
"(",
")",
"string",
"{",
"if",
"e",
".",
"bstrDescription",
"!=",
"nil",
"{",
"return",
"strings",
".",
"TrimSpace",
"(",
"BstrToString",
"(",
"e",
".",
"bstrDescription",
")",
")",
"\n",
"}",
"\n\n",
"src",
":=",
"\"",
"\"",
"\n",
"if",
"e",
".",
"bstrSource",
"!=",
"nil",
"{",
"src",
"=",
"BstrToString",
"(",
"e",
".",
"bstrSource",
")",
"\n",
"}",
"\n\n",
"code",
":=",
"e",
".",
"scode",
"\n",
"if",
"e",
".",
"wCode",
"!=",
"0",
"{",
"code",
"=",
"uint32",
"(",
"e",
".",
"wCode",
")",
"\n",
"}",
"\n\n",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"src",
",",
"code",
")",
"\n",
"}"
] |
// Error implements error interface and returns error string.
|
[
"Error",
"implements",
"error",
"interface",
"and",
"returns",
"error",
"string",
"."
] |
97b6244175ae18ea6eef668034fd6565847501c9
|
https://github.com/go-ole/go-ole/blob/97b6244175ae18ea6eef668034fd6565847501c9/ole.go#L67-L83
|
19,407
|
go-ole/go-ole
|
idispatch.go
|
GetSingleIDOfName
|
func (v *IDispatch) GetSingleIDOfName(name string) (displayID int32, err error) {
var displayIDs []int32
displayIDs, err = v.GetIDsOfName([]string{name})
if err != nil {
return
}
displayID = displayIDs[0]
return
}
|
go
|
func (v *IDispatch) GetSingleIDOfName(name string) (displayID int32, err error) {
var displayIDs []int32
displayIDs, err = v.GetIDsOfName([]string{name})
if err != nil {
return
}
displayID = displayIDs[0]
return
}
|
[
"func",
"(",
"v",
"*",
"IDispatch",
")",
"GetSingleIDOfName",
"(",
"name",
"string",
")",
"(",
"displayID",
"int32",
",",
"err",
"error",
")",
"{",
"var",
"displayIDs",
"[",
"]",
"int32",
"\n",
"displayIDs",
",",
"err",
"=",
"v",
".",
"GetIDsOfName",
"(",
"[",
"]",
"string",
"{",
"name",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"displayID",
"=",
"displayIDs",
"[",
"0",
"]",
"\n",
"return",
"\n",
"}"
] |
// GetSingleIDOfName is a helper that returns single display ID for IDispatch name.
//
// This replaces the common pattern of attempting to get a single name from the list of available
// IDs. It gives the first ID, if it is available.
|
[
"GetSingleIDOfName",
"is",
"a",
"helper",
"that",
"returns",
"single",
"display",
"ID",
"for",
"IDispatch",
"name",
".",
"This",
"replaces",
"the",
"common",
"pattern",
"of",
"attempting",
"to",
"get",
"a",
"single",
"name",
"from",
"the",
"list",
"of",
"available",
"IDs",
".",
"It",
"gives",
"the",
"first",
"ID",
"if",
"it",
"is",
"available",
"."
] |
97b6244175ae18ea6eef668034fd6565847501c9
|
https://github.com/go-ole/go-ole/blob/97b6244175ae18ea6eef668034fd6565847501c9/idispatch.go#L45-L53
|
19,408
|
go-ole/go-ole
|
idispatch.go
|
InvokeWithOptionalArgs
|
func (v *IDispatch) InvokeWithOptionalArgs(name string, dispatch int16, params []interface{}) (result *VARIANT, err error) {
displayID, err := v.GetSingleIDOfName(name)
if err != nil {
return
}
if len(params) < 1 {
result, err = v.Invoke(displayID, dispatch)
} else {
result, err = v.Invoke(displayID, dispatch, params...)
}
return
}
|
go
|
func (v *IDispatch) InvokeWithOptionalArgs(name string, dispatch int16, params []interface{}) (result *VARIANT, err error) {
displayID, err := v.GetSingleIDOfName(name)
if err != nil {
return
}
if len(params) < 1 {
result, err = v.Invoke(displayID, dispatch)
} else {
result, err = v.Invoke(displayID, dispatch, params...)
}
return
}
|
[
"func",
"(",
"v",
"*",
"IDispatch",
")",
"InvokeWithOptionalArgs",
"(",
"name",
"string",
",",
"dispatch",
"int16",
",",
"params",
"[",
"]",
"interface",
"{",
"}",
")",
"(",
"result",
"*",
"VARIANT",
",",
"err",
"error",
")",
"{",
"displayID",
",",
"err",
":=",
"v",
".",
"GetSingleIDOfName",
"(",
"name",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"params",
")",
"<",
"1",
"{",
"result",
",",
"err",
"=",
"v",
".",
"Invoke",
"(",
"displayID",
",",
"dispatch",
")",
"\n",
"}",
"else",
"{",
"result",
",",
"err",
"=",
"v",
".",
"Invoke",
"(",
"displayID",
",",
"dispatch",
",",
"params",
"...",
")",
"\n",
"}",
"\n\n",
"return",
"\n",
"}"
] |
// InvokeWithOptionalArgs accepts arguments as an array, works like Invoke.
//
// Accepts name and will attempt to retrieve Display ID to pass to Invoke.
//
// Passing params as an array is a workaround that could be fixed in later versions of Go that
// prevent passing empty params. During testing it was discovered that this is an acceptable way of
// getting around not being able to pass params normally.
|
[
"InvokeWithOptionalArgs",
"accepts",
"arguments",
"as",
"an",
"array",
"works",
"like",
"Invoke",
".",
"Accepts",
"name",
"and",
"will",
"attempt",
"to",
"retrieve",
"Display",
"ID",
"to",
"pass",
"to",
"Invoke",
".",
"Passing",
"params",
"as",
"an",
"array",
"is",
"a",
"workaround",
"that",
"could",
"be",
"fixed",
"in",
"later",
"versions",
"of",
"Go",
"that",
"prevent",
"passing",
"empty",
"params",
".",
"During",
"testing",
"it",
"was",
"discovered",
"that",
"this",
"is",
"an",
"acceptable",
"way",
"of",
"getting",
"around",
"not",
"being",
"able",
"to",
"pass",
"params",
"normally",
"."
] |
97b6244175ae18ea6eef668034fd6565847501c9
|
https://github.com/go-ole/go-ole/blob/97b6244175ae18ea6eef668034fd6565847501c9/idispatch.go#L62-L75
|
19,409
|
go-ole/go-ole
|
idispatch.go
|
CallMethod
|
func (v *IDispatch) CallMethod(name string, params ...interface{}) (*VARIANT, error) {
return v.InvokeWithOptionalArgs(name, DISPATCH_METHOD, params)
}
|
go
|
func (v *IDispatch) CallMethod(name string, params ...interface{}) (*VARIANT, error) {
return v.InvokeWithOptionalArgs(name, DISPATCH_METHOD, params)
}
|
[
"func",
"(",
"v",
"*",
"IDispatch",
")",
"CallMethod",
"(",
"name",
"string",
",",
"params",
"...",
"interface",
"{",
"}",
")",
"(",
"*",
"VARIANT",
",",
"error",
")",
"{",
"return",
"v",
".",
"InvokeWithOptionalArgs",
"(",
"name",
",",
"DISPATCH_METHOD",
",",
"params",
")",
"\n",
"}"
] |
// CallMethod invokes named function with arguments on object.
|
[
"CallMethod",
"invokes",
"named",
"function",
"with",
"arguments",
"on",
"object",
"."
] |
97b6244175ae18ea6eef668034fd6565847501c9
|
https://github.com/go-ole/go-ole/blob/97b6244175ae18ea6eef668034fd6565847501c9/idispatch.go#L78-L80
|
19,410
|
go-ole/go-ole
|
idispatch.go
|
GetProperty
|
func (v *IDispatch) GetProperty(name string, params ...interface{}) (*VARIANT, error) {
return v.InvokeWithOptionalArgs(name, DISPATCH_PROPERTYGET, params)
}
|
go
|
func (v *IDispatch) GetProperty(name string, params ...interface{}) (*VARIANT, error) {
return v.InvokeWithOptionalArgs(name, DISPATCH_PROPERTYGET, params)
}
|
[
"func",
"(",
"v",
"*",
"IDispatch",
")",
"GetProperty",
"(",
"name",
"string",
",",
"params",
"...",
"interface",
"{",
"}",
")",
"(",
"*",
"VARIANT",
",",
"error",
")",
"{",
"return",
"v",
".",
"InvokeWithOptionalArgs",
"(",
"name",
",",
"DISPATCH_PROPERTYGET",
",",
"params",
")",
"\n",
"}"
] |
// GetProperty retrieves the property with the name with the ability to pass arguments.
//
// Most of the time you will not need to pass arguments as most objects do not allow for this
// feature. Or at least, should not allow for this feature. Some servers don't follow best practices
// and this is provided for those edge cases.
|
[
"GetProperty",
"retrieves",
"the",
"property",
"with",
"the",
"name",
"with",
"the",
"ability",
"to",
"pass",
"arguments",
".",
"Most",
"of",
"the",
"time",
"you",
"will",
"not",
"need",
"to",
"pass",
"arguments",
"as",
"most",
"objects",
"do",
"not",
"allow",
"for",
"this",
"feature",
".",
"Or",
"at",
"least",
"should",
"not",
"allow",
"for",
"this",
"feature",
".",
"Some",
"servers",
"don",
"t",
"follow",
"best",
"practices",
"and",
"this",
"is",
"provided",
"for",
"those",
"edge",
"cases",
"."
] |
97b6244175ae18ea6eef668034fd6565847501c9
|
https://github.com/go-ole/go-ole/blob/97b6244175ae18ea6eef668034fd6565847501c9/idispatch.go#L87-L89
|
19,411
|
go-ole/go-ole
|
idispatch.go
|
PutProperty
|
func (v *IDispatch) PutProperty(name string, params ...interface{}) (*VARIANT, error) {
return v.InvokeWithOptionalArgs(name, DISPATCH_PROPERTYPUT, params)
}
|
go
|
func (v *IDispatch) PutProperty(name string, params ...interface{}) (*VARIANT, error) {
return v.InvokeWithOptionalArgs(name, DISPATCH_PROPERTYPUT, params)
}
|
[
"func",
"(",
"v",
"*",
"IDispatch",
")",
"PutProperty",
"(",
"name",
"string",
",",
"params",
"...",
"interface",
"{",
"}",
")",
"(",
"*",
"VARIANT",
",",
"error",
")",
"{",
"return",
"v",
".",
"InvokeWithOptionalArgs",
"(",
"name",
",",
"DISPATCH_PROPERTYPUT",
",",
"params",
")",
"\n",
"}"
] |
// PutProperty attempts to mutate a property in the object.
|
[
"PutProperty",
"attempts",
"to",
"mutate",
"a",
"property",
"in",
"the",
"object",
"."
] |
97b6244175ae18ea6eef668034fd6565847501c9
|
https://github.com/go-ole/go-ole/blob/97b6244175ae18ea6eef668034fd6565847501c9/idispatch.go#L92-L94
|
19,412
|
go-ole/go-ole
|
connect.go
|
Create
|
func (c *Connection) Create(progId string) (err error) {
var clsid *GUID
clsid, err = CLSIDFromProgID(progId)
if err != nil {
clsid, err = CLSIDFromString(progId)
if err != nil {
return
}
}
unknown, err := CreateInstance(clsid, IID_IUnknown)
if err != nil {
return
}
c.Object = unknown
return
}
|
go
|
func (c *Connection) Create(progId string) (err error) {
var clsid *GUID
clsid, err = CLSIDFromProgID(progId)
if err != nil {
clsid, err = CLSIDFromString(progId)
if err != nil {
return
}
}
unknown, err := CreateInstance(clsid, IID_IUnknown)
if err != nil {
return
}
c.Object = unknown
return
}
|
[
"func",
"(",
"c",
"*",
"Connection",
")",
"Create",
"(",
"progId",
"string",
")",
"(",
"err",
"error",
")",
"{",
"var",
"clsid",
"*",
"GUID",
"\n",
"clsid",
",",
"err",
"=",
"CLSIDFromProgID",
"(",
"progId",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"clsid",
",",
"err",
"=",
"CLSIDFromString",
"(",
"progId",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"}",
"\n\n",
"unknown",
",",
"err",
":=",
"CreateInstance",
"(",
"clsid",
",",
"IID_IUnknown",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"c",
".",
"Object",
"=",
"unknown",
"\n\n",
"return",
"\n",
"}"
] |
// Create IUnknown object based first on ProgId and then from String.
|
[
"Create",
"IUnknown",
"object",
"based",
"first",
"on",
"ProgId",
"and",
"then",
"from",
"String",
"."
] |
97b6244175ae18ea6eef668034fd6565847501c9
|
https://github.com/go-ole/go-ole/blob/97b6244175ae18ea6eef668034fd6565847501c9/connect.go#L21-L38
|
19,413
|
go-ole/go-ole
|
connect.go
|
Load
|
func (c *Connection) Load(names ...string) (errors []error) {
var tempErrors []error = make([]error, len(names))
var numErrors int = 0
for _, name := range names {
err := c.Create(name)
if err != nil {
tempErrors = append(tempErrors, err)
numErrors += 1
continue
}
break
}
copy(errors, tempErrors[0:numErrors])
return
}
|
go
|
func (c *Connection) Load(names ...string) (errors []error) {
var tempErrors []error = make([]error, len(names))
var numErrors int = 0
for _, name := range names {
err := c.Create(name)
if err != nil {
tempErrors = append(tempErrors, err)
numErrors += 1
continue
}
break
}
copy(errors, tempErrors[0:numErrors])
return
}
|
[
"func",
"(",
"c",
"*",
"Connection",
")",
"Load",
"(",
"names",
"...",
"string",
")",
"(",
"errors",
"[",
"]",
"error",
")",
"{",
"var",
"tempErrors",
"[",
"]",
"error",
"=",
"make",
"(",
"[",
"]",
"error",
",",
"len",
"(",
"names",
")",
")",
"\n",
"var",
"numErrors",
"int",
"=",
"0",
"\n",
"for",
"_",
",",
"name",
":=",
"range",
"names",
"{",
"err",
":=",
"c",
".",
"Create",
"(",
"name",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"tempErrors",
"=",
"append",
"(",
"tempErrors",
",",
"err",
")",
"\n",
"numErrors",
"+=",
"1",
"\n",
"continue",
"\n",
"}",
"\n",
"break",
"\n",
"}",
"\n\n",
"copy",
"(",
"errors",
",",
"tempErrors",
"[",
"0",
":",
"numErrors",
"]",
")",
"\n",
"return",
"\n",
"}"
] |
// Load COM object from list of programIDs or strings.
|
[
"Load",
"COM",
"object",
"from",
"list",
"of",
"programIDs",
"or",
"strings",
"."
] |
97b6244175ae18ea6eef668034fd6565847501c9
|
https://github.com/go-ole/go-ole/blob/97b6244175ae18ea6eef668034fd6565847501c9/connect.go#L46-L61
|
19,414
|
go-ole/go-ole
|
connect.go
|
Dispatch
|
func (c *Connection) Dispatch() (object *Dispatch, err error) {
dispatch, err := c.Object.QueryInterface(IID_IDispatch)
if err != nil {
return
}
object = &Dispatch{dispatch}
return
}
|
go
|
func (c *Connection) Dispatch() (object *Dispatch, err error) {
dispatch, err := c.Object.QueryInterface(IID_IDispatch)
if err != nil {
return
}
object = &Dispatch{dispatch}
return
}
|
[
"func",
"(",
"c",
"*",
"Connection",
")",
"Dispatch",
"(",
")",
"(",
"object",
"*",
"Dispatch",
",",
"err",
"error",
")",
"{",
"dispatch",
",",
"err",
":=",
"c",
".",
"Object",
".",
"QueryInterface",
"(",
"IID_IDispatch",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"object",
"=",
"&",
"Dispatch",
"{",
"dispatch",
"}",
"\n",
"return",
"\n",
"}"
] |
// Dispatch returns Dispatch object.
|
[
"Dispatch",
"returns",
"Dispatch",
"object",
"."
] |
97b6244175ae18ea6eef668034fd6565847501c9
|
https://github.com/go-ole/go-ole/blob/97b6244175ae18ea6eef668034fd6565847501c9/connect.go#L64-L71
|
19,415
|
go-ole/go-ole
|
connect.go
|
Call
|
func (d *Dispatch) Call(method string, params ...interface{}) (result *VARIANT, err error) {
id, err := d.GetId(method)
if err != nil {
return
}
result, err = d.Invoke(id, DISPATCH_METHOD, params)
return
}
|
go
|
func (d *Dispatch) Call(method string, params ...interface{}) (result *VARIANT, err error) {
id, err := d.GetId(method)
if err != nil {
return
}
result, err = d.Invoke(id, DISPATCH_METHOD, params)
return
}
|
[
"func",
"(",
"d",
"*",
"Dispatch",
")",
"Call",
"(",
"method",
"string",
",",
"params",
"...",
"interface",
"{",
"}",
")",
"(",
"result",
"*",
"VARIANT",
",",
"err",
"error",
")",
"{",
"id",
",",
"err",
":=",
"d",
".",
"GetId",
"(",
"method",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"result",
",",
"err",
"=",
"d",
".",
"Invoke",
"(",
"id",
",",
"DISPATCH_METHOD",
",",
"params",
")",
"\n",
"return",
"\n",
"}"
] |
// Call method on IDispatch with parameters.
|
[
"Call",
"method",
"on",
"IDispatch",
"with",
"parameters",
"."
] |
97b6244175ae18ea6eef668034fd6565847501c9
|
https://github.com/go-ole/go-ole/blob/97b6244175ae18ea6eef668034fd6565847501c9/connect.go#L79-L87
|
19,416
|
go-ole/go-ole
|
connect.go
|
MustCall
|
func (d *Dispatch) MustCall(method string, params ...interface{}) (result *VARIANT) {
id, err := d.GetId(method)
if err != nil {
panic(err)
}
result, err = d.Invoke(id, DISPATCH_METHOD, params)
if err != nil {
panic(err)
}
return
}
|
go
|
func (d *Dispatch) MustCall(method string, params ...interface{}) (result *VARIANT) {
id, err := d.GetId(method)
if err != nil {
panic(err)
}
result, err = d.Invoke(id, DISPATCH_METHOD, params)
if err != nil {
panic(err)
}
return
}
|
[
"func",
"(",
"d",
"*",
"Dispatch",
")",
"MustCall",
"(",
"method",
"string",
",",
"params",
"...",
"interface",
"{",
"}",
")",
"(",
"result",
"*",
"VARIANT",
")",
"{",
"id",
",",
"err",
":=",
"d",
".",
"GetId",
"(",
"method",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"result",
",",
"err",
"=",
"d",
".",
"Invoke",
"(",
"id",
",",
"DISPATCH_METHOD",
",",
"params",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"return",
"\n",
"}"
] |
// MustCall method on IDispatch with parameters.
|
[
"MustCall",
"method",
"on",
"IDispatch",
"with",
"parameters",
"."
] |
97b6244175ae18ea6eef668034fd6565847501c9
|
https://github.com/go-ole/go-ole/blob/97b6244175ae18ea6eef668034fd6565847501c9/connect.go#L90-L102
|
19,417
|
go-ole/go-ole
|
connect.go
|
Get
|
func (d *Dispatch) Get(name string, params ...interface{}) (result *VARIANT, err error) {
id, err := d.GetId(name)
if err != nil {
return
}
result, err = d.Invoke(id, DISPATCH_PROPERTYGET, params)
return
}
|
go
|
func (d *Dispatch) Get(name string, params ...interface{}) (result *VARIANT, err error) {
id, err := d.GetId(name)
if err != nil {
return
}
result, err = d.Invoke(id, DISPATCH_PROPERTYGET, params)
return
}
|
[
"func",
"(",
"d",
"*",
"Dispatch",
")",
"Get",
"(",
"name",
"string",
",",
"params",
"...",
"interface",
"{",
"}",
")",
"(",
"result",
"*",
"VARIANT",
",",
"err",
"error",
")",
"{",
"id",
",",
"err",
":=",
"d",
".",
"GetId",
"(",
"name",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"result",
",",
"err",
"=",
"d",
".",
"Invoke",
"(",
"id",
",",
"DISPATCH_PROPERTYGET",
",",
"params",
")",
"\n",
"return",
"\n",
"}"
] |
// Get property on IDispatch with parameters.
|
[
"Get",
"property",
"on",
"IDispatch",
"with",
"parameters",
"."
] |
97b6244175ae18ea6eef668034fd6565847501c9
|
https://github.com/go-ole/go-ole/blob/97b6244175ae18ea6eef668034fd6565847501c9/connect.go#L105-L112
|
19,418
|
go-ole/go-ole
|
connect.go
|
MustGet
|
func (d *Dispatch) MustGet(name string, params ...interface{}) (result *VARIANT) {
id, err := d.GetId(name)
if err != nil {
panic(err)
}
result, err = d.Invoke(id, DISPATCH_PROPERTYGET, params)
if err != nil {
panic(err)
}
return
}
|
go
|
func (d *Dispatch) MustGet(name string, params ...interface{}) (result *VARIANT) {
id, err := d.GetId(name)
if err != nil {
panic(err)
}
result, err = d.Invoke(id, DISPATCH_PROPERTYGET, params)
if err != nil {
panic(err)
}
return
}
|
[
"func",
"(",
"d",
"*",
"Dispatch",
")",
"MustGet",
"(",
"name",
"string",
",",
"params",
"...",
"interface",
"{",
"}",
")",
"(",
"result",
"*",
"VARIANT",
")",
"{",
"id",
",",
"err",
":=",
"d",
".",
"GetId",
"(",
"name",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"result",
",",
"err",
"=",
"d",
".",
"Invoke",
"(",
"id",
",",
"DISPATCH_PROPERTYGET",
",",
"params",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] |
// MustGet property on IDispatch with parameters.
|
[
"MustGet",
"property",
"on",
"IDispatch",
"with",
"parameters",
"."
] |
97b6244175ae18ea6eef668034fd6565847501c9
|
https://github.com/go-ole/go-ole/blob/97b6244175ae18ea6eef668034fd6565847501c9/connect.go#L115-L126
|
19,419
|
go-ole/go-ole
|
connect.go
|
Set
|
func (d *Dispatch) Set(name string, params ...interface{}) (result *VARIANT, err error) {
id, err := d.GetId(name)
if err != nil {
return
}
result, err = d.Invoke(id, DISPATCH_PROPERTYPUT, params)
return
}
|
go
|
func (d *Dispatch) Set(name string, params ...interface{}) (result *VARIANT, err error) {
id, err := d.GetId(name)
if err != nil {
return
}
result, err = d.Invoke(id, DISPATCH_PROPERTYPUT, params)
return
}
|
[
"func",
"(",
"d",
"*",
"Dispatch",
")",
"Set",
"(",
"name",
"string",
",",
"params",
"...",
"interface",
"{",
"}",
")",
"(",
"result",
"*",
"VARIANT",
",",
"err",
"error",
")",
"{",
"id",
",",
"err",
":=",
"d",
".",
"GetId",
"(",
"name",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"result",
",",
"err",
"=",
"d",
".",
"Invoke",
"(",
"id",
",",
"DISPATCH_PROPERTYPUT",
",",
"params",
")",
"\n",
"return",
"\n",
"}"
] |
// Set property on IDispatch with parameters.
|
[
"Set",
"property",
"on",
"IDispatch",
"with",
"parameters",
"."
] |
97b6244175ae18ea6eef668034fd6565847501c9
|
https://github.com/go-ole/go-ole/blob/97b6244175ae18ea6eef668034fd6565847501c9/connect.go#L129-L136
|
19,420
|
go-ole/go-ole
|
connect.go
|
MustSet
|
func (d *Dispatch) MustSet(name string, params ...interface{}) (result *VARIANT) {
id, err := d.GetId(name)
if err != nil {
panic(err)
}
result, err = d.Invoke(id, DISPATCH_PROPERTYPUT, params)
if err != nil {
panic(err)
}
return
}
|
go
|
func (d *Dispatch) MustSet(name string, params ...interface{}) (result *VARIANT) {
id, err := d.GetId(name)
if err != nil {
panic(err)
}
result, err = d.Invoke(id, DISPATCH_PROPERTYPUT, params)
if err != nil {
panic(err)
}
return
}
|
[
"func",
"(",
"d",
"*",
"Dispatch",
")",
"MustSet",
"(",
"name",
"string",
",",
"params",
"...",
"interface",
"{",
"}",
")",
"(",
"result",
"*",
"VARIANT",
")",
"{",
"id",
",",
"err",
":=",
"d",
".",
"GetId",
"(",
"name",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"result",
",",
"err",
"=",
"d",
".",
"Invoke",
"(",
"id",
",",
"DISPATCH_PROPERTYPUT",
",",
"params",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] |
// MustSet property on IDispatch with parameters.
|
[
"MustSet",
"property",
"on",
"IDispatch",
"with",
"parameters",
"."
] |
97b6244175ae18ea6eef668034fd6565847501c9
|
https://github.com/go-ole/go-ole/blob/97b6244175ae18ea6eef668034fd6565847501c9/connect.go#L139-L150
|
19,421
|
go-ole/go-ole
|
connect.go
|
GetId
|
func (d *Dispatch) GetId(name string) (id int32, err error) {
var dispid []int32
dispid, err = d.Object.GetIDsOfName([]string{name})
if err != nil {
return
}
id = dispid[0]
return
}
|
go
|
func (d *Dispatch) GetId(name string) (id int32, err error) {
var dispid []int32
dispid, err = d.Object.GetIDsOfName([]string{name})
if err != nil {
return
}
id = dispid[0]
return
}
|
[
"func",
"(",
"d",
"*",
"Dispatch",
")",
"GetId",
"(",
"name",
"string",
")",
"(",
"id",
"int32",
",",
"err",
"error",
")",
"{",
"var",
"dispid",
"[",
"]",
"int32",
"\n",
"dispid",
",",
"err",
"=",
"d",
".",
"Object",
".",
"GetIDsOfName",
"(",
"[",
"]",
"string",
"{",
"name",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"id",
"=",
"dispid",
"[",
"0",
"]",
"\n",
"return",
"\n",
"}"
] |
// GetId retrieves ID of name on IDispatch.
|
[
"GetId",
"retrieves",
"ID",
"of",
"name",
"on",
"IDispatch",
"."
] |
97b6244175ae18ea6eef668034fd6565847501c9
|
https://github.com/go-ole/go-ole/blob/97b6244175ae18ea6eef668034fd6565847501c9/connect.go#L153-L161
|
19,422
|
go-ole/go-ole
|
connect.go
|
GetIds
|
func (d *Dispatch) GetIds(names ...string) (dispid []int32, err error) {
dispid, err = d.Object.GetIDsOfName(names)
return
}
|
go
|
func (d *Dispatch) GetIds(names ...string) (dispid []int32, err error) {
dispid, err = d.Object.GetIDsOfName(names)
return
}
|
[
"func",
"(",
"d",
"*",
"Dispatch",
")",
"GetIds",
"(",
"names",
"...",
"string",
")",
"(",
"dispid",
"[",
"]",
"int32",
",",
"err",
"error",
")",
"{",
"dispid",
",",
"err",
"=",
"d",
".",
"Object",
".",
"GetIDsOfName",
"(",
"names",
")",
"\n",
"return",
"\n",
"}"
] |
// GetIds retrieves all IDs of names on IDispatch.
|
[
"GetIds",
"retrieves",
"all",
"IDs",
"of",
"names",
"on",
"IDispatch",
"."
] |
97b6244175ae18ea6eef668034fd6565847501c9
|
https://github.com/go-ole/go-ole/blob/97b6244175ae18ea6eef668034fd6565847501c9/connect.go#L164-L167
|
19,423
|
go-ole/go-ole
|
connect.go
|
Invoke
|
func (d *Dispatch) Invoke(id int32, dispatch int16, params []interface{}) (result *VARIANT, err error) {
if len(params) < 1 {
result, err = d.Object.Invoke(id, dispatch)
} else {
result, err = d.Object.Invoke(id, dispatch, params...)
}
return
}
|
go
|
func (d *Dispatch) Invoke(id int32, dispatch int16, params []interface{}) (result *VARIANT, err error) {
if len(params) < 1 {
result, err = d.Object.Invoke(id, dispatch)
} else {
result, err = d.Object.Invoke(id, dispatch, params...)
}
return
}
|
[
"func",
"(",
"d",
"*",
"Dispatch",
")",
"Invoke",
"(",
"id",
"int32",
",",
"dispatch",
"int16",
",",
"params",
"[",
"]",
"interface",
"{",
"}",
")",
"(",
"result",
"*",
"VARIANT",
",",
"err",
"error",
")",
"{",
"if",
"len",
"(",
"params",
")",
"<",
"1",
"{",
"result",
",",
"err",
"=",
"d",
".",
"Object",
".",
"Invoke",
"(",
"id",
",",
"dispatch",
")",
"\n",
"}",
"else",
"{",
"result",
",",
"err",
"=",
"d",
".",
"Object",
".",
"Invoke",
"(",
"id",
",",
"dispatch",
",",
"params",
"...",
")",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] |
// Invoke IDispatch on DisplayID of dispatch type with parameters.
//
// There have been problems where if send cascading params..., it would error
// out because the parameters would be empty.
|
[
"Invoke",
"IDispatch",
"on",
"DisplayID",
"of",
"dispatch",
"type",
"with",
"parameters",
".",
"There",
"have",
"been",
"problems",
"where",
"if",
"send",
"cascading",
"params",
"...",
"it",
"would",
"error",
"out",
"because",
"the",
"parameters",
"would",
"be",
"empty",
"."
] |
97b6244175ae18ea6eef668034fd6565847501c9
|
https://github.com/go-ole/go-ole/blob/97b6244175ae18ea6eef668034fd6565847501c9/connect.go#L173-L180
|
19,424
|
go-ole/go-ole
|
connect.go
|
Connect
|
func Connect(names ...string) (connection *Connection) {
connection.Initialize()
connection.Load(names...)
return
}
|
go
|
func Connect(names ...string) (connection *Connection) {
connection.Initialize()
connection.Load(names...)
return
}
|
[
"func",
"Connect",
"(",
"names",
"...",
"string",
")",
"(",
"connection",
"*",
"Connection",
")",
"{",
"connection",
".",
"Initialize",
"(",
")",
"\n",
"connection",
".",
"Load",
"(",
"names",
"...",
")",
"\n",
"return",
"\n",
"}"
] |
// Connect initializes COM and attempts to load IUnknown based on given names.
|
[
"Connect",
"initializes",
"COM",
"and",
"attempts",
"to",
"load",
"IUnknown",
"based",
"on",
"given",
"names",
"."
] |
97b6244175ae18ea6eef668034fd6565847501c9
|
https://github.com/go-ole/go-ole/blob/97b6244175ae18ea6eef668034fd6565847501c9/connect.go#L188-L192
|
19,425
|
go-ole/go-ole
|
safearray_windows.go
|
safeArrayGetElementString
|
func safeArrayGetElementString(safearray *SafeArray, index int32) (str string, err error) {
var element *int16
err = convertHresultToError(
procSafeArrayGetElement.Call(
uintptr(unsafe.Pointer(safearray)),
uintptr(unsafe.Pointer(&index)),
uintptr(unsafe.Pointer(&element))))
str = BstrToString(*(**uint16)(unsafe.Pointer(&element)))
SysFreeString(element)
return
}
|
go
|
func safeArrayGetElementString(safearray *SafeArray, index int32) (str string, err error) {
var element *int16
err = convertHresultToError(
procSafeArrayGetElement.Call(
uintptr(unsafe.Pointer(safearray)),
uintptr(unsafe.Pointer(&index)),
uintptr(unsafe.Pointer(&element))))
str = BstrToString(*(**uint16)(unsafe.Pointer(&element)))
SysFreeString(element)
return
}
|
[
"func",
"safeArrayGetElementString",
"(",
"safearray",
"*",
"SafeArray",
",",
"index",
"int32",
")",
"(",
"str",
"string",
",",
"err",
"error",
")",
"{",
"var",
"element",
"*",
"int16",
"\n",
"err",
"=",
"convertHresultToError",
"(",
"procSafeArrayGetElement",
".",
"Call",
"(",
"uintptr",
"(",
"unsafe",
".",
"Pointer",
"(",
"safearray",
")",
")",
",",
"uintptr",
"(",
"unsafe",
".",
"Pointer",
"(",
"&",
"index",
")",
")",
",",
"uintptr",
"(",
"unsafe",
".",
"Pointer",
"(",
"&",
"element",
")",
")",
")",
")",
"\n",
"str",
"=",
"BstrToString",
"(",
"*",
"(",
"*",
"*",
"uint16",
")",
"(",
"unsafe",
".",
"Pointer",
"(",
"&",
"element",
")",
")",
")",
"\n",
"SysFreeString",
"(",
"element",
")",
"\n",
"return",
"\n",
"}"
] |
// safeArrayGetElementString retrieves element at given index and converts to string.
|
[
"safeArrayGetElementString",
"retrieves",
"element",
"at",
"given",
"index",
"and",
"converts",
"to",
"string",
"."
] |
97b6244175ae18ea6eef668034fd6565847501c9
|
https://github.com/go-ole/go-ole/blob/97b6244175ae18ea6eef668034fd6565847501c9/safearray_windows.go#L217-L227
|
19,426
|
go-ole/go-ole
|
utility.go
|
ClassIDFrom
|
func ClassIDFrom(programID string) (classID *GUID, err error) {
classID, err = CLSIDFromProgID(programID)
if err != nil {
classID, err = CLSIDFromString(programID)
if err != nil {
return
}
}
return
}
|
go
|
func ClassIDFrom(programID string) (classID *GUID, err error) {
classID, err = CLSIDFromProgID(programID)
if err != nil {
classID, err = CLSIDFromString(programID)
if err != nil {
return
}
}
return
}
|
[
"func",
"ClassIDFrom",
"(",
"programID",
"string",
")",
"(",
"classID",
"*",
"GUID",
",",
"err",
"error",
")",
"{",
"classID",
",",
"err",
"=",
"CLSIDFromProgID",
"(",
"programID",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"classID",
",",
"err",
"=",
"CLSIDFromString",
"(",
"programID",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] |
// ClassIDFrom retrieves class ID whether given is program ID or application string.
//
// Helper that provides check against both Class ID from Program ID and Class ID from string. It is
// faster, if you know which you are using, to use the individual functions, but this will check
// against available functions for you.
|
[
"ClassIDFrom",
"retrieves",
"class",
"ID",
"whether",
"given",
"is",
"program",
"ID",
"or",
"application",
"string",
".",
"Helper",
"that",
"provides",
"check",
"against",
"both",
"Class",
"ID",
"from",
"Program",
"ID",
"and",
"Class",
"ID",
"from",
"string",
".",
"It",
"is",
"faster",
"if",
"you",
"know",
"which",
"you",
"are",
"using",
"to",
"use",
"the",
"individual",
"functions",
"but",
"this",
"will",
"check",
"against",
"available",
"functions",
"for",
"you",
"."
] |
97b6244175ae18ea6eef668034fd6565847501c9
|
https://github.com/go-ole/go-ole/blob/97b6244175ae18ea6eef668034fd6565847501c9/utility.go#L13-L22
|
19,427
|
go-ole/go-ole
|
utility.go
|
BytePtrToString
|
func BytePtrToString(p *byte) string {
a := (*[10000]uint8)(unsafe.Pointer(p))
i := 0
for a[i] != 0 {
i++
}
return string(a[:i])
}
|
go
|
func BytePtrToString(p *byte) string {
a := (*[10000]uint8)(unsafe.Pointer(p))
i := 0
for a[i] != 0 {
i++
}
return string(a[:i])
}
|
[
"func",
"BytePtrToString",
"(",
"p",
"*",
"byte",
")",
"string",
"{",
"a",
":=",
"(",
"*",
"[",
"10000",
"]",
"uint8",
")",
"(",
"unsafe",
".",
"Pointer",
"(",
"p",
")",
")",
"\n",
"i",
":=",
"0",
"\n",
"for",
"a",
"[",
"i",
"]",
"!=",
"0",
"{",
"i",
"++",
"\n",
"}",
"\n",
"return",
"string",
"(",
"a",
"[",
":",
"i",
"]",
")",
"\n",
"}"
] |
// BytePtrToString converts byte pointer to a Go string.
|
[
"BytePtrToString",
"converts",
"byte",
"pointer",
"to",
"a",
"Go",
"string",
"."
] |
97b6244175ae18ea6eef668034fd6565847501c9
|
https://github.com/go-ole/go-ole/blob/97b6244175ae18ea6eef668034fd6565847501c9/utility.go#L25-L32
|
19,428
|
go-ole/go-ole
|
utility.go
|
LpOleStrToString
|
func LpOleStrToString(p *uint16) string {
if p == nil {
return ""
}
length := lpOleStrLen(p)
a := make([]uint16, length)
ptr := unsafe.Pointer(p)
for i := 0; i < int(length); i++ {
a[i] = *(*uint16)(ptr)
ptr = unsafe.Pointer(uintptr(ptr) + 2)
}
return string(utf16.Decode(a))
}
|
go
|
func LpOleStrToString(p *uint16) string {
if p == nil {
return ""
}
length := lpOleStrLen(p)
a := make([]uint16, length)
ptr := unsafe.Pointer(p)
for i := 0; i < int(length); i++ {
a[i] = *(*uint16)(ptr)
ptr = unsafe.Pointer(uintptr(ptr) + 2)
}
return string(utf16.Decode(a))
}
|
[
"func",
"LpOleStrToString",
"(",
"p",
"*",
"uint16",
")",
"string",
"{",
"if",
"p",
"==",
"nil",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n\n",
"length",
":=",
"lpOleStrLen",
"(",
"p",
")",
"\n",
"a",
":=",
"make",
"(",
"[",
"]",
"uint16",
",",
"length",
")",
"\n\n",
"ptr",
":=",
"unsafe",
".",
"Pointer",
"(",
"p",
")",
"\n\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"int",
"(",
"length",
")",
";",
"i",
"++",
"{",
"a",
"[",
"i",
"]",
"=",
"*",
"(",
"*",
"uint16",
")",
"(",
"ptr",
")",
"\n",
"ptr",
"=",
"unsafe",
".",
"Pointer",
"(",
"uintptr",
"(",
"ptr",
")",
"+",
"2",
")",
"\n",
"}",
"\n\n",
"return",
"string",
"(",
"utf16",
".",
"Decode",
"(",
"a",
")",
")",
"\n",
"}"
] |
// LpOleStrToString converts COM Unicode to Go string.
|
[
"LpOleStrToString",
"converts",
"COM",
"Unicode",
"to",
"Go",
"string",
"."
] |
97b6244175ae18ea6eef668034fd6565847501c9
|
https://github.com/go-ole/go-ole/blob/97b6244175ae18ea6eef668034fd6565847501c9/utility.go#L42-L58
|
19,429
|
go-ole/go-ole
|
utility.go
|
BstrToString
|
func BstrToString(p *uint16) string {
if p == nil {
return ""
}
length := SysStringLen((*int16)(unsafe.Pointer(p)))
a := make([]uint16, length)
ptr := unsafe.Pointer(p)
for i := 0; i < int(length); i++ {
a[i] = *(*uint16)(ptr)
ptr = unsafe.Pointer(uintptr(ptr) + 2)
}
return string(utf16.Decode(a))
}
|
go
|
func BstrToString(p *uint16) string {
if p == nil {
return ""
}
length := SysStringLen((*int16)(unsafe.Pointer(p)))
a := make([]uint16, length)
ptr := unsafe.Pointer(p)
for i := 0; i < int(length); i++ {
a[i] = *(*uint16)(ptr)
ptr = unsafe.Pointer(uintptr(ptr) + 2)
}
return string(utf16.Decode(a))
}
|
[
"func",
"BstrToString",
"(",
"p",
"*",
"uint16",
")",
"string",
"{",
"if",
"p",
"==",
"nil",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n",
"length",
":=",
"SysStringLen",
"(",
"(",
"*",
"int16",
")",
"(",
"unsafe",
".",
"Pointer",
"(",
"p",
")",
")",
")",
"\n",
"a",
":=",
"make",
"(",
"[",
"]",
"uint16",
",",
"length",
")",
"\n\n",
"ptr",
":=",
"unsafe",
".",
"Pointer",
"(",
"p",
")",
"\n\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"int",
"(",
"length",
")",
";",
"i",
"++",
"{",
"a",
"[",
"i",
"]",
"=",
"*",
"(",
"*",
"uint16",
")",
"(",
"ptr",
")",
"\n",
"ptr",
"=",
"unsafe",
".",
"Pointer",
"(",
"uintptr",
"(",
"ptr",
")",
"+",
"2",
")",
"\n",
"}",
"\n",
"return",
"string",
"(",
"utf16",
".",
"Decode",
"(",
"a",
")",
")",
"\n",
"}"
] |
// BstrToString converts COM binary string to Go string.
|
[
"BstrToString",
"converts",
"COM",
"binary",
"string",
"to",
"Go",
"string",
"."
] |
97b6244175ae18ea6eef668034fd6565847501c9
|
https://github.com/go-ole/go-ole/blob/97b6244175ae18ea6eef668034fd6565847501c9/utility.go#L61-L75
|
19,430
|
go-ole/go-ole
|
utility.go
|
lpOleStrLen
|
func lpOleStrLen(p *uint16) (length int64) {
if p == nil {
return 0
}
ptr := unsafe.Pointer(p)
for i := 0; ; i++ {
if 0 == *(*uint16)(ptr) {
length = int64(i)
break
}
ptr = unsafe.Pointer(uintptr(ptr) + 2)
}
return
}
|
go
|
func lpOleStrLen(p *uint16) (length int64) {
if p == nil {
return 0
}
ptr := unsafe.Pointer(p)
for i := 0; ; i++ {
if 0 == *(*uint16)(ptr) {
length = int64(i)
break
}
ptr = unsafe.Pointer(uintptr(ptr) + 2)
}
return
}
|
[
"func",
"lpOleStrLen",
"(",
"p",
"*",
"uint16",
")",
"(",
"length",
"int64",
")",
"{",
"if",
"p",
"==",
"nil",
"{",
"return",
"0",
"\n",
"}",
"\n\n",
"ptr",
":=",
"unsafe",
".",
"Pointer",
"(",
"p",
")",
"\n\n",
"for",
"i",
":=",
"0",
";",
";",
"i",
"++",
"{",
"if",
"0",
"==",
"*",
"(",
"*",
"uint16",
")",
"(",
"ptr",
")",
"{",
"length",
"=",
"int64",
"(",
"i",
")",
"\n",
"break",
"\n",
"}",
"\n",
"ptr",
"=",
"unsafe",
".",
"Pointer",
"(",
"uintptr",
"(",
"ptr",
")",
"+",
"2",
")",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] |
// lpOleStrLen returns the length of Unicode string.
|
[
"lpOleStrLen",
"returns",
"the",
"length",
"of",
"Unicode",
"string",
"."
] |
97b6244175ae18ea6eef668034fd6565847501c9
|
https://github.com/go-ole/go-ole/blob/97b6244175ae18ea6eef668034fd6565847501c9/utility.go#L78-L93
|
19,431
|
go-ole/go-ole
|
utility.go
|
convertHresultToError
|
func convertHresultToError(hr uintptr, r2 uintptr, ignore error) (err error) {
if hr != 0 {
err = NewError(hr)
}
return
}
|
go
|
func convertHresultToError(hr uintptr, r2 uintptr, ignore error) (err error) {
if hr != 0 {
err = NewError(hr)
}
return
}
|
[
"func",
"convertHresultToError",
"(",
"hr",
"uintptr",
",",
"r2",
"uintptr",
",",
"ignore",
"error",
")",
"(",
"err",
"error",
")",
"{",
"if",
"hr",
"!=",
"0",
"{",
"err",
"=",
"NewError",
"(",
"hr",
")",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] |
// convertHresultToError converts syscall to error, if call is unsuccessful.
|
[
"convertHresultToError",
"converts",
"syscall",
"to",
"error",
"if",
"call",
"is",
"unsuccessful",
"."
] |
97b6244175ae18ea6eef668034fd6565847501c9
|
https://github.com/go-ole/go-ole/blob/97b6244175ae18ea6eef668034fd6565847501c9/utility.go#L96-L101
|
19,432
|
go-ole/go-ole
|
error_windows.go
|
errstr
|
func errstr(errno int) string {
// ask windows for the remaining errors
var flags uint32 = syscall.FORMAT_MESSAGE_FROM_SYSTEM | syscall.FORMAT_MESSAGE_ARGUMENT_ARRAY | syscall.FORMAT_MESSAGE_IGNORE_INSERTS
b := make([]uint16, 300)
n, err := syscall.FormatMessage(flags, 0, uint32(errno), 0, b, nil)
if err != nil {
return fmt.Sprintf("error %d (FormatMessage failed with: %v)", errno, err)
}
// trim terminating \r and \n
for ; n > 0 && (b[n-1] == '\n' || b[n-1] == '\r'); n-- {
}
return string(utf16.Decode(b[:n]))
}
|
go
|
func errstr(errno int) string {
// ask windows for the remaining errors
var flags uint32 = syscall.FORMAT_MESSAGE_FROM_SYSTEM | syscall.FORMAT_MESSAGE_ARGUMENT_ARRAY | syscall.FORMAT_MESSAGE_IGNORE_INSERTS
b := make([]uint16, 300)
n, err := syscall.FormatMessage(flags, 0, uint32(errno), 0, b, nil)
if err != nil {
return fmt.Sprintf("error %d (FormatMessage failed with: %v)", errno, err)
}
// trim terminating \r and \n
for ; n > 0 && (b[n-1] == '\n' || b[n-1] == '\r'); n-- {
}
return string(utf16.Decode(b[:n]))
}
|
[
"func",
"errstr",
"(",
"errno",
"int",
")",
"string",
"{",
"// ask windows for the remaining errors",
"var",
"flags",
"uint32",
"=",
"syscall",
".",
"FORMAT_MESSAGE_FROM_SYSTEM",
"|",
"syscall",
".",
"FORMAT_MESSAGE_ARGUMENT_ARRAY",
"|",
"syscall",
".",
"FORMAT_MESSAGE_IGNORE_INSERTS",
"\n",
"b",
":=",
"make",
"(",
"[",
"]",
"uint16",
",",
"300",
")",
"\n",
"n",
",",
"err",
":=",
"syscall",
".",
"FormatMessage",
"(",
"flags",
",",
"0",
",",
"uint32",
"(",
"errno",
")",
",",
"0",
",",
"b",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"errno",
",",
"err",
")",
"\n",
"}",
"\n",
"// trim terminating \\r and \\n",
"for",
";",
"n",
">",
"0",
"&&",
"(",
"b",
"[",
"n",
"-",
"1",
"]",
"==",
"'\\n'",
"||",
"b",
"[",
"n",
"-",
"1",
"]",
"==",
"'\\r'",
")",
";",
"n",
"--",
"{",
"}",
"\n",
"return",
"string",
"(",
"utf16",
".",
"Decode",
"(",
"b",
"[",
":",
"n",
"]",
")",
")",
"\n",
"}"
] |
// errstr converts error code to string.
|
[
"errstr",
"converts",
"error",
"code",
"to",
"string",
"."
] |
97b6244175ae18ea6eef668034fd6565847501c9
|
https://github.com/go-ole/go-ole/blob/97b6244175ae18ea6eef668034fd6565847501c9/error_windows.go#L12-L24
|
19,433
|
go-ole/go-ole
|
_example/libreoffice/libreoffice.go
|
LOGetCellString
|
func LOGetCellString(cell *ole.IDispatch) (value string) {
return oleutil.MustGetProperty(cell, "string").ToString()
}
|
go
|
func LOGetCellString(cell *ole.IDispatch) (value string) {
return oleutil.MustGetProperty(cell, "string").ToString()
}
|
[
"func",
"LOGetCellString",
"(",
"cell",
"*",
"ole",
".",
"IDispatch",
")",
"(",
"value",
"string",
")",
"{",
"return",
"oleutil",
".",
"MustGetProperty",
"(",
"cell",
",",
"\"",
"\"",
")",
".",
"ToString",
"(",
")",
"\n",
"}"
] |
// LOGetCellString returns the displayed value
|
[
"LOGetCellString",
"returns",
"the",
"displayed",
"value"
] |
97b6244175ae18ea6eef668034fd6565847501c9
|
https://github.com/go-ole/go-ole/blob/97b6244175ae18ea6eef668034fd6565847501c9/_example/libreoffice/libreoffice.go#L63-L65
|
19,434
|
go-ole/go-ole
|
_example/libreoffice/libreoffice.go
|
LOSetCellString
|
func LOSetCellString(cell *ole.IDispatch, text string) {
oleutil.MustPutProperty(cell, "string", text)
}
|
go
|
func LOSetCellString(cell *ole.IDispatch, text string) {
oleutil.MustPutProperty(cell, "string", text)
}
|
[
"func",
"LOSetCellString",
"(",
"cell",
"*",
"ole",
".",
"IDispatch",
",",
"text",
"string",
")",
"{",
"oleutil",
".",
"MustPutProperty",
"(",
"cell",
",",
"\"",
"\"",
",",
"text",
")",
"\n",
"}"
] |
// LOSetCellString sets the text value of a cell
|
[
"LOSetCellString",
"sets",
"the",
"text",
"value",
"of",
"a",
"cell"
] |
97b6244175ae18ea6eef668034fd6565847501c9
|
https://github.com/go-ole/go-ole/blob/97b6244175ae18ea6eef668034fd6565847501c9/_example/libreoffice/libreoffice.go#L80-L82
|
19,435
|
go-ole/go-ole
|
_example/libreoffice/libreoffice.go
|
LOSetCellValue
|
func LOSetCellValue(cell *ole.IDispatch, value float64) {
oleutil.MustPutProperty(cell, "value", value)
}
|
go
|
func LOSetCellValue(cell *ole.IDispatch, value float64) {
oleutil.MustPutProperty(cell, "value", value)
}
|
[
"func",
"LOSetCellValue",
"(",
"cell",
"*",
"ole",
".",
"IDispatch",
",",
"value",
"float64",
")",
"{",
"oleutil",
".",
"MustPutProperty",
"(",
"cell",
",",
"\"",
"\"",
",",
"value",
")",
"\n",
"}"
] |
// LOSetCellValue sets the numeric value of a cell
|
[
"LOSetCellValue",
"sets",
"the",
"numeric",
"value",
"of",
"a",
"cell"
] |
97b6244175ae18ea6eef668034fd6565847501c9
|
https://github.com/go-ole/go-ole/blob/97b6244175ae18ea6eef668034fd6565847501c9/_example/libreoffice/libreoffice.go#L85-L87
|
19,436
|
go-ole/go-ole
|
_example/libreoffice/libreoffice.go
|
LONewSpreadsheet
|
func LONewSpreadsheet(desktop *ole.IDispatch) (document *ole.IDispatch) {
var args = []string{}
document = oleutil.MustCallMethod(desktop,
"loadComponentFromURL", "private:factory/scalc", // alternative: private:factory/swriter
"_blank", 0, args).ToIDispatch()
return
}
|
go
|
func LONewSpreadsheet(desktop *ole.IDispatch) (document *ole.IDispatch) {
var args = []string{}
document = oleutil.MustCallMethod(desktop,
"loadComponentFromURL", "private:factory/scalc", // alternative: private:factory/swriter
"_blank", 0, args).ToIDispatch()
return
}
|
[
"func",
"LONewSpreadsheet",
"(",
"desktop",
"*",
"ole",
".",
"IDispatch",
")",
"(",
"document",
"*",
"ole",
".",
"IDispatch",
")",
"{",
"var",
"args",
"=",
"[",
"]",
"string",
"{",
"}",
"\n",
"document",
"=",
"oleutil",
".",
"MustCallMethod",
"(",
"desktop",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"// alternative: private:factory/swriter",
"\"",
"\"",
",",
"0",
",",
"args",
")",
".",
"ToIDispatch",
"(",
")",
"\n",
"return",
"\n",
"}"
] |
// LONewSpreadsheet creates a new spreadsheet in a new window and returns a document handle.
|
[
"LONewSpreadsheet",
"creates",
"a",
"new",
"spreadsheet",
"in",
"a",
"new",
"window",
"and",
"returns",
"a",
"document",
"handle",
"."
] |
97b6244175ae18ea6eef668034fd6565847501c9
|
https://github.com/go-ole/go-ole/blob/97b6244175ae18ea6eef668034fd6565847501c9/_example/libreoffice/libreoffice.go#L100-L106
|
19,437
|
go-ole/go-ole
|
_example/libreoffice/libreoffice.go
|
main
|
func main() {
ole.CoInitialize(0)
unknown, errCreate := oleutil.CreateObject("com.sun.star.ServiceManager")
checkError(errCreate, "Couldn't create a OLE connection to LibreOffice")
ServiceManager, errSM := unknown.QueryInterface(ole.IID_IDispatch)
checkError(errSM, "Couldn't start a LibreOffice instance")
desktop := oleutil.MustCallMethod(ServiceManager,
"createInstance", "com.sun.star.frame.Desktop").ToIDispatch()
document := LONewSpreadsheet(desktop)
sheet0 := LOGetWorksheet(document, 0)
cell1_1 := LOGetCell(sheet0, 1, 1) // cell B2
cell1_2 := LOGetCell(sheet0, 1, 2) // cell B3
cell1_3 := LOGetCell(sheet0, 1, 3) // cell B4
cell1_4 := LOGetCell(sheet0, 1, 4) // cell B5
LOSetCellString(cell1_1, "Hello World")
LOSetCellValue(cell1_2, 33.45)
LOSetCellFormula(cell1_3, "=B3+5")
b4Value := LOGetCellString(cell1_3)
LOSetCellString(cell1_4, b4Value)
// set background color yellow:
oleutil.MustPutProperty(cell1_1, "cellbackcolor", 0xFFFF00)
fmt.Printf("Press [ENTER] to exit")
fmt.Scanf("%s")
ServiceManager.Release()
ole.CoUninitialize()
}
|
go
|
func main() {
ole.CoInitialize(0)
unknown, errCreate := oleutil.CreateObject("com.sun.star.ServiceManager")
checkError(errCreate, "Couldn't create a OLE connection to LibreOffice")
ServiceManager, errSM := unknown.QueryInterface(ole.IID_IDispatch)
checkError(errSM, "Couldn't start a LibreOffice instance")
desktop := oleutil.MustCallMethod(ServiceManager,
"createInstance", "com.sun.star.frame.Desktop").ToIDispatch()
document := LONewSpreadsheet(desktop)
sheet0 := LOGetWorksheet(document, 0)
cell1_1 := LOGetCell(sheet0, 1, 1) // cell B2
cell1_2 := LOGetCell(sheet0, 1, 2) // cell B3
cell1_3 := LOGetCell(sheet0, 1, 3) // cell B4
cell1_4 := LOGetCell(sheet0, 1, 4) // cell B5
LOSetCellString(cell1_1, "Hello World")
LOSetCellValue(cell1_2, 33.45)
LOSetCellFormula(cell1_3, "=B3+5")
b4Value := LOGetCellString(cell1_3)
LOSetCellString(cell1_4, b4Value)
// set background color yellow:
oleutil.MustPutProperty(cell1_1, "cellbackcolor", 0xFFFF00)
fmt.Printf("Press [ENTER] to exit")
fmt.Scanf("%s")
ServiceManager.Release()
ole.CoUninitialize()
}
|
[
"func",
"main",
"(",
")",
"{",
"ole",
".",
"CoInitialize",
"(",
"0",
")",
"\n",
"unknown",
",",
"errCreate",
":=",
"oleutil",
".",
"CreateObject",
"(",
"\"",
"\"",
")",
"\n",
"checkError",
"(",
"errCreate",
",",
"\"",
"\"",
")",
"\n",
"ServiceManager",
",",
"errSM",
":=",
"unknown",
".",
"QueryInterface",
"(",
"ole",
".",
"IID_IDispatch",
")",
"\n",
"checkError",
"(",
"errSM",
",",
"\"",
"\"",
")",
"\n",
"desktop",
":=",
"oleutil",
".",
"MustCallMethod",
"(",
"ServiceManager",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
".",
"ToIDispatch",
"(",
")",
"\n\n",
"document",
":=",
"LONewSpreadsheet",
"(",
"desktop",
")",
"\n",
"sheet0",
":=",
"LOGetWorksheet",
"(",
"document",
",",
"0",
")",
"\n\n",
"cell1_1",
":=",
"LOGetCell",
"(",
"sheet0",
",",
"1",
",",
"1",
")",
"// cell B2",
"\n",
"cell1_2",
":=",
"LOGetCell",
"(",
"sheet0",
",",
"1",
",",
"2",
")",
"// cell B3",
"\n",
"cell1_3",
":=",
"LOGetCell",
"(",
"sheet0",
",",
"1",
",",
"3",
")",
"// cell B4",
"\n",
"cell1_4",
":=",
"LOGetCell",
"(",
"sheet0",
",",
"1",
",",
"4",
")",
"// cell B5",
"\n",
"LOSetCellString",
"(",
"cell1_1",
",",
"\"",
"\"",
")",
"\n",
"LOSetCellValue",
"(",
"cell1_2",
",",
"33.45",
")",
"\n",
"LOSetCellFormula",
"(",
"cell1_3",
",",
"\"",
"\"",
")",
"\n",
"b4Value",
":=",
"LOGetCellString",
"(",
"cell1_3",
")",
"\n",
"LOSetCellString",
"(",
"cell1_4",
",",
"b4Value",
")",
"\n",
"// set background color yellow:",
"oleutil",
".",
"MustPutProperty",
"(",
"cell1_1",
",",
"\"",
"\"",
",",
"0xFFFF00",
")",
"\n\n",
"fmt",
".",
"Printf",
"(",
"\"",
"\"",
")",
"\n",
"fmt",
".",
"Scanf",
"(",
"\"",
"\"",
")",
"\n",
"ServiceManager",
".",
"Release",
"(",
")",
"\n",
"ole",
".",
"CoUninitialize",
"(",
")",
"\n",
"}"
] |
// This example creates a new spreadsheet, reads and modifies cell values and style.
|
[
"This",
"example",
"creates",
"a",
"new",
"spreadsheet",
"reads",
"and",
"modifies",
"cell",
"values",
"and",
"style",
"."
] |
97b6244175ae18ea6eef668034fd6565847501c9
|
https://github.com/go-ole/go-ole/blob/97b6244175ae18ea6eef668034fd6565847501c9/_example/libreoffice/libreoffice.go#L134-L162
|
19,438
|
go-ole/go-ole
|
error.go
|
NewErrorWithDescription
|
func NewErrorWithDescription(hr uintptr, description string) *OleError {
return &OleError{hr: hr, description: description}
}
|
go
|
func NewErrorWithDescription(hr uintptr, description string) *OleError {
return &OleError{hr: hr, description: description}
}
|
[
"func",
"NewErrorWithDescription",
"(",
"hr",
"uintptr",
",",
"description",
"string",
")",
"*",
"OleError",
"{",
"return",
"&",
"OleError",
"{",
"hr",
":",
"hr",
",",
"description",
":",
"description",
"}",
"\n",
"}"
] |
// NewErrorWithDescription creates new COM error with HResult and description.
|
[
"NewErrorWithDescription",
"creates",
"new",
"COM",
"error",
"with",
"HResult",
"and",
"description",
"."
] |
97b6244175ae18ea6eef668034fd6565847501c9
|
https://github.com/go-ole/go-ole/blob/97b6244175ae18ea6eef668034fd6565847501c9/error.go#L16-L18
|
19,439
|
go-ole/go-ole
|
error.go
|
NewErrorWithSubError
|
func NewErrorWithSubError(hr uintptr, description string, err error) *OleError {
return &OleError{hr: hr, description: description, subError: err}
}
|
go
|
func NewErrorWithSubError(hr uintptr, description string, err error) *OleError {
return &OleError{hr: hr, description: description, subError: err}
}
|
[
"func",
"NewErrorWithSubError",
"(",
"hr",
"uintptr",
",",
"description",
"string",
",",
"err",
"error",
")",
"*",
"OleError",
"{",
"return",
"&",
"OleError",
"{",
"hr",
":",
"hr",
",",
"description",
":",
"description",
",",
"subError",
":",
"err",
"}",
"\n",
"}"
] |
// NewErrorWithSubError creates new COM error with parent error.
|
[
"NewErrorWithSubError",
"creates",
"new",
"COM",
"error",
"with",
"parent",
"error",
"."
] |
97b6244175ae18ea6eef668034fd6565847501c9
|
https://github.com/go-ole/go-ole/blob/97b6244175ae18ea6eef668034fd6565847501c9/error.go#L21-L23
|
19,440
|
go-ole/go-ole
|
error.go
|
String
|
func (v *OleError) String() string {
if v.description != "" {
return errstr(int(v.hr)) + " (" + v.description + ")"
}
return errstr(int(v.hr))
}
|
go
|
func (v *OleError) String() string {
if v.description != "" {
return errstr(int(v.hr)) + " (" + v.description + ")"
}
return errstr(int(v.hr))
}
|
[
"func",
"(",
"v",
"*",
"OleError",
")",
"String",
"(",
")",
"string",
"{",
"if",
"v",
".",
"description",
"!=",
"\"",
"\"",
"{",
"return",
"errstr",
"(",
"int",
"(",
"v",
".",
"hr",
")",
")",
"+",
"\"",
"\"",
"+",
"v",
".",
"description",
"+",
"\"",
"\"",
"\n",
"}",
"\n",
"return",
"errstr",
"(",
"int",
"(",
"v",
".",
"hr",
")",
")",
"\n",
"}"
] |
// String description, either manually set or format message with error code.
|
[
"String",
"description",
"either",
"manually",
"set",
"or",
"format",
"message",
"with",
"error",
"code",
"."
] |
97b6244175ae18ea6eef668034fd6565847501c9
|
https://github.com/go-ole/go-ole/blob/97b6244175ae18ea6eef668034fd6565847501c9/error.go#L31-L36
|
19,441
|
go-ole/go-ole
|
winrt.go
|
DeleteHString
|
func DeleteHString(hstring HString) (err error) {
hr, _, _ := procWindowsDeleteString.Call(uintptr(hstring))
if hr != 0 {
err = NewError(hr)
}
return
}
|
go
|
func DeleteHString(hstring HString) (err error) {
hr, _, _ := procWindowsDeleteString.Call(uintptr(hstring))
if hr != 0 {
err = NewError(hr)
}
return
}
|
[
"func",
"DeleteHString",
"(",
"hstring",
"HString",
")",
"(",
"err",
"error",
")",
"{",
"hr",
",",
"_",
",",
"_",
":=",
"procWindowsDeleteString",
".",
"Call",
"(",
"uintptr",
"(",
"hstring",
")",
")",
"\n",
"if",
"hr",
"!=",
"0",
"{",
"err",
"=",
"NewError",
"(",
"hr",
")",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] |
// DeleteHString deletes HString.
|
[
"DeleteHString",
"deletes",
"HString",
"."
] |
97b6244175ae18ea6eef668034fd6565847501c9
|
https://github.com/go-ole/go-ole/blob/97b6244175ae18ea6eef668034fd6565847501c9/winrt.go#L80-L86
|
19,442
|
go-ole/go-ole
|
winrt.go
|
String
|
func (h HString) String() string {
var u16buf uintptr
var u16len uint32
u16buf, _, _ = procWindowsGetStringRawBuffer.Call(
uintptr(h),
uintptr(unsafe.Pointer(&u16len)))
u16hdr := reflect.SliceHeader{Data: u16buf, Len: int(u16len), Cap: int(u16len)}
u16 := *(*[]uint16)(unsafe.Pointer(&u16hdr))
return syscall.UTF16ToString(u16)
}
|
go
|
func (h HString) String() string {
var u16buf uintptr
var u16len uint32
u16buf, _, _ = procWindowsGetStringRawBuffer.Call(
uintptr(h),
uintptr(unsafe.Pointer(&u16len)))
u16hdr := reflect.SliceHeader{Data: u16buf, Len: int(u16len), Cap: int(u16len)}
u16 := *(*[]uint16)(unsafe.Pointer(&u16hdr))
return syscall.UTF16ToString(u16)
}
|
[
"func",
"(",
"h",
"HString",
")",
"String",
"(",
")",
"string",
"{",
"var",
"u16buf",
"uintptr",
"\n",
"var",
"u16len",
"uint32",
"\n",
"u16buf",
",",
"_",
",",
"_",
"=",
"procWindowsGetStringRawBuffer",
".",
"Call",
"(",
"uintptr",
"(",
"h",
")",
",",
"uintptr",
"(",
"unsafe",
".",
"Pointer",
"(",
"&",
"u16len",
")",
")",
")",
"\n\n",
"u16hdr",
":=",
"reflect",
".",
"SliceHeader",
"{",
"Data",
":",
"u16buf",
",",
"Len",
":",
"int",
"(",
"u16len",
")",
",",
"Cap",
":",
"int",
"(",
"u16len",
")",
"}",
"\n",
"u16",
":=",
"*",
"(",
"*",
"[",
"]",
"uint16",
")",
"(",
"unsafe",
".",
"Pointer",
"(",
"&",
"u16hdr",
")",
")",
"\n",
"return",
"syscall",
".",
"UTF16ToString",
"(",
"u16",
")",
"\n",
"}"
] |
// String returns Go string value of HString.
|
[
"String",
"returns",
"Go",
"string",
"value",
"of",
"HString",
"."
] |
97b6244175ae18ea6eef668034fd6565847501c9
|
https://github.com/go-ole/go-ole/blob/97b6244175ae18ea6eef668034fd6565847501c9/winrt.go#L89-L99
|
19,443
|
go-ole/go-ole
|
oleutil/oleutil.go
|
ClassIDFrom
|
func ClassIDFrom(programID string) (classID *ole.GUID, err error) {
return ole.ClassIDFrom(programID)
}
|
go
|
func ClassIDFrom(programID string) (classID *ole.GUID, err error) {
return ole.ClassIDFrom(programID)
}
|
[
"func",
"ClassIDFrom",
"(",
"programID",
"string",
")",
"(",
"classID",
"*",
"ole",
".",
"GUID",
",",
"err",
"error",
")",
"{",
"return",
"ole",
".",
"ClassIDFrom",
"(",
"programID",
")",
"\n",
"}"
] |
// ClassIDFrom retrieves class ID whether given is program ID or application string.
|
[
"ClassIDFrom",
"retrieves",
"class",
"ID",
"whether",
"given",
"is",
"program",
"ID",
"or",
"application",
"string",
"."
] |
97b6244175ae18ea6eef668034fd6565847501c9
|
https://github.com/go-ole/go-ole/blob/97b6244175ae18ea6eef668034fd6565847501c9/oleutil/oleutil.go#L6-L8
|
19,444
|
go-ole/go-ole
|
oleutil/oleutil.go
|
CreateObject
|
func CreateObject(programID string) (unknown *ole.IUnknown, err error) {
classID, err := ole.ClassIDFrom(programID)
if err != nil {
return
}
unknown, err = ole.CreateInstance(classID, ole.IID_IUnknown)
if err != nil {
return
}
return
}
|
go
|
func CreateObject(programID string) (unknown *ole.IUnknown, err error) {
classID, err := ole.ClassIDFrom(programID)
if err != nil {
return
}
unknown, err = ole.CreateInstance(classID, ole.IID_IUnknown)
if err != nil {
return
}
return
}
|
[
"func",
"CreateObject",
"(",
"programID",
"string",
")",
"(",
"unknown",
"*",
"ole",
".",
"IUnknown",
",",
"err",
"error",
")",
"{",
"classID",
",",
"err",
":=",
"ole",
".",
"ClassIDFrom",
"(",
"programID",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"unknown",
",",
"err",
"=",
"ole",
".",
"CreateInstance",
"(",
"classID",
",",
"ole",
".",
"IID_IUnknown",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"return",
"\n",
"}"
] |
// CreateObject creates object from programID based on interface type.
//
// Only supports IUnknown.
//
// Program ID can be either program ID or application string.
|
[
"CreateObject",
"creates",
"object",
"from",
"programID",
"based",
"on",
"interface",
"type",
".",
"Only",
"supports",
"IUnknown",
".",
"Program",
"ID",
"can",
"be",
"either",
"program",
"ID",
"or",
"application",
"string",
"."
] |
97b6244175ae18ea6eef668034fd6565847501c9
|
https://github.com/go-ole/go-ole/blob/97b6244175ae18ea6eef668034fd6565847501c9/oleutil/oleutil.go#L15-L27
|
19,445
|
go-ole/go-ole
|
oleutil/oleutil.go
|
GetActiveObject
|
func GetActiveObject(programID string) (unknown *ole.IUnknown, err error) {
classID, err := ole.ClassIDFrom(programID)
if err != nil {
return
}
unknown, err = ole.GetActiveObject(classID, ole.IID_IUnknown)
if err != nil {
return
}
return
}
|
go
|
func GetActiveObject(programID string) (unknown *ole.IUnknown, err error) {
classID, err := ole.ClassIDFrom(programID)
if err != nil {
return
}
unknown, err = ole.GetActiveObject(classID, ole.IID_IUnknown)
if err != nil {
return
}
return
}
|
[
"func",
"GetActiveObject",
"(",
"programID",
"string",
")",
"(",
"unknown",
"*",
"ole",
".",
"IUnknown",
",",
"err",
"error",
")",
"{",
"classID",
",",
"err",
":=",
"ole",
".",
"ClassIDFrom",
"(",
"programID",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"unknown",
",",
"err",
"=",
"ole",
".",
"GetActiveObject",
"(",
"classID",
",",
"ole",
".",
"IID_IUnknown",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"return",
"\n",
"}"
] |
// GetActiveObject retrieves active object for program ID and interface ID based
// on interface type.
//
// Only supports IUnknown.
//
// Program ID can be either program ID or application string.
|
[
"GetActiveObject",
"retrieves",
"active",
"object",
"for",
"program",
"ID",
"and",
"interface",
"ID",
"based",
"on",
"interface",
"type",
".",
"Only",
"supports",
"IUnknown",
".",
"Program",
"ID",
"can",
"be",
"either",
"program",
"ID",
"or",
"application",
"string",
"."
] |
97b6244175ae18ea6eef668034fd6565847501c9
|
https://github.com/go-ole/go-ole/blob/97b6244175ae18ea6eef668034fd6565847501c9/oleutil/oleutil.go#L35-L47
|
19,446
|
go-ole/go-ole
|
oleutil/oleutil.go
|
CallMethod
|
func CallMethod(disp *ole.IDispatch, name string, params ...interface{}) (result *ole.VARIANT, err error) {
return disp.InvokeWithOptionalArgs(name, ole.DISPATCH_METHOD, params)
}
|
go
|
func CallMethod(disp *ole.IDispatch, name string, params ...interface{}) (result *ole.VARIANT, err error) {
return disp.InvokeWithOptionalArgs(name, ole.DISPATCH_METHOD, params)
}
|
[
"func",
"CallMethod",
"(",
"disp",
"*",
"ole",
".",
"IDispatch",
",",
"name",
"string",
",",
"params",
"...",
"interface",
"{",
"}",
")",
"(",
"result",
"*",
"ole",
".",
"VARIANT",
",",
"err",
"error",
")",
"{",
"return",
"disp",
".",
"InvokeWithOptionalArgs",
"(",
"name",
",",
"ole",
".",
"DISPATCH_METHOD",
",",
"params",
")",
"\n",
"}"
] |
// CallMethod calls method on IDispatch with parameters.
|
[
"CallMethod",
"calls",
"method",
"on",
"IDispatch",
"with",
"parameters",
"."
] |
97b6244175ae18ea6eef668034fd6565847501c9
|
https://github.com/go-ole/go-ole/blob/97b6244175ae18ea6eef668034fd6565847501c9/oleutil/oleutil.go#L50-L52
|
19,447
|
go-ole/go-ole
|
oleutil/oleutil.go
|
MustCallMethod
|
func MustCallMethod(disp *ole.IDispatch, name string, params ...interface{}) (result *ole.VARIANT) {
r, err := CallMethod(disp, name, params...)
if err != nil {
panic(err.Error())
}
return r
}
|
go
|
func MustCallMethod(disp *ole.IDispatch, name string, params ...interface{}) (result *ole.VARIANT) {
r, err := CallMethod(disp, name, params...)
if err != nil {
panic(err.Error())
}
return r
}
|
[
"func",
"MustCallMethod",
"(",
"disp",
"*",
"ole",
".",
"IDispatch",
",",
"name",
"string",
",",
"params",
"...",
"interface",
"{",
"}",
")",
"(",
"result",
"*",
"ole",
".",
"VARIANT",
")",
"{",
"r",
",",
"err",
":=",
"CallMethod",
"(",
"disp",
",",
"name",
",",
"params",
"...",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
".",
"Error",
"(",
")",
")",
"\n",
"}",
"\n",
"return",
"r",
"\n",
"}"
] |
// MustCallMethod calls method on IDispatch with parameters or panics.
|
[
"MustCallMethod",
"calls",
"method",
"on",
"IDispatch",
"with",
"parameters",
"or",
"panics",
"."
] |
97b6244175ae18ea6eef668034fd6565847501c9
|
https://github.com/go-ole/go-ole/blob/97b6244175ae18ea6eef668034fd6565847501c9/oleutil/oleutil.go#L55-L61
|
19,448
|
go-ole/go-ole
|
oleutil/oleutil.go
|
GetProperty
|
func GetProperty(disp *ole.IDispatch, name string, params ...interface{}) (result *ole.VARIANT, err error) {
return disp.InvokeWithOptionalArgs(name, ole.DISPATCH_PROPERTYGET, params)
}
|
go
|
func GetProperty(disp *ole.IDispatch, name string, params ...interface{}) (result *ole.VARIANT, err error) {
return disp.InvokeWithOptionalArgs(name, ole.DISPATCH_PROPERTYGET, params)
}
|
[
"func",
"GetProperty",
"(",
"disp",
"*",
"ole",
".",
"IDispatch",
",",
"name",
"string",
",",
"params",
"...",
"interface",
"{",
"}",
")",
"(",
"result",
"*",
"ole",
".",
"VARIANT",
",",
"err",
"error",
")",
"{",
"return",
"disp",
".",
"InvokeWithOptionalArgs",
"(",
"name",
",",
"ole",
".",
"DISPATCH_PROPERTYGET",
",",
"params",
")",
"\n",
"}"
] |
// GetProperty retrieves property from IDispatch.
|
[
"GetProperty",
"retrieves",
"property",
"from",
"IDispatch",
"."
] |
97b6244175ae18ea6eef668034fd6565847501c9
|
https://github.com/go-ole/go-ole/blob/97b6244175ae18ea6eef668034fd6565847501c9/oleutil/oleutil.go#L64-L66
|
19,449
|
go-ole/go-ole
|
oleutil/oleutil.go
|
MustGetProperty
|
func MustGetProperty(disp *ole.IDispatch, name string, params ...interface{}) (result *ole.VARIANT) {
r, err := GetProperty(disp, name, params...)
if err != nil {
panic(err.Error())
}
return r
}
|
go
|
func MustGetProperty(disp *ole.IDispatch, name string, params ...interface{}) (result *ole.VARIANT) {
r, err := GetProperty(disp, name, params...)
if err != nil {
panic(err.Error())
}
return r
}
|
[
"func",
"MustGetProperty",
"(",
"disp",
"*",
"ole",
".",
"IDispatch",
",",
"name",
"string",
",",
"params",
"...",
"interface",
"{",
"}",
")",
"(",
"result",
"*",
"ole",
".",
"VARIANT",
")",
"{",
"r",
",",
"err",
":=",
"GetProperty",
"(",
"disp",
",",
"name",
",",
"params",
"...",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
".",
"Error",
"(",
")",
")",
"\n",
"}",
"\n",
"return",
"r",
"\n",
"}"
] |
// MustGetProperty retrieves property from IDispatch or panics.
|
[
"MustGetProperty",
"retrieves",
"property",
"from",
"IDispatch",
"or",
"panics",
"."
] |
97b6244175ae18ea6eef668034fd6565847501c9
|
https://github.com/go-ole/go-ole/blob/97b6244175ae18ea6eef668034fd6565847501c9/oleutil/oleutil.go#L69-L75
|
19,450
|
go-ole/go-ole
|
oleutil/oleutil.go
|
PutProperty
|
func PutProperty(disp *ole.IDispatch, name string, params ...interface{}) (result *ole.VARIANT, err error) {
return disp.InvokeWithOptionalArgs(name, ole.DISPATCH_PROPERTYPUT, params)
}
|
go
|
func PutProperty(disp *ole.IDispatch, name string, params ...interface{}) (result *ole.VARIANT, err error) {
return disp.InvokeWithOptionalArgs(name, ole.DISPATCH_PROPERTYPUT, params)
}
|
[
"func",
"PutProperty",
"(",
"disp",
"*",
"ole",
".",
"IDispatch",
",",
"name",
"string",
",",
"params",
"...",
"interface",
"{",
"}",
")",
"(",
"result",
"*",
"ole",
".",
"VARIANT",
",",
"err",
"error",
")",
"{",
"return",
"disp",
".",
"InvokeWithOptionalArgs",
"(",
"name",
",",
"ole",
".",
"DISPATCH_PROPERTYPUT",
",",
"params",
")",
"\n",
"}"
] |
// PutProperty mutates property.
|
[
"PutProperty",
"mutates",
"property",
"."
] |
97b6244175ae18ea6eef668034fd6565847501c9
|
https://github.com/go-ole/go-ole/blob/97b6244175ae18ea6eef668034fd6565847501c9/oleutil/oleutil.go#L78-L80
|
19,451
|
go-ole/go-ole
|
oleutil/oleutil.go
|
MustPutProperty
|
func MustPutProperty(disp *ole.IDispatch, name string, params ...interface{}) (result *ole.VARIANT) {
r, err := PutProperty(disp, name, params...)
if err != nil {
panic(err.Error())
}
return r
}
|
go
|
func MustPutProperty(disp *ole.IDispatch, name string, params ...interface{}) (result *ole.VARIANT) {
r, err := PutProperty(disp, name, params...)
if err != nil {
panic(err.Error())
}
return r
}
|
[
"func",
"MustPutProperty",
"(",
"disp",
"*",
"ole",
".",
"IDispatch",
",",
"name",
"string",
",",
"params",
"...",
"interface",
"{",
"}",
")",
"(",
"result",
"*",
"ole",
".",
"VARIANT",
")",
"{",
"r",
",",
"err",
":=",
"PutProperty",
"(",
"disp",
",",
"name",
",",
"params",
"...",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
".",
"Error",
"(",
")",
")",
"\n",
"}",
"\n",
"return",
"r",
"\n",
"}"
] |
// MustPutProperty mutates property or panics.
|
[
"MustPutProperty",
"mutates",
"property",
"or",
"panics",
"."
] |
97b6244175ae18ea6eef668034fd6565847501c9
|
https://github.com/go-ole/go-ole/blob/97b6244175ae18ea6eef668034fd6565847501c9/oleutil/oleutil.go#L83-L89
|
19,452
|
go-ole/go-ole
|
oleutil/oleutil.go
|
PutPropertyRef
|
func PutPropertyRef(disp *ole.IDispatch, name string, params ...interface{}) (result *ole.VARIANT, err error) {
return disp.InvokeWithOptionalArgs(name, ole.DISPATCH_PROPERTYPUTREF, params)
}
|
go
|
func PutPropertyRef(disp *ole.IDispatch, name string, params ...interface{}) (result *ole.VARIANT, err error) {
return disp.InvokeWithOptionalArgs(name, ole.DISPATCH_PROPERTYPUTREF, params)
}
|
[
"func",
"PutPropertyRef",
"(",
"disp",
"*",
"ole",
".",
"IDispatch",
",",
"name",
"string",
",",
"params",
"...",
"interface",
"{",
"}",
")",
"(",
"result",
"*",
"ole",
".",
"VARIANT",
",",
"err",
"error",
")",
"{",
"return",
"disp",
".",
"InvokeWithOptionalArgs",
"(",
"name",
",",
"ole",
".",
"DISPATCH_PROPERTYPUTREF",
",",
"params",
")",
"\n",
"}"
] |
// PutPropertyRef mutates property reference.
|
[
"PutPropertyRef",
"mutates",
"property",
"reference",
"."
] |
97b6244175ae18ea6eef668034fd6565847501c9
|
https://github.com/go-ole/go-ole/blob/97b6244175ae18ea6eef668034fd6565847501c9/oleutil/oleutil.go#L92-L94
|
19,453
|
go-ole/go-ole
|
oleutil/oleutil.go
|
MustPutPropertyRef
|
func MustPutPropertyRef(disp *ole.IDispatch, name string, params ...interface{}) (result *ole.VARIANT) {
r, err := PutPropertyRef(disp, name, params...)
if err != nil {
panic(err.Error())
}
return r
}
|
go
|
func MustPutPropertyRef(disp *ole.IDispatch, name string, params ...interface{}) (result *ole.VARIANT) {
r, err := PutPropertyRef(disp, name, params...)
if err != nil {
panic(err.Error())
}
return r
}
|
[
"func",
"MustPutPropertyRef",
"(",
"disp",
"*",
"ole",
".",
"IDispatch",
",",
"name",
"string",
",",
"params",
"...",
"interface",
"{",
"}",
")",
"(",
"result",
"*",
"ole",
".",
"VARIANT",
")",
"{",
"r",
",",
"err",
":=",
"PutPropertyRef",
"(",
"disp",
",",
"name",
",",
"params",
"...",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
".",
"Error",
"(",
")",
")",
"\n",
"}",
"\n",
"return",
"r",
"\n",
"}"
] |
// MustPutPropertyRef mutates property reference or panics.
|
[
"MustPutPropertyRef",
"mutates",
"property",
"reference",
"or",
"panics",
"."
] |
97b6244175ae18ea6eef668034fd6565847501c9
|
https://github.com/go-ole/go-ole/blob/97b6244175ae18ea6eef668034fd6565847501c9/oleutil/oleutil.go#L97-L103
|
19,454
|
kevin-cantwell/dotmatrix
|
gif.go
|
drawOver
|
func (p *GIFPrinter) drawOver(target *image.Paletted, source image.Image) {
bounds := source.Bounds()
for y := bounds.Min.Y; y < bounds.Max.Y; y++ {
for x := bounds.Min.X; x < bounds.Max.X; x++ {
c := source.At(x, y)
if c == color.Transparent {
continue
}
target.Set(x, y, c)
}
}
}
|
go
|
func (p *GIFPrinter) drawOver(target *image.Paletted, source image.Image) {
bounds := source.Bounds()
for y := bounds.Min.Y; y < bounds.Max.Y; y++ {
for x := bounds.Min.X; x < bounds.Max.X; x++ {
c := source.At(x, y)
if c == color.Transparent {
continue
}
target.Set(x, y, c)
}
}
}
|
[
"func",
"(",
"p",
"*",
"GIFPrinter",
")",
"drawOver",
"(",
"target",
"*",
"image",
".",
"Paletted",
",",
"source",
"image",
".",
"Image",
")",
"{",
"bounds",
":=",
"source",
".",
"Bounds",
"(",
")",
"\n",
"for",
"y",
":=",
"bounds",
".",
"Min",
".",
"Y",
";",
"y",
"<",
"bounds",
".",
"Max",
".",
"Y",
";",
"y",
"++",
"{",
"for",
"x",
":=",
"bounds",
".",
"Min",
".",
"X",
";",
"x",
"<",
"bounds",
".",
"Max",
".",
"X",
";",
"x",
"++",
"{",
"c",
":=",
"source",
".",
"At",
"(",
"x",
",",
"y",
")",
"\n",
"if",
"c",
"==",
"color",
".",
"Transparent",
"{",
"continue",
"\n",
"}",
"\n",
"target",
".",
"Set",
"(",
"x",
",",
"y",
",",
"c",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] |
// Draws any non-transparent pixels into target
|
[
"Draws",
"any",
"non",
"-",
"transparent",
"pixels",
"into",
"target"
] |
d70fba7c1676bb77b7d5813b9a436c36562839ed
|
https://github.com/kevin-cantwell/dotmatrix/blob/d70fba7c1676bb77b7d5813b9a436c36562839ed/gif.go#L117-L128
|
19,455
|
kevin-cantwell/dotmatrix
|
gif.go
|
drawExact
|
func (p *GIFPrinter) drawExact(target *image.Paletted, source image.Image) {
bounds := source.Bounds()
for y := bounds.Min.Y; y < bounds.Max.Y; y++ {
for x := bounds.Min.X; x < bounds.Max.X; x++ {
target.Set(x, y, source.At(x, y))
}
}
}
|
go
|
func (p *GIFPrinter) drawExact(target *image.Paletted, source image.Image) {
bounds := source.Bounds()
for y := bounds.Min.Y; y < bounds.Max.Y; y++ {
for x := bounds.Min.X; x < bounds.Max.X; x++ {
target.Set(x, y, source.At(x, y))
}
}
}
|
[
"func",
"(",
"p",
"*",
"GIFPrinter",
")",
"drawExact",
"(",
"target",
"*",
"image",
".",
"Paletted",
",",
"source",
"image",
".",
"Image",
")",
"{",
"bounds",
":=",
"source",
".",
"Bounds",
"(",
")",
"\n",
"for",
"y",
":=",
"bounds",
".",
"Min",
".",
"Y",
";",
"y",
"<",
"bounds",
".",
"Max",
".",
"Y",
";",
"y",
"++",
"{",
"for",
"x",
":=",
"bounds",
".",
"Min",
".",
"X",
";",
"x",
"<",
"bounds",
".",
"Max",
".",
"X",
";",
"x",
"++",
"{",
"target",
".",
"Set",
"(",
"x",
",",
"y",
",",
"source",
".",
"At",
"(",
"x",
",",
"y",
")",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] |
// Draws pixels into target, including transparent ones.
|
[
"Draws",
"pixels",
"into",
"target",
"including",
"transparent",
"ones",
"."
] |
d70fba7c1676bb77b7d5813b9a436c36562839ed
|
https://github.com/kevin-cantwell/dotmatrix/blob/d70fba7c1676bb77b7d5813b9a436c36562839ed/gif.go#L131-L138
|
19,456
|
kevin-cantwell/dotmatrix
|
gif.go
|
resetCursor
|
func resetCursor(w io.Writer, rows int) {
w.Write([]byte(fmt.Sprintf("\033[999D\033[%dA", rows)))
}
|
go
|
func resetCursor(w io.Writer, rows int) {
w.Write([]byte(fmt.Sprintf("\033[999D\033[%dA", rows)))
}
|
[
"func",
"resetCursor",
"(",
"w",
"io",
".",
"Writer",
",",
"rows",
"int",
")",
"{",
"w",
".",
"Write",
"(",
"[",
"]",
"byte",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\\033",
"\\033",
"\"",
",",
"rows",
")",
")",
")",
"\n",
"}"
] |
// Move the cursor to the beginning of the line and up rows
|
[
"Move",
"the",
"cursor",
"to",
"the",
"beginning",
"of",
"the",
"line",
"and",
"up",
"rows"
] |
d70fba7c1676bb77b7d5813b9a436c36562839ed
|
https://github.com/kevin-cantwell/dotmatrix/blob/d70fba7c1676bb77b7d5813b9a436c36562839ed/gif.go#L141-L143
|
19,457
|
kevin-cantwell/dotmatrix
|
image.go
|
NewPrinter
|
func NewPrinter(w io.Writer, c *Config) *Printer {
return &Printer{
w: w,
c: mergeConfig(c),
}
}
|
go
|
func NewPrinter(w io.Writer, c *Config) *Printer {
return &Printer{
w: w,
c: mergeConfig(c),
}
}
|
[
"func",
"NewPrinter",
"(",
"w",
"io",
".",
"Writer",
",",
"c",
"*",
"Config",
")",
"*",
"Printer",
"{",
"return",
"&",
"Printer",
"{",
"w",
":",
"w",
",",
"c",
":",
"mergeConfig",
"(",
"c",
")",
",",
"}",
"\n",
"}"
] |
// NewPrinter provides an Printer. If drawer is nil, draw.FloydSteinberg is used.
|
[
"NewPrinter",
"provides",
"an",
"Printer",
".",
"If",
"drawer",
"is",
"nil",
"draw",
".",
"FloydSteinberg",
"is",
"used",
"."
] |
d70fba7c1676bb77b7d5813b9a436c36562839ed
|
https://github.com/kevin-cantwell/dotmatrix/blob/d70fba7c1676bb77b7d5813b9a436c36562839ed/image.go#L67-L72
|
19,458
|
chop-dbhi/sql-agent
|
encoder.go
|
EncodeJSON
|
func EncodeJSON(w io.Writer, i *Iterator) error {
r := make(Record)
// Open paren.
if _, err := w.Write([]byte{'['}); err != nil {
return err
}
var c int
enc := json.NewEncoder(w)
delim := []byte{',', '\n'}
for i.Next() {
if c > 0 {
if _, err := w.Write(delim); err != nil {
return err
}
}
c++
if err := i.Scan(r); err != nil {
return err
}
if err := enc.Encode(r); err != nil {
return err
}
}
// Close paren.
if _, err := w.Write([]byte{']'}); err != nil {
return err
}
return nil
}
|
go
|
func EncodeJSON(w io.Writer, i *Iterator) error {
r := make(Record)
// Open paren.
if _, err := w.Write([]byte{'['}); err != nil {
return err
}
var c int
enc := json.NewEncoder(w)
delim := []byte{',', '\n'}
for i.Next() {
if c > 0 {
if _, err := w.Write(delim); err != nil {
return err
}
}
c++
if err := i.Scan(r); err != nil {
return err
}
if err := enc.Encode(r); err != nil {
return err
}
}
// Close paren.
if _, err := w.Write([]byte{']'}); err != nil {
return err
}
return nil
}
|
[
"func",
"EncodeJSON",
"(",
"w",
"io",
".",
"Writer",
",",
"i",
"*",
"Iterator",
")",
"error",
"{",
"r",
":=",
"make",
"(",
"Record",
")",
"\n\n",
"// Open paren.",
"if",
"_",
",",
"err",
":=",
"w",
".",
"Write",
"(",
"[",
"]",
"byte",
"{",
"'['",
"}",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"var",
"c",
"int",
"\n",
"enc",
":=",
"json",
".",
"NewEncoder",
"(",
"w",
")",
"\n\n",
"delim",
":=",
"[",
"]",
"byte",
"{",
"','",
",",
"'\\n'",
"}",
"\n\n",
"for",
"i",
".",
"Next",
"(",
")",
"{",
"if",
"c",
">",
"0",
"{",
"if",
"_",
",",
"err",
":=",
"w",
".",
"Write",
"(",
"delim",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"c",
"++",
"\n\n",
"if",
"err",
":=",
"i",
".",
"Scan",
"(",
"r",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"enc",
".",
"Encode",
"(",
"r",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"// Close paren.",
"if",
"_",
",",
"err",
":=",
"w",
".",
"Write",
"(",
"[",
"]",
"byte",
"{",
"']'",
"}",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// EncodeJSON encodes the iterator as a JSON array of records.
|
[
"EncodeJSON",
"encodes",
"the",
"iterator",
"as",
"a",
"JSON",
"array",
"of",
"records",
"."
] |
7978b5bdb56370bd17fed45aadc06f614570ced6
|
https://github.com/chop-dbhi/sql-agent/blob/7978b5bdb56370bd17fed45aadc06f614570ced6/encoder.go#L52-L89
|
19,459
|
chop-dbhi/sql-agent
|
encoder.go
|
EncodeLDJSON
|
func EncodeLDJSON(w io.Writer, i *Iterator) error {
r := make(Record)
enc := json.NewEncoder(w)
for i.Next() {
if err := i.Scan(r); err != nil {
return err
}
if err := enc.Encode(r); err != nil {
return err
}
}
return nil
}
|
go
|
func EncodeLDJSON(w io.Writer, i *Iterator) error {
r := make(Record)
enc := json.NewEncoder(w)
for i.Next() {
if err := i.Scan(r); err != nil {
return err
}
if err := enc.Encode(r); err != nil {
return err
}
}
return nil
}
|
[
"func",
"EncodeLDJSON",
"(",
"w",
"io",
".",
"Writer",
",",
"i",
"*",
"Iterator",
")",
"error",
"{",
"r",
":=",
"make",
"(",
"Record",
")",
"\n\n",
"enc",
":=",
"json",
".",
"NewEncoder",
"(",
"w",
")",
"\n\n",
"for",
"i",
".",
"Next",
"(",
")",
"{",
"if",
"err",
":=",
"i",
".",
"Scan",
"(",
"r",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"enc",
".",
"Encode",
"(",
"r",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// EncodeLDJSON encodes the iterator as a line delimited stream
// of records.
|
[
"EncodeLDJSON",
"encodes",
"the",
"iterator",
"as",
"a",
"line",
"delimited",
"stream",
"of",
"records",
"."
] |
7978b5bdb56370bd17fed45aadc06f614570ced6
|
https://github.com/chop-dbhi/sql-agent/blob/7978b5bdb56370bd17fed45aadc06f614570ced6/encoder.go#L93-L109
|
19,460
|
chop-dbhi/sql-agent
|
driver.go
|
cleanParams
|
func cleanParams(p map[string]interface{}) map[string]interface{} {
c := make(map[string]interface{})
for k, v := range p {
switch x := v.(type) {
case string:
if x == "" {
continue
}
}
c[k] = v
}
return c
}
|
go
|
func cleanParams(p map[string]interface{}) map[string]interface{} {
c := make(map[string]interface{})
for k, v := range p {
switch x := v.(type) {
case string:
if x == "" {
continue
}
}
c[k] = v
}
return c
}
|
[
"func",
"cleanParams",
"(",
"p",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"c",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"\n\n",
"for",
"k",
",",
"v",
":=",
"range",
"p",
"{",
"switch",
"x",
":=",
"v",
".",
"(",
"type",
")",
"{",
"case",
"string",
":",
"if",
"x",
"==",
"\"",
"\"",
"{",
"continue",
"\n",
"}",
"\n",
"}",
"\n\n",
"c",
"[",
"k",
"]",
"=",
"v",
"\n",
"}",
"\n\n",
"return",
"c",
"\n",
"}"
] |
// cleanParams removes any key with empty string values.
|
[
"cleanParams",
"removes",
"any",
"key",
"with",
"empty",
"string",
"values",
"."
] |
7978b5bdb56370bd17fed45aadc06f614570ced6
|
https://github.com/chop-dbhi/sql-agent/blob/7978b5bdb56370bd17fed45aadc06f614570ced6/driver.go#L17-L32
|
19,461
|
chop-dbhi/sql-agent
|
connect.go
|
Scan
|
func (i *Iterator) Scan(r Record) error {
if err := i.rows.MapScan(r); err != nil {
return err
}
mapBytesToString(r)
return nil
}
|
go
|
func (i *Iterator) Scan(r Record) error {
if err := i.rows.MapScan(r); err != nil {
return err
}
mapBytesToString(r)
return nil
}
|
[
"func",
"(",
"i",
"*",
"Iterator",
")",
"Scan",
"(",
"r",
"Record",
")",
"error",
"{",
"if",
"err",
":=",
"i",
".",
"rows",
".",
"MapScan",
"(",
"r",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"mapBytesToString",
"(",
"r",
")",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// Scan takes a record and scans the values of a row into the record.
|
[
"Scan",
"takes",
"a",
"record",
"and",
"scans",
"the",
"values",
"of",
"a",
"row",
"into",
"the",
"record",
"."
] |
7978b5bdb56370bd17fed45aadc06f614570ced6
|
https://github.com/chop-dbhi/sql-agent/blob/7978b5bdb56370bd17fed45aadc06f614570ced6/connect.go#L37-L45
|
19,462
|
chop-dbhi/sql-agent
|
connect.go
|
Connect
|
func Connect(driver string, params map[string]interface{}) (*sqlx.DB, error) {
// Select the driver.
driver, ok := Drivers[driver]
if !ok {
return nil, ErrUnknownDriver
}
// Connect to the database.
connector := connectors[driver]
params = cleanParams(params)
dsn, ok := params["dsn"].(string)
if !ok {
dsn = connector(params)
}
return sqlx.Connect(driver, dsn)
}
|
go
|
func Connect(driver string, params map[string]interface{}) (*sqlx.DB, error) {
// Select the driver.
driver, ok := Drivers[driver]
if !ok {
return nil, ErrUnknownDriver
}
// Connect to the database.
connector := connectors[driver]
params = cleanParams(params)
dsn, ok := params["dsn"].(string)
if !ok {
dsn = connector(params)
}
return sqlx.Connect(driver, dsn)
}
|
[
"func",
"Connect",
"(",
"driver",
"string",
",",
"params",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"(",
"*",
"sqlx",
".",
"DB",
",",
"error",
")",
"{",
"// Select the driver.",
"driver",
",",
"ok",
":=",
"Drivers",
"[",
"driver",
"]",
"\n\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
",",
"ErrUnknownDriver",
"\n",
"}",
"\n\n",
"// Connect to the database.",
"connector",
":=",
"connectors",
"[",
"driver",
"]",
"\n\n",
"params",
"=",
"cleanParams",
"(",
"params",
")",
"\n\n",
"dsn",
",",
"ok",
":=",
"params",
"[",
"\"",
"\"",
"]",
".",
"(",
"string",
")",
"\n",
"if",
"!",
"ok",
"{",
"dsn",
"=",
"connector",
"(",
"params",
")",
"\n",
"}",
"\n\n",
"return",
"sqlx",
".",
"Connect",
"(",
"driver",
",",
"dsn",
")",
"\n",
"}"
] |
// Connect connects to a database given a driver name and set of connection parameters.
// Each database supports a different set of connection parameters, however the few
// that are common are standardized.
//
// - `host` - The database host.
// - `port` - The database port.
// - `user` - The username to authenticate with.
// - `password` - The password to authenticate with.
// - `database` - The database to connect to.
//
// Other known database-specific parameters will be appended to the connection string and the remaining will be ignored.
|
[
"Connect",
"connects",
"to",
"a",
"database",
"given",
"a",
"driver",
"name",
"and",
"set",
"of",
"connection",
"parameters",
".",
"Each",
"database",
"supports",
"a",
"different",
"set",
"of",
"connection",
"parameters",
"however",
"the",
"few",
"that",
"are",
"common",
"are",
"standardized",
".",
"-",
"host",
"-",
"The",
"database",
"host",
".",
"-",
"port",
"-",
"The",
"database",
"port",
".",
"-",
"user",
"-",
"The",
"username",
"to",
"authenticate",
"with",
".",
"-",
"password",
"-",
"The",
"password",
"to",
"authenticate",
"with",
".",
"-",
"database",
"-",
"The",
"database",
"to",
"connect",
"to",
".",
"Other",
"known",
"database",
"-",
"specific",
"parameters",
"will",
"be",
"appended",
"to",
"the",
"connection",
"string",
"and",
"the",
"remaining",
"will",
"be",
"ignored",
"."
] |
7978b5bdb56370bd17fed45aadc06f614570ced6
|
https://github.com/chop-dbhi/sql-agent/blob/7978b5bdb56370bd17fed45aadc06f614570ced6/connect.go#L62-L81
|
19,463
|
chop-dbhi/sql-agent
|
connect.go
|
Execute
|
func Execute(db *sqlx.DB, sql string, params map[string]interface{}) (*Iterator, error) {
var (
err error
rows *sqlx.Rows
)
// Execute the query.
if params != nil && len(params) > 0 {
rows, err = db.NamedQuery(sql, params)
} else {
rows, err = db.Queryx(sql)
}
if err != nil {
return nil, err
}
cols, err := rows.Columns()
if err != nil {
return nil, err
}
return &Iterator{
Cols: cols,
rows: rows,
}, nil
}
|
go
|
func Execute(db *sqlx.DB, sql string, params map[string]interface{}) (*Iterator, error) {
var (
err error
rows *sqlx.Rows
)
// Execute the query.
if params != nil && len(params) > 0 {
rows, err = db.NamedQuery(sql, params)
} else {
rows, err = db.Queryx(sql)
}
if err != nil {
return nil, err
}
cols, err := rows.Columns()
if err != nil {
return nil, err
}
return &Iterator{
Cols: cols,
rows: rows,
}, nil
}
|
[
"func",
"Execute",
"(",
"db",
"*",
"sqlx",
".",
"DB",
",",
"sql",
"string",
",",
"params",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"(",
"*",
"Iterator",
",",
"error",
")",
"{",
"var",
"(",
"err",
"error",
"\n",
"rows",
"*",
"sqlx",
".",
"Rows",
"\n",
")",
"\n\n",
"// Execute the query.",
"if",
"params",
"!=",
"nil",
"&&",
"len",
"(",
"params",
")",
">",
"0",
"{",
"rows",
",",
"err",
"=",
"db",
".",
"NamedQuery",
"(",
"sql",
",",
"params",
")",
"\n",
"}",
"else",
"{",
"rows",
",",
"err",
"=",
"db",
".",
"Queryx",
"(",
"sql",
")",
"\n",
"}",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"cols",
",",
"err",
":=",
"rows",
".",
"Columns",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"&",
"Iterator",
"{",
"Cols",
":",
"cols",
",",
"rows",
":",
"rows",
",",
"}",
",",
"nil",
"\n",
"}"
] |
// Execute takes a database instance, SQL statement, and parameters and executes the query
// returning the resulting rows.
|
[
"Execute",
"takes",
"a",
"database",
"instance",
"SQL",
"statement",
"and",
"parameters",
"and",
"executes",
"the",
"query",
"returning",
"the",
"resulting",
"rows",
"."
] |
7978b5bdb56370bd17fed45aadc06f614570ced6
|
https://github.com/chop-dbhi/sql-agent/blob/7978b5bdb56370bd17fed45aadc06f614570ced6/connect.go#L85-L111
|
19,464
|
chop-dbhi/sql-agent
|
connect.go
|
Shutdown
|
func Shutdown() {
connMapMutex.Lock()
for _, db := range connMap {
db.Close()
}
connMapMutex.Unlock()
}
|
go
|
func Shutdown() {
connMapMutex.Lock()
for _, db := range connMap {
db.Close()
}
connMapMutex.Unlock()
}
|
[
"func",
"Shutdown",
"(",
")",
"{",
"connMapMutex",
".",
"Lock",
"(",
")",
"\n",
"for",
"_",
",",
"db",
":=",
"range",
"connMap",
"{",
"db",
".",
"Close",
"(",
")",
"\n",
"}",
"\n",
"connMapMutex",
".",
"Unlock",
"(",
")",
"\n",
"}"
] |
// Shutdown closes all persisted database connections.
|
[
"Shutdown",
"closes",
"all",
"persisted",
"database",
"connections",
"."
] |
7978b5bdb56370bd17fed45aadc06f614570ced6
|
https://github.com/chop-dbhi/sql-agent/blob/7978b5bdb56370bd17fed45aadc06f614570ced6/connect.go#L147-L153
|
19,465
|
chop-dbhi/sql-agent
|
cmd/sql-agent/main.go
|
parseMimetype
|
func parseMimetype(mimetype string) string {
mimetype, params, err := mime.ParseMediaType(mimetype)
if err != nil {
return ""
}
// No Accept header passed.
if mimetype == "" {
return defaultMimetype
}
switch mimetype {
case "application/json":
if params["boundary"] == "NL" {
return "application/x-ldjson"
}
default:
if _, ok := mimetypeFormats[mimetype]; !ok {
return ""
}
}
return mimetype
}
|
go
|
func parseMimetype(mimetype string) string {
mimetype, params, err := mime.ParseMediaType(mimetype)
if err != nil {
return ""
}
// No Accept header passed.
if mimetype == "" {
return defaultMimetype
}
switch mimetype {
case "application/json":
if params["boundary"] == "NL" {
return "application/x-ldjson"
}
default:
if _, ok := mimetypeFormats[mimetype]; !ok {
return ""
}
}
return mimetype
}
|
[
"func",
"parseMimetype",
"(",
"mimetype",
"string",
")",
"string",
"{",
"mimetype",
",",
"params",
",",
"err",
":=",
"mime",
".",
"ParseMediaType",
"(",
"mimetype",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n\n",
"// No Accept header passed.",
"if",
"mimetype",
"==",
"\"",
"\"",
"{",
"return",
"defaultMimetype",
"\n",
"}",
"\n\n",
"switch",
"mimetype",
"{",
"case",
"\"",
"\"",
":",
"if",
"params",
"[",
"\"",
"\"",
"]",
"==",
"\"",
"\"",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n",
"default",
":",
"if",
"_",
",",
"ok",
":=",
"mimetypeFormats",
"[",
"mimetype",
"]",
";",
"!",
"ok",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"mimetype",
"\n",
"}"
] |
// parseMimetype parses a mimetype from the Accept header.
|
[
"parseMimetype",
"parses",
"a",
"mimetype",
"from",
"the",
"Accept",
"header",
"."
] |
7978b5bdb56370bd17fed45aadc06f614570ced6
|
https://github.com/chop-dbhi/sql-agent/blob/7978b5bdb56370bd17fed45aadc06f614570ced6/cmd/sql-agent/main.go#L65-L89
|
19,466
|
lithammer/fuzzysearch
|
fuzzy/fuzzy.go
|
MatchFold
|
func MatchFold(source, target string) bool {
return match(source, target, unicode.ToLower)
}
|
go
|
func MatchFold(source, target string) bool {
return match(source, target, unicode.ToLower)
}
|
[
"func",
"MatchFold",
"(",
"source",
",",
"target",
"string",
")",
"bool",
"{",
"return",
"match",
"(",
"source",
",",
"target",
",",
"unicode",
".",
"ToLower",
")",
"\n",
"}"
] |
// MatchFold is a case-insensitive version of Match.
|
[
"MatchFold",
"is",
"a",
"case",
"-",
"insensitive",
"version",
"of",
"Match",
"."
] |
9704abcb5729ef17e4316e31439d7fcece8dac5f
|
https://github.com/lithammer/fuzzysearch/blob/9704abcb5729ef17e4316e31439d7fcece8dac5f/fuzzy/fuzzy.go#L22-L24
|
19,467
|
lithammer/fuzzysearch
|
fuzzy/fuzzy.go
|
Find
|
func Find(source string, targets []string) []string {
return find(source, targets, noop)
}
|
go
|
func Find(source string, targets []string) []string {
return find(source, targets, noop)
}
|
[
"func",
"Find",
"(",
"source",
"string",
",",
"targets",
"[",
"]",
"string",
")",
"[",
"]",
"string",
"{",
"return",
"find",
"(",
"source",
",",
"targets",
",",
"noop",
")",
"\n",
"}"
] |
// Find will return a list of strings in targets that fuzzy matches source.
|
[
"Find",
"will",
"return",
"a",
"list",
"of",
"strings",
"in",
"targets",
"that",
"fuzzy",
"matches",
"source",
"."
] |
9704abcb5729ef17e4316e31439d7fcece8dac5f
|
https://github.com/lithammer/fuzzysearch/blob/9704abcb5729ef17e4316e31439d7fcece8dac5f/fuzzy/fuzzy.go#L52-L54
|
19,468
|
lithammer/fuzzysearch
|
fuzzy/fuzzy.go
|
FindFold
|
func FindFold(source string, targets []string) []string {
return find(source, targets, unicode.ToLower)
}
|
go
|
func FindFold(source string, targets []string) []string {
return find(source, targets, unicode.ToLower)
}
|
[
"func",
"FindFold",
"(",
"source",
"string",
",",
"targets",
"[",
"]",
"string",
")",
"[",
"]",
"string",
"{",
"return",
"find",
"(",
"source",
",",
"targets",
",",
"unicode",
".",
"ToLower",
")",
"\n",
"}"
] |
// FindFold is a case-insensitive version of Find.
|
[
"FindFold",
"is",
"a",
"case",
"-",
"insensitive",
"version",
"of",
"Find",
"."
] |
9704abcb5729ef17e4316e31439d7fcece8dac5f
|
https://github.com/lithammer/fuzzysearch/blob/9704abcb5729ef17e4316e31439d7fcece8dac5f/fuzzy/fuzzy.go#L57-L59
|
19,469
|
lithammer/fuzzysearch
|
fuzzy/fuzzy.go
|
RankMatchFold
|
func RankMatchFold(source, target string) int {
return rank(source, target, unicode.ToLower)
}
|
go
|
func RankMatchFold(source, target string) int {
return rank(source, target, unicode.ToLower)
}
|
[
"func",
"RankMatchFold",
"(",
"source",
",",
"target",
"string",
")",
"int",
"{",
"return",
"rank",
"(",
"source",
",",
"target",
",",
"unicode",
".",
"ToLower",
")",
"\n",
"}"
] |
// RankMatchFold is a case-insensitive version of RankMatch.
|
[
"RankMatchFold",
"is",
"a",
"case",
"-",
"insensitive",
"version",
"of",
"RankMatch",
"."
] |
9704abcb5729ef17e4316e31439d7fcece8dac5f
|
https://github.com/lithammer/fuzzysearch/blob/9704abcb5729ef17e4316e31439d7fcece8dac5f/fuzzy/fuzzy.go#L84-L86
|
19,470
|
lithammer/fuzzysearch
|
fuzzy/fuzzy.go
|
RankFind
|
func RankFind(source string, targets []string) Ranks {
var r Ranks
for index, target := range targets {
if match(source, target, noop) {
distance := LevenshteinDistance(source, target)
r = append(r, Rank{source, target, distance, index})
}
}
return r
}
|
go
|
func RankFind(source string, targets []string) Ranks {
var r Ranks
for index, target := range targets {
if match(source, target, noop) {
distance := LevenshteinDistance(source, target)
r = append(r, Rank{source, target, distance, index})
}
}
return r
}
|
[
"func",
"RankFind",
"(",
"source",
"string",
",",
"targets",
"[",
"]",
"string",
")",
"Ranks",
"{",
"var",
"r",
"Ranks",
"\n\n",
"for",
"index",
",",
"target",
":=",
"range",
"targets",
"{",
"if",
"match",
"(",
"source",
",",
"target",
",",
"noop",
")",
"{",
"distance",
":=",
"LevenshteinDistance",
"(",
"source",
",",
"target",
")",
"\n",
"r",
"=",
"append",
"(",
"r",
",",
"Rank",
"{",
"source",
",",
"target",
",",
"distance",
",",
"index",
"}",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"r",
"\n",
"}"
] |
// RankFind is similar to Find, except it will also rank all matches using
// Levenshtein distance.
|
[
"RankFind",
"is",
"similar",
"to",
"Find",
"except",
"it",
"will",
"also",
"rank",
"all",
"matches",
"using",
"Levenshtein",
"distance",
"."
] |
9704abcb5729ef17e4316e31439d7fcece8dac5f
|
https://github.com/lithammer/fuzzysearch/blob/9704abcb5729ef17e4316e31439d7fcece8dac5f/fuzzy/fuzzy.go#L122-L132
|
19,471
|
lithammer/fuzzysearch
|
fuzzy/fuzzy.go
|
RankFindFold
|
func RankFindFold(source string, targets []string) Ranks {
var r Ranks
for index, target := range targets {
if match(source, target, unicode.ToLower) {
distance := LevenshteinDistance(source, target)
r = append(r, Rank{source, target, distance, index})
}
}
return r
}
|
go
|
func RankFindFold(source string, targets []string) Ranks {
var r Ranks
for index, target := range targets {
if match(source, target, unicode.ToLower) {
distance := LevenshteinDistance(source, target)
r = append(r, Rank{source, target, distance, index})
}
}
return r
}
|
[
"func",
"RankFindFold",
"(",
"source",
"string",
",",
"targets",
"[",
"]",
"string",
")",
"Ranks",
"{",
"var",
"r",
"Ranks",
"\n\n",
"for",
"index",
",",
"target",
":=",
"range",
"targets",
"{",
"if",
"match",
"(",
"source",
",",
"target",
",",
"unicode",
".",
"ToLower",
")",
"{",
"distance",
":=",
"LevenshteinDistance",
"(",
"source",
",",
"target",
")",
"\n",
"r",
"=",
"append",
"(",
"r",
",",
"Rank",
"{",
"source",
",",
"target",
",",
"distance",
",",
"index",
"}",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"r",
"\n",
"}"
] |
// RankFindFold is a case-insensitive version of RankFind.
|
[
"RankFindFold",
"is",
"a",
"case",
"-",
"insensitive",
"version",
"of",
"RankFind",
"."
] |
9704abcb5729ef17e4316e31439d7fcece8dac5f
|
https://github.com/lithammer/fuzzysearch/blob/9704abcb5729ef17e4316e31439d7fcece8dac5f/fuzzy/fuzzy.go#L135-L145
|
19,472
|
huandu/xstrings
|
translate.go
|
TranslateRune
|
func (tr *Translator) TranslateRune(r rune) (result rune, translated bool) {
switch {
case tr.quickDict != nil:
if r <= unicode.MaxASCII {
result = tr.quickDict.Dict[r]
if result != 0 {
translated = true
if tr.mappedRune >= 0 {
result = tr.mappedRune
}
break
}
}
fallthrough
case tr.runeMap != nil:
var ok bool
if result, ok = tr.runeMap[r]; ok {
translated = true
if tr.mappedRune >= 0 {
result = tr.mappedRune
}
break
}
fallthrough
default:
var rrm *runeRangeMap
ranges := tr.ranges
for i := len(ranges) - 1; i >= 0; i-- {
rrm = ranges[i]
if rrm.FromLo <= r && r <= rrm.FromHi {
translated = true
if tr.mappedRune >= 0 {
result = tr.mappedRune
break
}
if rrm.ToLo < rrm.ToHi {
result = rrm.ToLo + r - rrm.FromLo
} else if rrm.ToLo > rrm.ToHi {
// ToHi can be smaller than ToLo if range is from higher to lower.
result = rrm.ToLo - r + rrm.FromLo
} else {
result = rrm.ToLo
}
break
}
}
}
if tr.reverted {
if !translated {
result = tr.mappedRune
}
translated = !translated
}
if !translated {
result = r
}
return
}
|
go
|
func (tr *Translator) TranslateRune(r rune) (result rune, translated bool) {
switch {
case tr.quickDict != nil:
if r <= unicode.MaxASCII {
result = tr.quickDict.Dict[r]
if result != 0 {
translated = true
if tr.mappedRune >= 0 {
result = tr.mappedRune
}
break
}
}
fallthrough
case tr.runeMap != nil:
var ok bool
if result, ok = tr.runeMap[r]; ok {
translated = true
if tr.mappedRune >= 0 {
result = tr.mappedRune
}
break
}
fallthrough
default:
var rrm *runeRangeMap
ranges := tr.ranges
for i := len(ranges) - 1; i >= 0; i-- {
rrm = ranges[i]
if rrm.FromLo <= r && r <= rrm.FromHi {
translated = true
if tr.mappedRune >= 0 {
result = tr.mappedRune
break
}
if rrm.ToLo < rrm.ToHi {
result = rrm.ToLo + r - rrm.FromLo
} else if rrm.ToLo > rrm.ToHi {
// ToHi can be smaller than ToLo if range is from higher to lower.
result = rrm.ToLo - r + rrm.FromLo
} else {
result = rrm.ToLo
}
break
}
}
}
if tr.reverted {
if !translated {
result = tr.mappedRune
}
translated = !translated
}
if !translated {
result = r
}
return
}
|
[
"func",
"(",
"tr",
"*",
"Translator",
")",
"TranslateRune",
"(",
"r",
"rune",
")",
"(",
"result",
"rune",
",",
"translated",
"bool",
")",
"{",
"switch",
"{",
"case",
"tr",
".",
"quickDict",
"!=",
"nil",
":",
"if",
"r",
"<=",
"unicode",
".",
"MaxASCII",
"{",
"result",
"=",
"tr",
".",
"quickDict",
".",
"Dict",
"[",
"r",
"]",
"\n\n",
"if",
"result",
"!=",
"0",
"{",
"translated",
"=",
"true",
"\n\n",
"if",
"tr",
".",
"mappedRune",
">=",
"0",
"{",
"result",
"=",
"tr",
".",
"mappedRune",
"\n",
"}",
"\n\n",
"break",
"\n",
"}",
"\n",
"}",
"\n\n",
"fallthrough",
"\n\n",
"case",
"tr",
".",
"runeMap",
"!=",
"nil",
":",
"var",
"ok",
"bool",
"\n\n",
"if",
"result",
",",
"ok",
"=",
"tr",
".",
"runeMap",
"[",
"r",
"]",
";",
"ok",
"{",
"translated",
"=",
"true",
"\n\n",
"if",
"tr",
".",
"mappedRune",
">=",
"0",
"{",
"result",
"=",
"tr",
".",
"mappedRune",
"\n",
"}",
"\n\n",
"break",
"\n",
"}",
"\n\n",
"fallthrough",
"\n\n",
"default",
":",
"var",
"rrm",
"*",
"runeRangeMap",
"\n",
"ranges",
":=",
"tr",
".",
"ranges",
"\n\n",
"for",
"i",
":=",
"len",
"(",
"ranges",
")",
"-",
"1",
";",
"i",
">=",
"0",
";",
"i",
"--",
"{",
"rrm",
"=",
"ranges",
"[",
"i",
"]",
"\n\n",
"if",
"rrm",
".",
"FromLo",
"<=",
"r",
"&&",
"r",
"<=",
"rrm",
".",
"FromHi",
"{",
"translated",
"=",
"true",
"\n\n",
"if",
"tr",
".",
"mappedRune",
">=",
"0",
"{",
"result",
"=",
"tr",
".",
"mappedRune",
"\n",
"break",
"\n",
"}",
"\n\n",
"if",
"rrm",
".",
"ToLo",
"<",
"rrm",
".",
"ToHi",
"{",
"result",
"=",
"rrm",
".",
"ToLo",
"+",
"r",
"-",
"rrm",
".",
"FromLo",
"\n",
"}",
"else",
"if",
"rrm",
".",
"ToLo",
">",
"rrm",
".",
"ToHi",
"{",
"// ToHi can be smaller than ToLo if range is from higher to lower.",
"result",
"=",
"rrm",
".",
"ToLo",
"-",
"r",
"+",
"rrm",
".",
"FromLo",
"\n",
"}",
"else",
"{",
"result",
"=",
"rrm",
".",
"ToLo",
"\n",
"}",
"\n\n",
"break",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"tr",
".",
"reverted",
"{",
"if",
"!",
"translated",
"{",
"result",
"=",
"tr",
".",
"mappedRune",
"\n",
"}",
"\n\n",
"translated",
"=",
"!",
"translated",
"\n",
"}",
"\n\n",
"if",
"!",
"translated",
"{",
"result",
"=",
"r",
"\n",
"}",
"\n\n",
"return",
"\n",
"}"
] |
// TranslateRune return translated rune and true if r matches the from pattern.
// If r doesn't match the pattern, original r is returned and translated is false.
|
[
"TranslateRune",
"return",
"translated",
"rune",
"and",
"true",
"if",
"r",
"matches",
"the",
"from",
"pattern",
".",
"If",
"r",
"doesn",
"t",
"match",
"the",
"pattern",
"original",
"r",
"is",
"returned",
"and",
"translated",
"is",
"false",
"."
] |
8bbcf2f9ccb55755e748b7644164cd4bdce94c1d
|
https://github.com/huandu/xstrings/blob/8bbcf2f9ccb55755e748b7644164cd4bdce94c1d/translate.go#L333-L409
|
19,473
|
huandu/xstrings
|
count.go
|
WordCount
|
func WordCount(str string) int {
var r rune
var size, n int
inWord := false
for len(str) > 0 {
r, size = utf8.DecodeRuneInString(str)
switch {
case isAlphabet(r):
if !inWord {
inWord = true
n++
}
case inWord && (r == '\'' || r == '-'):
// Still in word.
default:
inWord = false
}
str = str[size:]
}
return n
}
|
go
|
func WordCount(str string) int {
var r rune
var size, n int
inWord := false
for len(str) > 0 {
r, size = utf8.DecodeRuneInString(str)
switch {
case isAlphabet(r):
if !inWord {
inWord = true
n++
}
case inWord && (r == '\'' || r == '-'):
// Still in word.
default:
inWord = false
}
str = str[size:]
}
return n
}
|
[
"func",
"WordCount",
"(",
"str",
"string",
")",
"int",
"{",
"var",
"r",
"rune",
"\n",
"var",
"size",
",",
"n",
"int",
"\n\n",
"inWord",
":=",
"false",
"\n\n",
"for",
"len",
"(",
"str",
")",
">",
"0",
"{",
"r",
",",
"size",
"=",
"utf8",
".",
"DecodeRuneInString",
"(",
"str",
")",
"\n\n",
"switch",
"{",
"case",
"isAlphabet",
"(",
"r",
")",
":",
"if",
"!",
"inWord",
"{",
"inWord",
"=",
"true",
"\n",
"n",
"++",
"\n",
"}",
"\n\n",
"case",
"inWord",
"&&",
"(",
"r",
"==",
"'\\''",
"||",
"r",
"==",
"'-'",
")",
":",
"// Still in word.",
"default",
":",
"inWord",
"=",
"false",
"\n",
"}",
"\n\n",
"str",
"=",
"str",
"[",
"size",
":",
"]",
"\n",
"}",
"\n\n",
"return",
"n",
"\n",
"}"
] |
// WordCount returns number of words in a string.
//
// Word is defined as a locale dependent string containing alphabetic characters,
// which may also contain but not start with `'` and `-` characters.
|
[
"WordCount",
"returns",
"number",
"of",
"words",
"in",
"a",
"string",
".",
"Word",
"is",
"defined",
"as",
"a",
"locale",
"dependent",
"string",
"containing",
"alphabetic",
"characters",
"which",
"may",
"also",
"contain",
"but",
"not",
"start",
"with",
"and",
"-",
"characters",
"."
] |
8bbcf2f9ccb55755e748b7644164cd4bdce94c1d
|
https://github.com/huandu/xstrings/blob/8bbcf2f9ccb55755e748b7644164cd4bdce94c1d/count.go#L20-L47
|
19,474
|
huandu/xstrings
|
count.go
|
isAlphabet
|
func isAlphabet(r rune) bool {
if !unicode.IsLetter(r) {
return false
}
switch {
// Quick check for non-CJK character.
case r < minCJKCharacter:
return true
// Common CJK characters.
case r >= '\u4E00' && r <= '\u9FCC':
return false
// Rare CJK characters.
case r >= '\u3400' && r <= '\u4D85':
return false
// Rare and historic CJK characters.
case r >= '\U00020000' && r <= '\U0002B81D':
return false
}
return true
}
|
go
|
func isAlphabet(r rune) bool {
if !unicode.IsLetter(r) {
return false
}
switch {
// Quick check for non-CJK character.
case r < minCJKCharacter:
return true
// Common CJK characters.
case r >= '\u4E00' && r <= '\u9FCC':
return false
// Rare CJK characters.
case r >= '\u3400' && r <= '\u4D85':
return false
// Rare and historic CJK characters.
case r >= '\U00020000' && r <= '\U0002B81D':
return false
}
return true
}
|
[
"func",
"isAlphabet",
"(",
"r",
"rune",
")",
"bool",
"{",
"if",
"!",
"unicode",
".",
"IsLetter",
"(",
"r",
")",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"switch",
"{",
"// Quick check for non-CJK character.",
"case",
"r",
"<",
"minCJKCharacter",
":",
"return",
"true",
"\n\n",
"// Common CJK characters.",
"case",
"r",
">=",
"'\\u4E00'",
"&&",
"r",
"<=",
"'\\u9FCC'",
":",
"return",
"false",
"\n\n",
"// Rare CJK characters.",
"case",
"r",
">=",
"'\\u3400'",
"&&",
"r",
"<=",
"'\\u4D85'",
":",
"return",
"false",
"\n\n",
"// Rare and historic CJK characters.",
"case",
"r",
">=",
"'\\U00020000'",
"&&",
"r",
"<=",
"'\\U0002B81D'",
":",
"return",
"false",
"\n",
"}",
"\n\n",
"return",
"true",
"\n",
"}"
] |
// Checks r is a letter but not CJK character.
|
[
"Checks",
"r",
"is",
"a",
"letter",
"but",
"not",
"CJK",
"character",
"."
] |
8bbcf2f9ccb55755e748b7644164cd4bdce94c1d
|
https://github.com/huandu/xstrings/blob/8bbcf2f9ccb55755e748b7644164cd4bdce94c1d/count.go#L52-L76
|
19,475
|
huandu/xstrings
|
convert.go
|
SwapCase
|
func SwapCase(str string) string {
var r rune
var size int
buf := &bytes.Buffer{}
for len(str) > 0 {
r, size = utf8.DecodeRuneInString(str)
switch {
case unicode.IsUpper(r):
buf.WriteRune(unicode.ToLower(r))
case unicode.IsLower(r):
buf.WriteRune(unicode.ToUpper(r))
default:
buf.WriteRune(r)
}
str = str[size:]
}
return buf.String()
}
|
go
|
func SwapCase(str string) string {
var r rune
var size int
buf := &bytes.Buffer{}
for len(str) > 0 {
r, size = utf8.DecodeRuneInString(str)
switch {
case unicode.IsUpper(r):
buf.WriteRune(unicode.ToLower(r))
case unicode.IsLower(r):
buf.WriteRune(unicode.ToUpper(r))
default:
buf.WriteRune(r)
}
str = str[size:]
}
return buf.String()
}
|
[
"func",
"SwapCase",
"(",
"str",
"string",
")",
"string",
"{",
"var",
"r",
"rune",
"\n",
"var",
"size",
"int",
"\n\n",
"buf",
":=",
"&",
"bytes",
".",
"Buffer",
"{",
"}",
"\n\n",
"for",
"len",
"(",
"str",
")",
">",
"0",
"{",
"r",
",",
"size",
"=",
"utf8",
".",
"DecodeRuneInString",
"(",
"str",
")",
"\n\n",
"switch",
"{",
"case",
"unicode",
".",
"IsUpper",
"(",
"r",
")",
":",
"buf",
".",
"WriteRune",
"(",
"unicode",
".",
"ToLower",
"(",
"r",
")",
")",
"\n\n",
"case",
"unicode",
".",
"IsLower",
"(",
"r",
")",
":",
"buf",
".",
"WriteRune",
"(",
"unicode",
".",
"ToUpper",
"(",
"r",
")",
")",
"\n\n",
"default",
":",
"buf",
".",
"WriteRune",
"(",
"r",
")",
"\n",
"}",
"\n\n",
"str",
"=",
"str",
"[",
"size",
":",
"]",
"\n",
"}",
"\n\n",
"return",
"buf",
".",
"String",
"(",
")",
"\n",
"}"
] |
// SwapCase will swap characters case from upper to lower or lower to upper.
|
[
"SwapCase",
"will",
"swap",
"characters",
"case",
"from",
"upper",
"to",
"lower",
"or",
"lower",
"to",
"upper",
"."
] |
8bbcf2f9ccb55755e748b7644164cd4bdce94c1d
|
https://github.com/huandu/xstrings/blob/8bbcf2f9ccb55755e748b7644164cd4bdce94c1d/convert.go#L209-L233
|
19,476
|
huandu/xstrings
|
convert.go
|
FirstRuneToUpper
|
func FirstRuneToUpper(str string) string {
if str == "" {
return str
}
r, size := utf8.DecodeRuneInString(str)
if !unicode.IsLower(r) {
return str
}
buf := &bytes.Buffer{}
buf.WriteRune(unicode.ToUpper(r))
buf.WriteString(str[size:])
return buf.String()
}
|
go
|
func FirstRuneToUpper(str string) string {
if str == "" {
return str
}
r, size := utf8.DecodeRuneInString(str)
if !unicode.IsLower(r) {
return str
}
buf := &bytes.Buffer{}
buf.WriteRune(unicode.ToUpper(r))
buf.WriteString(str[size:])
return buf.String()
}
|
[
"func",
"FirstRuneToUpper",
"(",
"str",
"string",
")",
"string",
"{",
"if",
"str",
"==",
"\"",
"\"",
"{",
"return",
"str",
"\n",
"}",
"\n\n",
"r",
",",
"size",
":=",
"utf8",
".",
"DecodeRuneInString",
"(",
"str",
")",
"\n\n",
"if",
"!",
"unicode",
".",
"IsLower",
"(",
"r",
")",
"{",
"return",
"str",
"\n",
"}",
"\n\n",
"buf",
":=",
"&",
"bytes",
".",
"Buffer",
"{",
"}",
"\n",
"buf",
".",
"WriteRune",
"(",
"unicode",
".",
"ToUpper",
"(",
"r",
")",
")",
"\n",
"buf",
".",
"WriteString",
"(",
"str",
"[",
"size",
":",
"]",
")",
"\n",
"return",
"buf",
".",
"String",
"(",
")",
"\n",
"}"
] |
// FirstRuneToUpper converts first rune to upper case if necessary.
|
[
"FirstRuneToUpper",
"converts",
"first",
"rune",
"to",
"upper",
"case",
"if",
"necessary",
"."
] |
8bbcf2f9ccb55755e748b7644164cd4bdce94c1d
|
https://github.com/huandu/xstrings/blob/8bbcf2f9ccb55755e748b7644164cd4bdce94c1d/convert.go#L236-L251
|
19,477
|
huandu/xstrings
|
convert.go
|
FirstRuneToLower
|
func FirstRuneToLower(str string) string {
if str == "" {
return str
}
r, size := utf8.DecodeRuneInString(str)
if !unicode.IsUpper(r) {
return str
}
buf := &bytes.Buffer{}
buf.WriteRune(unicode.ToLower(r))
buf.WriteString(str[size:])
return buf.String()
}
|
go
|
func FirstRuneToLower(str string) string {
if str == "" {
return str
}
r, size := utf8.DecodeRuneInString(str)
if !unicode.IsUpper(r) {
return str
}
buf := &bytes.Buffer{}
buf.WriteRune(unicode.ToLower(r))
buf.WriteString(str[size:])
return buf.String()
}
|
[
"func",
"FirstRuneToLower",
"(",
"str",
"string",
")",
"string",
"{",
"if",
"str",
"==",
"\"",
"\"",
"{",
"return",
"str",
"\n",
"}",
"\n\n",
"r",
",",
"size",
":=",
"utf8",
".",
"DecodeRuneInString",
"(",
"str",
")",
"\n\n",
"if",
"!",
"unicode",
".",
"IsUpper",
"(",
"r",
")",
"{",
"return",
"str",
"\n",
"}",
"\n\n",
"buf",
":=",
"&",
"bytes",
".",
"Buffer",
"{",
"}",
"\n",
"buf",
".",
"WriteRune",
"(",
"unicode",
".",
"ToLower",
"(",
"r",
")",
")",
"\n",
"buf",
".",
"WriteString",
"(",
"str",
"[",
"size",
":",
"]",
")",
"\n",
"return",
"buf",
".",
"String",
"(",
")",
"\n",
"}"
] |
// FirstRuneToLower converts first rune to lower case if necessary.
|
[
"FirstRuneToLower",
"converts",
"first",
"rune",
"to",
"lower",
"case",
"if",
"necessary",
"."
] |
8bbcf2f9ccb55755e748b7644164cd4bdce94c1d
|
https://github.com/huandu/xstrings/blob/8bbcf2f9ccb55755e748b7644164cd4bdce94c1d/convert.go#L254-L269
|
19,478
|
huandu/xstrings
|
convert.go
|
ShuffleSource
|
func ShuffleSource(str string, src rand.Source) string {
if str == "" {
return str
}
runes := []rune(str)
index := 0
r := rand.New(src)
for i := len(runes) - 1; i > 0; i-- {
index = r.Intn(i + 1)
if i != index {
runes[i], runes[index] = runes[index], runes[i]
}
}
return string(runes)
}
|
go
|
func ShuffleSource(str string, src rand.Source) string {
if str == "" {
return str
}
runes := []rune(str)
index := 0
r := rand.New(src)
for i := len(runes) - 1; i > 0; i-- {
index = r.Intn(i + 1)
if i != index {
runes[i], runes[index] = runes[index], runes[i]
}
}
return string(runes)
}
|
[
"func",
"ShuffleSource",
"(",
"str",
"string",
",",
"src",
"rand",
".",
"Source",
")",
"string",
"{",
"if",
"str",
"==",
"\"",
"\"",
"{",
"return",
"str",
"\n",
"}",
"\n\n",
"runes",
":=",
"[",
"]",
"rune",
"(",
"str",
")",
"\n",
"index",
":=",
"0",
"\n",
"r",
":=",
"rand",
".",
"New",
"(",
"src",
")",
"\n\n",
"for",
"i",
":=",
"len",
"(",
"runes",
")",
"-",
"1",
";",
"i",
">",
"0",
";",
"i",
"--",
"{",
"index",
"=",
"r",
".",
"Intn",
"(",
"i",
"+",
"1",
")",
"\n\n",
"if",
"i",
"!=",
"index",
"{",
"runes",
"[",
"i",
"]",
",",
"runes",
"[",
"index",
"]",
"=",
"runes",
"[",
"index",
"]",
",",
"runes",
"[",
"i",
"]",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"string",
"(",
"runes",
")",
"\n",
"}"
] |
// ShuffleSource randomizes runes in a string with given random source.
|
[
"ShuffleSource",
"randomizes",
"runes",
"in",
"a",
"string",
"with",
"given",
"random",
"source",
"."
] |
8bbcf2f9ccb55755e748b7644164cd4bdce94c1d
|
https://github.com/huandu/xstrings/blob/8bbcf2f9ccb55755e748b7644164cd4bdce94c1d/convert.go#L293-L311
|
19,479
|
huandu/xstrings
|
manipulate.go
|
Reverse
|
func Reverse(str string) string {
var size int
tail := len(str)
buf := make([]byte, tail)
s := buf
for len(str) > 0 {
_, size = utf8.DecodeRuneInString(str)
tail -= size
s = append(s[:tail], []byte(str[:size])...)
str = str[size:]
}
return string(buf)
}
|
go
|
func Reverse(str string) string {
var size int
tail := len(str)
buf := make([]byte, tail)
s := buf
for len(str) > 0 {
_, size = utf8.DecodeRuneInString(str)
tail -= size
s = append(s[:tail], []byte(str[:size])...)
str = str[size:]
}
return string(buf)
}
|
[
"func",
"Reverse",
"(",
"str",
"string",
")",
"string",
"{",
"var",
"size",
"int",
"\n\n",
"tail",
":=",
"len",
"(",
"str",
")",
"\n",
"buf",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"tail",
")",
"\n",
"s",
":=",
"buf",
"\n\n",
"for",
"len",
"(",
"str",
")",
">",
"0",
"{",
"_",
",",
"size",
"=",
"utf8",
".",
"DecodeRuneInString",
"(",
"str",
")",
"\n",
"tail",
"-=",
"size",
"\n",
"s",
"=",
"append",
"(",
"s",
"[",
":",
"tail",
"]",
",",
"[",
"]",
"byte",
"(",
"str",
"[",
":",
"size",
"]",
")",
"...",
")",
"\n",
"str",
"=",
"str",
"[",
"size",
":",
"]",
"\n",
"}",
"\n\n",
"return",
"string",
"(",
"buf",
")",
"\n",
"}"
] |
// Reverse a utf8 encoded string.
|
[
"Reverse",
"a",
"utf8",
"encoded",
"string",
"."
] |
8bbcf2f9ccb55755e748b7644164cd4bdce94c1d
|
https://github.com/huandu/xstrings/blob/8bbcf2f9ccb55755e748b7644164cd4bdce94c1d/manipulate.go#L13-L28
|
19,480
|
huandu/xstrings
|
manipulate.go
|
Partition
|
func Partition(str, sep string) (head, match, tail string) {
index := strings.Index(str, sep)
if index == -1 {
head = str
return
}
head = str[:index]
match = str[index : index+len(sep)]
tail = str[index+len(sep):]
return
}
|
go
|
func Partition(str, sep string) (head, match, tail string) {
index := strings.Index(str, sep)
if index == -1 {
head = str
return
}
head = str[:index]
match = str[index : index+len(sep)]
tail = str[index+len(sep):]
return
}
|
[
"func",
"Partition",
"(",
"str",
",",
"sep",
"string",
")",
"(",
"head",
",",
"match",
",",
"tail",
"string",
")",
"{",
"index",
":=",
"strings",
".",
"Index",
"(",
"str",
",",
"sep",
")",
"\n\n",
"if",
"index",
"==",
"-",
"1",
"{",
"head",
"=",
"str",
"\n",
"return",
"\n",
"}",
"\n\n",
"head",
"=",
"str",
"[",
":",
"index",
"]",
"\n",
"match",
"=",
"str",
"[",
"index",
":",
"index",
"+",
"len",
"(",
"sep",
")",
"]",
"\n",
"tail",
"=",
"str",
"[",
"index",
"+",
"len",
"(",
"sep",
")",
":",
"]",
"\n",
"return",
"\n",
"}"
] |
// Partition splits a string by sep into three parts.
// The return value is a slice of strings with head, match and tail.
//
// If str contains sep, for example "hello" and "l", Partition returns
// "he", "l", "lo"
//
// If str doesn't contain sep, for example "hello" and "x", Partition returns
// "hello", "", ""
|
[
"Partition",
"splits",
"a",
"string",
"by",
"sep",
"into",
"three",
"parts",
".",
"The",
"return",
"value",
"is",
"a",
"slice",
"of",
"strings",
"with",
"head",
"match",
"and",
"tail",
".",
"If",
"str",
"contains",
"sep",
"for",
"example",
"hello",
"and",
"l",
"Partition",
"returns",
"he",
"l",
"lo",
"If",
"str",
"doesn",
"t",
"contain",
"sep",
"for",
"example",
"hello",
"and",
"x",
"Partition",
"returns",
"hello"
] |
8bbcf2f9ccb55755e748b7644164cd4bdce94c1d
|
https://github.com/huandu/xstrings/blob/8bbcf2f9ccb55755e748b7644164cd4bdce94c1d/manipulate.go#L87-L99
|
19,481
|
huandu/xstrings
|
manipulate.go
|
LastPartition
|
func LastPartition(str, sep string) (head, match, tail string) {
index := strings.LastIndex(str, sep)
if index == -1 {
tail = str
return
}
head = str[:index]
match = str[index : index+len(sep)]
tail = str[index+len(sep):]
return
}
|
go
|
func LastPartition(str, sep string) (head, match, tail string) {
index := strings.LastIndex(str, sep)
if index == -1 {
tail = str
return
}
head = str[:index]
match = str[index : index+len(sep)]
tail = str[index+len(sep):]
return
}
|
[
"func",
"LastPartition",
"(",
"str",
",",
"sep",
"string",
")",
"(",
"head",
",",
"match",
",",
"tail",
"string",
")",
"{",
"index",
":=",
"strings",
".",
"LastIndex",
"(",
"str",
",",
"sep",
")",
"\n\n",
"if",
"index",
"==",
"-",
"1",
"{",
"tail",
"=",
"str",
"\n",
"return",
"\n",
"}",
"\n\n",
"head",
"=",
"str",
"[",
":",
"index",
"]",
"\n",
"match",
"=",
"str",
"[",
"index",
":",
"index",
"+",
"len",
"(",
"sep",
")",
"]",
"\n",
"tail",
"=",
"str",
"[",
"index",
"+",
"len",
"(",
"sep",
")",
":",
"]",
"\n",
"return",
"\n",
"}"
] |
// LastPartition splits a string by last instance of sep into three parts.
// The return value is a slice of strings with head, match and tail.
//
// If str contains sep, for example "hello" and "l", LastPartition returns
// "hel", "l", "o"
//
// If str doesn't contain sep, for example "hello" and "x", LastPartition returns
// "", "", "hello"
|
[
"LastPartition",
"splits",
"a",
"string",
"by",
"last",
"instance",
"of",
"sep",
"into",
"three",
"parts",
".",
"The",
"return",
"value",
"is",
"a",
"slice",
"of",
"strings",
"with",
"head",
"match",
"and",
"tail",
".",
"If",
"str",
"contains",
"sep",
"for",
"example",
"hello",
"and",
"l",
"LastPartition",
"returns",
"hel",
"l",
"o",
"If",
"str",
"doesn",
"t",
"contain",
"sep",
"for",
"example",
"hello",
"and",
"x",
"LastPartition",
"returns",
"hello"
] |
8bbcf2f9ccb55755e748b7644164cd4bdce94c1d
|
https://github.com/huandu/xstrings/blob/8bbcf2f9ccb55755e748b7644164cd4bdce94c1d/manipulate.go#L109-L121
|
19,482
|
huandu/xstrings
|
manipulate.go
|
Insert
|
func Insert(dst, src string, index int) string {
return Slice(dst, 0, index) + src + Slice(dst, index, -1)
}
|
go
|
func Insert(dst, src string, index int) string {
return Slice(dst, 0, index) + src + Slice(dst, index, -1)
}
|
[
"func",
"Insert",
"(",
"dst",
",",
"src",
"string",
",",
"index",
"int",
")",
"string",
"{",
"return",
"Slice",
"(",
"dst",
",",
"0",
",",
"index",
")",
"+",
"src",
"+",
"Slice",
"(",
"dst",
",",
"index",
",",
"-",
"1",
")",
"\n",
"}"
] |
// Insert src into dst at given rune index.
// Index is counted by runes instead of bytes.
//
// If index is out of range of dst, panic with out of range.
|
[
"Insert",
"src",
"into",
"dst",
"at",
"given",
"rune",
"index",
".",
"Index",
"is",
"counted",
"by",
"runes",
"instead",
"of",
"bytes",
".",
"If",
"index",
"is",
"out",
"of",
"range",
"of",
"dst",
"panic",
"with",
"out",
"of",
"range",
"."
] |
8bbcf2f9ccb55755e748b7644164cd4bdce94c1d
|
https://github.com/huandu/xstrings/blob/8bbcf2f9ccb55755e748b7644164cd4bdce94c1d/manipulate.go#L127-L129
|
19,483
|
huandu/xstrings
|
manipulate.go
|
Scrub
|
func Scrub(str, repl string) string {
var buf *bytes.Buffer
var r rune
var size, pos int
var hasError bool
origin := str
for len(str) > 0 {
r, size = utf8.DecodeRuneInString(str)
if r == utf8.RuneError {
if !hasError {
if buf == nil {
buf = &bytes.Buffer{}
}
buf.WriteString(origin[:pos])
hasError = true
}
} else if hasError {
hasError = false
buf.WriteString(repl)
origin = origin[pos:]
pos = 0
}
pos += size
str = str[size:]
}
if buf != nil {
buf.WriteString(origin)
return buf.String()
}
// No invalid byte.
return origin
}
|
go
|
func Scrub(str, repl string) string {
var buf *bytes.Buffer
var r rune
var size, pos int
var hasError bool
origin := str
for len(str) > 0 {
r, size = utf8.DecodeRuneInString(str)
if r == utf8.RuneError {
if !hasError {
if buf == nil {
buf = &bytes.Buffer{}
}
buf.WriteString(origin[:pos])
hasError = true
}
} else if hasError {
hasError = false
buf.WriteString(repl)
origin = origin[pos:]
pos = 0
}
pos += size
str = str[size:]
}
if buf != nil {
buf.WriteString(origin)
return buf.String()
}
// No invalid byte.
return origin
}
|
[
"func",
"Scrub",
"(",
"str",
",",
"repl",
"string",
")",
"string",
"{",
"var",
"buf",
"*",
"bytes",
".",
"Buffer",
"\n",
"var",
"r",
"rune",
"\n",
"var",
"size",
",",
"pos",
"int",
"\n",
"var",
"hasError",
"bool",
"\n\n",
"origin",
":=",
"str",
"\n\n",
"for",
"len",
"(",
"str",
")",
">",
"0",
"{",
"r",
",",
"size",
"=",
"utf8",
".",
"DecodeRuneInString",
"(",
"str",
")",
"\n\n",
"if",
"r",
"==",
"utf8",
".",
"RuneError",
"{",
"if",
"!",
"hasError",
"{",
"if",
"buf",
"==",
"nil",
"{",
"buf",
"=",
"&",
"bytes",
".",
"Buffer",
"{",
"}",
"\n",
"}",
"\n\n",
"buf",
".",
"WriteString",
"(",
"origin",
"[",
":",
"pos",
"]",
")",
"\n",
"hasError",
"=",
"true",
"\n",
"}",
"\n",
"}",
"else",
"if",
"hasError",
"{",
"hasError",
"=",
"false",
"\n",
"buf",
".",
"WriteString",
"(",
"repl",
")",
"\n\n",
"origin",
"=",
"origin",
"[",
"pos",
":",
"]",
"\n",
"pos",
"=",
"0",
"\n",
"}",
"\n\n",
"pos",
"+=",
"size",
"\n",
"str",
"=",
"str",
"[",
"size",
":",
"]",
"\n",
"}",
"\n\n",
"if",
"buf",
"!=",
"nil",
"{",
"buf",
".",
"WriteString",
"(",
"origin",
")",
"\n",
"return",
"buf",
".",
"String",
"(",
")",
"\n",
"}",
"\n\n",
"// No invalid byte.",
"return",
"origin",
"\n",
"}"
] |
// Scrub scrubs invalid utf8 bytes with repl string.
// Adjacent invalid bytes are replaced only once.
|
[
"Scrub",
"scrubs",
"invalid",
"utf8",
"bytes",
"with",
"repl",
"string",
".",
"Adjacent",
"invalid",
"bytes",
"are",
"replaced",
"only",
"once",
"."
] |
8bbcf2f9ccb55755e748b7644164cd4bdce94c1d
|
https://github.com/huandu/xstrings/blob/8bbcf2f9ccb55755e748b7644164cd4bdce94c1d/manipulate.go#L133-L172
|
19,484
|
huandu/xstrings
|
manipulate.go
|
WordSplit
|
func WordSplit(str string) []string {
var word string
var words []string
var r rune
var size, pos int
inWord := false
for len(str) > 0 {
r, size = utf8.DecodeRuneInString(str)
switch {
case isAlphabet(r):
if !inWord {
inWord = true
word = str
pos = 0
}
case inWord && (r == '\'' || r == '-'):
// Still in word.
default:
if inWord {
inWord = false
words = append(words, word[:pos])
}
}
pos += size
str = str[size:]
}
if inWord {
words = append(words, word[:pos])
}
return words
}
|
go
|
func WordSplit(str string) []string {
var word string
var words []string
var r rune
var size, pos int
inWord := false
for len(str) > 0 {
r, size = utf8.DecodeRuneInString(str)
switch {
case isAlphabet(r):
if !inWord {
inWord = true
word = str
pos = 0
}
case inWord && (r == '\'' || r == '-'):
// Still in word.
default:
if inWord {
inWord = false
words = append(words, word[:pos])
}
}
pos += size
str = str[size:]
}
if inWord {
words = append(words, word[:pos])
}
return words
}
|
[
"func",
"WordSplit",
"(",
"str",
"string",
")",
"[",
"]",
"string",
"{",
"var",
"word",
"string",
"\n",
"var",
"words",
"[",
"]",
"string",
"\n",
"var",
"r",
"rune",
"\n",
"var",
"size",
",",
"pos",
"int",
"\n\n",
"inWord",
":=",
"false",
"\n\n",
"for",
"len",
"(",
"str",
")",
">",
"0",
"{",
"r",
",",
"size",
"=",
"utf8",
".",
"DecodeRuneInString",
"(",
"str",
")",
"\n\n",
"switch",
"{",
"case",
"isAlphabet",
"(",
"r",
")",
":",
"if",
"!",
"inWord",
"{",
"inWord",
"=",
"true",
"\n",
"word",
"=",
"str",
"\n",
"pos",
"=",
"0",
"\n",
"}",
"\n\n",
"case",
"inWord",
"&&",
"(",
"r",
"==",
"'\\''",
"||",
"r",
"==",
"'-'",
")",
":",
"// Still in word.",
"default",
":",
"if",
"inWord",
"{",
"inWord",
"=",
"false",
"\n",
"words",
"=",
"append",
"(",
"words",
",",
"word",
"[",
":",
"pos",
"]",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"pos",
"+=",
"size",
"\n",
"str",
"=",
"str",
"[",
"size",
":",
"]",
"\n",
"}",
"\n\n",
"if",
"inWord",
"{",
"words",
"=",
"append",
"(",
"words",
",",
"word",
"[",
":",
"pos",
"]",
")",
"\n",
"}",
"\n\n",
"return",
"words",
"\n",
"}"
] |
// WordSplit splits a string into words. Returns a slice of words.
// If there is no word in a string, return nil.
//
// Word is defined as a locale dependent string containing alphabetic characters,
// which may also contain but not start with `'` and `-` characters.
|
[
"WordSplit",
"splits",
"a",
"string",
"into",
"words",
".",
"Returns",
"a",
"slice",
"of",
"words",
".",
"If",
"there",
"is",
"no",
"word",
"in",
"a",
"string",
"return",
"nil",
".",
"Word",
"is",
"defined",
"as",
"a",
"locale",
"dependent",
"string",
"containing",
"alphabetic",
"characters",
"which",
"may",
"also",
"contain",
"but",
"not",
"start",
"with",
"and",
"-",
"characters",
"."
] |
8bbcf2f9ccb55755e748b7644164cd4bdce94c1d
|
https://github.com/huandu/xstrings/blob/8bbcf2f9ccb55755e748b7644164cd4bdce94c1d/manipulate.go#L179-L217
|
19,485
|
huandu/xstrings
|
common.go
|
allocBuffer
|
func allocBuffer(orig, cur string) *bytes.Buffer {
output := &bytes.Buffer{}
maxSize := len(orig) * 4
// Avoid to reserve too much memory at once.
if maxSize > bufferMaxInitGrowSize {
maxSize = bufferMaxInitGrowSize
}
output.Grow(maxSize)
output.WriteString(orig[:len(orig)-len(cur)])
return output
}
|
go
|
func allocBuffer(orig, cur string) *bytes.Buffer {
output := &bytes.Buffer{}
maxSize := len(orig) * 4
// Avoid to reserve too much memory at once.
if maxSize > bufferMaxInitGrowSize {
maxSize = bufferMaxInitGrowSize
}
output.Grow(maxSize)
output.WriteString(orig[:len(orig)-len(cur)])
return output
}
|
[
"func",
"allocBuffer",
"(",
"orig",
",",
"cur",
"string",
")",
"*",
"bytes",
".",
"Buffer",
"{",
"output",
":=",
"&",
"bytes",
".",
"Buffer",
"{",
"}",
"\n",
"maxSize",
":=",
"len",
"(",
"orig",
")",
"*",
"4",
"\n\n",
"// Avoid to reserve too much memory at once.",
"if",
"maxSize",
">",
"bufferMaxInitGrowSize",
"{",
"maxSize",
"=",
"bufferMaxInitGrowSize",
"\n",
"}",
"\n\n",
"output",
".",
"Grow",
"(",
"maxSize",
")",
"\n",
"output",
".",
"WriteString",
"(",
"orig",
"[",
":",
"len",
"(",
"orig",
")",
"-",
"len",
"(",
"cur",
")",
"]",
")",
"\n",
"return",
"output",
"\n",
"}"
] |
// Lazy initialize a buffer.
|
[
"Lazy",
"initialize",
"a",
"buffer",
"."
] |
8bbcf2f9ccb55755e748b7644164cd4bdce94c1d
|
https://github.com/huandu/xstrings/blob/8bbcf2f9ccb55755e748b7644164cd4bdce94c1d/common.go#L13-L25
|
19,486
|
trustmaster/goflow
|
component.go
|
Run
|
func Run(c Component) Wait {
wait := make(Wait)
go func() {
c.Process()
wait <- Done{}
}()
return wait
}
|
go
|
func Run(c Component) Wait {
wait := make(Wait)
go func() {
c.Process()
wait <- Done{}
}()
return wait
}
|
[
"func",
"Run",
"(",
"c",
"Component",
")",
"Wait",
"{",
"wait",
":=",
"make",
"(",
"Wait",
")",
"\n",
"go",
"func",
"(",
")",
"{",
"c",
".",
"Process",
"(",
")",
"\n",
"wait",
"<-",
"Done",
"{",
"}",
"\n",
"}",
"(",
")",
"\n",
"return",
"wait",
"\n",
"}"
] |
// Run the component process
|
[
"Run",
"the",
"component",
"process"
] |
98ea6cda15a37b5df5b92f04daa4af10e58c1874
|
https://github.com/trustmaster/goflow/blob/98ea6cda15a37b5df5b92f04daa4af10e58c1874/component.go#L15-L22
|
19,487
|
trustmaster/goflow
|
component.go
|
NewInputGuard
|
func NewInputGuard(ports ...string) *InputGuard {
portMap := make(map[string]bool, len(ports))
for _, p := range ports {
portMap[p] = false
}
return &InputGuard{portMap, 0}
}
|
go
|
func NewInputGuard(ports ...string) *InputGuard {
portMap := make(map[string]bool, len(ports))
for _, p := range ports {
portMap[p] = false
}
return &InputGuard{portMap, 0}
}
|
[
"func",
"NewInputGuard",
"(",
"ports",
"...",
"string",
")",
"*",
"InputGuard",
"{",
"portMap",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"bool",
",",
"len",
"(",
"ports",
")",
")",
"\n",
"for",
"_",
",",
"p",
":=",
"range",
"ports",
"{",
"portMap",
"[",
"p",
"]",
"=",
"false",
"\n",
"}",
"\n",
"return",
"&",
"InputGuard",
"{",
"portMap",
",",
"0",
"}",
"\n",
"}"
] |
// NewInputGuard returns a guard for a given number of inputs
|
[
"NewInputGuard",
"returns",
"a",
"guard",
"for",
"a",
"given",
"number",
"of",
"inputs"
] |
98ea6cda15a37b5df5b92f04daa4af10e58c1874
|
https://github.com/trustmaster/goflow/blob/98ea6cda15a37b5df5b92f04daa4af10e58c1874/component.go#L31-L37
|
19,488
|
trustmaster/goflow
|
component.go
|
Complete
|
func (g *InputGuard) Complete(port string) bool {
if !g.ports[port] {
g.ports[port] = true
g.complete++
}
return g.complete >= len(g.ports)
}
|
go
|
func (g *InputGuard) Complete(port string) bool {
if !g.ports[port] {
g.ports[port] = true
g.complete++
}
return g.complete >= len(g.ports)
}
|
[
"func",
"(",
"g",
"*",
"InputGuard",
")",
"Complete",
"(",
"port",
"string",
")",
"bool",
"{",
"if",
"!",
"g",
".",
"ports",
"[",
"port",
"]",
"{",
"g",
".",
"ports",
"[",
"port",
"]",
"=",
"true",
"\n",
"g",
".",
"complete",
"++",
"\n",
"}",
"\n",
"return",
"g",
".",
"complete",
">=",
"len",
"(",
"g",
".",
"ports",
")",
"\n",
"}"
] |
// Complete is called when a port is closed and returns true when all the ports have been closed
|
[
"Complete",
"is",
"called",
"when",
"a",
"port",
"is",
"closed",
"and",
"returns",
"true",
"when",
"all",
"the",
"ports",
"have",
"been",
"closed"
] |
98ea6cda15a37b5df5b92f04daa4af10e58c1874
|
https://github.com/trustmaster/goflow/blob/98ea6cda15a37b5df5b92f04daa4af10e58c1874/component.go#L40-L46
|
19,489
|
trustmaster/goflow
|
loader.go
|
ParseJSON
|
func ParseJSON(js []byte) *Graph {
// Parse JSON into Go struct
var descr graphDescription
err := json.Unmarshal(js, &descr)
if err != nil {
return nil
}
// fmt.Printf("%+v\n", descr)
constructor := func() interface{} {
// Create a new Graph
net := new(Graph)
net.InitGraphState()
// Add processes to the network
for procName, procValue := range descr.Processes {
net.AddNew(procValue.Component, procName)
// Process mode detection
if procValue.Metadata.PoolSize > 0 {
proc := net.Get(procName).(*Component)
proc.Mode = ComponentModePool
proc.PoolSize = uint8(procValue.Metadata.PoolSize)
} else if procValue.Metadata.Sync {
proc := net.Get(procName).(*Component)
proc.Mode = ComponentModeSync
}
}
// Add connections
for _, conn := range descr.Connections {
// Check if it is an IIP or actual connection
if conn.Data == nil {
// Add a connection
net.ConnectBuf(conn.Src.Process, conn.Src.Port, conn.Tgt.Process, conn.Tgt.Port, conn.Metadata.Buffer)
} else {
// Add an IIP
net.AddIIP(conn.Data, conn.Tgt.Process, conn.Tgt.Port)
}
}
// Add port exports
for _, export := range descr.Exports {
// Split private into proc.port
procName := export.Private[:strings.Index(export.Private, ".")]
procPort := export.Private[strings.Index(export.Private, ".")+1:]
// Try to detect port direction using reflection
procType := reflect.TypeOf(net.Get(procName)).Elem()
field, fieldFound := procType.FieldByName(procPort)
if !fieldFound {
panic("Private port '" + export.Private + "' not found")
}
if field.Type.Kind() == reflect.Chan && (field.Type.ChanDir()&reflect.RecvDir) != 0 {
// It's an inport
net.MapInPort(export.Public, procName, procPort)
} else if field.Type.Kind() == reflect.Chan && (field.Type.ChanDir()&reflect.SendDir) != 0 {
// It's an outport
net.MapOutPort(export.Public, procName, procPort)
} else {
// It's not a proper port
panic("Private port '" + export.Private + "' is not a valid channel")
}
// TODO add support for subgraphs
}
return net
}
// Register a component to be reused
if descr.Properties.Name != "" {
Register(descr.Properties.Name, constructor)
}
return constructor().(*Graph)
}
|
go
|
func ParseJSON(js []byte) *Graph {
// Parse JSON into Go struct
var descr graphDescription
err := json.Unmarshal(js, &descr)
if err != nil {
return nil
}
// fmt.Printf("%+v\n", descr)
constructor := func() interface{} {
// Create a new Graph
net := new(Graph)
net.InitGraphState()
// Add processes to the network
for procName, procValue := range descr.Processes {
net.AddNew(procValue.Component, procName)
// Process mode detection
if procValue.Metadata.PoolSize > 0 {
proc := net.Get(procName).(*Component)
proc.Mode = ComponentModePool
proc.PoolSize = uint8(procValue.Metadata.PoolSize)
} else if procValue.Metadata.Sync {
proc := net.Get(procName).(*Component)
proc.Mode = ComponentModeSync
}
}
// Add connections
for _, conn := range descr.Connections {
// Check if it is an IIP or actual connection
if conn.Data == nil {
// Add a connection
net.ConnectBuf(conn.Src.Process, conn.Src.Port, conn.Tgt.Process, conn.Tgt.Port, conn.Metadata.Buffer)
} else {
// Add an IIP
net.AddIIP(conn.Data, conn.Tgt.Process, conn.Tgt.Port)
}
}
// Add port exports
for _, export := range descr.Exports {
// Split private into proc.port
procName := export.Private[:strings.Index(export.Private, ".")]
procPort := export.Private[strings.Index(export.Private, ".")+1:]
// Try to detect port direction using reflection
procType := reflect.TypeOf(net.Get(procName)).Elem()
field, fieldFound := procType.FieldByName(procPort)
if !fieldFound {
panic("Private port '" + export.Private + "' not found")
}
if field.Type.Kind() == reflect.Chan && (field.Type.ChanDir()&reflect.RecvDir) != 0 {
// It's an inport
net.MapInPort(export.Public, procName, procPort)
} else if field.Type.Kind() == reflect.Chan && (field.Type.ChanDir()&reflect.SendDir) != 0 {
// It's an outport
net.MapOutPort(export.Public, procName, procPort)
} else {
// It's not a proper port
panic("Private port '" + export.Private + "' is not a valid channel")
}
// TODO add support for subgraphs
}
return net
}
// Register a component to be reused
if descr.Properties.Name != "" {
Register(descr.Properties.Name, constructor)
}
return constructor().(*Graph)
}
|
[
"func",
"ParseJSON",
"(",
"js",
"[",
"]",
"byte",
")",
"*",
"Graph",
"{",
"// Parse JSON into Go struct",
"var",
"descr",
"graphDescription",
"\n",
"err",
":=",
"json",
".",
"Unmarshal",
"(",
"js",
",",
"&",
"descr",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"// fmt.Printf(\"%+v\\n\", descr)",
"constructor",
":=",
"func",
"(",
")",
"interface",
"{",
"}",
"{",
"// Create a new Graph",
"net",
":=",
"new",
"(",
"Graph",
")",
"\n",
"net",
".",
"InitGraphState",
"(",
")",
"\n\n",
"// Add processes to the network",
"for",
"procName",
",",
"procValue",
":=",
"range",
"descr",
".",
"Processes",
"{",
"net",
".",
"AddNew",
"(",
"procValue",
".",
"Component",
",",
"procName",
")",
"\n",
"// Process mode detection",
"if",
"procValue",
".",
"Metadata",
".",
"PoolSize",
">",
"0",
"{",
"proc",
":=",
"net",
".",
"Get",
"(",
"procName",
")",
".",
"(",
"*",
"Component",
")",
"\n",
"proc",
".",
"Mode",
"=",
"ComponentModePool",
"\n",
"proc",
".",
"PoolSize",
"=",
"uint8",
"(",
"procValue",
".",
"Metadata",
".",
"PoolSize",
")",
"\n",
"}",
"else",
"if",
"procValue",
".",
"Metadata",
".",
"Sync",
"{",
"proc",
":=",
"net",
".",
"Get",
"(",
"procName",
")",
".",
"(",
"*",
"Component",
")",
"\n",
"proc",
".",
"Mode",
"=",
"ComponentModeSync",
"\n",
"}",
"\n",
"}",
"\n\n",
"// Add connections",
"for",
"_",
",",
"conn",
":=",
"range",
"descr",
".",
"Connections",
"{",
"// Check if it is an IIP or actual connection",
"if",
"conn",
".",
"Data",
"==",
"nil",
"{",
"// Add a connection",
"net",
".",
"ConnectBuf",
"(",
"conn",
".",
"Src",
".",
"Process",
",",
"conn",
".",
"Src",
".",
"Port",
",",
"conn",
".",
"Tgt",
".",
"Process",
",",
"conn",
".",
"Tgt",
".",
"Port",
",",
"conn",
".",
"Metadata",
".",
"Buffer",
")",
"\n",
"}",
"else",
"{",
"// Add an IIP",
"net",
".",
"AddIIP",
"(",
"conn",
".",
"Data",
",",
"conn",
".",
"Tgt",
".",
"Process",
",",
"conn",
".",
"Tgt",
".",
"Port",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"// Add port exports",
"for",
"_",
",",
"export",
":=",
"range",
"descr",
".",
"Exports",
"{",
"// Split private into proc.port",
"procName",
":=",
"export",
".",
"Private",
"[",
":",
"strings",
".",
"Index",
"(",
"export",
".",
"Private",
",",
"\"",
"\"",
")",
"]",
"\n",
"procPort",
":=",
"export",
".",
"Private",
"[",
"strings",
".",
"Index",
"(",
"export",
".",
"Private",
",",
"\"",
"\"",
")",
"+",
"1",
":",
"]",
"\n",
"// Try to detect port direction using reflection",
"procType",
":=",
"reflect",
".",
"TypeOf",
"(",
"net",
".",
"Get",
"(",
"procName",
")",
")",
".",
"Elem",
"(",
")",
"\n",
"field",
",",
"fieldFound",
":=",
"procType",
".",
"FieldByName",
"(",
"procPort",
")",
"\n",
"if",
"!",
"fieldFound",
"{",
"panic",
"(",
"\"",
"\"",
"+",
"export",
".",
"Private",
"+",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"field",
".",
"Type",
".",
"Kind",
"(",
")",
"==",
"reflect",
".",
"Chan",
"&&",
"(",
"field",
".",
"Type",
".",
"ChanDir",
"(",
")",
"&",
"reflect",
".",
"RecvDir",
")",
"!=",
"0",
"{",
"// It's an inport",
"net",
".",
"MapInPort",
"(",
"export",
".",
"Public",
",",
"procName",
",",
"procPort",
")",
"\n",
"}",
"else",
"if",
"field",
".",
"Type",
".",
"Kind",
"(",
")",
"==",
"reflect",
".",
"Chan",
"&&",
"(",
"field",
".",
"Type",
".",
"ChanDir",
"(",
")",
"&",
"reflect",
".",
"SendDir",
")",
"!=",
"0",
"{",
"// It's an outport",
"net",
".",
"MapOutPort",
"(",
"export",
".",
"Public",
",",
"procName",
",",
"procPort",
")",
"\n",
"}",
"else",
"{",
"// It's not a proper port",
"panic",
"(",
"\"",
"\"",
"+",
"export",
".",
"Private",
"+",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"// TODO add support for subgraphs",
"}",
"\n\n",
"return",
"net",
"\n",
"}",
"\n\n",
"// Register a component to be reused",
"if",
"descr",
".",
"Properties",
".",
"Name",
"!=",
"\"",
"\"",
"{",
"Register",
"(",
"descr",
".",
"Properties",
".",
"Name",
",",
"constructor",
")",
"\n",
"}",
"\n\n",
"return",
"constructor",
"(",
")",
".",
"(",
"*",
"Graph",
")",
"\n",
"}"
] |
// ParseJSON converts a JSON network definition string into
// a flow.Graph object that can be run or used in other networks
|
[
"ParseJSON",
"converts",
"a",
"JSON",
"network",
"definition",
"string",
"into",
"a",
"flow",
".",
"Graph",
"object",
"that",
"can",
"be",
"run",
"or",
"used",
"in",
"other",
"networks"
] |
98ea6cda15a37b5df5b92f04daa4af10e58c1874
|
https://github.com/trustmaster/goflow/blob/98ea6cda15a37b5df5b92f04daa4af10e58c1874/loader.go#L46-L119
|
19,490
|
trustmaster/goflow
|
loader.go
|
LoadJSON
|
func LoadJSON(filename string) *Graph {
js, err := ioutil.ReadFile(filename)
if err != nil {
return nil
}
return ParseJSON(js)
}
|
go
|
func LoadJSON(filename string) *Graph {
js, err := ioutil.ReadFile(filename)
if err != nil {
return nil
}
return ParseJSON(js)
}
|
[
"func",
"LoadJSON",
"(",
"filename",
"string",
")",
"*",
"Graph",
"{",
"js",
",",
"err",
":=",
"ioutil",
".",
"ReadFile",
"(",
"filename",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"ParseJSON",
"(",
"js",
")",
"\n",
"}"
] |
// LoadJSON loads a JSON graph definition file into
// a flow.Graph object that can be run or used in other networks
|
[
"LoadJSON",
"loads",
"a",
"JSON",
"graph",
"definition",
"file",
"into",
"a",
"flow",
".",
"Graph",
"object",
"that",
"can",
"be",
"run",
"or",
"used",
"in",
"other",
"networks"
] |
98ea6cda15a37b5df5b92f04daa4af10e58c1874
|
https://github.com/trustmaster/goflow/blob/98ea6cda15a37b5df5b92f04daa4af10e58c1874/loader.go#L123-L129
|
19,491
|
trustmaster/goflow
|
loader.go
|
RegisterJSON
|
func RegisterJSON(componentName, filePath string) bool {
var constructor ComponentConstructor
constructor = func() interface{} {
return LoadJSON(filePath)
}
return Register(componentName, constructor)
}
|
go
|
func RegisterJSON(componentName, filePath string) bool {
var constructor ComponentConstructor
constructor = func() interface{} {
return LoadJSON(filePath)
}
return Register(componentName, constructor)
}
|
[
"func",
"RegisterJSON",
"(",
"componentName",
",",
"filePath",
"string",
")",
"bool",
"{",
"var",
"constructor",
"ComponentConstructor",
"\n",
"constructor",
"=",
"func",
"(",
")",
"interface",
"{",
"}",
"{",
"return",
"LoadJSON",
"(",
"filePath",
")",
"\n",
"}",
"\n",
"return",
"Register",
"(",
"componentName",
",",
"constructor",
")",
"\n",
"}"
] |
// RegisterJSON registers an external JSON graph definition as a component
// that can be instantiated at run-time using component Factory.
// It returns true on success or false if component name is already taken.
|
[
"RegisterJSON",
"registers",
"an",
"external",
"JSON",
"graph",
"definition",
"as",
"a",
"component",
"that",
"can",
"be",
"instantiated",
"at",
"run",
"-",
"time",
"using",
"component",
"Factory",
".",
"It",
"returns",
"true",
"on",
"success",
"or",
"false",
"if",
"component",
"name",
"is",
"already",
"taken",
"."
] |
98ea6cda15a37b5df5b92f04daa4af10e58c1874
|
https://github.com/trustmaster/goflow/blob/98ea6cda15a37b5df5b92f04daa4af10e58c1874/loader.go#L134-L140
|
19,492
|
trustmaster/goflow
|
factory.go
|
NewFactory
|
func NewFactory(config ...FactoryConfig) *Factory {
conf := defaultFactoryConfig()
if len(config) == 1 {
conf = config[0]
}
return &Factory{
registry: make(map[string]registryEntry, conf.RegistryCapacity),
}
}
|
go
|
func NewFactory(config ...FactoryConfig) *Factory {
conf := defaultFactoryConfig()
if len(config) == 1 {
conf = config[0]
}
return &Factory{
registry: make(map[string]registryEntry, conf.RegistryCapacity),
}
}
|
[
"func",
"NewFactory",
"(",
"config",
"...",
"FactoryConfig",
")",
"*",
"Factory",
"{",
"conf",
":=",
"defaultFactoryConfig",
"(",
")",
"\n",
"if",
"len",
"(",
"config",
")",
"==",
"1",
"{",
"conf",
"=",
"config",
"[",
"0",
"]",
"\n",
"}",
"\n\n",
"return",
"&",
"Factory",
"{",
"registry",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"registryEntry",
",",
"conf",
".",
"RegistryCapacity",
")",
",",
"}",
"\n",
"}"
] |
// NewFactory creates a new component Factory instance
|
[
"NewFactory",
"creates",
"a",
"new",
"component",
"Factory",
"instance"
] |
98ea6cda15a37b5df5b92f04daa4af10e58c1874
|
https://github.com/trustmaster/goflow/blob/98ea6cda15a37b5df5b92f04daa4af10e58c1874/factory.go#L43-L52
|
19,493
|
trustmaster/goflow
|
factory.go
|
Register
|
func (f *Factory) Register(componentName string, constructor Constructor) error {
if _, exists := f.registry[componentName]; exists {
return fmt.Errorf("Registry error: component '%s' already registered", componentName)
}
f.registry[componentName] = registryEntry{
Constructor: constructor,
Info: ComponentInfo{
Name: componentName,
},
}
return nil
}
|
go
|
func (f *Factory) Register(componentName string, constructor Constructor) error {
if _, exists := f.registry[componentName]; exists {
return fmt.Errorf("Registry error: component '%s' already registered", componentName)
}
f.registry[componentName] = registryEntry{
Constructor: constructor,
Info: ComponentInfo{
Name: componentName,
},
}
return nil
}
|
[
"func",
"(",
"f",
"*",
"Factory",
")",
"Register",
"(",
"componentName",
"string",
",",
"constructor",
"Constructor",
")",
"error",
"{",
"if",
"_",
",",
"exists",
":=",
"f",
".",
"registry",
"[",
"componentName",
"]",
";",
"exists",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"componentName",
")",
"\n",
"}",
"\n",
"f",
".",
"registry",
"[",
"componentName",
"]",
"=",
"registryEntry",
"{",
"Constructor",
":",
"constructor",
",",
"Info",
":",
"ComponentInfo",
"{",
"Name",
":",
"componentName",
",",
"}",
",",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// Register registers a component so that it can be instantiated at run-time
|
[
"Register",
"registers",
"a",
"component",
"so",
"that",
"it",
"can",
"be",
"instantiated",
"at",
"run",
"-",
"time"
] |
98ea6cda15a37b5df5b92f04daa4af10e58c1874
|
https://github.com/trustmaster/goflow/blob/98ea6cda15a37b5df5b92f04daa4af10e58c1874/factory.go#L55-L66
|
19,494
|
trustmaster/goflow
|
factory.go
|
Annotate
|
func (f *Factory) Annotate(componentName string, annotation Annotation) error {
if _, exists := f.registry[componentName]; !exists {
return fmt.Errorf("Registry annotation error: component '%s' is not registered", componentName)
}
entry := f.registry[componentName]
entry.Info.Description = annotation.Description
entry.Info.Icon = annotation.Icon
f.registry[componentName] = entry
return nil
}
|
go
|
func (f *Factory) Annotate(componentName string, annotation Annotation) error {
if _, exists := f.registry[componentName]; !exists {
return fmt.Errorf("Registry annotation error: component '%s' is not registered", componentName)
}
entry := f.registry[componentName]
entry.Info.Description = annotation.Description
entry.Info.Icon = annotation.Icon
f.registry[componentName] = entry
return nil
}
|
[
"func",
"(",
"f",
"*",
"Factory",
")",
"Annotate",
"(",
"componentName",
"string",
",",
"annotation",
"Annotation",
")",
"error",
"{",
"if",
"_",
",",
"exists",
":=",
"f",
".",
"registry",
"[",
"componentName",
"]",
";",
"!",
"exists",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"componentName",
")",
"\n",
"}",
"\n",
"entry",
":=",
"f",
".",
"registry",
"[",
"componentName",
"]",
"\n",
"entry",
".",
"Info",
".",
"Description",
"=",
"annotation",
".",
"Description",
"\n",
"entry",
".",
"Info",
".",
"Icon",
"=",
"annotation",
".",
"Icon",
"\n",
"f",
".",
"registry",
"[",
"componentName",
"]",
"=",
"entry",
"\n",
"return",
"nil",
"\n",
"}"
] |
// Annotate adds human-readable documentation for a component to the runtime
|
[
"Annotate",
"adds",
"human",
"-",
"readable",
"documentation",
"for",
"a",
"component",
"to",
"the",
"runtime"
] |
98ea6cda15a37b5df5b92f04daa4af10e58c1874
|
https://github.com/trustmaster/goflow/blob/98ea6cda15a37b5df5b92f04daa4af10e58c1874/factory.go#L69-L78
|
19,495
|
trustmaster/goflow
|
factory.go
|
Unregister
|
func (f *Factory) Unregister(componentName string) error {
if _, exists := f.registry[componentName]; exists {
delete(f.registry, componentName)
return nil
}
return fmt.Errorf("Registry error: component '%s' is not registered", componentName)
}
|
go
|
func (f *Factory) Unregister(componentName string) error {
if _, exists := f.registry[componentName]; exists {
delete(f.registry, componentName)
return nil
}
return fmt.Errorf("Registry error: component '%s' is not registered", componentName)
}
|
[
"func",
"(",
"f",
"*",
"Factory",
")",
"Unregister",
"(",
"componentName",
"string",
")",
"error",
"{",
"if",
"_",
",",
"exists",
":=",
"f",
".",
"registry",
"[",
"componentName",
"]",
";",
"exists",
"{",
"delete",
"(",
"f",
".",
"registry",
",",
"componentName",
")",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"componentName",
")",
"\n",
"}"
] |
// Unregister removes a component with a given name from the component registry and returns true
// or returns false if no such component is registered.
|
[
"Unregister",
"removes",
"a",
"component",
"with",
"a",
"given",
"name",
"from",
"the",
"component",
"registry",
"and",
"returns",
"true",
"or",
"returns",
"false",
"if",
"no",
"such",
"component",
"is",
"registered",
"."
] |
98ea6cda15a37b5df5b92f04daa4af10e58c1874
|
https://github.com/trustmaster/goflow/blob/98ea6cda15a37b5df5b92f04daa4af10e58c1874/factory.go#L82-L88
|
19,496
|
trustmaster/goflow
|
factory.go
|
Create
|
func (f *Factory) Create(componentName string) (interface{}, error) {
if info, exists := f.registry[componentName]; exists {
return info.Constructor()
}
return nil, fmt.Errorf("Factory error: component '%s' does not exist", componentName)
}
|
go
|
func (f *Factory) Create(componentName string) (interface{}, error) {
if info, exists := f.registry[componentName]; exists {
return info.Constructor()
}
return nil, fmt.Errorf("Factory error: component '%s' does not exist", componentName)
}
|
[
"func",
"(",
"f",
"*",
"Factory",
")",
"Create",
"(",
"componentName",
"string",
")",
"(",
"interface",
"{",
"}",
",",
"error",
")",
"{",
"if",
"info",
",",
"exists",
":=",
"f",
".",
"registry",
"[",
"componentName",
"]",
";",
"exists",
"{",
"return",
"info",
".",
"Constructor",
"(",
")",
"\n",
"}",
"\n",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"componentName",
")",
"\n",
"}"
] |
// Create creates a new instance of a component registered under a specific name.
|
[
"Create",
"creates",
"a",
"new",
"instance",
"of",
"a",
"component",
"registered",
"under",
"a",
"specific",
"name",
"."
] |
98ea6cda15a37b5df5b92f04daa4af10e58c1874
|
https://github.com/trustmaster/goflow/blob/98ea6cda15a37b5df5b92f04daa4af10e58c1874/factory.go#L91-L96
|
19,497
|
trustmaster/goflow
|
graph_connect.go
|
ConnectBuf
|
func (n *Graph) ConnectBuf(senderName, senderPort, receiverName, receiverPort string, bufferSize int) error {
senderPortVal, err := n.getProcPort(senderName, senderPort, reflect.SendDir)
if err != nil {
return err
}
receiverPortVal, err := n.getProcPort(receiverName, receiverPort, reflect.RecvDir)
if err != nil {
return err
}
// Try to get an existing channel
var channel reflect.Value
if !receiverPortVal.IsNil() {
// Find existing channel attached to the receiver
channel = n.findExistingChan(receiverName, receiverPort, reflect.RecvDir)
}
sndPortType := senderPortVal.Type()
if !senderPortVal.IsNil() {
// If both ports are already busy, we cannot connect them
if channel.IsValid() && senderPortVal.Addr() != receiverPortVal.Addr() {
return fmt.Errorf("'%s.%s' cannot be connected to '%s.%s': both ports already in use", receiverName, receiverPort, senderName, senderPort)
}
// Find an existing channel attached to sender
// Receiver channel takes priority if exists
if !channel.IsValid() {
channel = n.findExistingChan(senderName, senderPort, reflect.SendDir)
}
}
// Create a new channel if none of the existing channles found
if !channel.IsValid() {
// Make a channel of an appropriate type
chanType := reflect.ChanOf(reflect.BothDir, sndPortType.Elem())
channel = reflect.MakeChan(chanType, bufferSize)
}
// Set the channels
// TODO fix rewiring a graph without disconnecting ports
if senderPortVal.IsNil() {
senderPortVal.Set(channel)
n.incSendChanRefCount(channel)
}
if receiverPortVal.IsNil() {
receiverPortVal.Set(channel)
}
// Add connection info
n.connections = append(n.connections, connection{
src: portName{proc: senderName,
port: senderPort},
tgt: portName{proc: receiverName,
port: receiverPort},
channel: channel,
buffer: bufferSize})
return nil
}
|
go
|
func (n *Graph) ConnectBuf(senderName, senderPort, receiverName, receiverPort string, bufferSize int) error {
senderPortVal, err := n.getProcPort(senderName, senderPort, reflect.SendDir)
if err != nil {
return err
}
receiverPortVal, err := n.getProcPort(receiverName, receiverPort, reflect.RecvDir)
if err != nil {
return err
}
// Try to get an existing channel
var channel reflect.Value
if !receiverPortVal.IsNil() {
// Find existing channel attached to the receiver
channel = n.findExistingChan(receiverName, receiverPort, reflect.RecvDir)
}
sndPortType := senderPortVal.Type()
if !senderPortVal.IsNil() {
// If both ports are already busy, we cannot connect them
if channel.IsValid() && senderPortVal.Addr() != receiverPortVal.Addr() {
return fmt.Errorf("'%s.%s' cannot be connected to '%s.%s': both ports already in use", receiverName, receiverPort, senderName, senderPort)
}
// Find an existing channel attached to sender
// Receiver channel takes priority if exists
if !channel.IsValid() {
channel = n.findExistingChan(senderName, senderPort, reflect.SendDir)
}
}
// Create a new channel if none of the existing channles found
if !channel.IsValid() {
// Make a channel of an appropriate type
chanType := reflect.ChanOf(reflect.BothDir, sndPortType.Elem())
channel = reflect.MakeChan(chanType, bufferSize)
}
// Set the channels
// TODO fix rewiring a graph without disconnecting ports
if senderPortVal.IsNil() {
senderPortVal.Set(channel)
n.incSendChanRefCount(channel)
}
if receiverPortVal.IsNil() {
receiverPortVal.Set(channel)
}
// Add connection info
n.connections = append(n.connections, connection{
src: portName{proc: senderName,
port: senderPort},
tgt: portName{proc: receiverName,
port: receiverPort},
channel: channel,
buffer: bufferSize})
return nil
}
|
[
"func",
"(",
"n",
"*",
"Graph",
")",
"ConnectBuf",
"(",
"senderName",
",",
"senderPort",
",",
"receiverName",
",",
"receiverPort",
"string",
",",
"bufferSize",
"int",
")",
"error",
"{",
"senderPortVal",
",",
"err",
":=",
"n",
".",
"getProcPort",
"(",
"senderName",
",",
"senderPort",
",",
"reflect",
".",
"SendDir",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"receiverPortVal",
",",
"err",
":=",
"n",
".",
"getProcPort",
"(",
"receiverName",
",",
"receiverPort",
",",
"reflect",
".",
"RecvDir",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"// Try to get an existing channel",
"var",
"channel",
"reflect",
".",
"Value",
"\n",
"if",
"!",
"receiverPortVal",
".",
"IsNil",
"(",
")",
"{",
"// Find existing channel attached to the receiver",
"channel",
"=",
"n",
".",
"findExistingChan",
"(",
"receiverName",
",",
"receiverPort",
",",
"reflect",
".",
"RecvDir",
")",
"\n",
"}",
"\n\n",
"sndPortType",
":=",
"senderPortVal",
".",
"Type",
"(",
")",
"\n\n",
"if",
"!",
"senderPortVal",
".",
"IsNil",
"(",
")",
"{",
"// If both ports are already busy, we cannot connect them",
"if",
"channel",
".",
"IsValid",
"(",
")",
"&&",
"senderPortVal",
".",
"Addr",
"(",
")",
"!=",
"receiverPortVal",
".",
"Addr",
"(",
")",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"receiverName",
",",
"receiverPort",
",",
"senderName",
",",
"senderPort",
")",
"\n",
"}",
"\n",
"// Find an existing channel attached to sender",
"// Receiver channel takes priority if exists",
"if",
"!",
"channel",
".",
"IsValid",
"(",
")",
"{",
"channel",
"=",
"n",
".",
"findExistingChan",
"(",
"senderName",
",",
"senderPort",
",",
"reflect",
".",
"SendDir",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"// Create a new channel if none of the existing channles found",
"if",
"!",
"channel",
".",
"IsValid",
"(",
")",
"{",
"// Make a channel of an appropriate type",
"chanType",
":=",
"reflect",
".",
"ChanOf",
"(",
"reflect",
".",
"BothDir",
",",
"sndPortType",
".",
"Elem",
"(",
")",
")",
"\n",
"channel",
"=",
"reflect",
".",
"MakeChan",
"(",
"chanType",
",",
"bufferSize",
")",
"\n",
"}",
"\n\n",
"// Set the channels",
"// TODO fix rewiring a graph without disconnecting ports",
"if",
"senderPortVal",
".",
"IsNil",
"(",
")",
"{",
"senderPortVal",
".",
"Set",
"(",
"channel",
")",
"\n",
"n",
".",
"incSendChanRefCount",
"(",
"channel",
")",
"\n",
"}",
"\n",
"if",
"receiverPortVal",
".",
"IsNil",
"(",
")",
"{",
"receiverPortVal",
".",
"Set",
"(",
"channel",
")",
"\n",
"}",
"\n\n",
"// Add connection info",
"n",
".",
"connections",
"=",
"append",
"(",
"n",
".",
"connections",
",",
"connection",
"{",
"src",
":",
"portName",
"{",
"proc",
":",
"senderName",
",",
"port",
":",
"senderPort",
"}",
",",
"tgt",
":",
"portName",
"{",
"proc",
":",
"receiverName",
",",
"port",
":",
"receiverPort",
"}",
",",
"channel",
":",
"channel",
",",
"buffer",
":",
"bufferSize",
"}",
")",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// ConnectBuf connects a sender to a receiver using a channel with a buffer of a given size.
// It returns true on success or panics and returns false if error occurs.
|
[
"ConnectBuf",
"connects",
"a",
"sender",
"to",
"a",
"receiver",
"using",
"a",
"channel",
"with",
"a",
"buffer",
"of",
"a",
"given",
"size",
".",
"It",
"returns",
"true",
"on",
"success",
"or",
"panics",
"and",
"returns",
"false",
"if",
"error",
"occurs",
"."
] |
98ea6cda15a37b5df5b92f04daa4af10e58c1874
|
https://github.com/trustmaster/goflow/blob/98ea6cda15a37b5df5b92f04daa4af10e58c1874/graph_connect.go#L47-L106
|
19,498
|
trustmaster/goflow
|
graph_connect.go
|
getProcPort
|
func (n *Graph) getProcPort(procName, portName string, dir reflect.ChanDir) (reflect.Value, error) {
nilValue := reflect.ValueOf(nil)
// Ensure process exists
proc, ok := n.procs[procName]
if !ok {
return nilValue, fmt.Errorf("Connect error: process '%s' not found", procName)
}
// Ensure sender is settable
val := reflect.ValueOf(proc)
if val.Kind() == reflect.Ptr && val.IsValid() {
val = val.Elem()
}
if !val.CanSet() {
return nilValue, fmt.Errorf("Connect error: process '%s' is not settable", procName)
}
// Get the port value
var portVal reflect.Value
var err error
// Check if sender is a net
net, ok := val.Interface().(Graph)
if ok {
// Sender is a net
if dir == reflect.SendDir {
portVal, err = net.getOutPort(portName)
} else {
portVal, err = net.getInPort(portName)
}
} else {
// Sender is a proc
portVal = val.FieldByName(portName)
if !portVal.IsValid() {
err = errors.New("")
}
}
if err != nil {
return nilValue, fmt.Errorf("Connect error: process '%s' does not have port '%s'", procName, portName)
}
// Validate port type
portType := portVal.Type()
// Sender port can be an array port
if dir == reflect.SendDir && portType.Kind() == reflect.Slice {
portType = portType.Elem()
}
// Validate
if portType.Kind() != reflect.Chan || portType.ChanDir()&dir == 0 {
return nilValue, fmt.Errorf("Connect error: '%s.%s' is not of the correct chan type", procName, portName)
}
// Check assignability
if !portVal.CanSet() {
return nilValue, fmt.Errorf("'%s.%s' is not assignable", procName, portName)
}
return portVal, nil
}
|
go
|
func (n *Graph) getProcPort(procName, portName string, dir reflect.ChanDir) (reflect.Value, error) {
nilValue := reflect.ValueOf(nil)
// Ensure process exists
proc, ok := n.procs[procName]
if !ok {
return nilValue, fmt.Errorf("Connect error: process '%s' not found", procName)
}
// Ensure sender is settable
val := reflect.ValueOf(proc)
if val.Kind() == reflect.Ptr && val.IsValid() {
val = val.Elem()
}
if !val.CanSet() {
return nilValue, fmt.Errorf("Connect error: process '%s' is not settable", procName)
}
// Get the port value
var portVal reflect.Value
var err error
// Check if sender is a net
net, ok := val.Interface().(Graph)
if ok {
// Sender is a net
if dir == reflect.SendDir {
portVal, err = net.getOutPort(portName)
} else {
portVal, err = net.getInPort(portName)
}
} else {
// Sender is a proc
portVal = val.FieldByName(portName)
if !portVal.IsValid() {
err = errors.New("")
}
}
if err != nil {
return nilValue, fmt.Errorf("Connect error: process '%s' does not have port '%s'", procName, portName)
}
// Validate port type
portType := portVal.Type()
// Sender port can be an array port
if dir == reflect.SendDir && portType.Kind() == reflect.Slice {
portType = portType.Elem()
}
// Validate
if portType.Kind() != reflect.Chan || portType.ChanDir()&dir == 0 {
return nilValue, fmt.Errorf("Connect error: '%s.%s' is not of the correct chan type", procName, portName)
}
// Check assignability
if !portVal.CanSet() {
return nilValue, fmt.Errorf("'%s.%s' is not assignable", procName, portName)
}
return portVal, nil
}
|
[
"func",
"(",
"n",
"*",
"Graph",
")",
"getProcPort",
"(",
"procName",
",",
"portName",
"string",
",",
"dir",
"reflect",
".",
"ChanDir",
")",
"(",
"reflect",
".",
"Value",
",",
"error",
")",
"{",
"nilValue",
":=",
"reflect",
".",
"ValueOf",
"(",
"nil",
")",
"\n",
"// Ensure process exists",
"proc",
",",
"ok",
":=",
"n",
".",
"procs",
"[",
"procName",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nilValue",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"procName",
")",
"\n",
"}",
"\n\n",
"// Ensure sender is settable",
"val",
":=",
"reflect",
".",
"ValueOf",
"(",
"proc",
")",
"\n",
"if",
"val",
".",
"Kind",
"(",
")",
"==",
"reflect",
".",
"Ptr",
"&&",
"val",
".",
"IsValid",
"(",
")",
"{",
"val",
"=",
"val",
".",
"Elem",
"(",
")",
"\n",
"}",
"\n",
"if",
"!",
"val",
".",
"CanSet",
"(",
")",
"{",
"return",
"nilValue",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"procName",
")",
"\n",
"}",
"\n\n",
"// Get the port value",
"var",
"portVal",
"reflect",
".",
"Value",
"\n",
"var",
"err",
"error",
"\n",
"// Check if sender is a net",
"net",
",",
"ok",
":=",
"val",
".",
"Interface",
"(",
")",
".",
"(",
"Graph",
")",
"\n",
"if",
"ok",
"{",
"// Sender is a net",
"if",
"dir",
"==",
"reflect",
".",
"SendDir",
"{",
"portVal",
",",
"err",
"=",
"net",
".",
"getOutPort",
"(",
"portName",
")",
"\n",
"}",
"else",
"{",
"portVal",
",",
"err",
"=",
"net",
".",
"getInPort",
"(",
"portName",
")",
"\n",
"}",
"\n\n",
"}",
"else",
"{",
"// Sender is a proc",
"portVal",
"=",
"val",
".",
"FieldByName",
"(",
"portName",
")",
"\n",
"if",
"!",
"portVal",
".",
"IsValid",
"(",
")",
"{",
"err",
"=",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nilValue",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"procName",
",",
"portName",
")",
"\n",
"}",
"\n\n",
"// Validate port type",
"portType",
":=",
"portVal",
".",
"Type",
"(",
")",
"\n\n",
"// Sender port can be an array port",
"if",
"dir",
"==",
"reflect",
".",
"SendDir",
"&&",
"portType",
".",
"Kind",
"(",
")",
"==",
"reflect",
".",
"Slice",
"{",
"portType",
"=",
"portType",
".",
"Elem",
"(",
")",
"\n",
"}",
"\n\n",
"// Validate",
"if",
"portType",
".",
"Kind",
"(",
")",
"!=",
"reflect",
".",
"Chan",
"||",
"portType",
".",
"ChanDir",
"(",
")",
"&",
"dir",
"==",
"0",
"{",
"return",
"nilValue",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"procName",
",",
"portName",
")",
"\n",
"}",
"\n\n",
"// Check assignability",
"if",
"!",
"portVal",
".",
"CanSet",
"(",
")",
"{",
"return",
"nilValue",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"procName",
",",
"portName",
")",
"\n",
"}",
"\n\n",
"return",
"portVal",
",",
"nil",
"\n",
"}"
] |
// getProcPort finds an assignable port field in one of the subprocesses
|
[
"getProcPort",
"finds",
"an",
"assignable",
"port",
"field",
"in",
"one",
"of",
"the",
"subprocesses"
] |
98ea6cda15a37b5df5b92f04daa4af10e58c1874
|
https://github.com/trustmaster/goflow/blob/98ea6cda15a37b5df5b92f04daa4af10e58c1874/graph_connect.go#L109-L169
|
19,499
|
trustmaster/goflow
|
graph_connect.go
|
findExistingChan
|
func (n *Graph) findExistingChan(proc, procPort string, dir reflect.ChanDir) reflect.Value {
var channel reflect.Value
// Find existing channel attached to the receiver
for _, conn := range n.connections {
var p portName
if dir == reflect.SendDir {
p = conn.src
} else {
p = conn.tgt
}
if p.port == procPort && p.proc == proc {
channel = conn.channel
break
}
}
return channel
}
|
go
|
func (n *Graph) findExistingChan(proc, procPort string, dir reflect.ChanDir) reflect.Value {
var channel reflect.Value
// Find existing channel attached to the receiver
for _, conn := range n.connections {
var p portName
if dir == reflect.SendDir {
p = conn.src
} else {
p = conn.tgt
}
if p.port == procPort && p.proc == proc {
channel = conn.channel
break
}
}
return channel
}
|
[
"func",
"(",
"n",
"*",
"Graph",
")",
"findExistingChan",
"(",
"proc",
",",
"procPort",
"string",
",",
"dir",
"reflect",
".",
"ChanDir",
")",
"reflect",
".",
"Value",
"{",
"var",
"channel",
"reflect",
".",
"Value",
"\n",
"// Find existing channel attached to the receiver",
"for",
"_",
",",
"conn",
":=",
"range",
"n",
".",
"connections",
"{",
"var",
"p",
"portName",
"\n",
"if",
"dir",
"==",
"reflect",
".",
"SendDir",
"{",
"p",
"=",
"conn",
".",
"src",
"\n",
"}",
"else",
"{",
"p",
"=",
"conn",
".",
"tgt",
"\n",
"}",
"\n",
"if",
"p",
".",
"port",
"==",
"procPort",
"&&",
"p",
".",
"proc",
"==",
"proc",
"{",
"channel",
"=",
"conn",
".",
"channel",
"\n",
"break",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"channel",
"\n",
"}"
] |
// findExistingChan returns a channel attached to receiver if it already exists among connections
|
[
"findExistingChan",
"returns",
"a",
"channel",
"attached",
"to",
"receiver",
"if",
"it",
"already",
"exists",
"among",
"connections"
] |
98ea6cda15a37b5df5b92f04daa4af10e58c1874
|
https://github.com/trustmaster/goflow/blob/98ea6cda15a37b5df5b92f04daa4af10e58c1874/graph_connect.go#L172-L188
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.