Commit 6bccc21f authored by jonas's avatar jonas

Add AllowWrite options

parent 4b7d0581
Pipeline #728 failed with stage
in 40 seconds
......@@ -35,6 +35,7 @@ func NewApp(config *Config) *App {
// NewServer creates a server from a new app
func NewServer(config *Config) *App {
config.AllowWrite = true
a := NewApp(config)
a.router = NewRouter(a)
......
......@@ -9,6 +9,8 @@ import (
// Config defines the application configuration
type Config struct {
AllowWrite bool
ListenAddr string `default:"127.0.0.1:7000" yaml:"listen_addr"`
Verbose bool `default:"false" yaml:"verbose"`
SendInterval string `default:"1h" yaml:"send_interval"`
......
......@@ -12,6 +12,7 @@ func newTestConfig() *Config {
}
return &Config{
AllowWrite: true,
PublicURL: "http://127.0.0.1:7000",
Database: tmpfile.Name(),
WebhookUser: "user",
......
......@@ -13,11 +13,18 @@ var (
// NewStore creates a store
func NewStore(a *App) *bolt.DB {
db, err := bolt.Open(a.config.Database, 0600, nil)
ReadOnly := !a.config.AllowWrite
log.Printf("opening database=%s readonly=%t\n", a.config.Database, ReadOnly)
db, err := bolt.Open(a.config.Database, 0600, &bolt.Options{ReadOnly: ReadOnly})
if err != nil {
log.Fatalln(err)
}
if ReadOnly {
return db
}
if err := db.Update(func(tx *bolt.Tx) error {
if _, err := tx.CreateBucketIfNotExists(eventsBucketKey); err != nil {
return err
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment