Skip to content

Commit

Permalink
Move nconnect codes into methods of nconnect struct
Browse files Browse the repository at this point in the history
Signed-off-by: bill fort <fxbao@hotmail.com>
  • Loading branch information
billfort authored and yilunzhang committed Apr 25, 2023
1 parent f1842ee commit cf3c932
Show file tree
Hide file tree
Showing 5 changed files with 271 additions and 201 deletions.
35 changes: 32 additions & 3 deletions bin/main.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package main

import (
"fmt"
"log"
"os"
"os/signal"
"syscall"

"github.com/jessevdk/go-flags"
"github.com/nknorg/nconnect"
Expand All @@ -16,13 +19,39 @@ func main() {
}
}()

var opts config.Opts
_, err := flags.Parse(&opts)
var opts = &config.Opts{}
_, err := flags.Parse(opts)
if err != nil {
if flagsErr, ok := err.(*flags.Error); ok && flagsErr.Type == flags.ErrHelp {
os.Exit(0)
}
log.Fatal(err)
}
nconnect.Run(&opts)

if opts.Version {
fmt.Println(config.Version)
os.Exit(0)
}

nc, err := nconnect.NewNconnect(opts)
if err != nil {
log.Fatal(err)
}

if opts.Client {
err = nc.StartClient()
if err != nil {
log.Fatal(err)
}
}
if opts.Server {
err = nc.StartServer()
if err != nil {
log.Fatal(err)
}
}

sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
<-sigs
}
3 changes: 0 additions & 3 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (

"github.com/nknorg/nconnect/util"
"github.com/nknorg/nkn/v2/common"
"github.com/nknorg/tuna/types"
)

const (
Expand Down Expand Up @@ -45,8 +44,6 @@ type Opts struct {
Address bool `long:"address" description:"Print client address (client mode) or admin address (server mode)"`
WalletAddress bool `long:"wallet-address" description:"Print wallet address (server only)"`
Version bool `long:"version" description:"Print version"`

TunaNode *types.Node
}

type Config struct {
Expand Down
Loading

0 comments on commit cf3c932

Please sign in to comment.