mirror of
				https://github.com/xiaoqidun/goini.git
				synced 2025-10-29 22:49:37 +08:00 
			
		
		
		
	Compare commits
	
		
			6 Commits
		
	
	
		
			v1.0.0
			...
			09ce6a39f0
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 09ce6a39f0 | |||
| b8fd6932d7 | |||
| 6310bae091 | |||
| 0eb4132cab | |||
| fce8036b7c | |||
| 4349dffbe5 | 
							
								
								
									
										10
									
								
								.drone.yml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								.drone.yml
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,10 @@ | |||||||
|  | kind: pipeline | ||||||
|  | type: docker | ||||||
|  | name: default | ||||||
|  |  | ||||||
|  | steps: | ||||||
|  |   - name: build | ||||||
|  |     pull: if-not-exists | ||||||
|  |     image: golang | ||||||
|  |     commands: | ||||||
|  |       - go build goini.go | ||||||
| @@ -1,4 +1,4 @@ | |||||||
| # GoINI | # GoINI[](https://pkg.go.dev/github.com/xiaoqidun/goini) | ||||||
| 简单易用的Golang INI配置解析库 | 简单易用的Golang INI配置解析库 | ||||||
| # 安装方法 | # 安装方法 | ||||||
| go get -u github.com/xiaoqidun/goini | go get -u github.com/xiaoqidun/goini | ||||||
|   | |||||||
							
								
								
									
										14
									
								
								goini.go
									
									
									
									
									
								
							
							
						
						
									
										14
									
								
								goini.go
									
									
									
									
									
								
							| @@ -12,6 +12,7 @@ import ( | |||||||
|  |  | ||||||
| // GoINI GoINI数据结构 | // GoINI GoINI数据结构 | ||||||
| type GoINI struct { | type GoINI struct { | ||||||
|  | 	tag         string | ||||||
| 	data        []byte | 	data        []byte | ||||||
| 	dataMap     map[string]map[string]string | 	dataMap     map[string]map[string]string | ||||||
| 	nameList    []string | 	nameList    []string | ||||||
| @@ -22,6 +23,7 @@ type GoINI struct { | |||||||
| // NewGoINI 获取GoINI对象 | // NewGoINI 获取GoINI对象 | ||||||
| func NewGoINI() *GoINI { | func NewGoINI() *GoINI { | ||||||
| 	return &GoINI{ | 	return &GoINI{ | ||||||
|  | 		tag:         "goini", | ||||||
| 		commonField: "BuiltCommon", | 		commonField: "BuiltCommon", | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
| @@ -120,6 +122,11 @@ func (ini *GoINI) String() string { | |||||||
| 	return strings.Join(iniLines, "\n") | 	return strings.Join(iniLines, "\n") | ||||||
| } | } | ||||||
|  |  | ||||||
|  | // SetTag 设置结构体的tag键名称 | ||||||
|  | func (ini *GoINI) SetTag(tag string) { | ||||||
|  | 	ini.tag = tag | ||||||
|  | } | ||||||
|  |  | ||||||
| // SetData 从代码读取配置并解析 | // SetData 从代码读取配置并解析 | ||||||
| func (ini *GoINI) SetData(fileData []byte) { | func (ini *GoINI) SetData(fileData []byte) { | ||||||
| 	ini.data = bytes.TrimSpace(fileData) | 	ini.data = bytes.TrimSpace(fileData) | ||||||
| @@ -225,15 +232,14 @@ func (ini *GoINI) MapToStruct(ptr interface{}) (err error) { | |||||||
| 	if t.Kind() != reflect.Ptr { | 	if t.Kind() != reflect.Ptr { | ||||||
| 		err = errors.New("input struct ptr") | 		err = errors.New("input struct ptr") | ||||||
| 		return | 		return | ||||||
| 	} else { | 	} | ||||||
| 	t = t.Elem() | 	t = t.Elem() | ||||||
| 	v = v.Elem() | 	v = v.Elem() | ||||||
| 	} |  | ||||||
| 	for i := 0; i < t.NumField(); i++ { | 	for i := 0; i < t.NumField(); i++ { | ||||||
| 		if !v.CanInterface() { | 		if !v.CanInterface() { | ||||||
| 			continue | 			continue | ||||||
| 		} | 		} | ||||||
| 		k := t.Field(i).Tag.Get("goini") | 		k := t.Field(i).Tag.Get(ini.tag) | ||||||
| 		if k == "" { | 		if k == "" { | ||||||
| 			k = t.Field(i).Name | 			k = t.Field(i).Name | ||||||
| 		} | 		} | ||||||
| @@ -245,7 +251,7 @@ func (ini *GoINI) MapToStruct(ptr interface{}) (err error) { | |||||||
| 				if !v.CanInterface() { | 				if !v.CanInterface() { | ||||||
| 					continue | 					continue | ||||||
| 				} | 				} | ||||||
| 				kk := tt.Field(ii).Tag.Get("goini") | 				kk := tt.Field(ii).Tag.Get(ini.tag) | ||||||
| 				if kk == "" { | 				if kk == "" { | ||||||
| 					kk = t.Field(ii).Name | 					kk = t.Field(ii).Name | ||||||
| 				} | 				} | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user