You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
tad/main.go

39 lines
895 B
Go

1 year ago
package main
import (
"fmt"
"github.com/jmoiron/sqlx"
1 year ago
"github.com/tad17/tad/fiber"
"os"
"strings"
1 year ago
)
func testRouter(db *sqlx.DB, query string) string {
//fmt.Printf("query: %s\n", query)
var urls []string
cmd := "select newurl from filemeta limit 5"
if err := db.Select(&urls, cmd); err != nil {
fmt.Errorf("ошибка выполнения: %s", cmd)
os.Exit(0)
}
s := strings.Join(urls, " ")
return s
}
func testHTML(db *sqlx.DB, query string) map[string]interface{} {
result := make(map[string]interface{})
result["Item"] = "Проверка"
result["value"] = 456
result["items"] = []string{"Первый", "Второй", "Третий"}
return result
}
1 year ago
func main() {
db := fiber.OpenDB("sea")
app := fiber.NewApp("test-app", db)
app.JSONRouter("/test", testRouter)
app.HTMLRouter("test2", testHTML)
app.Start(4444)
fmt.Printf("init app fiber: %v\n", app)
}