You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
66 lines
1.7 KiB
Go
66 lines
1.7 KiB
Go
package main
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
//"github.com/spf13/viper"
|
|
shorty "github.com/kreativmonkey/shrt/short"
|
|
"log"
|
|
"fmt"
|
|
)
|
|
|
|
const version = "0.01"
|
|
const port = "9090"
|
|
const db = "./test.db"
|
|
|
|
var (
|
|
short *shorty.Storage
|
|
)
|
|
|
|
func init() {
|
|
var err error
|
|
short, err = shorty.Open(db)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
/*
|
|
viper.SetDefault("ContentDir", "content")
|
|
viper.SetDefault("Token", map[string]string{"url": "url", "token": "token"})
|
|
|
|
viper.SetConfigName("config") // name of config file (without expression)
|
|
viper.AddConfigPath("/etc/appname/") // path to look for the config file in
|
|
viper.AddConfigPath("$HOME/.appname") // call multiple times to add many search paths
|
|
viper.AddConfigPath(".") // optionally look for config in the working directory
|
|
err = viper.ReadInConfig() // Find and read the config file
|
|
if err != nil { // Handle errors reading the config file
|
|
panic(fmt.Errorf("Fatal error config file: %s \n", 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("Shrt %s started on Port: %s \n", version, port)
|
|
http.Handle("/", router)
|
|
|
|
log.Fatal(http.ListenAndServe(":"+port, router))
|
|
|
|
}
|
|
|