タイトルの通り何ですが、『Go言語によるWebアプリケーション開発』でビルドするときに使うコマンドの./chat -host=":8080"がエラーになってしまいます。
※コードを追記しました
package main import ( "flag" "log" "net/http" "path/filepath" "sync" "text/template" "github.com/stretchr/gomniauth" "github.com/stretchr/gomniauth/providers/facebook" "github.com/stretchr/gomniauth/providers/github" "github.com/stretchr/gomniauth/providers/google" "github.com/stretchr/objx" ) //templは1つのテンプレートを表す type templateHandler struct { once sync.Once filename string templ *template.Template } //ServeHTTPはHTTPリクエストを処理する func (t *templateHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { t.once.Do(func() { t.templ = template.Must(template.ParseFiles(filepath.Join("templates", t.filename))) }) data := map[string]interface{}{ "Host": r.Host, } if authCookie, err := r.Cookie("auth"); err == nil { data["UserData"] = objx.MustFromBase64(authCookie.Value) } t.templ.Execute(w, data) } func main() { var addr = flag.String("addr", ":8080", "アプリケーションのアドレス") flag.Parse() //フラグを解釈します //Gomniauthのセットアップ gomniauth.SetSecurityKey("セキュリティキー") gomniauth.WithProviders( facebook.New("", "", "http://localhost:8080/auth/callback/facebook"), github.New("", "", "http://localhost:8080/auth/callback/github"), google.New("526115198658-gvoqprgin282r5ipkiiprii3pjqqi7vu.apps.googleusercontent.com", "tXvtbh5236VAlVZhonJaJMgE", "http://localhost:8080/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(":8080", nil); err != nil { log.Fatal("ListenAndServe:", err) } }
打ち込むコマンド
go build -o chat ./chat -host=":8080"
具体的なエラー結果は下記の通りです。
flag provided but not defined: -host Usage of ./chat: -addr string アプリケーションのアドレス (default ":8080")
ネットの記事にはこれを解決する方法は乗っていませんでした。
どうすればこのエラーを解決することができますか?
回答1件
あなたの回答
tips
プレビュー