Commit 002729cd authored by Benjamin Rokseth's avatar Benjamin Rokseth
Browse files

Add minio host to configuration

parent 90d3e0d3
......@@ -27,6 +27,7 @@ var validBucketName = regexp.MustCompile(`^[A-Za-z0-9][A-Za-z0-9\.\-\_\:]{1,61}[
type server struct {
minio *minio.Client // handle to minio bucket storage
mhost string // address:port of minio server
mux *chi.Mux // HTTP Routes handled by server
}
......@@ -34,9 +35,10 @@ type serverStats struct {
Objects int `json:"objects"`
}
func newServer(m *minio.Client) *server {
func newServer(m *minio.Client, h string) *server {
s := server{
minio: m,
mhost: h,
}
s.mux = s.setupRouter()
return &s
......@@ -177,7 +179,7 @@ func (s *server) uploadImage(w http.ResponseWriter, r *http.Request) {
img := Image{
Name: fileName,
Bucket: bucket,
URL: fmt.Sprintf("http://localhost:9000/images/%s/%s", bucket, fileName),
URL: fmt.Sprintf("http://%s/%s/%s", s.mhost, bucket, fileName),
Size: fileLen,
FileType: filetype,
File: file,
......@@ -251,18 +253,18 @@ func isValidBucketName(b string) error {
func main() {
var (
minioURL = flag.String("murl", "localhost:9000", "Address of minio storage API")
minioHost = flag.String("mhost", "localhost:9000", "host address:port of minio storage API")
minioSsl = flag.Bool("mssl", false, "Use ssl with minio")
listen = flag.String("l", ":1666", "server listeing address")
)
flag.Parse()
rand.Seed(time.Now().UTC().UnixNano())
m, err := minio.New(*minioURL, os.Getenv("MINIO_ACCESS_KEY"), os.Getenv("MINIO_SECRET_KEY"), *minioSsl)
m, err := minio.New(*minioHost, os.Getenv("MINIO_ACCESS_KEY"), os.Getenv("MINIO_SECRET_KEY"), *minioSsl)
if err != nil {
log.Fatal(err)
}
log.Printf("starting minotaur server; listening at %s", *listen)
s := newServer(m)
s := newServer(m, *minioHost)
if err := s.ListenAndServe(*listen); err != nil {
log.Printf("listen and serve at %s failed: %v", *listen, err)
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment