Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
imghost
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Janne Mareike Koschinski
imghost
Commits
c95ca769
Commit
c95ca769
authored
7 years ago
by
Janne Mareike Koschinski
Browse files
Options
Downloads
Patches
Plain Diff
Improved templating
parent
549835e3
No related branches found
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
main.go
+26
-43
26 additions, 43 deletions
main.go
templates/upload.html
+15
-0
15 additions, 0 deletions
templates/upload.html
templates/upload_failure.html
+0
-24
0 additions, 24 deletions
templates/upload_failure.html
templates/upload_success.html
+0
-21
0 additions, 21 deletions
templates/upload_success.html
with
41 additions
and
88 deletions
main.go
+
26
−
43
View file @
c95ca769
...
@@ -95,14 +95,8 @@ type UploadData struct {
...
@@ -95,14 +95,8 @@ type UploadData struct {
Result
Result
Result
Result
}
}
func
returnResult
(
w
http
.
ResponseWriter
,
data
UploadData
)
error
{
func
returnResult
(
w
http
.
ResponseWriter
,
templateName
string
,
data
interface
{})
error
{
var
pageTemplate
*
template
.
Template
pageTemplate
,
err
:=
template
.
New
(
templateName
)
.
ParseFiles
(
fmt
.
Sprintf
(
"templates/%s"
,
templateName
))
var
err
error
if
data
.
Result
.
Success
{
pageTemplate
,
err
=
template
.
New
(
"upload_success.html"
)
.
ParseFiles
(
"templates/upload_success.html"
)
}
else
{
pageTemplate
,
err
=
template
.
New
(
"upload_failure.html"
)
.
ParseFiles
(
"templates/upload_failure.html"
)
}
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
...
@@ -139,7 +133,7 @@ func main() {
...
@@ -139,7 +133,7 @@ func main() {
file
,
header
,
err
:=
r
.
FormFile
(
"file"
)
file
,
header
,
err
:=
r
.
FormFile
(
"file"
)
image
,
err
:=
createImage
(
&
config
,
file
,
header
)
image
,
err
:=
createImage
(
&
config
,
file
,
header
)
if
err
!=
nil
{
if
err
!=
nil
{
returnResult
(
w
,
UploadData
{
returnResult
(
w
,
"upload.html"
,
UploadData
{
user
,
user
,
Result
{
Result
{
Id
:
""
,
Id
:
""
,
...
@@ -159,14 +153,16 @@ func main() {
...
@@ -159,14 +153,16 @@ func main() {
data
,
err
:=
json
.
Marshal
(
image
)
data
,
err
:=
json
.
Marshal
(
image
)
if
err
!=
nil
{
if
err
!=
nil
{
returnResult
(
w
,
UploadData
{
if
err
=
returnResult
(
w
,
"upload.html"
,
UploadData
{
user
,
user
,
Result
{
Result
{
Id
:
image
.
Id
,
Id
:
image
.
Id
,
Success
:
false
,
Success
:
false
,
Errors
:
[]
string
{
err
.
Error
()},
Errors
:
[]
string
{
err
.
Error
()},
},
},
})
});
err
!=
nil
{
panic
(
err
)
}
return
return
}
}
...
@@ -179,28 +175,32 @@ func main() {
...
@@ -179,28 +175,32 @@ func main() {
for
waiting
{
for
waiting
{
message
,
err
:=
pubsub
.
ReceiveMessage
()
message
,
err
:=
pubsub
.
ReceiveMessage
()
if
err
!=
nil
{
if
err
!=
nil
{
returnResult
(
w
,
UploadData
{
if
err
=
returnResult
(
w
,
"upload.html"
,
UploadData
{
user
,
user
,
Result
{
Result
{
Id
:
image
.
Id
,
Id
:
image
.
Id
,
Success
:
false
,
Success
:
false
,
Errors
:
[]
string
{
err
.
Error
()},
Errors
:
[]
string
{
err
.
Error
()},
},
},
})
});
err
!=
nil
{
panic
(
err
)
}
return
return
}
}
result
:=
Result
{}
result
:=
Result
{}
err
=
json
.
Unmarshal
([]
byte
(
message
.
Payload
),
&
result
)
err
=
json
.
Unmarshal
([]
byte
(
message
.
Payload
),
&
result
)
if
err
!=
nil
{
if
err
!=
nil
{
returnResult
(
w
,
UploadData
{
if
err
=
returnResult
(
w
,
"upload.html"
,
UploadData
{
user
,
user
,
Result
{
Result
{
Id
:
image
.
Id
,
Id
:
image
.
Id
,
Success
:
false
,
Success
:
false
,
Errors
:
[]
string
{
err
.
Error
()},
Errors
:
[]
string
{
err
.
Error
()},
},
},
})
});
err
!=
nil
{
panic
(
err
)
}
return
return
}
}
...
@@ -209,28 +209,21 @@ func main() {
...
@@ -209,28 +209,21 @@ func main() {
if
result
.
Id
==
image
.
Id
{
if
result
.
Id
==
image
.
Id
{
waiting
=
false
waiting
=
false
returnResult
(
w
,
UploadData
{
if
err
=
returnResult
(
w
,
"upload.html"
,
UploadData
{
user
,
user
,
result
,
result
,
})
});
err
!=
nil
{
panic
(
err
)
}
return
return
}
}
}
}
}
else
{
}
else
{
user
:=
parseUser
(
r
)
user
:=
parseUser
(
r
)
if
err
=
returnResult
(
w
,
"upload.html"
,
UploadData
{
type
UploadData
struct
{
User
UserInfo
}
tmpl
,
err
:=
template
.
New
(
"upload.html"
)
.
ParseFiles
(
"templates/upload.html"
)
if
err
!=
nil
{
panic
(
err
)
}
err
=
tmpl
.
Execute
(
w
,
UploadData
{
user
,
user
,
})
Result
{},
if
err
!=
nil
{
});
err
!=
nil
{
panic
(
err
)
panic
(
err
)
}
}
}
}
...
@@ -269,15 +262,10 @@ func main() {
...
@@ -269,15 +262,10 @@ func main() {
images
=
append
(
images
,
info
)
images
=
append
(
images
,
info
)
}
}
pageTemplate
,
err
:=
template
.
New
(
"me_images.html"
)
.
ParseFiles
(
"templates/me_images.html"
)
if
err
=
returnResult
(
w
,
"me_images.html"
,
ImageListData
{
if
err
!=
nil
{
panic
(
err
)
}
err
=
pageTemplate
.
Execute
(
w
,
ImageListData
{
user
,
user
,
images
,
images
,
})
});
err
!=
nil
{
if
err
!=
nil
{
panic
(
err
)
panic
(
err
)
}
}
})
})
...
@@ -291,14 +279,9 @@ func main() {
...
@@ -291,14 +279,9 @@ func main() {
User
UserInfo
User
UserInfo
}
}
tmpl
,
err
:=
template
.
New
(
"index.html"
)
.
ParseFiles
(
"templates/index.html"
)
if
err
=
returnResult
(
w
,
"index.html"
,
IndexData
{
if
err
!=
nil
{
panic
(
err
)
}
err
=
tmpl
.
Execute
(
w
,
IndexData
{
user
,
user
,
})
});
err
!=
nil
{
if
err
!=
nil
{
panic
(
err
)
panic
(
err
)
}
}
})
})
...
...
This diff is collapsed.
Click to expand it.
templates/upload.html
+
15
−
0
View file @
c95ca769
...
@@ -11,6 +11,21 @@
...
@@ -11,6 +11,21 @@
<a
href=
"/upload"
>
Upload
</a>
<a
href=
"/upload"
>
Upload
</a>
</p>
</p>
{{ if .Result.Id }}
{{ if .Result.Success }}
<div
class=
"info success"
>
<h2>
Upload of {{ .Result.Id }} finished.
<a
href=
"/i/{{ .Result.Id }}"
>
View
</a>
.
</h2>
</div>
{{ else }}
<div
class=
"info error"
>
<h2>
Upload of {{ .Result.Id }} failed.
</h2>
{{ range .Result.Errors }}
<pre>
{{ . }}
</pre>
{{ end }}
</div>
{{ end }}
{{ end }}
<form
action=
"/upload/"
method=
"POST"
enctype=
"multipart/form-data"
>
<form
action=
"/upload/"
method=
"POST"
enctype=
"multipart/form-data"
>
<input
type=
"file"
name=
"file"
/>
<input
type=
"file"
name=
"file"
/>
<input
type=
"submit"
/>
<input
type=
"submit"
/>
...
...
This diff is collapsed.
Click to expand it.
templates/upload_failure.html
deleted
100644 → 0
+
0
−
24
View file @
549835e3
<!DOCTYPE html>
<meta
charset=
"utf-8"
>
<title>
Upload | ik8r
</title>
<link
href=
"/assets/css/style.css"
rel=
"stylesheet"
>
<link
href=
"/assets/css/fonts.css"
rel=
"stylesheet"
>
<p>
Welcome, {{ .User.Name }}
</p>
<p>
<a
href=
"/me/images"
>
My Images
</a>
|
<a
href=
"/me/albums"
>
My Albums
</a>
|
<a
href=
"/upload"
>
Upload
</a>
</p>
<div
class=
"info error"
>
<h2>
Upload of {{ .Result.Id }} failed.
</h2>
{{ range .Result.Errors }}
<pre>
{{ . }}
</pre>
{{ end }}
</div>
<form
action=
"/upload/"
method=
"POST"
enctype=
"multipart/form-data"
>
<input
type=
"file"
name=
"file"
/>
<input
type=
"submit"
/>
</form>
\ No newline at end of file
This diff is collapsed.
Click to expand it.
templates/upload_success.html
deleted
100644 → 0
+
0
−
21
View file @
549835e3
<!DOCTYPE html>
<meta
charset=
"utf-8"
>
<title>
Upload | ik8r
</title>
<link
href=
"/assets/css/style.css"
rel=
"stylesheet"
>
<link
href=
"/assets/css/fonts.css"
rel=
"stylesheet"
>
<p>
Welcome, {{ .User.Name }}
</p>
<p>
<a
href=
"/me/images"
>
My Images
</a>
|
<a
href=
"/me/albums"
>
My Albums
</a>
|
<a
href=
"/upload"
>
Upload
</a>
</p>
<div
class=
"info success"
>
<h2>
Upload of {{ .Result.Id }} finished.
<a
href=
"/i/{{ .Result.Id }}"
>
View
</a>
.
</h2>
</div>
<form
action=
"/upload/"
method=
"POST"
enctype=
"multipart/form-data"
>
<input
type=
"file"
name=
"file"
/>
<input
type=
"submit"
/>
</form>
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment