mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-06-06 06:06:49 +00:00

* [NOD-303] Implement get transaction by id for api server * [NOD-303] Make routeParamTxID a constant * [NOD-303] Change database is not current error. * [NOD-303] Add ID to TransactionInput and TransactionOutput models * [NOD-303] Change transactions_outputs table name to transaction_outputs and transactions_inputs to transaction_inputs * [NOD-303] Add json annotations to transaction response types * [NOD-303] Split server package * [NOD-303] Add GetTransactionByHashHandler * [NOD-303] Add comments to exported functions and variables * [NOD-303] Put response types in a separate file * [NOD-303] Rename functions
66 lines
2.2 KiB
Go
66 lines
2.2 KiB
Go
package config
|
|
|
|
import (
|
|
"errors"
|
|
"github.com/daglabs/btcd/apiserver/logger"
|
|
"github.com/daglabs/btcd/util"
|
|
"github.com/jessevdk/go-flags"
|
|
"path/filepath"
|
|
)
|
|
|
|
const (
|
|
defaultLogFilename = "apiserver.log"
|
|
defaultErrLogFilename = "apiserver_err.log"
|
|
)
|
|
|
|
var (
|
|
// Default configuration options
|
|
defaultLogDir = util.AppDataDir("apiserver", false)
|
|
defaultDBAddr = "localhost:3306"
|
|
defaultHTTPListen = "0.0.0.0:8080"
|
|
)
|
|
|
|
// Config defines the configuration options for the API server.
|
|
type Config struct {
|
|
LogDir string `long:"logdir" description:"Directory to log output."`
|
|
RPCUser string `short:"u" long:"rpcuser" description:"RPC username" required:"true"`
|
|
RPCPassword string `short:"P" long:"rpcpass" default-mask:"-" description:"RPC password" required:"true"`
|
|
RPCServer string `short:"s" long:"rpcserver" description:"RPC server to connect to" required:"true"`
|
|
RPCCert string `short:"c" long:"rpccert" description:"RPC server certificate chain for validation"`
|
|
DisableTLS bool `long:"notls" description:"Disable TLS"`
|
|
DBAddress string `long:"dbaddress" description:"Database address"`
|
|
DBUser string `long:"dbuser" description:"Database user" required:"true"`
|
|
DBPassword string `long:"dbpass" description:"Database password" required:"true"`
|
|
DBName string `long:"dbname" description:"Database name" required:"true"`
|
|
HTTPListen string `long:"listen" description:"HTTP address to listen on (default: 0.0.0.0:8080)"`
|
|
}
|
|
|
|
// Parse parses the CLI arguments and returns a config struct.
|
|
func Parse() (*Config, error) {
|
|
cfg := &Config{
|
|
LogDir: defaultLogDir,
|
|
DBAddress: defaultDBAddr,
|
|
HTTPListen: defaultHTTPListen,
|
|
}
|
|
parser := flags.NewParser(cfg, flags.PrintErrors|flags.HelpFlag)
|
|
_, err := parser.Parse()
|
|
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if cfg.RPCCert == "" && !cfg.DisableTLS {
|
|
return nil, errors.New("--notls has to be disabled if --cert is used")
|
|
}
|
|
|
|
if cfg.RPCCert != "" && cfg.DisableTLS {
|
|
return nil, errors.New("--cert should be omitted if --notls is used")
|
|
}
|
|
|
|
logFile := filepath.Join(cfg.LogDir, defaultLogFilename)
|
|
errLogFile := filepath.Join(cfg.LogDir, defaultErrLogFilename)
|
|
logger.InitLog(logFile, errLogFile)
|
|
|
|
return cfg, nil
|
|
}
|