feat: add routers pkg

This commit is contained in:
2025-10-17 22:41:21 +03:00
parent a856c476d9
commit 60a0120b58
12 changed files with 27 additions and 17 deletions

View File

@@ -12,3 +12,4 @@ gore
- [ ] actually rewrite this properly - [ ] actually rewrite this properly
- [ ] serve `index.html` from `/` - [ ] serve `index.html` from `/`
- [ ] pack the assetins into the [binary](https://github.com/gin-gonic/examples/tree/master/assets-in-binary) - [ ] pack the assetins into the [binary](https://github.com/gin-gonic/examples/tree/master/assets-in-binary)
- [ ] mise tasks for testing, releasing, etc, [example](https://github.com/jdx/mise/blob/main/tasks.toml)

0
backend/conf/app.toml Normal file
View File

View File

@@ -1,4 +1,4 @@
module api module git.madunde.ad/madundead/obi
go 1.25.3 go 1.25.3

View File

@@ -1,7 +1,6 @@
package main package main
import ( import (
// "fmt"
"io/fs" "io/fs"
"log" "log"
"os" "os"
@@ -12,12 +11,15 @@ import (
"github.com/gin-contrib/cors" "github.com/gin-contrib/cors"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"git.madunde.ad/madundead/obi/routers"
) )
func main() { func main() {
router := gin.Default() router := gin.Default()
router.SetTrustedProxies([]string{"127.0.0.1"}) // TODO: fix All origins allowed by default router.SetTrustedProxies([]string{"127.0.0.1"}) // TODO: fix All origins allowed by default
router.Use(cors.Default()) router.Use(cors.Default())
list := listFiles("/home/madundead/Syncthing/Obsidian/Personal") list := listFiles("/home/madundead/Syncthing/Obsidian/Personal")
router.GET("/api/v1/files", func(c *gin.Context) { router.GET("/api/v1/files", func(c *gin.Context) {
@@ -29,17 +31,11 @@ func main() {
router.GET("/api/v1/files/:id", func(c *gin.Context) { router.GET("/api/v1/files/:id", func(c *gin.Context) {
id := c.Params.ByName("id") id := c.Params.ByName("id")
// value, ok := db[user]
// if ok {
path, _ := base64.StdEncoding.DecodeString(id) path, _ := base64.StdEncoding.DecodeString(id)
data, _ := os.ReadFile(string(path)) data, _ := os.ReadFile(string(path))
// fmt.Print(string(dat))
c.JSON(http.StatusOK, gin.H{"data": string(data)}) c.JSON(http.StatusOK, gin.H{"data": string(data)})
// } else {
// c.JSON(http.StatusOK, gin.H{"user": user, "status": "no value"})
// }
}) })
if err := router.Run(); err != nil { if err := router.Run(); err != nil {

3
backend/routers/go.mod Normal file
View File

@@ -0,0 +1,3 @@
module routers
go 1.25.3

4
backend/routers/main.go Normal file
View File

@@ -0,0 +1,4 @@
package routers
func init() {
}

View File

@@ -0,0 +1 @@
exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1

BIN
backend/tmp/main Executable file

Binary file not shown.

View File

@@ -3,13 +3,8 @@ go = "latest"
bun = "latest" bun = "latest"
[env] [env]
# PORT = "8912" # api port BE_PORT = "8912" # api port
# FRONTEND_PORT = "8913" FE_PORT = "8913"
[tasks.dev] [task_config]
description = 'Run BE & FE in tmux' includes = ["tasks.toml"]
run = [
'tmux new-window "cd api; go install; PORT=8912 air"',
'tmux split-window "cd frontend; bun install; PORT=8913 bun src/index.tsx"',
'xdg-open "http://localhost:8913" || open "http://localhost:8913"'
]

10
tasks.toml Normal file
View File

@@ -0,0 +1,10 @@
[dev]
run = 'mise dev:tmux'
["dev:tmux"]
description = 'Run BE & FE in tmux'
run = [
'tmux new-window "cd backend; go install; PORT=8912 air"',
'tmux split-window "cd frontend; bun install; PORT=8913 bun src/index.tsx"',
'sleep 0.1 && (xdg-open "http://localhost:8913" || open "http://localhost:8913")'
]