Files
chis_osi/server.go
T

37 lines
1.2 KiB
Go

package main
import (
"fmt"
"net/http"
"chis_osi/config"
"chis_osi/handler"
)
// runServer 启动 server 模式 HTTP 服务,暴露查询端点。
func runServer(cfg config.Config, addr string) error {
client, err := buildOSIClient(cfg)
if err != nil {
return fmt.Errorf("build osi client: %w", err)
}
hr := handler.NewHealthRecordHandler(client)
hc := handler.NewHealthCheckHandler(client)
mux := http.NewServeMux()
mux.HandleFunc("/api/health-record/find", hr.Find)
mux.HandleFunc("/api/health-record/crowd", hr.Crowd)
mux.HandleFunc("/api/health-check/last", hc.Last)
mux.HandleFunc("/api/health-check/all", hc.All)
mux.HandleFunc("/api/health-check/list", hc.List)
fmt.Printf("chis_osi server listening on %s\n", addr)
fmt.Printf(" GET http://%s/api/health-record/find?idCard=<身份证>\n", addr)
fmt.Printf(" GET http://%s/api/health-record/crowd?idCard=<身份证>\n", addr)
fmt.Printf(" GET http://%s/api/health-check/last?idCard=<身份证>\n", addr)
fmt.Printf(" GET http://%s/api/health-check/all?idCard=<身份证>\n", addr)
fmt.Printf(" GET http://%s/api/health-check/list?checkYear=<年度>&idCard=<身份证>\n", addr)
server := &http.Server{Addr: addr, Handler: mux}
return server.ListenAndServe()
}