🎨 Update project structure

This commit is contained in:
LittleSheep 2024-06-16 23:24:54 +08:00
parent a1aa418496
commit 05a59113c9
28 changed files with 63 additions and 27 deletions

44
.idea/workspace.xml generated
View File

@ -4,7 +4,36 @@
<option name="autoReloadType" value="ALL" />
</component>
<component name="ChangeListManager">
<list default="true" id="18dd0d68-b4b8-40db-9734-9119b5c848bd" name="更改" comment=":bug: Fix uuid duplicate when link exists" />
<list default="true" id="18dd0d68-b4b8-40db-9734-9119b5c848bd" name="更改" comment=":bug: Fix uuid duplicate when link exists">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Dockerfile" beforeDir="false" afterPath="$PROJECT_DIR$/Dockerfile" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pkg/cmd/main.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/main.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pkg/database/migrator.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/database/migrator.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pkg/database/source.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/database/source.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pkg/grpc/attachments.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/grpc/attachments.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pkg/grpc/client.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/grpc/client.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pkg/grpc/proto/attachments.pb.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/proto/attachments.pb.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pkg/grpc/proto/attachments.proto" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/proto/attachments.proto" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pkg/grpc/proto/attachments_grpc.pb.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/proto/attachments_grpc.pb.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pkg/grpc/server.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/grpc/server.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pkg/meta.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/meta.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pkg/models/accounts.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/models/accounts.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pkg/models/attachments.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/models/attachments.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pkg/models/base.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/models/base.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pkg/models/destination.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/models/destination.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pkg/models/metadata.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/models/metadata.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pkg/server/attachments_api.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/server/attachments_api.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pkg/server/auth.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/server/auth.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pkg/server/startup.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/server/startup.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pkg/server/utils.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/server/utils.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pkg/server/well_known_api.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/server/well_known_api.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pkg/services/attachments.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/services/attachments.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pkg/services/auth.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/services/auth.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pkg/services/cleaner.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/services/cleaner.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pkg/services/jwt.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/services/jwt.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pkg/services/recycler.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/services/recycler.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pkg/services/uploader.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/services/uploader.go" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
@ -41,13 +70,20 @@
&quot;settings.editor.selected.configurable&quot;: &quot;preferences.lookFeel&quot;
}
}</component>
<component name="RecentsManager">
<key name="MoveFile.RECENT_KEYS">
<recent name="$PROJECT_DIR$/pkg" />
<recent name="$PROJECT_DIR$/pkg/internal" />
</key>
</component>
<component name="RunManager">
<configuration name="Backend" type="GoApplicationRunConfiguration" factoryName="Go Application">
<module name="Paperclip" />
<working_directory value="$PROJECT_DIR$" />
<kind value="FILE" />
<package value="git.solsynth.dev/hydrogen/paperclip" />
<directory value="$PROJECT_DIR$" />
<filePath value="$PROJECT_DIR$/pkg/cmd/main.go" />
<filePath value="$PROJECT_DIR$/pkg/main.go" />
<output_directory value="$PROJECT_DIR$/dist" />
<method v="2" />
</configuration>
@ -55,8 +91,8 @@
<component name="SharedIndexes">
<attachedChunks>
<set>
<option value="bundled-gosdk-33c477a475b1-b97fc8a1e17c-org.jetbrains.plugins.go.sharedIndexes.bundled-GO-241.14494.238" />
<option value="bundled-js-predefined-1d06a55b98c1-74d2a5396914-JavaScript-GO-241.14494.238" />
<option value="bundled-gosdk-33c477a475b1-e0158606a674-org.jetbrains.plugins.go.sharedIndexes.bundled-GO-241.17890.21" />
<option value="bundled-js-predefined-1d06a55b98c1-0b3e54e931b4-JavaScript-GO-241.17890.21" />
</set>
</attachedChunks>
</component>

View File

@ -5,7 +5,7 @@ RUN apk add nodejs npm
WORKDIR /source
COPY . .
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -buildvcs -o /dist ./pkg/cmd/main.go
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -buildvcs -o /dist ./pkg/main.go
# Runtime
FROM golang:alpine

View File

@ -3,10 +3,10 @@ package grpc
import (
"context"
"fmt"
"git.solsynth.dev/hydrogen/paperclip/pkg/internal/database"
"git.solsynth.dev/hydrogen/paperclip/pkg/proto"
"google.golang.org/protobuf/types/known/emptypb"
"git.solsynth.dev/hydrogen/paperclip/pkg/database"
"git.solsynth.dev/hydrogen/paperclip/pkg/grpc/proto"
"git.solsynth.dev/hydrogen/paperclip/pkg/models"
jsoniter "github.com/json-iterator/go"
)

View File

@ -1,9 +1,9 @@
package grpc
import (
"git.solsynth.dev/hydrogen/paperclip/pkg/proto"
"net"
"git.solsynth.dev/hydrogen/paperclip/pkg/grpc/proto"
"github.com/spf13/viper"
"google.golang.org/grpc"
"google.golang.org/grpc/reflection"

View File

@ -3,13 +3,13 @@ package server
import (
"context"
"fmt"
"git.solsynth.dev/hydrogen/paperclip/pkg/internal/database"
"git.solsynth.dev/hydrogen/paperclip/pkg/internal/grpc"
"net/url"
"path/filepath"
"git.solsynth.dev/hydrogen/paperclip/pkg/grpc"
"git.solsynth.dev/hydrogen/passport/pkg/grpc/proto"
"git.solsynth.dev/hydrogen/paperclip/pkg/database"
"git.solsynth.dev/hydrogen/paperclip/pkg/models"
"git.solsynth.dev/hydrogen/paperclip/pkg/services"
"github.com/gofiber/fiber/v2"

View File

@ -2,12 +2,12 @@ package services
import (
"fmt"
"git.solsynth.dev/hydrogen/paperclip/pkg/internal/database"
"mime"
"mime/multipart"
"net/http"
"path/filepath"
"git.solsynth.dev/hydrogen/paperclip/pkg/database"
"git.solsynth.dev/hydrogen/paperclip/pkg/models"
"github.com/google/uuid"
"gorm.io/gorm"

View File

@ -4,11 +4,11 @@ import (
"context"
"errors"
"fmt"
"git.solsynth.dev/hydrogen/paperclip/pkg/internal/database"
"git.solsynth.dev/hydrogen/paperclip/pkg/internal/grpc"
"reflect"
"time"
"git.solsynth.dev/hydrogen/paperclip/pkg/database"
"git.solsynth.dev/hydrogen/paperclip/pkg/grpc"
"git.solsynth.dev/hydrogen/paperclip/pkg/models"
"git.solsynth.dev/hydrogen/passport/pkg/grpc/proto"
"gorm.io/gorm"

View File

@ -1,9 +1,9 @@
package services
import (
database2 "git.solsynth.dev/hydrogen/paperclip/pkg/internal/database"
"time"
"git.solsynth.dev/hydrogen/paperclip/pkg/database"
"github.com/rs/zerolog/log"
)
@ -12,8 +12,8 @@ func DoAutoDatabaseCleanup() {
log.Debug().Time("deadline", deadline).Msg("Now cleaning up entire database...")
var count int64
for _, model := range database.AutoMaintainRange {
tx := database.C.Unscoped().Delete(model, "deleted_at >= ?", deadline)
for _, model := range database2.AutoMaintainRange {
tx := database2.C.Unscoped().Delete(model, "deleted_at >= ?", deadline)
if tx.Error != nil {
log.Error().Err(tx.Error).Msg("An error occurred when running auth context cleanup...")
}

View File

@ -1,17 +1,17 @@
package main
import (
database2 "git.solsynth.dev/hydrogen/paperclip/pkg/internal/database"
grpc2 "git.solsynth.dev/hydrogen/paperclip/pkg/internal/grpc"
"os"
"os/signal"
"syscall"
"git.solsynth.dev/hydrogen/paperclip/pkg/grpc"
"git.solsynth.dev/hydrogen/paperclip/pkg/server"
"git.solsynth.dev/hydrogen/paperclip/pkg/services"
"git.solsynth.dev/hydrogen/paperclip/pkg/internal/server"
"git.solsynth.dev/hydrogen/paperclip/pkg/internal/services"
"github.com/robfig/cron/v3"
paperclip "git.solsynth.dev/hydrogen/paperclip/pkg"
"git.solsynth.dev/hydrogen/paperclip/pkg/database"
"git.solsynth.dev/hydrogen/paperclip/pkg/internal"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"github.com/spf13/viper"
@ -35,14 +35,14 @@ func main() {
}
// Connect to database
if err := database.NewSource(); err != nil {
if err := database2.NewSource(); err != nil {
log.Fatal().Err(err).Msg("An error occurred when connect to database.")
} else if err := database.RunMigration(database.C); err != nil {
} else if err := database2.RunMigration(database2.C); err != nil {
log.Fatal().Err(err).Msg("An error occurred when running database auto migration.")
}
// Connect other services
if err := grpc.ConnectPassport(); err != nil {
if err := grpc2.ConnectPassport(); err != nil {
log.Fatal().Err(err).Msg("An error occurred when connecting to passport grpc endpoint...")
}
@ -57,19 +57,19 @@ func main() {
// Grpc Server
go func() {
if err := grpc.StartGrpc(); err != nil {
if err := grpc2.StartGrpc(); err != nil {
log.Fatal().Err(err).Msg("An message occurred when starting grpc server.")
}
}()
// Messages
log.Info().Msgf("Paperclip v%s is started...", paperclip.AppVersion)
log.Info().Msgf("Paperclip v%s is started...", pkg.AppVersion)
quit := make(chan os.Signal, 1)
signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)
<-quit
log.Info().Msgf("Paperclip v%s is quitting...", paperclip.AppVersion)
log.Info().Msgf("Paperclip v%s is quitting...", pkg.AppVersion)
quartz.Stop()
}