Browse Source

fixed naming to URL Shortener

dependabot/npm_and_yarn/web/prismjs-1.21.0
Max Schmitt 8 years ago
parent
commit
e45d710df4
  1. 30
      README.md
  2. 2
      docker-compose.yml
  3. 2
      handlers/handlers.go
  4. 3
      handlers/handlers_test.go
  5. 16
      main.go

30
README.md

@ -1,11 +1,13 @@
# Golang URL Shorter using BoltDB # Golang URL Shortener using BoltDB
## Features: ## Features:
- URL Shorting with visit counting - URL Shortening with visiter counting
- delete a URL - Delete an entry
- Authorization via tokens - Authorization
- Storing using BoltDB - Storing using BoltDB
- Easy ShareX integration
- Selfhosted
## Installation ## Installation
@ -21,6 +23,26 @@ Only execute the [docker-compose.yml](docker-compose.yml) and adjust the envirom
## [ShareX](https://github.com/ShareX/ShareX) Configuration ## [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`.
After you've done this, you need to set it as your standard URL Shortener. For that go back into your main menu => `Destinations` => `URL Shortener` => `Custom URL Shortener`.
```json
{
"Name": "Golang URL Shortener",
"DestinationType": "URLShortener",
"RequestType": "POST",
"RequestURL": "http://127.0.0.1:8080/api/v1/create",
"Arguments": {
"URL": "$input$"
},
"ResponseType": "Text",
"URL": "$json:URL$"
}
```
## TODOs ## TODOs
- github publishing - github publishing

2
docker-compose.yml

@ -1,4 +1,4 @@
shorter: shortener:
image: golang image: golang
restart: always restart: always
command: ./run.sh command: ./run.sh

2
handlers/handlers.go

@ -8,7 +8,7 @@ import (
"strings" "strings"
"github.com/julienschmidt/httprouter" "github.com/julienschmidt/httprouter"
"github.com/maxibanki/golang-url-shorter/store" "github.com/maxibanki/golang-url-shortener/store"
) )
// Handler holds the funcs and attributes for the // Handler holds the funcs and attributes for the

3
handlers/handlers_test.go

@ -12,12 +12,11 @@ import (
"strings" "strings"
"testing" "testing"
"github.com/maxibanki/golang-url-shorter/store" "github.com/maxibanki/golang-url-shortener/store"
"github.com/pkg/errors" "github.com/pkg/errors"
) )
const ( const (
baseURL = "http://myshorter"
testingDBName = "main.db" testingDBName = "main.db"
testURL = "https://www.google.de/" testURL = "https://www.google.de/"
) )

16
main.go

@ -6,22 +6,22 @@ import (
"os/signal" "os/signal"
"strconv" "strconv"
"github.com/maxibanki/golang-url-shorter/handlers" "github.com/maxibanki/golang-url-shortener/handlers"
"github.com/maxibanki/golang-url-shorter/store" "github.com/maxibanki/golang-url-shortener/store"
) )
func main() { func main() {
dbPath := "main.db" dbPath := "main.db"
listenAddr := ":8080" listenAddr := ":8080"
idLength := uint(4) idLength := uint(4)
if os.Getenv("SHORTER_DB_PATH") != "" { if os.Getenv("SHORTENER_DB_PATH") != "" {
dbPath = os.Getenv("SHORTER_DB_PATH") dbPath = os.Getenv("SHORTENER_DB_PATH")
} }
if os.Getenv("SHORTER_LISTEN_ADDR") != "" { if os.Getenv("SHORTENER_LISTEN_ADDR") != "" {
listenAddr = os.Getenv("SHORTER_LISTEN_ADDR") listenAddr = os.Getenv("SHORTENER_LISTEN_ADDR")
} }
if os.Getenv("SHORTER_ID_LENGTH") != "" { if os.Getenv("SHORTENER_ID_LENGTH") != "" {
length, err := strconv.ParseUint(os.Getenv("SHORTER_ID_LENGTH"), 10, 32) length, err := strconv.ParseUint(os.Getenv("SHORTENER_ID_LENGTH"), 10, 32)
if err != nil { if err != nil {
log.Fatalf("could not convert ID length into an uint: %v", err) log.Fatalf("could not convert ID length into an uint: %v", err)
} }

Loading…
Cancel
Save