Beispiel #1
0
func NewSever() *Server {
	info := meta.NewInfo(config.Config.Etcd.EtcdAddr)
	return &Server{
		sessions:  safemap.NewMap(),
		addr:      config.Config.Server.ListenAddr,
		info:      info,
		ddlManage: ddl.NewManage(config.Config.Etcd.EtcdAddr, config.Config.Server.RPCAddr, info),
		bpool:     NewBpool(),
		metaCahe:  NewMetaCache(info),
	}
}
Beispiel #2
0
func init() {
	RootCmd.AddCommand(adminCmd)
	adminCmd.AddCommand(addUserCmd)
	addUserCmd.Flags().StringVar(&etcd, "etcd", "http://localhost:2379", "etcd machines (default is http://localhost:2379)")
}

var etcd string

var addUserCmd = &cobra.Command{
	Use:     "addUser",
	Short:   "add user",
	Example: "rambo admin addUser user 123",
	Run: func(cmd *cobra.Command, args []string) {
		if len(args) != 2 {
			panic("bad input")
		}
		manage := admin.NewAdmin(meta.NewInfo(strings.Split(etcd, ",")))
		if err := manage.AddUser(args[0], args[1]); err != nil {
			fmt.Println(err)
			os.Exit(1)
		}
		result, err := manage.GetUser(args[0])
		if err != nil {
			fmt.Println(err)
			os.Exit(1)
		}
		fmt.Println(result)
	},
}