|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
shrty "github.com/kreativmonkey/shrt/shrty"
|
|
|
|
"log"
|
|
|
|
"fmt"
|
|
|
|
)
|
|
|
|
|
|
|
|
const version = "0.06"
|
|
|
|
|
|
|
|
var (
|
|
|
|
short *shrty.Store
|
|
|
|
|
|
|
|
// Global configuration Variable
|
|
|
|
config = ReadConfig()
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
var err error
|
|
|
|
short, err = shrty.Open(config.DB)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type shrt struct {
|
|
|
|
Token string `bson:"token" json:"token"`
|
|
|
|
URL string `bson:"url" json:"url"`
|
|
|
|
Date string `bson:"url_ending" json:"url_ending"`
|
|
|
|
Count int64 `bson:"click" json:"click"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
router := NewRouter()
|
|
|
|
|
|
|
|
s := http.StripPrefix("/css/", http.FileServer(http.Dir("./template/css/")))
|
|
|
|
router.PathPrefix("/css/").Handler(s)
|
|
|
|
s = http.StripPrefix("/img/", http.FileServer(http.Dir("./template/img/")))
|
|
|
|
router.PathPrefix("/img/").Handler(s)
|
|
|
|
|
|
|
|
/*
|
|
|
|
http.Handle("/css/", http.StripPrefix("/css/", http.FileServer(http.Dir("template/css"))))
|
|
|
|
http.Handle("/img/", http.StripPrefix("/img/", http.FileServer(http.Dir("template/img"))))
|
|
|
|
*/
|
|
|
|
fmt.Printf("Shrty %s is listen on Port: %s \n", version, config.Port)
|
|
|
|
fmt.Printf("For the API use following key: %s \n", config.APIkey)
|
|
|
|
http.Handle("/", router)
|
|
|
|
|
|
|
|
log.Fatal(http.ListenAndServe(":"+ config.Port, router))
|
|
|
|
}
|