mirror of
https://github.com/coalaura/up.git
synced 2025-07-17 21:44:35 +00:00
combine server and client into one binary
This commit is contained in:
6
.github/workflows/release.yml
vendored
6
.github/workflows/release.yml
vendored
@ -16,7 +16,6 @@ jobs:
|
||||
matrix:
|
||||
goos: [windows, linux, darwin]
|
||||
goarch: [amd64, arm64]
|
||||
type: [client, server]
|
||||
fail-fast: false
|
||||
|
||||
steps:
|
||||
@ -35,7 +34,7 @@ jobs:
|
||||
mkdir -p build
|
||||
[[ "${{ matrix.goos }}" == "windows" ]] && EXT=".exe" || EXT=""
|
||||
|
||||
OUT="build/up_${{ matrix.type }}_${{ github.ref_name }}_${{ matrix.goos }}_${{ matrix.goarch }}${EXT}"
|
||||
OUT="build/up_${{ github.ref_name }}_${{ matrix.goos }}_${{ matrix.goarch }}${EXT}"
|
||||
|
||||
GOOS=${{ matrix.goos }} \
|
||||
GOARCH=${{ matrix.goarch }} \
|
||||
@ -44,13 +43,12 @@ jobs:
|
||||
-trimpath \
|
||||
-buildvcs=false \
|
||||
-ldflags "-s -w -X 'main.Version=${{ github.ref_name }}'" \
|
||||
-tags "${{ matrix.flavour }}" \
|
||||
-o "$OUT" ./${{ matrix.type }}
|
||||
|
||||
- name: Upload artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: up_${{ matrix.type }}_${{ github.ref_name }}_${{ matrix.goos }}_${{ matrix.goarch }}
|
||||
name: up_${{ github.ref_name }}_${{ matrix.goos }}_${{ matrix.goarch }}
|
||||
path: build/*
|
||||
|
||||
release:
|
||||
|
@ -1,4 +1,4 @@
|
||||
package main
|
||||
package client
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
|
@ -1,4 +1,4 @@
|
||||
package main
|
||||
package client
|
||||
|
||||
import (
|
||||
"context"
|
||||
@ -13,40 +13,18 @@ import (
|
||||
"github.com/urfave/cli/v3"
|
||||
)
|
||||
|
||||
var (
|
||||
Version = "dev"
|
||||
var log *logger.Logger
|
||||
|
||||
func Before(ctx context.Context, _ *cli.Command) (context.Context, error) {
|
||||
log = logger.New().DetectTerminal().WithOptions(logger.Options{
|
||||
NoTime: true,
|
||||
NoLevel: true,
|
||||
})
|
||||
)
|
||||
|
||||
func main() {
|
||||
app := &cli.Command{
|
||||
Name: "up",
|
||||
Usage: "up client",
|
||||
Version: Version,
|
||||
ArgsUsage: "<file> <host>",
|
||||
UsageText: "up [options] <file> <host>",
|
||||
Flags: []cli.Flag{
|
||||
&cli.StringFlag{
|
||||
Name: "identity",
|
||||
Aliases: []string{"i"},
|
||||
Usage: "private key file for authentication",
|
||||
},
|
||||
},
|
||||
Action: run,
|
||||
EnableShellCompletion: true,
|
||||
UseShortOptionHandling: true,
|
||||
Suggest: true,
|
||||
}
|
||||
|
||||
err := app.Run(context.Background(), os.Args)
|
||||
log.MustPanic(err)
|
||||
return ctx, nil
|
||||
}
|
||||
|
||||
func run(_ context.Context, cmd *cli.Command) error {
|
||||
func Run(_ context.Context, cmd *cli.Command) error {
|
||||
args := cmd.Args().Slice()
|
||||
if len(args) != 2 {
|
||||
return errors.New("Usage: up [options] <file> <host>")
|
@ -1,4 +1,4 @@
|
||||
package main
|
||||
package client
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
@ -1,4 +1,4 @@
|
||||
package main
|
||||
package client
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
@ -1,4 +1,4 @@
|
||||
package main
|
||||
package client
|
||||
|
||||
import (
|
||||
"io"
|
||||
|
@ -1,4 +1,4 @@
|
||||
package main
|
||||
package client
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
|
63
main.go
Normal file
63
main.go
Normal file
@ -0,0 +1,63 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/coalaura/up/client"
|
||||
"github.com/coalaura/up/server"
|
||||
"github.com/urfave/cli/v3"
|
||||
)
|
||||
|
||||
var Version = "dev"
|
||||
|
||||
func main() {
|
||||
app := &cli.Command{
|
||||
Name: "up",
|
||||
Description: "fast, drop-in file transfer tool using HTTPS",
|
||||
UsageText: "up <command> [command options]",
|
||||
Version: Version,
|
||||
Commands: []*cli.Command{
|
||||
{
|
||||
Name: "send",
|
||||
Usage: "send a file to an up server",
|
||||
Version: Version,
|
||||
ArgsUsage: "<file> <host>",
|
||||
UsageText: "up send [options] <file> <host>",
|
||||
Flags: []cli.Flag{
|
||||
&cli.StringFlag{
|
||||
Name: "identity",
|
||||
Aliases: []string{"i"},
|
||||
Usage: "private key file for authentication",
|
||||
},
|
||||
},
|
||||
Before: client.Before,
|
||||
Action: client.Run,
|
||||
},
|
||||
{
|
||||
Name: "receive",
|
||||
Usage: "receive files from up clients",
|
||||
Flags: []cli.Flag{
|
||||
&cli.UintFlag{
|
||||
Name: "port",
|
||||
Aliases: []string{"p"},
|
||||
Usage: "custom port",
|
||||
Value: 7966,
|
||||
},
|
||||
},
|
||||
Before: server.Before,
|
||||
Action: server.Run,
|
||||
},
|
||||
},
|
||||
EnableShellCompletion: true,
|
||||
UseShortOptionHandling: true,
|
||||
Suggest: true,
|
||||
}
|
||||
|
||||
err := app.Run(context.Background(), os.Args)
|
||||
if err != nil {
|
||||
fmt.Printf("error: %s", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package main
|
||||
package server
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
|
@ -1,4 +1,4 @@
|
||||
package main
|
||||
package server
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
|
@ -1,4 +1,4 @@
|
||||
package main
|
||||
package server
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
|
@ -1,4 +1,4 @@
|
||||
package main
|
||||
package server
|
||||
|
||||
import (
|
||||
"sync"
|
||||
|
@ -1,11 +1,10 @@
|
||||
package main
|
||||
package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/tls"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/coalaura/logger"
|
||||
@ -24,56 +23,37 @@ const (
|
||||
)
|
||||
|
||||
var (
|
||||
Version = "dev"
|
||||
log = logger.New().DetectTerminal().WithOptions(logger.Options{
|
||||
log *logger.Logger
|
||||
rates *RateLimiter
|
||||
challenges *cache.Cache
|
||||
sessions *cache.Cache
|
||||
)
|
||||
|
||||
func Before(ctx context.Context, _ *cli.Command) (context.Context, error) {
|
||||
log = logger.New().DetectTerminal().WithOptions(logger.Options{
|
||||
NoLevel: true,
|
||||
})
|
||||
|
||||
challenges = cache.New(10*time.Second, time.Minute)
|
||||
sessions = cache.New(10*time.Second, time.Minute)
|
||||
rates = NewRateLimiter()
|
||||
)
|
||||
rates = NewRateLimiter()
|
||||
|
||||
func init() {
|
||||
challenges = cache.New(10*time.Second, time.Minute)
|
||||
challenges.OnEvicted(func(_ string, entry interface{}) {
|
||||
challenge := entry.(internal.ChallengeEntry)
|
||||
|
||||
rates.Dec(challenge.Client)
|
||||
})
|
||||
|
||||
sessions = cache.New(10*time.Second, time.Minute)
|
||||
sessions.OnEvicted(func(_ string, entry interface{}) {
|
||||
session := entry.(internal.SessionEntry)
|
||||
|
||||
rates.Dec(session.Client)
|
||||
})
|
||||
|
||||
return ctx, nil
|
||||
}
|
||||
|
||||
func main() {
|
||||
app := &cli.Command{
|
||||
Name: "up",
|
||||
Usage: "up server",
|
||||
Version: Version,
|
||||
Flags: []cli.Flag{
|
||||
&cli.UintFlag{
|
||||
Name: "port",
|
||||
Aliases: []string{"p"},
|
||||
Usage: "custom port",
|
||||
Value: 7966,
|
||||
},
|
||||
},
|
||||
Action: run,
|
||||
EnableShellCompletion: true,
|
||||
UseShortOptionHandling: true,
|
||||
Suggest: true,
|
||||
}
|
||||
|
||||
err := app.Run(context.Background(), os.Args)
|
||||
log.MustPanic(err)
|
||||
}
|
||||
|
||||
func run(_ context.Context, cmd *cli.Command) error {
|
||||
log.Printf("up server %s\n", Version)
|
||||
|
||||
func Run(_ context.Context, cmd *cli.Command) error {
|
||||
port := cmd.Uint("port")
|
||||
if port <= 0 || port > 65534 {
|
||||
port = 7966
|
Reference in New Issue
Block a user