mirror of
https://github.com/aljazceru/nigiri.git
synced 2026-01-16 04:54:29 +01:00
Changes for new version of esplora image (#62)
* changes for new version of esplora image * add electrs port and esplora url env vars in compose yaml files * wrap viper methods into Config type and use constants package * add controller to interact with nigiri resources: * .env for docker-compose * docker daemon * json config file * add use of constants and config packages and change start flag from --port to --env * add package for global constants and variables * add use of controller and constants packages instead of local methods and vars * bump version * use contants in logs command tests
This commit is contained in:
committed by
Marco Argentieri
parent
d0b3676c14
commit
e02c2fdd0d
58
cli/controller/parser.go
Normal file
58
cli/controller/parser.go
Normal file
@@ -0,0 +1,58 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/vulpemventures/nigiri/cli/constants"
|
||||
)
|
||||
|
||||
// Parser implements functions for parsing flags, JSON files
|
||||
// and system directories passed to the CLI commands
|
||||
type Parser struct {
|
||||
services map[string]bool
|
||||
}
|
||||
|
||||
func newParser(services map[string]bool) *Parser {
|
||||
p := &Parser{services}
|
||||
return p
|
||||
}
|
||||
|
||||
func (p *Parser) parseNetwork(network string) error {
|
||||
for _, n := range constants.AvaliableNetworks {
|
||||
if network == n {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
return constants.ErrInvalidNetwork
|
||||
}
|
||||
|
||||
func (p *Parser) parseDatadir(path string) error {
|
||||
if !filepath.IsAbs(path) {
|
||||
return constants.ErrInvalidDatadir
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *Parser) parseEnvJSON(strJSON string) (string, error) {
|
||||
// merge default json and incoming json by parsing DefaultEnv to
|
||||
// envJSON type and then parsing the incoming json using the same variable
|
||||
var parsedJSON envJSON
|
||||
defaultJSON, _ := json.Marshal(constants.DefaultEnv)
|
||||
json.Unmarshal(defaultJSON, &parsedJSON)
|
||||
err := json.Unmarshal([]byte(strJSON), &parsedJSON)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return "", constants.ErrMalformedJSON
|
||||
}
|
||||
merged, _ := json.Marshal(parsedJSON)
|
||||
return string(merged), nil
|
||||
}
|
||||
|
||||
func (p *Parser) parseServiceName(name string) error {
|
||||
if !p.services[name] {
|
||||
return constants.ErrInvalidServiceName
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user