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 list | docstring stringlengths 6 2.61k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 85 252 |
|---|---|---|---|---|---|---|---|---|---|---|---|
5,200 | go-chassis/go-archaius | core/event-system/eventsystem.go | DispatchEvent | func (dis *dispatcher) DispatchEvent(event *core.Event) error {
if event == nil {
return errors.New("empty event provided")
}
for regKey, listeners := range dis.listeners {
matched, err := regexp.MatchString(regKey, event.Key)
if err != nil {
openlogging.GetLogger().Errorf("regular expresssion for key %s failed: %s", regKey, err)
continue
}
if matched {
for _, listener := range listeners {
openlogging.GetLogger().Debugf("event generated for %s", regKey)
go listener.Event(event)
}
}
}
return nil
} | go | func (dis *dispatcher) DispatchEvent(event *core.Event) error {
if event == nil {
return errors.New("empty event provided")
}
for regKey, listeners := range dis.listeners {
matched, err := regexp.MatchString(regKey, event.Key)
if err != nil {
openlogging.GetLogger().Errorf("regular expresssion for key %s failed: %s", regKey, err)
continue
}
if matched {
for _, listener := range listeners {
openlogging.GetLogger().Debugf("event generated for %s", regKey)
go listener.Event(event)
}
}
}
return nil
} | [
"func",
"(",
"dis",
"*",
"dispatcher",
")",
"DispatchEvent",
"(",
"event",
"*",
"core",
".",
"Event",
")",
"error",
"{",
"if",
"event",
"==",
"nil",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"for",
"regKey",
",",... | // DispatchEvent sends the action trigger for a particular event on a configuration | [
"DispatchEvent",
"sends",
"the",
"action",
"trigger",
"for",
"a",
"particular",
"event",
"on",
"a",
"configuration"
] | 5b479bcb10437daee44d1d77af651939c6d92541 | https://github.com/go-chassis/go-archaius/blob/5b479bcb10437daee44d1d77af651939c6d92541/core/event-system/eventsystem.go#L102-L122 |
5,201 | go-chassis/go-archaius | core/config-manager/unmarshal.go | handlePtr | func (cMgr *ConfigurationManager) handlePtr(rValue reflect.Value, tagName string) error {
if rValue.IsNil() {
ptrValue := reflect.New(rValue.Type().Elem())
err := cMgr.unmarshal(ptrValue, getTagKey(tagName, doNotConsiderTag))
if err != nil {
return err
}
if rValue.CanSet() {
rValue.Set(ptrValue)
}
return nil
} else if rValue.Elem().Kind() == reflect.Ptr {
ptrValue := rValue.Elem()
err := cMgr.handlePtr(ptrValue, getTagKey(tagName, doNotConsiderTag))
if err != nil {
return err
}
}
ptrValue := rValue.Elem()
err := cMgr.unmarshal(ptrValue, getTagKey(tagName, doNotConsiderTag))
if err != nil {
return err
}
return nil
} | go | func (cMgr *ConfigurationManager) handlePtr(rValue reflect.Value, tagName string) error {
if rValue.IsNil() {
ptrValue := reflect.New(rValue.Type().Elem())
err := cMgr.unmarshal(ptrValue, getTagKey(tagName, doNotConsiderTag))
if err != nil {
return err
}
if rValue.CanSet() {
rValue.Set(ptrValue)
}
return nil
} else if rValue.Elem().Kind() == reflect.Ptr {
ptrValue := rValue.Elem()
err := cMgr.handlePtr(ptrValue, getTagKey(tagName, doNotConsiderTag))
if err != nil {
return err
}
}
ptrValue := rValue.Elem()
err := cMgr.unmarshal(ptrValue, getTagKey(tagName, doNotConsiderTag))
if err != nil {
return err
}
return nil
} | [
"func",
"(",
"cMgr",
"*",
"ConfigurationManager",
")",
"handlePtr",
"(",
"rValue",
"reflect",
".",
"Value",
",",
"tagName",
"string",
")",
"error",
"{",
"if",
"rValue",
".",
"IsNil",
"(",
")",
"{",
"ptrValue",
":=",
"reflect",
".",
"New",
"(",
"rValue",
... | // handle pointer type objects | [
"handle",
"pointer",
"type",
"objects"
] | 5b479bcb10437daee44d1d77af651939c6d92541 | https://github.com/go-chassis/go-archaius/blob/5b479bcb10437daee44d1d77af651939c6d92541/core/config-manager/unmarshal.go#L88-L115 |
5,202 | go-chassis/go-archaius | core/config-manager/unmarshal.go | getTagKey | func getTagKey(currentTag, addTag string) string {
if currentTag == doNotConsiderTag && addTag == doNotConsiderTag {
return doNotConsiderTag
} else if currentTag == doNotConsiderTag && addTag != doNotConsiderTag {
return addTag
} else if currentTag != doNotConsiderTag && addTag == doNotConsiderTag {
return currentTag
}
return currentTag + `.` + addTag
} | go | func getTagKey(currentTag, addTag string) string {
if currentTag == doNotConsiderTag && addTag == doNotConsiderTag {
return doNotConsiderTag
} else if currentTag == doNotConsiderTag && addTag != doNotConsiderTag {
return addTag
} else if currentTag != doNotConsiderTag && addTag == doNotConsiderTag {
return currentTag
}
return currentTag + `.` + addTag
} | [
"func",
"getTagKey",
"(",
"currentTag",
",",
"addTag",
"string",
")",
"string",
"{",
"if",
"currentTag",
"==",
"doNotConsiderTag",
"&&",
"addTag",
"==",
"doNotConsiderTag",
"{",
"return",
"doNotConsiderTag",
"\n",
"}",
"else",
"if",
"currentTag",
"==",
"doNotCon... | // get multi level configuration key | [
"get",
"multi",
"level",
"configuration",
"key"
] | 5b479bcb10437daee44d1d77af651939c6d92541 | https://github.com/go-chassis/go-archaius/blob/5b479bcb10437daee44d1d77af651939c6d92541/core/config-manager/unmarshal.go#L118-L128 |
5,203 | go-chassis/go-archaius | core/config-manager/unmarshal.go | handleStruct | func (cMgr *ConfigurationManager) handleStruct(rValue reflect.Value, tagName string) error {
structType := rValue.Type()
numOfField := structType.NumField()
for i := 0; i < numOfField; i++ {
structField := structType.Field(i)
fieldValue := rValue.Field(i)
keyName := cMgr.getKeyName(structField.Name, structField.Tag)
if keyName == ignoreField {
return nil
}
switch structField.Type.Kind() {
case reflect.String, reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64,
reflect.Float32, reflect.Float64, reflect.Uint, reflect.Uint8, reflect.Uint16,
reflect.Uint32, reflect.Uint64, reflect.Bool, reflect.Interface, reflect.Array,
reflect.Slice:
if fieldValue.CanSet() {
err := cMgr.setValue(fieldValue, getTagKey(tagName, keyName))
if err != nil {
return err
}
}
case reflect.Ptr:
err := cMgr.handlePtr(fieldValue, getTagKey(tagName, keyName))
if err != nil {
return err
}
case reflect.Struct:
err := cMgr.handleStruct(fieldValue, getTagKey(tagName, keyName))
if err != nil {
return err
}
case reflect.Map:
err := cMgr.handleMap(rValue, fieldValue, getTagKey(tagName, keyName))
if err != nil {
return err
}
case reflect.Uintptr, reflect.Complex64, reflect.Complex128, reflect.Chan, reflect.Func,
reflect.UnsafePointer:
// ignore
}
}
return nil
} | go | func (cMgr *ConfigurationManager) handleStruct(rValue reflect.Value, tagName string) error {
structType := rValue.Type()
numOfField := structType.NumField()
for i := 0; i < numOfField; i++ {
structField := structType.Field(i)
fieldValue := rValue.Field(i)
keyName := cMgr.getKeyName(structField.Name, structField.Tag)
if keyName == ignoreField {
return nil
}
switch structField.Type.Kind() {
case reflect.String, reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64,
reflect.Float32, reflect.Float64, reflect.Uint, reflect.Uint8, reflect.Uint16,
reflect.Uint32, reflect.Uint64, reflect.Bool, reflect.Interface, reflect.Array,
reflect.Slice:
if fieldValue.CanSet() {
err := cMgr.setValue(fieldValue, getTagKey(tagName, keyName))
if err != nil {
return err
}
}
case reflect.Ptr:
err := cMgr.handlePtr(fieldValue, getTagKey(tagName, keyName))
if err != nil {
return err
}
case reflect.Struct:
err := cMgr.handleStruct(fieldValue, getTagKey(tagName, keyName))
if err != nil {
return err
}
case reflect.Map:
err := cMgr.handleMap(rValue, fieldValue, getTagKey(tagName, keyName))
if err != nil {
return err
}
case reflect.Uintptr, reflect.Complex64, reflect.Complex128, reflect.Chan, reflect.Func,
reflect.UnsafePointer:
// ignore
}
}
return nil
} | [
"func",
"(",
"cMgr",
"*",
"ConfigurationManager",
")",
"handleStruct",
"(",
"rValue",
"reflect",
".",
"Value",
",",
"tagName",
"string",
")",
"error",
"{",
"structType",
":=",
"rValue",
".",
"Type",
"(",
")",
"\n",
"numOfField",
":=",
"structType",
".",
"N... | // handle struct type object | [
"handle",
"struct",
"type",
"object"
] | 5b479bcb10437daee44d1d77af651939c6d92541 | https://github.com/go-chassis/go-archaius/blob/5b479bcb10437daee44d1d77af651939c6d92541/core/config-manager/unmarshal.go#L131-L176 |
5,204 | go-chassis/go-archaius | core/config-manager/unmarshal.go | populateMap | func (cMgr *ConfigurationManager) populateMap(prefix string, mapType reflect.Type, rValues reflect.Value) (reflect.Value, error) {
tagList := cMgr.getTagList(prefix, rValues)
rValuePtr := reflect.New(mapType)
rValue := rValuePtr.Elem()
rValue.Set(reflect.MakeMap(mapType))
//rValue := reflect.MakeMap(mapType)
mapValueType := rValue.Type().Elem()
configValue := cMgr.GetConfigurations()
prefixForInline, inlineVal, mapKeys := cMgr.getMapKeys(configValue, prefix, tagList)
if strings.Contains(prefix, "inline") {
return cMgr.setValuesForInline(mapValueType, inlineVal, prefixForInline, rValue)
}
for _, key := range mapKeys {
// if key itself has map value stored
if key == "" {
val := cMgr.GetConfigurationsByKey(prefix)
setVal := reflect.ValueOf(val)
if mapType != setVal.Type() {
return rValue, fmt.Errorf("invalid value for map %s", mapType.String())
}
if rValue.CanSet() {
rValue.Set(setVal)
}
return rValue, nil
}
switch mapValueType.Kind() {
// for '.' separated configurations
case reflect.String, reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64,
reflect.Float32, reflect.Float64, reflect.Uint, reflect.Uint8, reflect.Uint16,
reflect.Uint32, reflect.Uint64, reflect.Bool, reflect.Interface:
val := cMgr.GetConfigurationsByKey(prefix + key)
setVal := reflect.ValueOf(val)
if mapValueType != setVal.Type() {
returnCongValue, err := ToRvalueType(setVal.Interface(), mapValueType)
if err != nil {
return rValue, fmt.Errorf("value types of %s not matched. expect type : %s, config client type : %s",
prefix+key, mapValueType, setVal.String())
}
setVal = returnCongValue
}
if rValue.CanSet() {
rValue.SetMapIndex(reflect.ValueOf(key[1:]), setVal)
}
default:
splitKey := strings.Split(key, `.`)
mapKey := splitKey[1]
mapValue := reflect.New(mapValueType)
err := cMgr.unmarshal(mapValue, getTagKey(prefix, mapKey))
if err != nil {
return rValue, err
}
if rValue.CanSet() {
rValue.SetMapIndex(reflect.ValueOf(mapKey), mapValue.Elem())
}
}
}
return rValue, nil
} | go | func (cMgr *ConfigurationManager) populateMap(prefix string, mapType reflect.Type, rValues reflect.Value) (reflect.Value, error) {
tagList := cMgr.getTagList(prefix, rValues)
rValuePtr := reflect.New(mapType)
rValue := rValuePtr.Elem()
rValue.Set(reflect.MakeMap(mapType))
//rValue := reflect.MakeMap(mapType)
mapValueType := rValue.Type().Elem()
configValue := cMgr.GetConfigurations()
prefixForInline, inlineVal, mapKeys := cMgr.getMapKeys(configValue, prefix, tagList)
if strings.Contains(prefix, "inline") {
return cMgr.setValuesForInline(mapValueType, inlineVal, prefixForInline, rValue)
}
for _, key := range mapKeys {
// if key itself has map value stored
if key == "" {
val := cMgr.GetConfigurationsByKey(prefix)
setVal := reflect.ValueOf(val)
if mapType != setVal.Type() {
return rValue, fmt.Errorf("invalid value for map %s", mapType.String())
}
if rValue.CanSet() {
rValue.Set(setVal)
}
return rValue, nil
}
switch mapValueType.Kind() {
// for '.' separated configurations
case reflect.String, reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64,
reflect.Float32, reflect.Float64, reflect.Uint, reflect.Uint8, reflect.Uint16,
reflect.Uint32, reflect.Uint64, reflect.Bool, reflect.Interface:
val := cMgr.GetConfigurationsByKey(prefix + key)
setVal := reflect.ValueOf(val)
if mapValueType != setVal.Type() {
returnCongValue, err := ToRvalueType(setVal.Interface(), mapValueType)
if err != nil {
return rValue, fmt.Errorf("value types of %s not matched. expect type : %s, config client type : %s",
prefix+key, mapValueType, setVal.String())
}
setVal = returnCongValue
}
if rValue.CanSet() {
rValue.SetMapIndex(reflect.ValueOf(key[1:]), setVal)
}
default:
splitKey := strings.Split(key, `.`)
mapKey := splitKey[1]
mapValue := reflect.New(mapValueType)
err := cMgr.unmarshal(mapValue, getTagKey(prefix, mapKey))
if err != nil {
return rValue, err
}
if rValue.CanSet() {
rValue.SetMapIndex(reflect.ValueOf(mapKey), mapValue.Elem())
}
}
}
return rValue, nil
} | [
"func",
"(",
"cMgr",
"*",
"ConfigurationManager",
")",
"populateMap",
"(",
"prefix",
"string",
",",
"mapType",
"reflect",
".",
"Type",
",",
"rValues",
"reflect",
".",
"Value",
")",
"(",
"reflect",
".",
"Value",
",",
"error",
")",
"{",
"tagList",
":=",
"c... | // generate map from config map | [
"generate",
"map",
"from",
"config",
"map"
] | 5b479bcb10437daee44d1d77af651939c6d92541 | https://github.com/go-chassis/go-archaius/blob/5b479bcb10437daee44d1d77af651939c6d92541/core/config-manager/unmarshal.go#L287-L355 |
5,205 | go-chassis/go-archaius | core/config-manager/unmarshal.go | setValue | func (cMgr *ConfigurationManager) setValue(rValue reflect.Value, keyName string) error {
configValue := cMgr.GetConfigurationsByKey(keyName)
if configValue == nil {
return nil
}
// assign value if assignable
configRValue := reflect.ValueOf(configValue)
if configRValue.Kind() != rValue.Kind() {
returnCongValue, err := ToRvalueType(configRValue.Interface(), rValue.Type())
if err != nil {
return fmt.Errorf("value types of %s not matched. expect type : %s, config client type : %s",
keyName, rValue.Kind(), configRValue.Kind())
}
configRValue = returnCongValue
}
if rValue.CanSet() {
rValue.Set(configRValue)
}
return nil
} | go | func (cMgr *ConfigurationManager) setValue(rValue reflect.Value, keyName string) error {
configValue := cMgr.GetConfigurationsByKey(keyName)
if configValue == nil {
return nil
}
// assign value if assignable
configRValue := reflect.ValueOf(configValue)
if configRValue.Kind() != rValue.Kind() {
returnCongValue, err := ToRvalueType(configRValue.Interface(), rValue.Type())
if err != nil {
return fmt.Errorf("value types of %s not matched. expect type : %s, config client type : %s",
keyName, rValue.Kind(), configRValue.Kind())
}
configRValue = returnCongValue
}
if rValue.CanSet() {
rValue.Set(configRValue)
}
return nil
} | [
"func",
"(",
"cMgr",
"*",
"ConfigurationManager",
")",
"setValue",
"(",
"rValue",
"reflect",
".",
"Value",
",",
"keyName",
"string",
")",
"error",
"{",
"configValue",
":=",
"cMgr",
".",
"GetConfigurationsByKey",
"(",
"keyName",
")",
"\n",
"if",
"configValue",
... | // set values in object | [
"set",
"values",
"in",
"object"
] | 5b479bcb10437daee44d1d77af651939c6d92541 | https://github.com/go-chassis/go-archaius/blob/5b479bcb10437daee44d1d77af651939c6d92541/core/config-manager/unmarshal.go#L480-L503 |
5,206 | go-chassis/go-archaius | core/config-manager/unmarshal.go | getKeyName | func (*ConfigurationManager) getKeyName(fieldName string, fieldTagName reflect.StructTag) string {
tagName := fieldTagName.Get(configClientTag)
if tagName == "-" {
return ignoreField
} else if tagName == "" {
return toSnake(fieldName)
} else if tagName == ",inline" {
tag := strings.Split(tagName, ",")
tagName = tag[1]
return tagName
}
return tagName
} | go | func (*ConfigurationManager) getKeyName(fieldName string, fieldTagName reflect.StructTag) string {
tagName := fieldTagName.Get(configClientTag)
if tagName == "-" {
return ignoreField
} else if tagName == "" {
return toSnake(fieldName)
} else if tagName == ",inline" {
tag := strings.Split(tagName, ",")
tagName = tag[1]
return tagName
}
return tagName
} | [
"func",
"(",
"*",
"ConfigurationManager",
")",
"getKeyName",
"(",
"fieldName",
"string",
",",
"fieldTagName",
"reflect",
".",
"StructTag",
")",
"string",
"{",
"tagName",
":=",
"fieldTagName",
".",
"Get",
"(",
"configClientTag",
")",
"\n",
"if",
"tagName",
"=="... | // get key from tag | [
"get",
"key",
"from",
"tag"
] | 5b479bcb10437daee44d1d77af651939c6d92541 | https://github.com/go-chassis/go-archaius/blob/5b479bcb10437daee44d1d77af651939c6d92541/core/config-manager/unmarshal.go#L506-L519 |
5,207 | go-chassis/go-archaius | core/config-manager/unmarshal.go | ToRvalueType | func ToRvalueType(confValue interface{}, convertType reflect.Type) (returnValue reflect.Value, err error) {
castValue := cast.NewValue(confValue, nil)
returnValue = reflect.New(convertType).Elem()
switch convertType.Kind() {
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
returnInt, rErr := castValue.ToInt64()
if err != nil {
err = rErr
}
returnValue.SetInt(returnInt)
case reflect.String:
returnString, rErr := castValue.ToString()
if err != nil {
err = rErr
}
returnValue.SetString(returnString)
case reflect.Float32, reflect.Float64:
returnFloat, rErr := castValue.ToFloat64()
if err != nil {
err = rErr
}
returnValue.SetFloat(returnFloat)
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
returnUInt, rErr := castValue.ToUint64()
if err != nil {
err = rErr
}
returnValue.SetUint(returnUInt)
case reflect.Bool:
returnBool, rErr := castValue.ToBool()
if err != nil {
err = rErr
}
returnValue.SetBool(returnBool)
default:
err = errors.New("canot convert type")
}
return returnValue, err
} | go | func ToRvalueType(confValue interface{}, convertType reflect.Type) (returnValue reflect.Value, err error) {
castValue := cast.NewValue(confValue, nil)
returnValue = reflect.New(convertType).Elem()
switch convertType.Kind() {
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
returnInt, rErr := castValue.ToInt64()
if err != nil {
err = rErr
}
returnValue.SetInt(returnInt)
case reflect.String:
returnString, rErr := castValue.ToString()
if err != nil {
err = rErr
}
returnValue.SetString(returnString)
case reflect.Float32, reflect.Float64:
returnFloat, rErr := castValue.ToFloat64()
if err != nil {
err = rErr
}
returnValue.SetFloat(returnFloat)
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
returnUInt, rErr := castValue.ToUint64()
if err != nil {
err = rErr
}
returnValue.SetUint(returnUInt)
case reflect.Bool:
returnBool, rErr := castValue.ToBool()
if err != nil {
err = rErr
}
returnValue.SetBool(returnBool)
default:
err = errors.New("canot convert type")
}
return returnValue, err
} | [
"func",
"ToRvalueType",
"(",
"confValue",
"interface",
"{",
"}",
",",
"convertType",
"reflect",
".",
"Type",
")",
"(",
"returnValue",
"reflect",
".",
"Value",
",",
"err",
"error",
")",
"{",
"castValue",
":=",
"cast",
".",
"NewValue",
"(",
"confValue",
",",... | // ToRvalueType Deserializes the object to a particular type | [
"ToRvalueType",
"Deserializes",
"the",
"object",
"to",
"a",
"particular",
"type"
] | 5b479bcb10437daee44d1d77af651939c6d92541 | https://github.com/go-chassis/go-archaius/blob/5b479bcb10437daee44d1d77af651939c6d92541/core/config-manager/unmarshal.go#L539-L583 |
5,208 | go-chassis/go-archaius | sources/file-source/file_handler.go | Convert2JavaProps | func Convert2JavaProps(p string, content []byte) (map[string]interface{}, error) {
configMap := make(map[string]interface{})
ss := yaml.MapSlice{}
err := yaml.Unmarshal([]byte(content), &ss)
if err != nil {
return nil, fmt.Errorf("yaml unmarshal [%s] failed, %s", content, err)
}
configMap = retrieveItems("", ss)
return configMap, nil
} | go | func Convert2JavaProps(p string, content []byte) (map[string]interface{}, error) {
configMap := make(map[string]interface{})
ss := yaml.MapSlice{}
err := yaml.Unmarshal([]byte(content), &ss)
if err != nil {
return nil, fmt.Errorf("yaml unmarshal [%s] failed, %s", content, err)
}
configMap = retrieveItems("", ss)
return configMap, nil
} | [
"func",
"Convert2JavaProps",
"(",
"p",
"string",
",",
"content",
"[",
"]",
"byte",
")",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
",",
"error",
")",
"{",
"configMap",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
... | //Convert2JavaProps is a FileHandler
//it convert the yaml content into java props | [
"Convert2JavaProps",
"is",
"a",
"FileHandler",
"it",
"convert",
"the",
"yaml",
"content",
"into",
"java",
"props"
] | 5b479bcb10437daee44d1d77af651939c6d92541 | https://github.com/go-chassis/go-archaius/blob/5b479bcb10437daee44d1d77af651939c6d92541/sources/file-source/file_handler.go#L15-L26 |
5,209 | go-chassis/go-archaius | sources/file-source/file_handler.go | UseFileNameAsKeyContentAsValue | func UseFileNameAsKeyContentAsValue(p string, content []byte) (map[string]interface{}, error) {
_, filename := filepath.Split(p)
configMap := make(map[string]interface{})
configMap[filename] = content
return configMap, nil
} | go | func UseFileNameAsKeyContentAsValue(p string, content []byte) (map[string]interface{}, error) {
_, filename := filepath.Split(p)
configMap := make(map[string]interface{})
configMap[filename] = content
return configMap, nil
} | [
"func",
"UseFileNameAsKeyContentAsValue",
"(",
"p",
"string",
",",
"content",
"[",
"]",
"byte",
")",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
",",
"error",
")",
"{",
"_",
",",
"filename",
":=",
"filepath",
".",
"Split",
"(",
"p",
")",
"... | //UseFileNameAsKeyContentAsValue is a FileHandler, it sets the yaml file name as key and the content as value | [
"UseFileNameAsKeyContentAsValue",
"is",
"a",
"FileHandler",
"it",
"sets",
"the",
"yaml",
"file",
"name",
"as",
"key",
"and",
"the",
"content",
"as",
"value"
] | 5b479bcb10437daee44d1d77af651939c6d92541 | https://github.com/go-chassis/go-archaius/blob/5b479bcb10437daee44d1d77af651939c6d92541/sources/file-source/file_handler.go#L51-L56 |
5,210 | go-chassis/go-archaius | sources/file-source/file_handler.go | Convert2configMap | func Convert2configMap(p string, content []byte) (map[string]interface{}, error) {
return UseFileNameAsKeyContentAsValue(p, content)
} | go | func Convert2configMap(p string, content []byte) (map[string]interface{}, error) {
return UseFileNameAsKeyContentAsValue(p, content)
} | [
"func",
"Convert2configMap",
"(",
"p",
"string",
",",
"content",
"[",
"]",
"byte",
")",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
",",
"error",
")",
"{",
"return",
"UseFileNameAsKeyContentAsValue",
"(",
"p",
",",
"content",
")",
"\n",
"}"
] | //Convert2configMap is legacy API | [
"Convert2configMap",
"is",
"legacy",
"API"
] | 5b479bcb10437daee44d1d77af651939c6d92541 | https://github.com/go-chassis/go-archaius/blob/5b479bcb10437daee44d1d77af651939c6d92541/sources/file-source/file_handler.go#L59-L61 |
5,211 | go-chassis/go-archaius | sources/configcenter/watcher.go | Cleanup | func (dynHandler *DynamicConfigHandler) Cleanup() error {
dynHandler.dynamicLock.Lock()
defer dynHandler.dynamicLock.Unlock()
if dynHandler.wsConnection != nil {
dynHandler.wsConnection.Close()
}
dynHandler.wsConnection = nil
return nil
} | go | func (dynHandler *DynamicConfigHandler) Cleanup() error {
dynHandler.dynamicLock.Lock()
defer dynHandler.dynamicLock.Unlock()
if dynHandler.wsConnection != nil {
dynHandler.wsConnection.Close()
}
dynHandler.wsConnection = nil
return nil
} | [
"func",
"(",
"dynHandler",
"*",
"DynamicConfigHandler",
")",
"Cleanup",
"(",
")",
"error",
"{",
"dynHandler",
".",
"dynamicLock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"dynHandler",
".",
"dynamicLock",
".",
"Unlock",
"(",
")",
"\n",
"if",
"dynHandler",
"."... | //Cleanup cleans particular dynamic configuration Handler up | [
"Cleanup",
"cleans",
"particular",
"dynamic",
"configuration",
"Handler",
"up"
] | 5b479bcb10437daee44d1d77af651939c6d92541 | https://github.com/go-chassis/go-archaius/blob/5b479bcb10437daee44d1d77af651939c6d92541/sources/configcenter/watcher.go#L43-L51 |
5,212 | go-chassis/go-archaius | archaius.go | Init | func Init(opts ...Option) error {
if running {
openlogging.Debug("can not init archaius again, call Clean first")
return nil
}
var err error
o := &Options{}
for _, opt := range opts {
opt(o)
}
// created config factory object
factory, err = NewConfigFactory()
if err != nil {
return err
}
factory.DeInit()
factory.Init()
fs, err := initFileSource(o)
if err != nil {
return err
}
if o.ConfigCenterInfo != (ConfigCenterInfo{}) {
if err := EnableConfigCenterSource(o.ConfigCenterInfo, o.ConfigClient); err != nil {
return err
}
}
err = factory.AddSource(fs)
if err != nil {
return err
}
// build-in config sources
if o.UseMemSource {
ms = memoryconfigsource.NewMemoryConfigurationSource()
factory.AddSource(ms)
}
if o.UseCLISource {
cmdSource := commandlinesource.NewCommandlineConfigSource()
factory.AddSource(cmdSource)
}
if o.UseENVSource {
envSource := envconfigsource.NewEnvConfigurationSource()
factory.AddSource(envSource)
}
eventHandler := EventListener{
Name: "EventHandler",
Factory: factory,
}
factory.RegisterListener(eventHandler, "a*")
openlogging.GetLogger().Info("archaius init success")
running = true
return nil
} | go | func Init(opts ...Option) error {
if running {
openlogging.Debug("can not init archaius again, call Clean first")
return nil
}
var err error
o := &Options{}
for _, opt := range opts {
opt(o)
}
// created config factory object
factory, err = NewConfigFactory()
if err != nil {
return err
}
factory.DeInit()
factory.Init()
fs, err := initFileSource(o)
if err != nil {
return err
}
if o.ConfigCenterInfo != (ConfigCenterInfo{}) {
if err := EnableConfigCenterSource(o.ConfigCenterInfo, o.ConfigClient); err != nil {
return err
}
}
err = factory.AddSource(fs)
if err != nil {
return err
}
// build-in config sources
if o.UseMemSource {
ms = memoryconfigsource.NewMemoryConfigurationSource()
factory.AddSource(ms)
}
if o.UseCLISource {
cmdSource := commandlinesource.NewCommandlineConfigSource()
factory.AddSource(cmdSource)
}
if o.UseENVSource {
envSource := envconfigsource.NewEnvConfigurationSource()
factory.AddSource(envSource)
}
eventHandler := EventListener{
Name: "EventHandler",
Factory: factory,
}
factory.RegisterListener(eventHandler, "a*")
openlogging.GetLogger().Info("archaius init success")
running = true
return nil
} | [
"func",
"Init",
"(",
"opts",
"...",
"Option",
")",
"error",
"{",
"if",
"running",
"{",
"openlogging",
".",
"Debug",
"(",
"\"",
"\"",
")",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"var",
"err",
"error",
"\n",
"o",
":=",
"&",
"Options",
"{",
"}",
"\... | // Init create a Archaius config singleton | [
"Init",
"create",
"a",
"Archaius",
"config",
"singleton"
] | 5b479bcb10437daee44d1d77af651939c6d92541 | https://github.com/go-chassis/go-archaius/blob/5b479bcb10437daee44d1d77af651939c6d92541/archaius.go#L58-L115 |
5,213 | go-chassis/go-archaius | archaius.go | EnableConfigCenterSource | func EnableConfigCenterSource(ci ConfigCenterInfo, cc config.Client) error {
if ci == (ConfigCenterInfo{}) {
return errors.New("ConfigCenterInfo can not be empty")
}
if configServerRunning {
openlogging.Debug("can not init config server again, call Clean first")
return nil
}
var err error
if cc == nil {
opts := config.Options{
DimensionInfo: ci.DefaultDimensionInfo,
ServerURI: ci.URL,
TenantName: ci.TenantName,
EnableSSL: ci.EnableSSL,
TLSConfig: ci.TLSConfig,
RefreshPort: ci.RefreshPort,
AutoDiscovery: ci.AutoDiscovery,
Env: ci.Environment,
}
cc, err = config.NewClient(ci.ClientType, opts)
if err != nil {
return err
}
}
configCenterSource := configcenter.NewConfigCenterSource(cc,
ci.DefaultDimensionInfo, ci.RefreshMode,
ci.RefreshInterval)
err = factory.AddSource(configCenterSource)
if err != nil {
return err
}
eventHandler := EventListener{
Name: "EventHandler",
Factory: factory,
}
factory.RegisterListener(eventHandler, "a*")
configServerRunning = true
return nil
} | go | func EnableConfigCenterSource(ci ConfigCenterInfo, cc config.Client) error {
if ci == (ConfigCenterInfo{}) {
return errors.New("ConfigCenterInfo can not be empty")
}
if configServerRunning {
openlogging.Debug("can not init config server again, call Clean first")
return nil
}
var err error
if cc == nil {
opts := config.Options{
DimensionInfo: ci.DefaultDimensionInfo,
ServerURI: ci.URL,
TenantName: ci.TenantName,
EnableSSL: ci.EnableSSL,
TLSConfig: ci.TLSConfig,
RefreshPort: ci.RefreshPort,
AutoDiscovery: ci.AutoDiscovery,
Env: ci.Environment,
}
cc, err = config.NewClient(ci.ClientType, opts)
if err != nil {
return err
}
}
configCenterSource := configcenter.NewConfigCenterSource(cc,
ci.DefaultDimensionInfo, ci.RefreshMode,
ci.RefreshInterval)
err = factory.AddSource(configCenterSource)
if err != nil {
return err
}
eventHandler := EventListener{
Name: "EventHandler",
Factory: factory,
}
factory.RegisterListener(eventHandler, "a*")
configServerRunning = true
return nil
} | [
"func",
"EnableConfigCenterSource",
"(",
"ci",
"ConfigCenterInfo",
",",
"cc",
"config",
".",
"Client",
")",
"error",
"{",
"if",
"ci",
"==",
"(",
"ConfigCenterInfo",
"{",
"}",
")",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\... | //EnableConfigCenterSource create a config center source singleton
//A config center source pull remote config server key values into local memory
//so that you can use GetXXX to get value easily | [
"EnableConfigCenterSource",
"create",
"a",
"config",
"center",
"source",
"singleton",
"A",
"config",
"center",
"source",
"pull",
"remote",
"config",
"server",
"key",
"values",
"into",
"local",
"memory",
"so",
"that",
"you",
"can",
"use",
"GetXXX",
"to",
"get",
... | 5b479bcb10437daee44d1d77af651939c6d92541 | https://github.com/go-chassis/go-archaius/blob/5b479bcb10437daee44d1d77af651939c6d92541/archaius.go#L148-L190 |
5,214 | go-chassis/go-archaius | archaius.go | Event | func (e EventListener) Event(event *core.Event) {
value := e.Factory.GetConfigurationByKey(event.Key)
openlogging.GetLogger().Infof("config value after change %s | %s", event.Key, value)
} | go | func (e EventListener) Event(event *core.Event) {
value := e.Factory.GetConfigurationByKey(event.Key)
openlogging.GetLogger().Infof("config value after change %s | %s", event.Key, value)
} | [
"func",
"(",
"e",
"EventListener",
")",
"Event",
"(",
"event",
"*",
"core",
".",
"Event",
")",
"{",
"value",
":=",
"e",
".",
"Factory",
".",
"GetConfigurationByKey",
"(",
"event",
".",
"Key",
")",
"\n",
"openlogging",
".",
"GetLogger",
"(",
")",
".",
... | // Event is invoked while generating events at run time | [
"Event",
"is",
"invoked",
"while",
"generating",
"events",
"at",
"run",
"time"
] | 5b479bcb10437daee44d1d77af651939c6d92541 | https://github.com/go-chassis/go-archaius/blob/5b479bcb10437daee44d1d77af651939c6d92541/archaius.go#L199-L202 |
5,215 | go-chassis/go-archaius | archaius.go | GetBool | func GetBool(key string, defaultValue bool) bool {
b, err := factory.GetValue(key).ToBool()
if err != nil {
return defaultValue
}
return b
} | go | func GetBool(key string, defaultValue bool) bool {
b, err := factory.GetValue(key).ToBool()
if err != nil {
return defaultValue
}
return b
} | [
"func",
"GetBool",
"(",
"key",
"string",
",",
"defaultValue",
"bool",
")",
"bool",
"{",
"b",
",",
"err",
":=",
"factory",
".",
"GetValue",
"(",
"key",
")",
".",
"ToBool",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"defaultValue",
"\n",
... | // GetBool is gives the key value in the form of bool | [
"GetBool",
"is",
"gives",
"the",
"key",
"value",
"in",
"the",
"form",
"of",
"bool"
] | 5b479bcb10437daee44d1d77af651939c6d92541 | https://github.com/go-chassis/go-archaius/blob/5b479bcb10437daee44d1d77af651939c6d92541/archaius.go#L220-L226 |
5,216 | go-chassis/go-archaius | archaius.go | GetFloat64 | func GetFloat64(key string, defaultValue float64) float64 {
result, err := factory.GetValue(key).ToFloat64()
if err != nil {
return defaultValue
}
return result
} | go | func GetFloat64(key string, defaultValue float64) float64 {
result, err := factory.GetValue(key).ToFloat64()
if err != nil {
return defaultValue
}
return result
} | [
"func",
"GetFloat64",
"(",
"key",
"string",
",",
"defaultValue",
"float64",
")",
"float64",
"{",
"result",
",",
"err",
":=",
"factory",
".",
"GetValue",
"(",
"key",
")",
".",
"ToFloat64",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"defaul... | // GetFloat64 gives the key value in the form of float64 | [
"GetFloat64",
"gives",
"the",
"key",
"value",
"in",
"the",
"form",
"of",
"float64"
] | 5b479bcb10437daee44d1d77af651939c6d92541 | https://github.com/go-chassis/go-archaius/blob/5b479bcb10437daee44d1d77af651939c6d92541/archaius.go#L229-L235 |
5,217 | go-chassis/go-archaius | archaius.go | GetInt | func GetInt(key string, defaultValue int) int {
result, err := factory.GetValue(key).ToInt()
if err != nil {
return defaultValue
}
return result
} | go | func GetInt(key string, defaultValue int) int {
result, err := factory.GetValue(key).ToInt()
if err != nil {
return defaultValue
}
return result
} | [
"func",
"GetInt",
"(",
"key",
"string",
",",
"defaultValue",
"int",
")",
"int",
"{",
"result",
",",
"err",
":=",
"factory",
".",
"GetValue",
"(",
"key",
")",
".",
"ToInt",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"defaultValue",
"\n",... | // GetInt gives the key value in the form of GetInt | [
"GetInt",
"gives",
"the",
"key",
"value",
"in",
"the",
"form",
"of",
"GetInt"
] | 5b479bcb10437daee44d1d77af651939c6d92541 | https://github.com/go-chassis/go-archaius/blob/5b479bcb10437daee44d1d77af651939c6d92541/archaius.go#L238-L244 |
5,218 | go-chassis/go-archaius | archaius.go | GetString | func GetString(key string, defaultValue string) string {
result, err := factory.GetValue(key).ToString()
if err != nil {
return defaultValue
}
return result
} | go | func GetString(key string, defaultValue string) string {
result, err := factory.GetValue(key).ToString()
if err != nil {
return defaultValue
}
return result
} | [
"func",
"GetString",
"(",
"key",
"string",
",",
"defaultValue",
"string",
")",
"string",
"{",
"result",
",",
"err",
":=",
"factory",
".",
"GetValue",
"(",
"key",
")",
".",
"ToString",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"defaultVal... | // GetString gives the key value in the form of GetString | [
"GetString",
"gives",
"the",
"key",
"value",
"in",
"the",
"form",
"of",
"GetString"
] | 5b479bcb10437daee44d1d77af651939c6d92541 | https://github.com/go-chassis/go-archaius/blob/5b479bcb10437daee44d1d77af651939c6d92541/archaius.go#L247-L253 |
5,219 | go-chassis/go-archaius | archaius.go | GetStringByDI | func GetStringByDI(dimensionInfo, key string, defaultValue string) string {
result, err := factory.GetValueByDI(dimensionInfo, key).ToString()
if err != nil {
return defaultValue
}
return result
} | go | func GetStringByDI(dimensionInfo, key string, defaultValue string) string {
result, err := factory.GetValueByDI(dimensionInfo, key).ToString()
if err != nil {
return defaultValue
}
return result
} | [
"func",
"GetStringByDI",
"(",
"dimensionInfo",
",",
"key",
"string",
",",
"defaultValue",
"string",
")",
"string",
"{",
"result",
",",
"err",
":=",
"factory",
".",
"GetValueByDI",
"(",
"dimensionInfo",
",",
"key",
")",
".",
"ToString",
"(",
")",
"\n",
"if"... | // GetStringByDI get the value of configuration key in other dimension | [
"GetStringByDI",
"get",
"the",
"value",
"of",
"configuration",
"key",
"in",
"other",
"dimension"
] | 5b479bcb10437daee44d1d77af651939c6d92541 | https://github.com/go-chassis/go-archaius/blob/5b479bcb10437daee44d1d77af651939c6d92541/archaius.go#L261-L267 |
5,220 | go-chassis/go-archaius | archaius.go | AddDI | func AddDI(dimensionInfo string) (map[string]string, error) {
config, err := factory.AddByDimensionInfo(dimensionInfo)
return config, err
} | go | func AddDI(dimensionInfo string) (map[string]string, error) {
config, err := factory.AddByDimensionInfo(dimensionInfo)
return config, err
} | [
"func",
"AddDI",
"(",
"dimensionInfo",
"string",
")",
"(",
"map",
"[",
"string",
"]",
"string",
",",
"error",
")",
"{",
"config",
",",
"err",
":=",
"factory",
".",
"AddByDimensionInfo",
"(",
"dimensionInfo",
")",
"\n",
"return",
"config",
",",
"err",
"\n... | // AddDI adds a NewDimensionInfo of which configurations needs to be taken | [
"AddDI",
"adds",
"a",
"NewDimensionInfo",
"of",
"which",
"configurations",
"needs",
"to",
"be",
"taken"
] | 5b479bcb10437daee44d1d77af651939c6d92541 | https://github.com/go-chassis/go-archaius/blob/5b479bcb10437daee44d1d77af651939c6d92541/archaius.go#L275-L278 |
5,221 | go-chassis/go-archaius | archaius.go | RegisterListener | func RegisterListener(listenerObj core.EventListener, key ...string) error {
return factory.RegisterListener(listenerObj, key...)
} | go | func RegisterListener(listenerObj core.EventListener, key ...string) error {
return factory.RegisterListener(listenerObj, key...)
} | [
"func",
"RegisterListener",
"(",
"listenerObj",
"core",
".",
"EventListener",
",",
"key",
"...",
"string",
")",
"error",
"{",
"return",
"factory",
".",
"RegisterListener",
"(",
"listenerObj",
",",
"key",
"...",
")",
"\n",
"}"
] | //RegisterListener to Register all listener for different key changes, each key could be a regular expression | [
"RegisterListener",
"to",
"Register",
"all",
"listener",
"for",
"different",
"key",
"changes",
"each",
"key",
"could",
"be",
"a",
"regular",
"expression"
] | 5b479bcb10437daee44d1d77af651939c6d92541 | https://github.com/go-chassis/go-archaius/blob/5b479bcb10437daee44d1d77af651939c6d92541/archaius.go#L281-L283 |
5,222 | go-chassis/go-archaius | archaius.go | UnRegisterListener | func UnRegisterListener(listenerObj core.EventListener, key ...string) error {
return factory.UnRegisterListener(listenerObj, key...)
} | go | func UnRegisterListener(listenerObj core.EventListener, key ...string) error {
return factory.UnRegisterListener(listenerObj, key...)
} | [
"func",
"UnRegisterListener",
"(",
"listenerObj",
"core",
".",
"EventListener",
",",
"key",
"...",
"string",
")",
"error",
"{",
"return",
"factory",
".",
"UnRegisterListener",
"(",
"listenerObj",
",",
"key",
"...",
")",
"\n",
"}"
] | // UnRegisterListener is to remove the listener | [
"UnRegisterListener",
"is",
"to",
"remove",
"the",
"listener"
] | 5b479bcb10437daee44d1d77af651939c6d92541 | https://github.com/go-chassis/go-archaius/blob/5b479bcb10437daee44d1d77af651939c6d92541/archaius.go#L286-L288 |
5,223 | go-chassis/go-archaius | archaius.go | AddFile | func AddFile(file string, opts ...FileOption) error {
o := &FileOptions{}
for _, f := range opts {
f(o)
}
if err := fs.AddFile(file, filesource.DefaultFilePriority, o.Handler); err != nil {
return err
}
return factory.Refresh(fs.GetSourceName())
} | go | func AddFile(file string, opts ...FileOption) error {
o := &FileOptions{}
for _, f := range opts {
f(o)
}
if err := fs.AddFile(file, filesource.DefaultFilePriority, o.Handler); err != nil {
return err
}
return factory.Refresh(fs.GetSourceName())
} | [
"func",
"AddFile",
"(",
"file",
"string",
",",
"opts",
"...",
"FileOption",
")",
"error",
"{",
"o",
":=",
"&",
"FileOptions",
"{",
"}",
"\n",
"for",
"_",
",",
"f",
":=",
"range",
"opts",
"{",
"f",
"(",
"o",
")",
"\n",
"}",
"\n",
"if",
"err",
":... | // AddFile is for to add the configuration files into the configfactory at run time | [
"AddFile",
"is",
"for",
"to",
"add",
"the",
"configuration",
"files",
"into",
"the",
"configfactory",
"at",
"run",
"time"
] | 5b479bcb10437daee44d1d77af651939c6d92541 | https://github.com/go-chassis/go-archaius/blob/5b479bcb10437daee44d1d77af651939c6d92541/archaius.go#L291-L300 |
5,224 | go-chassis/go-archaius | archaius.go | Clean | func Clean() error {
err := factory.DeInit()
if err != nil {
return err
}
running = false
configServerRunning = false
return nil
} | go | func Clean() error {
err := factory.DeInit()
if err != nil {
return err
}
running = false
configServerRunning = false
return nil
} | [
"func",
"Clean",
"(",
")",
"error",
"{",
"err",
":=",
"factory",
".",
"DeInit",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"running",
"=",
"false",
"\n",
"configServerRunning",
"=",
"false",
"\n",
"return",
"nil"... | //Clean will call config manager CleanUp Method,
//it deletes all sources which means all of key value is deleted.
//after you call Clean, you can init archaius again | [
"Clean",
"will",
"call",
"config",
"manager",
"CleanUp",
"Method",
"it",
"deletes",
"all",
"sources",
"which",
"means",
"all",
"of",
"key",
"value",
"is",
"deleted",
".",
"after",
"you",
"call",
"Clean",
"you",
"can",
"init",
"archaius",
"again"
] | 5b479bcb10437daee44d1d77af651939c6d92541 | https://github.com/go-chassis/go-archaius/blob/5b479bcb10437daee44d1d77af651939c6d92541/archaius.go#L326-L334 |
5,225 | go-chassis/go-archaius | examples/hack/main.go | Event | func (e EventListener) Event(event *core.Event) {
configValue := ConfigFactory.GetConfigurationByKey(event.Key)
openlogging.GetLogger().Infof("config value ", event.Key, " | ", configValue)
} | go | func (e EventListener) Event(event *core.Event) {
configValue := ConfigFactory.GetConfigurationByKey(event.Key)
openlogging.GetLogger().Infof("config value ", event.Key, " | ", configValue)
} | [
"func",
"(",
"e",
"EventListener",
")",
"Event",
"(",
"event",
"*",
"core",
".",
"Event",
")",
"{",
"configValue",
":=",
"ConfigFactory",
".",
"GetConfigurationByKey",
"(",
"event",
".",
"Key",
")",
"\n",
"openlogging",
".",
"GetLogger",
"(",
")",
".",
"... | //Event is a method get config value and logs it | [
"Event",
"is",
"a",
"method",
"get",
"config",
"value",
"and",
"logs",
"it"
] | 5b479bcb10437daee44d1d77af651939c6d92541 | https://github.com/go-chassis/go-archaius/blob/5b479bcb10437daee44d1d77af651939c6d92541/examples/hack/main.go#L161-L165 |
5,226 | go-chassis/go-archaius | sources/file-source/filesource.go | NewFileSource | func NewFileSource() FileSource {
if fileConfigSource == nil {
fileConfigSource = new(fileSource)
fileConfigSource.priority = fileSourcePriority
fileConfigSource.files = make([]file, 0)
fileConfigSource.fileHandlers = make(map[string]FileHandler)
}
return fileConfigSource
} | go | func NewFileSource() FileSource {
if fileConfigSource == nil {
fileConfigSource = new(fileSource)
fileConfigSource.priority = fileSourcePriority
fileConfigSource.files = make([]file, 0)
fileConfigSource.fileHandlers = make(map[string]FileHandler)
}
return fileConfigSource
} | [
"func",
"NewFileSource",
"(",
")",
"FileSource",
"{",
"if",
"fileConfigSource",
"==",
"nil",
"{",
"fileConfigSource",
"=",
"new",
"(",
"fileSource",
")",
"\n",
"fileConfigSource",
".",
"priority",
"=",
"fileSourcePriority",
"\n",
"fileConfigSource",
".",
"files",
... | //NewFileSource creates a source which can handler local files | [
"NewFileSource",
"creates",
"a",
"source",
"which",
"can",
"handler",
"local",
"files"
] | 5b479bcb10437daee44d1d77af651939c6d92541 | https://github.com/go-chassis/go-archaius/blob/5b479bcb10437daee44d1d77af651939c6d92541/sources/file-source/filesource.go#L106-L115 |
5,227 | go-chassis/go-archaius | examples/event/event.go | Event | func (e *Listener) Event(event *core.Event) {
openlogging.GetLogger().Info(event.Key)
openlogging.GetLogger().Infof(fmt.Sprintf("%s", event.Value))
openlogging.GetLogger().Info(event.EventType)
} | go | func (e *Listener) Event(event *core.Event) {
openlogging.GetLogger().Info(event.Key)
openlogging.GetLogger().Infof(fmt.Sprintf("%s", event.Value))
openlogging.GetLogger().Info(event.EventType)
} | [
"func",
"(",
"e",
"*",
"Listener",
")",
"Event",
"(",
"event",
"*",
"core",
".",
"Event",
")",
"{",
"openlogging",
".",
"GetLogger",
"(",
")",
".",
"Info",
"(",
"event",
".",
"Key",
")",
"\n",
"openlogging",
".",
"GetLogger",
"(",
")",
".",
"Infof"... | //Event is a method for QPS event listening | [
"Event",
"is",
"a",
"method",
"for",
"QPS",
"event",
"listening"
] | 5b479bcb10437daee44d1d77af651939c6d92541 | https://github.com/go-chassis/go-archaius/blob/5b479bcb10437daee44d1d77af651939c6d92541/examples/event/event.go#L18-L22 |
5,228 | go-chassis/go-archaius | core/cast/cast.go | NewValue | func NewValue(val interface{}, err error) Value {
confVal := new(configValue)
confVal.value = val
confVal.err = err
return confVal
} | go | func NewValue(val interface{}, err error) Value {
confVal := new(configValue)
confVal.value = val
confVal.err = err
return confVal
} | [
"func",
"NewValue",
"(",
"val",
"interface",
"{",
"}",
",",
"err",
"error",
")",
"Value",
"{",
"confVal",
":=",
"new",
"(",
"configValue",
")",
"\n",
"confVal",
".",
"value",
"=",
"val",
"\n",
"confVal",
".",
"err",
"=",
"err",
"\n",
"return",
"confV... | // NewValue creates an object for an interface X | [
"NewValue",
"creates",
"an",
"object",
"for",
"an",
"interface",
"X"
] | 5b479bcb10437daee44d1d77af651939c6d92541 | https://github.com/go-chassis/go-archaius/blob/5b479bcb10437daee44d1d77af651939c6d92541/core/cast/cast.go#L27-L32 |
5,229 | go-chassis/go-archaius | sources/enviromentvariable-source/envconfigurationsource.go | NewEnvConfigurationSource | func NewEnvConfigurationSource() core.ConfigSource {
envConfigSource := new(EnvConfigurationSource)
envConfigSource.priority = envVariableSourcePriority
config, err := envConfigSource.pullConfigurations()
if err != nil {
openlogging.GetLogger().Error("failed to initialize environment configurations: " + err.Error())
return envConfigSource
}
envConfigSource.Configurations = config
return envConfigSource
} | go | func NewEnvConfigurationSource() core.ConfigSource {
envConfigSource := new(EnvConfigurationSource)
envConfigSource.priority = envVariableSourcePriority
config, err := envConfigSource.pullConfigurations()
if err != nil {
openlogging.GetLogger().Error("failed to initialize environment configurations: " + err.Error())
return envConfigSource
}
envConfigSource.Configurations = config
return envConfigSource
} | [
"func",
"NewEnvConfigurationSource",
"(",
")",
"core",
".",
"ConfigSource",
"{",
"envConfigSource",
":=",
"new",
"(",
"EnvConfigurationSource",
")",
"\n",
"envConfigSource",
".",
"priority",
"=",
"envVariableSourcePriority",
"\n",
"config",
",",
"err",
":=",
"envCon... | //NewEnvConfigurationSource configures a new environment configuration | [
"NewEnvConfigurationSource",
"configures",
"a",
"new",
"environment",
"configuration"
] | 5b479bcb10437daee44d1d77af651939c6d92541 | https://github.com/go-chassis/go-archaius/blob/5b479bcb10437daee44d1d77af651939c6d92541/sources/enviromentvariable-source/envconfigurationsource.go#L45-L56 |
5,230 | go-chassis/go-archaius | sources/configcenter/event_handler.go | OnReceive | func (eventHandler *ConfigCenterEventHandler) OnReceive(sourceConfig map[string]interface{}) {
events, err := eventHandler.ConfigSource.populateEvents(sourceConfig)
if err != nil {
openlogging.GetLogger().Error("error in generating event:" + err.Error())
return
}
openlogging.GetLogger().Debugf("event On Receive", events)
for _, event := range events {
eventHandler.Callback.OnEvent(event)
}
return
} | go | func (eventHandler *ConfigCenterEventHandler) OnReceive(sourceConfig map[string]interface{}) {
events, err := eventHandler.ConfigSource.populateEvents(sourceConfig)
if err != nil {
openlogging.GetLogger().Error("error in generating event:" + err.Error())
return
}
openlogging.GetLogger().Debugf("event On Receive", events)
for _, event := range events {
eventHandler.Callback.OnEvent(event)
}
return
} | [
"func",
"(",
"eventHandler",
"*",
"ConfigCenterEventHandler",
")",
"OnReceive",
"(",
"sourceConfig",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"{",
"events",
",",
"err",
":=",
"eventHandler",
".",
"ConfigSource",
".",
"populateEvents",
"(",
"sourc... | //OnReceive initializes all necessary components for a configuration center | [
"OnReceive",
"initializes",
"all",
"necessary",
"components",
"for",
"a",
"configuration",
"center"
] | 5b479bcb10437daee44d1d77af651939c6d92541 | https://github.com/go-chassis/go-archaius/blob/5b479bcb10437daee44d1d77af651939c6d92541/sources/configcenter/event_handler.go#L28-L42 |
5,231 | go-chassis/go-archaius | configurationfactory.go | NewConfigFactory | func NewConfigFactory() (ConfigurationFactory, error) {
arc := new(ConfigFactory)
//// Source init should be before config manager init
//sources.NewSourceInit()
arc.dispatcher = eventsystem.NewDispatcher()
arc.configMgr = configmanager.NewConfigurationManager(arc.dispatcher)
openlogging.GetLogger().Debug("ConfigurationFactory Initiated")
return arc, nil
} | go | func NewConfigFactory() (ConfigurationFactory, error) {
arc := new(ConfigFactory)
//// Source init should be before config manager init
//sources.NewSourceInit()
arc.dispatcher = eventsystem.NewDispatcher()
arc.configMgr = configmanager.NewConfigurationManager(arc.dispatcher)
openlogging.GetLogger().Debug("ConfigurationFactory Initiated")
return arc, nil
} | [
"func",
"NewConfigFactory",
"(",
")",
"(",
"ConfigurationFactory",
",",
"error",
")",
"{",
"arc",
":=",
"new",
"(",
"ConfigFactory",
")",
"\n",
"//// Source init should be before config manager init",
"//sources.NewSourceInit()",
"arc",
".",
"dispatcher",
"=",
"eventsys... | // NewConfigFactory creates a new configuration object for config center | [
"NewConfigFactory",
"creates",
"a",
"new",
"configuration",
"object",
"for",
"config",
"center"
] | 5b479bcb10437daee44d1d77af651939c6d92541 | https://github.com/go-chassis/go-archaius/blob/5b479bcb10437daee44d1d77af651939c6d92541/configurationfactory.go#L83-L92 |
5,232 | go-chassis/go-archaius | configurationfactory.go | GetConfigurationsByDimensionInfo | func (arc *ConfigFactory) GetConfigurationsByDimensionInfo(dimensionInfo string) map[string]interface{} {
if arc.initSuccess == false {
return nil
}
config, err := arc.configMgr.GetConfigurationsByDimensionInfo(dimensionInfo)
if err != nil {
openlogging.GetLogger().Errorf("Failed to get the configuration by dimension info: %s", err)
}
return config
} | go | func (arc *ConfigFactory) GetConfigurationsByDimensionInfo(dimensionInfo string) map[string]interface{} {
if arc.initSuccess == false {
return nil
}
config, err := arc.configMgr.GetConfigurationsByDimensionInfo(dimensionInfo)
if err != nil {
openlogging.GetLogger().Errorf("Failed to get the configuration by dimension info: %s", err)
}
return config
} | [
"func",
"(",
"arc",
"*",
"ConfigFactory",
")",
"GetConfigurationsByDimensionInfo",
"(",
"dimensionInfo",
"string",
")",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"if",
"arc",
".",
"initSuccess",
"==",
"false",
"{",
"return",
"nil",
"\n",
"}",
... | //GetConfigurationsByDimensionInfo dump complete configuration managed by config-client Only return config Center configurations. | [
"GetConfigurationsByDimensionInfo",
"dump",
"complete",
"configuration",
"managed",
"by",
"config",
"-",
"client",
"Only",
"return",
"config",
"Center",
"configurations",
"."
] | 5b479bcb10437daee44d1d77af651939c6d92541 | https://github.com/go-chassis/go-archaius/blob/5b479bcb10437daee44d1d77af651939c6d92541/configurationfactory.go#L114-L125 |
5,233 | go-chassis/go-archaius | configurationfactory.go | AddByDimensionInfo | func (arc *ConfigFactory) AddByDimensionInfo(dimensionInfo string) (map[string]string, error) {
if arc.initSuccess == false {
return nil, nil
}
config, err := arc.configMgr.AddDimensionInfo(dimensionInfo)
return config, err
} | go | func (arc *ConfigFactory) AddByDimensionInfo(dimensionInfo string) (map[string]string, error) {
if arc.initSuccess == false {
return nil, nil
}
config, err := arc.configMgr.AddDimensionInfo(dimensionInfo)
return config, err
} | [
"func",
"(",
"arc",
"*",
"ConfigFactory",
")",
"AddByDimensionInfo",
"(",
"dimensionInfo",
"string",
")",
"(",
"map",
"[",
"string",
"]",
"string",
",",
"error",
")",
"{",
"if",
"arc",
".",
"initSuccess",
"==",
"false",
"{",
"return",
"nil",
",",
"nil",
... | // AddByDimensionInfo adds a NewDimensionInfo of which configurations needs to be taken | [
"AddByDimensionInfo",
"adds",
"a",
"NewDimensionInfo",
"of",
"which",
"configurations",
"needs",
"to",
"be",
"taken"
] | 5b479bcb10437daee44d1d77af651939c6d92541 | https://github.com/go-chassis/go-archaius/blob/5b479bcb10437daee44d1d77af651939c6d92541/configurationfactory.go#L128-L135 |
5,234 | go-chassis/go-archaius | configurationfactory.go | GetConfigurationByKey | func (arc *ConfigFactory) GetConfigurationByKey(key string) interface{} {
if arc.initSuccess == false {
return nil
}
return arc.configMgr.GetConfigurationsByKey(key)
} | go | func (arc *ConfigFactory) GetConfigurationByKey(key string) interface{} {
if arc.initSuccess == false {
return nil
}
return arc.configMgr.GetConfigurationsByKey(key)
} | [
"func",
"(",
"arc",
"*",
"ConfigFactory",
")",
"GetConfigurationByKey",
"(",
"key",
"string",
")",
"interface",
"{",
"}",
"{",
"if",
"arc",
".",
"initSuccess",
"==",
"false",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"return",
"arc",
".",
"configMgr",
"."... | // GetConfigurationByKey return all values of different sources | [
"GetConfigurationByKey",
"return",
"all",
"values",
"of",
"different",
"sources"
] | 5b479bcb10437daee44d1d77af651939c6d92541 | https://github.com/go-chassis/go-archaius/blob/5b479bcb10437daee44d1d77af651939c6d92541/configurationfactory.go#L138-L144 |
5,235 | go-chassis/go-archaius | configurationfactory.go | GetConfigurationByKeyAndDimensionInfo | func (arc *ConfigFactory) GetConfigurationByKeyAndDimensionInfo(dimensionInfo, key string) interface{} {
if arc.initSuccess == false {
return nil
}
return arc.configMgr.GetConfigurationsByKeyAndDimensionInfo(dimensionInfo, key)
} | go | func (arc *ConfigFactory) GetConfigurationByKeyAndDimensionInfo(dimensionInfo, key string) interface{} {
if arc.initSuccess == false {
return nil
}
return arc.configMgr.GetConfigurationsByKeyAndDimensionInfo(dimensionInfo, key)
} | [
"func",
"(",
"arc",
"*",
"ConfigFactory",
")",
"GetConfigurationByKeyAndDimensionInfo",
"(",
"dimensionInfo",
",",
"key",
"string",
")",
"interface",
"{",
"}",
"{",
"if",
"arc",
".",
"initSuccess",
"==",
"false",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"ret... | // GetConfigurationByKeyAndDimensionInfo get the value for a key in a particular dimensionInfo | [
"GetConfigurationByKeyAndDimensionInfo",
"get",
"the",
"value",
"for",
"a",
"key",
"in",
"a",
"particular",
"dimensionInfo"
] | 5b479bcb10437daee44d1d77af651939c6d92541 | https://github.com/go-chassis/go-archaius/blob/5b479bcb10437daee44d1d77af651939c6d92541/configurationfactory.go#L147-L153 |
5,236 | go-chassis/go-archaius | configurationfactory.go | AddSource | func (arc *ConfigFactory) AddSource(source core.ConfigSource) error {
if source == nil {
return errors.New("source can not be nil")
}
if arc.initSuccess == false {
openlogging.Warn("Plz call factory.Init() first, failed to add source: " + source.GetSourceName())
return nil
}
return arc.configMgr.AddSource(source, source.GetPriority())
} | go | func (arc *ConfigFactory) AddSource(source core.ConfigSource) error {
if source == nil {
return errors.New("source can not be nil")
}
if arc.initSuccess == false {
openlogging.Warn("Plz call factory.Init() first, failed to add source: " + source.GetSourceName())
return nil
}
return arc.configMgr.AddSource(source, source.GetPriority())
} | [
"func",
"(",
"arc",
"*",
"ConfigFactory",
")",
"AddSource",
"(",
"source",
"core",
".",
"ConfigSource",
")",
"error",
"{",
"if",
"source",
"==",
"nil",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"arc",
".",
"i... | // AddSource return all values of different sources | [
"AddSource",
"return",
"all",
"values",
"of",
"different",
"sources"
] | 5b479bcb10437daee44d1d77af651939c6d92541 | https://github.com/go-chassis/go-archaius/blob/5b479bcb10437daee44d1d77af651939c6d92541/configurationfactory.go#L156-L166 |
5,237 | go-chassis/go-archaius | configurationfactory.go | IsKeyExist | func (arc *ConfigFactory) IsKeyExist(key string) bool {
if arc.initSuccess == false {
return false
}
return arc.configMgr.IsKeyExist(key)
} | go | func (arc *ConfigFactory) IsKeyExist(key string) bool {
if arc.initSuccess == false {
return false
}
return arc.configMgr.IsKeyExist(key)
} | [
"func",
"(",
"arc",
"*",
"ConfigFactory",
")",
"IsKeyExist",
"(",
"key",
"string",
")",
"bool",
"{",
"if",
"arc",
".",
"initSuccess",
"==",
"false",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"return",
"arc",
".",
"configMgr",
".",
"IsKeyExist",
"(",
"... | // IsKeyExist check existence of key | [
"IsKeyExist",
"check",
"existence",
"of",
"key"
] | 5b479bcb10437daee44d1d77af651939c6d92541 | https://github.com/go-chassis/go-archaius/blob/5b479bcb10437daee44d1d77af651939c6d92541/configurationfactory.go#L169-L175 |
5,238 | go-chassis/go-archaius | configurationfactory.go | RegisterListener | func (arc *ConfigFactory) RegisterListener(listenerObj core.EventListener, keys ...string) error {
for _, key := range keys {
_, err := regexp.Compile(key)
if err != nil {
openlogging.GetLogger().Error(fmt.Sprintf("invalid key format for %s key. key registration ignored: %s", key, err))
return fmt.Errorf("invalid key format for %s key", key)
}
}
return arc.dispatcher.RegisterListener(listenerObj, keys...)
} | go | func (arc *ConfigFactory) RegisterListener(listenerObj core.EventListener, keys ...string) error {
for _, key := range keys {
_, err := regexp.Compile(key)
if err != nil {
openlogging.GetLogger().Error(fmt.Sprintf("invalid key format for %s key. key registration ignored: %s", key, err))
return fmt.Errorf("invalid key format for %s key", key)
}
}
return arc.dispatcher.RegisterListener(listenerObj, keys...)
} | [
"func",
"(",
"arc",
"*",
"ConfigFactory",
")",
"RegisterListener",
"(",
"listenerObj",
"core",
".",
"EventListener",
",",
"keys",
"...",
"string",
")",
"error",
"{",
"for",
"_",
",",
"key",
":=",
"range",
"keys",
"{",
"_",
",",
"err",
":=",
"regexp",
"... | // RegisterListener Function to Register all listener for different key changes | [
"RegisterListener",
"Function",
"to",
"Register",
"all",
"listener",
"for",
"different",
"key",
"changes"
] | 5b479bcb10437daee44d1d77af651939c6d92541 | https://github.com/go-chassis/go-archaius/blob/5b479bcb10437daee44d1d77af651939c6d92541/configurationfactory.go#L178-L188 |
5,239 | go-chassis/go-archaius | configurationfactory.go | DeInit | func (arc *ConfigFactory) DeInit() error {
if arc.initSuccess == false {
return nil
}
arc.initSuccess = false
arc.configMgr.Cleanup()
return nil
} | go | func (arc *ConfigFactory) DeInit() error {
if arc.initSuccess == false {
return nil
}
arc.initSuccess = false
arc.configMgr.Cleanup()
return nil
} | [
"func",
"(",
"arc",
"*",
"ConfigFactory",
")",
"DeInit",
"(",
")",
"error",
"{",
"if",
"arc",
".",
"initSuccess",
"==",
"false",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"arc",
".",
"initSuccess",
"=",
"false",
"\n",
"arc",
".",
"configMgr",
".",
"Clea... | // DeInit return all values of different sources | [
"DeInit",
"return",
"all",
"values",
"of",
"different",
"sources"
] | 5b479bcb10437daee44d1d77af651939c6d92541 | https://github.com/go-chassis/go-archaius/blob/5b479bcb10437daee44d1d77af651939c6d92541/configurationfactory.go#L221-L228 |
5,240 | go-chassis/go-archaius | configurationfactory.go | GetValue | func (arc *ConfigFactory) GetValue(key string) cast.Value {
if arc.initSuccess == false {
return nil
}
var confValue cast.Value
val := arc.GetConfigurationByKey(key)
if val == nil {
confValue = cast.NewValue(nil, errors.New("key does not exist"))
} else {
confValue = cast.NewValue(val, nil)
}
return confValue
} | go | func (arc *ConfigFactory) GetValue(key string) cast.Value {
if arc.initSuccess == false {
return nil
}
var confValue cast.Value
val := arc.GetConfigurationByKey(key)
if val == nil {
confValue = cast.NewValue(nil, errors.New("key does not exist"))
} else {
confValue = cast.NewValue(val, nil)
}
return confValue
} | [
"func",
"(",
"arc",
"*",
"ConfigFactory",
")",
"GetValue",
"(",
"key",
"string",
")",
"cast",
".",
"Value",
"{",
"if",
"arc",
".",
"initSuccess",
"==",
"false",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"var",
"confValue",
"cast",
".",
"Value",
"\n",
... | // GetValue an abstraction to return key's value in respective type | [
"GetValue",
"an",
"abstraction",
"to",
"return",
"key",
"s",
"value",
"in",
"respective",
"type"
] | 5b479bcb10437daee44d1d77af651939c6d92541 | https://github.com/go-chassis/go-archaius/blob/5b479bcb10437daee44d1d77af651939c6d92541/configurationfactory.go#L231-L245 |
5,241 | go-chassis/go-archaius | configurationfactory.go | GetValueByDI | func (arc *ConfigFactory) GetValueByDI(dimensionInfo, key string) cast.Value {
if arc.initSuccess == false {
return nil
}
var confValue cast.Value
val := arc.GetConfigurationByKeyAndDimensionInfo(dimensionInfo, key)
if val == nil {
confValue = cast.NewValue(nil, errors.New("key does not exist"))
} else {
confValue = cast.NewValue(val, nil)
}
return confValue
} | go | func (arc *ConfigFactory) GetValueByDI(dimensionInfo, key string) cast.Value {
if arc.initSuccess == false {
return nil
}
var confValue cast.Value
val := arc.GetConfigurationByKeyAndDimensionInfo(dimensionInfo, key)
if val == nil {
confValue = cast.NewValue(nil, errors.New("key does not exist"))
} else {
confValue = cast.NewValue(val, nil)
}
return confValue
} | [
"func",
"(",
"arc",
"*",
"ConfigFactory",
")",
"GetValueByDI",
"(",
"dimensionInfo",
",",
"key",
"string",
")",
"cast",
".",
"Value",
"{",
"if",
"arc",
".",
"initSuccess",
"==",
"false",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"var",
"confValue",
"cast"... | // GetValueByDI an abstraction to return key's value in respective type based on dimension info which is provided by user | [
"GetValueByDI",
"an",
"abstraction",
"to",
"return",
"key",
"s",
"value",
"in",
"respective",
"type",
"based",
"on",
"dimension",
"info",
"which",
"is",
"provided",
"by",
"user"
] | 5b479bcb10437daee44d1d77af651939c6d92541 | https://github.com/go-chassis/go-archaius/blob/5b479bcb10437daee44d1d77af651939c6d92541/configurationfactory.go#L248-L262 |
5,242 | go-chassis/go-archaius | configurationfactory.go | Refresh | func (arc *ConfigFactory) Refresh(name string) error {
return arc.configMgr.Refresh(name)
} | go | func (arc *ConfigFactory) Refresh(name string) error {
return arc.configMgr.Refresh(name)
} | [
"func",
"(",
"arc",
"*",
"ConfigFactory",
")",
"Refresh",
"(",
"name",
"string",
")",
"error",
"{",
"return",
"arc",
".",
"configMgr",
".",
"Refresh",
"(",
"name",
")",
"\n",
"}"
] | //Refresh pull config from source and update configuration map | [
"Refresh",
"pull",
"config",
"from",
"source",
"and",
"update",
"configuration",
"map"
] | 5b479bcb10437daee44d1d77af651939c6d92541 | https://github.com/go-chassis/go-archaius/blob/5b479bcb10437daee44d1d77af651939c6d92541/configurationfactory.go#L265-L267 |
5,243 | go-chassis/go-archaius | sources/memory-source/memorysource.go | NewMemoryConfigurationSource | func NewMemoryConfigurationSource() MemorySource {
memoryConfigSource := new(MemoryConfigurationSource)
memoryConfigSource.priority = memoryVariableSourcePriority
memoryConfigSource.Configurations = make(map[string]interface{})
memoryConfigSource.CallbackCheck = make(chan bool)
return memoryConfigSource
} | go | func NewMemoryConfigurationSource() MemorySource {
memoryConfigSource := new(MemoryConfigurationSource)
memoryConfigSource.priority = memoryVariableSourcePriority
memoryConfigSource.Configurations = make(map[string]interface{})
memoryConfigSource.CallbackCheck = make(chan bool)
return memoryConfigSource
} | [
"func",
"NewMemoryConfigurationSource",
"(",
")",
"MemorySource",
"{",
"memoryConfigSource",
":=",
"new",
"(",
"MemoryConfigurationSource",
")",
"\n",
"memoryConfigSource",
".",
"priority",
"=",
"memoryVariableSourcePriority",
"\n",
"memoryConfigSource",
".",
"Configuration... | //NewMemoryConfigurationSource initializes all necessary components for memory configuration | [
"NewMemoryConfigurationSource",
"initializes",
"all",
"necessary",
"components",
"for",
"memory",
"configuration"
] | 5b479bcb10437daee44d1d77af651939c6d92541 | https://github.com/go-chassis/go-archaius/blob/5b479bcb10437daee44d1d77af651939c6d92541/sources/memory-source/memorysource.go#L54-L60 |
5,244 | go-chassis/go-archaius | sources/memory-source/memorysource.go | DynamicConfigHandler | func (confSrc *MemoryConfigurationSource) DynamicConfigHandler(callback core.DynamicConfigCallback) error {
confSrc.callback = callback
openlogging.Info("mem source callback prepared")
confSrc.CallbackCheck <- true
return nil
} | go | func (confSrc *MemoryConfigurationSource) DynamicConfigHandler(callback core.DynamicConfigCallback) error {
confSrc.callback = callback
openlogging.Info("mem source callback prepared")
confSrc.CallbackCheck <- true
return nil
} | [
"func",
"(",
"confSrc",
"*",
"MemoryConfigurationSource",
")",
"DynamicConfigHandler",
"(",
"callback",
"core",
".",
"DynamicConfigCallback",
")",
"error",
"{",
"confSrc",
".",
"callback",
"=",
"callback",
"\n",
"openlogging",
".",
"Info",
"(",
"\"",
"\"",
")",
... | //DynamicConfigHandler dynamically handles a memory configuration | [
"DynamicConfigHandler",
"dynamically",
"handles",
"a",
"memory",
"configuration"
] | 5b479bcb10437daee44d1d77af651939c6d92541 | https://github.com/go-chassis/go-archaius/blob/5b479bcb10437daee44d1d77af651939c6d92541/sources/memory-source/memorysource.go#L103-L108 |
5,245 | go-chassis/go-archaius | sources/memory-source/memorysource.go | AddKeyValue | func (confSrc *MemoryConfigurationSource) AddKeyValue(key string, value interface{}) error {
if !confSrc.ChanStatus {
<-confSrc.CallbackCheck
confSrc.ChanStatus = true
}
event := new(core.Event)
event.EventSource = confSrc.GetSourceName()
event.Key = key
event.Value = value
confSrc.Lock()
defer confSrc.Unlock()
if _, ok := confSrc.Configurations[key]; !ok {
event.EventType = core.Create
} else {
event.EventType = core.Update
}
confSrc.Configurations[key] = value
if confSrc.callback != nil {
confSrc.callback.OnEvent(event)
}
return nil
} | go | func (confSrc *MemoryConfigurationSource) AddKeyValue(key string, value interface{}) error {
if !confSrc.ChanStatus {
<-confSrc.CallbackCheck
confSrc.ChanStatus = true
}
event := new(core.Event)
event.EventSource = confSrc.GetSourceName()
event.Key = key
event.Value = value
confSrc.Lock()
defer confSrc.Unlock()
if _, ok := confSrc.Configurations[key]; !ok {
event.EventType = core.Create
} else {
event.EventType = core.Update
}
confSrc.Configurations[key] = value
if confSrc.callback != nil {
confSrc.callback.OnEvent(event)
}
return nil
} | [
"func",
"(",
"confSrc",
"*",
"MemoryConfigurationSource",
")",
"AddKeyValue",
"(",
"key",
"string",
",",
"value",
"interface",
"{",
"}",
")",
"error",
"{",
"if",
"!",
"confSrc",
".",
"ChanStatus",
"{",
"<-",
"confSrc",
".",
"CallbackCheck",
"\n",
"confSrc",
... | //AddKeyValue creates new configuration for corresponding key and value pair | [
"AddKeyValue",
"creates",
"new",
"configuration",
"for",
"corresponding",
"key",
"and",
"value",
"pair"
] | 5b479bcb10437daee44d1d77af651939c6d92541 | https://github.com/go-chassis/go-archaius/blob/5b479bcb10437daee44d1d77af651939c6d92541/sources/memory-source/memorysource.go#L111-L137 |
5,246 | go-chassis/go-archaius | sources/configcenter/configcentersource.go | NewConfigCenterSource | func NewConfigCenterSource(cc config.Client, dimInfo string,
refreshMode, refreshInterval int) core.ConfigSource {
if ConfigCenterConfig == nil {
ConfigCenterConfig = new(Handler)
ConfigCenterConfig.priority = configCenterSourcePriority
ConfigCenterConfig.cc = cc
ConfigCenterConfig.dimensionsInfo = dimInfo
ConfigCenterConfig.initSuccess = true
ConfigCenterConfig.RefreshMode = refreshMode
ConfigCenterConfig.RefreshInterval = time.Second * time.Duration(refreshInterval)
}
return ConfigCenterConfig
} | go | func NewConfigCenterSource(cc config.Client, dimInfo string,
refreshMode, refreshInterval int) core.ConfigSource {
if ConfigCenterConfig == nil {
ConfigCenterConfig = new(Handler)
ConfigCenterConfig.priority = configCenterSourcePriority
ConfigCenterConfig.cc = cc
ConfigCenterConfig.dimensionsInfo = dimInfo
ConfigCenterConfig.initSuccess = true
ConfigCenterConfig.RefreshMode = refreshMode
ConfigCenterConfig.RefreshInterval = time.Second * time.Duration(refreshInterval)
}
return ConfigCenterConfig
} | [
"func",
"NewConfigCenterSource",
"(",
"cc",
"config",
".",
"Client",
",",
"dimInfo",
"string",
",",
"refreshMode",
",",
"refreshInterval",
"int",
")",
"core",
".",
"ConfigSource",
"{",
"if",
"ConfigCenterConfig",
"==",
"nil",
"{",
"ConfigCenterConfig",
"=",
"new... | //NewConfigCenterSource initializes all components of configuration center | [
"NewConfigCenterSource",
"initializes",
"all",
"components",
"of",
"configuration",
"center"
] | 5b479bcb10437daee44d1d77af651939c6d92541 | https://github.com/go-chassis/go-archaius/blob/5b479bcb10437daee44d1d77af651939c6d92541/sources/configcenter/configcentersource.go#L72-L86 |
5,247 | go-chassis/go-archaius | sources/configcenter/configcentersource.go | GetConfigurations | func (cfgSrcHandler *Handler) GetConfigurations() (map[string]interface{}, error) {
configMap := make(map[string]interface{})
err := cfgSrcHandler.refreshConfigurations("")
if err != nil {
return nil, err
}
if cfgSrcHandler.RefreshMode == 1 {
go cfgSrcHandler.refreshConfigurationsPeriodically("")
}
cfgSrcHandler.Lock()
for key, value := range cfgSrcHandler.Configurations {
configMap[key] = value
}
cfgSrcHandler.Unlock()
return configMap, nil
} | go | func (cfgSrcHandler *Handler) GetConfigurations() (map[string]interface{}, error) {
configMap := make(map[string]interface{})
err := cfgSrcHandler.refreshConfigurations("")
if err != nil {
return nil, err
}
if cfgSrcHandler.RefreshMode == 1 {
go cfgSrcHandler.refreshConfigurationsPeriodically("")
}
cfgSrcHandler.Lock()
for key, value := range cfgSrcHandler.Configurations {
configMap[key] = value
}
cfgSrcHandler.Unlock()
return configMap, nil
} | [
"func",
"(",
"cfgSrcHandler",
"*",
"Handler",
")",
"GetConfigurations",
"(",
")",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
",",
"error",
")",
"{",
"configMap",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"\... | //GetConfigurations gets a particular configuration | [
"GetConfigurations",
"gets",
"a",
"particular",
"configuration"
] | 5b479bcb10437daee44d1d77af651939c6d92541 | https://github.com/go-chassis/go-archaius/blob/5b479bcb10437daee44d1d77af651939c6d92541/sources/configcenter/configcentersource.go#L95-L112 |
5,248 | go-chassis/go-archaius | sources/configcenter/configcentersource.go | GetConfigurationsByDI | func (cfgSrcHandler *Handler) GetConfigurationsByDI(dimensionInfo string) (map[string]interface{}, error) {
configMap := make(map[string]interface{})
err := cfgSrcHandler.refreshConfigurations(dimensionInfo)
if err != nil {
return nil, err
}
if cfgSrcHandler.RefreshMode == 1 {
go cfgSrcHandler.refreshConfigurationsPeriodically(dimensionInfo)
}
cfgSrcHandler.Lock()
for key, value := range cfgSrcHandler.dimensionsInfoConfiguration {
configMap[key] = value
}
cfgSrcHandler.Unlock()
return configMap, nil
} | go | func (cfgSrcHandler *Handler) GetConfigurationsByDI(dimensionInfo string) (map[string]interface{}, error) {
configMap := make(map[string]interface{})
err := cfgSrcHandler.refreshConfigurations(dimensionInfo)
if err != nil {
return nil, err
}
if cfgSrcHandler.RefreshMode == 1 {
go cfgSrcHandler.refreshConfigurationsPeriodically(dimensionInfo)
}
cfgSrcHandler.Lock()
for key, value := range cfgSrcHandler.dimensionsInfoConfiguration {
configMap[key] = value
}
cfgSrcHandler.Unlock()
return configMap, nil
} | [
"func",
"(",
"cfgSrcHandler",
"*",
"Handler",
")",
"GetConfigurationsByDI",
"(",
"dimensionInfo",
"string",
")",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
",",
"error",
")",
"{",
"configMap",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"in... | //GetConfigurationsByDI gets required configurations for particular dimension info | [
"GetConfigurationsByDI",
"gets",
"required",
"configurations",
"for",
"particular",
"dimension",
"info"
] | 5b479bcb10437daee44d1d77af651939c6d92541 | https://github.com/go-chassis/go-archaius/blob/5b479bcb10437daee44d1d77af651939c6d92541/sources/configcenter/configcentersource.go#L115-L133 |
5,249 | go-chassis/go-archaius | sources/configcenter/configcentersource.go | GetConfigurationByKeyAndDimensionInfo | func (cfgSrcHandler *Handler) GetConfigurationByKeyAndDimensionInfo(key, dimensionInfo string) (interface{}, error) {
var (
configSrcVal interface{}
actualValue interface{}
exist bool
)
cfgSrcHandler.Lock()
for _, v := range cfgSrcHandler.dimensionsInfoConfigurations {
value, ok := v[dimensionInfo]
if ok {
actualValue, exist = value[key]
}
}
cfgSrcHandler.Unlock()
if exist {
configSrcVal = actualValue
return configSrcVal, nil
}
return nil, errors.New("key not exist")
} | go | func (cfgSrcHandler *Handler) GetConfigurationByKeyAndDimensionInfo(key, dimensionInfo string) (interface{}, error) {
var (
configSrcVal interface{}
actualValue interface{}
exist bool
)
cfgSrcHandler.Lock()
for _, v := range cfgSrcHandler.dimensionsInfoConfigurations {
value, ok := v[dimensionInfo]
if ok {
actualValue, exist = value[key]
}
}
cfgSrcHandler.Unlock()
if exist {
configSrcVal = actualValue
return configSrcVal, nil
}
return nil, errors.New("key not exist")
} | [
"func",
"(",
"cfgSrcHandler",
"*",
"Handler",
")",
"GetConfigurationByKeyAndDimensionInfo",
"(",
"key",
",",
"dimensionInfo",
"string",
")",
"(",
"interface",
"{",
"}",
",",
"error",
")",
"{",
"var",
"(",
"configSrcVal",
"interface",
"{",
"}",
"\n",
"actualVal... | //GetConfigurationByKeyAndDimensionInfo gets required configuration for a particular key and dimension pair | [
"GetConfigurationByKeyAndDimensionInfo",
"gets",
"required",
"configuration",
"for",
"a",
"particular",
"key",
"and",
"dimension",
"pair"
] | 5b479bcb10437daee44d1d77af651939c6d92541 | https://github.com/go-chassis/go-archaius/blob/5b479bcb10437daee44d1d77af651939c6d92541/sources/configcenter/configcentersource.go#L253-L275 |
5,250 | go-chassis/go-archaius | sources/configcenter/configcentersource.go | AddDimensionInfo | func (cfgSrcHandler *Handler) AddDimensionInfo(dimensionInfo string) (map[string]string, error) {
if len(cfgSrcHandler.dimensionInfoMap) == 0 {
cfgSrcHandler.dimensionInfoMap = make(map[string]string)
}
for i := range cfgSrcHandler.dimensionInfoMap {
if i == dimensionInfo {
openlogging.GetLogger().Errorf("dimension info already exist")
return cfgSrcHandler.dimensionInfoMap, errors.New("dimension info allready exist")
}
}
cfgSrcHandler.dimensionInfoMap[dimensionInfo] = dimensionInfo
return cfgSrcHandler.dimensionInfoMap, nil
} | go | func (cfgSrcHandler *Handler) AddDimensionInfo(dimensionInfo string) (map[string]string, error) {
if len(cfgSrcHandler.dimensionInfoMap) == 0 {
cfgSrcHandler.dimensionInfoMap = make(map[string]string)
}
for i := range cfgSrcHandler.dimensionInfoMap {
if i == dimensionInfo {
openlogging.GetLogger().Errorf("dimension info already exist")
return cfgSrcHandler.dimensionInfoMap, errors.New("dimension info allready exist")
}
}
cfgSrcHandler.dimensionInfoMap[dimensionInfo] = dimensionInfo
return cfgSrcHandler.dimensionInfoMap, nil
} | [
"func",
"(",
"cfgSrcHandler",
"*",
"Handler",
")",
"AddDimensionInfo",
"(",
"dimensionInfo",
"string",
")",
"(",
"map",
"[",
"string",
"]",
"string",
",",
"error",
")",
"{",
"if",
"len",
"(",
"cfgSrcHandler",
".",
"dimensionInfoMap",
")",
"==",
"0",
"{",
... | //AddDimensionInfo adds dimension info for a configuration | [
"AddDimensionInfo",
"adds",
"dimension",
"info",
"for",
"a",
"configuration"
] | 5b479bcb10437daee44d1d77af651939c6d92541 | https://github.com/go-chassis/go-archaius/blob/5b479bcb10437daee44d1d77af651939c6d92541/sources/configcenter/configcentersource.go#L278-L293 |
5,251 | go-chassis/go-archaius | sources/configcenter/configcentersource.go | DynamicConfigHandler | func (cfgSrcHandler *Handler) DynamicConfigHandler(callback core.DynamicConfigCallback) error {
if cfgSrcHandler.initSuccess != true {
return errors.New("config center source initialization failed")
}
dynCfgHandler, err := newDynConfigHandlerSource(cfgSrcHandler, callback)
if err != nil {
openlogging.GetLogger().Error("failed to initialize dynamic config center Handler:" + err.Error())
return errors.New("failed to initialize dynamic config center Handler")
}
cfgSrcHandler.dynamicConfigHandler = dynCfgHandler
if cfgSrcHandler.RefreshMode == 0 {
// Pull All the configuration for the first time.
cfgSrcHandler.refreshConfigurations("")
//Start a web socket connection to recieve change events.
dynCfgHandler.startDynamicConfigHandler()
}
return nil
} | go | func (cfgSrcHandler *Handler) DynamicConfigHandler(callback core.DynamicConfigCallback) error {
if cfgSrcHandler.initSuccess != true {
return errors.New("config center source initialization failed")
}
dynCfgHandler, err := newDynConfigHandlerSource(cfgSrcHandler, callback)
if err != nil {
openlogging.GetLogger().Error("failed to initialize dynamic config center Handler:" + err.Error())
return errors.New("failed to initialize dynamic config center Handler")
}
cfgSrcHandler.dynamicConfigHandler = dynCfgHandler
if cfgSrcHandler.RefreshMode == 0 {
// Pull All the configuration for the first time.
cfgSrcHandler.refreshConfigurations("")
//Start a web socket connection to recieve change events.
dynCfgHandler.startDynamicConfigHandler()
}
return nil
} | [
"func",
"(",
"cfgSrcHandler",
"*",
"Handler",
")",
"DynamicConfigHandler",
"(",
"callback",
"core",
".",
"DynamicConfigCallback",
")",
"error",
"{",
"if",
"cfgSrcHandler",
".",
"initSuccess",
"!=",
"true",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
... | //DynamicConfigHandler dynamically handles a configuration | [
"DynamicConfigHandler",
"dynamically",
"handles",
"a",
"configuration"
] | 5b479bcb10437daee44d1d77af651939c6d92541 | https://github.com/go-chassis/go-archaius/blob/5b479bcb10437daee44d1d77af651939c6d92541/sources/configcenter/configcentersource.go#L311-L331 |
5,252 | go-chassis/go-archaius | sources/configcenter/configcentersource.go | Cleanup | func (cfgSrcHandler *Handler) Cleanup() error {
cfgSrcHandler.connsLock.Lock()
defer cfgSrcHandler.connsLock.Unlock()
if cfgSrcHandler.dynamicConfigHandler != nil {
cfgSrcHandler.dynamicConfigHandler.Cleanup()
}
cfgSrcHandler.dynamicConfigHandler = nil
cfgSrcHandler.Configurations = nil
return nil
} | go | func (cfgSrcHandler *Handler) Cleanup() error {
cfgSrcHandler.connsLock.Lock()
defer cfgSrcHandler.connsLock.Unlock()
if cfgSrcHandler.dynamicConfigHandler != nil {
cfgSrcHandler.dynamicConfigHandler.Cleanup()
}
cfgSrcHandler.dynamicConfigHandler = nil
cfgSrcHandler.Configurations = nil
return nil
} | [
"func",
"(",
"cfgSrcHandler",
"*",
"Handler",
")",
"Cleanup",
"(",
")",
"error",
"{",
"cfgSrcHandler",
".",
"connsLock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"cfgSrcHandler",
".",
"connsLock",
".",
"Unlock",
"(",
")",
"\n\n",
"if",
"cfgSrcHandler",
".",
... | //Cleanup cleans the particular configuration up | [
"Cleanup",
"cleans",
"the",
"particular",
"configuration",
"up"
] | 5b479bcb10437daee44d1d77af651939c6d92541 | https://github.com/go-chassis/go-archaius/blob/5b479bcb10437daee44d1d77af651939c6d92541/sources/configcenter/configcentersource.go#L334-L346 |
5,253 | shogo82148/androidbinary | table.go | ParseResID | func ParseResID(s string) (ResID, error) {
if !IsResID(s) {
return 0, fmt.Errorf("androidbinary: %s is not ResID", s)
}
id, err := strconv.ParseUint(s[3:], 16, 32)
if err != nil {
return 0, err
}
return ResID(id), nil
} | go | func ParseResID(s string) (ResID, error) {
if !IsResID(s) {
return 0, fmt.Errorf("androidbinary: %s is not ResID", s)
}
id, err := strconv.ParseUint(s[3:], 16, 32)
if err != nil {
return 0, err
}
return ResID(id), nil
} | [
"func",
"ParseResID",
"(",
"s",
"string",
")",
"(",
"ResID",
",",
"error",
")",
"{",
"if",
"!",
"IsResID",
"(",
"s",
")",
"{",
"return",
"0",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"s",
")",
"\n",
"}",
"\n",
"id",
",",
"err",
":=",
... | // ParseResID parses ResId. | [
"ParseResID",
"parses",
"ResId",
"."
] | 6d4ec43b2255c1fd76350d5833fd286d28f8d350 | https://github.com/shogo82148/androidbinary/blob/6d4ec43b2255c1fd76350d5833fd286d28f8d350/table.go#L192-L201 |
5,254 | shogo82148/androidbinary | table.go | NewTableFile | func NewTableFile(r io.ReaderAt) (*TableFile, error) {
f := new(TableFile)
sr := io.NewSectionReader(r, 0, 1<<63-1)
header := new(ResTableHeader)
binary.Read(sr, binary.LittleEndian, header)
f.tablePackages = make(map[uint32]*TablePackage)
offset := int64(header.Header.HeaderSize)
for offset < int64(header.Header.Size) {
chunkHeader, err := f.readChunk(sr, offset)
if err != nil {
return nil, err
}
offset += int64(chunkHeader.Size)
}
return f, nil
} | go | func NewTableFile(r io.ReaderAt) (*TableFile, error) {
f := new(TableFile)
sr := io.NewSectionReader(r, 0, 1<<63-1)
header := new(ResTableHeader)
binary.Read(sr, binary.LittleEndian, header)
f.tablePackages = make(map[uint32]*TablePackage)
offset := int64(header.Header.HeaderSize)
for offset < int64(header.Header.Size) {
chunkHeader, err := f.readChunk(sr, offset)
if err != nil {
return nil, err
}
offset += int64(chunkHeader.Size)
}
return f, nil
} | [
"func",
"NewTableFile",
"(",
"r",
"io",
".",
"ReaderAt",
")",
"(",
"*",
"TableFile",
",",
"error",
")",
"{",
"f",
":=",
"new",
"(",
"TableFile",
")",
"\n",
"sr",
":=",
"io",
".",
"NewSectionReader",
"(",
"r",
",",
"0",
",",
"1",
"<<",
"63",
"-",
... | // NewTableFile returns new TableFile. | [
"NewTableFile",
"returns",
"new",
"TableFile",
"."
] | 6d4ec43b2255c1fd76350d5833fd286d28f8d350 | https://github.com/shogo82148/androidbinary/blob/6d4ec43b2255c1fd76350d5833fd286d28f8d350/table.go#L223-L240 |
5,255 | shogo82148/androidbinary | table.go | GetResource | func (f *TableFile) GetResource(id ResID, config *ResTableConfig) (interface{}, error) {
p := f.findPackage(id.Package())
if p == nil {
return nil, fmt.Errorf("androidbinary: package 0x%02X not found", id.Package())
}
e := p.findEntry(id.Type(), id.Entry(), config)
v := e.Value
if v == nil {
return nil, fmt.Errorf("androidbinary: entry 0x%04X not found", id.Entry())
}
switch v.DataType {
case TypeNull:
return nil, nil
case TypeString:
return f.GetString(ResStringPoolRef(v.Data)), nil
case TypeIntDec:
return v.Data, nil
case TypeIntHex:
return v.Data, nil
case TypeIntBoolean:
return v.Data != 0, nil
}
return v.Data, nil
} | go | func (f *TableFile) GetResource(id ResID, config *ResTableConfig) (interface{}, error) {
p := f.findPackage(id.Package())
if p == nil {
return nil, fmt.Errorf("androidbinary: package 0x%02X not found", id.Package())
}
e := p.findEntry(id.Type(), id.Entry(), config)
v := e.Value
if v == nil {
return nil, fmt.Errorf("androidbinary: entry 0x%04X not found", id.Entry())
}
switch v.DataType {
case TypeNull:
return nil, nil
case TypeString:
return f.GetString(ResStringPoolRef(v.Data)), nil
case TypeIntDec:
return v.Data, nil
case TypeIntHex:
return v.Data, nil
case TypeIntBoolean:
return v.Data != 0, nil
}
return v.Data, nil
} | [
"func",
"(",
"f",
"*",
"TableFile",
")",
"GetResource",
"(",
"id",
"ResID",
",",
"config",
"*",
"ResTableConfig",
")",
"(",
"interface",
"{",
"}",
",",
"error",
")",
"{",
"p",
":=",
"f",
".",
"findPackage",
"(",
"id",
".",
"Package",
"(",
")",
")",... | // GetResource returns a resrouce referenced by id. | [
"GetResource",
"returns",
"a",
"resrouce",
"referenced",
"by",
"id",
"."
] | 6d4ec43b2255c1fd76350d5833fd286d28f8d350 | https://github.com/shogo82148/androidbinary/blob/6d4ec43b2255c1fd76350d5833fd286d28f8d350/table.go#L272-L295 |
5,256 | shogo82148/androidbinary | table.go | IsLocaleMoreSpecificThan | func (c *ResTableConfig) IsLocaleMoreSpecificThan(o *ResTableConfig) int {
if (c.Language != [2]uint8{} || c.Country != [2]uint8{}) || (o.Language != [2]uint8{} || o.Country != [2]uint8{}) {
if c.Language != o.Language {
if c.Language == [2]uint8{} {
return -1
}
if o.Language == [2]uint8{} {
return 1
}
}
if c.Country != o.Country {
if c.Country == [2]uint8{} {
return -1
}
if o.Country == [2]uint8{} {
return 1
}
}
}
return 0
} | go | func (c *ResTableConfig) IsLocaleMoreSpecificThan(o *ResTableConfig) int {
if (c.Language != [2]uint8{} || c.Country != [2]uint8{}) || (o.Language != [2]uint8{} || o.Country != [2]uint8{}) {
if c.Language != o.Language {
if c.Language == [2]uint8{} {
return -1
}
if o.Language == [2]uint8{} {
return 1
}
}
if c.Country != o.Country {
if c.Country == [2]uint8{} {
return -1
}
if o.Country == [2]uint8{} {
return 1
}
}
}
return 0
} | [
"func",
"(",
"c",
"*",
"ResTableConfig",
")",
"IsLocaleMoreSpecificThan",
"(",
"o",
"*",
"ResTableConfig",
")",
"int",
"{",
"if",
"(",
"c",
".",
"Language",
"!=",
"[",
"2",
"]",
"uint8",
"{",
"}",
"||",
"c",
".",
"Country",
"!=",
"[",
"2",
"]",
"ui... | // IsLocaleMoreSpecificThan a positive integer if this config is more specific than o,
// a negative integer if |o| is more specific
// and 0 if they're equally specific. | [
"IsLocaleMoreSpecificThan",
"a",
"positive",
"integer",
"if",
"this",
"config",
"is",
"more",
"specific",
"than",
"o",
"a",
"negative",
"integer",
"if",
"|o|",
"is",
"more",
"specific",
"and",
"0",
"if",
"they",
"re",
"equally",
"specific",
"."
] | 6d4ec43b2255c1fd76350d5833fd286d28f8d350 | https://github.com/shogo82148/androidbinary/blob/6d4ec43b2255c1fd76350d5833fd286d28f8d350/table.go#L879-L900 |
5,257 | shogo82148/androidbinary | table.go | IsLocaleBetterThan | func (c *ResTableConfig) IsLocaleBetterThan(o *ResTableConfig, r *ResTableConfig) bool {
if r.Language == [2]uint8{} && r.Country == [2]uint8{} {
// The request doesn't have a locale, so no resource is better
// than the other.
return false
}
if c.Language == [2]uint8{} && c.Country == [2]uint8{} && o.Language == [2]uint8{} && o.Country == [2]uint8{} {
// The locales parts of both resources are empty, so no one is better
// than the other.
return false
}
if c.Language != o.Language {
// The languages of the two resources are not the same.
// the US English resource have traditionally lived for most apps.
if r.Language == [2]uint8{'e', 'n'} {
if r.Country == [2]uint8{'U', 'S'} {
if c.Language != [2]uint8{} {
return c.Country == [2]uint8{} || c.Country == [2]uint8{'U', 'S'}
}
return !(c.Country == [2]uint8{} || c.Country == [2]uint8{'U', 'S'})
}
}
return c.Language != [2]uint8{}
}
if c.Country != o.Country {
return c.Country != [2]uint8{}
}
return false
} | go | func (c *ResTableConfig) IsLocaleBetterThan(o *ResTableConfig, r *ResTableConfig) bool {
if r.Language == [2]uint8{} && r.Country == [2]uint8{} {
// The request doesn't have a locale, so no resource is better
// than the other.
return false
}
if c.Language == [2]uint8{} && c.Country == [2]uint8{} && o.Language == [2]uint8{} && o.Country == [2]uint8{} {
// The locales parts of both resources are empty, so no one is better
// than the other.
return false
}
if c.Language != o.Language {
// The languages of the two resources are not the same.
// the US English resource have traditionally lived for most apps.
if r.Language == [2]uint8{'e', 'n'} {
if r.Country == [2]uint8{'U', 'S'} {
if c.Language != [2]uint8{} {
return c.Country == [2]uint8{} || c.Country == [2]uint8{'U', 'S'}
}
return !(c.Country == [2]uint8{} || c.Country == [2]uint8{'U', 'S'})
}
}
return c.Language != [2]uint8{}
}
if c.Country != o.Country {
return c.Country != [2]uint8{}
}
return false
} | [
"func",
"(",
"c",
"*",
"ResTableConfig",
")",
"IsLocaleBetterThan",
"(",
"o",
"*",
"ResTableConfig",
",",
"r",
"*",
"ResTableConfig",
")",
"bool",
"{",
"if",
"r",
".",
"Language",
"==",
"[",
"2",
"]",
"uint8",
"{",
"}",
"&&",
"r",
".",
"Country",
"==... | // IsLocaleBetterThan returns true if c is a better locale match than o for the r configuration. | [
"IsLocaleBetterThan",
"returns",
"true",
"if",
"c",
"is",
"a",
"better",
"locale",
"match",
"than",
"o",
"for",
"the",
"r",
"configuration",
"."
] | 6d4ec43b2255c1fd76350d5833fd286d28f8d350 | https://github.com/shogo82148/androidbinary/blob/6d4ec43b2255c1fd76350d5833fd286d28f8d350/table.go#L903-L936 |
5,258 | shogo82148/androidbinary | table.go | Locale | func (c *ResTableConfig) Locale() string {
if c.Language[0] == 0 {
return ""
}
if c.Country[0] == 0 {
return fmt.Sprintf("%c%c", c.Language[0], c.Language[1])
}
return fmt.Sprintf("%c%c-%c%c", c.Language[0], c.Language[1], c.Country[0], c.Country[1])
} | go | func (c *ResTableConfig) Locale() string {
if c.Language[0] == 0 {
return ""
}
if c.Country[0] == 0 {
return fmt.Sprintf("%c%c", c.Language[0], c.Language[1])
}
return fmt.Sprintf("%c%c-%c%c", c.Language[0], c.Language[1], c.Country[0], c.Country[1])
} | [
"func",
"(",
"c",
"*",
"ResTableConfig",
")",
"Locale",
"(",
")",
"string",
"{",
"if",
"c",
".",
"Language",
"[",
"0",
"]",
"==",
"0",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n",
"if",
"c",
".",
"Country",
"[",
"0",
"]",
"==",
"0",
"{",
"retu... | // Locale returns the locale of the configuration. | [
"Locale",
"returns",
"the",
"locale",
"of",
"the",
"configuration",
"."
] | 6d4ec43b2255c1fd76350d5833fd286d28f8d350 | https://github.com/shogo82148/androidbinary/blob/6d4ec43b2255c1fd76350d5833fd286d28f8d350/table.go#L1085-L1093 |
5,259 | shogo82148/androidbinary | xml.go | NewXMLFile | func NewXMLFile(r io.ReaderAt) (*XMLFile, error) {
f := new(XMLFile)
sr := io.NewSectionReader(r, 0, 1<<63-1)
fmt.Fprintf(&f.xmlBuffer, xml.Header)
header := new(ResChunkHeader)
if err := binary.Read(sr, binary.LittleEndian, header); err != nil {
return nil, err
}
offset := int64(header.HeaderSize)
for offset < int64(header.Size) {
chunkHeader, err := f.readChunk(r, offset)
if err != nil {
return nil, err
}
offset += int64(chunkHeader.Size)
}
return f, nil
} | go | func NewXMLFile(r io.ReaderAt) (*XMLFile, error) {
f := new(XMLFile)
sr := io.NewSectionReader(r, 0, 1<<63-1)
fmt.Fprintf(&f.xmlBuffer, xml.Header)
header := new(ResChunkHeader)
if err := binary.Read(sr, binary.LittleEndian, header); err != nil {
return nil, err
}
offset := int64(header.HeaderSize)
for offset < int64(header.Size) {
chunkHeader, err := f.readChunk(r, offset)
if err != nil {
return nil, err
}
offset += int64(chunkHeader.Size)
}
return f, nil
} | [
"func",
"NewXMLFile",
"(",
"r",
"io",
".",
"ReaderAt",
")",
"(",
"*",
"XMLFile",
",",
"error",
")",
"{",
"f",
":=",
"new",
"(",
"XMLFile",
")",
"\n",
"sr",
":=",
"io",
".",
"NewSectionReader",
"(",
"r",
",",
"0",
",",
"1",
"<<",
"63",
"-",
"1",... | // NewXMLFile returns a new XMLFile. | [
"NewXMLFile",
"returns",
"a",
"new",
"XMLFile",
"."
] | 6d4ec43b2255c1fd76350d5833fd286d28f8d350 | https://github.com/shogo82148/androidbinary/blob/6d4ec43b2255c1fd76350d5833fd286d28f8d350/xml.go#L60-L79 |
5,260 | shogo82148/androidbinary | xml.go | Reader | func (f *XMLFile) Reader() *bytes.Reader {
return bytes.NewReader(f.xmlBuffer.Bytes())
} | go | func (f *XMLFile) Reader() *bytes.Reader {
return bytes.NewReader(f.xmlBuffer.Bytes())
} | [
"func",
"(",
"f",
"*",
"XMLFile",
")",
"Reader",
"(",
")",
"*",
"bytes",
".",
"Reader",
"{",
"return",
"bytes",
".",
"NewReader",
"(",
"f",
".",
"xmlBuffer",
".",
"Bytes",
"(",
")",
")",
"\n",
"}"
] | // Reader returns a reader of XML file expressed in text format. | [
"Reader",
"returns",
"a",
"reader",
"of",
"XML",
"file",
"expressed",
"in",
"text",
"format",
"."
] | 6d4ec43b2255c1fd76350d5833fd286d28f8d350 | https://github.com/shogo82148/androidbinary/blob/6d4ec43b2255c1fd76350d5833fd286d28f8d350/xml.go#L82-L84 |
5,261 | shogo82148/androidbinary | apk/apk.go | OpenFile | func OpenFile(filename string) (apk *Apk, err error) {
f, err := os.Open(filename)
if err != nil {
return nil, err
}
defer func() {
if err != nil {
f.Close()
}
}()
fi, err := f.Stat()
if err != nil {
return nil, err
}
apk, err = OpenZipReader(f, fi.Size())
if err != nil {
return nil, err
}
apk.f = f
return
} | go | func OpenFile(filename string) (apk *Apk, err error) {
f, err := os.Open(filename)
if err != nil {
return nil, err
}
defer func() {
if err != nil {
f.Close()
}
}()
fi, err := f.Stat()
if err != nil {
return nil, err
}
apk, err = OpenZipReader(f, fi.Size())
if err != nil {
return nil, err
}
apk.f = f
return
} | [
"func",
"OpenFile",
"(",
"filename",
"string",
")",
"(",
"apk",
"*",
"Apk",
",",
"err",
"error",
")",
"{",
"f",
",",
"err",
":=",
"os",
".",
"Open",
"(",
"filename",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"... | // OpenFile will open the file specified by filename and return Apk | [
"OpenFile",
"will",
"open",
"the",
"file",
"specified",
"by",
"filename",
"and",
"return",
"Apk"
] | 6d4ec43b2255c1fd76350d5833fd286d28f8d350 | https://github.com/shogo82148/androidbinary/blob/6d4ec43b2255c1fd76350d5833fd286d28f8d350/apk/apk.go#L30-L50 |
5,262 | shogo82148/androidbinary | apk/apk.go | OpenZipReader | func OpenZipReader(r io.ReaderAt, size int64) (*Apk, error) {
zipreader, err := zip.NewReader(r, size)
if err != nil {
return nil, err
}
apk := &Apk{
zipreader: zipreader,
}
if err = apk.parseManifest(); err != nil {
return nil, errors.Wrap(err, "parse-manifest")
}
if err = apk.parseResources(); err != nil {
return nil, err
}
return apk, nil
} | go | func OpenZipReader(r io.ReaderAt, size int64) (*Apk, error) {
zipreader, err := zip.NewReader(r, size)
if err != nil {
return nil, err
}
apk := &Apk{
zipreader: zipreader,
}
if err = apk.parseManifest(); err != nil {
return nil, errors.Wrap(err, "parse-manifest")
}
if err = apk.parseResources(); err != nil {
return nil, err
}
return apk, nil
} | [
"func",
"OpenZipReader",
"(",
"r",
"io",
".",
"ReaderAt",
",",
"size",
"int64",
")",
"(",
"*",
"Apk",
",",
"error",
")",
"{",
"zipreader",
",",
"err",
":=",
"zip",
".",
"NewReader",
"(",
"r",
",",
"size",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",... | // OpenZipReader has same arguments like zip.NewReader | [
"OpenZipReader",
"has",
"same",
"arguments",
"like",
"zip",
".",
"NewReader"
] | 6d4ec43b2255c1fd76350d5833fd286d28f8d350 | https://github.com/shogo82148/androidbinary/blob/6d4ec43b2255c1fd76350d5833fd286d28f8d350/apk/apk.go#L53-L68 |
5,263 | shogo82148/androidbinary | apk/apk.go | Close | func (k *Apk) Close() error {
if k.f == nil {
return nil
}
return k.f.Close()
} | go | func (k *Apk) Close() error {
if k.f == nil {
return nil
}
return k.f.Close()
} | [
"func",
"(",
"k",
"*",
"Apk",
")",
"Close",
"(",
")",
"error",
"{",
"if",
"k",
".",
"f",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"k",
".",
"f",
".",
"Close",
"(",
")",
"\n",
"}"
] | // Close is avaliable only if apk is created with OpenFile | [
"Close",
"is",
"avaliable",
"only",
"if",
"apk",
"is",
"created",
"with",
"OpenFile"
] | 6d4ec43b2255c1fd76350d5833fd286d28f8d350 | https://github.com/shogo82148/androidbinary/blob/6d4ec43b2255c1fd76350d5833fd286d28f8d350/apk/apk.go#L71-L76 |
5,264 | shogo82148/androidbinary | apk/apk.go | Icon | func (k *Apk) Icon(resConfig *androidbinary.ResTableConfig) (image.Image, error) {
iconPath := k.getResource(k.manifest.App.Icon, resConfig)
if androidbinary.IsResID(iconPath) {
return nil, errors.New("unable to convert icon-id to icon path")
}
imgData, err := k.readZipFile(iconPath)
if err != nil {
return nil, err
}
m, _, err := image.Decode(bytes.NewReader(imgData))
return m, err
} | go | func (k *Apk) Icon(resConfig *androidbinary.ResTableConfig) (image.Image, error) {
iconPath := k.getResource(k.manifest.App.Icon, resConfig)
if androidbinary.IsResID(iconPath) {
return nil, errors.New("unable to convert icon-id to icon path")
}
imgData, err := k.readZipFile(iconPath)
if err != nil {
return nil, err
}
m, _, err := image.Decode(bytes.NewReader(imgData))
return m, err
} | [
"func",
"(",
"k",
"*",
"Apk",
")",
"Icon",
"(",
"resConfig",
"*",
"androidbinary",
".",
"ResTableConfig",
")",
"(",
"image",
".",
"Image",
",",
"error",
")",
"{",
"iconPath",
":=",
"k",
".",
"getResource",
"(",
"k",
".",
"manifest",
".",
"App",
".",
... | // Icon returns the icon image of the APK. | [
"Icon",
"returns",
"the",
"icon",
"image",
"of",
"the",
"APK",
"."
] | 6d4ec43b2255c1fd76350d5833fd286d28f8d350 | https://github.com/shogo82148/androidbinary/blob/6d4ec43b2255c1fd76350d5833fd286d28f8d350/apk/apk.go#L79-L90 |
5,265 | shogo82148/androidbinary | apk/apk.go | Label | func (k *Apk) Label(resConfig *androidbinary.ResTableConfig) (s string, err error) {
s = k.getResource(k.manifest.App.Label, resConfig)
if androidbinary.IsResID(s) {
err = errors.New("unable to convert label-id to string")
}
return
} | go | func (k *Apk) Label(resConfig *androidbinary.ResTableConfig) (s string, err error) {
s = k.getResource(k.manifest.App.Label, resConfig)
if androidbinary.IsResID(s) {
err = errors.New("unable to convert label-id to string")
}
return
} | [
"func",
"(",
"k",
"*",
"Apk",
")",
"Label",
"(",
"resConfig",
"*",
"androidbinary",
".",
"ResTableConfig",
")",
"(",
"s",
"string",
",",
"err",
"error",
")",
"{",
"s",
"=",
"k",
".",
"getResource",
"(",
"k",
".",
"manifest",
".",
"App",
".",
"Label... | // Label returns the label of the APK. | [
"Label",
"returns",
"the",
"label",
"of",
"the",
"APK",
"."
] | 6d4ec43b2255c1fd76350d5833fd286d28f8d350 | https://github.com/shogo82148/androidbinary/blob/6d4ec43b2255c1fd76350d5833fd286d28f8d350/apk/apk.go#L93-L99 |
5,266 | shogo82148/androidbinary | apk/apk.go | MainActivity | func (k *Apk) MainActivity() (activity string, err error) {
for _, act := range k.manifest.App.Activities {
for _, intent := range act.IntentFilters {
if isMainIntentFilter(intent) {
return act.Name, nil
}
}
}
for _, act := range k.manifest.App.ActivityAliases {
for _, intent := range act.IntentFilters {
if isMainIntentFilter(intent) {
return act.TargetActivity, nil
}
}
}
return "", errors.New("No main activity found")
} | go | func (k *Apk) MainActivity() (activity string, err error) {
for _, act := range k.manifest.App.Activities {
for _, intent := range act.IntentFilters {
if isMainIntentFilter(intent) {
return act.Name, nil
}
}
}
for _, act := range k.manifest.App.ActivityAliases {
for _, intent := range act.IntentFilters {
if isMainIntentFilter(intent) {
return act.TargetActivity, nil
}
}
}
return "", errors.New("No main activity found")
} | [
"func",
"(",
"k",
"*",
"Apk",
")",
"MainActivity",
"(",
")",
"(",
"activity",
"string",
",",
"err",
"error",
")",
"{",
"for",
"_",
",",
"act",
":=",
"range",
"k",
".",
"manifest",
".",
"App",
".",
"Activities",
"{",
"for",
"_",
",",
"intent",
":=... | // MainActivity returns the name of the main activity. | [
"MainActivity",
"returns",
"the",
"name",
"of",
"the",
"main",
"activity",
"."
] | 6d4ec43b2255c1fd76350d5833fd286d28f8d350 | https://github.com/shogo82148/androidbinary/blob/6d4ec43b2255c1fd76350d5833fd286d28f8d350/apk/apk.go#L133-L150 |
5,267 | janekolszak/idp | idp.go | NewIDP | func NewIDP(config *IDPConfig) *IDP {
var idp = new(IDP)
idp.config = config
idp.cache = cache.New(config.KeyCacheExpiration, config.CacheCleanupInterval)
idp.cache.OnEvicted(func(key string, value interface{}) { idp.refreshCache(key) })
idp.createChallengeCookieOptions = new(sessions.Options)
idp.createChallengeCookieOptions.Path = "/"
idp.createChallengeCookieOptions.MaxAge = int(config.ChallengeExpiration.Seconds())
idp.createChallengeCookieOptions.Secure = true // Send only via https
idp.createChallengeCookieOptions.HttpOnly = false
idp.deleteChallengeCookieOptions = new(sessions.Options)
idp.deleteChallengeCookieOptions.Path = "/"
idp.deleteChallengeCookieOptions.MaxAge = -1 // Mark for deletion
idp.deleteChallengeCookieOptions.Secure = true // Send only via https
idp.deleteChallengeCookieOptions.HttpOnly = false
return idp
} | go | func NewIDP(config *IDPConfig) *IDP {
var idp = new(IDP)
idp.config = config
idp.cache = cache.New(config.KeyCacheExpiration, config.CacheCleanupInterval)
idp.cache.OnEvicted(func(key string, value interface{}) { idp.refreshCache(key) })
idp.createChallengeCookieOptions = new(sessions.Options)
idp.createChallengeCookieOptions.Path = "/"
idp.createChallengeCookieOptions.MaxAge = int(config.ChallengeExpiration.Seconds())
idp.createChallengeCookieOptions.Secure = true // Send only via https
idp.createChallengeCookieOptions.HttpOnly = false
idp.deleteChallengeCookieOptions = new(sessions.Options)
idp.deleteChallengeCookieOptions.Path = "/"
idp.deleteChallengeCookieOptions.MaxAge = -1 // Mark for deletion
idp.deleteChallengeCookieOptions.Secure = true // Send only via https
idp.deleteChallengeCookieOptions.HttpOnly = false
return idp
} | [
"func",
"NewIDP",
"(",
"config",
"*",
"IDPConfig",
")",
"*",
"IDP",
"{",
"var",
"idp",
"=",
"new",
"(",
"IDP",
")",
"\n",
"idp",
".",
"config",
"=",
"config",
"\n\n",
"idp",
".",
"cache",
"=",
"cache",
".",
"New",
"(",
"config",
".",
"KeyCacheExpir... | // Create the Identity Provider helper | [
"Create",
"the",
"Identity",
"Provider",
"helper"
] | a4ef1ea49381cd05f4fe96700d2399cd5a51ab1e | https://github.com/janekolszak/idp/blob/a4ef1ea49381cd05f4fe96700d2399cd5a51ab1e/idp.go#L75-L95 |
5,268 | janekolszak/idp | idp.go | refreshCache | func (idp *IDP) refreshCache(key string) {
switch key {
case VerifyPublicKey:
idp.cacheVerificationKey()
return
case ConsentPrivateKey:
idp.cacheConsentKey()
return
default:
// Will get here for client IDs.
// Fine to just let them expire, the next request from that
// client will trigger a refresh
return
}
} | go | func (idp *IDP) refreshCache(key string) {
switch key {
case VerifyPublicKey:
idp.cacheVerificationKey()
return
case ConsentPrivateKey:
idp.cacheConsentKey()
return
default:
// Will get here for client IDs.
// Fine to just let them expire, the next request from that
// client will trigger a refresh
return
}
} | [
"func",
"(",
"idp",
"*",
"IDP",
")",
"refreshCache",
"(",
"key",
"string",
")",
"{",
"switch",
"key",
"{",
"case",
"VerifyPublicKey",
":",
"idp",
".",
"cacheVerificationKey",
"(",
")",
"\n",
"return",
"\n\n",
"case",
"ConsentPrivateKey",
":",
"idp",
".",
... | // Called when any key expires | [
"Called",
"when",
"any",
"key",
"expires"
] | a4ef1ea49381cd05f4fe96700d2399cd5a51ab1e | https://github.com/janekolszak/idp/blob/a4ef1ea49381cd05f4fe96700d2399cd5a51ab1e/idp.go#L130-L146 |
5,269 | janekolszak/idp | idp.go | downloadVerificationKey | func (idp *IDP) downloadVerificationKey() (*rsa.PublicKey, error) {
jwk, err := idp.hc.JSONWebKeys.GetKey(hoauth2.ConsentChallengeKey, "public")
if err != nil {
return nil, err
}
rsaKey, ok := hjwk.First(jwk.Keys).Key.(*rsa.PublicKey)
if !ok {
return nil, ErrorBadPublicKey
}
return rsaKey, nil
} | go | func (idp *IDP) downloadVerificationKey() (*rsa.PublicKey, error) {
jwk, err := idp.hc.JSONWebKeys.GetKey(hoauth2.ConsentChallengeKey, "public")
if err != nil {
return nil, err
}
rsaKey, ok := hjwk.First(jwk.Keys).Key.(*rsa.PublicKey)
if !ok {
return nil, ErrorBadPublicKey
}
return rsaKey, nil
} | [
"func",
"(",
"idp",
"*",
"IDP",
")",
"downloadVerificationKey",
"(",
")",
"(",
"*",
"rsa",
".",
"PublicKey",
",",
"error",
")",
"{",
"jwk",
",",
"err",
":=",
"idp",
".",
"hc",
".",
"JSONWebKeys",
".",
"GetKey",
"(",
"hoauth2",
".",
"ConsentChallengeKey... | // Downloads the hydra's public key | [
"Downloads",
"the",
"hydra",
"s",
"public",
"key"
] | a4ef1ea49381cd05f4fe96700d2399cd5a51ab1e | https://github.com/janekolszak/idp/blob/a4ef1ea49381cd05f4fe96700d2399cd5a51ab1e/idp.go#L149-L162 |
5,270 | janekolszak/idp | idp.go | downloadConsentKey | func (idp *IDP) downloadConsentKey() (*rsa.PrivateKey, error) {
jwk, err := idp.hc.JSONWebKeys.GetKey(hoauth2.ConsentEndpointKey, "private")
if err != nil {
return nil, err
}
rsaKey, ok := hjwk.First(jwk.Keys).Key.(*rsa.PrivateKey)
if !ok {
return nil, ErrorBadPrivateKey
}
return rsaKey, nil
} | go | func (idp *IDP) downloadConsentKey() (*rsa.PrivateKey, error) {
jwk, err := idp.hc.JSONWebKeys.GetKey(hoauth2.ConsentEndpointKey, "private")
if err != nil {
return nil, err
}
rsaKey, ok := hjwk.First(jwk.Keys).Key.(*rsa.PrivateKey)
if !ok {
return nil, ErrorBadPrivateKey
}
return rsaKey, nil
} | [
"func",
"(",
"idp",
"*",
"IDP",
")",
"downloadConsentKey",
"(",
")",
"(",
"*",
"rsa",
".",
"PrivateKey",
",",
"error",
")",
"{",
"jwk",
",",
"err",
":=",
"idp",
".",
"hc",
".",
"JSONWebKeys",
".",
"GetKey",
"(",
"hoauth2",
".",
"ConsentEndpointKey",
... | // Downloads the private key used for signing the consent | [
"Downloads",
"the",
"private",
"key",
"used",
"for",
"signing",
"the",
"consent"
] | a4ef1ea49381cd05f4fe96700d2399cd5a51ab1e | https://github.com/janekolszak/idp/blob/a4ef1ea49381cd05f4fe96700d2399cd5a51ab1e/idp.go#L165-L177 |
5,271 | janekolszak/idp | idp.go | Connect | func (idp *IDP) Connect(verifyTLS bool) error {
var err error
if verifyTLS {
idp.hc, err = hydra.Connect(
hydra.ClientID(idp.config.ClientID),
hydra.ClientSecret(idp.config.ClientSecret),
hydra.ClusterURL(idp.config.ClusterURL),
)
} else {
idp.hc, err = hydra.Connect(
hydra.ClientID(idp.config.ClientID),
hydra.ClientSecret(idp.config.ClientSecret),
hydra.ClusterURL(idp.config.ClusterURL),
hydra.SkipTLSVerify(),
)
}
if err != nil {
return err
}
err = idp.cacheVerificationKey()
if err != nil {
return err
}
err = idp.cacheConsentKey()
if err != nil {
return err
}
return nil
} | go | func (idp *IDP) Connect(verifyTLS bool) error {
var err error
if verifyTLS {
idp.hc, err = hydra.Connect(
hydra.ClientID(idp.config.ClientID),
hydra.ClientSecret(idp.config.ClientSecret),
hydra.ClusterURL(idp.config.ClusterURL),
)
} else {
idp.hc, err = hydra.Connect(
hydra.ClientID(idp.config.ClientID),
hydra.ClientSecret(idp.config.ClientSecret),
hydra.ClusterURL(idp.config.ClusterURL),
hydra.SkipTLSVerify(),
)
}
if err != nil {
return err
}
err = idp.cacheVerificationKey()
if err != nil {
return err
}
err = idp.cacheConsentKey()
if err != nil {
return err
}
return nil
} | [
"func",
"(",
"idp",
"*",
"IDP",
")",
"Connect",
"(",
"verifyTLS",
"bool",
")",
"error",
"{",
"var",
"err",
"error",
"\n",
"if",
"verifyTLS",
"{",
"idp",
".",
"hc",
",",
"err",
"=",
"hydra",
".",
"Connect",
"(",
"hydra",
".",
"ClientID",
"(",
"idp",... | // Connect to Hydra | [
"Connect",
"to",
"Hydra"
] | a4ef1ea49381cd05f4fe96700d2399cd5a51ab1e | https://github.com/janekolszak/idp/blob/a4ef1ea49381cd05f4fe96700d2399cd5a51ab1e/idp.go#L180-L212 |
5,272 | janekolszak/idp | idp.go | getChallengeToken | func (idp *IDP) getChallengeToken(challengeString string) (*jwt.Token, error) {
token, err := jwt.Parse(challengeString, func(token *jwt.Token) (interface{}, error) {
_, ok := token.Method.(*jwt.SigningMethodRSA)
if !ok {
return nil, ErrorBadSigningMethod
}
return idp.getVerificationKey()
})
if err != nil {
return nil, err
}
if !token.Valid {
return nil, ErrorInvalidToken
}
return token, nil
} | go | func (idp *IDP) getChallengeToken(challengeString string) (*jwt.Token, error) {
token, err := jwt.Parse(challengeString, func(token *jwt.Token) (interface{}, error) {
_, ok := token.Method.(*jwt.SigningMethodRSA)
if !ok {
return nil, ErrorBadSigningMethod
}
return idp.getVerificationKey()
})
if err != nil {
return nil, err
}
if !token.Valid {
return nil, ErrorInvalidToken
}
return token, nil
} | [
"func",
"(",
"idp",
"*",
"IDP",
")",
"getChallengeToken",
"(",
"challengeString",
"string",
")",
"(",
"*",
"jwt",
".",
"Token",
",",
"error",
")",
"{",
"token",
",",
"err",
":=",
"jwt",
".",
"Parse",
"(",
"challengeString",
",",
"func",
"(",
"token",
... | // Parse and verify the challenge JWT | [
"Parse",
"and",
"verify",
"the",
"challenge",
"JWT"
] | a4ef1ea49381cd05f4fe96700d2399cd5a51ab1e | https://github.com/janekolszak/idp/blob/a4ef1ea49381cd05f4fe96700d2399cd5a51ab1e/idp.go#L215-L234 |
5,273 | janekolszak/idp | idp.go | NewChallenge | func (idp *IDP) NewChallenge(ctx context.Context, r *http.Request, user string) (challenge *Challenge, err error) {
tokenStr := r.FormValue("challenge")
if tokenStr == "" {
// No challenge token
err = ErrorBadRequest
return
}
token, err := idp.getChallengeToken(tokenStr)
if err != nil {
// Most probably, token can't be verified or parsed
return
}
claims := token.Claims.(jwt.MapClaims)
challenge = new(Challenge)
challenge.Expires = time.Unix(int64(claims["exp"].(float64)), 0)
if challenge.Expires.Before(time.Now()) {
challenge = nil
err = ErrorChallengeExpired
return
}
// Get data from the challenge jwt
challenge.Client, err = idp.getClient(ctx, claims["aud"].(string))
if err != nil {
return nil, err
}
challenge.Redirect = claims["redir"].(string)
challenge.JTI = claims["jti"].(string)
challenge.User = user
challenge.idp = idp
scopes := claims["scp"].([]interface{})
challenge.Scopes = make([]string, len(scopes), len(scopes))
for i, scope := range scopes {
challenge.Scopes[i] = scope.(string)
}
return
} | go | func (idp *IDP) NewChallenge(ctx context.Context, r *http.Request, user string) (challenge *Challenge, err error) {
tokenStr := r.FormValue("challenge")
if tokenStr == "" {
// No challenge token
err = ErrorBadRequest
return
}
token, err := idp.getChallengeToken(tokenStr)
if err != nil {
// Most probably, token can't be verified or parsed
return
}
claims := token.Claims.(jwt.MapClaims)
challenge = new(Challenge)
challenge.Expires = time.Unix(int64(claims["exp"].(float64)), 0)
if challenge.Expires.Before(time.Now()) {
challenge = nil
err = ErrorChallengeExpired
return
}
// Get data from the challenge jwt
challenge.Client, err = idp.getClient(ctx, claims["aud"].(string))
if err != nil {
return nil, err
}
challenge.Redirect = claims["redir"].(string)
challenge.JTI = claims["jti"].(string)
challenge.User = user
challenge.idp = idp
scopes := claims["scp"].([]interface{})
challenge.Scopes = make([]string, len(scopes), len(scopes))
for i, scope := range scopes {
challenge.Scopes[i] = scope.(string)
}
return
} | [
"func",
"(",
"idp",
"*",
"IDP",
")",
"NewChallenge",
"(",
"ctx",
"context",
".",
"Context",
",",
"r",
"*",
"http",
".",
"Request",
",",
"user",
"string",
")",
"(",
"challenge",
"*",
"Challenge",
",",
"err",
"error",
")",
"{",
"tokenStr",
":=",
"r",
... | // Create a new Challenge. The request will contain all the necessary information from Hydra, passed in the URL. | [
"Create",
"a",
"new",
"Challenge",
".",
"The",
"request",
"will",
"contain",
"all",
"the",
"necessary",
"information",
"from",
"Hydra",
"passed",
"in",
"the",
"URL",
"."
] | a4ef1ea49381cd05f4fe96700d2399cd5a51ab1e | https://github.com/janekolszak/idp/blob/a4ef1ea49381cd05f4fe96700d2399cd5a51ab1e/idp.go#L290-L331 |
5,274 | janekolszak/idp | idp.go | GetChallenge | func (idp *IDP) GetChallenge(r *http.Request) (*Challenge, error) {
session, err := idp.config.ChallengeStore.Get(r, SessionCookieName)
if err != nil {
return nil, err
}
challenge, ok := session.Values[SessionCookieName].(*Challenge)
if !ok {
return nil, ErrorBadChallengeCookie
}
if challenge.Expires.Before(time.Now()) {
return nil, ErrorChallengeExpired
}
challenge.idp = idp
return challenge, nil
} | go | func (idp *IDP) GetChallenge(r *http.Request) (*Challenge, error) {
session, err := idp.config.ChallengeStore.Get(r, SessionCookieName)
if err != nil {
return nil, err
}
challenge, ok := session.Values[SessionCookieName].(*Challenge)
if !ok {
return nil, ErrorBadChallengeCookie
}
if challenge.Expires.Before(time.Now()) {
return nil, ErrorChallengeExpired
}
challenge.idp = idp
return challenge, nil
} | [
"func",
"(",
"idp",
"*",
"IDP",
")",
"GetChallenge",
"(",
"r",
"*",
"http",
".",
"Request",
")",
"(",
"*",
"Challenge",
",",
"error",
")",
"{",
"session",
",",
"err",
":=",
"idp",
".",
"config",
".",
"ChallengeStore",
".",
"Get",
"(",
"r",
",",
"... | // Get the Challenge from a cookie, using Gorilla sessions | [
"Get",
"the",
"Challenge",
"from",
"a",
"cookie",
"using",
"Gorilla",
"sessions"
] | a4ef1ea49381cd05f4fe96700d2399cd5a51ab1e | https://github.com/janekolszak/idp/blob/a4ef1ea49381cd05f4fe96700d2399cd5a51ab1e/idp.go#L334-L352 |
5,275 | janekolszak/idp | challenge.go | Save | func (c *Challenge) Save(w http.ResponseWriter, r *http.Request) error {
session, err := c.idp.config.ChallengeStore.New(r, SessionCookieName)
if err != nil {
return err
}
session.Options = c.idp.createChallengeCookieOptions
session.Values[SessionCookieName] = c
return c.idp.config.ChallengeStore.Save(r, w, session)
} | go | func (c *Challenge) Save(w http.ResponseWriter, r *http.Request) error {
session, err := c.idp.config.ChallengeStore.New(r, SessionCookieName)
if err != nil {
return err
}
session.Options = c.idp.createChallengeCookieOptions
session.Values[SessionCookieName] = c
return c.idp.config.ChallengeStore.Save(r, w, session)
} | [
"func",
"(",
"c",
"*",
"Challenge",
")",
"Save",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"error",
"{",
"session",
",",
"err",
":=",
"c",
".",
"idp",
".",
"config",
".",
"ChallengeStore",
".",
"New",
"(",... | // Saves the Challenge to it's session store | [
"Saves",
"the",
"Challenge",
"to",
"it",
"s",
"session",
"store"
] | a4ef1ea49381cd05f4fe96700d2399cd5a51ab1e | https://github.com/janekolszak/idp/blob/a4ef1ea49381cd05f4fe96700d2399cd5a51ab1e/challenge.go#L46-L56 |
5,276 | janekolszak/idp | challenge.go | Delete | func (c *Challenge) Delete(w http.ResponseWriter, r *http.Request) error {
session, err := c.idp.config.ChallengeStore.Get(r, SessionCookieName)
if err != nil {
return err
}
session.Options = c.idp.deleteChallengeCookieOptions
return c.idp.config.ChallengeStore.Save(r, w, session)
} | go | func (c *Challenge) Delete(w http.ResponseWriter, r *http.Request) error {
session, err := c.idp.config.ChallengeStore.Get(r, SessionCookieName)
if err != nil {
return err
}
session.Options = c.idp.deleteChallengeCookieOptions
return c.idp.config.ChallengeStore.Save(r, w, session)
} | [
"func",
"(",
"c",
"*",
"Challenge",
")",
"Delete",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"error",
"{",
"session",
",",
"err",
":=",
"c",
".",
"idp",
".",
"config",
".",
"ChallengeStore",
".",
"Get",
"(... | // Deletes the challenge from the store | [
"Deletes",
"the",
"challenge",
"from",
"the",
"store"
] | a4ef1ea49381cd05f4fe96700d2399cd5a51ab1e | https://github.com/janekolszak/idp/blob/a4ef1ea49381cd05f4fe96700d2399cd5a51ab1e/challenge.go#L72-L80 |
5,277 | janekolszak/idp | challenge.go | RefuseAccess | func (c *Challenge) RefuseAccess(w http.ResponseWriter, r *http.Request) error {
err := c.Delete(w, r)
if err != nil {
return err
}
http.Redirect(w, r, c.Redirect+"&consent=false", http.StatusFound)
return nil
} | go | func (c *Challenge) RefuseAccess(w http.ResponseWriter, r *http.Request) error {
err := c.Delete(w, r)
if err != nil {
return err
}
http.Redirect(w, r, c.Redirect+"&consent=false", http.StatusFound)
return nil
} | [
"func",
"(",
"c",
"*",
"Challenge",
")",
"RefuseAccess",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"error",
"{",
"err",
":=",
"c",
".",
"Delete",
"(",
"w",
",",
"r",
")",
"\n",
"if",
"err",
"!=",
"nil",
... | // User refused access to requested scopes, forward the desicion to Hydra via redirection. | [
"User",
"refused",
"access",
"to",
"requested",
"scopes",
"forward",
"the",
"desicion",
"to",
"Hydra",
"via",
"redirection",
"."
] | a4ef1ea49381cd05f4fe96700d2399cd5a51ab1e | https://github.com/janekolszak/idp/blob/a4ef1ea49381cd05f4fe96700d2399cd5a51ab1e/challenge.go#L83-L92 |
5,278 | janekolszak/idp | challenge.go | GrantAccessToAll | func (c *Challenge) GrantAccessToAll(w http.ResponseWriter, r *http.Request) error {
now := time.Now()
token := jwt.New(jwt.SigningMethodRS256)
claims := token.Claims.(jwt.MapClaims)
claims["aud"] = c.Client.GetID()
claims["exp"] = now.Add(time.Minute * 4).Unix()
claims["iat"] = now.Unix()
claims["scp"] = c.Scopes
claims["jti"] = c.JTI
claims["sub"] = c.User
// Sign and get the complete encoded token as a string
key, err := c.idp.getConsentKey()
if err != nil {
return err
}
tokenString, err := token.SignedString(key)
if err != nil {
return err
}
// Delete the cookie
err = c.Delete(w, r)
if err != nil {
return err
}
// All this work might have taken too long (fetching key may be time consuming)
// so check token expiration
if c.Expires.Before(time.Now()) {
return ErrorChallengeExpired
}
http.Redirect(w, r, c.Redirect+"&consent="+tokenString, http.StatusFound)
return nil
} | go | func (c *Challenge) GrantAccessToAll(w http.ResponseWriter, r *http.Request) error {
now := time.Now()
token := jwt.New(jwt.SigningMethodRS256)
claims := token.Claims.(jwt.MapClaims)
claims["aud"] = c.Client.GetID()
claims["exp"] = now.Add(time.Minute * 4).Unix()
claims["iat"] = now.Unix()
claims["scp"] = c.Scopes
claims["jti"] = c.JTI
claims["sub"] = c.User
// Sign and get the complete encoded token as a string
key, err := c.idp.getConsentKey()
if err != nil {
return err
}
tokenString, err := token.SignedString(key)
if err != nil {
return err
}
// Delete the cookie
err = c.Delete(w, r)
if err != nil {
return err
}
// All this work might have taken too long (fetching key may be time consuming)
// so check token expiration
if c.Expires.Before(time.Now()) {
return ErrorChallengeExpired
}
http.Redirect(w, r, c.Redirect+"&consent="+tokenString, http.StatusFound)
return nil
} | [
"func",
"(",
"c",
"*",
"Challenge",
")",
"GrantAccessToAll",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"error",
"{",
"now",
":=",
"time",
".",
"Now",
"(",
")",
"\n\n",
"token",
":=",
"jwt",
".",
"New",
"("... | // User granted access to requested scopes, forward the desicion to Hydra via redirection. | [
"User",
"granted",
"access",
"to",
"requested",
"scopes",
"forward",
"the",
"desicion",
"to",
"Hydra",
"via",
"redirection",
"."
] | a4ef1ea49381cd05f4fe96700d2399cd5a51ab1e | https://github.com/janekolszak/idp/blob/a4ef1ea49381cd05f4fe96700d2399cd5a51ab1e/challenge.go#L95-L134 |
5,279 | gorilla/css | scanner/scanner.go | emitToken | func (s *Scanner) emitToken(t tokenType, v string) *Token {
token := &Token{t, v, s.row, s.col}
s.updatePosition(v)
return token
} | go | func (s *Scanner) emitToken(t tokenType, v string) *Token {
token := &Token{t, v, s.row, s.col}
s.updatePosition(v)
return token
} | [
"func",
"(",
"s",
"*",
"Scanner",
")",
"emitToken",
"(",
"t",
"tokenType",
",",
"v",
"string",
")",
"*",
"Token",
"{",
"token",
":=",
"&",
"Token",
"{",
"t",
",",
"v",
",",
"s",
".",
"row",
",",
"s",
".",
"col",
"}",
"\n",
"s",
".",
"updatePo... | // emitToken returns a Token for the string v and updates the scanner position. | [
"emitToken",
"returns",
"a",
"Token",
"for",
"the",
"string",
"v",
"and",
"updates",
"the",
"scanner",
"position",
"."
] | c1a14c1cca8927b0aea71ee7a92add9bb4525a01 | https://github.com/gorilla/css/blob/c1a14c1cca8927b0aea71ee7a92add9bb4525a01/scanner/scanner.go#L333-L337 |
5,280 | gorilla/css | scanner/scanner.go | emitSimple | func (s *Scanner) emitSimple(t tokenType, v string) *Token {
token := &Token{t, v, s.row, s.col}
s.col += len(v)
s.pos += len(v)
return token
} | go | func (s *Scanner) emitSimple(t tokenType, v string) *Token {
token := &Token{t, v, s.row, s.col}
s.col += len(v)
s.pos += len(v)
return token
} | [
"func",
"(",
"s",
"*",
"Scanner",
")",
"emitSimple",
"(",
"t",
"tokenType",
",",
"v",
"string",
")",
"*",
"Token",
"{",
"token",
":=",
"&",
"Token",
"{",
"t",
",",
"v",
",",
"s",
".",
"row",
",",
"s",
".",
"col",
"}",
"\n",
"s",
".",
"col",
... | // emitSimple returns a Token for the string v and updates the scanner
// position in a simplified manner.
//
// The string is known to have only ASCII characters and to not have a newline. | [
"emitSimple",
"returns",
"a",
"Token",
"for",
"the",
"string",
"v",
"and",
"updates",
"the",
"scanner",
"position",
"in",
"a",
"simplified",
"manner",
".",
"The",
"string",
"is",
"known",
"to",
"have",
"only",
"ASCII",
"characters",
"and",
"to",
"not",
"ha... | c1a14c1cca8927b0aea71ee7a92add9bb4525a01 | https://github.com/gorilla/css/blob/c1a14c1cca8927b0aea71ee7a92add9bb4525a01/scanner/scanner.go#L343-L348 |
5,281 | gorilla/css | scanner/scanner.go | emitPrefixOrChar | func (s *Scanner) emitPrefixOrChar(t tokenType, prefix string) *Token {
if strings.HasPrefix(s.input[s.pos:], prefix) {
return s.emitSimple(t, prefix)
}
return s.emitSimple(TokenChar, string(prefix[0]))
} | go | func (s *Scanner) emitPrefixOrChar(t tokenType, prefix string) *Token {
if strings.HasPrefix(s.input[s.pos:], prefix) {
return s.emitSimple(t, prefix)
}
return s.emitSimple(TokenChar, string(prefix[0]))
} | [
"func",
"(",
"s",
"*",
"Scanner",
")",
"emitPrefixOrChar",
"(",
"t",
"tokenType",
",",
"prefix",
"string",
")",
"*",
"Token",
"{",
"if",
"strings",
".",
"HasPrefix",
"(",
"s",
".",
"input",
"[",
"s",
".",
"pos",
":",
"]",
",",
"prefix",
")",
"{",
... | // emitPrefixOrChar returns a Token for type t if the current position
// matches the given prefix. Otherwise it returns a Char token using the
// first character from the prefix.
//
// The prefix is known to have only ASCII characters and to not have a newline. | [
"emitPrefixOrChar",
"returns",
"a",
"Token",
"for",
"type",
"t",
"if",
"the",
"current",
"position",
"matches",
"the",
"given",
"prefix",
".",
"Otherwise",
"it",
"returns",
"a",
"Char",
"token",
"using",
"the",
"first",
"character",
"from",
"the",
"prefix",
... | c1a14c1cca8927b0aea71ee7a92add9bb4525a01 | https://github.com/gorilla/css/blob/c1a14c1cca8927b0aea71ee7a92add9bb4525a01/scanner/scanner.go#L355-L360 |
5,282 | rsc/qr | coding/qr.go | DataBytes | func (v Version) DataBytes(l Level) int {
vt := &vtab[v]
lev := &vt.level[l]
return vt.bytes - lev.nblock*lev.check
} | go | func (v Version) DataBytes(l Level) int {
vt := &vtab[v]
lev := &vt.level[l]
return vt.bytes - lev.nblock*lev.check
} | [
"func",
"(",
"v",
"Version",
")",
"DataBytes",
"(",
"l",
"Level",
")",
"int",
"{",
"vt",
":=",
"&",
"vtab",
"[",
"v",
"]",
"\n",
"lev",
":=",
"&",
"vt",
".",
"level",
"[",
"l",
"]",
"\n",
"return",
"vt",
".",
"bytes",
"-",
"lev",
".",
"nblock... | // DataBytes returns the number of data bytes that can be
// stored in a QR code with the given version and level. | [
"DataBytes",
"returns",
"the",
"number",
"of",
"data",
"bytes",
"that",
"can",
"be",
"stored",
"in",
"a",
"QR",
"code",
"with",
"the",
"given",
"version",
"and",
"level",
"."
] | ca9a01fc2f9505024045632c50e5e8cd6142fafe | https://github.com/rsc/qr/blob/ca9a01fc2f9505024045632c50e5e8cd6142fafe/coding/qr.go#L45-L49 |
5,283 | rsc/qr | coding/qr.go | NewPlan | func NewPlan(version Version, level Level, mask Mask) (*Plan, error) {
p, err := vplan(version)
if err != nil {
return nil, err
}
if err := fplan(level, mask, p); err != nil {
return nil, err
}
if err := lplan(version, level, p); err != nil {
return nil, err
}
if err := mplan(mask, p); err != nil {
return nil, err
}
return p, nil
} | go | func NewPlan(version Version, level Level, mask Mask) (*Plan, error) {
p, err := vplan(version)
if err != nil {
return nil, err
}
if err := fplan(level, mask, p); err != nil {
return nil, err
}
if err := lplan(version, level, p); err != nil {
return nil, err
}
if err := mplan(mask, p); err != nil {
return nil, err
}
return p, nil
} | [
"func",
"NewPlan",
"(",
"version",
"Version",
",",
"level",
"Level",
",",
"mask",
"Mask",
")",
"(",
"*",
"Plan",
",",
"error",
")",
"{",
"p",
",",
"err",
":=",
"vplan",
"(",
"version",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",... | // NewPlan returns a Plan for a QR code with the given
// version, level, and mask. | [
"NewPlan",
"returns",
"a",
"Plan",
"for",
"a",
"QR",
"code",
"with",
"the",
"given",
"version",
"level",
"and",
"mask",
"."
] | ca9a01fc2f9505024045632c50e5e8cd6142fafe | https://github.com/rsc/qr/blob/ca9a01fc2f9505024045632c50e5e8cd6142fafe/coding/qr.go#L362-L377 |
5,284 | rsc/qr | coding/qr.go | vplan | func vplan(v Version) (*Plan, error) {
p := &Plan{Version: v}
if v < 1 || v > 40 {
return nil, fmt.Errorf("invalid QR version %d", int(v))
}
siz := 17 + int(v)*4
m := grid(siz)
p.Pixel = m
// Timing markers (overwritten by boxes).
const ti = 6 // timing is in row/column 6 (counting from 0)
for i := range m {
p := Timing.Pixel()
if i&1 == 0 {
p |= Black
}
m[i][ti] = p
m[ti][i] = p
}
// Position boxes.
posBox(m, 0, 0)
posBox(m, siz-7, 0)
posBox(m, 0, siz-7)
// Alignment boxes.
info := &vtab[v]
for x := 4; x+5 < siz; {
for y := 4; y+5 < siz; {
// don't overwrite timing markers
if (x < 7 && y < 7) || (x < 7 && y+5 >= siz-7) || (x+5 >= siz-7 && y < 7) {
} else {
alignBox(m, x, y)
}
if y == 4 {
y = info.apos
} else {
y += info.astride
}
}
if x == 4 {
x = info.apos
} else {
x += info.astride
}
}
// Version pattern.
pat := vtab[v].pattern
if pat != 0 {
v := pat
for x := 0; x < 6; x++ {
for y := 0; y < 3; y++ {
p := PVersion.Pixel()
if v&1 != 0 {
p |= Black
}
m[siz-11+y][x] = p
m[x][siz-11+y] = p
v >>= 1
}
}
}
// One lonely black pixel
m[siz-8][8] = Unused.Pixel() | Black
return p, nil
} | go | func vplan(v Version) (*Plan, error) {
p := &Plan{Version: v}
if v < 1 || v > 40 {
return nil, fmt.Errorf("invalid QR version %d", int(v))
}
siz := 17 + int(v)*4
m := grid(siz)
p.Pixel = m
// Timing markers (overwritten by boxes).
const ti = 6 // timing is in row/column 6 (counting from 0)
for i := range m {
p := Timing.Pixel()
if i&1 == 0 {
p |= Black
}
m[i][ti] = p
m[ti][i] = p
}
// Position boxes.
posBox(m, 0, 0)
posBox(m, siz-7, 0)
posBox(m, 0, siz-7)
// Alignment boxes.
info := &vtab[v]
for x := 4; x+5 < siz; {
for y := 4; y+5 < siz; {
// don't overwrite timing markers
if (x < 7 && y < 7) || (x < 7 && y+5 >= siz-7) || (x+5 >= siz-7 && y < 7) {
} else {
alignBox(m, x, y)
}
if y == 4 {
y = info.apos
} else {
y += info.astride
}
}
if x == 4 {
x = info.apos
} else {
x += info.astride
}
}
// Version pattern.
pat := vtab[v].pattern
if pat != 0 {
v := pat
for x := 0; x < 6; x++ {
for y := 0; y < 3; y++ {
p := PVersion.Pixel()
if v&1 != 0 {
p |= Black
}
m[siz-11+y][x] = p
m[x][siz-11+y] = p
v >>= 1
}
}
}
// One lonely black pixel
m[siz-8][8] = Unused.Pixel() | Black
return p, nil
} | [
"func",
"vplan",
"(",
"v",
"Version",
")",
"(",
"*",
"Plan",
",",
"error",
")",
"{",
"p",
":=",
"&",
"Plan",
"{",
"Version",
":",
"v",
"}",
"\n",
"if",
"v",
"<",
"1",
"||",
"v",
">",
"40",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(... | // vplan creates a Plan for the given version. | [
"vplan",
"creates",
"a",
"Plan",
"for",
"the",
"given",
"version",
"."
] | ca9a01fc2f9505024045632c50e5e8cd6142fafe | https://github.com/rsc/qr/blob/ca9a01fc2f9505024045632c50e5e8cd6142fafe/coding/qr.go#L536-L604 |
5,285 | rsc/qr | coding/qr.go | fplan | func fplan(l Level, m Mask, p *Plan) error {
// Format pixels.
fb := uint32(l^1) << 13 // level: L=01, M=00, Q=11, H=10
fb |= uint32(m) << 10 // mask
const formatPoly = 0x537
rem := fb
for i := 14; i >= 10; i-- {
if rem&(1<<uint(i)) != 0 {
rem ^= formatPoly << uint(i-10)
}
}
fb |= rem
invert := uint32(0x5412)
siz := len(p.Pixel)
for i := uint(0); i < 15; i++ {
pix := Format.Pixel() + OffsetPixel(i)
if (fb>>i)&1 == 1 {
pix |= Black
}
if (invert>>i)&1 == 1 {
pix ^= Invert | Black
}
// top left
switch {
case i < 6:
p.Pixel[i][8] = pix
case i < 8:
p.Pixel[i+1][8] = pix
case i < 9:
p.Pixel[8][7] = pix
default:
p.Pixel[8][14-i] = pix
}
// bottom right
switch {
case i < 8:
p.Pixel[8][siz-1-int(i)] = pix
default:
p.Pixel[siz-1-int(14-i)][8] = pix
}
}
return nil
} | go | func fplan(l Level, m Mask, p *Plan) error {
// Format pixels.
fb := uint32(l^1) << 13 // level: L=01, M=00, Q=11, H=10
fb |= uint32(m) << 10 // mask
const formatPoly = 0x537
rem := fb
for i := 14; i >= 10; i-- {
if rem&(1<<uint(i)) != 0 {
rem ^= formatPoly << uint(i-10)
}
}
fb |= rem
invert := uint32(0x5412)
siz := len(p.Pixel)
for i := uint(0); i < 15; i++ {
pix := Format.Pixel() + OffsetPixel(i)
if (fb>>i)&1 == 1 {
pix |= Black
}
if (invert>>i)&1 == 1 {
pix ^= Invert | Black
}
// top left
switch {
case i < 6:
p.Pixel[i][8] = pix
case i < 8:
p.Pixel[i+1][8] = pix
case i < 9:
p.Pixel[8][7] = pix
default:
p.Pixel[8][14-i] = pix
}
// bottom right
switch {
case i < 8:
p.Pixel[8][siz-1-int(i)] = pix
default:
p.Pixel[siz-1-int(14-i)][8] = pix
}
}
return nil
} | [
"func",
"fplan",
"(",
"l",
"Level",
",",
"m",
"Mask",
",",
"p",
"*",
"Plan",
")",
"error",
"{",
"// Format pixels.",
"fb",
":=",
"uint32",
"(",
"l",
"^",
"1",
")",
"<<",
"13",
"// level: L=01, M=00, Q=11, H=10",
"\n",
"fb",
"|=",
"uint32",
"(",
"m",
... | // fplan adds the format pixels | [
"fplan",
"adds",
"the",
"format",
"pixels"
] | ca9a01fc2f9505024045632c50e5e8cd6142fafe | https://github.com/rsc/qr/blob/ca9a01fc2f9505024045632c50e5e8cd6142fafe/coding/qr.go#L607-L649 |
5,286 | rsc/qr | coding/qr.go | mplan | func mplan(m Mask, p *Plan) error {
p.Mask = m
for y, row := range p.Pixel {
for x, pix := range row {
if r := pix.Role(); (r == Data || r == Check || r == Extra) && p.Mask.Invert(y, x) {
row[x] ^= Black | Invert
}
}
}
return nil
} | go | func mplan(m Mask, p *Plan) error {
p.Mask = m
for y, row := range p.Pixel {
for x, pix := range row {
if r := pix.Role(); (r == Data || r == Check || r == Extra) && p.Mask.Invert(y, x) {
row[x] ^= Black | Invert
}
}
}
return nil
} | [
"func",
"mplan",
"(",
"m",
"Mask",
",",
"p",
"*",
"Plan",
")",
"error",
"{",
"p",
".",
"Mask",
"=",
"m",
"\n",
"for",
"y",
",",
"row",
":=",
"range",
"p",
".",
"Pixel",
"{",
"for",
"x",
",",
"pix",
":=",
"range",
"row",
"{",
"if",
"r",
":="... | // mplan edits a version+level-only Plan to add the mask. | [
"mplan",
"edits",
"a",
"version",
"+",
"level",
"-",
"only",
"Plan",
"to",
"add",
"the",
"mask",
"."
] | ca9a01fc2f9505024045632c50e5e8cd6142fafe | https://github.com/rsc/qr/blob/ca9a01fc2f9505024045632c50e5e8cd6142fafe/coding/qr.go#L754-L764 |
5,287 | rsc/qr | qr.go | Encode | func Encode(text string, level Level) (*Code, error) {
// Pick data encoding, smallest first.
// We could split the string and use different encodings
// but that seems like overkill for now.
var enc coding.Encoding
switch {
case coding.Num(text).Check() == nil:
enc = coding.Num(text)
case coding.Alpha(text).Check() == nil:
enc = coding.Alpha(text)
default:
enc = coding.String(text)
}
// Pick size.
l := coding.Level(level)
var v coding.Version
for v = coding.MinVersion; ; v++ {
if v > coding.MaxVersion {
return nil, errors.New("text too long to encode as QR")
}
if enc.Bits(v) <= v.DataBytes(l)*8 {
break
}
}
// Build and execute plan.
p, err := coding.NewPlan(v, l, 0)
if err != nil {
return nil, err
}
cc, err := p.Encode(enc)
if err != nil {
return nil, err
}
// TODO: Pick appropriate mask.
return &Code{cc.Bitmap, cc.Size, cc.Stride, 8}, nil
} | go | func Encode(text string, level Level) (*Code, error) {
// Pick data encoding, smallest first.
// We could split the string and use different encodings
// but that seems like overkill for now.
var enc coding.Encoding
switch {
case coding.Num(text).Check() == nil:
enc = coding.Num(text)
case coding.Alpha(text).Check() == nil:
enc = coding.Alpha(text)
default:
enc = coding.String(text)
}
// Pick size.
l := coding.Level(level)
var v coding.Version
for v = coding.MinVersion; ; v++ {
if v > coding.MaxVersion {
return nil, errors.New("text too long to encode as QR")
}
if enc.Bits(v) <= v.DataBytes(l)*8 {
break
}
}
// Build and execute plan.
p, err := coding.NewPlan(v, l, 0)
if err != nil {
return nil, err
}
cc, err := p.Encode(enc)
if err != nil {
return nil, err
}
// TODO: Pick appropriate mask.
return &Code{cc.Bitmap, cc.Size, cc.Stride, 8}, nil
} | [
"func",
"Encode",
"(",
"text",
"string",
",",
"level",
"Level",
")",
"(",
"*",
"Code",
",",
"error",
")",
"{",
"// Pick data encoding, smallest first.",
"// We could split the string and use different encodings",
"// but that seems like overkill for now.",
"var",
"enc",
"co... | // Encode returns an encoding of text at the given error correction level. | [
"Encode",
"returns",
"an",
"encoding",
"of",
"text",
"at",
"the",
"given",
"error",
"correction",
"level",
"."
] | ca9a01fc2f9505024045632c50e5e8cd6142fafe | https://github.com/rsc/qr/blob/ca9a01fc2f9505024045632c50e5e8cd6142fafe/qr.go#L30-L69 |
5,288 | rsc/qr | gf256/gf256.go | nbit | func nbit(p int) uint {
n := uint(0)
for ; p > 0; p >>= 1 {
n++
}
return n
} | go | func nbit(p int) uint {
n := uint(0)
for ; p > 0; p >>= 1 {
n++
}
return n
} | [
"func",
"nbit",
"(",
"p",
"int",
")",
"uint",
"{",
"n",
":=",
"uint",
"(",
"0",
")",
"\n",
"for",
";",
"p",
">",
"0",
";",
"p",
">>=",
"1",
"{",
"n",
"++",
"\n",
"}",
"\n",
"return",
"n",
"\n",
"}"
] | // nbit returns the number of significant in p. | [
"nbit",
"returns",
"the",
"number",
"of",
"significant",
"in",
"p",
"."
] | ca9a01fc2f9505024045632c50e5e8cd6142fafe | https://github.com/rsc/qr/blob/ca9a01fc2f9505024045632c50e5e8cd6142fafe/gf256/gf256.go#L57-L63 |
5,289 | rsc/qr | gf256/gf256.go | polyDiv | func polyDiv(p, q int) int {
np := nbit(p)
nq := nbit(q)
for ; np >= nq; np-- {
if p&(1<<(np-1)) != 0 {
p ^= q << (np - nq)
}
}
return p
} | go | func polyDiv(p, q int) int {
np := nbit(p)
nq := nbit(q)
for ; np >= nq; np-- {
if p&(1<<(np-1)) != 0 {
p ^= q << (np - nq)
}
}
return p
} | [
"func",
"polyDiv",
"(",
"p",
",",
"q",
"int",
")",
"int",
"{",
"np",
":=",
"nbit",
"(",
"p",
")",
"\n",
"nq",
":=",
"nbit",
"(",
"q",
")",
"\n",
"for",
";",
"np",
">=",
"nq",
";",
"np",
"--",
"{",
"if",
"p",
"&",
"(",
"1",
"<<",
"(",
"n... | // polyDiv divides the polynomial p by q and returns the remainder. | [
"polyDiv",
"divides",
"the",
"polynomial",
"p",
"by",
"q",
"and",
"returns",
"the",
"remainder",
"."
] | ca9a01fc2f9505024045632c50e5e8cd6142fafe | https://github.com/rsc/qr/blob/ca9a01fc2f9505024045632c50e5e8cd6142fafe/gf256/gf256.go#L66-L75 |
5,290 | rsc/qr | gf256/gf256.go | reducible | func reducible(p int) bool {
// Multiplying n-bit * n-bit produces (2n-1)-bit,
// so if p is reducible, one of its factors must be
// of np/2+1 bits or fewer.
np := nbit(p)
for q := 2; q < 1<<(np/2+1); q++ {
if polyDiv(p, q) == 0 {
return true
}
}
return false
} | go | func reducible(p int) bool {
// Multiplying n-bit * n-bit produces (2n-1)-bit,
// so if p is reducible, one of its factors must be
// of np/2+1 bits or fewer.
np := nbit(p)
for q := 2; q < 1<<(np/2+1); q++ {
if polyDiv(p, q) == 0 {
return true
}
}
return false
} | [
"func",
"reducible",
"(",
"p",
"int",
")",
"bool",
"{",
"// Multiplying n-bit * n-bit produces (2n-1)-bit,",
"// so if p is reducible, one of its factors must be",
"// of np/2+1 bits or fewer.",
"np",
":=",
"nbit",
"(",
"p",
")",
"\n",
"for",
"q",
":=",
"2",
";",
"q",
... | // reducible reports whether p is reducible. | [
"reducible",
"reports",
"whether",
"p",
"is",
"reducible",
"."
] | ca9a01fc2f9505024045632c50e5e8cd6142fafe | https://github.com/rsc/qr/blob/ca9a01fc2f9505024045632c50e5e8cd6142fafe/gf256/gf256.go#L94-L105 |
5,291 | rsc/qr | gf256/gf256.go | Inv | func (f *Field) Inv(x byte) byte {
if x == 0 {
return 0
}
return f.exp[255-f.log[x]]
} | go | func (f *Field) Inv(x byte) byte {
if x == 0 {
return 0
}
return f.exp[255-f.log[x]]
} | [
"func",
"(",
"f",
"*",
"Field",
")",
"Inv",
"(",
"x",
"byte",
")",
"byte",
"{",
"if",
"x",
"==",
"0",
"{",
"return",
"0",
"\n",
"}",
"\n",
"return",
"f",
".",
"exp",
"[",
"255",
"-",
"f",
".",
"log",
"[",
"x",
"]",
"]",
"\n",
"}"
] | // Inv returns the multiplicative inverse of x in the field.
// If x == 0, Inv returns 0. | [
"Inv",
"returns",
"the",
"multiplicative",
"inverse",
"of",
"x",
"in",
"the",
"field",
".",
"If",
"x",
"==",
"0",
"Inv",
"returns",
"0",
"."
] | ca9a01fc2f9505024045632c50e5e8cd6142fafe | https://github.com/rsc/qr/blob/ca9a01fc2f9505024045632c50e5e8cd6142fafe/gf256/gf256.go#L132-L137 |
5,292 | rsc/qr | gf256/gf256.go | Mul | func (f *Field) Mul(x, y byte) byte {
if x == 0 || y == 0 {
return 0
}
return f.exp[int(f.log[x])+int(f.log[y])]
} | go | func (f *Field) Mul(x, y byte) byte {
if x == 0 || y == 0 {
return 0
}
return f.exp[int(f.log[x])+int(f.log[y])]
} | [
"func",
"(",
"f",
"*",
"Field",
")",
"Mul",
"(",
"x",
",",
"y",
"byte",
")",
"byte",
"{",
"if",
"x",
"==",
"0",
"||",
"y",
"==",
"0",
"{",
"return",
"0",
"\n",
"}",
"\n",
"return",
"f",
".",
"exp",
"[",
"int",
"(",
"f",
".",
"log",
"[",
... | // Mul returns the product of x and y in the field. | [
"Mul",
"returns",
"the",
"product",
"of",
"x",
"and",
"y",
"in",
"the",
"field",
"."
] | ca9a01fc2f9505024045632c50e5e8cd6142fafe | https://github.com/rsc/qr/blob/ca9a01fc2f9505024045632c50e5e8cd6142fafe/gf256/gf256.go#L140-L145 |
5,293 | rsc/qr | gf256/gf256.go | NewRSEncoder | func NewRSEncoder(f *Field, c int) *RSEncoder {
gen, lgen := f.gen(c)
return &RSEncoder{f: f, c: c, gen: gen, lgen: lgen}
} | go | func NewRSEncoder(f *Field, c int) *RSEncoder {
gen, lgen := f.gen(c)
return &RSEncoder{f: f, c: c, gen: gen, lgen: lgen}
} | [
"func",
"NewRSEncoder",
"(",
"f",
"*",
"Field",
",",
"c",
"int",
")",
"*",
"RSEncoder",
"{",
"gen",
",",
"lgen",
":=",
"f",
".",
"gen",
"(",
"c",
")",
"\n",
"return",
"&",
"RSEncoder",
"{",
"f",
":",
"f",
",",
"c",
":",
"c",
",",
"gen",
":",
... | // NewRSEncoder returns a new Reed-Solomon encoder
// over the given field and number of error correction bytes. | [
"NewRSEncoder",
"returns",
"a",
"new",
"Reed",
"-",
"Solomon",
"encoder",
"over",
"the",
"given",
"field",
"and",
"number",
"of",
"error",
"correction",
"bytes",
"."
] | ca9a01fc2f9505024045632c50e5e8cd6142fafe | https://github.com/rsc/qr/blob/ca9a01fc2f9505024045632c50e5e8cd6142fafe/gf256/gf256.go#L187-L190 |
5,294 | rsc/qr | gf256/gf256.go | ECC | func (rs *RSEncoder) ECC(data []byte, check []byte) {
if len(check) < rs.c {
panic("gf256: invalid check byte length")
}
if rs.c == 0 {
return
}
// The check bytes are the remainder after dividing
// data padded with c zeros by the generator polynomial.
// p = data padded with c zeros.
var p []byte
n := len(data) + rs.c
if len(rs.p) >= n {
p = rs.p
} else {
p = make([]byte, n)
}
copy(p, data)
for i := len(data); i < len(p); i++ {
p[i] = 0
}
// Divide p by gen, leaving the remainder in p[len(data):].
// p[0] is the most significant term in p, and
// gen[0] is the most significant term in the generator,
// which is always 1.
// To avoid repeated work, we store various values as
// lv, not v, where lv = log[v].
f := rs.f
lgen := rs.lgen[1:]
for i := 0; i < len(data); i++ {
c := p[i]
if c == 0 {
continue
}
q := p[i+1:]
exp := f.exp[f.log[c]:]
for j, lg := range lgen {
if lg != 255 { // lgen uses 255 for log 0
q[j] ^= exp[lg]
}
}
}
copy(check, p[len(data):])
rs.p = p
} | go | func (rs *RSEncoder) ECC(data []byte, check []byte) {
if len(check) < rs.c {
panic("gf256: invalid check byte length")
}
if rs.c == 0 {
return
}
// The check bytes are the remainder after dividing
// data padded with c zeros by the generator polynomial.
// p = data padded with c zeros.
var p []byte
n := len(data) + rs.c
if len(rs.p) >= n {
p = rs.p
} else {
p = make([]byte, n)
}
copy(p, data)
for i := len(data); i < len(p); i++ {
p[i] = 0
}
// Divide p by gen, leaving the remainder in p[len(data):].
// p[0] is the most significant term in p, and
// gen[0] is the most significant term in the generator,
// which is always 1.
// To avoid repeated work, we store various values as
// lv, not v, where lv = log[v].
f := rs.f
lgen := rs.lgen[1:]
for i := 0; i < len(data); i++ {
c := p[i]
if c == 0 {
continue
}
q := p[i+1:]
exp := f.exp[f.log[c]:]
for j, lg := range lgen {
if lg != 255 { // lgen uses 255 for log 0
q[j] ^= exp[lg]
}
}
}
copy(check, p[len(data):])
rs.p = p
} | [
"func",
"(",
"rs",
"*",
"RSEncoder",
")",
"ECC",
"(",
"data",
"[",
"]",
"byte",
",",
"check",
"[",
"]",
"byte",
")",
"{",
"if",
"len",
"(",
"check",
")",
"<",
"rs",
".",
"c",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"rs",
... | // ECC writes to check the error correcting code bytes
// for data using the given Reed-Solomon parameters. | [
"ECC",
"writes",
"to",
"check",
"the",
"error",
"correcting",
"code",
"bytes",
"for",
"data",
"using",
"the",
"given",
"Reed",
"-",
"Solomon",
"parameters",
"."
] | ca9a01fc2f9505024045632c50e5e8cd6142fafe | https://github.com/rsc/qr/blob/ca9a01fc2f9505024045632c50e5e8cd6142fafe/gf256/gf256.go#L194-L241 |
5,295 | lithammer/dedent | dedent.go | Dedent | func Dedent(text string) string {
var margin string
text = whitespaceOnly.ReplaceAllString(text, "")
indents := leadingWhitespace.FindAllStringSubmatch(text, -1)
// Look for the longest leading string of spaces and tabs common to all
// lines.
for i, indent := range indents {
if i == 0 {
margin = indent[1]
} else if strings.HasPrefix(indent[1], margin) {
// Current line more deeply indented than previous winner:
// no change (previous winner is still on top).
continue
} else if strings.HasPrefix(margin, indent[1]) {
// Current line consistent with and no deeper than previous winner:
// it's the new winner.
margin = indent[1]
} else {
// Current line and previous winner have no common whitespace:
// there is no margin.
margin = ""
break
}
}
if margin != "" {
text = regexp.MustCompile("(?m)^"+margin).ReplaceAllString(text, "")
}
return text
} | go | func Dedent(text string) string {
var margin string
text = whitespaceOnly.ReplaceAllString(text, "")
indents := leadingWhitespace.FindAllStringSubmatch(text, -1)
// Look for the longest leading string of spaces and tabs common to all
// lines.
for i, indent := range indents {
if i == 0 {
margin = indent[1]
} else if strings.HasPrefix(indent[1], margin) {
// Current line more deeply indented than previous winner:
// no change (previous winner is still on top).
continue
} else if strings.HasPrefix(margin, indent[1]) {
// Current line consistent with and no deeper than previous winner:
// it's the new winner.
margin = indent[1]
} else {
// Current line and previous winner have no common whitespace:
// there is no margin.
margin = ""
break
}
}
if margin != "" {
text = regexp.MustCompile("(?m)^"+margin).ReplaceAllString(text, "")
}
return text
} | [
"func",
"Dedent",
"(",
"text",
"string",
")",
"string",
"{",
"var",
"margin",
"string",
"\n\n",
"text",
"=",
"whitespaceOnly",
".",
"ReplaceAllString",
"(",
"text",
",",
"\"",
"\"",
")",
"\n",
"indents",
":=",
"leadingWhitespace",
".",
"FindAllStringSubmatch",... | // Dedent removes any common leading whitespace from every line in text.
//
// This can be used to make multiline strings to line up with the left edge of
// the display, while still presenting them in the source code in indented
// form. | [
"Dedent",
"removes",
"any",
"common",
"leading",
"whitespace",
"from",
"every",
"line",
"in",
"text",
".",
"This",
"can",
"be",
"used",
"to",
"make",
"multiline",
"strings",
"to",
"line",
"up",
"with",
"the",
"left",
"edge",
"of",
"the",
"display",
"while"... | bacd562a68752afbd2c992df855db07be0db9bde | https://github.com/lithammer/dedent/blob/bacd562a68752afbd2c992df855db07be0db9bde/dedent.go#L18-L49 |
5,296 | mitchellh/colorstring | colorstring.go | Color | func (c *Colorize) Color(v string) string {
matches := parseRe.FindAllStringIndex(v, -1)
if len(matches) == 0 {
return v
}
result := new(bytes.Buffer)
colored := false
m := []int{0, 0}
for _, nm := range matches {
// Write the text in between this match and the last
result.WriteString(v[m[1]:nm[0]])
m = nm
var replace string
if code, ok := c.Colors[v[m[0]+1:m[1]-1]]; ok {
colored = true
if !c.Disable {
replace = fmt.Sprintf("\033[%sm", code)
}
} else {
replace = v[m[0]:m[1]]
}
result.WriteString(replace)
}
result.WriteString(v[m[1]:])
if colored && c.Reset && !c.Disable {
// Write the clear byte at the end
result.WriteString("\033[0m")
}
return result.String()
} | go | func (c *Colorize) Color(v string) string {
matches := parseRe.FindAllStringIndex(v, -1)
if len(matches) == 0 {
return v
}
result := new(bytes.Buffer)
colored := false
m := []int{0, 0}
for _, nm := range matches {
// Write the text in between this match and the last
result.WriteString(v[m[1]:nm[0]])
m = nm
var replace string
if code, ok := c.Colors[v[m[0]+1:m[1]-1]]; ok {
colored = true
if !c.Disable {
replace = fmt.Sprintf("\033[%sm", code)
}
} else {
replace = v[m[0]:m[1]]
}
result.WriteString(replace)
}
result.WriteString(v[m[1]:])
if colored && c.Reset && !c.Disable {
// Write the clear byte at the end
result.WriteString("\033[0m")
}
return result.String()
} | [
"func",
"(",
"c",
"*",
"Colorize",
")",
"Color",
"(",
"v",
"string",
")",
"string",
"{",
"matches",
":=",
"parseRe",
".",
"FindAllStringIndex",
"(",
"v",
",",
"-",
"1",
")",
"\n",
"if",
"len",
"(",
"matches",
")",
"==",
"0",
"{",
"return",
"v",
"... | // Color colorizes a string according to the settings setup in the struct.
//
// For more details on the syntax, see the top-level Color function. | [
"Color",
"colorizes",
"a",
"string",
"according",
"to",
"the",
"settings",
"setup",
"in",
"the",
"struct",
".",
"For",
"more",
"details",
"on",
"the",
"syntax",
"see",
"the",
"top",
"-",
"level",
"Color",
"function",
"."
] | d06e56a500db4d08c33db0b79461e7c9beafca2d | https://github.com/mitchellh/colorstring/blob/d06e56a500db4d08c33db0b79461e7c9beafca2d/colorstring.go#L66-L101 |
5,297 | mitchellh/colorstring | colorstring.go | Print | func Print(a string) (n int, err error) {
return fmt.Print(Color(a))
} | go | func Print(a string) (n int, err error) {
return fmt.Print(Color(a))
} | [
"func",
"Print",
"(",
"a",
"string",
")",
"(",
"n",
"int",
",",
"err",
"error",
")",
"{",
"return",
"fmt",
".",
"Print",
"(",
"Color",
"(",
"a",
")",
")",
"\n",
"}"
] | // Print is a convenience wrapper for fmt.Print with support for color codes.
//
// Print formats using the default formats for its operands and writes to
// standard output with support for color codes. Spaces are added between
// operands when neither is a string. It returns the number of bytes written
// and any write error encountered. | [
"Print",
"is",
"a",
"convenience",
"wrapper",
"for",
"fmt",
".",
"Print",
"with",
"support",
"for",
"color",
"codes",
".",
"Print",
"formats",
"using",
"the",
"default",
"formats",
"for",
"its",
"operands",
"and",
"writes",
"to",
"standard",
"output",
"with"... | d06e56a500db4d08c33db0b79461e7c9beafca2d | https://github.com/mitchellh/colorstring/blob/d06e56a500db4d08c33db0b79461e7c9beafca2d/colorstring.go#L191-L193 |
5,298 | mitchellh/colorstring | colorstring.go | Println | func Println(a string) (n int, err error) {
return fmt.Println(Color(a))
} | go | func Println(a string) (n int, err error) {
return fmt.Println(Color(a))
} | [
"func",
"Println",
"(",
"a",
"string",
")",
"(",
"n",
"int",
",",
"err",
"error",
")",
"{",
"return",
"fmt",
".",
"Println",
"(",
"Color",
"(",
"a",
")",
")",
"\n",
"}"
] | // Println is a convenience wrapper for fmt.Println with support for color
// codes.
//
// Println formats using the default formats for its operands and writes to
// standard output with support for color codes. Spaces are always added
// between operands and a newline is appended. It returns the number of bytes
// written and any write error encountered. | [
"Println",
"is",
"a",
"convenience",
"wrapper",
"for",
"fmt",
".",
"Println",
"with",
"support",
"for",
"color",
"codes",
".",
"Println",
"formats",
"using",
"the",
"default",
"formats",
"for",
"its",
"operands",
"and",
"writes",
"to",
"standard",
"output",
... | d06e56a500db4d08c33db0b79461e7c9beafca2d | https://github.com/mitchellh/colorstring/blob/d06e56a500db4d08c33db0b79461e7c9beafca2d/colorstring.go#L202-L204 |
5,299 | mitchellh/colorstring | colorstring.go | Printf | func Printf(format string, a ...interface{}) (n int, err error) {
return fmt.Printf(Color(format), a...)
} | go | func Printf(format string, a ...interface{}) (n int, err error) {
return fmt.Printf(Color(format), a...)
} | [
"func",
"Printf",
"(",
"format",
"string",
",",
"a",
"...",
"interface",
"{",
"}",
")",
"(",
"n",
"int",
",",
"err",
"error",
")",
"{",
"return",
"fmt",
".",
"Printf",
"(",
"Color",
"(",
"format",
")",
",",
"a",
"...",
")",
"\n",
"}"
] | // Printf is a convenience wrapper for fmt.Printf with support for color codes.
//
// Printf formats according to a format specifier and writes to standard output
// with support for color codes. It returns the number of bytes written and any
// write error encountered. | [
"Printf",
"is",
"a",
"convenience",
"wrapper",
"for",
"fmt",
".",
"Printf",
"with",
"support",
"for",
"color",
"codes",
".",
"Printf",
"formats",
"according",
"to",
"a",
"format",
"specifier",
"and",
"writes",
"to",
"standard",
"output",
"with",
"support",
"... | d06e56a500db4d08c33db0b79461e7c9beafca2d | https://github.com/mitchellh/colorstring/blob/d06e56a500db4d08c33db0b79461e7c9beafca2d/colorstring.go#L211-L213 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.