コード例 #1
0
ファイル: routes.go プロジェクト: davidwinton/feedbag
func templateHandler(c *gin.Context) {
	var err error
	Templates, err = tmpl.ParseDir(TemplatesDir)
	if err != nil {
		logging.ErrorWithTags([]string{"templates"}, "Failed to load templates.", err.Error())
	}

	c.JSON(200, Templates)
}
コード例 #2
0
ファイル: feedbag.go プロジェクト: davidwinton/feedbag
func Start(port, templatesDir string, publicDir string) error {
	dbmap = setupDb()
	defer dbmap.Db.Close()

	// Process our templates
	TemplatesDir = templatesDir
	var err error
	Templates, err = tmpl.ParseDir(TemplatesDir)
	if err != nil {
		logging.ErrorWithTags([]string{"templates"}, "Failed to parse templates", err.Error())
		return err
	}

	// Setup Goth Authentication
	goth.UseProviders(
		github.New(os.Getenv("GITHUB_KEY"), os.Getenv("GITHUB_SECRET"), "http://localhost:3000/auth/github/callback", "repo", "user:email"),
	)

	// Setup Socket.io server and related activity fetching
	socketServer, err := SetupSocketIO()
	if err != nil {
		return err
	}

	err = StartSocketPusher(socketServer, activityChan)
	if err != nil {
		return err
	}

	err = StartExistingUsers(activityChan)
	if err != nil {
		return err
	}

	// Start up gin and its friends
	r := gin.Default()
	r.Use(cors.Middleware(cors.Options{AllowCredentials: true}))

	// Serve static assets
	r.Use(static.Serve("/", static.LocalFile(publicDir, false)))

	SetupRoutes(r, socketServer)
	r.Run(fmt.Sprintf(":%s", port))

	return nil
}
コード例 #3
0
ファイル: tmpl_test.go プロジェクト: davidwinton/feedbag
func Test_ParseTemplatesDir(t *testing.T) {
	testDir := "./test_templates"
	templates, err := tmpl.ParseDir(testDir)

	Convey("Given the test template directory", t, func() {
		So(err, ShouldBeNil)
		So(len(templates), ShouldEqual, 4)

		var (
			newPrTmpl         tmpl.Template
			missingNameTmpl   tmpl.Template
			newCommentTmpl    tmpl.Template
			longerMarkersTmpl tmpl.Template
		)

		for _, tmpl := range templates {
			switch tmpl.Id {
			case "new_comment":
				newCommentTmpl = *tmpl
			case "new_pr":
				newPrTmpl = *tmpl
			case "missing_name":
				missingNameTmpl = *tmpl
			case "longer_markers":
				longerMarkersTmpl = *tmpl
			}
		}

		Convey("The New Comment template should exist", func() {
			t := newCommentTmpl
			So(t, ShouldNotBeNil)
			So(t.Id, ShouldEqual, "new_comment")
			So(t.Name, ShouldEqual, "New Comment")
			So(t.Event, ShouldEqual, "comment_pull_request")
		})

		Convey("The New PR template should exist", func() {
			t := newPrTmpl
			So(t, ShouldNotBeNil)
			So(t.Id, ShouldEqual, "new_pr")
			So(t.Name, ShouldEqual, "New Pull Request")
			So(t.Event, ShouldEqual, "new_pull_request")
		})

		Convey("The Missing Name template should exist", func() {
			t := missingNameTmpl
			So(t, ShouldNotBeNil)
			So(t.Id, ShouldEqual, "missing_name")
			So(t.Name, ShouldEqual, "")
			So(t.Event, ShouldEqual, "comment_pull_request")
		})

		Convey("The Longer Than Default Markers template should exist", func() {
			t := longerMarkersTmpl
			So(t, ShouldNotBeNil)
			So(t.Id, ShouldEqual, "longer_markers")
			So(t.Name, ShouldEqual, "Longer Than Default Markers")
			So(t.Event, ShouldEqual, "comment_pull_request")
		})

	})
}