import main app, dep files
This commit is contained in:
parent
2751cc33f7
commit
5e617c76fb
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
/build
|
||||
75
Gopkg.lock
generated
Normal file
75
Gopkg.lock
generated
Normal file
@ -0,0 +1,75 @@
|
||||
# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'.
|
||||
|
||||
|
||||
[[projects]]
|
||||
name = "github.com/go-chi/chi"
|
||||
packages = [
|
||||
".",
|
||||
"middleware"
|
||||
]
|
||||
revision = "e83ac2304db3c50cf03d96a2fcd39009d458bc35"
|
||||
version = "v3.3.2"
|
||||
|
||||
[[projects]]
|
||||
name = "github.com/go-chi/cors"
|
||||
packages = ["."]
|
||||
revision = "dba6525398619dead495962a916728e7ee2ca322"
|
||||
version = "v1.0.0"
|
||||
|
||||
[[projects]]
|
||||
name = "github.com/go-sql-driver/mysql"
|
||||
packages = ["."]
|
||||
revision = "d523deb1b23d913de5bdada721a6071e71283618"
|
||||
version = "v1.4.0"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/jmoiron/sqlx"
|
||||
packages = [
|
||||
".",
|
||||
"reflectx"
|
||||
]
|
||||
revision = "2aeb6a910c2b94f2d5eb53d9895d80e27264ec41"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/lib/pq"
|
||||
packages = [
|
||||
".",
|
||||
"oid"
|
||||
]
|
||||
revision = "90697d60dd844d5ef6ff15135d0203f65d2f53b8"
|
||||
|
||||
[[projects]]
|
||||
name = "github.com/pkg/errors"
|
||||
packages = ["."]
|
||||
revision = "645ef00459ed84a119197bfb8d8205042c6df63d"
|
||||
version = "v0.8.0"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/sony/sonyflake"
|
||||
packages = ["."]
|
||||
revision = "fa881fb1052b152e977c41023052c2f2a1c475e9"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/titpetric/factory"
|
||||
packages = [
|
||||
".",
|
||||
"resputil"
|
||||
]
|
||||
revision = "65282e3db1e919ad2c9c50afc2cd270019e5e360"
|
||||
|
||||
[[projects]]
|
||||
name = "google.golang.org/appengine"
|
||||
packages = ["cloudsql"]
|
||||
revision = "150dc57a1b433e64154302bdc40b6bb8aefa313a"
|
||||
version = "v1.0.0"
|
||||
|
||||
[solve-meta]
|
||||
analyzer-name = "dep"
|
||||
analyzer-version = 1
|
||||
inputs-digest = "f598552769c6b338e9bbb91c55da9bd072beca1d44b8e6fa8747ac72f205e11b"
|
||||
solver-name = "gps-cdcl"
|
||||
solver-version = 1
|
||||
46
Gopkg.toml
Normal file
46
Gopkg.toml
Normal file
@ -0,0 +1,46 @@
|
||||
# Gopkg.toml example
|
||||
#
|
||||
# Refer to https://golang.github.io/dep/docs/Gopkg.toml.html
|
||||
# for detailed Gopkg.toml documentation.
|
||||
#
|
||||
# required = ["github.com/user/thing/cmd/thing"]
|
||||
# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"]
|
||||
#
|
||||
# [[constraint]]
|
||||
# name = "github.com/user/project"
|
||||
# version = "1.0.0"
|
||||
#
|
||||
# [[constraint]]
|
||||
# name = "github.com/user/project2"
|
||||
# branch = "dev"
|
||||
# source = "github.com/myfork/project2"
|
||||
#
|
||||
# [[override]]
|
||||
# name = "github.com/x/y"
|
||||
# version = "2.4.0"
|
||||
#
|
||||
# [prune]
|
||||
# non-go = false
|
||||
# go-tests = true
|
||||
# unused-packages = true
|
||||
|
||||
|
||||
[[constraint]]
|
||||
name = "github.com/go-chi/chi"
|
||||
version = "3.3.2"
|
||||
|
||||
[[constraint]]
|
||||
name = "github.com/go-chi/cors"
|
||||
version = "1.0.0"
|
||||
|
||||
[[constraint]]
|
||||
name = "github.com/pkg/errors"
|
||||
version = "0.8.0"
|
||||
|
||||
[[constraint]]
|
||||
branch = "master"
|
||||
name = "github.com/titpetric/factory"
|
||||
|
||||
[prune]
|
||||
go-tests = true
|
||||
unused-packages = true
|
||||
27
build.sh
Executable file
27
build.sh
Executable file
@ -0,0 +1,27 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
PROJECT=$(basename $(dirname $(readlink -f $0)))
|
||||
|
||||
if [ -d "vendor" ]; then
|
||||
docker run --rm -v $(pwd):/go/src/github.com/titpetric/$PROJECT -w /go/src/github.com/titpetric/$PROJECT -e GOOS=${OS} -e GOARCH=${ARCH} -e CGO_ENABLED=0 -e GOARM=7 titpetric/golang dep ensure
|
||||
else
|
||||
docker run --rm -v $(pwd):/go/src/github.com/titpetric/$PROJECT -w /go/src/github.com/titpetric/$PROJECT -e GOOS=${OS} -e GOARCH=${ARCH} -e CGO_ENABLED=0 -e GOARM=7 titpetric/golang dep init
|
||||
fi
|
||||
|
||||
NAMES=$(ls cmd/* -d | xargs -n1 basename)
|
||||
for NAME in $NAMES; do
|
||||
OSES=${OSS:-"linux"}
|
||||
ARCHS=${ARCHS:-"amd64"}
|
||||
for ARCH in $ARCHS; do
|
||||
for OS in $OSES; do
|
||||
echo $OS $ARCH $NAME
|
||||
docker run --rm -v $(pwd):/go/src/github.com/titpetric/$PROJECT -w /go/src/github.com/titpetric/$PROJECT -e GOOS=${OS} -e GOARCH=${ARCH} -e CGO_ENABLED=0 -e GOARM=7 titpetric/golang go build -o build/${NAME}-${OS}-${ARCH} cmd/${NAME}/*.go
|
||||
if [ $? -eq 0 ]; then
|
||||
echo OK
|
||||
fi
|
||||
if [ "$OS" == "windows" ]; then
|
||||
mv build/${NAME}-${OS}-${ARCH} build/${NAME}-${OS}-${ARCH}.exe
|
||||
fi
|
||||
done
|
||||
done
|
||||
done
|
||||
58
cmd/sam/main.go
Normal file
58
cmd/sam/main.go
Normal file
@ -0,0 +1,58 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"log"
|
||||
"net"
|
||||
"os"
|
||||
|
||||
"net/http"
|
||||
|
||||
"github.com/go-chi/chi"
|
||||
|
||||
"github.com/titpetric/crust/sam"
|
||||
"github.com/titpetric/factory"
|
||||
)
|
||||
|
||||
func handleError(err error, message string) {
|
||||
if message == "" {
|
||||
message = "Error making API call"
|
||||
}
|
||||
if err != nil {
|
||||
log.Fatalf(message+": %v", err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
// set up flags
|
||||
var (
|
||||
addr = flag.String("addr", ":3000", "Listen address for HTTP server")
|
||||
)
|
||||
flag.Parse()
|
||||
|
||||
// log to stdout not stderr
|
||||
log.SetOutput(os.Stdout)
|
||||
|
||||
// set up database connection
|
||||
factory.Database.Add("default", "crust:crust@tcp(db1:3306)/crust?collation=utf8mb4_general_ci")
|
||||
|
||||
/*
|
||||
db, err := factory.Database.Get()
|
||||
handleError(err, "Can't connect to database")
|
||||
db.Profiler = &factory.Database.ProfilerStdout
|
||||
*/
|
||||
|
||||
// listen socket for http server
|
||||
log.Println("Starting http server on address " + *addr)
|
||||
listener, err := net.Listen("tcp", *addr)
|
||||
handleError(err, "Can't listen on addr "+*addr)
|
||||
|
||||
// route options
|
||||
routeOptions, err := RouteOptions{}.New()
|
||||
handleError(err, "Error creating RouteOptions object")
|
||||
|
||||
// mount routes
|
||||
r := chi.NewRouter()
|
||||
MountRoutes(r, routeOptions, sam.MountRoutes)
|
||||
http.Serve(listener, r)
|
||||
}
|
||||
16
cmd/sam/options.go
Normal file
16
cmd/sam/options.go
Normal file
@ -0,0 +1,16 @@
|
||||
package main
|
||||
|
||||
type RouteOptions struct {
|
||||
enableLogging bool
|
||||
}
|
||||
|
||||
func (RouteOptions) New() (*RouteOptions, error) {
|
||||
opts := &RouteOptions{}
|
||||
opts.enableLogging = true
|
||||
return opts, nil
|
||||
}
|
||||
|
||||
func (o *RouteOptions) EnableLogging(enable bool) *RouteOptions {
|
||||
o.enableLogging = enable
|
||||
return o
|
||||
}
|
||||
26
cmd/sam/routes.go
Normal file
26
cmd/sam/routes.go
Normal file
@ -0,0 +1,26 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/go-chi/chi"
|
||||
"github.com/go-chi/chi/middleware"
|
||||
"github.com/go-chi/cors"
|
||||
)
|
||||
|
||||
// MountRoutes will register API routes
|
||||
func MountRoutes(r chi.Router, opts *RouteOptions, mountRoutes func(r chi.Router)) {
|
||||
// CORS for local development...
|
||||
cors := cors.New(cors.Options{
|
||||
AllowedOrigins: []string{"*"},
|
||||
AllowedMethods: []string{"GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS"},
|
||||
AllowedHeaders: []string{"Accept", "Authorization", "Content-Type", "X-CSRF-Token"},
|
||||
AllowCredentials: true,
|
||||
MaxAge: 300, // Maximum value not ignored by any of major browsers
|
||||
})
|
||||
r.Use(cors.Handler)
|
||||
|
||||
if opts.enableLogging {
|
||||
r.Use(middleware.Logger)
|
||||
}
|
||||
|
||||
mountRoutes(r)
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user