Comments (7)
It's pretty straightforward:
handlers, err := yaml.Child(config.Root, "handlers")
// handle err
lst, ok := handlers.(yaml.List)
// handle !ok
for i := 0; i < lst.Len(); i++ {
node := lst.Item(i);
// use node
}
from go-gypsy.
Hmm. i can't do this:
config, err := yaml.ReadFile(dst+"/app.yaml")
if err != nil {
fmt.Printf("readfile(%q): %s", dst+"/app.yaml", err)
}
handlers, err := config.Get("handlers")
lst, ok := handlers.(yaml.List)
if !ok {
return
}
for i := 0; i < lst.Len(); i++ {
node := lst.Item(i)
vals := node.(yaml.Map)
fmt.Printf("%+v\n%+T\n", vals, vals)
}
go builds says:
invalid type assertion: handlers.(yaml.List) (non-interface type string on left)
from go-gypsy.
oh, you probably have to use yaml.Child to get the Node out.
from go-gypsy.
Code:
handlers, err := yaml.Child(config.Root, "handlers")
if err != nil {
return
}
lst, ok := handlers.(yaml.List)
if !ok {
return
}
for i := 0; i < lst.Len(); i++ {
node := lst.Item(i)
vals := node.(yaml.Map)
fmt.Printf("%+v\n%+T\n", vals, vals)
}
Produces:
interface conversion: interface is nil, not yaml.Map
from go-gypsy.
types.go needs changing:
diff --git a/yaml/types.go b/yaml/types.go
index c28ed61..ceaf4c6 100644
--- a/yaml/types.go
+++ b/yaml/types.go
@@ -69,7 +69,7 @@ func (node List) Len() int {
// Get the idx'th item from the List.
func (node List) Item(idx int) Node {
- if idx < 0 || idx > len(node) {
+ if idx >= 0 && idx < node.Len() {
return node[idx]
}
return nil
After that all works fine.
from go-gypsy.
Oh dear! If you want to submit a pull request, I'd be happy to pull it and credit you for the fix :).
from go-gypsy.
done
from go-gypsy.
Related Issues (10)
- multi-line string support HOT 3
- Issue getting a List HOT 4
- Problems with multi-line strings HOT 3
- Scalar can't contain colon (":") HOT 1
- formal specification HOT 2
- the scalar can't start with '-'
- Issue in termination of multiline string with indentation HOT 3
- TestLineBreak fails
- Not enough examples/documentation on usage
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 go-gypsy.