Skip to content

Commit

Permalink
update healthcheck
Browse files Browse the repository at this point in the history
  • Loading branch information
wj00037 committed Oct 16, 2024
1 parent f03bf40 commit 5535ef3
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 289 deletions.
39 changes: 0 additions & 39 deletions BigFiles/go.mod

This file was deleted.

103 changes: 0 additions & 103 deletions BigFiles/go.sum

This file was deleted.

127 changes: 0 additions & 127 deletions BigFiles/main.go

This file was deleted.

5 changes: 5 additions & 0 deletions batch/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ type Request struct {
} `json:"objects"`
}

type SuccessResponse struct {
Message string `json:"message"`
Data interface{} `json:"data,omitempty"`
}

type ErrorResponse struct {
Message string `json:"message"`
DocURL string `json:"documentation_url,omitempty"`
Expand Down
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ func main() {
if strings.HasPrefix(os.Getenv("AWS_EXECUTION_ENV"), "AWS_Lambda_") {
algnhsa.ListenAndServe(s, nil)
} else {
log.Println("serving on http://127.0.0.1:5000 ...")
if err := http.ListenAndServe("127.0.0.1:5000", s); err != nil {
log.Println("serving on http://0.0.0.0:5000 ...")
if err := http.ListenAndServe("0.0.0.0:5000", s); err != nil {
log.Fatalln(err)
}
}
Expand Down
32 changes: 14 additions & 18 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,29 +95,13 @@ func New(o Options) (http.Handler, error) {
}

r := chi.NewRouter()
r.Post("/{owner}/{repo}/objects/batch", s.handleBatch)

r.Get("/", s.healthCheck)
r.Post("/{owner}/{repo}/objects/batch", s.handleBatch)

return r, nil
}

type SuccessResponse struct {
Message string `json:"message"`
Data interface{} `json:"data,omitempty"` // 可选数据字段
}

func (s *server) healthCheck(w http.ResponseWriter, r *http.Request) {
response := SuccessResponse{
Message: "Success",
Data: "healthCheck success", // 替换为实际的数据
}

// 设置响应头
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK) // 200
must(json.NewEncoder(w).Encode(response))
}

type server struct {
client *minio.Client
bucket string
Expand Down Expand Up @@ -155,6 +139,7 @@ func (s *server) handleBatch(w http.ResponseWriter, r *http.Request) {
userInRepo.Username = username
userInRepo.Password = password
err = s.isAuthorized(userInRepo)
// TODO: 若仓库无lfs服务权限,不能返回401,否则会继续提示输入用户名密码。返回403
if err != nil {
err = fmt.Errorf("unauthorized: %w", err)
}
Expand Down Expand Up @@ -252,6 +237,17 @@ func (s *server) handleBatch(w http.ResponseWriter, r *http.Request) {
must(json.NewEncoder(w).Encode(resp))
}

func (s *server) healthCheck(w http.ResponseWriter, r *http.Request) {
response := batch.SuccessResponse{
Message: "Success",
Data: "healthCheck success",
}

w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
must(json.NewEncoder(w).Encode(response))
}

// --

func must(err error) {
Expand Down

0 comments on commit 5535ef3

Please sign in to comment.