Skip to content

Commit

Permalink
Merge pull request #317 from gaohan085/dev
Browse files Browse the repository at this point in the history
update & fix go program flag usage
  • Loading branch information
gaohan085 authored Nov 13, 2024
2 parents 900ba8b + 7f3d2e1 commit 3ca7f3c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 52 deletions.
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@ make && make build
#### Usage

```bash
videoserver-0.7.0.1-linux-amd64 usage -ffmpeg -pro # As ffmpeg server in production mode
videoserver-0.7.0.1-linux-amd64 -usage=ffmpeg # As ffmpeg server in production mode
```

```bash
videoserver-0.7.0.1-linux-amd64 usage -pro # As main video server in production mode
videoserver-0.7.0.1-linux-amd64 -usage=pro # As main video server in production mode
```

```bash
videoserver-0.7.0.1-linux-amd64 usage -dev # As main video server in development mode
videoserver-0.7.0.1-linux-amd64 -usage=dev -file=remote # As main video server in development mode and get file information from remote server
```
```bash
videoserver-0.7.0.1-linux-amd64 -usage=dev -file=local # As main video server in development mode and get file information from local path
```
54 changes: 6 additions & 48 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,55 +27,13 @@ var content embed.FS
// main usage -ffmpeg -pro

func Parseflag() {
usage := flag.NewFlagSet("usage", flag.ExitOnError)
usageFFmpeg := usage.Bool("ffmpeg", false, "-ffmpeg use as ffmpeg server, not provide as main server")
usageIsDev := usage.Bool("dev", false, "'-dev' use as development server and '-pro' use as production server")
usageIsPro := usage.Bool("pro", false, "'-dev' use as development server and '-pro' use as production server")
usageIsLocal := usage.Bool("local", false, "-local to show local file")
usageIsRemote := usage.Bool("remote", false, "-remote to get file info from remote")

if len(os.Args) <= 1 {
log.Panic("expected 'usage' commands")
}
usage := flag.String("usage", "dev", "Web server usage, can be 'pro' 'dev' or 'ffmpeg'. Default: dev")
file := flag.String("file", "local", "Where to get file information, can be 'local' or 'remote'. Default: local")

switch os.Args[1] {
case "usage":
usage.Parse(os.Args[2:])
if *usageFFmpeg {
os.Setenv("USAGE", "ffmpeg")
} else {
os.Setenv("USAGE", "main")
}

if *usageIsDev && *usageIsPro {
log.Panic("'-dev' and '-pro' cannot be provided at same time.")
}

if *usageIsDev {
os.Setenv("ENV", "dev")

if !*usageIsLocal && !*usageIsRemote {
log.Panic("Please provide file location '-local' or '-remote'")
}
}

if *usageIsPro {
os.Setenv("ENV", "pro")
}

if *usageIsLocal && *usageIsRemote {
log.Panic("'-local' and '-remote' cannot provide at same time.")
}

if *usageIsLocal {
os.Setenv("FILELOCATION", "local")
}
if *usageIsRemote {
os.Setenv("FILELOCATION", "remote")
}
default:
log.Panic("expect command 'usage'")
}
flag.Parse()

os.Setenv("USAGE", *usage)
os.Setenv("FileLocation", *file)
}

func main() {
Expand Down
2 changes: 1 addition & 1 deletion routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func SetRoutes(app *fiber.App) {
api.Get("/actress/:name", handlers.GetVideosByActress)
api.Post("/convert", handlers.ConvertHandler)

switch os.Getenv("FILELOCATION") {
switch os.Getenv("FileLocation") {
case "local":
api.Get("/*", handlers.FileReaderHandler)

Expand Down

0 comments on commit 3ca7f3c

Please sign in to comment.