Go: How can I start the browser AFTER the server started listening?

后端 未结 3 1463
暖寄归人
暖寄归人 2020-12-15 07:40

In Go, how can I start the browser AFTER the server started listening ?
Preferably the simplest way possible.

My code so far, super dumbed down to the point:<

3条回答
  •  一个人的身影
    2020-12-15 08:17

    The API is not absolutely terrible, but let's just say "It takes some getting used to". Here is how you use custom attributes on the Server struct:

    s := &http.Server{
        Addr:           cnf.API_SERVER_ADDRESS,
        Handler:        h,
        ReadTimeout:    0, // 1 * time.Minute,
        WriteTimeout:   30 * time.Minute,
        MaxHeaderBytes: 1 << 20,
    }
    
    go func() {
    
        l, err := net.Listen("tcp", cnf.API_SERVER_ADDRESS)
    
        if err != nil {
            log.Fatal(err)
        }
    
        fmt.Println(`{"server_state":"listening"}`)
        log.Fatal(s.Serve(l));
    }()
    

    because if you instead use:

    http.Serve(l, handler)
    

    then you can't define custom properties on the server

提交回复
热议问题