golang和ListenAndServeTLS返回错误

时间:2015-04-13 09:05:56

标签: http go

func main(){
    runtime.GOMAXPROCS(runtime.NumCPU())

    r := mux.NewRouter()

    www := r.Host("secure.domain.com").Subrouter()
    www.HandleFunc("/", Handler_www)

    api := r.Host("api.domain.com").Subrouter()
    api.HandleFunc("/", Handler_api)

    go func(){
        cert := "/var/ini/ssl/secure.domain.com/intermediate.crt"
        prv_key := "/var/ini/ssl/secure.domain.com/private.key"
        err := http.ListenAndServeTLS(":9443", cert, prv_key, r)
        if err != nil {
            log.Fatal("HTTPS server: ", err)
        }
    }

    err := http.ListenAndServe(":9000", r)
    if err != nil {
        log.Fatal("HTTP server: ", err)
    }
}

1 个答案:

答案 0 :(得分:2)

在结束()后尝试添加}

这样,您实际上会调用func()

go func(){
    cert := "/var/ini/ssl/secure.domain.com/intermediate.crt"
    prv_key := "/var/ini/ssl/secure.domain.com/private.key"
    err := http.ListenAndServeTLS(":9443", cert, prv_key, r)
    if err != nil {
        log.Fatal("HTTPS server: ", err)
    }
}()