mirror of
https://github.com/ditatompel/xmr-remote-nodes.git
synced 2024-12-22 19:49:25 +00:00
Separating client and server package #3
The client and server package is now separated, so I can build additional server package with `-tags server`.
This commit is contained in:
parent
e0cd343be7
commit
7dea8380b8
8 changed files with 39 additions and 36 deletions
|
@ -1,4 +1,4 @@
|
|||
package cmd
|
||||
package client
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
|
@ -30,19 +30,15 @@ func newProber(cfg *config.App) *proberClient {
|
|||
return &proberClient{config: cfg}
|
||||
}
|
||||
|
||||
var probeCmd = &cobra.Command{
|
||||
var ProbeCmd = &cobra.Command{
|
||||
Use: "probe",
|
||||
Short: "Run Monero node prober",
|
||||
Run: func(_ *cobra.Command, _ []string) {
|
||||
runProbe()
|
||||
Short: "Probe remote nodes",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
RunProbe()
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(probeCmd)
|
||||
}
|
||||
|
||||
func runProbe() {
|
||||
func RunProbe() {
|
||||
cfg := config.AppCfg()
|
||||
if cfg.ServerEndpoint == "" {
|
||||
fmt.Println("Please set SERVER_ENDPOINT in .env")
|
|
@ -2,26 +2,26 @@ package cmd
|
|||
|
||||
import (
|
||||
"os"
|
||||
"xmr-remote-nodes/internal/config"
|
||||
"xmr-remote-nodes/cmd/client"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
const AppVer = "0.0.1"
|
||||
|
||||
var rootCmd = &cobra.Command{
|
||||
var Root = &cobra.Command{
|
||||
Use: "xmr-nodes",
|
||||
Short: "XMR Nodes",
|
||||
Version: AppVer,
|
||||
}
|
||||
|
||||
func Execute() {
|
||||
err := rootCmd.Execute()
|
||||
err := Root.Execute()
|
||||
if err != nil {
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
func init() {
|
||||
config.LoadAll(".env")
|
||||
Root.AddCommand(client.ProbeCmd)
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package cmd
|
||||
package server
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
|
@ -13,7 +13,7 @@ import (
|
|||
"golang.org/x/term"
|
||||
)
|
||||
|
||||
var adminCmd = &cobra.Command{
|
||||
var AdminCmd = &cobra.Command{
|
||||
Use: "admin",
|
||||
Short: "Create Admin",
|
||||
Long: `Create an admin account for WebUI access.`,
|
||||
|
@ -37,10 +37,6 @@ var adminCmd = &cobra.Command{
|
|||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(adminCmd)
|
||||
}
|
||||
|
||||
func createAdmin() error {
|
||||
admin := repo.NewAdminRepo(database.GetDB())
|
||||
a := repo.Admin{
|
|
@ -1,4 +1,4 @@
|
|||
package cmd
|
||||
package server
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
@ -25,7 +25,7 @@ type importData struct {
|
|||
DateEntered int `json:"date_entered"`
|
||||
}
|
||||
|
||||
var importCmd = &cobra.Command{
|
||||
var ImportCmd = &cobra.Command{
|
||||
Use: "import",
|
||||
Short: "Import Monero nodes from old API",
|
||||
Long: `Import Monero nodes from old API.
|
||||
|
@ -72,10 +72,6 @@ This command only available during migration process and will be removed in futu
|
|||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(importCmd)
|
||||
}
|
||||
|
||||
func (i *importClient) processData(node importData) error {
|
||||
query := `SELECT id FROM tbl_node WHERE hostname = ? AND port = ? AND protocol = ?`
|
||||
row := i.db.QueryRow(query, node.Hostname, node.Port, node.Protocol)
|
|
@ -1,4 +1,4 @@
|
|||
package cmd
|
||||
package server
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
@ -6,6 +6,7 @@ import (
|
|||
"strings"
|
||||
"text/tabwriter"
|
||||
"time"
|
||||
"xmr-remote-nodes/cmd"
|
||||
"xmr-remote-nodes/internal/database"
|
||||
"xmr-remote-nodes/internal/repo"
|
||||
|
||||
|
@ -80,7 +81,7 @@ var addProbersCmd = &cobra.Command{
|
|||
}
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(probersCmd)
|
||||
cmd.Root.AddCommand(probersCmd)
|
||||
probersCmd.AddCommand(listProbersCmd)
|
||||
probersCmd.AddCommand(addProbersCmd)
|
||||
listProbersCmd.Flags().StringP("sort-by", "s", "last_submit_ts", "Sort by column name, can be id or last_submit_ts")
|
|
@ -1,4 +1,4 @@
|
|||
package cmd
|
||||
package server
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
@ -21,7 +21,7 @@ import (
|
|||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var serveCmd = &cobra.Command{
|
||||
var ServeCmd = &cobra.Command{
|
||||
Use: "serve",
|
||||
Short: "Serve the WebUI",
|
||||
Long: `This command will run HTTP server for APIs and WebUI.`,
|
||||
|
@ -30,10 +30,6 @@ var serveCmd = &cobra.Command{
|
|||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(serveCmd)
|
||||
}
|
||||
|
||||
func serve() {
|
||||
appCfg := config.AppCfg()
|
||||
// connect to DB
|
||||
|
@ -105,6 +101,6 @@ func fiberConfig() fiber.Config {
|
|||
return fiber.Config{
|
||||
Prefork: config.AppCfg().Prefork,
|
||||
ProxyHeader: config.AppCfg().ProxyHeader,
|
||||
AppName: "ditatompel's XMR Nodes HTTP server " + AppVer,
|
||||
AppName: "ditatompel's XMR Nodes HTTP server",
|
||||
}
|
||||
}
|
6
main.go
6
main.go
|
@ -1,7 +1,11 @@
|
|||
package main
|
||||
|
||||
import "xmr-remote-nodes/cmd"
|
||||
import (
|
||||
"xmr-remote-nodes/cmd"
|
||||
"xmr-remote-nodes/internal/config"
|
||||
)
|
||||
|
||||
func main() {
|
||||
config.LoadAll(".env")
|
||||
cmd.Execute()
|
||||
}
|
||||
|
|
14
server.go
Normal file
14
server.go
Normal file
|
@ -0,0 +1,14 @@
|
|||
//go:build server
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"xmr-remote-nodes/cmd"
|
||||
"xmr-remote-nodes/cmd/server"
|
||||
)
|
||||
|
||||
func init() {
|
||||
cmd.Root.AddCommand(server.AdminCmd)
|
||||
cmd.Root.AddCommand(server.ServeCmd)
|
||||
cmd.Root.AddCommand(server.ImportCmd)
|
||||
}
|
Loading…
Reference in a new issue