|
@@ -0,0 +1,68 @@
|
|
|
|
+package api
|
|
|
|
+
|
|
|
|
+import (
|
|
|
|
+ "git.sfnt.net/sfnt/cnlink/conf"
|
|
|
|
+ "github.com/gin-gonic/gin"
|
|
|
|
+ "net/http"
|
|
|
|
+)
|
|
|
|
+type version struct {
|
|
|
|
+ Version string `json:"version"`
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+type errorResp struct {
|
|
|
|
+ Msg string `json:"msg"`
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+type shortReq struct {
|
|
|
|
+ LongURL string `json:"longURL"`
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+type shortResp struct {
|
|
|
|
+ ShortURL string `json:"shortURL"`
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+type expandReq struct {
|
|
|
|
+ ShortURL string `json:"shortURL"`
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+type expandResp struct {
|
|
|
|
+ LongURL string `json:"longURL"`
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func CheckVersion(c *gin.Context) {
|
|
|
|
+ //versionInfo, _ := json.Marshal(version{Version: conf.Version})
|
|
|
|
+ c.JSON(200, gin.H{
|
|
|
|
+ "message": conf.Version,
|
|
|
|
+ })
|
|
|
|
+
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func CheckHealth(c *gin.Context) {
|
|
|
|
+ //tpl := template.New("health.html")
|
|
|
|
+ /*
|
|
|
|
+ var err error
|
|
|
|
+ tpl, err = tpl.ParseFiles("views/health.html")
|
|
|
|
+ if err != nil {
|
|
|
|
+ log.Printf("parse views error. %v", err)
|
|
|
|
+ //w.WriteHeader(http.StatusInternalServerError)
|
|
|
|
+ c.JSON(http.StatusInternalServerError, gin.H{
|
|
|
|
+ "message": http.StatusText(http.StatusInternalServerError),
|
|
|
|
+ })
|
|
|
|
+ //w.Write([]byte(http.StatusText(http.StatusInternalServerError)))
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ */
|
|
|
|
+ c.HTML(http.StatusOK, "health.html",nil)
|
|
|
|
+ /*
|
|
|
|
+ err = tpl.Execute(c.Writer, nil)
|
|
|
|
+ if err != nil {
|
|
|
|
+ log.Printf("execute views error. %v", err)
|
|
|
|
+ c.JSON(http.StatusInternalServerError, gin.H{
|
|
|
|
+ "message": http.StatusText(http.StatusInternalServerError),
|
|
|
|
+ })
|
|
|
|
+ //w.WriteHeader(http.StatusInternalServerError)
|
|
|
|
+ //w.Write([]byte(http.StatusText(http.StatusInternalServerError)))
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ */
|
|
|
|
+}
|