Skip to content
Snippets Groups Projects
Commit 1452cfff authored by Janne Mareike Koschinski's avatar Janne Mareike Koschinski
Browse files

Updated minor changes

parent a563d9b9
Branches
Tags
No related merge requests found
hash: 55e100566d38affe5f77251e4ea0b07d3ebcca1480b2931c9cdc0e606398f5f3 hash: a4dc37eb677d9e7f409018b840b435b3dfbd02ad229d24f42ac942d2a07116b5
updated: 2018-03-16T16:44:29.59466378+01:00 updated: 2018-03-16T23:16:25.752919561+01:00
imports: imports:
- name: github.com/go-redis/redis - name: github.com/go-redis/redis
version: 877867d2845fbaf86798befe410b6ceb6f5c29a3 version: 877867d2845fbaf86798befe410b6ceb6f5c29a3
...@@ -11,9 +11,8 @@ imports: ...@@ -11,9 +11,8 @@ imports:
- internal/proto - internal/proto
- internal/singleflight - internal/singleflight
- internal/util - internal/util
- name: gopkg.in/gographics/imagick.v2 - name: github.com/lib/pq
version: 589a8ef16fd4f08a29ad26afe5c33fb5673e4efc version: 88edab0803230a3898347e77b474f8c1820a1f20
subpackages: subpackages:
- imagick - oid
- imagick/types
testImports: [] testImports: []
...@@ -2,3 +2,4 @@ package: github.com/justjanne/imghost-frontend ...@@ -2,3 +2,4 @@ package: github.com/justjanne/imghost-frontend
import: import:
- package: github.com/go-redis/redis - package: github.com/go-redis/redis
version: ^6.10.2 version: ^6.10.2
- package: github.com/lib/pq
File added
...@@ -87,24 +87,33 @@ func returnResult(writer http.ResponseWriter, result Result) error { ...@@ -87,24 +87,33 @@ func returnResult(writer http.ResponseWriter, result Result) error {
return nil return nil
} }
func main() { func printHeaders(r *http.Request) {
config := Config{} fmt.Println(r.URL)
for key, value := range r.Header {
fmt.Printf(" %s: %s\n", key, value)
}
}
json.Unmarshal([]byte(os.Getenv("IK8R_SIZES")), &config.Sizes) func main() {
json.Unmarshal([]byte(os.Getenv("IK8R_QUALITY")), &config.Quality) config := NewConfigFromEnv()
config.SourceFolder = os.Getenv("IK8R_SOURCE_FOLDER")
config.TargetFolder = os.Getenv("IK8R_TARGET_FOLDER")
config.Redis.Address = os.Getenv("IK8R_REDIS_ADDRESS")
config.Redis.Password = os.Getenv("IK8R_REDIS_PASSWORD")
config.ImageQueue = os.Getenv("IK8R_REDIS_IMAGE_QUEUE")
config.ResultChannel = os.Getenv("IK8R_REDIS_RESULT_CHANNEL")
client := redis.NewClient(&redis.Options{ client := redis.NewClient(&redis.Options{
Addr: config.Redis.Address, Addr: config.Redis.Address,
Password: config.Redis.Password, Password: config.Redis.Password,
}) })
http.HandleFunc("/upload", func(w http.ResponseWriter, r *http.Request) { //db, err := sql.Open(config.Database.Format, config.Database.Url)
//if err != nil {
//panic(err)
//}
staticServer := http.FileServer(http.Dir("static/"))
imageServer := http.FileServer(http.Dir(config.TargetFolder))
http.HandleFunc("/upload/", func(w http.ResponseWriter, r *http.Request) {
printHeaders(r)
if r.Method == "POST" {
r.ParseMultipartForm(32 << 20) r.ParseMultipartForm(32 << 20)
file, _, err := r.FormFile("file") file, _, err := r.FormFile("file")
image, err := createImage(&config, file) image, err := createImage(&config, file)
...@@ -166,13 +175,16 @@ func main() { ...@@ -166,13 +175,16 @@ func main() {
return return
} }
} }
} else {
staticServer.ServeHTTP(w, r)
}
}) })
fs := http.FileServer(http.Dir("static/"))
http.Handle("/", fs)
imageServer := http.FileServer(http.Dir(config.TargetFolder))
http.Handle("/i/", http.StripPrefix("/i/", imageServer)) http.Handle("/i/", http.StripPrefix("/i/", imageServer))
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
printHeaders(r)
staticServer.ServeHTTP(w, r)
})
err := http.ListenAndServe(":8080", nil) err := http.ListenAndServe(":8080", nil)
if err != nil { if err != nil {
......
<html><form action="/upload" method="POST" enctype="multipart/form-data"><input type="file" name="file"/><input type="submit"/></form></html> <html><a href="/upload/">Upload images</a></html>
\ No newline at end of file \ No newline at end of file
html html
form(action="/upload", method="POST" enctype="multipart/form-data") a(href="/upload/").
input(type="file", name="file") Upload images
input(type="submit") \ No newline at end of file
\ No newline at end of file
<html><form action="/upload/" method="POST" enctype="multipart/form-data"><input type="file" name="file"/><input type="submit"/></form></html>
\ No newline at end of file
html
form(action="/upload/", method="POST" enctype="multipart/form-data")
input(type="file", name="file")
input(type="submit")
\ No newline at end of file
package main package main
import (
"os"
"encoding/json"
)
type Image struct { type Image struct {
Id string `json:"id"` Id string `json:"id"`
MimeType string `json:"mime_type"` MimeType string `json:"mime_type"`
...@@ -37,12 +42,35 @@ type RedisConfig struct { ...@@ -37,12 +42,35 @@ type RedisConfig struct {
Password string Password string
} }
type DatabaseConfig struct {
Format string
Url string
}
type Config struct { type Config struct {
Sizes []SizeDefinition Sizes []SizeDefinition
Quality Quality Quality Quality
SourceFolder string SourceFolder string
TargetFolder string TargetFolder string
Redis RedisConfig Redis RedisConfig
Database DatabaseConfig
ImageQueue string ImageQueue string
ResultChannel string ResultChannel string
} }
func NewConfigFromEnv() Config {
config := Config{}
json.Unmarshal([]byte(os.Getenv("IK8R_SIZES")), &config.Sizes)
json.Unmarshal([]byte(os.Getenv("IK8R_QUALITY")), &config.Quality)
config.SourceFolder = os.Getenv("IK8R_SOURCE_FOLDER")
config.TargetFolder = os.Getenv("IK8R_TARGET_FOLDER")
config.Redis.Address = os.Getenv("IK8R_REDIS_ADDRESS")
config.Redis.Password = os.Getenv("IK8R_REDIS_PASSWORD")
config.ImageQueue = os.Getenv("IK8R_REDIS_IMAGE_QUEUE")
config.ResultChannel = os.Getenv("IK8R_REDIS_RESULT_CHANNEL")
config.Database.Format = os.Getenv("IK8R_DATABASE_TYPE")
config.Database.Url = os.Getenv("IK8R_DATABASE_URL")
return config
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment