From 3ec2257880b9d321096b7858e47bd44873fcd97d Mon Sep 17 00:00:00 2001 From: Max Schmitt Date: Sun, 29 Oct 2017 23:49:36 +0100 Subject: [PATCH] - Removed that the IP of the creator will be shown in the info request - improved README.md --- README.md | 48 +++++++++++++++++++++++++++++--------------- handlers/handlers.go | 9 +++++++-- store/store.go | 2 +- 3 files changed, 40 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index f0c7071..961f309 100644 --- a/README.md +++ b/README.md @@ -2,26 +2,38 @@ ## Features: -- URL Shortening with visiter counting -- Delete an entry -- Authorization -- Storing using BoltDB -- Easy ShareX integration -- Selfhosted +- URL Shortening with visitor counting +- Deletion URLs +- Authorization System +- High Performance database with [bolt](https://github.com/boltdb/bolt) +- ShareX integration +- Easy Docker Deployment -## Installation +## Server Installation ### Standard ```bash +git clone https://github.com/maxibanki/golang-url-shortener go get -v ./... -go run -v main.go +go build +./golang-url-shortener ``` ### Docker Compose -Only execute the [docker-compose.yml](docker-compose.yml) and adjust the enviroment variables to your needs. +- Only execute the [docker-compose.yml](docker-compose.yml) and adjust the enviroment variables to your needs. -## [ShareX](https://github.com/ShareX/ShareX) Configuration +### Envirment Variables: + +| Envirment Variable | Description | Default Value | +| ------------------ | ----------- | ------------- | +| SHORTENER_DB_PATH | Relative or absolute path to the bolt DB | main.db | +| SHORTENER_LISTEN_ADDR | Adress to which the http server should listen to | :8080 | +| SHORTENER_ID_LENGTH | Length of the random short URL id | 4 | + +## Clients: + +### [ShareX](https://github.com/ShareX/ShareX) Configuration This URL Shortener has fully support with ShareX. To use it, just import the configuration to your ShareX. For that you need to open the `Destination settings` => `Other / Custom uploaders` => `Import` => `From Clipboard`. @@ -41,11 +53,15 @@ After you've done this, you need to set it as your standard URL Shortener. For t } ``` +### Curl +## TODO -## TODOs - -- github publishing -- authentification -- deletion - - ShareX example \ No newline at end of file +- Authentification +- Deletion +- Github publishing +- Add shields: + - downloads + - travis + - godoc + - license \ No newline at end of file diff --git a/handlers/handlers.go b/handlers/handlers.go index 7e1d622..872a3be 100644 --- a/handlers/handlers.go +++ b/handlers/handlers.go @@ -152,13 +152,18 @@ func (h *Handler) handleInfo(w http.ResponseWriter, r *http.Request, p httproute http.Error(w, "no ID provided", http.StatusBadRequest) return } - raw, err := h.store.GetEntryByIDRaw(req.ID) + entry, err := h.store.GetEntryByID(req.ID) if err != nil { http.Error(w, err.Error(), http.StatusNotFound) return } + entry.RemoteAddr = "" w.Header().Add("Content-Type", "application/json") - w.Write(raw) + err = json.NewEncoder(w).Encode(entry) + if err != nil { + http.Error(w, err.Error(), http.StatusNotFound) + return + } } // handleAccess handles the access for incoming requests diff --git a/store/store.go b/store/store.go index e4ecdab..c633758 100644 --- a/store/store.go +++ b/store/store.go @@ -21,7 +21,7 @@ type Store struct { type Entry struct { URL string VisitCount int - RemoteAddr string + RemoteAddr string `json:",omitempty"` CreatedOn time.Time LastVisit time.Time }