package blog import ( "database/sql" _ "fmt" "github.com/go-chi/chi" "github.com/go-chi/jwtauth" _ "github.com/go-chi/render" "net/http" "time" ) var ( DB *sql.DB TokenAuth *jwtauth.JWTAuth ) type BlogPost struct { Title string `json:"title",db:"title"` Slug string `json:"slug",db:"slug"` Author string `json:"author",db:"author"` DatePublished time.Time `json:"date", db:"date"` } func Init() { dbCreateStatement := ` CREATE TABLE IF NOT EXISTS blog (id SERIAL PRIMARY KEY, title text, slug text, author text REFERENCES users (username), date timestamp)` DB.Exec(dbCreateStatement) } func Routes() *chi.Mux { r := chi.NewRouter() r.Group(func(r chi.Router) { r.Use(jwtauth.Verifier(TokenAuth)) r.Use(jwtauth.Authenticator) r.Post("/", createBlogPost) r.Patch("/{slug}", updateBlogPost) }) r.Get("/", getAllBlogPosts) r.Get("/{slug}", getBlogPost) return r } func createBlogPost(w http.ResponseWriter, r *http.Request) { return } func updateBlogPost(w http.ResponseWriter, r *http.Request) { return } func getAllBlogPosts(w http.ResponseWriter, r *http.Request) { return } func getBlogPost(w http.ResponseWriter, r *http.Request) { return }