This is a implementation of dim, which is built in python. But this time in go.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

87 lines
2.2 KiB

package main
import (
_ ""
_ ""
var (
configPath = flag.String("config", "dim.conf", "path to the config file")
type (
Config struct {
Listen string `toml:"listen"`
DB struct {
Type string `toml:"type"`
Connection string `toml:"conn"`
} `toml:"db"`
Debug bool `toml:"debug_mode"`
func main() {
cfg := Config{}
raw, err := toml.LoadFile(*configPath)
if err != nil {
log.Fatalf("could not load config file '%s': %s", *configPath, err)
if err := raw.Unmarshal(&cfg); err != nil {
log.Fatalf("could not parse config file '%s': %s", *configPath, err)
if cfg.DB.Type != "mysql" && cfg.DB.Type != "postgres" {
"unknown database type '%s' in config '%s'. Allowed is 'mysql' and 'postgres'",
if strings.Trim(cfg.DB.Connection, " \t\n\r") == "" {
log.Fatalf("no database connection string in config '%s' set", *configPath)
db, err := sql.Open(cfg.DB.Type, cfg.DB.Connection)
if err != nil {
log.Fatalf("could not open database connection: %s", err)
s, err := NewServer(db, cfg.Debug)
if err != nil {
log.Fatalf("could not create server instance: %s", err)
s.Register("layer3domain_create", layer3DomainCreate)
s.Register("layer3domain_list", layer3DomainList)
s.Register("layer3domain_get_attr", layer3DomainGetAttr)
s.Register("layer3domain_set_attr", layer3DomainSetAttr)
s.Register("ipblock_create", containerCreate)
s.Register("ipblock_remove", containerDelete)
s.Register("ipblock_list", containerList)
s.Register("ipblock_set_attr", containerSetAttr)
s.Register("ipblock_get_attr", containerGetAttr)
s.Register("ippool_create", PoolCreate)
s.Register("ippool_delete", PoolDelete)
s.Register("ippool_list", PoolList)
s.Register("ippool_get_attr", PoolGetAttr)
s.Register("ippool_set_attr", PoolSetAttr)
s.Register("zone_create", zoneCreate)
s.Register("zone_list", zoneList)
http.HandleFunc("/dim", s.Handle)
log.Fatal(http.ListenAndServe(cfg.Listen, nil))