github.com/ronaksoft/rony@v0.16.26-0.20230807065236-1743dbfe6959/example/echo/cmd/cli-echo/main.go (about)

     1  package main
     2  
     3  import (
     4  	"fmt"
     5  	"time"
     6  
     7  	"go.opentelemetry.io/otel/sdk/resource"
     8  	semconv "go.opentelemetry.io/otel/semconv/v1.7.0"
     9  
    10  	"github.com/ronaksoft/rony/config"
    11  	"github.com/ronaksoft/rony/tools"
    12  	"github.com/spf13/cobra"
    13  	"go.opentelemetry.io/otel"
    14  	"go.opentelemetry.io/otel/exporters/jaeger"
    15  	"go.opentelemetry.io/otel/sdk/trace"
    16  )
    17  
    18  func main() {
    19  	// Define the configs if this executable is running as a server instance
    20  	// Set the flags as config parameters
    21  	config.SetCmdFlags(ServerCmd,
    22  		config.StringFlag("server.id", tools.RandomID(12), ""),
    23  		config.StringFlag("gateway.listen", "0.0.0.0:80", ""),
    24  		config.StringSliceFlag("gateway.advertise.url", nil, ""),
    25  		config.StringFlag("tunnel.listen", "0.0.0.0:81", ""),
    26  		config.StringSliceFlag("tunnel.advertise.url", nil, ""),
    27  		config.DurationFlag("idle-time", time.Minute, ""),
    28  		config.IntFlag("raft.port", 7080, ""),
    29  		config.Uint64Flag("replica-set", 1, ""),
    30  		config.IntFlag("gossip.port", 7081, ""),
    31  		config.StringFlag("data.path", "./_hdd", ""),
    32  		config.BoolFlag("bootstrap", false, ""),
    33  	)
    34  
    35  	// Define the configs if this executable is running as a server instance
    36  	config.SetCmdFlags(ClientCmd,
    37  		config.StringFlag("host", "127.0.0.1", "the host of the seed server"),
    38  		config.IntFlag("port", 80, "the port of the seed server"),
    39  	)
    40  
    41  	RootCmd.AddCommand(ServerCmd, ClientCmd)
    42  
    43  	if err := RootCmd.Execute(); err != nil {
    44  		fmt.Println("we got error:", err)
    45  	}
    46  }
    47  
    48  func initTracer() *trace.TracerProvider {
    49  	if jaegerURL := config.GetString("jaeger.url"); jaegerURL != "" {
    50  		exp, err := jaeger.New(
    51  			jaeger.WithCollectorEndpoint(
    52  				jaeger.WithEndpoint("http://localhost:14268/api/traces"),
    53  			),
    54  		)
    55  		if err != nil {
    56  			panic(err)
    57  		}
    58  
    59  		tp := trace.NewTracerProvider(
    60  			trace.WithBatcher(exp),
    61  			trace.WithResource(
    62  				resource.NewWithAttributes(
    63  					semconv.SchemaURL,
    64  					semconv.ServiceNameKey.String("Echo"),
    65  				),
    66  			),
    67  		)
    68  		otel.SetTracerProvider(tp)
    69  
    70  		return tp
    71  	}
    72  
    73  	return nil
    74  }
    75  
    76  var RootCmd = &cobra.Command{
    77  	Use: "echo",
    78  }