本文整理汇总了Golang中rsc/io/letsencrypt.Manager.SetHosts方法的典型用法代码示例。如果您正苦于以下问题:Golang Manager.SetHosts方法的具体用法?Golang Manager.SetHosts怎么用?Golang Manager.SetHosts使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rsc/io/letsencrypt.Manager
的用法示例。
在下文中一共展示了Manager.SetHosts方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: main
//.........这里部分代码省略.........
// courses
r.Get("/v2/courses", auth, withTx, withCurrentUser, GetCourses)
r.Get("/v2/courses/:course_id", auth, withTx, withCurrentUser, GetCourse)
r.Delete("/v2/courses/:course_id", auth, withTx, withCurrentUser, administratorOnly, DeleteCourse)
// users
r.Get("/v2/users", auth, withTx, withCurrentUser, GetUsers)
r.Get("/v2/users/me", auth, withTx, withCurrentUser, GetUserMe)
r.Get("/v2/users/me/cookie", auth, GetUserMeCookie)
r.Get("/v2/users/:user_id", auth, withTx, withCurrentUser, GetUser)
r.Get("/v2/courses/:course_id/users", auth, withTx, withCurrentUser, GetCourseUsers)
r.Delete("/v2/users/:user_id", auth, withTx, withCurrentUser, administratorOnly, DeleteUser)
// assignments
r.Get("/v2/users/:user_id/assignments", auth, withTx, withCurrentUser, GetUserAssignments)
r.Get("/v2/courses/:course_id/users/:user_id/assignments", auth, withTx, withCurrentUser, GetCourseUserAssignments)
r.Get("/v2/assignments/:assignment_id", auth, withTx, withCurrentUser, GetAssignment)
r.Delete("/v2/assignments/:assignment_id", auth, withTx, withCurrentUser, administratorOnly, DeleteAssignment)
// commits
r.Get("/v2/assignments/:assignment_id/problems/:problem_id/commits/last", auth, withTx, withCurrentUser, GetAssignmentProblemCommitLast)
r.Get("/v2/assignments/:assignment_id/problems/:problem_id/steps/:step/commits/last", auth, withTx, withCurrentUser, GetAssignmentProblemStepCommitLast)
r.Delete("/v2/commits/:commit_id", auth, withTx, withCurrentUser, administratorOnly, DeleteCommit)
// commit bundles
r.Post("/v2/commit_bundles/unsigned", auth, withTx, withCurrentUser, binding.Json(CommitBundle{}), PostCommitBundlesUnsigned)
r.Post("/v2/commit_bundles/signed", auth, withTx, withCurrentUser, binding.Json(CommitBundle{}), PostCommitBundlesSigned)
}
// set up daycare role
if daycare {
// make sure relevant secrets are included in config file
if Config.DaycareSecret == "" {
log.Fatalf("cannot run with no DaycareSecret in the config file")
}
// attach to docker and try a ping
var err error
dockerClient, err = docker.NewVersionedClient("unix:///var/run/docker.sock", "1.18")
if err != nil {
log.Fatalf("NewVersionedClient: %v", err)
}
if err = dockerClient.Ping(); err != nil {
log.Fatalf("Ping: %v", err)
}
r.Get("/v2/sockets/:problem_type/:action", SocketProblemTypeAction)
}
// start redirecting http calls to https
log.Printf("starting http -> https forwarder")
go http.ListenAndServe(":http", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// get the address of the client
addr := r.Header.Get("X-Real-IP")
if addr == "" {
addr = r.Header.Get("X-Forwarded-For")
if addr == "" {
addr = r.RemoteAddr
}
}
// make sure the request is for the right host name
if Config.Hostname != r.Host {
loggedHTTPErrorf(w, http.StatusNotFound, "http request to invalid host: %s", r.Host)
return
}
var u url.URL = *r.URL
u.Scheme = "https"
u.Host = Config.Hostname
log.Printf("redirecting http request from %s to %s", addr, u.String())
http.Redirect(w, r, u.String(), http.StatusMovedPermanently)
}))
// set up letsencrypt
lem := letsencrypt.Manager{}
if err := lem.CacheFile(Config.LetsEncryptCache); err != nil {
log.Fatalf("Setting up LetsEncrypt: %v", err)
}
lem.SetHosts([]string{Config.Hostname})
if !lem.Registered() {
log.Printf("registering with letsencrypt")
if err := lem.Register(Config.LetsEncryptEmail, nil); err != nil {
log.Fatalf("Registering with LetsEncrypt: %v", err)
}
}
// start the https server
log.Printf("accepting https connections")
server := &http.Server{
Addr: ":https",
Handler: m,
TLSConfig: &tls.Config{
MinVersion: tls.VersionTLS10,
GetCertificate: lem.GetCertificate,
},
}
if err := server.ListenAndServeTLS("", ""); err != nil {
log.Fatalf("ListenAndServeTLS: %v", err)
}
}