Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from ob-vss-ss18/refactor
Restructure files
- Loading branch information
Showing
6 changed files
with
87 additions
and
54 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package api | ||
|
||
import ( | ||
"log" | ||
|
||
"github.com/graphql-go/graphql" | ||
"github.com/graphql-go/handler" | ||
) | ||
|
||
var ApiHandler *handler.Handler | ||
|
||
func init() { | ||
schema, err := graphql.NewSchema(graphql.SchemaConfig{ | ||
Query: QueryType, | ||
// Mutation: MutationType, | ||
}) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
ApiHandler = handler.New(&handler.Config{ | ||
Schema: &schema, | ||
GraphiQL: true, | ||
}) | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package main | ||
package api | ||
|
||
import ( | ||
"github.com/graphql-go/graphql" | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package backend | ||
|
||
import ( | ||
"database/sql" | ||
"log" | ||
"os" | ||
|
||
"github.com/golang-migrate/migrate" | ||
"github.com/golang-migrate/migrate/database/postgres" | ||
_ "github.com/golang-migrate/migrate/source/file" | ||
_ "github.com/lib/pq" | ||
) | ||
|
||
var db *sql.DB | ||
|
||
func ConnectDb() { | ||
var err error | ||
log.Printf("Connecting to database '%s'\n", os.Getenv("DATABASE_URL")) | ||
db, err = sql.Open("postgres", os.Getenv("DATABASE_URL")) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
} | ||
|
||
func MigrateDb() { | ||
driver, err := postgres.WithInstance(db, &postgres.Config{}) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
m, err := migrate.NewWithDatabaseInstance( | ||
"file://../migrations/", | ||
"postgres", driver) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
m.Log = migrationLogger{false} | ||
log.Printf("Running needed migrations\n") | ||
m.Up() | ||
} | ||
|
||
type migrationLogger struct { | ||
verbose bool | ||
} | ||
|
||
func (m migrationLogger) Printf(format string, v ...interface{}) { | ||
log.Printf(format, v...) | ||
} | ||
|
||
func (m migrationLogger) Verbose() bool { | ||
return m.verbose | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package main | ||
package backend | ||
|
||
type User struct { | ||
ID int `json:"id"` | ||
|
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