示例#1
0
func main() {
	var addr = flag.String("addr", ":8080", "The addr of the application.")
	flag.Parse() // parse the flags
	gomniauth.SetSecurityKey("some long key")
	gomniauth.WithProviders(
		facebook.New("key", "secret", "http://localhost:8080/auth/callback/facebook"),
		github.New("key", "secret", "http://localhost:8080/auth/callback/github"),
		google.New("key", "secret", "http://localhost:8080/auth/callback/google"),
	)
	r := newRoom()
	r.tracer = trace.New(os.Stdout)

	http.Handle("/chat", MustAuth(&templateHandler{filename: "chat.html"}))
	http.Handle("/login", &templateHandler{filename: "login.html"})
	http.HandleFunc("/auth/", loginHandler)
	http.Handle("/room", r)

	// get the room going
	go r.run()

	// start the web server
	log.Println("Starting web server on", *addr)
	if err := http.ListenAndServe(*addr, nil); err != nil {
		log.Fatal("ListenAndServe:", err)
	}

}
示例#2
0
文件: main.go 项目: lfq618/golearn
func main() {
	var addr = flag.String("addr", ":8080", "The addr of the application.")
	// set up gomniauth
	gomniauth.SetSecurityKey("lfq618")
	gomniauth.WithProviders(
		facebook.New("608517422619964", "ff3966474a0e0925419a57cd79776bdd", "http://localhost:8080/auth/callback/facebook"),
		github.New("6f6ab375ab58c83ce223", "20e565a7e13d235c60ede23a26d33bd8a735e03a", "http://localhost:8080/auth/callback/github"),
		google.New("507301202565-k1drgkq7v6u5b42fk849k90pm33b3van.apps.googleusercontent.com", "EmPZvBUVc1-Tc5fWQ4gjSh78", "http://localhost:8080/auth/callback/google"),
	)

	r := newRoom()
	//r.tracer = trace.New(os.Stdout)

	//root
	http.Handle("/chat", MustAuth(&templateHandler{filename: "chat.html"}))
	http.Handle("/login", &templateHandler{filename: "login.html"})
	http.HandleFunc("/auth/", loginHandler)
	http.Handle("/room", r)

	//get the room goint
	go r.run()

	//start the web server
	log.Println("Starting web server on", *addr)
	if err := http.ListenAndServe(*addr, nil); err != nil {
		log.Fatal("ListenAndServe:", err)
	}
}
示例#3
0
func main() {

	flag.Parse() // parse the flags

	// setup gomniauth
	gomniauth.SetSecurityKey("98dfbg7iu2nb4uywevihjw4tuiyub34noilk")
	gomniauth.WithProviders(
		github.New("3d1e6ba69036e0624b61", "7e8938928d802e7582908a5eadaaaf22d64babf1", "http://localhost:8080/auth/callback/github"),
		google.New("44166123467-o6brs9o43tgaek9q12lef07bk48m3jmf.apps.googleusercontent.com", "rpXpakthfjPVoFGvcf9CVCu7", "http://localhost:8080/auth/callback/google"),
		facebook.New("537611606322077", "f9f4d77b3d3f4f5775369f5c9f88f65e", "http://localhost:8080/auth/callback/facebook"),
	)

	r := newRoom()
	r.tracer = trace.New(os.Stdout)

	http.Handle("/chat", MustAuth(&templateHandler{filename: "chat.html"}))
	http.Handle("/login", &templateHandler{filename: "login.html"})
	http.HandleFunc("/auth/", loginHandler)
	http.Handle("/room", r)

	// get the room going
	go r.run()

	// start the web server
	log.Println("Starting web server on", *host)
	if err := http.ListenAndServe(*host, nil); err != nil {
		log.Fatal("ListenAndServe:", err)
	}

}
示例#4
0
func main() {
	var addr = flag.String("addr", ":8080", "The addr of the application")
	flag.Parse()

	gomniauth.SetSecurityKey("wetre94541gd616fd1g6fd")
	gomniauth.WithProviders(
		facebook.New("1578364069092723", "3be3e79ef1c5a14a8d556d45ab28bc23",
			"http://localhost:8080/auth/callback/facebook"),
		google.New("773345955621-aj0hpvne7depi9er2cp72t2mrknb3l26.apps.googleusercontent.com", "zT2_36o-f18VxmmvdltT_9vX",
			"http://localhost:8080/auth/callback/google"),
	)

	r := newRoom()
	r.tracer = trace.New(os.Stdout)
	http.Handle("/chat", MustAuth(&templateHandler{filename: "chat.html"}))
	http.Handle("/login", &templateHandler{filename: "login.html"})
	http.HandleFunc("/auth/", loginHander)
	http.Handle("/room", r)

	//start the room in the background
	go r.run()

	//start the web server
	log.Println("Starting web server on", *addr)
	if err := http.ListenAndServe(*addr, nil); err != nil {
		log.Fatal("ListenAndServe:", err)
	}
}
示例#5
0
func main() {
	var addr = flag.String("addr", ":8080", "app address")
	flag.Parse()

	gomniauth.SetSecurityKey(signature.RandomKey(64))
	gomniauth.WithProviders(
		google.New("391625238451-97uhiqpmehlvmgc48f5dscu2qi933v4l.apps.googleusercontent.com", "eqjo3wv_tXr6i9FJlgFiYRKD", "http://localhost:8080/auth/callback/google"),
	)

	r := newRoom()
	r.tracer = trace.New(os.Stdout)
	// http.Handle("/", &templateHandler{filename: "chat.html"})
	http.Handle("/chat", MustAuth(&templateHandler{filename: "chat.html"}))
	http.Handle("/login", &templateHandler{filename: "login.html"})
	http.HandleFunc("/logout", func(w http.ResponseWriter, r *http.Request) {
		http.SetCookie(w, &http.Cookie{
			Name:   "auth",
			Value:  "",
			Path:   "/",
			MaxAge: -1,
		})
		w.Header()["Location"] = []string{"/chat"}
		w.WriteHeader(http.StatusTemporaryRedirect)
	})
	http.HandleFunc("/auth/", loginHandler)
	http.Handle("/room", r)

	go r.run()

	log.Println("launching server port :", *addr)

	if err := http.ListenAndServe(*addr, nil); err != nil {
		log.Fatal("ListenAndServe:", err)
	}
}
示例#6
0
func main() {
	var addr = flag.String("addr", ":8080", "アプリケーションのアドレス")
	flag.Parse() // フラグを解釈します
	// Gomniauthのセットアップ
	gomniauth.SetSecurityKey("セキュリティキー")
	gomniauth.WithProviders(
		facebook.New("クライアントID", "秘密の値", "http://localhost:8080/auth/callback/facebook"),
		github.New("クライアントID", "秘密の値", "http://localhost:8080/auth/callback/github"),
		google.New("クライアントID", "秘密の値", "http://localhost:8080/auth/callback/google"),
	)

	r := newRoom()
	r.tracer = trace.New(os.Stdout)
	http.Handle("/chat", MustAuth(&templateHandler{filename: "chat.html"}))
	http.Handle("/login", &templateHandler{filename: "login.html"})
	http.HandleFunc("/auth/", loginHandler)
	http.Handle("/room", r)
	// チャットルームを開始します
	go r.run()
	// Webサーバーを起動します
	log.Println("Webサーバーを開始します。ポート: ", *addr)
	if err := http.ListenAndServe(*addr, nil); err != nil {
		log.Fatal("ListenAndServe:", err)
	}
}
示例#7
0
文件: main.go 项目: bonegollira/gogo
func main() {
	addr := flag.String("addr", ":8080", "アプリケーションのアドレス")
	flag.Parse()

	gomniauth.SetSecurityKey("GoChat")
	gomniauth.WithProviders(
		google.New(googleClientID, googleSecret, "http://localhost:8080/auth/callback/google"),
	)

	r := newRoom()
	r.tracer = trace.New(os.Stdout)

	// http.HandleFunc("/", func (w http.ResponseWriter, r *http.Request) {w.Write([]byte())})
	// http.Handle("/assets/", http.StripPrefix("/assets", http.FileServer(http.Dir("/assetsへのパス"))))
	// *templateHandler型(templateHandlerのポインタ型)にServeHTTPが実装されている
	// のでtemplateHandlerのアドレスを渡してポインタである*templateHandler型を渡す
	http.Handle("/chat", MustAuth(&templateHandler{filename: "chat.html"}))
	http.Handle("/login", &templateHandler{filename: "login.html"})
	http.HandleFunc("/auth/", loginHandler)
	http.Handle("/room", r)

	go r.run()

	log.Println("Webサーバを開始します。ポート: ", *addr)

	// start web server
	if err := http.ListenAndServe(*addr, nil); err != nil {
		log.Fatal("ListenAndServe:", err)
	}
}
示例#8
0
func main() {
	var addr = flag.String("addr", ":8080", "アプリケーションのアドレス")
	flag.Parse()
	gomniauth.SetSecurityKey(signature.RandomKey(64))
	gomniauth.WithProviders(
		google.New(
			os.Getenv("client_id"),
			os.Getenv("client_secret"),
			"http://localhost:8080/auth/callback/google"))
	r := newRoom(UseFileSystemAvatar)
	http.Handle("/chat", MustAuth(&templateHandler{filename: "chat.html"}))
	http.Handle("/login", &templateHandler{filename: "login.html"})
	http.HandleFunc("/logout", func(w http.ResponseWriter, r *http.Request) {
		http.SetCookie(w, &http.Cookie{
			Name:   "auth",
			Value:  "",
			Path:   "/",
			MaxAge: -1,
		})
		w.Header().Set("Location", "/chat")
		w.WriteHeader(http.StatusTemporaryRedirect)
	})
	http.HandleFunc("/auth/", loginHandler)
	http.Handle("/room", r)
	http.Handle("/upload", &templateHandler{filename: "upload.html"})
	http.HandleFunc("/uploader", uploaderHandler)
	http.Handle("/avatars/",
		http.StripPrefix("/avatars/",
			http.FileServer(http.Dir("./avatars"))))
	go r.run()
	log.Println("Webサーバーを開始します。ポート: ", *addr)
	if err := http.ListenAndServe(*addr, nil); err != nil {
		log.Fatal("ListenAndServe:", err)
	}
}
示例#9
0
func main() {
	var addr = flag.String("addr", ":18080", "アプリケーションのアドレス")
	flag.Parse() // フラグを解釈します

	// Gomniauth のセットアップ
	gomniauth.SetSecurityKey("RESIDENCE101")
	gomniauth.WithProviders(
		facebook.New("957653387645069", "bd4b9984868d78cb2012b4554a6c61a8", "http://localhost:18080/auth/callback/facebook"),
		github.New("60c22ff289a776f58746", "cd1581d547e80cfc01586bdfd343317a8b9e3f65", "http://localhost:18080/auth/callback/github"),
		google.New("940801949020-9b6d4r5emh1k6ds9mmmiq1esdt669mrs.apps.googleusercontent.com", "jd3H38hVee1Ragcx0UzStHoW", "http://localhost:18080/auth/callback/google"),
	)

	r := newRoom()
	http.Handle("/chat", MustAuth(&templateHandler{filename: "chat.html"}))
	http.Handle("/login", &templateHandler{filename: "login.html"})
	http.HandleFunc("/auth/", loginHandler)
	http.Handle("/room", r)

	// チャットルームを開始します
	go r.run()

	// Web サーバーを開始します
	log.Println("Web サーバーを開始します。ポート: ", *addr)
	if err := http.ListenAndServe(*addr, nil); err != nil {
		log.Fatal("ListenAndServe:", err)
	}
}
示例#10
0
func _main() {
	var addr = flag.String("addr", ":8080", "アプリケーションのアドレス")
	var callbackURL = flag.String("google-oauth-callback", "http://localhost:8080/auth/callback/google", "Google認証のコールバックURL")
	flag.Parse()

	gomniauth.SetSecurityKey(signature.RandomKey(64))
	gomniauth.WithProviders(
		google.New(os.Getenv("GOOGLE_OAUTH_CLIENT_ID"), os.Getenv("GOOGLE_OAUTH_CLIENT_SECRET"), *callbackURL),
	)

	r := newRoom()
	r.tracer = trace.New(os.Stdout)
	http.Handle("/chat", MustAuth(&templateHandler{filename: "index.html"}))
	http.Handle("/login", &templateHandler{filename: "login.html"})
	http.HandleFunc("/auth/", loginHandler)
	http.Handle("/room", r)

	go r.run()

	log.Println("Webサーバーを開始します。ポート: ", *addr)
	log.Println("Google認証のコールバックURL: ", *callbackURL)
	if err := http.ListenAndServe(*addr, nil); err != nil {
		log.Fatal("ListenAndServe: ", err)
	}
}
示例#11
0
func setUpProvider() {
	// setup the providers
	gomniauth.SetSecurityKey(MySecurityKey)
	gomniauth.WithProviders(
		google.New(GoogleClientId, GoogleSecret, "http://localhost:8080/auth/google/callback"),
	)
}
示例#12
0
文件: auth.go 项目: RorNHJ/GoLanguage
func init() {
	// gomniauth 정보 셋팅
	gomniauth.SetSecurityKey(authSecurityKey)
	gomniauth.WithProviders(
		google.New("636296155193-a9abes4mc1p81752l116qkr9do6oev3f.apps.googleusercontent.com", "EVvuy0Agv4jWflml0pvC6-vI",
			"http://127.0.0.1:3000/auth/callback/google"),
	)
}
示例#13
0
文件: login.go 项目: joonazan/go-opas
func init() {

	gomniauth.SetSecurityKey(signature.RandomKey(64))
	gomniauth.WithProviders(
		google.New("712450255947-o5uppfp82sc3sb2c1dum7es8k93ras4q.apps.googleusercontent.com", "TrFX1I5QJZ_unJ-P5UgYLF4N", PalvelimenOsoite+"/authcallback/google"),
	)

	gob.Register(User{})
}
示例#14
0
func main() {
	// The de nition for the addr variable sets up our flag
	// as a string that defaults to :8080
	addr := flag.String("addr", ":8080", "The addr of the application.")
	// must call flag. Parse() that parses the arguments
	// and extracts the appropriate information.
	// Then, we can reference the value of the host  ag by using *addr.
	flag.Parse() // parse the flags

	// set up gomniauth
	gomniauth.SetSecurityKey("some long key")
	gomniauth.WithProviders(
		facebook.New("key", "secret", ""),
		github.New("key", "secret", ""),
		google.New("151570833065-i9p63mogjm7adt0h0490or9bvqua0r2l.apps.googleusercontent.com",
			"jzEEORYarixD30S6qyosGrWe",
			"http://localhost:3000/auth/callback/google"),
	)

	//	r := newRoom(UseAuthAvatar)
	//	r := newRoom(UseGravatar)
	r := newRoom(UseFileSystemAvatar)
	r.tracer = trace.New(os.Stdout)

	http.Handle("/chat", MustAuth(&templateHandler{filename: "chat.html"}))
	http.Handle("/login", &templateHandler{filename: "login.html"})
	http.HandleFunc("/auth/", loginHandler)
	http.Handle("/room", r)
	http.HandleFunc("/logout", func(w http.ResponseWriter, r *http.Request) {
		http.SetCookie(w, &http.Cookie{
			Name:   "auth",
			Value:  "",
			Path:   "/",
			MaxAge: -1,
		})
		w.Header()["Location"] = []string{"/chat"}
		w.WriteHeader(http.StatusTemporaryRedirect)
	})
	http.Handle("/upload", &templateHandler{filename: "upload.html"})
	http.HandleFunc("/uploader", uploaderHandler)
	http.Handle("/avatars/",
		http.StripPrefix("chapter2/chat/avatars/",
			http.FileServer(http.Dir("./avatars"))))

	// get the room going
	// running the room in a separate Go routine
	// so that the chatting operations occur in the background,
	// allowing our main thread to run the web server.
	go r.run()
	// start the web server
	log.Println("Starting web server on", *addr)
	// start the web server
	if err := http.ListenAndServe(*addr, nil); err != nil {
		log.Fatal("ListenAndServe:", err)
	}
}
示例#15
0
func (a *defaultAuthenticator) getAuthProvider(r *http.Request, providerName string) (common.Provider, error) {
	gomniauth.WithProviders(
		google.New(a.cfg.GoogleClientID,
			a.cfg.GoogleSecret,
			getBaseURL(r)+"/api/auth/oauth2/google/callback/",
		),
	)
	provider, err := gomniauth.Provider(providerName)
	if err != nil {
		return provider, errgo.Mask(err)
	}
	return provider, nil
}
示例#16
0
文件: main.go 项目: oywc410/MYPG
func main() {

	var addr = flag.String("addr", ":8001", "アプリケーションのアドレス")
	flag.Parse()

	gomniauth.SetSecurityKey("mysrcuritykey")
	gomniauth.WithProviders(
		//facebook.New("???", "???", "http://......")
		google.New("400720597353-vb6mkg2ia79blui2qs2vbc67dedtnrns.apps.googleusercontent.com", "qUDc1kADhKC7dGjdNNI1MVU7", "http://127.0.0.1:8001/auth/callback/google"),
	)

	//r := newRoom(UseAuthAvatar)
	//r := newRoom(UserGravatar)
	r := newRoom()
	r.tracer = trace.New(os.Stdout)

	//StripPrefix显示文件目录列表
	//FileServer文件服务器
	http.Handle("/avatars/", http.StripPrefix("/avatars", http.FileServer(http.Dir("./avatars"))))
	http.Handle("/assets/", http.StripPrefix("/assets", http.FileServer(http.Dir("./assets"))))
	//http.Handler("/assets/", http.FileServer(http.Dir("./assets")))

	http.Handle("/chat", MustAuth(&templateHandler{filename: "chat.html"}))
	http.Handle("/login", &templateHandler{filename: "login.html"})
	http.HandleFunc("/auth/", loginHandler)
	http.Handle("/room", r)
	http.HandleFunc("/logout", func(w http.ResponseWriter, r *http.Request) {
		http.SetCookie(w, &http.Cookie{
			Name:   "auth",
			Value:  "",
			Path:   "/",
			MaxAge: -1,
		})
		w.Header()["Location"] = []string{"/chat"}
		w.WriteHeader(http.StatusTemporaryRedirect)
	})
	http.Handle("/upload", &templateHandler{filename: "upload.html"})
	http.HandleFunc("/uploader", uploaderHandler)

	// '/root'  只解析到/root       '/root/'  解析/root/XXXXX 至结束

	//启动socket监听
	go r.run()

	log.Println("Web服务器启动,端口:", *addr)

	if err := http.ListenAndServe(*addr, nil); err != nil {
		log.Fatal("ListenAndServer:", err)
	}
}
示例#17
0
文件: main.go 项目: liyu-wang/go-chat
func main() {
	var addr = flag.String("addr", ":8080", "The addr of the application.")
	flag.Parse() // parse the flags

	// set up gomniauth
	gomniauth.SetSecurityKey("amazing2050")
	gomniauth.WithProviders(
		facebook.New("key", "secret", "http://localhost:8080/auth/callback/facebook"),
		github.New("key", "secret", "http://localhost:8080/auth/callback/github"),
		google.New("638547583987-2l7p38d7iq7kpp2rvvms4ambvg1qaq5b.apps.googleusercontent.com", "whS4UlWsA0YXRdD7nVQScrcK", "http://localhost:8080/auth/callback/google"),
	)

	r := newRoom()
	r.tracer = trace.New(os.Stdout)

	// handlers
	http.Handle("/chat", MustAuth(&templateHandler{filename: "chat.html"}))
	http.Handle("/login", &templateHandler{filename: "login.html"})
	http.HandleFunc("/auth/", loginHander)
	http.Handle("/room", r)
	http.Handle("/upload", MustAuth(&templateHandler{filename: "upload.html"}))
	http.HandleFunc("/uploader", uploaderHandler)
	// both http.StripPrefix and http.FileServer return Handler and they
	// use the decorator pattern
	// The StripPrefix function takes Handler in, modifies the path by removing
	// the specified prefix, and passes functionality onto an inner handler.
	// The FileServer handler simply serve static files, and generating the
	// 404 Not Fount error if it cannot find the file.
	http.Handle("/avatars/",
		http.StripPrefix("/avatars/",
			http.FileServer(http.Dir("./avatars"))))
	http.HandleFunc("/logout", func(w http.ResponseWriter, r *http.Request) {
		http.SetCookie(w, &http.Cookie{
			Name:   "auth",
			Value:  "",
			Path:   "/",
			MaxAge: -1,
		})
		w.Header()["Location"] = []string{"/chat"}
		w.WriteHeader(http.StatusTemporaryRedirect)
	})

	// get the room going
	go r.run()
	// start the web server
	log.Println("Starting web server on", *addr)
	if err := http.ListenAndServe(*addr, nil); err != nil {
		log.Fatal("ListenAndServe:", err)
	}
}
示例#18
0
func main() {
	secretKey := "kyokomi-secret"

	gomniauth.SetSecurityKey(secretKey)
	gomniauth.WithProviders(
		github.New(githubClientID, githubSecretKey, githubRedirectURL),
		google.New(googleClientID, googleSecretKey, googleRedirectURL),
	)

	kami.Get("/", indexHandler)
	kami.Get("/auth/login/:provider", loginHandler)
	kami.Get("/auth/callback/:provider", callbackHandler)

	kami.Serve()
}
示例#19
0
func main() {
	addr := flag.String("addr", ":8080", "An address of application")
	flag.Parse()

	config := loadConfig()

	gomniauth.SetSecurityKey("セキュリティキー")
	gomniauth.WithProviders(
		facebook.New(
			config.Facebook.ClientID,
			config.Facebook.ClientSecret,
			"http://localhost:8080/auth/callback/facebook",
		),
		github.New(
			config.Github.ClientID,
			config.Github.ClientSecret,
			"http://localhost:8080/auth/callback/github",
		),
		google.New(
			config.Google.ClientID,
			config.Google.ClientSecret,
			"http://localhost:8080/auth/callback/google",
		),
	)
	r := newRoom(UseGravatar)
	http.Handle("/chat", MustAuth(&templateHandler{filename: "chat.html"}))
	http.Handle("/login", &templateHandler{filename: "login.html"})
	http.HandleFunc("/auth/", loginHandler)
	http.Handle("/room", r)
	http.HandleFunc("/logout", func(w http.ResponseWriter, r *http.Request) {
		http.SetCookie(w, &http.Cookie{
			Name:   "auth",
			Value:  "",
			Path:   "/",
			MaxAge: -1,
		})
		w.Header()["Location"] = []string{"/chat"}
		w.WriteHeader(http.StatusTemporaryRedirect)
	})
	http.Handle("/upload", &templateHandler{filename: "upload.html"})
	http.HandleFunc("/uploader", uploadHandler)

	go r.run()
	log.Println("start web server. port: ", *addr)
	if err := http.ListenAndServe(*addr, nil); err != nil {
		log.Fatal("ListenAndServe:", err)
	}
}
示例#20
0
文件: main.go 项目: keito-jp/chat
func main() {
	var addr = flag.String("addr", ":8080", "アプリケーションのアドレス")
	flag.Parse()

	c, err := redis.Dial("tcp", ":6379")
	if err != nil {
		fmt.Println(err)
		return
	}
	defer c.Close()
	log.Println("Redisにせつぞくしました。")

	gomniauth.SetSecurityKey(os.Getenv("FUNNYCHAT_SECURITY_KEY"))
	gomniauth.WithProviders(
		facebook.New(os.Getenv("FB_CLIENT_ID"), os.Getenv("FB_SECRET_KEY"), "http://localhost:8080/auth/callback/facebook"),
		google.New(os.Getenv("GOOGLE_CLIENT_ID"), os.Getenv("GOOGLE_SECRET_KEY"), "http://localhost:8080/auth/callback/google"),
		github.New(os.Getenv("GITHUB_CLIENT_ID"), os.Getenv("GITHUB_SECRET_KEY"), "http://localhost:8080/auth/callback/github"),
	)

	r := newRoom(c)
	r.subscribe("room01")
	r.tracer = trace.New(os.Stdout)

	http.Handle("/chat", MustAuth(&templateHandler{filename: "chat.html"}))
	http.Handle("/login", &templateHandler{filename: "login.html"})
	http.HandleFunc("/auth/", loginHandler)
	http.HandleFunc("/logout", func(w http.ResponseWriter, r *http.Request) {
		http.SetCookie(w, &http.Cookie{
			Name:   "auth",
			Value:  "",
			Path:   "/",
			MaxAge: -1,
		})
		w.Header()["Location"] = []string{"/chat"}
		w.WriteHeader(http.StatusTemporaryRedirect)
	})
	http.Handle("/room", r)
	http.Handle("/upload", &templateHandler{filename: "upload.html"})
	http.HandleFunc("/uploader", uploadHandler)
	http.Handle("/avatars/", http.StripPrefix("/avatars/", http.FileServer(http.Dir("./avatars"))))
	http.Handle("/assets/", http.StripPrefix("/assets", http.FileServer(http.Dir("assets"))))
	go r.run()
	go r.receive()
	log.Println("Webサーバーを開始します。ポート: ", *addr)
	if err := http.ListenAndServe(*addr, nil); err != nil {
		log.Fatal("ListenAndServe:", err)
	}
}
示例#21
0
func main() {
	var addr = flag.String("addr", ":8080", "アプリケーションのアドレス")
	flag.Parse() // フラグを解釈します

	// Gomniauthのセットアップ
	gomniauth.SetSecurityKey(os.Getenv("SECURITY_KEY"))
	gomniauth.WithProviders(
		google.New(os.Getenv("GOOGLE_CLIENT_ID"), os.Getenv("GOOGLE_SECRET_KEY"), "http://localhost:8080/auth/callback/google"),
	)

	// staticファイルを配布する場合
	// http.Handle("/assets/",
	// 	http.StripPrefix("/assets",
	// 		http.FileServer(http.Dir("/assets/"))))

	r := newRoom(UseFileSystemAvatar)
	r.tracer = trace.New(os.Stdout)
	// ルート
	http.Handle("/login", &templateHandler{filename: "login.html"})
	http.Handle("/chat", MustAuth(&templateHandler{filename: "chat.html"}))
	http.HandleFunc("/auth/", loginHandler)
	http.HandleFunc("/logout", func(w http.ResponseWriter, r *http.Request) {
		http.SetCookie(w, &http.Cookie{
			Name:   "auth",
			Value:  "",
			Path:   "/",
			MaxAge: -1,
		})
		w.Header()["Location"] = []string{"/chat"}
		w.WriteHeader(http.StatusTemporaryRedirect)
	})
	http.Handle("/room", r)
	http.Handle("/upload", &templateHandler{filename: "upload.html"})
	http.HandleFunc("/uploader", uploaderHandler)
	// TODO: p77を再読
	http.Handle("/avatars/",
		http.StripPrefix("/avatars/",
			http.FileServer(http.Dir("./avatars/"))))

	// チャットルームを開始する
	go r.run()

	// Webサーバーを開始します
	log.Println("Webサーバーを開始します。ポート: ", *addr)
	if err := http.ListenAndServe(*addr, nil); err != nil {
		log.Fatal("ListenAndServe", err)
	}
}
示例#22
0
func main() {
	var addr = flag.String("addr", ":8080", "The addr of the application.")
	flag.Parse() // parse the flags
	//	set up gomniauth
	gomniauth.SetSecurityKey("this is my own crazy phrase not")
	gomniauth.WithProviders(
		facebook.New("key", "secret", "http://localhost:8080/auth/callback/facebook"),
		github.New("key", "secret", "http://localhost:8080/auth/callback/github"),
		google.New("AIzaSyAHdC_P8iM2SU3D5BEh5747tGb4Sr5xxj8", "3aoJeQ8Ub3l2Gfvz-wNIOXUo", "http://localhost:8080/auth/callback/google"),
	)
	r := newRoom()
	//	output to the os.Stdout standard output pipe (prints output to the terminal)
	//r.tracer = trace.New(os.Stdout)
	// root
	http.Handle("/chat", MustAuth(&templateHandler{filename: "chat.html"}))
	http.Handle("/login", &templateHandler{filename: "login.html"})
	http.HandleFunc("/auth/", loginHandler)
	http.Handle("/room", r)

	//	Directory used to store css and js files.
	//http.Handle("/assets/",
	//	http.StripPrefix("/assets",
	//		http.FileServer(http.Dir("/path/to/assets/"))))

	//	get the room going
	go r.run()

	//	Writes out the hardcoded HTML when a request is made
	/*http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
		w.Write([]byte(`
			<html>
				<head>
					<title>Chat</title>
				</head>
				<body>
					Let's chat!
				</body>
			</html>
		`))
	})*/
	// 	Starts web server using ListenAndServe
	log.Println("Starting web server on", *addr)
	if err := http.ListenAndServe(":8080", nil); err != nil {
		log.Fatal("ListenAndServe:", err)
	}
}
示例#23
0
文件: main.go 项目: onufert/chat
func main() {

	var addr = flag.String("addr", ":8080", "Address to serve application from")
	var debug = flag.Bool("debug", true, "Turn on debugging")
	flag.Parse()

	gomniauth.SetSecurityKey("some long key")
	gomniauth.WithProviders(
		google.New(googleClientID, googleClientSecret, "http://localhost:8080/auth/callback/google"),
	)

	r := newRoom()
	if *debug {
		r.tracer = trace.New(os.Stdout)
	}
	http.Handle("/static/",
		http.StripPrefix("/static",
			http.FileServer(http.Dir("static/"))))
	http.Handle("/avatars/",
		http.StripPrefix("/avatars/",
			http.FileServer(http.Dir("./avatars"))))
	http.Handle("/", &templateHandler{filename: "chat.html"})
	http.Handle("/chat", MustAuth(&templateHandler{filename: "chat.html"}))
	http.Handle("/login", &templateHandler{filename: "login.html"})
	http.HandleFunc("/logout", func(w http.ResponseWriter, r *http.Request) {
		http.SetCookie(w, &http.Cookie{
			Name:   "auth",
			Value:  "",
			Path:   "/",
			MaxAge: -1,
		})
		w.Header()["Location"] = []string{"/chat"}
		w.WriteHeader(http.StatusTemporaryRedirect)
	})
	http.HandleFunc("/auth/", loginHandler)
	http.Handle("/upload", &templateHandler{filename: "upload.html"})
	http.HandleFunc("/uploader", uploadHandler)
	http.Handle("/room", r)
	// start the room for clients to connect to
	go r.run()
	//start the web server
	log.Println("Starting web server on port ", *addr)
	if err := http.ListenAndServe(":8080", nil); err != nil {
		log.Fatal("ListenAndServe:", err)
	}
}
示例#24
0
func main() {

	flag.Parse() // parse the flags

	// setup gomniauth
	gomniauth.SetSecurityKey("98dfbg7iu2nb4uywevihjw4tuiyub34noilk")
	gomniauth.WithProviders(
		github.New("3d1e6ba69036e0624b61", "7e8938928d802e7582908a5eadaaaf22d64babf1", "http://localhost:8080/auth/callback/github"),
		google.New("44166123467-o6brs9o43tgaek9q12lef07bk48m3jmf.apps.googleusercontent.com", "rpXpakthfjPVoFGvcf9CVCu7", "http://localhost:8080/auth/callback/google"),
		facebook.New("537611606322077", "f9f4d77b3d3f4f5775369f5c9f88f65e", "http://localhost:8080/auth/callback/facebook"),
	)

	r := newRoom()
	r.tracer = trace.New(os.Stdout)

	http.Handle("/chat", MustAuth(&templateHandler{filename: "chat.html"}))
	http.Handle("/login", &templateHandler{filename: "login.html"})
	http.HandleFunc("/auth/", loginHandler)
	http.Handle("/room", r)
	http.HandleFunc("/logout", func(w http.ResponseWriter, r *http.Request) {
		http.SetCookie(w, &http.Cookie{
			Name:   "auth",
			Value:  "",
			Path:   "/",
			MaxAge: -1,
		})
		w.Header().Set("Location", "/chat")
		w.WriteHeader(http.StatusTemporaryRedirect)
	})
	http.Handle("/upload", &templateHandler{filename: "upload.html"})
	http.HandleFunc("/uploader", uploaderHandler)

	http.Handle("/avatars/",
		http.StripPrefix("/avatars/",
			http.FileServer(http.Dir("./avatars"))))

	// get the room going
	go r.run()

	// start the web server
	log.Println("Starting web server on", *host)
	if err := http.ListenAndServe(*host, nil); err != nil {
		log.Fatal("ListenAndServe:", err)
	}

}
示例#25
0
func main() {
	var addr = flag.String("addr", ":8080", "The addr of the application")
	flag.Parse() // parse the flag

	gomniauth.SetSecurityKey(signature.RandomKey(64))
	gomniauth.WithProviders(
		google.New("605169096484-hvgf6b5u60cdv0krm7r106b1v4lsuvk9.apps.googleusercontent.com",
			"0F1iTCjapfcoFUupsINMc-6X", "http://localhost:8080/auth/callback/google"),
	)

	r := newRoom()
	r.tracer = trace.New(os.Stdout)

	http.HandleFunc("/logout", func(w http.ResponseWriter, r *http.Request) {
		http.SetCookie(w, &http.Cookie{
			Name:   "auth",
			Value:  "",
			Path:   "/",
			MaxAge: -1,
		})
		w.Header()["Location"] = []string{"/chat"}
		w.WriteHeader(http.StatusTemporaryRedirect)
	})
	http.Handle("/chat",
		MustAuth(&templateHandler{filename: "chat.html"}))
	http.Handle("/login",
		&templateHandler{filename: "login.html"})
	http.Handle("/upload", &templateHandler{filename: "upload.html"})

	http.Handle("/avatars/",
		http.StripPrefix("/avatars/", http.FileServer(http.Dir("./avatars"))))

	http.HandleFunc("/uploader", uploaderHandler)
	http.HandleFunc("/auth/", loginHandler)
	http.Handle("/room", r)

	// get the room going
	go r.run()

	// start the web server
	log.Println("Starting web server on", *addr)
	if err := http.ListenAndServe(*addr, nil); err != nil {
		log.Fatal("ListenAndServe:", err)
	}

}
示例#26
0
func main() {
	var addr = flag.String("addr", ":3000", "The addr of the application")
	flag.Parse()

	// set up gomniauth
	gomniauth.SetSecurityKey("some long key")
	gomniauth.WithProviders(
		facebook.New("key", "secret",
			"http://localhost:3000/auth/callback/facebook"),
		github.New("key", "secret",
			"http://localhost:3000/auth/callback/github"),
		google.New("89198476902-sp9n6ukjk37ccc2vuh11chkga865sidq.apps.googleusercontent.com", "GeQA1wriK2DdN_tTg8Sv1x9r",
			"http://localhost:3000/auth/callback/google"),
	)

	r := newRoom(UseAuthAvatar)
	http.HandleFunc("/room", r.serveHTTP)

	mainTemplate := &templateHandler{filename: "chat.html", messages: r.Messages}
	loginTemplate := &templateHandler{filename: "login.html"}

	http.HandleFunc("/auth/", LoginHandler)
	http.HandleFunc("/chat", MustAuth(mainTemplate).ServeHTTP)
	http.HandleFunc("/login", loginTemplate.ServeHTTP)

	http.HandleFunc("/logout", func(w http.ResponseWriter, r *http.Request) {
		http.SetCookie(w, &http.Cookie{
			Name:   "auth",
			Value:  "",
			Path:   "/",
			MaxAge: -1,
		})
		w.Header()["Location"] = []string{"/chat"}
		w.WriteHeader(http.StatusTemporaryRedirect)
	})

	go r.run()

	log.Println("Server starting on ", *addr)
	err := http.ListenAndServe(*addr, nil)
	if err != nil {
		log.Fatal("ListenAndServe: ", err)
	}
}
示例#27
0
func main() {
	var addr = flag.String("addr", ":8080", "The addr of the application")
	flag.Parse()

	gomniauth.SetSecurityKey("wetre94541gd616fd1g6fd")
	gomniauth.WithProviders(
		facebook.New("1578364069092723", "3be3e79ef1c5a14a8d556d45ab28bc23",
			"http://localhost:8080/auth/callback/facebook"),
		google.New("773345955621-aj0hpvne7depi9er2cp72t2mrknb3l26.apps.googleusercontent.com", "zT2_36o-f18VxmmvdltT_9vX",
			"http://localhost:8080/auth/callback/google"),
	)

	r := newRoom()
	r.tracer = trace.New(os.Stdout)
	http.Handle("/chat", MustAuth(&templateHandler{filename: "chat.html"}))
	http.Handle("/login", &templateHandler{filename: "login.html"})
	http.HandleFunc("/auth/", loginHander)
	http.Handle("/room", r)
	http.HandleFunc("/logout", func(w http.ResponseWriter, r *http.Request) {
		http.SetCookie(w, &http.Cookie{
			Name:   "auth",
			Value:  "",
			Path:   "/",
			MaxAge: -1,
		})
		w.Header()["Location"] = []string{"/chat"}
		w.WriteHeader(http.StatusTemporaryRedirect)
	})
	http.Handle("/upload", &templateHandler{filename: "upload.html"})
	http.HandleFunc("/uploader", uploadHandler)
	http.Handle("/avatars/",
		http.StripPrefix("/avatars",
			http.FileServer(http.Dir("./avatars"))))

	//start the room in the background
	go r.run()

	//start the web server
	log.Println("Starting web server on", *addr)
	if err := http.ListenAndServe(*addr, nil); err != nil {
		log.Fatal("ListenAndServe:", err)
	}
}
示例#28
0
文件: main.go 项目: gopher2121/gocode
func main() {
	// command line flags to make the address configurable
	var addr = flag.String("addr", ":8080", "address of the application")
	flag.Parse()

	//set up gomniauth
	gomniauth.SetSecurityKey("No matter how bad it is or how bad it gets I am gonna make it")
	gomniauth.WithProviders(
		google.New("395935673361-5p9o8soma5rsoh2j67nvqqc8urfno5vn.apps.googleusercontent.com", "7mF1VxAD5S7FlK4cToQmGZiJ", "http://localhost:8080/auth/callback/google"),
	)

	// create a new room
	r := newRoom()
	r.tracer = trace.New(os.Stdout)

	http.Handle("/chat", MustAuth(&templateHandler{filename: "index.html"}))
	//	http.Handle("/", &templateHandler{filename: "index.html"})

	http.Handle("/login", &templateHandler{filename: "login.html"})
	http.HandleFunc("/auth/", loginHandler)
	http.Handle("/room", r)
	// run the room as a separate go routine
	go r.run()
	/*
				// some old code to test whether server is working or not . Remove it once the final code is ready
			http.HandleFunc("/", func(rw http.ResponseWriter, req *http.Request) {
				rw.Write([]byte(`
		            <html>
		            <head>
		            <title> web server </title>
		            <body>
		            <h1> consistency is the key and one day I will be where I want to be </h1>
		            </body>
		            </html>
					`))
			})
	*/
	//  start the web server at port :8080 for now
	log.Println("starting web server on ", *addr)
	if err := http.ListenAndServe(*addr, nil); err != nil {
		log.Fatal("error information:", err)
	}
}
示例#29
0
func main() {

	// setup the providers
	gomniauth.SetSecurityKey("yLiCQYG7CAflDavqGH461IO0MHp7TEbpg6TwHBWdJzNwYod1i5ZTbrIF5bEoO3oP") // NOTE: DO NOT COPY THIS - MAKE YOR OWN!
	gomniauth.WithProviders(
		github.New("3d1e6ba69036e0624b61", "7e8938928d802e7582908a5eadaaaf22d64babf1", "http://localhost:8080/auth/github/callback"),
		google.New("1051709296778.apps.googleusercontent.com", "7oZxBGwpCI3UgFMgCq80Kx94", "http://localhost:8080/auth/google/callback"),
		facebook.New("537611606322077", "f9f4d77b3d3f4f5775369f5c9f88f65e", "http://localhost:8080/auth/facebook/callback"),
	)

	http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
		template := `
			<!DOCTYPE html>
			<html>
				<body>
				<h2>Log in with...</h2>
				<ul>
					<li>
					<a href="auth/github/login">GitHub</a>
					</li>
					<li>
					<a href="auth/google/login">Google</a>
					</li>
					<li>
					<a href="auth/facebook/login">Facebook</a>
					</li>
				</ul>
				</body>
			</html>
			`
		io.WriteString(w, template)
	})

	providers := []string{"google", "github", "facebook"}
	for _, provider := range providers {
		http.HandleFunc(fmt.Sprintf("/auth/%s/login", provider), loginHandler(provider))
		http.HandleFunc(fmt.Sprintf("/auth/%s/callback", provider), callbackHandler(provider))
	}

	http.ListenAndServe(Address, nil)

}
示例#30
0
func main() {
	var host = flag.String("host", ":8080", "The host of the application.")
	flag.Parse()

	key, secret := ReadCredentials("keys/chat-keys-google.json")
	// Set up gomniauth.
	gomniauth.SetSecurityKey("Q/AnKc03rI1ZzMuOBDL0ZCJiWbmO1dMUk3PiH6e/Gi83pqljwt9kV9eEZl7a5s0H")
	gomniauth.WithProviders(
		facebook.New("key", "secret", "http://localhost:8080/auth/callback/facebook"),
		github.New("key", "secret", "http://localhost:8080/auth/callback/github"),
		google.New(key, secret, "http://localhost:8080/auth/callback/google"),
	)

	http.HandleFunc("/auth/", loginHandler)
	http.Handle("/avatars/", http.StripPrefix("/avatars/", http.FileServer(http.Dir("./avatars"))))
	http.Handle("/chat", MustAuth(&templateHandler{filename: "chat.html"}))
	http.Handle("/login", &templateHandler{filename: "login.html"})
	http.Handle("/upload", &templateHandler{filename: "upload.html"})
	http.HandleFunc("/uploader", uploadHandler)
	http.HandleFunc("/logout", func(w http.ResponseWriter, r *http.Request) {
		http.SetCookie(w, &http.Cookie{
			Name:   "auth",
			Value:  "",
			Path:   "/",
			MaxAge: -1,
		})
		w.Header()["Location"] = []string{"/chat"}
		w.WriteHeader(http.StatusTemporaryRedirect)
	})

	r := newRoom()
	// r.tracer = trace.New(os.Stdout)
	http.Handle("/room", r)
	go r.run()

	// Start the web server.
	log.Println("Starting web server on", *host)
	if err := http.ListenAndServe(*host, nil); err != nil {
		log.Fatal("ListenAndServer:", err)
	}
}