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
No related branches found
No related tags found
No related merge requests found
hash: 55e100566d38affe5f77251e4ea0b07d3ebcca1480b2931c9cdc0e606398f5f3
updated: 2018-03-16T16:44:29.59466378+01:00
hash: a4dc37eb677d9e7f409018b840b435b3dfbd02ad229d24f42ac942d2a07116b5
updated: 2018-03-16T23:16:25.752919561+01:00
imports:
- name: github.com/go-redis/redis
version: 877867d2845fbaf86798befe410b6ceb6f5c29a3
......@@ -11,9 +11,8 @@ imports:
- internal/proto
- internal/singleflight
- internal/util
- name: gopkg.in/gographics/imagick.v2
version: 589a8ef16fd4f08a29ad26afe5c33fb5673e4efc
- name: github.com/lib/pq
version: 88edab0803230a3898347e77b474f8c1820a1f20
subpackages:
- imagick
- imagick/types
- oid
testImports: []
......@@ -2,3 +2,4 @@ package: github.com/justjanne/imghost-frontend
import:
- package: github.com/go-redis/redis
version: ^6.10.2
- package: github.com/lib/pq
File added
......@@ -87,24 +87,33 @@ func returnResult(writer http.ResponseWriter, result Result) error {
return nil
}
func main() {
config := Config{}
func printHeaders(r *http.Request) {
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)
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")
func main() {
config := NewConfigFromEnv()
client := redis.NewClient(&redis.Options{
Addr: config.Redis.Address,
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)
file, _, err := r.FormFile("file")
image, err := createImage(&config, file)
......@@ -166,13 +175,16 @@ func main() {
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.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
printHeaders(r)
staticServer.ServeHTTP(w, r)
})
err := http.ListenAndServe(":8080", nil)
if err != nil {
......
<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><a href="/upload/">Upload images</a></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
a(href="/upload/").
Upload images
\ 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
import (
"os"
"encoding/json"
)
type Image struct {
Id string `json:"id"`
MimeType string `json:"mime_type"`
......@@ -37,12 +42,35 @@ type RedisConfig struct {
Password string
}
type DatabaseConfig struct {
Format string
Url string
}
type Config struct {
Sizes []SizeDefinition
Quality Quality
SourceFolder string
TargetFolder string
Redis RedisConfig
Database DatabaseConfig
ImageQueue 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