ags-upload

Insert AGS files to a database
git clone git://src.adamsgaard.dk/ags-upload # fast
git clone https://src.adamsgaard.dk/ags-upload.git # slow
Log | Files | Refs Back to index

commit 8c20757fbcd6969699b356f36a4d86b1de329eb1
parent 031c2903d9b6a8d603996ae9e6b9bd214afa2942
Author: Anders Damsgaard <anders@adamsgaard.dk>
Date:   Wed,  8 Oct 2025 09:43:33 +0200

main.go: add outline of main

Diffstat:
Acmd/main.go | 50++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 50 insertions(+), 0 deletions(-)

diff --git a/cmd/main.go b/cmd/main.go @@ -0,0 +1,50 @@ +package main + +import ( + "fmt" + "log" + "os" + + "github.com/gin-gonic/gin" + "gorm.io/driver/postgres" + "gorm.io/gorm" + "gorm.io/gorm/schema" +) + +type Cpt struct { + ID uint `gorm:"primaryKey"` + LocaId string +} + +func main() { + dsn := os.Getenv("DB_CONN") + dbSchema := "jupiter" + db, err := gorm.Open(postgres.Open(dsn), + &gorm.Config{ + NamingStrategy: schema.NamingStrategy{ + TablePrefix: dbSchema + ".", + SingularTable: false, + }, + }) + if err != nil { + log.Fatal(err) + } + + sql := fmt.Sprintf(`CREATE SCHEMA IF NOT EXISTS "%s"`, dbSchema) + if err := db.Exec(sql).Error; err != nil { + log.Fatal(err) + } + + if err := db.AutoMigrate(&Cpt{}); err != nil { + log.Fatal(err) + } + + db.Create(&Cpt{LocaId: "asdf"}) + + r := gin.Default() + r.POST("/ingest/:ags", func(c *gin.Context) { + }) + + _ = r.Run(":8080") + +}