Beispiel #1
0
func init() {
	c, err := config.ParseYaml(`

local:
  debug: true
  port: 5000
  title: lmbd
  db: ./db.sqlite
  api:
    prefix: /api
  duktape:
    pool:
      use: false

production:
  debug: false
  port: 5000
  title: lmbd
  api:
    prefix: /api
  duktape:
    pool:
      use: true
      size: 1
`)
	Must(err)
	conf = c
}
Beispiel #2
0
//TODO Melhorar parser do config
func NewConfig(e string, p string) (c *Config, err error) {
	var mode string

	switch e {
	case PRODUCTION.String():
		mode = "release"
	case DEVELOPMENT.String(), TEST.String():
		mode = "debug"
	default:
		return nil, errors.New("No valid enviroment.")
	}

	data, err := parseEnvs(p)
	if err != nil {
		return nil, err
	}

	cfg, err := config.ParseYaml(string(data))
	if err != nil {
		return nil, err
	}

	lg, err := cfg.Get("log")
	if err != nil {
		return nil, err
	}

	em, err := cfg.Get("email")
	if err != nil {
		return nil, err
	}

	db, err := cfg.Get("database")
	if err != nil {
		return nil, err
	}

	tk, err := cfg.Get("token")
	if err != nil {
		return nil, err
	}

	c = &Config{
		cfg,
		e,
		&DatabaseConfig{db.UString("host"), db.UString("name"), db.UString("username"), db.UString("password")},
		&TokenConfig{tk.UString("expiration"), tk.UString("secret")},
		&EmailConfig{em.UString("host"), em.UString("port"), em.UString("username"), em.UString("password"), em.UString("sender")},
		&LogConfig{lg.UBool("rotate"), lg.UString("level"), lg.UString("file"), lg.UString("format")},
		cfg.UString("name"),
		cfg.UString("version"),
		cfg.UString("port"),
		mode,
	}

	return c, nil
}
Beispiel #3
0
func load() {
	var err error
	var yml []byte
	configFile := detectProdConfig(false)
	yml, err = ioutil.ReadFile(configFile)
	if err != nil {
		log.Printf("Unable to find config in path: %s,  %s", configFile, err)
		return
	}
	AppConfig, err = config.ParseYaml(string(yml))
	logfileName, _ := AppConfig.String("logfile")
	EnableLogfile(logfileName)
}
Beispiel #4
0
func parse(e Environment, file string) (*config.Config, error) {

	f, err := os.Open(file)
	if err != nil {
		return nil, err
	}

	defer f.Close()
	reader := bufio.NewReader(f)
	scanner := bufio.NewScanner(reader)

	data := make([]byte, 0)

	for scanner.Scan() {
		parsed := scanner.Text() + "\n"
		p := regex.FindAllStringSubmatch(parsed, -1)
		if len(p) > 0 {
			parsed = fmt.Sprintf("%s\"%s\"\n", p[0][1], os.Getenv(p[0][2]))
		}

		data = append(data, []byte(parsed)...)
	}

	cfg, err := config.ParseYaml(string(data))
	if err != nil {
		return nil, err
	}

	env, err := cfg.Get(e.String())
	if err == nil {

		def, err := cfg.Get("default")

		if err == nil {
			return def.Extend(env)
		}

		return env, nil
	}

	return nil, nil
}
Beispiel #5
0
func (cfg *Config) ExtendWithFile(p string) (err error) {
	data, err := parseEnvs(p)
	if err != nil {
		return err
	}

	cc, err := config.ParseYaml(string(data))
	if err != nil {
		return err
	}

	cc, err = cc.Get(cfg.Enviroment)
	if err != nil {
		return err
	}

	reg := regexp.MustCompile(`([\w\d\_\-]+)\.yml$`)
	ps := reg.FindAllStringSubmatch(p, -1)

	return cfg.Set(ps[0][1], cc.Root)
}
Beispiel #6
0
func TestCreationOfPrometheusLabels(t *testing.T) {
	assert := assert.New(t)
	nodeinfo := data.NodeInfo{
		Hostname: "Testnode",
		System: data.SystemStruct{
			SiteCode: "fftest",
		},
		NodeId: "1122",
	}
	var err error
	config.Global, err = cfg.ParseYaml(testConfig)
	assert.Nil(err)

	prmcfg, err := config.Global.Get("prometheus")
	assert.Nil(err)
	assert.NotNil(prmcfg)

	nodeLabels := getLabels(nodeinfo, "metric")
	assert.Equal(4, len(nodeLabels))
	assert.Equal("1122", nodeLabels[0])
	assert.Equal("Testnode", nodeLabels[1])
	assert.Equal("fftest", nodeLabels[2])
	assert.Equal("metric", nodeLabels[3])
}
Beispiel #7
0
package main

import (
	"github.com/olebedev/config"
	stdlog "log"
	"os"
	"path/filepath"
)

var log = stdlog.New(os.Stdout, "\033[1;33m[srlt] >>\033[m ", 0)
var conf, _ = config.ParseYaml(`
basepath: pwd
force: false
file: srlt.json
`)

func initConf() {
	// basepath
	bp, _ := conf.String("basepath")
	if bp == "pwd" {
		bp, _ = os.Getwd()
	}
	bp, _ = filepath.Abs(bp)
	conf.Set("basepath", bp)

	//file
	f, _ := conf.String("file")
	f, _ = filepath.Abs(f)
	conf.Set("file", f)
}
Beispiel #8
0
// NewApp returns initialized struct
// of main server application.
func NewApp(opts ...AppOptions) *App {
	var options AppOptions
	for _, i := range opts {
		options = i
		i.init()
		break
	}

	// Parse config yaml string from ./conf.go
	conf, err := config.ParseYaml(confString)
	Must(err)
	// Choise a config section by given string
	conf, err = conf.Get(options.Config)
	Must(err)

	// Parse environ variables for defined
	// in config constants
	conf.Env()

	// Set up gin
	if !conf.UBool("debug") {
		gin.SetMode(gin.ReleaseMode)
	}

	// Make an engine
	engine := gin.Default()

	// Initialize the application
	app := &App{
		Conf:   conf,
		Engine: engine,
		Api:    &Api{},
		React: NewReact(
			conf.UBool("debug"),
			engine,
		),
	}

	// Define routes and middlewares
	app.Engine.StaticFS("/static", &assetfs.AssetFS{
		Asset:    Asset,
		AssetDir: AssetDir,
		Prefix:   "static",
	})

	// Map app struct to access from request handlers
	// and middlewares
	app.Engine.Use(func(c *gin.Context) {
		c.Set("app", app)
	})

	// Avoid favicon react handling
	app.Engine.GET("/favicon.ico", func(c *gin.Context) {
		c.Redirect(301, "/static/images/favicon.ico")
	})

	// Bind api hadling for URL api.prefix
	app.Api.Bind(
		app.Engine.Group(
			app.Conf.UString("api.prefix"),
		),
	)

	// Map uuid for every requests
	app.Engine.Use(func(c *gin.Context) {
		id, _ := uuid.NewV4()
		c.Set("uuid", id)
	})

	// Handle all not found routes via react app
	app.Engine.NoRoute(app.React.Handle)

	return app
}
Beispiel #9
0
	"log"
	"net/http"
	"os"

	"github.com/go-martini/martini"
	"github.com/olebedev/cdn/lib"
	"github.com/olebedev/config"
	"labix.org/v2/mgo"
)

var conf, _ = config.ParseYaml(`
debug: false
port: 5000
maxSize: 1000
showInfo: true
tailOnly: false
mongo:
  uri: localhost
mongodb:
  database: cdn
`)

func main() {
	conf.Env().Flag()
	r := martini.NewRouter()
	m := martini.New()
	if conf.UBool("debug") {
		m.Use(martini.Logger())
	}
	m.MapTo(r, (*martini.Routes)(nil))
	m.Action(r.Handle)
Beispiel #10
0
import (
	"unicode"
	"unicode/utf8"

	"github.com/gin-gonic/gin"
	"github.com/olebedev/config"
	"github.com/olebedev/staticbin"
)

// Base configuration
var conf, _ = config.ParseYaml(`
env: development
app:
  name: go react example
api:
  prefix: /api/v1
duktape:
  poolSize: 5
debug: true
port: 5000
title: Go React Example
`)

type __api__ struct{}

var api = __api__{}

func (api __api__) bind(r *gin.RouterGroup) {
	r.GET("/users/:username", api.username)
}

func upperFirst(s string) string {
Beispiel #11
0
// NewApp returns initialized struct
// of main server application.
func NewApp(opts ...AppOptions) *App {
	options := AppOptions{}
	for _, i := range opts {
		options = i
		break
	}
	options.init()

	// Parse config yaml string from ./conf.go
	conf, err := config.ParseYaml(confString)
	Must(err)

	// Parse environ variables for defined
	// in config constants
	conf.Env()

	// Make an engine
	engine := echo.New()

	// Set up echo
	engine.SetDebug(conf.UBool("debug"))

	// Regular middlewares
	engine.Use(middleware.Logger())
	engine.Use(middleware.Recover())

	// Initialize the application
	app := &App{
		Conf:   conf,
		Engine: engine,
		API:    &API{},
		React: NewReact(
			conf.UString("duktape.path"),
			conf.UBool("debug"),
			engine,
		),
	}

	// Use precompiled embedded templates
	app.Engine.SetRenderer(NewTemplate())

	// Map app struct to access from request handlers
	// and middlewares
	app.Engine.Use(func(c *echo.Context) error {
		c.Set("app", app)
		return nil
	})

	// Map uuid for every requests
	app.Engine.Use(func(c *echo.Context) error {
		id, _ := uuid.NewV4()
		c.Set("uuid", id)
		return nil
	})

	// Avoid favicon react handling
	app.Engine.Get("/favicon.ico", func(c *echo.Context) error {
		c.Redirect(301, "/static/images/favicon.ico")
		return nil
	})

	// Bind api hadling for URL api.prefix
	app.API.Bind(
		app.Engine.Group(
			app.Conf.UString("api.prefix"),
		),
	)

	// Create file http server from bindata
	fileServerHandler := http.FileServer(&assetfs.AssetFS{
		Asset:    Asset,
		AssetDir: AssetDir,
	})

	// Serve static via bindata and handle via react app
	// in case when static file was not found
	app.Engine.Use(func(h echo.HandlerFunc) echo.HandlerFunc {
		return func(c *echo.Context) error {
			// execute echo handlers chain
			err := h(c)
			// if page(handler) for url/method not found
			if err != nil && err.Error() == http.StatusText(http.StatusNotFound) {
				// check if file exists
				// omit first `/`
				if _, err := Asset(c.Request().URL.Path[1:]); err == nil {
					fileServerHandler.ServeHTTP(c.Response(), c.Request())
					return nil
				}
				// if static file not found handle request via react application
				return app.React.Handle(c)
			}
			// Move further if err is not `Not Found`
			return err
		}
	})

	return app
}
Beispiel #12
0
// NewApp returns initialized struct
// of main server application.
func NewApp(opts ...AppOptions) *App {
	options := AppOptions{}
	for _, i := range opts {
		options = i
		break
	}
	options.init()

	// Parse config yaml string from ./conf.go
	conf, err := config.ParseYaml(confString)
	Must(err)
	// Choise a config section by given string
	conf, err = conf.Get(options.Config)
	Must(err)

	// Parse environ variables for defined
	// in config constants
	conf.Env()

	// Make an engine
	engine := echo.New()

	// Set up echo
	engine.SetDebug(conf.UBool("debug"))

	// Regular middlewares
	engine.Use(
		middleware.Logger(),
		middleware.Recover(),
	)

	// Initialize the application
	app := &App{
		Conf:   conf,
		Engine: engine,
		API:    &API{},
		React: NewReact(
			conf.UString("duktape.path"),
			conf.UBool("debug"),
			engine,
		),
	}

	// Load embedded templates
	app.Engine.SetRenderer(echoRenderer{})

	// Map app struct to access from request handlers
	// and middlewares
	app.Engine.Use(func(c *echo.Context) error {
		c.Set("app", app)
		return nil
	})

	// Map uuid for every requests
	app.Engine.Use(func(c *echo.Context) error {
		id, _ := uuid.NewV4()
		c.Set("uuid", id)
		return nil
	})

	// Create file http server from bindata
	fileServerHandler := http.FileServer(&assetfs.AssetFS{
		Asset:    Asset,
		AssetDir: AssetDir,
	})

	app.Engine.Get("/static/*", func(c *echo.Context) error {
		if _, err := Asset(c.Request().URL.Path[1:]); err == nil {
			fileServerHandler.ServeHTTP(c.Response(), c.Request())
			return nil
		}
		return echo.NewHTTPError(http.StatusNotFound)
	})

	// Avoid favicon react handling
	app.Engine.Get("/favicon.ico", func(c *echo.Context) error {
		c.Redirect(301, "/static/images/favicon.ico")
		return nil
	})

	// Bind api hadling for URL api.prefix
	app.API.Bind(
		app.Engine.Group(
			app.Conf.UString("api.prefix"),
		),
	)

	// Bind React app
	app.Engine.Get("/*", app.React.Handle)
	return app
}
Beispiel #13
0
func (a *App) ReadConfig(path string) {
	if path == "" {
		path = "config.yaml"
	}

	var cfg kit.Config

	if f, err := os.Open(path); err != nil {
		a.Logger().Infof("Could not find or read config at '%v' - Using default settings\n", path)
	} else {
		defer f.Close()
		content, err := ioutil.ReadAll(f)
		if err != nil {
			a.Logger().Panicf("Could not read config at '%v': %v\n", path, err)
		} else {
			rawCfg, err := config.ParseYaml(string(content))
			if err != nil {
				panic("Malformed config file " + path + ": " + err.Error())
			}

			cfg = NewConfig(rawCfg.Root)
		}
	}

	if cfg == nil {
		cfg = NewConfig(map[string]interface{}{
			"env":      "dev",
			"debug":    true,
			"tmpPath":  "tmp",
			"dataPath": "data",
		})
	}

	// Read environment variables.
	cfg.ENV()

	// Set default values if not present.
	env, _ := cfg.String("ENV")
	if env == "" {
		a.Logger().Info("No environment specified, defaulting to 'dev'")
		cfg.Set("ENV", "dev")
		env = "dev"
	}

	if envCfg, err := cfg.Get(env); err == nil {
		cfg = NewConfig(envCfg.GetData())
		cfg.Set("ENV", env)
	}

	// Fill in default values into the config and ensure they are valid.

	// If debug is not explicitly set, set it to false, or to true if
	// environment is dev.
	_, err := cfg.Bool("debug")
	if err != nil {
		cfg.Set("debug", env == "dev")
	}

	// Ensure a tmp directory exists and is readable.
	tmpDir := cfg.TmpDir()
	if err := os.MkdirAll(tmpDir, 0777); err != nil {
		a.Logger().Panicf("Could not read or create tmp dir at '%v': %v", tmpDir, err)
	}

	// Ensure a data directory exists and is readable.
	dataDir := cfg.UPath("dataDir", "data")
	if err := os.MkdirAll(dataDir, 0777); err != nil {
		a.Logger().Panicf("Could not read or create data dir at '%v': %v", tmpDir, err)
	}

	a.registry.SetConfig(cfg)
}
Beispiel #14
0
// NewApp returns initialized struct
// of main server application.
func NewApp(opts ...AppOptions) *App {
	options := AppOptions{}
	for _, i := range opts {
		options = i
		break
	}
	options.init()

	// Parse config yaml string from ./conf.go
	conf, err := config.ParseYaml(confString)
	Must(err)
	// Choise a config section by given string
	conf, err = conf.Get(options.Config)
	Must(err)

	// Parse environ variables for defined
	// in config constants
	conf.Env()

	// Make an engine
	engine := echo.New()

	// Set up echo
	engine.SetDebug(conf.UBool("debug"))

	// Middlewares
	engine.Use(mw.Logger())
	engine.Use(mw.Recover())

	// Initialize the application
	app := &App{
		Conf:   conf,
		Engine: engine,
		API:    &API{},
		React: NewReact(
			conf.UString("duktape.path"),
			conf.UBool("debug"),
			engine,
		),
	}

	// Load embedded templates MISSING
	app.Engine.SetRenderer(echoRenderer{})

	// Map app struct to access from request handlers
	// and middlewares
	app.Engine.Use(func(c *echo.Context) error {
		c.Set("app", app)
		return nil
	})

	// Map uuid for every requests
	app.Engine.Use(func(c *echo.Context) error {
		id, _ := uuid.NewV4()
		c.Set("uuid", id)
		return nil
	})

	var staticPathRegExp = regexp.MustCompile(`^/static/?.*`)

	staticAsset := assetfs.AssetFS{
		Asset:    Asset,
		AssetDir: AssetDir,
		Prefix:   "",
	}

	fileServerHandler := http.FileServer(&staticAsset)

	// Handle all not found routes via react app (except for static files)
	app.Engine.Use(func(h echo.HandlerFunc) echo.HandlerFunc {
		return func(c *echo.Context) error {
			err := h(c)
			if err != nil && err.Error() == http.StatusText(http.StatusNotFound) {
				if staticPathRegExp.MatchString(c.Request().URL.Path) {
					// Handles static files with assetFs
					fileServerHandler.ServeHTTP(c.Response(), c.Request())
					return nil
				}
				//if not found and not a static file then serv with react.
				return app.React.Handle(c)
			}
			return err
		}
	})

	// Avoid favicon react handling
	app.Engine.Get("/favicon.ico", func(c *echo.Context) error {
		c.Redirect(301, "/static/images/favicon.ico")
		return nil
	})

	//Force handle index to React otherwise it will throw Method not allowed.
	app.Engine.Get("/", app.React.Handle)

	// Bind api hadling for URL api.prefix
	app.API.Bind(
		app.Engine.Group(app.Conf.UString("api.prefix")),
	)
	return app
}
Beispiel #15
0
func main() {

	file, readErr := ioutil.ReadFile("config.yaml")
	if readErr != nil {
		log.Fatalf("Could not %s", readErr)
	}

	yamlConfig := string(file)

	cfg, cfgErr := config.ParseYaml(yamlConfig)
	if cfgErr != nil {
		log.Fatalf("Please verify the config file's syntax at http://yamllint.com/ %s", cfgErr)
	}

	_, gcssErr := gcss.CompileFile("expose.gcss")
	if gcssErr != nil {
		log.Fatal("Unable to compile gcss file")
	}
	fmt.Println("CSS compiled succesfully")

	imgBaseURL, cfgErr := cfg.String("imgBaseURL")
	if cfgErr != nil {
		log.Fatal(cfgErr)
	}

	jsonData, jsonErr := os.Open("object.json")
	if jsonErr != nil {
		log.Fatal(jsonErr)
	}

	defer jsonData.Close()

	object, decodeErr := decodeObject(jsonData)
	if decodeErr != nil {
		log.Fatal(decodeErr)
	}
	fmt.Println("JSON decoded succesfully")

	objectMap, makeMapError := createMap(object, imgBaseURL)
	if makeMapError != nil {
		log.Fatal(makeMapError)
	}

	//fmt.Println("Object Map:", &objectMap)

	tpl, aceErr := ace.Load("expose", "", nil)
	if aceErr != nil {
		log.Fatal(aceErr)
	}

	// Need a buffer for the template function
	buf := new(bytes.Buffer)

	templateErr := tpl.Execute(buf, objectMap)
	if templateErr != nil {
		log.Fatal("Unable to execute template", templateErr)
	} else {
		fmt.Println("Template executed succesfully")
	}

	// Write html buffer to file
	fileErr := ioutil.WriteFile("expose.html", []byte(buf.String()), 0644)
	if fileErr != nil {
		log.Panic(fileErr)
	}
	fmt.Println("HTML written succesfully")

	// with wrapper
	result, gopdfErr := gopdf.Url2pdf("expose.html")
	fmt.Println(gopdfErr)

	_ = ioutil.WriteFile("expose.pdf", result, 0644)

	// without wrapper, takes less time

	/*
		_, wkErr := exec.Command("wkhtmltopdf", "expose.html", "expose.pdf").Output()
		if wkErr != nil {
			log.Fatal(wkErr)
		}
	*/

	fmt.Println("PDF written succesfully")

	fmt.Println("Success!")
}
func NewConfigContent(configContent string) (*DockerTestConfig, error) {
	config, err := config.ParseYaml(configContent)
	return &DockerTestConfig{config}, err
}
Beispiel #17
0
func main() {

	file, readErr := ioutil.ReadFile("config.yaml")
	if readErr != nil {
		fmt.Println("Could not read config.yaml:", readErr)
		os.Exit(6)
	}

	yamlConfig := string(file)

	cfg, cfgErr := config.ParseYaml(yamlConfig)
	if cfgErr != nil {
		fmt.Println("Please verify the config file's syntax at http://yamllint.com/")
		fmt.Println(cfgErr)
		os.Exit(2)
	}

	host, hostErr := cfg.String("network.host")
	if hostErr != nil {
		fmt.Println(hostErr)
	}
	port, _ := cfg.Int("network.port")
	if port > 65535 {
		fmt.Errorf("Illegal Port, try 6667 or 6697 instead")
	}
	hostPassword, _ := cfg.String("network.password")
	joinChannelName, _ := cfg.String("network.joinChannelName")

	botNick, _ := cfg.String("bot.botNick")
	botUsername, _ := cfg.String("bot.botUsername")
	_, _ = cfg.String("bot.botPassword") //todo: identify with services when set

	USDAAPIKEY, _ := cfg.String("api.USDA.USDA-API-KEY")

	loadBullets()

	fmt.Printf("\nConfig:\nHost: %s Port: %d Password: %s JoinChannel: %s\n\n", host, port, hostPassword, joinChannelName)

	con := irc.IRC(botNick, botUsername)
	con.Password = hostPassword
	err := con.Connect(host + ":" + strconv.Itoa(port))
	if err != nil {
		fmt.Println("Failed connecting :(")
		fmt.Println(err)
		return
	}

	con.AddCallback("001", func(e *irc.Event) {
		con.Join(joinChannelName)
	})

	con.AddCallback("JOIN", func(e *irc.Event) {
	})
	con.AddCallback("PRIVMSG", func(e *irc.Event) {

		args := strings.Split(e.Message(), " ")
		channel := strings.Split(e.Raw, " ")[2]

		if channel == con.GetNick() {
			channel = strings.Split(e.Raw[1:], "!")[0]
			fmt.Printf("Query from %s: %s\n", channel, e.Message())
		} else {
			fmt.Printf("%s - %s: %s\n", channel, e.Nick, e.Message())
		}

		switch args[0] {

		case ".help", ".commands":
			{
				con.Privmsg(channel, "Available commands: .quit .part .join .changelog .date .fortune .larts .weather .nutrition .ping .pong .ayy .coinflip .dice .joint .roulette .echo .bodyfat .starthunt .stophunt .bang")
			}

		case ".quit", ".leave", ".part":
			{
				switch e.Nick {
				//Todo: only let channel ops use this
				case "Moter8", "Phi_is_161803398874989", "jokester", "Solfire", "Potentia", "SodomizingMexican", "Antranik":
					con.Privmsgf(channel, "Leaving at %s's request!", e.Nick)
					delaySecond(1)
					if channel == e.Nick { //not con.GetNick() as we changed that already
						con.Quit()
						fmt.Printf("%s made me quit the Server!\n", e.Nick)
					} else {
						con.Part(channel)
						fmt.Printf("%s made me leave %s\n", e.Nick, channel)
					}
				}
			}

		case ".join", ".enter":
			{
				if len(args) > 1 && args[1][0] == '#' {
					con.Join(args[1])
					fmt.Printf("%s attempts me to join %s\n", e.Nick, args[1])
				}
			}

		case ".changelog", ".readme", ".version":
			{
				con.Privmsg(channel, "I now respond in the channel/query I was written at!")
			}

		case ".date", ".flirt":
			{
				flirtLines, err := readLines("flirts.txt")
				if err != nil {
					fmt.Println("Failed to read flirts.txt file!")
					return
				}
				if len(args) > 1 {
					con.Privmsgf(channel, "%s, "+flirtLines[rand.Intn(len(flirtLines))], args[1])
				}
			}

		case ".fortune", ".fortunes", ".cowsay":
			{
				fortuneLines, err := readLines("fortunes.txt")
				if err != nil {
					fmt.Println("Failed to read fortunes.txt file!")
					return
				}
				if len(args) > 1 {
					con.Privmsgf(channel, "%s, "+fortuneLines[rand.Intn(len(fortuneLines))], args[1])
				}
			}

		case ".larts", ".lart", ".annoy":
			{
				lartLines, err := readLines("larts.txt")
				if err != nil {
					fmt.Println("Failed to read larts.txt file!")
					return
				}
				if len(args) > 1 {
					con.Actionf(channel, lartLines[rand.Intn(len(lartLines))], args[1])
				}
			}

		case ".weather", ".temp", ".temperature":
			{
				args := strings.Split(e.Message(), " ")
				city := ""
				for _, val := range args[1:] {
					city = city + val + " "
				}
				city = strings.TrimSpace(city)

				data, err := queryWeather(city)
				if err != nil {
					fmt.Printf("Error %s, City: %s", err, strings.Title(city))
					con.Privmsgf(channel, "Error getting Weather for %s", strings.Title(city))
					return
				}

				celsius := data.Main.Kelvin - 273.15
				fahrenheit := (data.Main.Kelvin-273.15)*1.8 + 32

				con.Privmsgf(channel, "Weather in %s: %.1f°C - %.2f°F - %d%% Humidity", strings.Title(city), celsius, fahrenheit, data.Main.Humidity)
				fmt.Printf("Weather in %s: %.1f°C - %.2f°F - %d%% Humidity", strings.Title(city), celsius, fahrenheit, data.Main.Humidity)
			}

		case ".nutrition", ".nut", ".calories", ".cal", ".kcal":
			{
				nutrition := ""
				for _, val := range args[1:] {
					nutrition += val + " "
				}
				nutrition = strings.TrimSpace(nutrition)
				data, err := queryNutritionList(nutrition, USDAAPIKEY)

				if err != nil {
					fmt.Printf("Error: %s, Query: \"%s\"", err, nutrition)
					con.Privmsgf(channel, "Error getting Nutrition data for %s", nutrition)
					return
				}

				fmt.Println(data.Report.Food)

				con.Privmsgf(channel, "%s: %.1f kcal - %.1fg Proteins - %.1fg Fats - %.1fg Carbs",
					data.Report.Food.Name,
					data.Report.Food.Nutrients[1].Value,
					data.Report.Food.Nutrients[3].Value,
					data.Report.Food.Nutrients[4].Value,
					data.Report.Food.Nutrients[6].Value,
				)

			}

		case ".ping":
			{
				con.Privmsg(channel, "Pong!")
			}
		case ".pong":
			{
				con.Privmsg(channel, "Ping!")
			}

		case ".ayy", ".ayylmao", ".lmao":
			{
				con.Privmsg(channel, "Ayy Lmao")
			}

		case ".coinflip", ".coin", ".flip", ".flipcoin":
			{
				randNumber := rand.Intn(103)
				con.Privmsg(channel, "Flipping a coin!")
				delaySecond(4)
				if randNumber <= 50 {
					con.Privmsg(channel, "Heads win!")
				} else if randNumber > 50 && randNumber <= 100 {
					con.Privmsg(channel, "Tails win!")
				} else if randNumber == 101 {
					con.Privmsg(channel, "Woops. Seems like I lost the coin!")
				} else {
					con.Privmsg(channel, "The coin landed on its side! No winner!")
				}
			}

		case ".dice", ".roll":
			{
				con.Privmsgf(channel, "You rolled a %d!", rand.Intn(6)+1)
			}

		case "∆", " ∆", "∆ ∆", "  ∆", " ∆ ∆":
			{
				con.Kick(e.Nick, channel, "We aren't 4chan!")
			}

		case ".joint", ".spliff", ".edible", ".brownie", ".weed":
			{
				array := [...]string{"gives %s a bag of weed", "is amazed by %s's plants", "enjoys smoking a spliff with %s", "gives %s an entire Marijuana"}
				fmt.Println("tried to marijuana")
				if len(args) > 1 {
					con.Actionf(channel, array[rand.Intn(len(array))], args[1])
				}
			}

		case ".roulette", ".spin", ".revolver":
			{
				switch rand.Intn(remainingBullets) {
				case 0:
					fmt.Println("Shot a guy")
					con.Kick(e.Nick, channel, "BANG!")

					delaySecond(1)
					con.Action(channel, "reloads and spins the chambers")
					loadBullets()
				case 1:
					fmt.Println("Blanket")
					remainingBullets--
					con.Privmsgf(channel, "*BANG* Hey, who put a blank in here?! %d Bullets remaining!", remainingBullets+1)
				case 2, 3, 4, 5:
					remainingBullets--
					con.Privmsgf(channel, "*SPIN* Are you feeling lucky? %d Bullets remaining!", remainingBullets+1)
				}
			}

		case ".echo":
			{
				newstring := ""
				for _, val := range args[1:] {
					newstring = newstring + val + " "
				}
				if strings.TrimSpace(newstring) != "" {
					con.Privmsgf(channel, "You really want me to say \"%s\"?", strings.TrimSpace(newstring))
				}
			}

		case ".bodyfat", ".bf":
			{
				delaySecond(1)
				array := [...]string{"About tree fiddy", "I'd say about 11%", "Probably around 7%!", "Way less than what I have got!"}
				con.Privmsg(channel, array[rand.Intn(len(array))])
			}

		case ".starthunt":
			{
				if huntActive {
					con.Privmsg(channel, "The Hunt is already going on!")
				} else {
					huntActive = true
					con.Privmsg(channel, "The Hunt is Active! You can probably shoot somehow...")
				}
			}

		case ".stophunt":
			{
				if !huntActive {
					con.Privmsg(channel, "The Hunt is not ongoing!")
				} else {
					huntActive = false
					ducksAlive = 0
					con.Privmsg(channel, "The Hunt has Ended!")
				}
			}

			if huntActive {
				if rand.Intn(150) == 1 {
					fmt.Println("Spawned duck")
					ducksAlive++
					timeSpawn = float64(time.Duration(time.Now().UnixNano()))
					switch rand.Intn(3) {
					default:
						con.Privmsg(channel, "・゜ ​ ゜・。。・゜゜\\​​_0< FLA​P FLAP!")
					case 1:
						con.Privmsg(channel, "・゜゜・。 ​ 。・゜゜\\_ö<​ Q​UACK!")
					case 2:
						con.Privmsg(channel, "・゜ ​ ゜・。。・゜゜\\​​_0< FLA​P FLAP!")
					case 3:
						con.Privmsg(channel, "・゜゜・。 ​ 。・゜゜\\_ö<​ Q​UACK!")
					}
				}

				if args[0] == ".bang" && ducksAlive >= 1 {
					currentTime := float64(time.Duration(time.Now().UnixNano()))
					elapsedTime := (currentTime - timeSpawn) / 1000000000
					switch ducksAlive {
					case 1:
						con.SendRawf("PRIVMSG %s :%s, it took you %s seconds to shoot a duck with a shotgun!", channel, e.Nick, strconv.FormatFloat(elapsedTime, 'f', 3, 64))
					case 2:
						con.SendRawf("PRIVMSG %s :%s, it took you %s seconds to shoot two ducks with a shotgun!", channel, e.Nick, strconv.FormatFloat(elapsedTime, 'f', 3, 64))
					default:
						con.SendRawf("PRIVMSG %s :%s, it took you %s seconds shot a pile of ducks with a rifle!", channel, e.Nick, strconv.FormatFloat(elapsedTime, 'f', 3, 64))
					}
					killDucks()
				} else if args[0] == ".bang" && ducksAlive == 0 {
					con.Kick(e.Nick, channel, "There were no ducks, so you shot yourself! Ouch!")
					fmt.Printf("\nKicked %s\n\n", e.Nick)
				}
			}

		} // close switch

	})
	con.Loop()
}