35 lines
		
	
	
		
			681 B
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			35 lines
		
	
	
		
			681 B
		
	
	
	
		
			Go
		
	
	
	
	
	
package handler
 | 
						|
 | 
						|
import (
 | 
						|
	"nf-disk/internal/ndh"
 | 
						|
	"nf-disk/internal/s3"
 | 
						|
)
 | 
						|
 | 
						|
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
 | 
						|
	}
 | 
						|
 | 
						|
	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(), "连接失败")
 | 
						|
	}
 | 
						|
 | 
						|
	return c.Send200("test success")
 | 
						|
}
 |