forked from cgzirim/seek-tune
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
64 lines (58 loc) · 1.45 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package main
import (
"context"
"flag"
"fmt"
"log/slog"
"os"
"song-recognition/utils"
"github.com/mdobak/go-xerrors"
)
func main() {
err := utils.CreateFolder("tmp")
if err != nil {
logger := utils.GetLogger()
err := xerrors.New(err)
ctx := context.Background()
logger.ErrorContext(ctx, "Failed create tmp dir.", slog.Any("error", err))
}
err = utils.CreateFolder(SONGS_DIR)
if err != nil {
err := xerrors.New(err)
logger := utils.GetLogger()
ctx := context.Background()
logMsg := fmt.Sprintf("failed to create directory %v", SONGS_DIR)
logger.ErrorContext(ctx, logMsg, slog.Any("error", err))
}
if len(os.Args) < 2 {
fmt.Println("Expected 'find', 'download', 'erase', or 'serve' subcommands")
os.Exit(1)
}
switch os.Args[1] {
case "find":
if len(os.Args) < 3 {
fmt.Println("Usage: main.go find <path_to_wav_file>")
os.Exit(1)
}
filePath := os.Args[2]
find(filePath)
case "download":
if len(os.Args) < 3 {
fmt.Println("Usage: main.go download <spotify_url>")
os.Exit(1)
}
url := os.Args[2]
download(url)
case "serve":
serveCmd := flag.NewFlagSet("serve", flag.ExitOnError)
protocol := serveCmd.String("proto", "http", "Protocol to use (http or https)")
port := serveCmd.String("p", "5000", "Port to use")
serveCmd.Parse(os.Args[2:])
serve(*protocol, *port)
case "erase":
erase(SONGS_DIR)
default:
fmt.Println("Expected 'find', 'download', 'erase', or 'serve' subcommands")
os.Exit(1)
}
}