aboutsummaryrefslogtreecommitdiff
path: root/api/api.go
diff options
context:
space:
mode:
authorjackyzha0 <[email protected]>2020-05-09 20:15:59 -0700
committerjackyzha0 <[email protected]>2020-05-09 20:15:59 -0700
commitdedabf41a18820527aed9e77b75564e69c9030ce (patch)
tree9258832576f9c1bcad6126cf76ef8f7f6a128e82 /api/api.go
parentMerge pull request #3 from jackyzha0/doc-expiry (diff)
downloadctrl-v-dedabf41a18820527aed9e77b75564e69c9030ce.tar.xz
ctrl-v-dedabf41a18820527aed9e77b75564e69c9030ce.zip
folder refactor
Diffstat (limited to 'api/api.go')
-rw-r--r--api/api.go57
1 files changed, 0 insertions, 57 deletions
diff --git a/api/api.go b/api/api.go
deleted file mode 100644
index c197774..0000000
--- a/api/api.go
+++ /dev/null
@@ -1,57 +0,0 @@
-package api
-
-import (
- "net/http"
- "os"
- "os/signal"
- "strconv"
- "syscall"
- "time"
-
- mux "github.com/gorilla/mux"
- log "github.com/sirupsen/logrus"
-)
-
-func cleanup() {
- log.Print("Shutting down server...")
-}
-
-// Define router and start server
-func Serve(port int) {
- // Sigint trapper
- c := make(chan os.Signal)
- signal.Notify(c, os.Interrupt, syscall.SIGTERM)
- go func() {
- <-c
- cleanup()
- os.Exit(0)
- }()
-
- // Define Mux Router
- r := mux.NewRouter()
- r.HandleFunc("/health", healthCheckFunc)
- r.HandleFunc("/api", insertFunc).Methods("POST")
- r.HandleFunc("/api/{hash}", getHashFunc).Methods("GET")
-
- http.Handle("/", r)
-
- // Start HTTP server
- server := newServer(":"+strconv.Itoa(port), r)
- log.Printf("Starting server on %d", port)
-
- defer cleanup()
- err := server.ListenAndServe()
- if err != nil {
- log.Fatal(err)
- }
-}
-
-// Function to create new HTTP server
-func newServer(addr string, router http.Handler) *http.Server {
- return &http.Server{
- Addr: addr,
- Handler: router,
- ReadTimeout: time.Second * 30,
- WriteTimeout: time.Second * 30,
- }
-}