func NewServer(confPath string, setup PipelineSetupFunc) (*OsInstallServer, error) { conf, err := jsonconf.New(confPath).Load() if err != nil { return nil, err } log := logger.NewBeeLogger(conf) repo, err := mysqlrepo.NewRepo(conf, log) if err != nil { return nil, err } api := rest.NewAPI() api.Use(setup(conf, log, repo)...) // routes a global router, err := rest.MakeRouter(routes...) api.SetApp(router) server := &OsInstallServer{ Conf: conf, Log: log, Repo: repo, handler: api.MakeHandler(), } return server, nil }
// New create agent func New() (*OSInstallAgent, error) { // get config var conf, err = iniconf.NewContent([]byte(confContent)).Load() if err != nil { return nil, err } var log = logger.NewBeeLogger(conf) var agent = &OSInstallAgent{ Config: conf, Logger: log, } // var data []byte // // get sn // agent.Logger.Debug("START to get SN") // if data, err = execScript(GetSNScript); err != nil { // agent.Logger.Error(data) // agent.Logger.Error(err) // return nil, fmt.Errorf("get SN error: \n#%s\n%v\n%s", GetSNScript, err, string(data)) // } // agent.Sn = string(data) // agent.Sn = strings.Trim(agent.Sn, "\n") // agent.Logger.Debugf("SN: %s", agent.Sn) // get mac addr by sysinfo.sh // get mac addr // agent.Logger.Debug("START to get mac addr") // if data, err = execScript(GetMacScript); err != nil { // agent.Logger.Error(data) // log.Error(err) // return nil, fmt.Errorf("get mac addr error: \n#%s\n%v\n%s", GetMacScript, err, string(data)) // } // agent.MacAddr = string(data) // agent.MacAddr = strings.Trim(agent.MacAddr, "\n") // agent.Logger.Debugf("Mac ADDR: %s", agent.MacAddr) var serverAddr = "" // get server addr agent.Logger.Debug("START to get SERVER_ADDR") if serverAddr, err = getCmdlineArgs(RegexpServerAddr); err != nil { return nil, err } agent.ServerAddr = serverAddr // agent.ServerAddr = "http://10.0.0.135:8083" agent.ServerAddr = strings.Trim(agent.ServerAddr, "\n") agent.Logger.Debugf("SERVER_ADDR: %s", agent.ServerAddr) // loop interval var interval string agent.Logger.Debug("START to get LOOP_INTERVAL") if interval, err = getCmdlineArgs(RegexpLoopInterval); err != nil { agent.Logger.Debug(err) agent.LoopInterval = defaultLoopInterval } else { agent.LoopInterval = parseInterval(interval) } agent.Logger.Debugf("LOOP_INTERVAL: %s", agent.LoopInterval) var developMode = "" agent.Logger.Debug("START to get DEVELOPER") if developMode, err = getCmdlineArgs(RegexpDeveloper); err != nil { agent.Logger.Debug(err) agent.DevelopeMode = "" } agent.DevelopeMode = developMode agent.DevelopeMode = strings.Trim(agent.DevelopeMode, "\n") agent.Logger.Debugf("DEVELOPER: %s", agent.DevelopeMode) return agent, nil }