Arrange Variables
This commit is contained in:
parent
5bd1a40cf1
commit
a1f2724f64
7
main.go
7
main.go
|
@ -48,6 +48,9 @@ func main() {
|
|||
log.Fatal(srv.ListenAndServe())
|
||||
}
|
||||
|
||||
const dbL = "/home/adalricus/projects/db/adalricus.db"
|
||||
const alphaNum = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
|
||||
|
||||
type shortP struct {
|
||||
ShortURL string
|
||||
URL string
|
||||
|
@ -64,7 +67,6 @@ func sURLH(w http.ResponseWriter, r *http.Request) {
|
|||
errChk(err)
|
||||
}
|
||||
|
||||
dbL := "/home/adalricus/projects/db/adalricus.db"
|
||||
url := r.FormValue("url")
|
||||
db, err := sql.Open("sqlite3", dbL)
|
||||
errChk(err)
|
||||
|
@ -106,7 +108,6 @@ func urlH(w http.ResponseWriter, r *http.Request) {
|
|||
vars := mux.Vars(r)
|
||||
shortURL := vars["sURL"]
|
||||
|
||||
dbL := "/home/adalricus/projects/db/adalricus.db"
|
||||
db, err := sql.Open("sqlite3", dbL)
|
||||
errChk(err)
|
||||
defer db.Close()
|
||||
|
@ -128,7 +129,7 @@ func errChk(err error) {
|
|||
}
|
||||
|
||||
func randS(n int) string {
|
||||
const alphaNum = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
|
||||
|
||||
b := make([]byte, n)
|
||||
for i := range b {
|
||||
b[i] = alphaNum[rand.Intn(len(alphaNum))]
|
||||
|
|
Loading…
Reference in New Issue