mirror of
https://github.com/taigrr/pastebin
synced 2026-04-07 17:41:30 -07:00
- Update module path from prologic/pastebin to taigrr/pastebin - Replace go.rice with stdlib embed for templates and static assets - Replace httprouter with stdlib net/http ServeMux (Go 1.22+) - Replace namsral/flag with cobra + fang for CLI argument parsing - Fix inverted TLS insecure logic in client (was negating the flag) - Close HTTP response body in client - Use base64 URLEncoding instead of StdEncoding for paste IDs - Add comprehensive handler tests for all endpoints - Add client package tests - Add utils tests for RandomString - Remove templates.go (replaced by embed) - Remove unused dependencies (go-metrics, stats, logger, httprouter, go.rice)
46 lines
1.1 KiB
Go
46 lines
1.1 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"os"
|
|
"time"
|
|
|
|
"github.com/charmbracelet/fang"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
// version is set at build time via ldflags.
|
|
var version = "dev"
|
|
|
|
func main() {
|
|
var cfg Config
|
|
|
|
rootCmd := &cobra.Command{
|
|
Use: "pastebin",
|
|
Short: "A self-hosted ephemeral pastebin service",
|
|
Long: "pastebin is a self-hosted pastebin web app that lets you create and share ephemeral data between devices and users.",
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
if cfg.Expiry.Seconds() < 60 {
|
|
return fmt.Errorf("expiry of %s is too small (minimum 1m)", cfg.Expiry)
|
|
}
|
|
server := NewServer(cfg)
|
|
return server.ListenAndServe()
|
|
},
|
|
}
|
|
|
|
rootCmd.Flags().StringVar(&cfg.Bind, "bind", defaultBind, "address and port to bind to")
|
|
rootCmd.Flags().StringVar(&cfg.FQDN, "fqdn", defaultFQDN, "FQDN for public access")
|
|
rootCmd.Flags().DurationVar(&cfg.Expiry, "expiry", defaultExpiry, "expiry time for pastes")
|
|
|
|
if err := fang.Execute(context.Background(), rootCmd, fang.WithVersion(version)); err != nil {
|
|
os.Exit(1)
|
|
}
|
|
}
|
|
|
|
const (
|
|
defaultBind = "0.0.0.0:8000"
|
|
defaultFQDN = "localhost"
|
|
defaultExpiry = 5 * time.Minute
|
|
)
|