This repository has been archived on 2020-09-27. You can view files and clone it, but cannot push or open issues or pull requests.
2017-04-07 11:56:28 +02:00
|
|
|
package runtime
|
2017-04-03 14:59:43 +02:00
|
|
|
|
2017-04-07 13:13:37 +02:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"net/http"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/genofire/hs_master-kss-monolith/lib/log"
|
|
|
|
)
|
|
|
|
|
|
|
|
var ProductURL string
|
|
|
|
|
|
|
|
type boolMicroServiceCache struct {
|
|
|
|
LastCheck time.Time
|
|
|
|
Value bool
|
|
|
|
}
|
|
|
|
|
|
|
|
var productExistCache map[int64]boolMicroServiceCache
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
productExistCache = make(map[int64]boolMicroServiceCache)
|
|
|
|
}
|
|
|
|
|
|
|
|
func ProductExists(id int64) (bool, error) {
|
|
|
|
if cache, ok := productExistCache[id]; ok {
|
|
|
|
return cache.Value, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
url := fmt.Sprintf(ProductURL, id)
|
|
|
|
log.Log.WithField("url", url).Info("exists product?")
|
|
|
|
res, err := http.Get(url)
|
|
|
|
if err != nil {
|
|
|
|
return false, err
|
|
|
|
}
|
|
|
|
productExistCache[id] = boolMicroServiceCache{
|
|
|
|
LastCheck: time.Now(),
|
|
|
|
Value: (res.StatusCode == http.StatusOK),
|
|
|
|
}
|
|
|
|
return productExistCache[id].Value, nil
|
2017-04-03 14:59:43 +02:00
|
|
|
}
|