Skip to content

Commit

Permalink
fix: Harmonize style of comments
Browse files Browse the repository at this point in the history
Signed-off-by: Steffen Vogel <[email protected]>
  • Loading branch information
stv0g committed Nov 7, 2024
1 parent a8dcb00 commit 0cbc25c
Show file tree
Hide file tree
Showing 23 changed files with 95 additions and 76 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,6 @@ jobs:
with:
distribution: goreleaser
version: latest
args: release --rm-dist
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4 changes: 3 additions & 1 deletion .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# SPDX-FileCopyrightText: 2023 Steffen Vogel <[email protected]>
# SPDX-License-Identifier: Apache-2.0

version: 2

project_name: gose

before:
Expand Down Expand Up @@ -39,7 +41,7 @@ checksum:
name_template: 'checksums.txt'

snapshot:
name_template: "{{ incpatch .Version }}-next"
version_template: "{{ incpatch .Version }}-next"

changelog:
sort: asc
Expand Down
8 changes: 4 additions & 4 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ var (
const apiBase = "/api/v1"

func main() {
log.Printf("GoSƐ %s, commit %s, built at %s by %s", version, commit, date, builtBy)
log.Printf("GoSƐ %s, commit %s, built at %s by %s\n", version, commit, date, builtBy)

// Generate our config based on the config supplied
// by the user in the flags
// by the user in the flags.
cfgFile, err := config.ParseFlags()
if err != nil {
log.Fatal(err)
Expand All @@ -43,11 +43,11 @@ func main() {
log.Fatal(err)
}

// Run the server
// Run the server.
run(cfg)
}

// APIMiddleware will add the db connection to the context
// APIMiddleware will add the db connection to the context.
func APIMiddleware(svrs server.List, shortener *shortener.Shortener, cfg *config.Config) gin.HandlerFunc {
return func(c *gin.Context) {
c.Set("servers", svrs)
Expand Down
2 changes: 1 addition & 1 deletion cmd/static_embed.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func embedFolder(fsEmbed embed.FS, targetPath string) static.ServeFileSystem {
}
}

// StaticMiddleware serves static assets package by Webpack
// StaticMiddleware serves static assets package by Webpack.
func StaticMiddleware(cfg *config.Config) gin.HandlerFunc {
return static.Serve("/", embedFolder(frontend.Files, "dist"))
}
2 changes: 1 addition & 1 deletion cmd/static_local.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/stv0g/gose/pkg/config"
)

// StaticMiddleware serves static assets package by Webpack
// StaticMiddleware serves static assets package by Webpack.
func StaticMiddleware(cfg *config.Config) gin.HandlerFunc {
return static.Serve("/", static.LocalFile(cfg.Static, false))
}
16 changes: 16 additions & 0 deletions default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,24 @@ buildGoModule {
mv $out/bin/cmd $out/bin/gose
'';

tags = [ "embed" ];

ldflags = [
"-s"
"-w"
"-X"
"main.version=${version}"
"-X"
"main.builtBy=Nix"
];

checkFlags = "-skip TestShortener";

nativeInstallCheckInputs = [
versionCheckHook
];
doInstallCheck = true;

prePatch = ''
ln -s ${frontend} frontend/dist
'';
Expand Down
1 change: 1 addition & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
golangci-lint
reuse
nodejs_22
goreleaser
];
};

Expand Down
2 changes: 1 addition & 1 deletion frontend/css/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ $color-dragzone: #eb71a0;
}

.logo {
margin-left: 2em; // Aligns goose feet with title text
margin-left: 2em; // Aligns goose feet with title text.
max-width: 40%;
}

Expand Down
8 changes: 4 additions & 4 deletions frontend/webpack.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ module.exports = {
use: [
MiniCssExtractPlugin.loader,
{
loader: "css-loader", // translates CSS into CommonJS modules
loader: "css-loader", // Translates CSS into CommonJS modules.
},
{
loader: "postcss-loader", // Run post css actions
loader: "postcss-loader", // Run post CSS actions.
options: {
postcssOptions: {
plugins() { // post css plugins, can be exported to postcss.config.js
plugins() { // Post CSS plugins, can be exported to postcss.config.js
return [
require("precss"),
require("autoprefixer")
Expand All @@ -56,7 +56,7 @@ module.exports = {
},
},
{
loader: "sass-loader" // compiles Sass to CSS
loader: "sass-loader" // Compiles Sass to CSS.
}
]
},
Expand Down
44 changes: 22 additions & 22 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,20 @@ const (
// MinPartSize is the minimally supported part size for an S3 multi-part upload part.
MinPartSize size = 5 << 20 // 5MiB

// DefaultPartSize is the default size of the chunks used for Multi-part Upload if not provided by the configuration
// DefaultPartSize is the default size of the chunks used for Multi-part Upload if not provided by the configuration.
DefaultPartSize size = 16 << 20 // 16MiB

// DefaultMaxUploadSize is the maximum upload size if not provided by the configuration
// DefaultMaxUploadSize is the maximum upload size if not provided by the configuration.
DefaultMaxUploadSize size = 1 << 40 // 1TiB

// DefaultRegion is the default S3 region if not provided by the configuration
// DefaultRegion is the default S3 region if not provided by the configuration.
DefaultRegion = "us-east-1"

// DefaultBucket is the default S3 bucket name to use if not provided by the configuration
// DefaultBucket is the default S3 bucket name to use if not provided by the configuration.
DefaultBucket = "gose-uploads"
)

// DefaultExpiration is list of default expiration classes
// DefaultExpiration is list of default expiration classes.
var DefaultExpiration = []Expiration{
{
ID: "1day",
Expand Down Expand Up @@ -69,15 +69,15 @@ func (s *size) UnmarshalText(text []byte) error {
return nil
}

// Expiration describes how long files are kept before getting deleted
// Expiration describes how long files are kept before getting deleted.
type Expiration struct {
ID string `json:"id" yaml:"id"`
Title string `json:"title" yaml:"title"`

Days int64 `json:"days" yaml:"days"`
}

// S3ServerConfig is the public part of S3Server
// S3ServerConfig is the public part of S3Server.
type S3ServerConfig struct {
ID string `json:"id" yaml:"id"`
Title string `json:"title" yaml:"title"`
Expand All @@ -88,7 +88,7 @@ type S3ServerConfig struct {
Expiration []Expiration `json:"expiration" yaml:"expiration"`
}

// S3ServerSetup describes initial configuration for an S3 server/bucket
// S3ServerSetup describes initial configuration for an S3 server/bucket.
type S3ServerSetup struct {
Bucket bool `json:"bucket" yaml:"bucket"`
CORS bool `json:"cors" yaml:"cors"`
Expand All @@ -98,7 +98,7 @@ type S3ServerSetup struct {

// S3Server describes an S3 server
type S3Server struct {
// S3ServerConfig is the public info about an S3 server shared with the frontend
// S3ServerConfig is the public info about an S3 server shared with the frontend.
S3ServerConfig `json:",squash"`

Endpoint string `json:"endpoint" yaml:"endpoint"`
Expand All @@ -112,14 +112,14 @@ type S3Server struct {
Setup S3ServerSetup `json:"setup" yaml:"setup"`
}

// ShortenerConfig contains Link-shortener specific configuration
// ShortenerConfig contains Link-shortener specific configuration.
type ShortenerConfig struct {
Endpoint string `json:"endpoint" yaml:"endpoint"`
Method string `json:"method" yaml:"method"`
Response string `json:"response" yaml:"response"`
}

// NotificationConfig contains notification specific configuration
// NotificationConfig contains notification specific configuration.
type NotificationConfig struct {
URLs []string `json:"urls" yaml:"urls"`
Template string `json:"template" yaml:"template"`
Expand All @@ -133,32 +133,32 @@ type NotificationConfig struct {
} `json:"mail" yaml:"mail"`
}

// Config contains the main configuration
// Config contains the main configuration.
type Config struct {
*viper.Viper `json:"-" yaml:"-"`

// Default or single server config values
// Default or single server config values.
S3Server `json:",squash" yaml:"default"`

// Multiple server config values
// Multiple server config values.
Servers []S3Server `json:"servers" yaml:"servers,omitempty"`

// Host is the local machine IP Address to bind the HTTP Server to
// Host is the local machine IP Address to bind the HTTP Server to.
Listen string `json:"listen" yaml:"listen,omitempty"`

// Directory of frontend assets if not bundled
// Directory of frontend assets if not bundled.
Static string `json:"static" yaml:"static,omitempty"`

// BaseURL at which Gose is accessible
// BaseURL at which Gose is accessible.
BaseURL string `json:"base_url" yaml:"base_url,omitempty"`

Shortener *ShortenerConfig `json:"shortener" yaml:"shortener,omitempty"`
Notification *NotificationConfig `json:"notification" yaml:"notification,omitempty"`
}

// NewConfig returns a new decoded Config struct
// NewConfig returns a new decoded Config struct.
func NewConfig(configFile string) (*Config, error) {
// Create cfg structure
// Create config structure.
cfg := &Config{
Viper: viper.New(),
}
Expand Down Expand Up @@ -207,12 +207,12 @@ func NewConfig(configFile string) (*Config, error) {
return nil, fmt.Errorf("failed to unmarshal config: %w", err)
}

// Use the default values as the single server if no others are configured
// Use the default values as the single server if no others are configured.
if len(cfg.Servers) == 0 {
cfg.Servers = append(cfg.Servers, cfg.S3Server)
}

// Some normalization and default values for servers
// Some normalization and default values for servers.
for i := range cfg.Servers {
svr := &cfg.Servers[i]

Expand Down Expand Up @@ -273,7 +273,7 @@ func (c *Config) Check() error {
}

// ParseFlags will create and parse the CLI flags
// and return the path to be used elsewhere
// and return the path to be used elsewhere.
func ParseFlags() (string, error) {
// String that contains the configured configuration path
var configPath string
Expand Down
8 changes: 4 additions & 4 deletions pkg/handlers/complete.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type completionResponse struct {
URL string `json:"url"`
}

// HandleComplete handles a completed upload
// HandleComplete handles a completed upload.
func HandleComplete(c *gin.Context) {
svrs := c.MustGet("servers").(server.List)
cfg := c.MustGet("config").(*config.Config)
Expand Down Expand Up @@ -75,7 +75,7 @@ func HandleComplete(c *gin.Context) {
return
}

// Prepare MPU completion request
// Prepare MPU completion request.
parts := []*s3.CompletedPart{}
for _, part := range req.Parts {
parts = append(parts, &s3.CompletedPart{
Expand Down Expand Up @@ -116,7 +116,7 @@ func HandleComplete(c *gin.Context) {
}
}

// Retrieve meta-data
// Retrieve meta-data.
obj, err := svr.HeadObject(&s3.HeadObjectInput{
Bucket: aws.String(svr.Config.Bucket),
Key: aws.String(req.ETag),
Expand All @@ -133,7 +133,7 @@ func HandleComplete(c *gin.Context) {
url = svr.GetObjectURL(req.ETag).String()
}

// Send notifications
// Send notifications.
go func(key string) {
if cfg.Notification != nil && cfg.Notification.Uploads {
if notif, err := notifier.NewNotifier(cfg.Notification.Template, cfg.Notification.URLs...); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/handlers/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type configResponse struct {
Features featureResponse `json:"features"`
}

// HandleConfigWith returns runtime configuration to the frontend
// HandleConfigWith returns runtime configuration to the frontend.
func HandleConfigWith(version, commit, date string) func(*gin.Context) {
return func(c *gin.Context) {
cfg := c.MustGet("config").(*config.Config)
Expand Down
4 changes: 2 additions & 2 deletions pkg/handlers/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"github.com/vfaronov/httpheader"
)

// HandleDownload handles a request for downloading a file
// HandleDownload handles a request for downloading a file.
func HandleDownload(c *gin.Context) {
var err error

Expand All @@ -42,7 +42,7 @@ func HandleDownload(c *gin.Context) {
return
}

// Retrieve meta-data
// Retrieve meta-data.
obj, err := svr.HeadObject(&s3.HeadObjectInput{
Bucket: aws.String(svr.Config.Bucket),
Key: aws.String(etag),
Expand Down
Loading

0 comments on commit 0cbc25c

Please sign in to comment.