mirror of
https://github.com/taigrr/pastebin
synced 2026-04-16 20:04:59 -07:00
feat: modernize codebase and complete API surface
- 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)
This commit is contained in:
@@ -1,36 +1,45 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/prologic/pastebin/client"
|
||||
|
||||
"github.com/namsral/flag"
|
||||
"github.com/charmbracelet/fang"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/taigrr/pastebin/client"
|
||||
)
|
||||
|
||||
const (
|
||||
defaultConfig = "pastebin.conf"
|
||||
defaultUserConfig = "~/.pastebin.conf"
|
||||
defaultURL = "http://localhost:8000"
|
||||
defaultURL = "http://localhost:8000"
|
||||
)
|
||||
|
||||
// version is set at build time via ldflags.
|
||||
var version = "dev"
|
||||
|
||||
func main() {
|
||||
var (
|
||||
url string
|
||||
insecure bool
|
||||
serviceURL string
|
||||
insecure bool
|
||||
)
|
||||
|
||||
flag.StringVar(&url, "url", defaultURL, "pastebin service url")
|
||||
flag.BoolVar(&insecure, "insecure", false, "insecure (skip ssl verify)")
|
||||
rootCmd := &cobra.Command{
|
||||
Use: "pb",
|
||||
Short: "CLI client for the pastebin service",
|
||||
Long: "pb reads from stdin and submits the content as a paste to the pastebin service.",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
cli := client.NewClient(serviceURL, insecure)
|
||||
if err := cli.Paste(os.Stdin); err != nil {
|
||||
return fmt.Errorf("posting paste: %w", err)
|
||||
}
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
flag.Parse()
|
||||
rootCmd.Flags().StringVar(&serviceURL, "url", defaultURL, "pastebin service URL")
|
||||
rootCmd.Flags().BoolVar(&insecure, "insecure", false, "skip TLS certificate verification")
|
||||
|
||||
cli := client.NewClient(url, insecure)
|
||||
|
||||
err := cli.Paste(os.Stdin)
|
||||
if err != nil {
|
||||
log.Printf("error posting paste: %s", err)
|
||||
if err := fang.Execute(context.Background(), rootCmd, fang.WithVersion(version)); err != nil {
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user