Exemple #1
0
func TestDownloadURLInvalidOS(t *testing.T) {
	release, _ := getantibody.LatestRelease()
	url, err := getantibody.DownloadURL(
		release,
		"windows",
		"x86_64",
	)
	assert.Empty(t, url)
	assert.Error(t, err)
}
Exemple #2
0
func TestDownloadURLInvalidArch(t *testing.T) {
	release, _ := getantibody.LatestRelease()
	url, err := getantibody.DownloadURL(
		release,
		"darwin",
		"ppc",
	)
	assert.Empty(t, url)
	assert.Error(t, err)
}
Exemple #3
0
func TestDownloadURLValidOSAndArch(t *testing.T) {
	release, _ := getantibody.LatestRelease()
	url, err := getantibody.DownloadURL(
		release,
		"Darwin",
		"x86_64",
	)
	assert.Contains(t, url, "github.com")
	assert.NoError(t, err)
}
Exemple #4
0
func main() {
	e := echo.New()
	e.Use(mw.Logger())
	e.Use(mw.Recover())

	e.Get("/distributions", func(c *echo.Context) error {
		return c.JSON(http.StatusOK, getantibody.Distributions())
	})

	e.Get("/latest/:os/:arch", func(c *echo.Context) error {
		os := c.Param("os")
		arch := c.Param("arch")
		v, err := getantibody.LatestRelease()
		if err != nil {
			return c.String(http.StatusBadRequest, err.Error())
		}
		url, err := getantibody.DownloadURL(v, os, arch)
		if err != nil {
			return c.String(http.StatusBadRequest, err.Error())
		}
		return c.Redirect(http.StatusSeeOther, url)
	})

	// frontend
	assetHandler := http.FileServer(rice.MustFindBox("static").HTTPBox())
	e.Get("/", func(c *echo.Context) error {
		assetHandler.ServeHTTP(c.Response().Writer(), c.Request())
		return nil
	})
	e.Get("/static/*", func(c *echo.Context) error {
		http.StripPrefix("/static/", assetHandler).
			ServeHTTP(c.Response().Writer(), c.Request())
		return nil
	})

	e.Run(":3000")
}