update reademe and use flags
This commit is contained in:
parent
1dbd948eec
commit
3a8b83f434
|
@ -25,8 +25,11 @@ sudo yum install -y go mariadb-server mariadb
|
|||
|
||||
* go get https://github.com/ewhal/Pastebin
|
||||
* nano pastebin.go
|
||||
* Configure port and database details
|
||||
* make
|
||||
```
|
||||
./pastebin --db-name="pastes" --db-username="pastebin" --db-pass=""
|
||||
--port=":9900" --length=6
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
|
|
23
pastebin.go
23
pastebin.go
|
@ -7,6 +7,7 @@ import (
|
|||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"encoding/xml"
|
||||
"flag"
|
||||
"fmt"
|
||||
"html"
|
||||
"html/template"
|
||||
|
@ -27,19 +28,19 @@ import (
|
|||
"github.com/gorilla/mux"
|
||||
)
|
||||
|
||||
const (
|
||||
var (
|
||||
// ADDRESS that pastebin will return links for
|
||||
ADDRESS = "http://localhost:9900"
|
||||
ADDRESS string
|
||||
// LENGTH of paste id
|
||||
LENGTH = 6
|
||||
LENGTH int
|
||||
// PORT that pastebin will listen on
|
||||
PORT = ":9900"
|
||||
PORT string
|
||||
// USERNAME for database
|
||||
USERNAME = ""
|
||||
USERNAME string
|
||||
// PASS database password
|
||||
PASS = ""
|
||||
PASS string
|
||||
// NAME database name
|
||||
NAME = ""
|
||||
NAME string
|
||||
// DATABASE connection String
|
||||
DATABASE = USERNAME + ":" + PASS + "@/" + NAME + "?charset=utf8"
|
||||
)
|
||||
|
@ -380,6 +381,14 @@ func RootHandler(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
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.HandleFunc("/p/{pasteId}", PasteHandler).Methods("GET")
|
||||
router.HandleFunc("/raw/{pasteId}", RawHandler).Methods("GET")
|
||||
|
|
Loading…
Reference in New Issue