गो में, सर्वर ने सुनना शुरू करने के बाद ब्राउज़र कैसे शुरू कर सकता हूं?
पसंदीदा रूप से सबसे आसान तरीका संभव है।जाओ: सर्वर ने सुनना शुरू करने के बाद ब्राउज़र कैसे शुरू कर सकता हूं?
मेरे कोड अब तक, बात करने के लिए नीचे सुपर dumbed:
package main
import (
// Standard library packages
"fmt"
"net/http"
"github.com/skratchdot/open-golang/open"
// Third party packages
"github.com/julienschmidt/httprouter"
)
// go get github.com/toqueteos/webbrowser
func main() {
// Instantiate a new router
r := httprouter.New()
// Add a handler on /test
r.GET("/test", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
// Simply write some test data for now
fmt.Fprint(w, "Welcome!\n")
})
//open.Run("https://google.com/")
// open.Start("https://google.com")
// http://127.0.0.1:3000/test
// Fire up the server
http.ListenAndServe("localhost:3000", r)
fmt.Println("ListenAndServe is blocking")
open.RunWith("http://localhost:3000/test", "firefox")
fmt.Println("Done")
}
गो में "अवरुद्ध" http.ListenAndServe' "अवरुद्ध" करने के लिए बहुत जटिल नहीं है: 'http.ListenAndServe (...)' पर जाएं, शायद कुछ त्रुटि प्रबंधन के साथ। तो समस्या वास्तव में क्या है? – Volker
@ वोल्कर: समस्या यह है कि यह मेरे पहले कदम हैं, इसलिए मैं इसमें बहुत स्पष्ट नहीं हूं, फिर भी, मैं ब्राउज़र खोलने से पहले कुछ नया मिलीसेकंड के लिए एक नया धागा बनाउंगा और सो जाऊंगा; और फिलहाल मेरे पास अन्य चीजें हैं;) इसके अलावा, अगर सुनो और सर्वर गैर-अवरुद्ध था, तो यह मुख्य कार्यक्रम बाहर निकलने के पल से बाहर निकल जाएगा (AFAIK), जो तुरंत होगा। –