Browse Source

- Removed that the IP of the creator will be shown in the info request

- improved README.md
dependabot/npm_and_yarn/web/prismjs-1.21.0
Max Schmitt 8 years ago
parent
commit
3ec2257880
  1. 48
      README.md
  2. 9
      handlers/handlers.go
  3. 2
      store/store.go

48
README.md

@ -2,26 +2,38 @@
## Features: ## Features:
- URL Shortening with visiter counting - URL Shortening with visitor counting
- Delete an entry - Deletion URLs
- Authorization - Authorization System
- Storing using BoltDB - High Performance database with [bolt](https://github.com/boltdb/bolt)
- Easy ShareX integration - ShareX integration
- Selfhosted - Easy Docker Deployment
## Installation ## Server Installation
### Standard ### Standard
```bash ```bash
git clone https://github.com/maxibanki/golang-url-shortener
go get -v ./... go get -v ./...
go run -v main.go go build
./golang-url-shortener
``` ```
### Docker Compose ### 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`. 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 - Authentification
- Deletion
- github publishing - Github publishing
- authentification - Add shields:
- deletion - downloads
- ShareX example - travis
- godoc
- license

9
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) http.Error(w, "no ID provided", http.StatusBadRequest)
return return
} }
raw, err := h.store.GetEntryByIDRaw(req.ID) entry, err := h.store.GetEntryByID(req.ID)
if err != nil { if err != nil {
http.Error(w, err.Error(), http.StatusNotFound) http.Error(w, err.Error(), http.StatusNotFound)
return return
} }
entry.RemoteAddr = ""
w.Header().Add("Content-Type", "application/json") 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 // handleAccess handles the access for incoming requests

2
store/store.go

@ -21,7 +21,7 @@ type Store struct {
type Entry struct { type Entry struct {
URL string URL string
VisitCount int VisitCount int
RemoteAddr string RemoteAddr string `json:",omitempty"`
CreatedOn time.Time CreatedOn time.Time
LastVisit time.Time LastVisit time.Time
} }

Loading…
Cancel
Save