84 lines
1.5 KiB
Go
84 lines
1.5 KiB
Go
package apikey
|
|
|
|
import (
|
|
"encoding/json"
|
|
"git.loafle.net/overflow/commons_go/model/timestamp"
|
|
//"git.loafle.net/overflow/overflow_service/proxy"
|
|
//"log"
|
|
"git.loafle.net/overflow/overflow_service/proxy/utils"
|
|
)
|
|
|
|
type ApiKeyService struct {
|
|
|
|
}
|
|
|
|
type ApiKey struct {
|
|
Id json.Number `json:"id,Number,omitempty"`
|
|
Apikey string `json:"apiKey,omitempty"`
|
|
CreateDAte timestamp.Timestamp`json:"createDate,omitempty"`
|
|
HostName string `json:"hostName,omitempty"`
|
|
}
|
|
|
|
|
|
func NewApiKeyService() *ApiKeyService {
|
|
return &ApiKeyService{}
|
|
}
|
|
|
|
|
|
func(k *ApiKeyService)SaveApikey(key *ApiKey) (string, error) {
|
|
|
|
|
|
//bytes, err := json.Marshal(key)
|
|
//
|
|
//if err != nil {
|
|
// return "", err
|
|
//}
|
|
//
|
|
//m := make(map[string]string)
|
|
//
|
|
//m["com.loafle.overflow.keystore.model.Apikey"] = string(bytes)
|
|
//
|
|
//out := proxy.InvokeDB("apiKey", "create", m)
|
|
//
|
|
//log.Print(out)
|
|
|
|
out, err := utils.InvokeDBByModel("apiKey", "create", key, "com.loafle.overflow.keystore.model.Apikey")
|
|
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
return out, nil
|
|
|
|
}
|
|
|
|
func(k *ApiKeyService)CheckApikey(apikey string) (bool, error) {
|
|
|
|
ak := ApiKey{
|
|
Apikey:apikey,
|
|
}
|
|
|
|
//bytes, err := json.Marshal(ak)
|
|
//
|
|
//if err != nil {
|
|
// return false, err
|
|
//}
|
|
//
|
|
//m := make(map[string]string)
|
|
//
|
|
//m["com.loafle.overflow.keystore.model.Apikey"] = string(bytes)
|
|
//
|
|
//out := proxy.InvokeDB("apiKey", "findByApiKey", m)
|
|
//
|
|
//log.Print(out)
|
|
|
|
_, err := utils.InvokeDB("apiKey", "findByApiKey", ak)
|
|
|
|
if err != nil {
|
|
return false, err
|
|
}
|
|
|
|
return true, nil
|
|
|
|
|
|
} |