-
-
Save Linuturk/97c85c91c972c6ebf9fce9db01e12d62 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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