Exemplo n.º 1
0
func main() {
	configfile := flag.String("config", "devel.yml", "config file")
	flag.Parse()
	config, err := yaml.Open(*configfile)
	if err != nil {
		fmt.Printf("readfile(%q): %s", *config, err)
		os.Exit(1)
	} else {
		cfg := config.Get("cluster").(map[interface{}]interface{})
		cluster.Config(cfg)
	}

	ln, err := net.Listen("tcp", "0.0.0.0:7000")
	if err != nil {
		// handle error
	}
	for {
		conn, err := ln.Accept()
		if err != nil {
			// handle error
			continue
		}
		go handleConnection(conn)
	}
}
Exemplo n.º 2
0
func init() {
	gob.Register(UserModel{})

	// Load config file
	conf, err := yaml.Open("config.yml")
	if err != nil {
		log.Fatal(err)
	}

	// Retrieve credentials from config file
	username := to.String(conf.Get("database", "username"))
	password := to.String(conf.Get("database", "password"))
	name := to.String(conf.Get("database", "name"))

	// Open mysql connection
	dsn := fmt.Sprintf("%s:%s@/%s?%s", username, password, name, "parseTime=true")
	db, err = sql.Open("mysql", dsn)
	if err != nil {
		log.Fatal(err)
	}

	// Sets the maximum number of connections in the idle connection pool
	db.SetMaxIdleConns(100)

}
Exemplo n.º 3
0
func main() {
	// intialize routes muxer
	r := mux.NewRouter()

	// article routes
	r.HandleFunc("/articles", ArticleController{}.Index()).Methods("GET")
	r.HandleFunc("/articles", ArticleController{}.Create()).Methods("POST")
	r.HandleFunc("/articles/new", ArticleController{}.Form()).Methods("GET")
	r.HandleFunc("/articles/{id:[0-9]+}", ArticleController{}.Retrieve()).Methods("GET")
	r.HandleFunc("/articles/{id:[0-9]+}/publish", ArticleController{}.Publish()).Methods("POST")
	r.HandleFunc("/articles/{id:[0-9]+}/edit", ArticleController{}.Edit()).Methods("GET")
	r.HandleFunc("/articles/{id:[0-9]+}/delete", ArticleController{}.Delete()).Methods("POST")

	// interview routes
	r.HandleFunc("/interviews", InterviewController{}.Index()).Methods("GET")
	r.HandleFunc("/interviews/{id:[0-9]+}", InterviewController{}.Retrieve()).Methods("GET")
	r.HandleFunc("/interviews/new", InterviewController{}.Form()).Methods("GET")
	r.HandleFunc("/interviews/new", InterviewController{}.Create()).Methods("POST")

	// account routes
	r.HandleFunc("/accounts", UserController{}.Index())
	r.HandleFunc("/accounts/{id:[0-9]+}", UserController{}.Retrieve())

	// static page routes
	r.HandleFunc("/about", MainController{}.About())
	r.HandleFunc("/terms", MainController{}.Terms())
	r.HandleFunc("/privacy", MainController{}.Privacy())
	r.HandleFunc("/", MainController{}.Landing())

	// user routes
	r.HandleFunc("/signin", UserController{}.SignInForm()).Methods("GET")
	r.HandleFunc("/signin", UserController{}.SignInApi()).Methods("POST")
	r.HandleFunc("/signout", UserController{}.SignOut()).Methods("GET")
	r.HandleFunc("/signup", UserController{}.SignUpForm()).Methods("GET")
	r.HandleFunc("/signup", UserController{}.SignUpApi()).Methods("POST")

	// api routes
	r.HandleFunc("/api/charts/groupwork", Chart{}.GroupWork())
	r.HandleFunc("/api/charts/fulfillment", Chart{}.Fulfillment())
	r.HandleFunc("/api/charts/breakdown", Chart{}.Breakdown())

	// static resource files
	http.Handle("/public/", http.StripPrefix("/public/", http.FileServer(http.Dir("public"))))
	http.Handle("/vendor/", http.StripPrefix("/vendor/", http.FileServer(http.Dir("vendor"))))

	// register gorrilla router as root
	http.Handle("/", r)

	// Load config file
	conf, err := yaml.Open("config.yml")
	if err != nil {
		log.Fatal(err)
	}

	port := to.String(conf.Get("server", "port"))
	if err = http.ListenAndServe(":"+port, nil); err != nil {
		log.Fatal(err)
	}
}
Exemplo n.º 4
0
func TestSettings(t *testing.T) {
	var err error
	conf, err = yaml.Open(SettingsFile)

	if err != nil {
		panic(err.Error())
	}

}
Exemplo n.º 5
0
func TestToken(t *testing.T) {
	yf, err := yaml.Open("settings.yaml")

	client = New()

	if err == nil {
		client.SetAccessToken(to.String(yf.Get("providers", "instagram", "access_token")))
	}
}
Exemplo n.º 6
0
func readSettings(configFileName string) error {
	file, err := yaml.Open(configFileName)
	if err != nil {
		return fmt.Errorf("Can't read config file %s: %s", configFileName, err.Error())
	}
	config = &yamlSettings{file}
	notifier.SetSettings(config)

	return nil
}
Exemplo n.º 7
0
func main() {
	usage := `Lims2 Autodeploy.

Usage:
  lims2 <command> [<args>...]
  lims2 -h | --help
  lims2 --version

Options:
  -h --help     Show this screen.
  --version     Show version.

Commands:
  up                   Create and start containers
  get-cron             Output crontab
  get-sphinx           Output sphinxsearch config
  update-cron          Output to /etc/cron.d/lims2 in container.`

	var defaultArgs []string
	if len(os.Args[1:]) == 0 {
		defaultArgs = []string{
			"-h",
		}
	} else {
		defaultArgs = os.Args[1:]
	}

	args, _ := docopt.Parse(usage, defaultArgs, true, "Lims2 Autodeploy 0.1", true)

	command := args["<command>"]

	subCommand, exits := commandsMap[command]

	//如果传值错误
	if !exits {
		docopt.Parse(usage, []string{"-h"}, true, "Lims2 Autodeploy 0.1", true)
	}

	defer func() {

		if r := recover(); r != nil {
			fmt.Println(r)
			os.Exit(1)
		}
	}()

	if _, err := os.Stat("main.yml"); err == nil {
		subCommand.info, _ = yaml.Open("main.yml")
	} else {
		panic(errors.New("main.yml not exists."))
	}

	subCommand.Run(subCommand)
}
Exemplo n.º 8
0
func (m *cfgMgr) Init() {
	fileSyncCfgFile := getAbs(settingStruct.Filesync.CfgFile)
	fileSyncCfg := readConfig(fileSyncCfgFile)
	fmt.Println(fileSyncCfg)

	fsCfgWriter, err := yaml.Open(fileSyncCfgFile)
	if err != nil {
		panic(err)
	}

	m.cfg = fileSyncCfg
	m.writer = fsCfgWriter
}
Exemplo n.º 9
0
func readConfig(configFileName *string) error {
	file, err := yaml.Open(*configFileName)
	if err != nil {
		return fmt.Errorf("Can't read config file %s: %s", *configFileName, err.Error())
	}
	pidFileName = to.String(file.Get("cache", "pid"))
	logFileName = to.String(file.Get("cache", "log_file"))
	listen = to.String(file.Get("cache", "listen"))
	retentionConfigFileName = to.String(file.Get("cache", "retention-config"))
	redisURI = fmt.Sprintf("%s:%s", to.String(file.Get("redis", "host")), to.String(file.Get("redis", "port")))
	graphiteURI = to.String(file.Get("graphite", "uri"))
	graphitePrefix = to.String(file.Get("graphite", "prefix"))
	graphiteInterval = to.Int64(file.Get("graphite", "interval"))
	return nil
}
Exemplo n.º 10
0
func main() {
	var response = []sugar.Tuple{}

	names := getPlugins()

	for _, name := range names {
		file := name + PS + "package.yaml"
		pkg, err := yaml.Open(file)

		if err != nil {
			panic(err)
		}

		item := sugar.Tuple{}

		keys := []string{
			"name",
			"stable",
			"latest",
			"license",
			"url",
			"demo_url",
			"description",
			"author",
			"copyright",
			"packages",
		}

		item["pkg"] = name

		for _, key := range keys {
			item[key] = pkg.Get(key)
		}

		if to.Bool(pkg.Get("hidden")) == false {
			response = append(response, item)
		}

	}

	data, _ := json.Marshal(response)

	fmt.Printf("%s", string(data))
}
Exemplo n.º 11
0
func init() {
	// Load config file
	conf, err := yaml.Open("config.yml")
	if err != nil {
		log.Fatal(err)
	}

	// Retrieve credentials from config file
	username := to.String(conf.Get("database", "username"))
	password := to.String(conf.Get("database", "password"))
	name := to.String(conf.Get("database", "name"))

	// Open mysql connection
	db, err = sql.Open("mysql", username+":"+password+"@/"+name)
	if err != nil {
		log.Fatal(err)
	}

	// Sets the maximum number of connections in the idle connection pool
	db.SetMaxIdleConns(100)
}
Exemplo n.º 12
0
func init() {
	// parse templates
	t = template.Must(t.ParseGlob("views/_templates/*.html"))
	t = template.Must(t.ParseGlob("views/articles/*.html"))
	t = template.Must(t.ParseGlob("views/interviews/*.html"))
	t = template.Must(t.ParseGlob("views/interviews/components/*.html"))
	t = template.Must(t.ParseGlob("views/accounts/*.html"))
	t = template.Must(t.ParseGlob("views/users/*.html"))
	t = template.Must(t.ParseGlob("views/*.html"))

	// Load config file
	conf, err := yaml.Open("config.yml")
	if err != nil {
		log.Fatal(err)
	}

	// grab server secret from config file
	secret := to.String(conf.Get("server", "secret"))

	// initialize session storage
	store = sessions.NewCookieStore([]byte(secret))
}
Exemplo n.º 13
0
func init() {
	// Load config file
	conf, err := yaml.Open("config.yml")
	if err != nil {
		log.Fatal(err)
	}

	// compile templates
	t = template.Must(t.ParseGlob("views/_templates/*.html"))
	t = template.Must(t.ParseGlob("views/users/*.html"))
	t = template.Must(t.ParseGlob("views/songs/*.html"))
	t = template.Must(t.ParseGlob("views/auth/*.html"))
	t = template.Must(t.ParseGlob("views/*.html"))

	// initialize session storage
	store = sessions.NewCookieStore([]byte(to.String(conf.Get("server", "secret"))))

	gob.Register(&models.UserModel{})

	// load variables from config
	access := to.String(conf.Get("amazon", "s3", "access"))
	secret := to.String(conf.Get("amazon", "s3", "secret"))
	name := to.String(conf.Get("amazon", "s3", "name"))

	// configure aws authentication
	auth, err := aws.GetAuth(access, secret)
	if err != nil {
		log.Fatal(err)
	}

	// create s3 client
	client := s3.New(auth, aws.USWest2)

	// retrieve bucket from name
	bucket = client.Bucket(name)
}
Exemplo n.º 14
0
func main() {

	// load settings from config file
	conf, err := yaml.Open("config.yml")
	if err != nil {
		log.Fatal(err)
	}

	// initialize router
	router := InitializeRouter()

	// register router
	http.Handle("/", router)

	// get port number from config file
	port := to.String(conf.Get("server", "port"))

	fmt.Printf("Serving application from port %s\n", port)

	// serve application
	if err = http.ListenAndServe(":"+port, nil); err != nil {
		log.Fatal(err)
	}
}
Exemplo n.º 15
0
func (self *Build) load(pkg string, ctx *Context) {
	var err error
	var version string

	minjs, _ := regexp.Compile(`\.js$`)

	if ctx.Loaded[pkg] == true {
		return
	} else {
		ctx.Loaded[pkg] = true
	}

	if strings.Contains(pkg, ":") {
		i := strings.LastIndex(pkg, ":")
		version = pkg[i+1:]
		pkg = pkg[0:i]
	}

	filename := PluginsRoot + tango.PS + pkg + tango.PS + "package.yaml"

	_, err = os.Stat(filename)

	if err == nil {

		info, err := yaml.Open(filename)

		if err == nil {

			if version == "" {
				version = to.String(info.Get("latest"))
			}

			files := to.Map(info.Get(fmt.Sprintf("packages/%s", version)))

			if files == nil {
				ctx.Buf.Write([]byte(fmt.Sprintf("/* Package \"%s\" with version \"%s\" was not found. */\n", pkg, version)))
			} else {

				if files["requires"] != nil {
					for _, req := range to.List(files["requires"]) {
						self.load(req.(string), ctx)
					}
				}

				ctx.Buf.Write([]byte(fmt.Sprintf("/* %s: %s. %s */\n", pkg, to.String(info.Get("name")), to.String(info.Get("copyright")))))

				if files["source"] != nil {
					for _, jsfile := range to.List(files["source"]) {
						minfile := minjs.ReplaceAllString(jsfile.(string), ".min.js")
						ctx.Buf.Write(self.read(PluginsRoot + tango.PS + pkg + tango.PS + minfile))
						ctx.Buf.Write([]byte(fmt.Sprintf("\n")))
					}
				}

				ctx.Buf.Write([]byte(fmt.Sprintf("\n\n")))

				if files["style"] != nil {

					styles := to.List(files["style"])

					cssfiles := make([]string, len(styles))

					for i, _ := range styles {
						cssfiles[i] = fmt.Sprintf("plugins/%s/%s", pkg, styles[i].(string))
					}

					css, _ := json.Marshal(cssfiles)

					ctx.Buf.Write([]byte(fmt.Sprintf("$.foo.styles.apply($.foo, %s);\n", string(css))))
				}

			}

			ctx.Buf.Write([]byte(fmt.Sprintf("\n\n")))

		} else {
			ctx.Buf.Write([]byte(fmt.Sprintf("/* Package \"%s\": metadata error. */\n", pkg)))
		}
	} else {
		ctx.Buf.Write([]byte(fmt.Sprintf("/* Package \"%s\": missing. */\n", pkg)))
	}

}