2024-09-26 17:54:14 +08:00
|
|
|
package handler
|
|
|
|
|
|
|
|
import (
|
|
|
|
"nf-disk/internal/ndh"
|
2024-09-26 22:35:43 +08:00
|
|
|
"nf-disk/internal/s3"
|
2024-09-26 17:54:14 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func ConnectionTest(c *ndh.Ctx) error {
|
|
|
|
type Req struct {
|
|
|
|
Name string `json:"name"`
|
|
|
|
Endpoint string `json:"endpoint"`
|
|
|
|
Access string `json:"access"`
|
|
|
|
Key string `json:"key"`
|
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
|
|
|
err error
|
|
|
|
req = new(Req)
|
|
|
|
)
|
|
|
|
|
|
|
|
if err = c.ReqParse(req); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2024-09-26 22:35:43 +08:00
|
|
|
if req.Endpoint == "" || req.Access == "" || req.Key == "" {
|
|
|
|
return c.Send400(nil, "endpoint, secret_access, secret_key 是必填项")
|
|
|
|
}
|
|
|
|
|
|
|
|
if _, err = s3.New(c.Context(), req.Endpoint, req.Access, req.Key); err != nil {
|
|
|
|
return c.Send500(err.Error(), "连接失败")
|
|
|
|
}
|
|
|
|
|
2024-09-26 17:54:14 +08:00
|
|
|
return c.Send200("test success")
|
|
|
|
}
|