mirror of
https://github.com/aykhans/oh-my-url.git
synced 2025-04-19 19:16:20 +00:00
38 lines
1.0 KiB
Go
38 lines
1.0 KiB
Go
package main
|
|
|
|
import (
|
|
"github.com/aykhans/oh-my-url/app/config"
|
|
"github.com/aykhans/oh-my-url/app/db"
|
|
"github.com/aykhans/oh-my-url/app/http_handlers"
|
|
"net/http"
|
|
"sync"
|
|
)
|
|
|
|
func main() {
|
|
config := config.GetAppConfig()
|
|
dbCreate := db.GetDB()
|
|
dbCreate.Init()
|
|
handlerCreate := httpHandlers.HandlerCreate{DB: dbCreate, ForwardDomain: config.FORWARD_DOMAIN}
|
|
urlCreateMux := http.NewServeMux()
|
|
urlCreateMux.HandleFunc("/", handlerCreate.UrlCreate)
|
|
urlCreateMux.HandleFunc("/favicon.ico", httpHandlers.FaviconHandler)
|
|
|
|
dbRead := db.GetDB()
|
|
handlerForward := httpHandlers.HandlerForward{DB: dbRead, CreateDomain: config.CREATE_DOMAIN}
|
|
urlReadMux := http.NewServeMux()
|
|
urlReadMux.HandleFunc("/", handlerForward.UrlForward)
|
|
urlReadMux.HandleFunc("/favicon.ico", httpHandlers.FaviconHandler)
|
|
|
|
var wg sync.WaitGroup
|
|
wg.Add(2)
|
|
go func() {
|
|
defer wg.Done()
|
|
panic(http.ListenAndServe(":"+config.LISTEN_PORT_CREATE, urlCreateMux))
|
|
}()
|
|
go func() {
|
|
defer wg.Done()
|
|
panic(http.ListenAndServe(":"+config.LISTEN_PORT_FORWARD, urlReadMux))
|
|
}()
|
|
wg.Wait()
|
|
}
|