55 lines
1.4 KiB
Go
55 lines
1.4 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"flag"
|
|
"fmt"
|
|
"log"
|
|
"net/http"
|
|
|
|
"github.com/prometheus/client_golang/prometheus/promhttp"
|
|
"github.com/redis/go-redis/v9"
|
|
|
|
"sunshine.industries/some-automoderation/metrics"
|
|
"sunshine.industries/some-automoderation/rooms"
|
|
"sunshine.industries/some-automoderation/routes"
|
|
"sunshine.industries/some-automoderation/sessions"
|
|
)
|
|
|
|
var ctx = context.Background()
|
|
|
|
func main() {
|
|
var port int
|
|
flag.IntVar(&port, "port", 8080, "Port on which the server should start")
|
|
var metricsPort int
|
|
flag.IntVar(&metricsPort, "metricsPort", 8081, "Port on which the server expose metrics")
|
|
var redisPort int
|
|
flag.IntVar(&redisPort, "redisPort", 7777, "Port on which server should connect to redis db")
|
|
flag.Parse()
|
|
|
|
metrics := metrics.SetupMetrics()
|
|
|
|
promhttp.Handler()
|
|
promHandler := promhttp.HandlerFor(metrics.Registry, promhttp.HandlerOpts{})
|
|
promMux := http.NewServeMux()
|
|
promMux.Handle("/metrics", promHandler)
|
|
|
|
go func() {
|
|
log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", metricsPort), promMux))
|
|
}()
|
|
|
|
rdb := redis.NewClient(&redis.Options{
|
|
Addr: fmt.Sprintf("localhost:%d", redisPort),
|
|
Password: "",
|
|
DB: 0,
|
|
})
|
|
|
|
roomsM := rooms.RedisRM{Rdb: rdb}
|
|
sessions := sessions.RedisSM{Rdb: rdb}
|
|
|
|
log.Printf("Server will start on port: %d; /metrics on %d; listening to redis on: %d\n", port, metricsPort, redisPort)
|
|
routes.RegisterRoutes(sessions, roomsM, &metrics)
|
|
|
|
log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", port), nil))
|
|
}
|