Exemple #1
0
func PrintPanicStack() {
	if x := recover(); x != nil {
		log.Errorf("%v", x)
		for i := 0; i < 10; i++ {
			funcName, file, line, ok := runtime.Caller(i)
			if ok {
				log.Errorf("Panic %v:[func:%v,file:%v,line:%v]\n", i, runtime.FuncForPC(funcName).Name(), file, line)
			}
		}
	}
}
Exemple #2
0
func (c *Cache) Delete(key string) {
	params := &s3.DeleteObjectInput{
		Bucket: aws.String(c.Bucket),
		Key:    aws.String(CacheKeyToObjectKey(key)),
	}

	_, err := c.S3.DeleteObject(params)

	if err != nil {
		log.Errorf("Error deleting s3 object: %v", err.Error())
		return
	}
}
Exemple #3
0
func (c *Cache) Set(key string, resp []byte) {
	params := &s3.PutObjectInput{
		Bucket: aws.String(c.Bucket),
		Key:    aws.String(CacheKeyToObjectKey(key)),
		Body:   bytes.NewReader(resp),
	}

	_, err := c.S3.PutObject(params)

	if err != nil {
		log.Errorf("Error Putting s3 object: %v", err.Error())
		return
	}
}
Exemple #4
0
func (c *Cache) Get(key string) (resp []byte, ok bool) {
	params := &s3.GetObjectInput{
		Bucket: aws.String(c.Bucket),
		Key:    aws.String(CacheKeyToObjectKey(key)),
	}

	object, err := c.S3.GetObject(params)

	if err != nil {
		log.Debugf("Error getting s3 object: %v", err)
		return []byte{}, false
	}

	data, err := ioutil.ReadAll(object.Body)
	if err != nil {
		log.Errorf("Error reading s3 object: %v", err.Error())
		return []byte{}, false
	}
	return data, err == nil
}