This commit is contained in:
parent
2bceac7f85
commit
affae5941b
29
config.go
Normal file
29
config.go
Normal file
@ -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
|
||||||
|
}
|
2
go.mod
2
go.mod
@ -5,3 +5,5 @@ go 1.17
|
|||||||
require github.com/google/uuid v1.3.0
|
require github.com/google/uuid v1.3.0
|
||||||
|
|
||||||
require github.com/go-chi/chi/v5 v5.0.7
|
require github.com/go-chi/chi/v5 v5.0.7
|
||||||
|
|
||||||
|
require github.com/pelletier/go-toml v1.9.4 // indirect
|
||||||
|
2
go.sum
2
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/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 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
|
||||||
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
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=
|
||||||
|
6
gpaste-server.toml
Normal file
6
gpaste-server.toml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
LogLevel = "INFO"
|
||||||
|
URL = "http://paste.example.org"
|
||||||
|
ListenAddr = ":8080"
|
||||||
|
|
||||||
|
[Store]
|
||||||
|
Type = "memory"
|
Loading…
Reference in New Issue
Block a user