package main import ( "embed" "github.com/go-chi/chi" "github.com/go-chi/chi/middleware" "github.com/joho/godotenv" "log" "net/http" "template/migration" ) //go:embed db/dev/*.sql var devMigrations embed.FS func init() { godotenv.Load() log.SetPrefix("") log.SetFlags(log.Ldate | log.Ltime | log.Lshortfile) } func main() { client, err := connectToDb() if err != nil { log.Fatalf("couldn't connect to db: %v", err) } if err := migration.InitializeMigrations(client, devMigrations); err != nil { log.Fatalf("couldn't execute migrations: %v", err) } r := chi.NewRouter() r.Use(middleware.RequestID) r.Use(middleware.RealIP) r.Use(middleware.Logger) r.Use(middleware.Recoverer) r.Get("/", helloWorld) log.Fatal(http.ListenAndServe(":5281", r)) } func helloWorld(w http.ResponseWriter, r *http.Request) { response := struct { Title string `json:"title"` Message string `json:"message"` }{Title: "hello world", Message: "this is an example of response"} render(w, r, http.StatusOK, response) }