package config

import (
	"path"

	"github.com/octavore/naga/service"
	"github.com/octavore/nagax/config"
)

const defaultDataDir = "data"

type Config struct {
	DataDir string `json:"data_dir"` // themes, plugins
}

type Module struct {
	*config.Module
	Config Config
}

func (m *Module) Init(c *service.Config) {
	c.Setup = func() error {
		err := m.ReadConfig(&m.Config)
		if err != nil {
			return err
		}
		if m.Config.DataDir == "" {
			m.Config.DataDir = defaultDataDir
		}
		return nil
	}
}

func (m *Module) DataPath(p, backup string) string {
	if p == "" {
		p = backup
	}
	return path.Join(m.Config.DataDir, p)
}

package config

import (
	"path"

	"github.com/octavore/naga/service"
	"github.com/octavore/nagax/config"
)

type Config struct {
	DataDir string `json:"data_dir"` // themes, plugins
}

type Module struct {
	*config.Module
	Config Config
}

func (m *Module) Init(c *service.Config) {
	c.Setup = func() error {
		return m.ReadConfig(&m.Config)
	}
}

func (m *Module) DataPath(p, backup string) string {
	if p == "" {
		p = backup
	}
	return path.Join(m.Config.DataDir, p)
}

--- 
+++ 
@@ -6,6 +6,8 @@
 	"github.com/octavore/naga/service"
 	"github.com/octavore/nagax/config"
 )
+
+const defaultDataDir = "data"
 
 type Config struct {
 	DataDir string `json:"data_dir"` // themes, plugins
@@ -18,7 +20,14 @@
 
 func (m *Module) Init(c *service.Config) {
 	c.Setup = func() error {
-		return m.ReadConfig(&m.Config)
+		err := m.ReadConfig(&m.Config)
+		if err != nil {
+			return err
+		}
+		if m.Config.DataDir == "" {
+			m.Config.DataDir = defaultDataDir
+		}
+		return nil
 	}
 }
 
server: Make ./data the default data dir.
