Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
canifa_note
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Vũ Hoàng Anh
canifa_note
Commits
3874523e
Commit
3874523e
authored
Feb 18, 2022
by
email
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chore: format server code
parent
6f3663cd
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
36 additions
and
12 deletions
+36
-12
memo.go
api/memo.go
+3
-3
profile.go
bin/server/cmd/profile.go
+16
-9
auth.go
server/auth.go
+2
-0
memo.go
server/memo.go
+4
-0
resource.go
server/resource.go
+2
-0
shortcut.go
server/shortcut.go
+4
-0
user.go
server/user.go
+3
-0
webhook.go
server/webhook.go
+2
-0
No files found.
api/memo.go
View file @
3874523e
...
...
@@ -11,8 +11,9 @@ type Memo struct {
}
type
MemoCreate
struct
{
Content
string
`json:"content"`
CreatorId
int
Content
string
`json:"content"`
}
type
MemoPatch
struct
{
...
...
@@ -29,8 +30,7 @@ type MemoFind struct {
}
type
MemoDelete
struct
{
Id
*
int
`json:"id"`
CreatorId
*
int
Id
*
int
`json:"id"`
}
type
MemoService
interface
{
...
...
bin/server/cmd/profile.go
View file @
3874523e
package
cmd
import
(
"flag"
"fmt"
"os"
"path/filepath"
"strconv"
"strings"
)
...
...
@@ -40,22 +40,29 @@ func checkDSN(dataDir string) (string, error) {
// GetDevProfile will return a profile for dev.
func
GetProfile
()
Profile
{
mode
:=
flag
.
String
(
"mode"
,
"dev"
,
""
)
port
:=
flag
.
Int
(
"port"
,
8080
,
""
)
data
:=
flag
.
String
(
"data"
,
""
,
""
)
flag
.
Parse
()
mode
:=
os
.
Getenv
(
"mode"
)
if
mode
!=
"dev"
&&
mode
!=
"release"
{
mode
=
"dev"
}
port
,
err
:=
strconv
.
Atoi
(
os
.
Getenv
(
"port"
))
if
err
!=
nil
{
port
=
8080
}
data
:=
os
.
Getenv
(
"data"
)
dataDir
,
err
:=
checkDSN
(
*
data
)
dataDir
,
err
:=
checkDSN
(
data
)
if
err
!=
nil
{
fmt
.
Printf
(
"Failed to check dsn: %s, err: %+v
\n
"
,
dataDir
,
err
)
os
.
Exit
(
1
)
}
dsn
:=
fmt
.
Sprintf
(
"file:%s/memos_%s.db"
,
dataDir
,
*
mode
)
dsn
:=
fmt
.
Sprintf
(
"file:%s/memos_%s.db"
,
dataDir
,
mode
)
return
Profile
{
mode
:
*
mode
,
port
:
*
port
,
mode
:
mode
,
port
:
port
,
dsn
:
dsn
,
}
}
server/auth.go
View file @
3874523e
...
...
@@ -47,6 +47,7 @@ func (s *Server) registerAuthRoutes(g *echo.Group) {
return
nil
})
g
.
POST
(
"/auth/logout"
,
func
(
c
echo
.
Context
)
error
{
err
:=
removeUserSession
(
c
)
if
err
!=
nil
{
...
...
@@ -56,6 +57,7 @@ func (s *Server) registerAuthRoutes(g *echo.Group) {
c
.
Response
()
.
WriteHeader
(
http
.
StatusOK
)
return
nil
})
g
.
POST
(
"/auth/signup"
,
func
(
c
echo
.
Context
)
error
{
signup
:=
&
api
.
Signup
{}
if
err
:=
json
.
NewDecoder
(
c
.
Request
()
.
Body
)
.
Decode
(
signup
);
err
!=
nil
{
...
...
server/memo.go
View file @
3874523e
...
...
@@ -33,6 +33,7 @@ func (s *Server) registerMemoRoutes(g *echo.Group) {
return
nil
})
g
.
PATCH
(
"/memo/:memoId"
,
func
(
c
echo
.
Context
)
error
{
memoId
,
err
:=
strconv
.
Atoi
(
c
.
Param
(
"memoId"
))
if
err
!=
nil
{
...
...
@@ -58,6 +59,7 @@ func (s *Server) registerMemoRoutes(g *echo.Group) {
return
nil
})
g
.
GET
(
"/memo"
,
func
(
c
echo
.
Context
)
error
{
userId
:=
c
.
Get
(
getUserIdContextKey
())
.
(
int
)
memoFind
:=
&
api
.
MemoFind
{
...
...
@@ -86,6 +88,7 @@ func (s *Server) registerMemoRoutes(g *echo.Group) {
return
nil
})
g
.
GET
(
"/memo/:memoId"
,
func
(
c
echo
.
Context
)
error
{
memoId
,
err
:=
strconv
.
Atoi
(
c
.
Param
(
"memoId"
))
if
err
!=
nil
{
...
...
@@ -111,6 +114,7 @@ func (s *Server) registerMemoRoutes(g *echo.Group) {
return
nil
})
g
.
DELETE
(
"/memo/:memoId"
,
func
(
c
echo
.
Context
)
error
{
memoId
,
err
:=
strconv
.
Atoi
(
c
.
Param
(
"memoId"
))
if
err
!=
nil
{
...
...
server/resource.go
View file @
3874523e
...
...
@@ -59,6 +59,7 @@ func (s *Server) registerResourceRoutes(g *echo.Group) {
return
nil
})
g
.
GET
(
"/resource"
,
func
(
c
echo
.
Context
)
error
{
userId
:=
c
.
Get
(
getUserIdContextKey
())
.
(
int
)
resourceFind
:=
&
api
.
ResourceFind
{
...
...
@@ -76,6 +77,7 @@ func (s *Server) registerResourceRoutes(g *echo.Group) {
return
nil
})
g
.
DELETE
(
"/resource/:resourceId"
,
func
(
c
echo
.
Context
)
error
{
resourceId
,
err
:=
strconv
.
Atoi
(
c
.
Param
(
"resourceId"
))
if
err
!=
nil
{
...
...
server/shortcut.go
View file @
3874523e
...
...
@@ -32,6 +32,7 @@ func (s *Server) registerShortcutRoutes(g *echo.Group) {
return
nil
})
g
.
PATCH
(
"/shortcut/:shortcutId"
,
func
(
c
echo
.
Context
)
error
{
shortcutId
,
err
:=
strconv
.
Atoi
(
c
.
Param
(
"shortcutId"
))
if
err
!=
nil
{
...
...
@@ -57,6 +58,7 @@ func (s *Server) registerShortcutRoutes(g *echo.Group) {
return
nil
})
g
.
GET
(
"/shortcut"
,
func
(
c
echo
.
Context
)
error
{
userId
:=
c
.
Get
(
getUserIdContextKey
())
.
(
int
)
shortcutFind
:=
&
api
.
ShortcutFind
{
...
...
@@ -74,6 +76,7 @@ func (s *Server) registerShortcutRoutes(g *echo.Group) {
return
nil
})
g
.
GET
(
"/shortcut/:shortcutId"
,
func
(
c
echo
.
Context
)
error
{
shortcutId
,
err
:=
strconv
.
Atoi
(
c
.
Param
(
"shortcutId"
))
if
err
!=
nil
{
...
...
@@ -95,6 +98,7 @@ func (s *Server) registerShortcutRoutes(g *echo.Group) {
return
nil
})
g
.
DELETE
(
"/shortcut/:shortcutId"
,
func
(
c
echo
.
Context
)
error
{
shortcutId
,
err
:=
strconv
.
Atoi
(
c
.
Param
(
"shortcutId"
))
if
err
!=
nil
{
...
...
server/user.go
View file @
3874523e
...
...
@@ -34,6 +34,7 @@ func (s *Server) registerUserRoutes(g *echo.Group) {
return
nil
})
g
.
POST
(
"/user/rename_check"
,
func
(
c
echo
.
Context
)
error
{
userRenameCheck
:=
&
api
.
UserRenameCheck
{}
if
err
:=
json
.
NewDecoder
(
c
.
Request
()
.
Body
)
.
Decode
(
userRenameCheck
);
err
!=
nil
{
...
...
@@ -64,6 +65,7 @@ func (s *Server) registerUserRoutes(g *echo.Group) {
return
nil
})
g
.
POST
(
"/user/password_check"
,
func
(
c
echo
.
Context
)
error
{
userId
:=
c
.
Get
(
getUserIdContextKey
())
.
(
int
)
userPasswordCheck
:=
&
api
.
UserPasswordCheck
{}
...
...
@@ -96,6 +98,7 @@ func (s *Server) registerUserRoutes(g *echo.Group) {
return
nil
})
g
.
PATCH
(
"/user/me"
,
func
(
c
echo
.
Context
)
error
{
userId
:=
c
.
Get
(
getUserIdContextKey
())
.
(
int
)
userPatch
:=
&
api
.
UserPatch
{
...
...
server/webhook.go
View file @
3874523e
...
...
@@ -14,6 +14,7 @@ func (s *Server) registerWebhookRoutes(g *echo.Group) {
g
.
GET
(
"/test"
,
func
(
c
echo
.
Context
)
error
{
return
c
.
HTML
(
http
.
StatusOK
,
"<strong>Hello, World!</strong>"
)
})
g
.
POST
(
"/:openId/memo"
,
func
(
c
echo
.
Context
)
error
{
openId
:=
c
.
Param
(
"openId"
)
...
...
@@ -47,6 +48,7 @@ func (s *Server) registerWebhookRoutes(g *echo.Group) {
return
nil
})
g
.
GET
(
"/:openId/memo"
,
func
(
c
echo
.
Context
)
error
{
openId
:=
c
.
Param
(
"openId"
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment