This repository has been archived on 2022-05-25. You can view files and clone it, but cannot push or open issues or pull requests.
elon-eats-my-tweets/main.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))
}