Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
backendgo
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
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
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
nicolas.albanesi
backendgo
Commits
08b2158b
Commit
08b2158b
authored
2 years ago
by
nicolas.albanesi
Browse files
Options
Downloads
Patches
Plain Diff
Changed directory
parent
899866d8
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
.gitignore
+0
-1
0 additions, 1 deletion
.gitignore
Makefile
+7
-0
7 additions, 0 deletions
Makefile
main.go
+11
-9
11 additions, 9 deletions
main.go
with
18 additions
and
10 deletions
.gitignore
deleted
100644 → 0
+
0
−
1
View file @
899866d8
Makefile
This diff is collapsed.
Click to expand it.
Makefile
0 → 100644
+
7
−
0
View file @
08b2158b
all
:
display_backend
display_backend
:
main.go queue.c queue.h
CC
=
arm-linux-gcc
GOARCH
=
arm
GOOS
=
linux
CGO_ENABLED
=
1 go build
-o
$@
install
:
display_backend
sudo cp
display_backend ~/Documents/hepia/3eme_sem/embedded_linux/nfsroot/root/.
\ No newline at end of file
This diff is collapsed.
Click to expand it.
main.go
+
11
−
9
View file @
08b2158b
...
...
@@ -27,6 +27,7 @@ import (
"github.com/labstack/echo/v4/middleware"
)
const
SERVER_PATH
=
"/var/backendgo/"
func
main
()
{
...
...
@@ -37,7 +38,8 @@ func main() {
e
.
HideBanner
=
true
e
.
Use
(
middleware
.
BodyLimit
(
"1M"
))
os
.
Mkdir
(
"images"
,
os
.
ModePerm
)
os
.
Mkdir
(
SERVER_PATH
,
os
.
ModePerm
)
os
.
Mkdir
(
SERVER_PATH
+
"images"
,
os
.
ModePerm
)
e
.
GET
(
"/list"
,
listFiles
)
e
.
GET
(
"/download/:image"
,
downloadFile
)
...
...
@@ -57,7 +59,7 @@ func listFiles(c echo.Context) error {
var
buffer
bytes
.
Buffer
// Read the files in a directory
files
,
err
:=
ioutil
.
ReadDir
(
"images"
)
files
,
err
:=
ioutil
.
ReadDir
(
SERVER_PATH
+
"images"
)
if
err
!=
nil
{
log
.
Fatal
(
err
)
return
c
.
String
(
http
.
StatusInternalServerError
,
"Failed to get files list"
)
...
...
@@ -78,13 +80,13 @@ func deleteFile(c echo.Context) error {
filename
:=
c
.
Param
(
"image"
)
// Check if the file exists
_
,
err
:=
os
.
Stat
(
"images/"
+
filename
)
_
,
err
:=
os
.
Stat
(
SERVER_PATH
+
"images/"
+
filename
)
if
errors
.
Is
(
err
,
os
.
ErrNotExist
)
{
return
c
.
String
(
http
.
StatusNotFound
,
"File "
+
filename
+
" not found.
\n
"
)
}
// Remove the file
os
.
Remove
(
"images/"
+
filename
)
os
.
Remove
(
SERVER_PATH
+
"images/"
+
filename
)
return
c
.
String
(
http
.
StatusOK
,
filename
+
" Deleted
\n
"
)
}
...
...
@@ -106,7 +108,7 @@ func uploadFile(c echo.Context) error {
defer
src
.
Close
()
// Open destination file
dst
,
err
:=
os
.
Create
(
"images/"
+
file
.
Filename
)
dst
,
err
:=
os
.
Create
(
SERVER_PATH
+
"images/"
+
file
.
Filename
)
if
err
!=
nil
{
return
err
}
...
...
@@ -128,19 +130,19 @@ func downloadFile(c echo.Context) error {
filename
:=
c
.
Param
(
"image"
)
// Check if the file exists
_
,
err
:=
os
.
Stat
(
"images/"
+
filename
)
_
,
err
:=
os
.
Stat
(
SERVER_PATH
+
"images/"
+
filename
)
if
errors
.
Is
(
err
,
os
.
ErrNotExist
)
{
fmt
.
Println
(
err
.
Error
())
return
c
.
String
(
http
.
StatusNotFound
,
"File "
+
filename
+
" not found.
\n
"
)
}
return
c
.
File
(
"images/"
+
filename
)
return
c
.
File
(
SERVER_PATH
+
"images/"
+
filename
)
}
// Convert a file from any format to .ppm and scale it to 240x320
func
convertFile
(
filename
string
)
{
basename
:=
strings
.
Split
(
filename
,
"."
)[
0
]
cmd
:=
exec
.
Command
(
"convert"
,
"images/"
+
filename
,
"-scale"
,
"240x320!"
,
"images/"
+
basename
+
".ppm"
)
cmd
:=
exec
.
Command
(
"convert"
,
SERVER_PATH
+
"images/"
+
filename
,
"-scale"
,
"240x320!"
,
SERVER_PATH
+
"images/"
+
basename
+
".ppm"
)
err
:=
cmd
.
Run
()
if
err
!=
nil
{
...
...
@@ -151,7 +153,7 @@ func convertFile(filename string) {
func
displayImage
(
c
echo
.
Context
)
error
{
filename
:=
c
.
Param
(
"image"
)
// Check if the file exists
_
,
err
:=
os
.
Stat
(
"images/"
+
filename
)
_
,
err
:=
os
.
Stat
(
SERVER_PATH
+
"images/"
+
filename
)
if
errors
.
Is
(
err
,
os
.
ErrNotExist
)
&&
filename
!=
"break"
{
fmt
.
Println
(
err
.
Error
())
return
c
.
String
(
http
.
StatusNotFound
,
"File "
+
filename
+
" not found.
\n
"
)
...
...
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