Another Post

Another Post

This is another post

My name is Christian.

package main

import (
  "context"
  "database/sql"
  "net/http"
  "log/slog"
  "os"

  "github.com/gin-gonic/gin"
  _ "github.com/mattn/go-sqlite3"
)

func main() {
  ctx := context.Background()
  db, err := sql.Open("sqlite3", "./notes.db")
  if err != nil {
    slog.Log(ctx, slog.LevelError.Level(), "Unable to open database", "error", err)
    os.Exit(1)
  }

  router := gin.Default()
  handler := NewRouteHandler(db)
  

  router.Run(":8080")
}

type RouteHandler struct {
  db *sql.DB
}

func NewRouteHandler(db *sql.DB) *RouteHandler {
  return &RouteHandler{
    db: db,
  }
}

func(r *RouteHandler) HandleIndex(c *gin.Context) {
  c.JSON(http.StatusOK, gin.H{"status": "ok"})
}