Skip to content

Commit

Permalink
Assert config/pkg version equality before startup
Browse files Browse the repository at this point in the history
  • Loading branch information
a-hilaly committed Aug 13, 2018
1 parent b9bece6 commit dbc6bd8
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
6 changes: 3 additions & 3 deletions cmd/start/server_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,13 @@ func runServer() {
var configuration *config.StartupConfig

if cfg, err := config.LoadConfigFromPath(configFile); err != nil {
log.Panic(err)
log.Fatal(err)
} else {
configuration = cfg
}

if err := initpkg.InitFromConfig(configuration); err != nil {
log.Panic(err)
log.Fatal(err)
}

if syncdb {
Expand All @@ -102,7 +102,7 @@ func runServer() {
}
}
if err != nil {
panic(err)
log.Fatal(err)
}
fmt.Println("connected to database...")
}
Expand Down
3 changes: 2 additions & 1 deletion config.local.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
meta:
name: medtune beta platform
description: beta test
description: medtune beta test
version: v0.1.1
prod: true

database:
Expand Down
8 changes: 7 additions & 1 deletion pkg/initpkg/init.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package initpkg

import (
"fmt"
"log"

"github.com/medtune/beta-platform/pkg"
"github.com/medtune/beta-platform/pkg/service/capsul"

tfsclient "github.com/medtune/capsul/pkg/tfs-client"
Expand All @@ -15,7 +17,7 @@ import (
"github.com/medtune/go-utils/random"
)

// Init packages from configuration file
// InitFromFile from configuration file
func InitFromFile(file string) error {
config, err := config.LoadConfigFromPath(file)
if err != nil {
Expand All @@ -31,6 +33,10 @@ func InitFromFile(file string) error {

// InitFromConfig uration file
func InitFromConfig(c *config.StartupConfig) error {
// Check version
if c.Meta.Version != pkg.VERSION {
return fmt.Errorf("Configuration meta version did'nt match\n\tpackage version: %v\n\tconfigs version: %v", pkg.VERSION, c.Meta.Version)
}
// init package pkg/session
if err := initSession(c.Session); err != nil {
return err
Expand Down

0 comments on commit dbc6bd8

Please sign in to comment.