48 lines
1.0 KiB
Go
48 lines
1.0 KiB
Go
package main
|
|
|
|
//go:generate sqlc generate
|
|
|
|
import (
|
|
"context"
|
|
"log"
|
|
"net/http"
|
|
|
|
"git.netflux.io/rob/elon-eats-my-tweets/config"
|
|
"git.netflux.io/rob/elon-eats-my-tweets/generated/store"
|
|
"git.netflux.io/rob/elon-eats-my-tweets/httpserver"
|
|
"git.netflux.io/rob/elon-eats-my-tweets/twitter"
|
|
"github.com/gorilla/sessions"
|
|
"github.com/jackc/pgx/v4/pgxpool"
|
|
"go.uber.org/zap"
|
|
)
|
|
|
|
func main() {
|
|
cfg, err := config.NewFromEnv()
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
|
|
logger, err := zap.NewDevelopment()
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
|
|
ctx := context.Background()
|
|
dbconn, err := pgxpool.Connect(ctx, cfg.DatabaseURL)
|
|
if err != nil {
|
|
log.Fatalf("error connecting to database: %s", err)
|
|
}
|
|
defer dbconn.Close()
|
|
store := store.New(dbconn)
|
|
|
|
handler := httpserver.NewHandler(
|
|
cfg,
|
|
store,
|
|
func(c *http.Client) httpserver.TwitterAPIClient { return twitter.NewAPIClient(c) },
|
|
sessions.NewCookieStore([]byte(cfg.SessionKey)),
|
|
httpserver.RandomTokenGenerator{},
|
|
logger,
|
|
)
|
|
log.Fatal(http.ListenAndServe(cfg.ListenAddr, handler))
|
|
}
|