Exemplo n.º 1
0
	"net/http"

	"github.com/dancannon/gorethink"
	"github.com/gorilla/context"
	"github.com/julienschmidt/httprouter"

	"github.com/golang-vietnam/grox/api/rethink"
	"github.com/golang-vietnam/grox/api/xhttp"
	"github.com/golang-vietnam/grox/dbscript"
	"github.com/golang-vietnam/grox/handlers"
	"github.com/golang-vietnam/grox/middlewares"
	"github.com/golang-vietnam/grox/stores"
	"github.com/golang-vietnam/grox/utils/logs"
)

var l = logs.New("grox/server")

type setupStruct struct {
	Config

	Rethink *rethink.Instance
	Handler http.Handler
}

func setup(cfg Config) *setupStruct {
	s := &setupStruct{Config: cfg}
	s.setupRethink()
	s.setupRoutes()

	return s
}
Exemplo n.º 2
0
Arquivo: main.go Projeto: ngthorg/grox
package main

import (
	"flag"

	"github.com/golang-vietnam/grox/server"
	"github.com/golang-vietnam/grox/utils/load-config"
	"github.com/golang-vietnam/grox/utils/logs"
)

var (
	flConfigFile = flag.String("config-file", "config-default.json", "Load config from file")

	l = logs.New("grox-server")
)

func main() {
	flag.Parse()

	var cfg server.Config
	err := loadConfig.FromFileAndEnv(&cfg, *flConfigFile)
	if err != nil {
		l.Fatalln("Error loading config:", err)
	}

	server.Start(cfg)
}
Exemplo n.º 3
0
	"encoding/json"
	"io/ioutil"
	"os"
	"path/filepath"
	"reflect"
	"strings"

	"github.com/golang-vietnam/grox/utils/logs"
)

const (
	pkgName = "utils/load-config"
)

var (
	l = logs.New(pkgName)
)

func FromFileAndEnv(cfg interface{}, configPath string) error {
	err := FromFile(cfg, configPath)
	if err != nil {
		return err
	}

	FromEnv(cfg, "")
	return nil
}

func FromFile(cfg interface{}, configPath string) error {
	absPath, err := filepath.Abs(configPath)
	if err != nil {
Exemplo n.º 4
0
package rethink

import (
	r "github.com/dancannon/gorethink"

	"github.com/golang-vietnam/grox/utils/logs"
)

var (
	l = logs.New("api/rethink")
)

type Instance struct {
	opts    r.ConnectOpts
	session *r.Session

	db string
}

func NewInstance(opts r.ConnectOpts) (ins *Instance, err error) {
	ins = &Instance{
		opts: opts,
		db:   opts.Database,
	}

	ins.session, err = r.Connect(opts)
	if err != nil {
		return nil, err
	}

	return ins, nil
Exemplo n.º 5
0
func NewRecovery() func(http.Handler) http.Handler {
	r := Recovery{logs.New("Recovery")}
	return r.factory
}
Exemplo n.º 6
0
func NewLogger() func(http.Handler) http.Handler {
	l := Logger{logs.New("HTTP")}
	return l.factory
}
Exemplo n.º 7
0
package dbscript

import (
	"strings"

	"github.com/dancannon/gorethink"
	"github.com/golang-vietnam/grox/api/rethink"
	"github.com/golang-vietnam/grox/stores"
	"github.com/golang-vietnam/grox/utils/logs"
)

var l = logs.New("dbscript")

type RethinkScript struct {
	re     *rethink.Instance
	dbname string
}

func NewRethinkScript(re *rethink.Instance, dbname string) *RethinkScript {
	if len(strings.TrimSpace(dbname)) == 0 {
		l.Fatalln("Empty database name")
	}
	return &RethinkScript{
		re:     re,
		dbname: dbname,
	}
}
func (this *RethinkScript) Setup() error {
	dbname := this.dbname
	err := this.re.Exec(gorethink.DB(dbname).Info())