Browse Source

added configuration

dependabot/npm_and_yarn/web/prismjs-1.21.0
Max Schmitt 8 years ago
parent
commit
38cd8445df
  1. 3
      README.md
  2. 1
      handlers/handlers.go
  3. 21
      main.go

3
README.md

@ -23,9 +23,6 @@ Only execute the [docker-compose.yml](docker-compose.yml) and adjust the envirom
## TODOs ## TODOs
- Unit tests
- code refactoring
- enviroment or configuration file integration
- github publishing - github publishing
- authentification - authentification
- deletion - deletion

1
handlers/handlers.go

@ -155,7 +155,6 @@ func (h *Handler) handleInfo(w http.ResponseWriter, r *http.Request, p httproute
raw, err := h.store.GetEntryByIDRaw(req.ID) raw, err := h.store.GetEntryByIDRaw(req.ID)
if err != nil { if err != nil {
http.Error(w, err.Error(), http.StatusNotFound) http.Error(w, err.Error(), http.StatusNotFound)
return return
} }
w.Header().Add("Content-Type", "application/json") w.Header().Add("Content-Type", "application/json")

21
main.go

@ -4,19 +4,36 @@ import (
"log" "log"
"os" "os"
"os/signal" "os/signal"
"strconv"
"github.com/maxibanki/golang-url-shorter/handlers" "github.com/maxibanki/golang-url-shorter/handlers"
"github.com/maxibanki/golang-url-shorter/store" "github.com/maxibanki/golang-url-shorter/store"
) )
func main() { func main() {
dbPath := "main.db"
listenAddr := ":8080"
idLength := uint(4)
if os.Getenv("SHORTER_DB_PATH") != "" {
dbPath = os.Getenv("SHORTER_DB_PATH")
}
if os.Getenv("SHORTER_LISTEN_ADDR") != "" {
listenAddr = os.Getenv("SHORTER_LISTEN_ADDR")
}
if os.Getenv("SHORTER_ID_LENGTH") != "" {
length, err := strconv.ParseUint(os.Getenv("SHORTER_ID_LENGTH"), 10, 32)
if err != nil {
log.Fatalf("could not convert ID length into an uint: %v", err)
}
idLength = uint(length)
}
stop := make(chan os.Signal, 1) stop := make(chan os.Signal, 1)
signal.Notify(stop, os.Interrupt) signal.Notify(stop, os.Interrupt)
store, err := store.New("main.db", 4) store, err := store.New(dbPath, idLength)
if err != nil { if err != nil {
log.Fatalf("could not create store: %v", err) log.Fatalf("could not create store: %v", err)
} }
handler := handlers.New(":8080", *store) handler := handlers.New(listenAddr, *store)
go func() { go func() {
err := handler.Listen() err := handler.Listen()
if err != nil { if err != nil {

Loading…
Cancel
Save