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
e23ade1f
Unverified
Commit
e23ade1f
authored
May 07, 2025
by
Sergey Gorbunov
Committed by
GitHub
May 07, 2025
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: support listening on a UNIX socket (#4654)
parent
2a92baf5
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
32 additions
and
7 deletions
+32
-7
main.go
bin/memos/main.go
+14
-4
profile.go
server/profile/profile.go
+2
-0
v1.go
server/router/api/v1/v1.go
+7
-1
server.go
server/server.go
+9
-2
No files found.
bin/memos/main.go
View file @
e23ade1f
...
...
@@ -39,6 +39,7 @@ var (
Mode
:
viper
.
GetString
(
"mode"
),
Addr
:
viper
.
GetString
(
"addr"
),
Port
:
viper
.
GetInt
(
"port"
),
UNIXSock
:
viper
.
GetString
(
"unix-sock"
),
Data
:
viper
.
GetString
(
"data"
),
Driver
:
viper
.
GetString
(
"driver"
),
DSN
:
viper
.
GetString
(
"dsn"
),
...
...
@@ -106,6 +107,7 @@ func init() {
rootCmd
.
PersistentFlags
()
.
String
(
"mode"
,
"dev"
,
`mode of server, can be "prod" or "dev" or "demo"`
)
rootCmd
.
PersistentFlags
()
.
String
(
"addr"
,
""
,
"address of server"
)
rootCmd
.
PersistentFlags
()
.
Int
(
"port"
,
8081
,
"port of server"
)
rootCmd
.
PersistentFlags
()
.
String
(
"unix-sock"
,
""
,
"path to the unix socket, overrides --addr and --port"
)
rootCmd
.
PersistentFlags
()
.
String
(
"data"
,
""
,
"data directory"
)
rootCmd
.
PersistentFlags
()
.
String
(
"driver"
,
"sqlite"
,
"database driver"
)
rootCmd
.
PersistentFlags
()
.
String
(
"dsn"
,
""
,
"database source name(aka. DSN)"
)
...
...
@@ -120,6 +122,9 @@ func init() {
if
err
:=
viper
.
BindPFlag
(
"port"
,
rootCmd
.
PersistentFlags
()
.
Lookup
(
"port"
));
err
!=
nil
{
panic
(
err
)
}
if
err
:=
viper
.
BindPFlag
(
"unix-sock"
,
rootCmd
.
PersistentFlags
()
.
Lookup
(
"unix-sock"
));
err
!=
nil
{
panic
(
err
)
}
if
err
:=
viper
.
BindPFlag
(
"data"
,
rootCmd
.
PersistentFlags
()
.
Lookup
(
"data"
));
err
!=
nil
{
panic
(
err
)
}
...
...
@@ -151,16 +156,21 @@ version: %s
data: %s
addr: %s
port: %d
unix-sock: %s
mode: %s
driver: %s
---
`
,
profile
.
Version
,
profile
.
Data
,
profile
.
Addr
,
profile
.
Port
,
profile
.
Mode
,
profile
.
Driver
)
`
,
profile
.
Version
,
profile
.
Data
,
profile
.
Addr
,
profile
.
Port
,
profile
.
UNIXSock
,
profile
.
Mode
,
profile
.
Driver
)
print
(
greetingBanner
)
if
len
(
profile
.
Addr
)
==
0
{
fmt
.
Printf
(
"Version %s has been started on port %d
\n
"
,
profile
.
Version
,
profile
.
Port
)
if
len
(
profile
.
UNIXSock
)
==
0
{
if
len
(
profile
.
Addr
)
==
0
{
fmt
.
Printf
(
"Version %s has been started on port %d
\n
"
,
profile
.
Version
,
profile
.
Port
)
}
else
{
fmt
.
Printf
(
"Version %s has been started on address '%s' and port %d
\n
"
,
profile
.
Version
,
profile
.
Addr
,
profile
.
Port
)
}
}
else
{
fmt
.
Printf
(
"Version %s has been started on
address '%s' and port %d
\n
"
,
profile
.
Version
,
profile
.
Addr
,
profile
.
Port
)
fmt
.
Printf
(
"Version %s has been started on
unix socket %s
\n
"
,
profile
.
Version
,
profile
.
UNIXSock
)
}
fmt
.
Printf
(
`---
See more in:
...
...
server/profile/profile.go
View file @
e23ade1f
...
...
@@ -19,6 +19,8 @@ type Profile struct {
Addr
string
// Port is the binding port for server
Port
int
// UNIXSock is the IPC binding path. Overrides Addr and Port
UNIXSock
string
// Data is the data directory
Data
string
// DSN points to where memos stores its own data
...
...
server/router/api/v1/v1.go
View file @
e23ade1f
...
...
@@ -67,8 +67,14 @@ func NewAPIV1Service(secret string, profile *profile.Profile, store *store.Store
// RegisterGateway registers the gRPC-Gateway with the given Echo instance.
func
(
s
*
APIV1Service
)
RegisterGateway
(
ctx
context
.
Context
,
echoServer
*
echo
.
Echo
)
error
{
var
target
string
if
len
(
s
.
Profile
.
UNIXSock
)
==
0
{
target
=
fmt
.
Sprintf
(
"%s:%d"
,
s
.
Profile
.
Addr
,
s
.
Profile
.
Port
)
}
else
{
target
=
fmt
.
Sprintf
(
"unix:%s"
,
s
.
Profile
.
UNIXSock
)
}
conn
,
err
:=
grpc
.
NewClient
(
fmt
.
Sprintf
(
"%s:%d"
,
s
.
Profile
.
Addr
,
s
.
Profile
.
Port
)
,
target
,
grpc
.
WithTransportCredentials
(
insecure
.
NewCredentials
()),
grpc
.
WithDefaultCallOptions
(
grpc
.
MaxCallRecvMsgSize
(
math
.
MaxInt32
)),
)
...
...
server/server.go
View file @
e23ade1f
...
...
@@ -93,8 +93,15 @@ func NewServer(ctx context.Context, profile *profile.Profile, store *store.Store
}
func
(
s
*
Server
)
Start
(
ctx
context
.
Context
)
error
{
address
:=
fmt
.
Sprintf
(
"%s:%d"
,
s
.
Profile
.
Addr
,
s
.
Profile
.
Port
)
listener
,
err
:=
net
.
Listen
(
"tcp"
,
address
)
var
address
,
network
string
if
len
(
s
.
Profile
.
UNIXSock
)
==
0
{
address
=
fmt
.
Sprintf
(
"%s:%d"
,
s
.
Profile
.
Addr
,
s
.
Profile
.
Port
)
network
=
"tcp"
}
else
{
address
=
s
.
Profile
.
UNIXSock
network
=
"unix"
}
listener
,
err
:=
net
.
Listen
(
network
,
address
)
if
err
!=
nil
{
return
errors
.
Wrap
(
err
,
"failed to listen"
)
}
...
...
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