<commit_before>package main

import (
	"fmt"
	"log"
	"net"
	"os"
	"strings"

	"github.com/n0stack/n0core/datastore/etcd"
	"github.com/n0stack/n0core/provisioning/node"
	pprovisioning "github.com/n0stack/proto.go/provisioning/v0"

	"github.com/urfave/cli"
	"google.golang.org/grpc"
	"google.golang.org/grpc/reflection"
)

func main() {
	app := cli.NewApp()
	app.Name = "n0core API"
	// app.Usage = ""
	app.Version = "0.1.0" // CIで取るようにする

	// command action
	app.Commands = []cli.Command{
		{
			Name:  "serve",
			Usage: "Join to API and serve some daemons.",
			Action: func(c *cli.Context) error {
				var err error
				e, err := etcd.NewEtcdDatastore("node", strings.Split(c.String("etcd-endpoints"), ","))
				if err != nil {
					return err
				}

				lis, err := net.Listen("tcp", fmt.Sprintf("%s:%d", c.String("bind-address"), c.Int("bind-port")))
				if err != nil {
					return err
				}

				s := grpc.NewServer()

				// starterをsliceでとったほうがいいかもしれない
				n, err := node.CreateNodeAPI(e, c.String("memberlist-starter"))
				if err != nil {
					return err
					fmt.Printf("%v", err.Error())

				}

				pprovisioning.RegisterNodeServiceServer(s, n)
				reflection.Register(s)

				log.Printf("[INFO] Starting API")
				if err := s.Serve(lis); err != nil {
					return err
				}

				return nil
			},
			Flags: []cli.Flag{
				cli.StringFlag{
					Name: "etcd-endpoints",
				},
				cli.StringFlag{
					// interfaceからも取れるようにしたい
					Name:  "bind-address",
					Value: "0.0.0.0",
				},
				cli.IntFlag{
					Name:  "bind-port",
					Value: 20180,
				},
			},
		},
	}

	if err := app.Run(os.Args); err != nil {
		log.Fatalf("Failed to start process, err:%v", err.Error())<commit_msg>close etcd connection<commit_after>package main

import (
	"fmt"
	"log"
	"net"
	"os"
	"strings"

	"github.com/n0stack/n0core/datastore/etcd"
	"github.com/n0stack/n0core/provisioning/node"
	pprovisioning "github.com/n0stack/proto.go/provisioning/v0"

	"github.com/urfave/cli"
	"google.golang.org/grpc"
	"google.golang.org/grpc/reflection"
)

func main() {
	app := cli.NewApp()
	app.Name = "n0core API"
	// app.Usage = ""
	app.Version = "0.1.0" // CIで取るようにする

	app.Commands = []cli.Command{
		{
			Name:  "serve",
			Usage: "Join to API and serve some daemons.",
			Action: func(c *cli.Context) error {
				var err error
				e, err := etcd.NewEtcdDatastore("node", strings.Split(c.String("etcd-endpoints"), ","))
				if err != nil {
					return err
				}
				defer e.Close()

				lis, err := net.Listen("tcp", fmt.Sprintf("%s:%d", c.String("bind-address"), c.Int("bind-port")))
				if err != nil {
					return err
				}

				s := grpc.NewServer()

				// starterをsliceでとったほうがいいかもしれない
				n, err := node.CreateNodeAPI(e, c.String("memberlist-starter"))
				if err != nil {
					return err
				}

				pprovisioning.RegisterNodeServiceServer(s, n)
				reflection.Register(s)

				log.Printf("[INFO] Starting API")
				return s.Serve(lis)
			},
			Flags: []cli.Flag{
				cli.StringFlag{
					Name: "etcd-endpoints",
				},
				cli.StringFlag{
					// interfaceからも取れるようにしたい
					Name:  "bind-address",
					Value: "0.0.0.0",
				},
				cli.IntFlag{
					Name:  "bind-port",
					Value: 20180,
				},
			},
		},
	}

	if err := app.Run(os.Args); err != nil {
		log.Fatalf("Failed to start process, err:%v", err.Error())
{'fraction_non_alphanumeric': 0.1732283464566929, 'fraction_numerical': 0.01150817686250757, 'mean_word_length': 2.7491486946651533, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1302933', 'n_tokens_mistral': 1604, 'n_tokens_neox': 1303, 'n_words': 238}