~repos /gromer

#golang#htmx#ssr

git clone https://pyrossh.dev/repos/gromer.git

gromer is a framework and cli to build multipage web apps in golang using htmx and alpinejs.


a17ab5c9 Peter John

4 years ago
use 404 and update readme
example/pages/api/todos/_todoId_/delete.go CHANGED
@@ -7,7 +7,11 @@ import (
7
7
  )
8
8
 
9
9
  func DELETE(ctx context.Context, id string) (string, int, error) {
10
+ _, status, err := GET(ctx, id, GetParams{})
11
+ if err != nil {
12
+ return "", status, err
13
+ }
10
- err := db.Query.DeleteTodo(ctx, id)
14
+ err = db.Query.DeleteTodo(ctx, id)
11
15
  if err != nil {
12
16
  return id, 500, err
13
17
  }
example/pages/api/todos/_todoId_/get.go CHANGED
@@ -2,6 +2,8 @@ package todos_todoId_
2
2
 
3
3
  import (
4
4
  "context"
5
+ "fmt"
6
+ "strings"
5
7
 
6
8
  "github.com/pyros2097/gromer/example/db"
7
9
  )
@@ -13,6 +15,9 @@ type GetParams struct {
13
15
  func GET(ctx context.Context, id string, params GetParams) (*db.Todo, int, error) {
14
16
  todo, err := db.Query.GetTodo(ctx, id)
15
17
  if err != nil {
18
+ if strings.Contains(err.Error(), "no rows") {
19
+ return nil, 404, fmt.Errorf("Todo with id '%s' not found", id)
20
+ }
16
21
  return nil, 500, err
17
22
  }
18
23
  if params.Show == "true" {
example/pages/api/todos/_todoId_/put.go CHANGED
@@ -12,6 +12,10 @@ type PutParams struct {
12
12
  }
13
13
 
14
14
  func PUT(ctx context.Context, id string, params PutParams) (*db.Todo, int, error) {
15
+ _, status, err := GET(ctx, id, GetParams{})
16
+ if err != nil {
17
+ return nil, status, err
18
+ }
15
19
  todo, err := db.Query.UpdateTodo(ctx, db.UpdateTodoParams{
16
20
  ID: id,
17
21
  Completed: params.Completed,
example/readme.md ADDED
@@ -0,0 +1,19 @@
1
+ # Example
2
+
3
+ This example demonstrates gromer with a simple web app.
4
+
5
+ It uses postgres as the database and sqlc to generate queries and models. It uses dbmate for migrations.
6
+
7
+ # Requirements
8
+
9
+ 1. go >= 1.16
10
+ 2. docker >= 20
11
+
12
+ # Running
13
+
14
+ ```sh
15
+ make setup
16
+ make start-db
17
+ make migrate
18
+ make run
19
+ ```
readme.md CHANGED
@@ -6,17 +6,19 @@
6
6
 
7
7
  # gromer
8
8
 
9
- **gromer** is a framework to build web apps in golang.
10
- It uses a declarative syntax using funcs that allows creating and dealing with HTML elements only by using Go, and without writing any HTML markup. It is highly opioninated and integrates uses tailwind css and alpinejs.
9
+ **gromer** is a framework and cli to build web apps in golang.
10
+ It uses a declarative syntax using funcs that allows creating and dealing with HTML elements only by using Go, and without writing any HTML markup.
11
11
 
12
+ It also generates http handlers for your routes which follow a particular folder structure. Similar to other frameworks like nextjs, sveltekit.
13
+
12
- # Install Cli
14
+ # Install
13
15
 
14
16
  ```sh
15
- go mod init
16
17
  go get -u -v github.com/pyros2097/wapp/cmd/gromer
17
18
  ```
18
19
 
19
20
  # Using
21
+
20
22
  You need to follow this directory structure similar to nextjs for the api route handlers to be generated
21
23
 
22
24
  Take a look at the example for now,