This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func GetPresignedUrl(file string) (string, error) { | |
| req, _ := S3Client.GetObjectRequest(&s3.GetObjectInput{ | |
| Bucket: aws.String(config.S3.Bucket), | |
| Key: aws.String(file), | |
| ResponseContentDisposition: aws.String("attachment; filename=\"" + filepath.Base(file) + "\""), // to make sure the file is automatically downloaded | |
| }) | |
| return req.Presign(config.S3.PresignDuration) // time.Duration | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func GetRabbitMessageThenProcess() { | |
| defer log.RecoverWithTrace() | |
| _, ch := rabbit.ConnectMQ() | |
| _, err := ch.QueueDeclare( | |
| etc.TranscriptQueue, | |
| true, | |
| false, | |
| false, | |
| false, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func DeleteFromS3(dir string, filename string) error { | |
| log.Debug("Deleting media from amazon s3 server...") | |
| fileDestination := filename | |
| if len(dir) > 0 { | |
| fileDestination = dir + "/" + filename | |
| } | |
| svc := s3.New(session.Must(session.NewSession(&aws.Config{ | |
| Region: aws.String(config.S3.Region), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func RandomString(n int) string { | |
| src := rand.NewSource(time.Now().UnixNano()) | |
| const str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" | |
| var letterIdxBits int64 = 6 | |
| var letterIdxMask int64 = 1<<letterIdxBits - 1 | |
| letterIdxMax := 63 / letterIdxBits | |
| b := make([]byte, n) | |
| for i, cache, remain := n-1, src.Int63(), letterIdxMax; i >= 0; { | |
| if remain == 0 { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func PrintMemUsage() { | |
| var m runtime.MemStats | |
| runtime.ReadMemStats(&m) | |
| fmt.Printf("Alloc = %v MiB", m.Alloc / 1024 / 1024) | |
| fmt.Printf("\tTotalAlloc = %v MiB", m.TotalAlloc / 1024 / 1024) | |
| fmt.Printf("\tSys = %v MiB", m.Sys / 1024 / 1024) | |
| fmt.Printf("\tNumGC = %v\n", m.NumGC) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "fmt" | |
| "time" | |
| ) | |
| var data string | |
| func main() { |