chore: rename router package

This commit is contained in:
Steven 2024-05-01 10:28:32 +08:00
parent 8ae4bc95dc
commit 20dd3e17f7
32 changed files with 4 additions and 216 deletions

View File

@ -15,7 +15,7 @@ FROM golang:1.22-alpine AS backend
WORKDIR /backend-build
COPY . .
COPY --from=frontend /frontend-build/web/dist /backend-build/server/route/frontend/dist
COPY --from=frontend /frontend-build/web/dist /backend-build/server/router/frontend/dist
RUN CGO_ENABLED=0 go build -o memos ./bin/memos/main.go

2
go.mod
View File

@ -10,7 +10,6 @@ require (
github.com/aws/aws-sdk-go-v2/credentials v1.17.11
github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.16.15
github.com/aws/aws-sdk-go-v2/service/s3 v1.53.1
github.com/disintegration/imaging v1.6.2
github.com/go-sql-driver/mysql v1.8.1
github.com/google/cel-go v0.20.1
github.com/google/uuid v1.6.0
@ -51,7 +50,6 @@ require (
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/stoewer/go-strcase v1.3.0 // indirect
golang.org/x/exp v0.0.0-20240409090435-93d18d7e34b8 // indirect
golang.org/x/image v0.15.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240415180920-8c6c420018be // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
modernc.org/gc/v3 v3.0.0-20240304020402-f0dba7c97c2b // indirect

5
go.sum
View File

@ -93,8 +93,6 @@ github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8Yc
github.com/desertbit/timer v0.0.0-20180107155436-c41aec40b27f h1:U5y3Y5UE0w7amNe7Z5G/twsBW0KEalRQXZzf8ufSh9I=
github.com/desertbit/timer v0.0.0-20180107155436-c41aec40b27f/go.mod h1:xH/i4TFMt8koVQZ6WFms69WAsDWr2XsYL3Hkl7jkoLE=
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
github.com/disintegration/imaging v1.6.2 h1:w1LecBlG2Lnp8B3jk5zSuNqd7b4DXhcjwek1ei82L+c=
github.com/disintegration/imaging v1.6.2/go.mod h1:44/5580QXChDfwIclfc/PCwrr44amcmDAg8hxG0Ewe4=
github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
@ -477,9 +475,6 @@ golang.org/x/exp v0.0.0-20240409090435-93d18d7e34b8 h1:ESSUROHIBHg7USnszlcdmjBEw
golang.org/x/exp v0.0.0-20240409090435-93d18d7e34b8/go.mod h1:/lliqkxwWAhPjf5oSOIJup2XcqJaw8RGS6k3TGEc7GI=
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/image v0.0.0-20191009234506-e7c1f5e7dbb8/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/image v0.15.0 h1:kOELfmgrmJlw4Cdb7g/QGuB3CvDrXbqEIww/pNtNBm8=
golang.org/x/image v0.15.0/go.mod h1:HUYqC05R2ZcZ3ejNQsIHQDQiwWM4JBqmm6MKANTp4LE=
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=

View File

@ -1,13 +0,0 @@
# This file is used by gen-api-v1-docs.ps1 and gen-api-v1-docs.sh
# You should list additional dirs here if the API grows
SWAG_API_DIRS=./server/route/api/v1
# Where general API info is documented
SWAG_GENERAL_INFO=./server/route/api/v1/v1.go
# Possible output files: go (docs.go), json (swagger.json), yaml (swagger.yaml)
SWAG_OUTPUT_TYPES=go,yaml
# Where generated files are outputted
SWAG_OUTPUT=./server/route/api/v1

View File

@ -1,73 +0,0 @@
# This script generates API documentation using swaggo/swag
# For more details, check the docs:
# * https://usememos.com/docs/contribution/development
# * https://github.com/usememos/memos/blob/main/docs/api/documentation.md
# Requirements:
# * go
# swag is configured mainly via gen-api-v1-docs.cfg file.
# Usage:
# ./scripts/gen-api-v1-docs.ps1
foreach ($dir in @(".", "../")) {
if (Test-Path (Join-Path $dir ".gitignore")) {
$repoRoot = (Resolve-Path $dir).Path
break
}
}
Set-Location $repoRoot
Write-Host "Parsing gen-api-v1-docs.cfg..."
foreach ($line in (Get-Content "$repoRoot\scripts\gen-api-v1-docs.cfg" )) {
if ($line.Trim().StartsWith('#')) {
continue
}
$name, $value = $line.split('=')
if ([string]::IsNullOrWhiteSpace($name)) {
continue
}
Set-Content env:\$name $value
}
Write-Host "API directories: $env:SWAG_API_DIRS" -f Cyan
Write-Host "Output directory: $env:SWAG_OUTPUT" -f Cyan
Write-Host "General info: $env:SWAG_GENERAL_INFO" -f Cyan
$swag = (Get-Command swag -ErrorAction SilentlyContinue).Path
if (-not $swag) {
foreach ($path in @((Join-Path $HOME "go/bin"), (Join-Path $env:GOPATH "/bin"))) {
$swag = Join-Path (Resolve-Path $path).Path "swag.exe"
if (Test-Path $swag) {
break
}
}
}
if (-not (Test-Path $swag)) {
Write-Host "Swag is not installed. Installing..." -f Magenta
go install github.com/swaggo/swag/cmd/swag@latest
}
$generalInfoPath = (Split-Path (Resolve-Path $env:SWAG_GENERAL_INFO -Relative) -Parent)
$apiDirs = $env:SWAG_API_DIRS -split ',' | ForEach-Object { "$(Resolve-Path $_ -Relative)" }
$swagFmtDirs = $generalInfoPath + "," + $($apiDirs -join ",")
Write-Host "Formatting comments via ``swag fmt --dir `"$swagFmtDirs`"``..." -f Magenta
&$swag fmt --dir "`"${swagFmtDirs}`""
$goFmtDirs = $swagFmtDirs -split ',' | ForEach-Object { "`"$($_)`"" }
# This is just in case swag fmt do something non-conforming to go fmt
Write-Host "Formatting code via ``go fmt ${goFmtDirs}``..." -f Magenta
go fmt ${goFmtDirs}
Write-Host "Generating Swagger API documentation..." -f Magenta
&$swag init --output $env:SWAG_OUTPUT --outputTypes $env:SWAG_OUTPUT_TYPES --generalInfo $env:SWAG_GENERAL_INFO --dir "./,${env:SWAG_API_DIRS}"
if ($LASTEXITCODE -ne 0) {
Write-Host "Failed to generate API documentation!" -f Red
exit $LASTEXITCODE
}
Write-Host "API documentation updated!" -f Green

View File

@ -1,108 +0,0 @@
#!/bin/bash
# This script generates API documentation using swaggo/swag
# For more details, check the docs:
# * https://usememos.com/docs/contribution/development
# * https://github.com/usememos/memos/blob/main/docs/api/documentation.md
# Requirements:
# * go
# swag is configured via gen-api-v1-docs.cfg file.
# Usage:
# chmod +x ./scripts/gen-api-v1-docs.sh
# ./scripts/gen-api-v1-docs.sh
find_repo_root() {
# Usage: find_repo_root <file_at_root> <dir1> <dir2> ...
local looking_for="${1:-".gitignore"}"
shift
local default_dirs=("." "../")
local dirs=("${@:-${default_dirs[@]}}")
for dir in "${dirs[@]}"; do
if [ -f "$dir/$looking_for" ]; then
echo $(realpath "$dir")
return
fi
done
}
find_binary() {
# Usage: find_binary <binary> <dir1> <dir2> ...
local looking_for="$1"
shift
local default_dirs=(".")
local binary=$(command -v $looking_for)
if [ ! -z "$binary" ]; then
echo "$binary"
return
fi
local dirs=("${@:-${default_dirs[@]}}")
for dir in "${dirs[@]}"; do
if [ -f "$dir/$looking_for" ]; then
echo $(realpath "$dir")/$looking_for
return
fi
done
}
repo_root=$(find_repo_root)
if [ -z "$repo_root" ]; then
echo -e "\033[0;31mRepository root not found! Exiting.\033[0m"
exit 1
else
echo -e "Repository root: \033[0;34m$repo_root\033[0m"
fi
cd $repo_root
echo "Parsing gen-api-v1-docs.cfg..."
source "$repo_root/scripts/gen-api-v1-docs.cfg"
echo -e "API directories: \033[0;34m$SWAG_API_DIRS\033[0m"
echo -e "Output directory: \033[0;34m$SWAG_OUTPUT\033[0m"
echo -e "General info: \033[0;34m$SWAG_GENERAL_INFO\033[0m"
if [ -z "$SWAG_API_DIRS" ]; then
echo -e "\033[0;31mAPI directories not set! Exiting.\033[0m"
exit 1
fi
swag=$(find_binary swag "$HOME/go/bin" "$GOPATH/bin")
if [ -z "$swag" ]; then
echo "Swag is not installed. Installing..."
go install github.com/swaggo/swag/cmd/swag@latest
swag=$(find_binary swag "$HOME/go/bin" "$GOPATH/bin")
fi
if [ -z "$swag" ]; then
echo -e "\033[0;31mSwag binary not found! Exiting.\033[0m"
exit 1
fi
echo -e "Swag binary: \033[0;34m$swag\033[0m"
general_info_path=$(dirname "$SWAG_GENERAL_INFO")
if [ ! -d "$general_info_path" ]; then
echo -e "\033[0;31mGeneral info directory does not exist!\033[0m"
exit 1
fi
echo -e "\e[35mFormatting comments via \`swag fmt --dir "$general_info_path,$SWAG_API_DIRS"\`...\e[0m"
$swag fmt --dir "$general_info_path,$SWAG_API_DIRS"
# This is just in case "swag fmt" do something non-conforming to "go fmt"
go_fmt_dirs=$(echo $general_info_path $SWAG_API_DIRS | tr "," " ")
echo -e "\e[35mFormatting code via \`go fmt $go_fmt_dirs\`...\e[0m"
go fmt $go_fmt_dirs
echo -e "\e[35mGenerating Swagger API documentation...\e[0m"
$swag init --output "$SWAG_OUTPUT" --outputTypes "$SWAG_OUTPUT_TYPES" --generalInfo "$SWAG_GENERAL_INFO" --dir "./,$SWAG_API_DIRS"
if [ $? -ne 0 ]; then
echo -e "\033[0;31mFailed to generate Swagger API documentation!\033[0m"
exit 1
fi
echo -e "\033[0;32mSwagger API documentation updated!\033[0m"

View File

@ -1,11 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Memos</title>
</head>
<body>
No embeddable frontend found.
</body>
</html>

View File

@ -16,9 +16,9 @@ import (
storepb "github.com/usememos/memos/proto/gen/store"
"github.com/usememos/memos/server/profile"
apiv1 "github.com/usememos/memos/server/route/api/v1"
"github.com/usememos/memos/server/route/frontend"
"github.com/usememos/memos/server/route/rss"
apiv1 "github.com/usememos/memos/server/router/api/v1"
"github.com/usememos/memos/server/router/frontend"
"github.com/usememos/memos/server/router/rss"
versionchecker "github.com/usememos/memos/server/service/version_checker"
"github.com/usememos/memos/store"
)