• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang util.GetConfig函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/cloudwan/gohan/util.GetConfig函数的典型用法代码示例。如果您正苦于以下问题:Golang GetConfig函数的具体用法?Golang GetConfig怎么用?Golang GetConfig使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了GetConfig函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: TestExtensions

// TestExtensions runs extension tests when invoked from Gohan CLI
func TestExtensions(c *cli.Context) {
	buflog.SetUpDefaultLogging()

	var config *util.Config
	configFilePath := c.String("config-file")

	if configFilePath != "" && !c.Bool("verbose") {
		config = util.GetConfig()
		err := config.ReadConfig(configFilePath)
		if err != nil {
			log.Error(fmt.Sprintf("Failed to read config from path %s: %v", configFilePath, err))
			os.Exit(1)
		}

		err = gohan_log.SetUpLogging(config)
		if err != nil {
			log.Error(fmt.Sprintf("Failed to set up logging: %v", err))
			os.Exit(1)
		}
	}

	testFiles := getTestFiles(c.Args())

	//logging from config is a limited printAllLogs option
	returnCode := RunTests(testFiles, c.Bool("verbose") || config != nil, c.String("run-test"))
	os.Exit(returnCode)
}
开发者ID:cloudwan,项目名称:gohan,代码行数:28,代码来源:framework.go


示例2: startSyncWatchProcess

//Sync Watch Process
func startSyncWatchProcess(server *Server) {
	config := util.GetConfig()
	watch := config.GetStringList("watch/keys", nil)
	events := config.GetStringList("watch/events", nil)
	if watch == nil {
		return
	}
	extensions := map[string]extension.Environment{}
	for _, event := range events {
		path := "sync://" + event
		env, err := server.NewEnvironmentForPath("sync."+event, path)
		if err != nil {
			log.Fatal(err.Error())
		}
		extensions[event] = env
	}
	responseChan := make(chan *gohan_sync.Event)
	stopChan := make(chan bool)
	for _, path := range watch {
		go func(path string) {
			defer util.LogFatalPanic(log)
			for server.running {
				lockKey := lockPath + "watch"
				err := server.sync.Lock(lockKey, true)
				if err != nil {
					log.Warning("Can't start watch process due to lock", err)
					time.Sleep(5 * time.Second)
					continue
				}
				defer func() {
					server.sync.Unlock(lockKey)
				}()
				err = server.sync.Watch(path, responseChan, stopChan)
				if err != nil {
					log.Error(fmt.Sprintf("sync watch error: %s", err))
				}
			}
		}(path)
	}
	//main response lisnter process
	go func() {
		defer util.LogFatalPanic(log)
		for server.running {
			response := <-responseChan
			server.queue.Add(job.NewJob(
				func() {
					defer util.LogPanic(log)
					for _, event := range events {
						//match extensions
						if strings.HasPrefix(response.Key, "/"+event) {
							env := extensions[event]
							runExtensionOnSync(server, response, env.Clone())
							return
						}
					}
				}))
		}
	}()

}
开发者ID:vozhyk-,项目名称:gohan,代码行数:61,代码来源:sync.go


示例3: getGraceServerCommand

func getGraceServerCommand() cli.Command {
	return cli.Command{
		Name:        "glace-server",
		ShortName:   "gsrv",
		Usage:       "Run API Server with graceful restart support",
		Description: "Run Gohan API server with graceful restart support",
		Flags: []cli.Flag{
			cli.StringFlag{Name: "config-file", Value: defaultConfigFile, Usage: "Server config File"},
		},
		Action: func(c *cli.Context) {
			configFile := c.String("config-file")
			loadConfig(configFile)
			opts := &options{OptInterval: -1}
			opts.OptCommand = os.Args[0]
			config := util.GetConfig()
			opts.OptPorts = []string{config.GetString("address", ":9091")}
			opts.OptArgs = []string{"server", "--config-file", configFile}
			s, err := starter.NewStarter(opts)
			if err != nil {
				fmt.Fprintf(os.Stderr, "error: %s\n", err)
				return
			}
			s.Run()
		},
	}
}
开发者ID:vozhyk-,项目名称:gohan,代码行数:26,代码来源:cli.go


示例4: startAMQPProcess

//AMQP Process
func startAMQPProcess(server *Server) {
	config := util.GetConfig()
	enableAMQP := config.GetParam("amqp", nil)
	if enableAMQP == nil {
		return
	}
	listenAMQP(server)
}
开发者ID:marcin-ptaszynski,项目名称:gohan,代码行数:9,代码来源:amqp.go


示例5: startSNMPProcess

//SNMP Process
//Experimental
func startSNMPProcess(server *Server) {
	manager := schema.GetManager()
	config := util.GetConfig()
	enabled := config.GetParam("snmp", nil)
	if enabled == nil {
		return
	}
	host := config.GetString("snmp/address", "localhost:162")

	path := "snmp://"
	env := newEnvironment(server.db, server.keystoneIdentity, server.timelimit)
	err := env.LoadExtensionsForPath(manager.Extensions, path)
	if err != nil {
		log.Fatal(fmt.Sprintf("Extensions parsing error: %v", err))
	}

	addr, err := net.ResolveUDPAddr("udp", host)
	if err != nil {
		log.Fatal(err)
	}

	conn, err := net.ListenUDP("udp", addr)
	if err != nil {
		log.Fatal(err)
	}

	buf := make([]byte, 1024)
	go func() {
		defer conn.Close()
		for server.running {
			rlen, remote, err := conn.ReadFromUDP(buf)
			if err != nil {
				log.Error(fmt.Sprintf("[SNMP] failed read bytes %s", err))
				return
			}
			decoded, err := wapsnmp.DecodeSequence(buf[:rlen])
			if err != nil {
				log.Error(fmt.Sprintf("[SNMP] failed decode bytes %s", err))
				continue
			}
			infos := decoded[3].([]interface{})[4].([]interface{})[1:]
			trap := map[string]string{}
			for _, info := range infos {
				listInfo := info.([]interface{})
				oid := listInfo[1].(wapsnmp.Oid)
				trap[oid.String()] = fmt.Sprintf("%v", listInfo[2])
			}

			context := map[string]interface{}{
				"trap":   trap,
				"remote": remote,
			}
			if err := env.HandleEvent("notification", context); err != nil {
				log.Warning(fmt.Sprintf("extension error: %s", err))
			}
		}
	}()
}
开发者ID:masaki-saeki,项目名称:gohan,代码行数:60,代码来源:snmp.go


示例6: connectDB

func (server *Server) connectDB() error {
	config := util.GetConfig()
	dbType, dbConnection, _, _ := server.getDatabaseConfig()
	maxConn := config.GetInt("database/max_open_conn", db.DefaultMaxOpenConn)
	dbConn, err := db.ConnectDB(dbType, dbConnection, maxConn)
	if server.sync == nil {
		server.db = dbConn
	} else {
		server.db = &DbSyncWrapper{dbConn}
	}
	return err
}
开发者ID:vozhyk-,项目名称:gohan,代码行数:12,代码来源:server.go


示例7: startCRONProcess

//CRON Process
func startCRONProcess(server *Server) {
	manager := schema.GetManager()
	config := util.GetConfig()
	jobList := config.GetParam("cron", nil)
	if jobList == nil {
		return
	}
	log.Info("Started CRON process")
	c := cron.New()
	for _, rawJob := range jobList.([]interface{}) {
		job := rawJob.(map[string]interface{})
		path := job["path"].(string)
		timing := job["timing"].(string)
		env := newEnvironment(server.db, server.keystoneIdentity)
		err := env.LoadExtensionsForPath(manager.Extensions, path)
		if err != nil {
			log.Fatal(fmt.Sprintf("Extensions parsing error: %v", err))
		}
		log.Info("New job for %s / %s", path, timing)
		c.AddFunc(timing, func() {
			lockKey := lockPath + "/" + path
			err := server.sync.Lock(lockKey, false)
			if err != nil {
				return
			}
			defer func() {
				server.sync.Unlock(lockKey)
			}()
			tx, err := server.db.Begin()
			defer tx.Close()
			context := map[string]interface{}{
				"path": path,
			}
			if err != nil {
				log.Warning(fmt.Sprintf("extension error: %s", err))
				return
			}
			if err := env.HandleEvent("notification", context); err != nil {
				log.Warning(fmt.Sprintf("extension error: %s", err))
				return
			}
			err = tx.Commit()
			if err != nil {
				log.Warning(fmt.Sprintf("extension error: %s", err))
				return
			}
			return
		})
	}
	c.Start()
}
开发者ID:nati,项目名称:gohan,代码行数:52,代码来源:cron.go


示例8: getDatabaseConfig

func (server *Server) getDatabaseConfig() (string, string, bool, bool) {
	config := util.GetConfig()
	databaseType := config.GetString("database/type", "sqlite3")
	if databaseType == "json" || databaseType == "yaml" {
		log.Fatal("json or yaml isn't supported as main db backend")
	}
	databaseConnection := config.GetString("database/connection", "")
	if databaseConnection == "" {
		log.Fatal("no database connection specified in the configuraion file.")
	}
	databaseDropOnCreate := config.GetBool("database/drop_on_create", false)
	databaseCascade := config.GetBool("database/cascade_delete", false)
	return databaseType, databaseConnection, databaseDropOnCreate, databaseCascade
}
开发者ID:gitter-badger,项目名称:gohan,代码行数:14,代码来源:server.go


示例9: mapRoutes

func (server *Server) mapRoutes() {
	config := util.GetConfig()
	schemaManager := schema.GetManager()
	MapNamespacesRoutes(server.martini)
	MapRouteBySchemas(server, server.db)

	tx, err := server.db.Begin()
	if err != nil {
		log.Fatal(err)
	}
	defer tx.Close()
	coreSchema, _ := schemaManager.Schema("schema")
	if coreSchema == nil {
		log.Fatal("Gohan core schema not found")
		return
	}

	policySchema, _ := schemaManager.Schema("policy")
	policyList, _, err := tx.List(policySchema, nil, nil)
	if err != nil {
		log.Info(err.Error())
	}
	schemaManager.LoadPolicies(policyList)

	extensionSchema, _ := schemaManager.Schema("extension")
	extensionList, _, err := tx.List(extensionSchema, nil, nil)
	if err != nil {
		log.Info(err.Error())
	}
	schemaManager.LoadExtensions(extensionList)

	namespaceSchema, _ := schemaManager.Schema("namespace")
	if namespaceSchema == nil {
		log.Error("No gohan schema. Disabling schema editing mode")
		return
	}
	namespaceList, _, err := tx.List(namespaceSchema, nil, nil)
	if err != nil {
		log.Info(err.Error())
	}
	err = tx.Commit()
	if err != nil {
		log.Info(err.Error())
	}
	schemaManager.LoadNamespaces(namespaceList)

	if config.GetBool("keystone/fake", false) {
		middleware.FakeKeystone(server.martini)
	}
}
开发者ID:nati,项目名称:gohan,代码行数:50,代码来源:server.go


示例10: startCRONProcess

//CRON Process
func startCRONProcess(server *Server) {
	config := util.GetConfig()
	jobList := config.GetParam("cron", nil)
	if jobList == nil {
		return
	}
	if server.sync == nil {
		log.Fatalf(fmt.Sprintf("Could not start CRON process because of sync backend misconfiguration."))
		util.LogFatalPanic(log)
	}
	log.Info("Started CRON process")
	c := cron.New()
	for _, rawJob := range jobList.([]interface{}) {
		job := rawJob.(map[string]interface{})
		path := job["path"].(string)
		timing := job["timing"].(string)
		name := strings.TrimPrefix(path, "cron://")
		env, err := server.NewEnvironmentForPath(name, path)
		if err != nil {
			log.Fatal(err.Error())
		}
		log.Info("New job for %s / %s", path, timing)
		c.AddFunc(timing, func() {
			lockKey := lockPath + "/" + path
			err := server.sync.Lock(lockKey, false)
			if err != nil {
				return
			}
			defer func() {
				server.sync.Unlock(lockKey)
			}()
			context := map[string]interface{}{
				"path": path,
			}
			if err != nil {
				log.Warning(fmt.Sprintf("extension error: %s", err))
				return
			}
			if err := env.HandleEvent("notification", context); err != nil {
				log.Warning(fmt.Sprintf("extension error: %s", err))
				return
			}
			return
		})
	}
	c.Start()
}
开发者ID:cloudwan,项目名称:gohan,代码行数:48,代码来源:cron.go


示例11: doTemplate

func doTemplate(c *cli.Context) {
	template := c.String("template")
	manager := schema.GetManager()
	configFile := c.String("config-file")
	config := util.GetConfig()
	err := config.ReadConfig(configFile)
	if err != nil {
		util.ExitFatal(err)
		return
	}
	templateCode, err := util.GetContent(template)
	if err != nil {
		util.ExitFatal(err)
		return
	}
	pwd, _ := os.Getwd()
	os.Chdir(path.Dir(configFile))
	schemaFiles := config.GetStringList("schemas", nil)
	if schemaFiles == nil {
		util.ExitFatal("No schema specified in configuraion")
	} else {
		err = manager.LoadSchemasFromFiles(schemaFiles...)
		if err != nil {
			util.ExitFatal(err)
			return
		}
	}
	schemas := manager.OrderedSchemas()

	if err != nil {
		util.ExitFatal(err)
		return
	}
	tpl, err := pongo2.FromString(string(templateCode))
	if err != nil {
		util.ExitFatal(err)
		return
	}
	output, err := tpl.Execute(pongo2.Context{"schemas": schemas})
	if err != nil {
		util.ExitFatal(err)
		return
	}
	os.Chdir(pwd)
	fmt.Println(output)
}
开发者ID:vozhyk-,项目名称:gohan,代码行数:46,代码来源:template.go


示例12: loadNPMModules

func loadNPMModules() {
	config := util.GetConfig()
	npmPath := config.GetString("extension/npm_path", ".")
	files, _ := ioutil.ReadDir(npmPath + "/node_modules/")
	for _, f := range files {
		if f.IsDir() && !strings.HasPrefix(f.Name(), ".") {
			module, err := motto.FindFileModule(f.Name(), npmPath, nil)
			if err != nil {
				log.Error("Finding module failed %s in %s", err, f.Name())
				break
			}
			if !strings.HasSuffix(module, ".js") {
				module = module + "/index.js"
			}
			loader := motto.CreateLoaderFromFile(module)
			motto.AddModule(f.Name(), loader)
		}
	}
}
开发者ID:vozhyk-,项目名称:gohan,代码行数:19,代码来源:gohan_core.go


示例13: loadConfig

func loadConfig(configFile string) {
	if configFile == "" {
		return
	}
	config := util.GetConfig()
	err := config.ReadConfig(configFile)
	if err != nil {
		if configFile != defaultConfigFile {
			fmt.Println(err)
			os.Exit(1)
		}
		return
	}
	err = l.SetUpLogging(config)
	if err != nil {
		fmt.Printf("Logging setup error: %s\n", err)
		os.Exit(1)
		return
	}
	log.Info("logging initialized")
}
开发者ID:vozhyk-,项目名称:gohan,代码行数:21,代码来源:cli.go


示例14: TestOttoExtension

		}
	}
	return nil
}

func TestOttoExtension(t *testing.T) {
	RegisterFailHandler(Fail)
	RunSpecs(t, "Otto Extension Suite")
}

var _ = Describe("Suite set up and tear down", func() {
	var _ = BeforeSuite(func() {
		var err error
		Expect(os.Chdir(configDir)).To(Succeed())
		testDB, err = db.ConnectDB(dbType, dbFile, db.DefaultMaxOpenConn)
		Expect(err).ToNot(HaveOccurred(), "Failed to connect database.")
		manager := schema.GetManager()
		config := util.GetConfig()
		Expect(config.ReadConfig(configFile)).To(Succeed())
		schemaFiles := config.GetStringList("schemas", nil)
		Expect(schemaFiles).NotTo(BeNil())
		Expect(manager.LoadSchemasFromFiles(schemaFiles...)).To(Succeed())
		Expect(db.InitDBWithSchemas(dbType, dbFile, false, false)).To(Succeed())
	})

	var _ = AfterSuite(func() {
		schema.ClearManager()
		os.Remove(dbFile)
	})
})
开发者ID:marcin-ptaszynski,项目名称:gohan,代码行数:30,代码来源:otto_suite_test.go


示例15: setupEditor

func setupEditor(server *Server) {
	manager := schema.GetManager()
	config := util.GetConfig()
	editableSchemaFile := config.GetString("editable_schema", "")
	golang.RegisterGoCallback("handle_schema",
		func(event string, context map[string]interface{}) error {
			auth := context["auth"].(schema.Authorization)
			if event == "pre_list" {
				list := []interface{}{}
				total := 0
				for _, currentSchema := range manager.OrderedSchemas() {
					trimmedSchema, err := GetSchema(currentSchema, auth)
					if err != nil {
						return err
					}
					if trimmedSchema != nil {
						s := trimmedSchema.Data()
						s["url"] = currentSchema.URL
						list = append(list, s)
						total = total + 1
					}
				}
				context["total"] = total
				context["response"] = map[string]interface{}{
					"schemas": list,
				}
				return nil
			} else if event == "pre_show" {
				ID := context["id"].(string)
				currentSchema, _ := manager.Schema(ID)
				object, _ := GetSchema(currentSchema, auth)
				s := object.Data()
				s["url"] = currentSchema.URL
				context["response"] = map[string]interface{}{
					"schema": s,
				}
				return nil
			}
			if event != "pre_create" && event != "pre_update" && event != "pre_delete" {
				return nil
			}

			if editableSchemaFile == "" {
				return nil
			}

			ID := context["id"].(string)

			schemasInFile, err := util.LoadMap(editableSchemaFile)
			if err != nil {
				return nil
			}
			schemas := schemasInFile["schemas"].([]interface{})
			updatedSchemas := []interface{}{}
			var existingSchema map[string]interface{}
			for _, rawSchema := range schemas {
				s := rawSchema.(map[string]interface{})
				if s["id"] == ID {
					existingSchema = s
				} else {
					updatedSchemas = append(updatedSchemas, s)
				}
			}

			if event == "pre_create" {
				if existingSchema != nil {
					return fmt.Errorf("ID has been taken")
				}
				newSchema := context["resource"].(map[string]interface{})
				_, err := schema.NewSchemaFromObj(newSchema)
				if err != nil {
					return err
				}
				schemasInFile["schemas"] = append(updatedSchemas, context["resource"].(map[string]interface{}))
				context["response"] = map[string]interface{}{
					"schema": context["resource"],
				}
				context["exception"] = map[string]interface{}{
					"name":    "CustomException",
					"message": context["response"],
					"code":    201,
				}
			} else if event == "pre_update" {
				if existingSchema == nil {
					return fmt.Errorf("Not found or Update isn't supported for this schema")
				}
				for key, value := range context["resource"].(map[string]interface{}) {
					existingSchema[key] = value
				}
				_, err := schema.NewSchemaFromObj(existingSchema)
				if err != nil {
					return err
				}
				schemasInFile["schemas"] = append(updatedSchemas, existingSchema)
				context["response"] = map[string]interface{}{
					"schema": context["resource"],
				}
				context["exception"] = map[string]interface{}{
					"name":    "CustomException",
					"message": context["response"],
//.........这里部分代码省略.........
开发者ID:vozhyk-,项目名称:gohan,代码行数:101,代码来源:editor.go


示例16: listenAMQP

func listenAMQP(server *Server) {

	hostname, _ := os.Hostname()
	processID := hostname + uuid.NewV4().String()
	config := util.GetConfig()
	connection := config.GetString("amqp/connection", "amqp://guest:[email protected]:5672/")
	queues := config.GetStringList("amqp/queues", []string{"notifications.info", "notifications.error"})
	events := config.GetStringList("amqp/events", []string{})
	extensions := map[string]extension.Environment{}
	for _, event := range events {
		path := "amqp://" + event
		env, err := server.NewEnvironmentForPath("amqp."+event, path)
		if err != nil {
			log.Fatal(err.Error())
		}
		extensions[event] = env
	}

	for _, queue := range queues {
		go func(queue string) {
			defer util.LogPanic(log)
			for server.running {
				conn, err := amqp.Dial(connection)
				if err != nil {
					log.Error(fmt.Sprintf("[AMQP] connection error: %s", err))
					time.Sleep(connectionWait)
					continue
				}
				defer conn.Close()

				ch, err := conn.Channel()
				if err != nil {
					log.Error(fmt.Sprintf("[AMQP] channel: %s", err))
					return
				}
				defer ch.Close()
				q, err := ch.QueueDeclare(
					queue, // name
					false, // durable
					false, // delete when usused
					false, // exclusive
					false, // no-wait
					nil,   // arguments
				)
				if err != nil {
					log.Error(fmt.Sprintf("[AMQP] queue declare error: %s", err))
					return
				}

				for server.running {
					msgs, err := ch.Consume(
						q.Name, // queue
						"gohan-"+processID+"-"+queue, // consumer
						true,  // auto-ack
						false, // exclusive
						false, // no-local
						false, // no-wait
						nil,   // args
					)

					if err != nil {
						log.Error(fmt.Sprintf("[AMQP] consume queue error: %s", err))
						break
					}
					for d := range msgs {
						var message map[string]interface{}
						err = json.Unmarshal(d.Body, &message)
						log.Debug(fmt.Sprintf("Received a message: %s %s", queue, d.Body))
						if err != nil {
							log.Error(fmt.Sprintf("[AMQP] json decode error: %s", err))
							continue
						}
						eventType, ok := message["event_type"].(string)
						if !ok {
							log.Error("[AMQP] wrong event type")
							continue
						}
						for _, event := range events {
							if strings.HasPrefix(eventType, event) {
								env := extensions[event]

								context := map[string]interface{}{
									"event": message,
								}
								if err := env.HandleEvent("notification", context); err != nil {
									log.Warning(fmt.Sprintf("extension error: %s", err))
								}
							}
						}
					}
				}
			}
		}(queue)
	}
}
开发者ID:marcin-ptaszynski,项目名称:gohan,代码行数:95,代码来源:amqp.go


示例17: ReadConfig

//ReadConfig reads configuraion from file.
func ReadConfig(path string) error {
	config := util.GetConfig()
	err := config.ReadConfig(path)
	return err
}
开发者ID:marcin-ptaszynski,项目名称:gohan,代码行数:6,代码来源:gohan.go


示例18: startSyncWatchProcess

//Sync Watch Process
func startSyncWatchProcess(server *Server) {
	manager := schema.GetManager()
	config := util.GetConfig()
	watch := config.GetStringList("watch/keys", nil)
	events := config.GetStringList("watch/events", nil)
	maxWorkerCount := config.GetParam("watch/worker_count", 0).(int)
	if watch == nil {
		return
	}
	extensions := map[string]extension.Environment{}
	for _, event := range events {
		path := "sync://" + event
		env := newEnvironment(server.db, server.keystoneIdentity)
		err := env.LoadExtensionsForPath(manager.Extensions, path)
		if err != nil {
			log.Fatal(fmt.Sprintf("Extensions parsing error: %v", err))
		}
		extensions[event] = env
	}
	responseChan := make(chan *gohan_sync.Event)
	stopChan := make(chan bool)
	for _, path := range watch {
		go func(path string) {
			for server.running {
				err := server.sync.Watch(path, responseChan, stopChan)
				if err != nil {
					log.Error(fmt.Sprintf("sync watch error: %s", err))
				}
				time.Sleep(5 * time.Second)
			}
		}(path)
	}
	//main response lisnter process
	go func() {
		var wg sync.WaitGroup
		workerCount := 0
		for server.running {
			response := <-responseChan
			wg.Add(1)
			workerCount++
			//spawn workers up to max worker count
			go func() {
				defer func() {
					workerCount--
					wg.Done()
				}()
				for _, event := range events {
					//match extensions
					if strings.HasPrefix(response.Key, "/"+event) {
						env := extensions[event]
						runExtensionOnSync(server, response, env)
						return
					}
				}
			}()
			// Wait if worker pool is full
			if workerCount > maxWorkerCount {
				wg.Wait()
			}
		}
		stopChan <- true
	}()

}
开发者ID:gitter-badger,项目名称:gohan,代码行数:65,代码来源:sync.go


示例19: GetConfig

//GetConfig returns config by key.
func GetConfig(key string, defaultValue interface{}) interface{} {
	config := util.GetConfig()
	return config.GetParam(key, defaultValue)
}
开发者ID:marcin-ptaszynski,项目名称:gohan,代码行数:5,代码来源:gohan.go


示例20: NewServer

//NewServer returns new GohanAPIServer
func NewServer(configFile string) (*Server, error) {
	manager := schema.GetManager()
	config := util.GetConfig()
	err := config.ReadConfig(configFile)
	err = os.Chdir(path.Dir(configFile))
	if err != nil {
		return nil, fmt.Errorf("Config load error: %s", err)
	}
	err = l.SetUpLogging(config)
	if err != nil {
		return nil, fmt.Errorf("Logging setup error: %s", err)
	}
	log.Info("logging initialized")

	server := &Server{}

	m := martini.Classic()
	m.Handlers()
	m.Use(middleware.Logging())
	m.Use(martini.Recovery())
	m.Use(middleware.JSONURLs())
	m.Use(middleware.WithContext())

	server.martini = m

	port := os.Getenv("PORT")

	if port == "" {
		port = "9091"
	}

	setupEditor(server)

	server.timelimit = config.GetInt("extension/timelimit", 30)
	server.extensions = config.GetStringList("extension/use", []string{
		"javascript",
		"gohanscript",
		"go",
	})
	schema.DefaultExtension = config.GetString("extension/default", "javascript")
	server.address = config.GetString("address", ":"+port)
	if config.GetBool("tls/enabled", false) {
		log.Info("TLS enabled")
		server.tls = &tlsConfig{
			KeyFile:  config.GetString("tls/key_file", "./etc/key.pem"),
			CertFile: config.GetString("tls/cert_file", "./etc/cert.pem"),
		}
	}

	etcdServers := config.GetStringList("etcd", nil)
	if etcdServers != nil {
		log.Info("etcd servers: %s", etcdServers)
		server.sync = etcd.NewSync(etcdServers)
	}

	server.connectDB()

	schemaFiles := config.GetStringList("schemas", nil)
	if schemaFiles == nil {
		log.Fatal("No schema specified in configuraion")
	} else {
		err = manager.LoadSchemasFromFiles(schemaFiles...)
		if err != nil {
			return nil, fmt.Errorf("invalid schema: %s", err)
		}
	}
	if !config.GetBool("database/no_init", false) {
		server.initDB()
	}

	if config.GetList("database/initial_data", nil) != nil {
		initialDataList := config.GetList("database/initial_data", nil)
		for _, initialData := range initialDataList {
			initialDataConfig := initialData.(map[string]interface{})
			inType := initialDataConfig["type"].(string)
			inConnection := initialDataConfig["connection"].(string)
			log.Info("Importing data from %s ...", inConnection)
			inDB, err := db.ConnectDB(inType, inConnection, db.DefaultMaxOpenConn)
			if err != nil {
				log.Fatal(err)
			}
			db.CopyDBResources(inDB, server.db, false)
		}
	}

	if config.GetBool("keystone/use_keystone", false) {
		//TODO remove this
		if config.GetBool("keystone/fake", false) {
			server.keystoneIdentity = &middleware.FakeIdentity{}
			//TODO(marcin) requests to fake server also get authenticated
			//             we need a separate routing Group
			log.Info("Debug Mode with Fake Keystone Server")
		} else {
			log.Info("Keystone backend server configured")
			server.keystoneIdentity, err = cloud.NewKeystoneIdentity(
				config.GetString("keystone/auth_url", "http://localhost:35357/v3"),
				config.GetString("keystone/user_name", "admin"),
				config.GetString("keystone/password", "password"),
				config.GetString("keystone/domain_name", "Default"),
//.........这里部分代码省略.........
开发者ID:vozhyk-,项目名称:gohan,代码行数:101,代码来源:server.go



注:本文中的github.com/cloudwan/gohan/util.GetConfig函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang flocker-go.NewClient函数代码示例发布时间:2022-05-23
下一篇:
Golang middleware.IdentityService类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap