func NewConfig(args []string) (*Config, error) {
	config := &Config{}
	if len(args) == 0 {
		return config, errors.New("arguments cannot be empty")
	}
	config.FlagPort = defaultHTTPPort
	config.FlagGetRequestTimeout = defaultGETRequestTimeout
	flagSet := flag.NewFlagSet(dcosLog, flag.ContinueOnError)
	config.setFlags(flagSet)
	if err := flagSet.Parse(args[1:]); err != nil {
		return config, err
	}
	if err := readAndUpdateConfigFile(config); err != nil {
		return nil, err
	}
	if config.FlagVerbose {
		logrus.SetLevel(logrus.DebugLevel)
		logrus.Debug("Using debug level")
	}
	return config, validateConfigStruct(config)
}
NewConfig returns a new instance of Config with loaded fields.
package config
import (
	"encoding/json"
	"errors"
	"flag"
	"io/ioutil"
	"github.com/sirupsen/logrus"
	"github.com/xeipuuv/gojsonschema"
)
const (
	dcosLog                  = "dcos-log"
	defaultHTTPPort          = 8080
	defaultGETRequestTimeout = "5s"
)
var internalJSONValidationSchema = `
	{
	  "title": "User config validate schema",
	  "type": "object",
	  "properties": {
	    "port": {
	      "type": "integer",
	      "minimum": 1024,
	      "maximum": 65535
	    },
	    "verbose": {
	      "type": "boolean"
	    },
	    "config": {
	      "type": "string"
	    },
	    "auth": {
	      "type": "boolean"
	    },
	    "ca-cert": {
	      "type": "string"
	    },
	    "timeout": {
	      "type": "string"
	    },
	    "role": {
	      "type": "string",
	      "enum": ["master", "agent", "agent_public"]
	    }
	  },
	  "required": ["role"],
	  "additionalProperties": false
	}`
type Config struct {
	FlagPort int `json:"port"`
	FlagVerbose bool `json:"verbose"`
	FlagConfig string `json:"-"`
	FlagAuth bool `json:"auth"`
	FlagCACertFile string `json:"ca-cert"`
	FlagGetRequestTimeout string `json:"timeout"`
	FlagRole string `json:"role"`
}
func (c *Config) setFlags(fs *flag.FlagSet) {
	fs.IntVar(&c.FlagPort, "port", c.FlagPort, "Sets TCP port.")
	fs.BoolVar(&c.FlagVerbose, "verbose", c.FlagVerbose, "Print out verbose output.")
	fs.StringVar(&c.FlagConfig, "config", c.FlagConfig, "Use config file.")
	fs.BoolVar(&c.FlagAuth, "auth", c.FlagAuth, "Enable authorization.")
	fs.StringVar(&c.FlagCACertFile, "ca-cert", c.FlagCACertFile, "Use certificate authority.")
	fs.StringVar(&c.FlagGetRequestTimeout, "timeout", c.FlagGetRequestTimeout, "GET request timeout.")
	fs.StringVar(&c.FlagRole, "role", c.FlagRole, "Set node's role.")
}