Esempio n. 1
0
func TestAll(t *testing.T) {
	tempDir, err := ioutil.TempDir("", "homescreen-test-")
	assertNoError(t, err)
	defer os.RemoveAll(tempDir)

	db, err := storage.New(path.Join(tempDir, "test.db"))
	assertNoError(t, err)
	defer db.Close()

	err = db.SetRaw("foo/bar", []byte(`"blubber"`))
	assertNoError(t, err)

	err = db.Set("bim/baz", 1337)
	assertNoError(t, err)

	err = db.Set("wut/not", []string{"bish", "bash", "bosh"})
	assertNoError(t, err)

	value, err := db.GetRaw("foo/bar")
	assertNoError(t, err)
	assertEquals(t, `"blubber"`, string(value))

	value, err = db.GetRaw("bim/baz")
	assertNoError(t, err)
	assertEquals(t, `1337`, string(value))

	value, err = db.GetRaw("wut/not")
	assertNoError(t, err)
	assertEquals(t, `["bish","bash","bosh"]`, string(value))

	var foobar string
	err = db.Get("foo/bar", &foobar)
	assertNoError(t, err)
	assertEquals(t, "blubber", foobar)

	var bimbaz int
	err = db.Get("bim/baz", &bimbaz)
	assertNoError(t, err)
	assertEquals(t, "1337", fmt.Sprintf("%#v", bimbaz))

	var wutnot []string
	err = db.Get("wut/not", &wutnot)
	assertNoError(t, err)
	assertEquals(t, `[]string{"bish", "bash", "bosh"}`,
		fmt.Sprintf("%#v", wutnot))
}
Esempio n. 2
0
func main() {
	gin.SetMode(gin.ReleaseMode)
	m := gin.Default()

	var execMode = flag.Bool("exec", false, "spawns plugins during startup")
	flag.Parse()

	ds, err := storage.New("storage.db")
	if err != nil {
		log.Println(err)
		os.Exit(1)
	}
	mm := modulemanager.New(ds, *execMode)

	pwd, err := os.Getwd()
	if err != nil {
		log.Println(err)
		os.Exit(1)
	}

	// every file in frontend will be served

	log.Print(pwd + "/core/frontend/index.html")
	m.StaticFile("/", pwd+"/core/frontend/index.html")
	m.Static("/www", pwd+"/core/frontend")

	rootGroup := m.Group("/api/v1")
	{
		mm.RegisterRouterGroup(rootGroup.Group("/modules"))
		ds.RegisterRouterGroup(rootGroup.Group("/storage"))
	}

	m.NoRoute(func(c *gin.Context) {
		c.Status(http.StatusNotFound)
	})
	mm.ScanForModules()
	log.Println("Server is running on tcp port 3000...")

	m.Run(":3000")

}