Advertisement
CyberMix

Untitled

Sep 3rd, 2015
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 2.07 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4.   "github.com/gin-gonic/gin"
  5.   "fmt"
  6.   "net/http"
  7.   "io/ioutil"
  8.   // "path/filepath"
  9.   // "html/template"
  10. )
  11.  
  12. func init() {
  13.   fmt.Println("Start cigo") // ^_^
  14. }
  15.  
  16. func main() {
  17.   router := gin.Default()
  18.  
  19.   router.StaticFile("/favicon.ico", "./img/favicon.ico")
  20.   router.Static("/assets", "./assets")
  21.   router.LoadHTMLGlob("templates/*")              // templates files
  22.  
  23.   router.GET("/", home)
  24.   router.GET("/config", config)
  25.   router.GET("/builds", showBuilds)
  26.   router.GET("/builds/:build_name", editBuilds)
  27.  
  28.   // Builds routes
  29. /*  v1 := router.Group("/builds/:buildname")
  30.   {
  31.       v1.POST("/login", loginEndpoint)
  32.       v1.POST("/submit", submitEndpoint)
  33.       v1.POST("/read", readEndpoint)
  34.   }*/
  35.  
  36.   //router.POST("/api/:name", apiTest)
  37.  
  38.   router.Run(":7000")
  39. }
  40.  
  41. func checkErr(e error) {
  42.   if e != nil {
  43.       panic(e)
  44.   }
  45. }
  46.  
  47. func home(c *gin.Context) {
  48.   c.HTML(http.StatusOK, "index", gin.H{           // index it's template name (index.tmpl
  49.     "title": "cigo : GO Continiuos Integration",
  50.     "appname": "cigo Deploy",
  51.     "headertext": "Hello world!",
  52.   })
  53. }
  54.  
  55. func config(c *gin.Context) {
  56.   c.HTML(http.StatusOK, "index", gin.H{           // index.tmpl
  57.     "title": "cigo : Config page",
  58.     "appname": "cigo Deploy",
  59.     "headertext": "cigo Config",
  60.   })
  61. }
  62.  
  63. func showBuilds(c *gin.Context) {
  64.   build_files, err := ioutil.ReadDir("./builds")
  65.   checkErr(err)
  66.   fmt.Printf("%v", build_files)
  67.   c.HTML(http.StatusOK, "builds", gin.H{              // builds.tmpl
  68.     "title": "cigo : Config page",
  69.     "appname": "cigo Deploy",
  70.     "headertext": "Builds list",
  71.     "FileInfo" : build_files,
  72.   })
  73. }
  74.  
  75. func editBuilds(c *gin.Context) {
  76.   // build_name := c.Param("build_name")
  77.   fmt.Println("editBuilds func exec")
  78.  
  79.   //build_raw = ioutil.ReadFile("builds/" + build_name)
  80.   //fmt.Printf("%v", build_raw)
  81.   c.HTML(http.StatusOK, "edit_build", gin.H{              // edit_build.tmpl
  82.     "title": "cigo : Config page",
  83.     "appname": "cigo Deploy",
  84.     "headertext": "Builds list",
  85.     "editFile": "data",
  86.   })
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement