update reademe and use flags

This commit is contained in:
Eliot Whalan 2016-07-15 15:05:51 +10:00
parent edf3f836e8
commit 07a5f9e32b
No known key found for this signature in database
GPG Key ID: C0A42175139840D6
2 changed files with 20 additions and 8 deletions

View File

@ -25,8 +25,11 @@ sudo yum install -y go mariadb-server mariadb
* go get https://github.com/ewhal/Pastebin * go get https://github.com/ewhal/Pastebin
* nano pastebin.go * nano pastebin.go
* Configure port and database details
* make * make
```
./pastebin --db-name="pastes" --db-username="pastebin" --db-pass=""
--port=":9900" --length=6
```
## License ## License

View File

@ -7,6 +7,7 @@ import (
"encoding/base64" "encoding/base64"
"encoding/json" "encoding/json"
"encoding/xml" "encoding/xml"
"flag"
"fmt" "fmt"
"html" "html"
"html/template" "html/template"
@ -27,19 +28,19 @@ import (
"github.com/gorilla/mux" "github.com/gorilla/mux"
) )
const ( var (
// ADDRESS that pastebin will return links for // ADDRESS that pastebin will return links for
ADDRESS = "http://localhost:9900" ADDRESS string
// LENGTH of paste id // LENGTH of paste id
LENGTH = 6 LENGTH int
// PORT that pastebin will listen on // PORT that pastebin will listen on
PORT = ":9900" PORT string
// USERNAME for database // USERNAME for database
USERNAME = "" USERNAME string
// PASS database password // PASS database password
PASS = "" PASS string
// NAME database name // NAME database name
NAME = "" NAME string
// DATABASE connection String // DATABASE connection String
DATABASE = USERNAME + ":" + PASS + "@/" + NAME + "?charset=utf8" DATABASE = USERNAME + ":" + PASS + "@/" + NAME + "?charset=utf8"
) )
@ -380,6 +381,14 @@ func RootHandler(w http.ResponseWriter, r *http.Request) {
} }
func main() { func main() {
flag.StringVar(&ADDRESS, "address", "", "host to serve pastes on")
flag.StringVar(&PORT, "port", ":9990", "host to serve pastes on")
flag.StringVar(&USERNAME, "db-username", "", "db username")
flag.StringVar(&PASS, "db-pass", "", "db pass")
flag.StringVar(&NAME, "db-name", "", "db name")
flag.IntVar(&LENGTH, "id-length", 6, "length of uploaded file IDs")
flag.Parse()
router := mux.NewRouter() router := mux.NewRouter()
router.HandleFunc("/p/{pasteId}", PasteHandler).Methods("GET") router.HandleFunc("/p/{pasteId}", PasteHandler).Methods("GET")
router.HandleFunc("/raw/{pasteId}", RawHandler).Methods("GET") router.HandleFunc("/raw/{pasteId}", RawHandler).Methods("GET")