示例#1
0
func NewServer() *server.Server {
	l, err := net.Listen("tcp", "127.0.0.1:0")
	if err != nil {
		panic(err)
	}
	s := server.NewServer(l, &test_auth{}, nil)
	ENDPOINT = "127.0.0.1:" + strconv.Itoa(s.ListeningPort())
	return s
}
示例#2
0
文件: lipwig.go 项目: rmoorman/lipwig
func main() {
	var address string
	var insecure bool
	var openLogin bool

	cfg.InitConfig()

	flag.StringVar(&address, "listen", "0.0.0.0:8787", "Listening address")
	flag.BoolVar(&insecure, "insecure", false, "Disable TLS")
	flag.BoolVar(&openLogin, "open", false, "Enable open login")
	flag.Parse()

	auth := &server.MultiSchemeAuthenticator{
		Schemes: map[string]server.AuthenticatorFunc{},
	}

	if openLogin {
		fmt.Println("WARN: open login is enabled")
		auth.Schemes["open"] = func(_ net.Conn, _, _, _ []byte) bool { return true }
	}

	if len(cfg.Secret) > 0 {
		b, err := ioutil.ReadFile(cfg.Secret)
		if err != nil {
			panic(err)
		}
		auth.Schemes["secret"] = server.SecretAuth(bytes.TrimSpace(b))
	}

	l, err := net.Listen("tcp", address)
	if err != nil {
		panic(err)
	}
	var tlsCfg *tls.Config = nil
	if insecure {
		fmt.Println("WARN: TLS is disabled")
	} else {
		tlsCfg = cfg.TLSConfig()
		auth.Schemes["cert"] = server.CertAuth
	}
	s := server.NewServer(l, auth, tlsCfg)
	SetupSignalHandler(s)
	fmt.Println("lipwig serving at", s.ListeningPort())
	err = s.Serve()
	if err != nil {
		panic(err)
	}
	fmt.Println("exit.")
}