huntlabs / hunt

A refined core library for D programming language. The module has concurrency / collections / event / io / logging / text / serialization and more.
Apache License 2.0
95 stars 15 forks source link

Configuration support array #30

Closed zoujiaqing closed 5 years ago

zoujiaqing commented 5 years ago

test.conf

server.addreses = 127.0.0.1:8080
server.addreses = 127.0.0.1:9090

D Code:

class ServerConf
{
    string addresses[];
}
Heromyth commented 5 years ago

test.conf

servers[0].listen = 8.8.6.1
servers[0].port = 81

servers[1].listen = 8.8.6.2
servers[1].port = 82

ages = 20, 30, 40
users = user01, user02, user03

The code

@Configuration("server")
struct ServerSettings
{
    @Value("listen")
    string ip = "127.0.0.1";
    ushort port = 8080;
}

class ArrayTestConfig {
    string name;
    int[] ages;
    string[] users;
    ServerSettings[] servers;
}