Merge branch 'ai_0.3_install_api' into 'test'

add mock api

See merge request opensource/answer!175
This commit is contained in:
linkinstar 2022-11-03 07:09:34 +00:00
commit a9a59f801d
1 changed files with 22 additions and 2 deletions

View File

@ -4,6 +4,7 @@ import (
"embed"
"fmt"
"io/fs"
"math/rand"
"net/http"
"os"
@ -11,6 +12,7 @@ import (
"github.com/answerdev/answer/internal/base/handler"
"github.com/answerdev/answer/ui"
"github.com/gin-gonic/gin"
"github.com/segmentfault/pacman/errors"
"github.com/segmentfault/pacman/log"
)
@ -93,11 +95,29 @@ func (a *UIRouter) Register(r *gin.Engine) {
})
r.POST("/installation/db/check", func(c *gin.Context) {
handler.HandleResponse(c, nil, gin.H{})
num := rand.Intn(10)
if num > 5 {
err := errors.BadRequest("connection error")
handler.HandleResponse(c, err, gin.H{})
} else {
handler.HandleResponse(c, nil, gin.H{
"connection_success": true,
})
}
})
r.POST("/installation/config-file/check", func(c *gin.Context) {
handler.HandleResponse(c, nil, gin.H{})
num := rand.Intn(10)
if num > 5 {
handler.HandleResponse(c, nil, gin.H{
"exist": true,
})
} else {
handler.HandleResponse(c, nil, gin.H{
"exist": false,
})
}
})
r.POST("/installation/init", func(c *gin.Context) {