36 lines
640 B
Go
36 lines
640 B
Go
package service
|
|
|
|
import (
|
|
"case-open-api/extend/aliyun"
|
|
"errors"
|
|
"net/http"
|
|
)
|
|
|
|
type PublicService struct {
|
|
}
|
|
|
|
// GetUserIP 获取用户ip
|
|
func (r *PublicService) GetUserIP(h *http.Request) string {
|
|
forwarded := h.Header.Get("X-FORWARDED-FOR")
|
|
if forwarded != "" {
|
|
return forwarded
|
|
}
|
|
return h.RemoteAddr
|
|
}
|
|
|
|
// GetOssSign 获取oss签名
|
|
func (a *PublicService) GetOssSign(scene int) (*aliyun.GetOssSignResponse, error) {
|
|
var dir string
|
|
if scene == 1 {
|
|
dir = dir + "user/avatar/"
|
|
}
|
|
|
|
if dir == "" {
|
|
return nil, errors.New("获取签名失败")
|
|
}
|
|
|
|
// 生成签名
|
|
ossSign, _ := aliyun.GetOssSign(dir)
|
|
return ossSign, nil
|
|
}
|