diff --git a/config.go b/config.go new file mode 100644 index 0000000..dd99385 --- /dev/null +++ b/config.go @@ -0,0 +1,29 @@ +package gpaste + +import ( + "fmt" + "io" + + "github.com/pelletier/go-toml" +) + +type ServerConfig struct { + LogLevel string `toml:"LogLevel"` + URL string `toml:"URL"` + ListenAddr string `toml:"ListenAddr"` + Store *ServerStoreConfig `toml:"Store"` +} + +type ServerStoreConfig struct { + Type string `toml:"Type"` +} + +func ServerConfigFromReader(r io.Reader) (*ServerConfig, error) { + decoder := toml.NewDecoder(r) + var c ServerConfig + if err := decoder.Decode(&c); err != nil { + return nil, fmt.Errorf("error decoding server config: %w", err) + } + + return &c, nil +} diff --git a/go.mod b/go.mod index 6cae926..19d317b 100644 --- a/go.mod +++ b/go.mod @@ -5,3 +5,5 @@ go 1.17 require github.com/google/uuid v1.3.0 require github.com/go-chi/chi/v5 v5.0.7 + +require github.com/pelletier/go-toml v1.9.4 // indirect diff --git a/go.sum b/go.sum index aff816d..af8ffdc 100644 --- a/go.sum +++ b/go.sum @@ -2,3 +2,5 @@ github.com/go-chi/chi/v5 v5.0.7 h1:rDTPXLDHGATaeHvVlLcR4Qe0zftYethFucbjVQ1PxU8= github.com/go-chi/chi/v5 v5.0.7/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8= github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/pelletier/go-toml v1.9.4 h1:tjENF6MfZAg8e4ZmZTeWaWiT2vXtsoO6+iuOjFhECwM= +github.com/pelletier/go-toml v1.9.4/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c= diff --git a/gpaste-server.toml b/gpaste-server.toml new file mode 100644 index 0000000..473dc41 --- /dev/null +++ b/gpaste-server.toml @@ -0,0 +1,6 @@ +LogLevel = "INFO" +URL = "http://paste.example.org" +ListenAddr = ":8080" + +[Store] +Type = "memory"