mirror of
https://github.com/aljazceru/nigiri.git
synced 2025-12-18 23:04:24 +01:00
* 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
59 lines
1.3 KiB
Go
59 lines
1.3 KiB
Go
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
|
|
}
|