go-akka / configuration Goto Github PK
View Code? Open in Web Editor NEWtypesafe HOCON
License: Apache License 2.0
typesafe HOCON
License: Apache License 2.0
According to API Recommendations booleans may have 6 valid values ("true", "false", "on", "off", "yes", "no"), but they are not fully supported in the library. It supports first four and in lower case only. I suggest to support all of them case insensitively.
sample.conf
server {
addr: 239.0.0.1
addr: 224.0.0.0
}
expect get server.addr is 224.0.0.0 but got 239.0.0.1
HoconValue.isString not just match string
key:[1,ab]
on key
1
is also treat as string,should it be know as NONE string?
What I guess how does WithFallback() method work... based experiences of Java version
is like this...
refConf := configuration.Parse("reference.conf")
myConf := configuration.Parse("my.conf")
conf := myConf.WithFallback(refConf)
But actually it had to be applied in opposite way to achieve correct result
conf := refConf.WithFallback(myConf)
Is this intended design?
Hi!
Would be cool to support toMap() map[string]interface{}
method to simplify JSON-to-HOCON code replacement in the apps.
i.e. I have an app where I use JSON as a configuration format, now I want to use HOCON. My old code was converting JSON string to map[string]interface{}
and expected it as the result, so I want to replace only the parsing part.
Thanks!
Hi!
Trying your library. Looks like there is a bug with object concatenation
I'm getting:
fatal error: stack overflow
runtime stack:
runtime.throw(0x4e3ece, 0xe)
/usr/local/go/src/runtime/panic.go:566 +0x95
runtime.newstack()
/usr/local/go/src/runtime/stack.go:1061 +0x416
runtime.morestack()
/usr/local/go/src/runtime/asm_amd64.s:366 +0x7f
goroutine 1 [running]:
github.com/go-akka/configuration/hocon.(*HoconSubstitution).IsString(0xc42000e4e0, 0x0)
/go/src/github.com/go-akka/configuration/hocon/substitution.go:12 fp=0xc44008c2c0 sp=0xc44008c2b8
github.com/go-akka/configuration/hocon.(*HoconValue).IsString(0xc42000e340, 0x0)
/go/src/github.com/go-akka/configuration/hocon/value.go:45 +0x5b fp=0xc44008c300 sp=0xc44008c2c0
github.com/go-akka/configuration/hocon.(*HoconSubstitution).IsString(0xc42000e4e0, 0x0)
/go/src/github.com/go-akka/configuration/hocon/substitution.go:13 +0x2f fp=0xc44008c320 sp=0xc44008c300
github.com/go-akka/configuration/hocon.(*HoconValue).IsString(0xc42000e340, 0x0)
/go/src/github.com/go-akka/configuration/hocon/value.go:45 +0x5b fp=0xc44008c360 sp=0xc44008c320
github.com/go-akka/configuration/hocon.(*HoconSubstitution).IsString(0xc42000e4e0, 0x0)
/go/src/github.com/go-akka/configuration/hocon/substitution.go:13 +0x2f fp=0xc44008c380 sp=0xc44008c360
github.com/go-akka/configuration/hocon.(*HoconValue).IsString(0xc42000e340, 0x0)
/go/src/github.com/go-akka/configuration/hocon/value.go:45 +0x5b fp=0xc44008c3c0 sp=0xc44008c380
github.com/go-akka/configuration/hocon.(*HoconSubstitution).IsString(0xc42000e4e0, 0x0)
/go/src/github.com/go-akka/configuration/hocon/substitution.go:13 +0x2f fp=0xc44008c3e0 sp=0xc44008c3c0
github.com/go-akka/configuration/hocon.(*HoconValue).IsString(0xc42000e340, 0x0)
/go/src/github.com/go-akka/configuration/hocon/value.go:45 +0x5b fp=0xc44008c420 sp=0xc44008c3e0
github.com/go-akka/configuration/hocon.(*HoconSubstitution).IsString(0xc42000e4e0, 0x0)
/go/src/github.com/go-akka/configuration/hocon/substitution.go:13 +0x2f fp=0xc44008c440 sp=0xc44008c420
github.com/go-akka/configuration/hocon.(*HoconValue).IsString(0xc42000e340, 0x0)
/go/src/github.com/go-akka/configuration/hocon/value.go:45 +0x5b fp=0xc44008c480 sp=0xc44008c440
github.com/go-akka/configuration/hocon.(*HoconSubstitution).IsString(0xc42000e4e0, 0x0)
with:
package main
import (
"fmt"
"github.com/go-akka/configuration"
)
var configText = `
test: yo, "test2":123, foo: [ 1 ], foo: ${foo} [ 2 ]
`
func main() {
conf := configuration.ParseString(configText)
fmt.Println("result:", conf.String())
}
When trying to overwrite a variable with an optional substitution, if the substitution cannot be resolved the last value of the variable should be kept.
The variable's value is overwritten by the empty string.
With the DATABASE_URL
environment variable not being set:
package main
import (
"fmt"
"github.com/go-akka/configuration"
)
var cfg = `
url = "root:@tcp(127.0.0.1:3306)/table?parseTime=True&loc=Local"
url = ${?DATABASE_URL}
`
func main() {
conf := configuration.ParseString(cfg)
fmt.Println("url =", conf.GetString("url"))
// Output: url =
// Expected: url = root:@tcp(127.0.0.1:3306)/table?parseTime=True&loc=Local
}
I tried to inspect the code and I think the problem appears because GetOrCreateKey()
(https://github.com/go-akka/configuration/blob/master/hocon/parser.go#L90) moves the values into the oldValue
variable which is never used when handling optional substitution.
I would be happy to start a PR if someone could point me in the right direction :)
if I use in my configuration file * .hocon in a field, for example, a port (this is an int type) and try to get this value using getInt32, I get a panic because in this field I typed this:
test {
port = 1231dsf
}
It is necessary in this case to return the error interface, because in this case I will have a default value.
ParseString
either returns a result (which is never nil), or it panics. There's no way to use the library to detect and handle parsing problems
Looks like the code tries to take into account of quotes in path: https://github.com/go-akka/configuration/blob/master/config.go#L326
func splitDottedPathHonouringQuotes(path string) []string {
tmp1 := strings.Split(path, "\"")
var values []string
for i := 0; i < len(tmp1); i++ {
tmp2 := strings.Split(tmp1[i], ".")
for j := 0; j < len(tmp2); j++ {
if len(tmp2[j]) > 0 {
values = append(values, tmp2[j])
}
}
}
return values
}
but it doesn't seem to work as intended. Attempts to look up a path containing quoted nodes doesn't work:
val := config.GetString("a.\"b.c\"")
// val is ""
instead, I have to do the following:
a := config.GetNode("a")
bc := a.GetChildObject("b.c")
val := bc.GetString()
// val has the correct value
The correct behavior is documented in https://github.com/lightbend/config/blob/master/HOCON.md#path-expressions
test.conf as
packets: [
{
data = 1
}
}
The README says some HOCON features are not implemented but doesn't say which ones.
I was expecting test.g3.o1.order
to return 1. Mind you the code does not raise an error now but it also does not return a correct value. As such i was not sure if this is supported or no ?
test.g1={
o1 {
order = 1
}
}
test.g2 = {
o2 {
order = 2
}
}
test.g3 = ${test.g1}
test.g3 = {
o2 {
order = 2
}
}
//or another more eaiser syntax way
test.g3 = ${test.g1} {
o2 {
order = 2
}
}
func TestInheritance(t *testing.T) {
conf := LoadConfig("tests/t3.conf")
fmt.Println("test.g3:", conf.GetInt64("test.g3.o1.order"))
}
Thanks !
Is it possible to provide more API like GetInt8, GetInt16, GetUint8,....?
Does not parse strings that are urls such as the following:
website: https://www.google.com/
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.