✨ optimized image list interface
This commit is contained in:
7
common/constant/bucket_name.go
Normal file
7
common/constant/bucket_name.go
Normal file
@@ -0,0 +1,7 @@
|
||||
package constant
|
||||
|
||||
const (
|
||||
FaceBucketName = "schisandra-face-samples"
|
||||
CommentImagesBucketName = "schisandra-comment-images"
|
||||
ThumbnailBucketName = "schisandra-thumbnail-images"
|
||||
)
|
6
common/constant/mq_topic.go
Normal file
6
common/constant/mq_topic.go
Normal file
@@ -0,0 +1,6 @@
|
||||
package constant
|
||||
|
||||
const (
|
||||
MQTopicImageProcess = "image-process-topic"
|
||||
MQTopicCommentLike = "comment-like-topic"
|
||||
)
|
@@ -1,6 +0,0 @@
|
||||
package constant
|
||||
|
||||
const (
|
||||
FaceBucketName = "faces"
|
||||
CommentImagesBucketName = "comments"
|
||||
)
|
@@ -22,7 +22,7 @@ const (
|
||||
|
||||
const (
|
||||
ImageListPrefix = "image:list:"
|
||||
ImageListMetaPrefix = "image:meta:"
|
||||
ImageRecentPrefix = "image:recent:"
|
||||
ImageFaceListPrefix = "image:face:list:"
|
||||
ImageFaceListPrefix = "image:faces:"
|
||||
ImageSinglePrefix = "image:single:"
|
||||
)
|
||||
|
27
common/nsqx/docker-compose.yml
Normal file
27
common/nsqx/docker-compose.yml
Normal file
@@ -0,0 +1,27 @@
|
||||
version: '3'
|
||||
services:
|
||||
nsqlookupd:
|
||||
image: nsqio/nsq
|
||||
command: /nsqlookupd
|
||||
ports:
|
||||
- "4160:4160"
|
||||
- "4161:4161"
|
||||
|
||||
nsqd:
|
||||
image: nsqio/nsq
|
||||
command: /nsqd --mem-queue-size=0 -data-path=/data --broadcast-address=1.95.0.111 --lookupd-tcp-address=nsqlookupd:4160
|
||||
depends_on:
|
||||
- nsqlookupd
|
||||
volumes:
|
||||
- ./nsqd/data:/data
|
||||
ports:
|
||||
- "4150:4150"
|
||||
- "4151:4151"
|
||||
|
||||
nsqadmin:
|
||||
image: nsqio/nsq
|
||||
command: /nsqadmin --lookupd-http-address=nsqlookupd:4161
|
||||
depends_on:
|
||||
- nsqlookupd
|
||||
ports:
|
||||
- "4171:4171"
|
28
common/nsqx/nsq.go
Normal file
28
common/nsqx/nsq.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package nsqx
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/nsqio/go-nsq"
|
||||
"time"
|
||||
)
|
||||
|
||||
func NewNsqProducer(url string) *nsq.Producer {
|
||||
producer, err := nsq.NewProducer(url, nsq.NewConfig())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
producer.SetLoggerLevel(nsq.LogLevelError)
|
||||
return producer
|
||||
}
|
||||
|
||||
func NewNSQConsumer(topic string) *nsq.Consumer {
|
||||
config := nsq.NewConfig()
|
||||
config.LookupdPollInterval = 15 * time.Second
|
||||
consumer, err := nsq.NewConsumer(topic, "channel", config)
|
||||
if err != nil {
|
||||
fmt.Printf("InitNSQ consumer error: %v\n", err)
|
||||
return nil
|
||||
}
|
||||
consumer.SetLoggerLevel(nsq.LogLevelError)
|
||||
return consumer
|
||||
}
|
41
common/utils/bytes_to_file.go
Normal file
41
common/utils/bytes_to_file.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"mime/multipart"
|
||||
)
|
||||
|
||||
// ByteReader 实现了 multipart.File 接口
|
||||
type ByteReader struct {
|
||||
data []byte
|
||||
index int
|
||||
}
|
||||
|
||||
func (r *ByteReader) Read(p []byte) (n int, err error) {
|
||||
if r.index >= len(r.data) {
|
||||
return 0, io.EOF
|
||||
}
|
||||
n = copy(p, r.data[r.index:])
|
||||
r.index += n
|
||||
return n, nil
|
||||
}
|
||||
|
||||
func (r *ByteReader) Seek(offset int64, whence int) (int64, error) {
|
||||
return 0, fmt.Errorf("Seek not implemented")
|
||||
}
|
||||
|
||||
func (r *ByteReader) ReadAt(p []byte, off int64) (n int, err error) {
|
||||
return 0, fmt.Errorf("ReadAt not implemented")
|
||||
}
|
||||
|
||||
// 实现 Close 方法,符合 multipart.File 接口
|
||||
func (r *ByteReader) Close() error {
|
||||
// 这里没有实际需要清理的资源,但必须实现 Close 方法
|
||||
return nil
|
||||
}
|
||||
|
||||
// ToMultipartFile 将 []byte 转换为 multipart.File
|
||||
func ToMultipartFile(data []byte) multipart.File {
|
||||
return &ByteReader{data: data}
|
||||
}
|
Reference in New Issue
Block a user