Finalize whole implementation
parent
6081a6a7c2
commit
742ccbaa79
@ -1,12 +1,12 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/creekorful/trandoshan/internal/feeder"
|
||||
"github.com/creekorful/trandoshan/internal/trandoshanctl"
|
||||
"os"
|
||||
)
|
||||
|
||||
func main() {
|
||||
app := feeder.GetApp()
|
||||
app := trandoshanctl.GetApp()
|
||||
if err := app.Run(os.Args); err != nil {
|
||||
os.Exit(1)
|
||||
}
|
@ -1,49 +0,0 @@
|
||||
package feeder
|
||||
|
||||
import (
|
||||
"github.com/creekorful/trandoshan/api"
|
||||
"github.com/creekorful/trandoshan/internal/util/logging"
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
// GetApp return the feeder app
|
||||
func GetApp() *cli.App {
|
||||
return &cli.App{
|
||||
Name: "tdsh-feeder",
|
||||
Version: "0.3.0",
|
||||
Usage: "Trandoshan feeder process",
|
||||
Flags: []cli.Flag{
|
||||
logging.GetLogFlag(),
|
||||
&cli.StringFlag{
|
||||
Name: "api-uri",
|
||||
Usage: "URI to the API server",
|
||||
Required: true,
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "url",
|
||||
Usage: "URL to send to the crawler",
|
||||
Required: true,
|
||||
},
|
||||
},
|
||||
Action: execute,
|
||||
}
|
||||
}
|
||||
|
||||
func execute(ctx *cli.Context) error {
|
||||
logging.ConfigureLogger(ctx)
|
||||
|
||||
log.Info().Str("ver", ctx.App.Version).Msg("Starting tdsh-feeder")
|
||||
|
||||
log.Debug().Str("uri", ctx.String("api-uri")).Msg("Using API server")
|
||||
|
||||
apiClient := api.NewClient(ctx.String("api-uri"))
|
||||
if err := apiClient.AddURL(ctx.String("url")); err != nil {
|
||||
log.Err(err).Msg("Unable to publish URL")
|
||||
return err
|
||||
}
|
||||
|
||||
log.Info().Str("url", ctx.String("url")).Msg("URL successfully sent to the crawler")
|
||||
|
||||
return nil
|
||||
}
|
@ -0,0 +1,58 @@
|
||||
package trandoshanctl
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/creekorful/trandoshan/api"
|
||||
"github.com/creekorful/trandoshan/internal/util/logging"
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
// GetApp returns the Trandoshan CLI app
|
||||
func GetApp() *cli.App {
|
||||
return &cli.App{
|
||||
Name: "trandoshanctl",
|
||||
Version: "0.3.0",
|
||||
Usage: "Trandoshan CLI",
|
||||
Flags: []cli.Flag{
|
||||
logging.GetLogFlag(),
|
||||
&cli.StringFlag{
|
||||
Name: "api-uri",
|
||||
Usage: "URI to the API server",
|
||||
Value: "http://localhost:15005",
|
||||
},
|
||||
},
|
||||
Commands: []*cli.Command{
|
||||
{
|
||||
Name: "schedule",
|
||||
Usage: "Schedule crawling for given URL",
|
||||
Action: schedule,
|
||||
ArgsUsage: "URL",
|
||||
},
|
||||
},
|
||||
Before: before,
|
||||
}
|
||||
}
|
||||
|
||||
func before(ctx *cli.Context) error {
|
||||
logging.ConfigureLogger(ctx)
|
||||
return nil
|
||||
}
|
||||
|
||||
func schedule(c *cli.Context) error {
|
||||
if c.NArg() == 0 {
|
||||
return fmt.Errorf("missing argument URL")
|
||||
}
|
||||
|
||||
url := c.Args().First()
|
||||
apiClient := api.NewClient(c.String("api-uri"))
|
||||
|
||||
if err := apiClient.ScheduleURL(url); err != nil {
|
||||
log.Err(err).Str("url", url).Msg("Unable to schedule crawling for URL")
|
||||
return err
|
||||
}
|
||||
|
||||
log.Info().Str("url", url).Msg("Successfully schedule crawling")
|
||||
|
||||
return nil
|
||||
}
|
Loading…
Reference in New Issue