Skip to content

Instantly share code, notes, and snippets.

@Linuturk

Linuturk/main.go Secret

Last active October 23, 2017 21:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Linuturk/97c85c91c972c6ebf9fce9db01e12d62 to your computer and use it in GitHub Desktop.
Save Linuturk/97c85c91c972c6ebf9fce9db01e12d62 to your computer and use it in GitHub Desktop.
package main
import (
"flag"
"fmt"
"io"
"log"
"net/http"
"os"
"strconv"
"github.com/manyminds/api2go"
"domain.com/user/mypkg"
)
var portFlag = flag.Int(snip)
var cassandraAppFlag = flag.String(snip)
var cassandraKeyspaceFlag = flag.String(snip)
// logPath returns a file hander or os.Stdout based on
// whether this is local dev or deployed in EC2
func logFile() io.Writer {
snip
}
// initDB initializes the database session
func initDB(app, keyspace string) error {
snip
}
func main() {
// parse flags and set port
flag.Parse()
port := fmt.Sprintf(":%v", strconv.Itoa(*portFlag))
app := *cassandraAppFlag
keyspace := *cassandraKeyspaceFlag
// init DB connection
err := initDB(app, keyspace)
if err != nil {
log.Fatalf("Failed to connect to database: %v", err)
}
// new jsonapi spec
api := api2go.NewAPI("v2")
api.AddResource(Device{}, &Device{})
api.AddResource(Family{}, &Family{})
api.AddResource(Job{}, &Job{})
api.AddResource(Sequence{}, &Sequence{})
// Index, Healthcheck, initDatabase
r := api.Router()
r.Handle("GET", "/", mypkg.Index)
r.Handle("GET", "/healthcheck", mypkg.HealthCheck)
r.Handle("GET", "/InitDB", mypkg.InitDB)
// launch http service
log.Printf("Launching server on http://localhost%v\n", port)
log.Fatal(http.ListenAndServe(port, api.Handler()))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment