Comments (4)
You can use a field tag to tell exactly how the name should look like:
ReportSeconds int64 `yaml:"reportSeconds"`
from yaml.
By the way, there's full documentation for these options at:
http://gopkg.in/yaml.v2#Marshal
from yaml.
Oh sorry, thanks for the help!
from yaml.
You can use a field tag to tell exactly how the name should look like:
ReportSeconds int64 `yaml:"reportSeconds"`
it doesnt work
the yaml file:
max: 1
maxIdleConnections: 10
max_open_connections: 10
the demo code here:
package main
import (
"fmt"
"gopkg.in/yaml.v3"
"io/ioutil"
)
func main() {
// 加载配置
var d Database
d.LoadConfig("config.yaml")
fmt.Println(d.Max)
fmt.Println(d.MaxOpenConnections)
fmt.Println(d.MaxOpenConnections)
}
// 映射 总配置信息
type Database struct {
Max int `yaml: "max"`
MaxIdleConnections int64 `yaml: "maxIdleConnections"`
MaxOpenConnections int64 `yaml: 'max_open_connections'`
}
func (configuration *Database)LoadConfig(filename string){
//应该是 绝对地址
yamlFile, err := ioutil.ReadFile(filename)
if err != nil {
fmt.Println(err.Error())
}
err = yaml.Unmarshal(yamlFile, configuration)
if err != nil {
fmt.Println(err.Error())
}
}
and the output here
1
0
0
explain: the first line which key is max was parse correctly, and it doesnt work for yaml: "maxIdleConnections"
and yaml: 'max_open_connections'
from yaml.
Related Issues (20)
- v3 skips blank elements in a sequence whereas v2 does not HOT 1
- Different behaviors between this library and standard encoding/json when unmarshal yaml to a struct embedded with other structs HOT 1
- Force marshaler to use multi-line for string with `\n` HOT 1
- Empty `!!null` node fails encoding and causes panic
- Comments rendering issue related to array nodes
- Yaml encoder writing tag of merge node `!!merge` in output HOT 1
- Untagged field names "y" and "n" marshalled with quotes, others not HOT 6
- Custom (Un-)Marshaller on Generic Types ignored
- mining
- Incorrect RC3339 encoding HOT 1
- YAML parsing is not as expected HOT 2
- Yea
- yaml omitempty HOT 2
- `flow` and `inline` structure tags don't work together
- Increased memory consumption when serializing long slices.
- Module abandoned? HOT 4
- Merge doesn't work as expected
- Unmarshal drops lines and does not return error HOT 1
- Encode does not respect Style = LiteralStyle
- Does the documentation for Decoder.KnownFields make grammatical sense?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from yaml.