feat: use cobra to run the app

This commit is contained in:
Muyao CHEN
2024-10-01 13:37:31 +02:00
parent e13c4a9380
commit 8ae94d19a6
4 changed files with 110 additions and 17 deletions

View File

@ -22,25 +22,19 @@
package main
// Use the init of automaxprocs package to get the real max procs in a
// container, in order to avoid latency caused by too many threads.
import (
"fmt"
"net/http"
"os"
"github.com/gin-gonic/gin"
"git.vinchent.xyz/vinchent/howmuch/internal/howmuch"
_ "go.uber.org/automaxprocs"
)
const port = 8080
func main() {
fmt.Println("How much do I owe you?")
command := howmuch.NewHowMuchCommand()
r := gin.Default()
r.GET("/", func(ctx *gin.Context) {
ctx.JSON(http.StatusOK, gin.H{
"message": "how much?",
})
})
r.Run(fmt.Sprintf(":%d", port))
if err := command.Execute(); err != nil {
os.Exit(1)
}
}