예제 #1
0
func main() {

	var serverRoot string = os.Getenv("STATICSERVER_ROOT")
	if serverRoot == "" {
		log.Fatal("STATICSERVER_ROOT was not specified.")
	} else {
		log.Println("Serving local files from: ", serverRoot)
	}

	var s3Root string = os.Getenv("S3_ROOT")

	logger := log.WithField("svc", "static")
	logger.Printf("Logger prefix set.")
	ss := StaticServer{
		vc: vascoClient.New(
			vascoClient.Logger(logger),
			vascoClient.VascoAddress(os.Getenv("VASCO_ADDR")),
			vascoClient.HostURL(os.Getenv("HOST_URL")),
			vascoClient.MyIP(os.Getenv("MY_IP")),
		),
		mkv:          NewMongoKV("", "", "", ""),
		serverRoot:   serverRoot,
		staticPrefix: "/file",
		s3root:       s3Root,
		s3Prefix:     "/static",
	}

	s3r, err := ss.mkv.FindOne("S3_ROOT")
	if err == nil {
		ss.s3root = s3r.(string)
		log.Println("Setting ", ss.s3root, " as S3_ROOT")
	}

	if s3Root == "" {
		log.Fatal("S3_ROOT was not specified or found in the key database.")
	} else {
		log.Println("Serving S3 content from: ", s3Root)
	}

	var port string = strings.TrimSpace(os.Getenv("MY_PORT"))
	if port == "" {
		port = ss.vc.GetPort()
	}

	if port == "" {
		port = "8080"
	}

	err = ss.vc.Register("staticserver", port, "/(?:static/.*|s3/.*|key/.*|id/.*)", "/status")
	if err != nil {
		log.Fatal(err)
	}

	mux := ss.createRoutes()

	log.Printf("Static server listening on port %s\n", port)
	server := &http.Server{Addr: ":" + port, Handler: mux}
	log.Fatal(server.ListenAndServe())
}
예제 #2
0
func TestMain(m *testing.M) {
	static = &StaticServer{
		vc: vascoClient.New(
			vascoClient.VascoAddress(os.Getenv("VASCO_ADDR")),
			vascoClient.HostURL(os.Getenv("HOST_URL")),
			vascoClient.MyIP(os.Getenv("MY_IP")),
		),
		mkv:          NewMongoKV("", "", "", ""),
		serverRoot:   ".",
		staticPrefix: "/static",
	}
	mux = static.createRoutes()

	memResult := m.Run()
	os.Exit(memResult)
}