package
0.0.0-20240228044302-56ad08b2fa1c
Repository: https://github.com/parsiya/parsia-code.git
Documentation: pkg.go.dev
# README
Gophercises - 18 - Image Transformer
Problem
Solution
- main.go: Main functionality.
- primitive/primitive.go: Primitive package.
Lessons Learned
HTML Input type File
We can use something like this
<input type="file"
id="upload" name="upload"
accept="image/jpeg,image/png" />
This only shows files of type jpeg
and png
. We can also do image/*
to show all images.
Int to Enum
Assuming we have this enum:
type EnumType int
const (
Zero Enum = iota
One
Two
Three
)
We can convert an int to this type with EnumType(2)
.
http.Request.FormFile
Gets the first file in the param (usually POST body).
file, header, err := r.FormFile("upload")
file
can be used like any other file (hint: implementsio.Reader
).header
has info about the file like name and size.
Response.PostForm is a map of url.Values
(map[string][]string
).