func startApi(n ApiConfigurationNetwork) {
	apiListener, err := net.Listen("tcp", fmt.Sprintf("%v:%v", n.BindIP, n.BindPort))

	if err != nil {
		panic(err)
	}

	// Adding items:
	goji.Post("/food/add", routeAddFood)

	// Getting items
	goji.Get("/food/get/all", routeGetFoodAll)
	goji.Get("/food/get/id/:id", routeGetFoodById)
	goji.Get("/food/get/date/:year/:month/:day", routeGetFoodByDate)
	// goji.Get("/food/get/name/:name", routeGetFoodByName)

	// Removing items
	goji.Delete("/food/delete/id/:id", routeDeleteFoodById)
	goji.Delete("/food/delete/name/:name", routeDeleteFoodByName)

	// Updating items
	// goji.Put("/food/edit/id/:id", routeUpdateItemById)
	// goji.Put("/food/edit/name/:name", routeUpdateItemByName)

	goji.Get("/food/email/today", routeEmailSendToday)

	goji.ServeListener(apiListener)
}
Beispiel #2
0
func StartWebServer(bind, auth string) error {
	err := loadTemplates()
	if err != nil {
		return err
	}

	if auth != "" {
		authParts := strings.Split(auth, ":")
		goji.Use(httpauth.SimpleBasicAuth(authParts[0], authParts[1]))
	}

	goji.Get("/", homeRoute)
	goji.Get("/status", statusRoute)
	goji.Get("/robots.txt", robotsRoute)
	goji.Get("/setEnabled", setEnabledRoute)
	goji.Handle("/config", configRoute)

	listener, err := net.Listen("tcp", bind)
	if err != nil {
		return err
	}

	goji.ServeListener(listener)
	return nil
}
Beispiel #3
0
func main() {
	goji.Get("/", hello)

	fd := flag.Uint("fd", 0, "File descriptor to listen and serve.")
	flag.Parse()

	if *fd != 0 {
		listener, err := net.FileListener(os.NewFile(uintptr(*fd), ""))
		if err != nil {
			panic(err)
		}
		goji.ServeListener(listener)
	} else {
		goji.Serve()
	}
}
func main() {
	err := swlb.Load(os.Args[1])

	if err != nil {
		panic(err)
	}

	fmt.Println("Starting API with the following configuration...")
	fmt.Printf("\tBindPort: %v\n\tBindIP: %v\n\tAPIName: %v\n", swlb.Cfg.BindIP, swlb.Cfg.BindPort, swlb.Cfg.APIName)

	bind_to := fmt.Sprintf("%v:%v", swlb.Cfg.BindIP, swlb.Cfg.BindPort)
	listener, err := net.Listen("tcp", bind_to)

	goji.Get("/", swlb.RouteIndex)
	goji.Get("/health", swlb.RouteHealth)
	goji.Get("/health/flip", swlb.RouteFlipHealth)

	goji.ServeListener(listener)
}
Beispiel #5
0
func main() {
	flag.StringVar(&Config.bind, "b", "127.0.0.1:8080",
		"host to bind to (default: 127.0.0.1:8080)")
	flag.StringVar(&Config.filesDir, "filespath", "files/",
		"path to files directory")
	flag.StringVar(&Config.metaDir, "metapath", "meta/",
		"path to metadata directory")
	flag.BoolVar(&Config.noLogs, "nologs", false,
		"remove stdout output for each request")
	flag.BoolVar(&Config.allowHotlink, "allowhotlink", false,
		"Allow hotlinking of files")
	flag.StringVar(&Config.siteName, "sitename", "linx",
		"name of the site")
	flag.StringVar(&Config.siteURL, "siteurl", "http://"+Config.bind+"/",
		"site base url (including trailing slash)")
	flag.BoolVar(&Config.fastcgi, "fastcgi", false,
		"serve through fastcgi")
	flag.BoolVar(&Config.remoteUploads, "remoteuploads", false,
		"enable remote uploads")
	flag.StringVar(&Config.contentSecurityPolicy, "contentsecuritypolicy",
		"default-src 'self'; img-src 'self' data:; style-src 'self' 'unsafe-inline'; referrer none;",
		"value of default Content-Security-Policy header")
	flag.StringVar(&Config.fileContentSecurityPolicy, "filecontentsecuritypolicy",
		"default-src 'none'; img-src 'self'; object-src 'self'; media-src 'self'; sandbox; referrer none;",
		"value of Content-Security-Policy header for file access")
	flag.StringVar(&Config.xFrameOptions, "xframeoptions", "SAMEORIGIN",
		"value of X-Frame-Options header")
	flag.Parse()

	setup()

	listener, err := net.Listen("tcp", Config.bind)
	if err != nil {
		log.Fatal("Could not bind: ", err)
	}

	if Config.fastcgi {
		fcgi.Serve(listener, goji.DefaultMux)
	} else {
		goji.ServeListener(listener)
	}
}
Beispiel #6
0
func serve(mailserver *MailServer) {
	if mailserver.httpport == "" {
		log.Fatal("HTTPPort needs to be configured")
	}
	mailserver.database = make([]MailConnection, 0)
	mailserver.mu = &sync.Mutex{}
	go func() {
		for {
			mailserver.cleanupDatabase()
			time.Sleep(time.Duration(mailserver.expireinterval) * time.Second)
		}
	}()
	setupWebRoutes(mailserver)

	listener := createListener(mailserver)
	go func() {
		for {
			conn, err := listener.Accept()
			if err != nil {
				log.Panicf("Unable to accept: %s\n", err)
				continue
			}
			go processClientRequest(&MailConnection{
				mailserver: mailserver,
				connection: conn,
				address:    conn.RemoteAddr().String(),
				reader:     bufio.NewReader(conn),
				writer:     bufio.NewWriter(conn),
				MailId:     uuid.New(),
				Mail:       Mail{Received: time.Now().Unix()},
			})
		}
	}()
	log.Println("Trying to bind web to port ", mailserver.httpport)
	l, lerr := net.Listen("tcp", ":"+mailserver.httpport)
	if lerr != nil {
		log.Fatalf("Unable to bind to port %s.\n%s\n. ", mailserver.httpport, lerr)
	}
	goji.ServeListener(l)
}
Beispiel #7
0
//
// Yay, we are gonna do the mains
//
func main() {
	goji.Get("/", index)
	goji.Get("/:context", index)
	goji.ServeListener(bind.Socket("0.0.0.0:8080"))
}
Beispiel #8
0
func serveGoji() {
	goji.Get("/fs/[a-zA-Z0-9._/-]+", httpfs.HandleGet)
	goji.Put("/fs/[a-zA-Z0-9._/-]+", httpfs.HandlePut)
	goji.Delete("/fs/[a-zA-Z0-9._/-]+", httpfs.HandleDelete)
	goji.ServeListener(bind.Socket(":10002"))
}