Ejemplo n.º 1
0
func runServer() {
	secrets := auth.HtpasswdFileProvider(".htpasswd")
	a := auth.BasicAuthenticator("oldbailey", secrets)

	http.HandleFunc("/static/", view.StaticHandler)
	http.HandleFunc("/case/", a(view.CaseHandler))
	http.HandleFunc("/search", a(view.SearchHandler))
	http.HandleFunc("/cache", a(view.CacheHandler))
	log.Println("Staring server on port 2258")
	log.Fatal(http.ListenAndServe(":2258", nil))
}
Ejemplo n.º 2
0
func main() {
	authenticator := auth.BasicAuthenticator("example.com", Secret)

	rpcServer = rpc.NewServer()
	rpcServer.RegisterCodec(json.NewCodec(), "application/json")
	rpcServer.RegisterService(new(HelloService), "")
	http.HandleFunc("/rpc", authenticator(handler))

	err := http.ListenAndServe(":9000", nil)
	if err != nil {
		log.Fatal(err)
	}
}
Ejemplo n.º 3
0
func main() {

	var config_path = flag.String("config", "", "Path to the config file")
	flag.Parse()

	if *config_path == "" {
		log.Fatal("Give path to the config file with -path=")
	}

	b, err := ioutil.ReadFile(*config_path)
	if err != nil {
		log.Fatal(err)
	}

	err = json.Unmarshal(b, &config)
	if err != nil {
		log.Fatal(err)
	}

	if config.Port == 0 || config.Auth_file == "" || len(config.Log_files) == 0 {
		log.Fatal("Invalid configuration")
	}

	watcher, err := fsnotify.NewWatcher()
	if err != nil {
		log.Fatal(err)
	}

	go func() {
		for {
			select {
			case ev := <-watcher.Event:
				log.Println("event:", ev)
			case err := <-watcher.Error:
				log.Println("error:", err)
			}
		}
	}()

	for _, v := range config.Log_files {
		log.Print(v.Path)
		err = watcher.Watch(v.Path)
		if err != nil {
			log.Fatal(err)
		}
	}

	secrets := auth.HtpasswdFileProvider(config.Auth_file)
	authenticator := auth.BasicAuthenticator("logserv", secrets)

	http.HandleFunc("/", authenticator(rootHandler))

	http.Handle("/websocket", websocket.Handler(EchoServer))
	listen_address := fmt.Sprintf(":%d", config.Port)
	http.ListenAndServe(listen_address, nil)
	if err != nil {
		panic("ListenAndServe: " + err.Error())
	}

	watcher.Close()
}