-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
249 additions
and
221 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,15 @@ | ||
package api | ||
|
||
import ( | ||
"github.com/gocodo/bloomdb" | ||
) | ||
|
||
var bloomConn *bloomdb.BloomDatabase | ||
|
||
func Conn() *bloomdb.BloomDatabase { | ||
if bloomConn == nil { | ||
bloomConn = bloomdb.CreateDB() | ||
} | ||
|
||
return bloomConn | ||
} |
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
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
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,28 +1,27 @@ | ||
package bloomapi | ||
package cmd | ||
|
||
import ( | ||
"log" | ||
"io/ioutil" | ||
"github.com/gocodo/bloomdb" | ||
) | ||
|
||
func Drop() { | ||
bloomdb := bloomdb.CreateDB() | ||
|
||
file, err := ioutil.ReadFile("drop.sql") | ||
if err != nil { | ||
log.Fatal("Failed to read file.", err) | ||
} | ||
|
||
metaSql := string(file[:]) | ||
conn, err := bloomdb.SqlConnection() | ||
if err != nil { | ||
log.Fatal("Failed to get database connection.", err) | ||
} | ||
defer conn.Close() | ||
|
||
_, err = conn.Exec(metaSql) | ||
_, err = conn.Exec(dropSql) | ||
if err != nil { | ||
log.Fatal("Failed to create metadata tables.", err) | ||
} | ||
} | ||
} | ||
|
||
var dropSql = | ||
`DROP TABLE IF EXISTS sources; | ||
DROP TABLE IF EXISTS source_tables; | ||
DROP TABLE IF EXISTS source_versions; | ||
DROP TABLE IF EXISTS search_types;` |
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,39 @@ | ||
package cmd | ||
|
||
import ( | ||
"log" | ||
"github.com/codegangsta/negroni" | ||
"github.com/spf13/viper" | ||
"github.com/gorilla/mux" | ||
|
||
"github.com/untoldone/bloomapi/middleware" | ||
"github.com/untoldone/bloomapi/handler" | ||
"github.com/untoldone/bloomapi/handler_compat" | ||
) | ||
|
||
func Server() { | ||
port := viper.GetString("bloomapiPort") | ||
n := negroni.Classic() | ||
|
||
// Middleware setup | ||
n.Use(middleware.NewAuthentication()) | ||
|
||
// Router setup | ||
router := mux.NewRouter() | ||
|
||
// Current API | ||
router.HandleFunc("/api/sources", handler.SourcesHandler).Methods("GET") | ||
router.HandleFunc("/api/search/{source}", handler.SearchSourceHandler).Methods("GET") | ||
router.HandleFunc("/api/sources/{source}/{id}", handler.ItemHandler).Methods("GET") | ||
|
||
// For Backwards Compatibility Feb 13, 2015 | ||
router.HandleFunc("/api/search", handler_compat.NpiSearchHandler).Methods("GET") | ||
router.HandleFunc("/api/search/npi", handler_compat.NpiSearchHandler).Methods("GET") | ||
router.HandleFunc("/api/npis/{npi:[0-9]+}", handler_compat.NpiItemHandler).Methods("GET") | ||
router.HandleFunc("/api/sources/npi/{npi:[0-9]+}", handler_compat.NpiItemHandler).Methods("GET") | ||
|
||
n.UseHandler(router) | ||
|
||
log.Println("Running Server") | ||
n.Run(":" + port) | ||
} |
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
Oops, something went wrong.