cmd

package
v1.0.0-beta.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 16, 2018 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CreateDomain = &cobra.Command{
	Use:   "create-domain",
	Short: "Creates new domain",
	Run: func(cmd *cobra.Command, args []string) {
		var opts []grpc.CallOption
		var err error

		if len(args) == 0 {
			return
		}

		d := &pb.Domain{
			Name: args[0],
			Type: defaultDomainType,
		}

		if enableWildcard {
			d.Type = pb.Domain_WILDCARD
		}

		r := &pb.Redirect{}

		if url != "" {
			m := &pb.Redirect_Match{
				Path: path,
				Type: pb.Redirect_Match_WILDCARD,
			}

			t := &pb.Redirect_Target{
				Url:        url,
				Parameters: params,
				Code:       pb.HTTPStatusCode(statusCode),
			}

			r.Match = m
			r.Target = t
		}

		d.Redirects = []*pb.Redirect{r}

		dial, err := dialer.NewDialer(config.C)
		if err != nil {
			log.Fatal(err)
		}
		defer dial.Close()

		ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
		defer cancel()

		if len(args) == 0 {
			log.Fatal(ErrNoDomain)
		}

		client := pb.NewOutlawClient(dial)
		in := &pb.CreateDomainRequest{Domain: d}

		resp, err := client.CreateDomain(ctx, in, opts...)
		if err != nil {
			log.Fatal(err)
		}

		log.Printf("%s", resp.Domain.GetUuid())
	},
}
View Source
var DeleteDomain = &cobra.Command{
	Use:   "delete-domain",
	Short: "Deletes a domain",
	Run: func(cmd *cobra.Command, args []string) {
		var opts []grpc.CallOption
		var err error

		dial, err := dialer.NewDialer(config.C)
		if err != nil {
			log.Fatal(err)
		}
		defer dial.Close()

		ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
		defer cancel()

		client := pb.NewOutlawClient(dial)
		in := &pb.DeleteDomainRequest{Domain: &pb.Domain{
			Name: args[0],
		}}

		resp, err := client.DeleteDomain(ctx, in, opts...)
		if err != nil {
			log.Fatal(err)
		}

		log.Printf("%s", resp.Domain.GetUuid())
	},
}
View Source
var (
	ErrNoDomain = errors.New("no domain provided")
)
View Source
var GetDomain = &cobra.Command{
	Use:   "get-domain",
	Short: "Get domain",
	Run: func(cmd *cobra.Command, args []string) {
		var opts []grpc.CallOption
		var err error

		dial, err := dialer.NewDialer(config.C)
		if err != nil {
			log.Fatal(err)
		}
		defer dial.Close()

		ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
		defer cancel()

		client := pb.NewOutlawClient(dial)
		in := &pb.GetDomainRequest{Domain: &pb.Domain{
			Name: args[0],
		}}

		resp, err := client.GetDomain(ctx, in, opts...)
		if err != nil {
			log.Fatal(err)
		}

		pretty.Println(resp.Domain)
	},
}
View Source
var ListDomains = &cobra.Command{
	Use:   "list-domains",
	Short: "Lists domains",
	Run: func(cmd *cobra.Command, args []string) {
		var opts []grpc.CallOption
		var err error

		dial, err := dialer.NewDialer(config.C)
		if err != nil {
			log.Fatal(err)
		}
		defer dial.Close()

		ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
		defer cancel()

		client := pb.NewOutlawClient(dial)
		in := &pb.ListDomainsRequest{}

		resp, err := client.ListDomains(ctx, in, opts...)
		if err != nil {
			log.Fatal(err)
		}

		log.Println(resp.Domains)
	},
}

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL