init
This commit is contained in:
36
main.go
Normal file
36
main.go
Normal file
@@ -0,0 +1,36 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"time"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// 获取环境变量或使用默认值
|
||||
port := os.Getenv("PORT")
|
||||
if port == "" {
|
||||
port = "8080"
|
||||
}
|
||||
|
||||
// 创建一个简单的HTTP服务器
|
||||
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||
hostname, _ := os.Hostname()
|
||||
fmt.Fprintf(w, "Hello from DevContainer!\n")
|
||||
fmt.Fprintf(w, "Server time: %s\n", time.Now().Format(time.RFC1123))
|
||||
fmt.Fprintf(w, "Hostname: %s\n", hostname)
|
||||
fmt.Fprintf(w, "Remote Address: %s\n", r.RemoteAddr)
|
||||
fmt.Fprintf(w, "User-Agent: %s\n", r.UserAgent())
|
||||
})
|
||||
|
||||
http.HandleFunc("/health", func(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
fmt.Fprintf(w, "Healthy")
|
||||
})
|
||||
|
||||
// 启动服务器
|
||||
log.Printf("Starting server on port %s", port)
|
||||
log.Fatal(http.ListenAndServe(":"+port, nil))
|
||||
}
|
||||
Reference in New Issue
Block a user