Exemplo n.º 1
0
func httpDomains(c *echo.Context) error {
	r := c.Request()
	e := c.Get("engine").(storage.Engine)

	domain := "origins.domains"

	iter, code, err := domainIteratorResource(domain, r, e)

	// Special case, just show an empty list.
	if err == view.ErrDoesNotExist {
		return c.JSON(http.StatusOK, []string{})
	}

	if err != nil {
		return c.JSON(code, map[string]interface{}{
			"error": fmt.Sprint(err),
		})
	}

	// Extract the domain names.
	idents, err := origins.Entities(iter)

	if err != nil {
		return c.JSON(code, map[string]interface{}{
			"error": fmt.Sprint(err),
		})
	}

	names := make([]string, len(idents))

	for i, id := range idents {
		names[i] = id.Name
	}

	return c.JSON(http.StatusOK, names)
}
Exemplo n.º 2
0
func httpDomainEntities(c *echo.Context) error {
	r := c.Request()
	e := c.Get("engine").(storage.Engine)

	domain := c.Param("domain")

	iter, code, err := domainIteratorResource(domain, r, e)

	if err != nil {
		return c.JSON(code, map[string]interface{}{
			"error": fmt.Sprint(err),
		})
	}

	idents, err := origins.Entities(iter)

	if err != nil {
		return c.JSON(code, map[string]interface{}{
			"error": fmt.Sprint(err),
		})
	}

	return c.JSON(http.StatusOK, idents)
}
Exemplo n.º 3
0
	Use: "domains",

	Short: "Outputs a list of domains.",

	Run: func(cmd *cobra.Command, args []string) {
		bindStorageFlags(cmd.Flags())

		engine := initStorage()

		log, err := view.OpenLog(engine, origins.DomainsDomain, "commit")

		if err != nil {
			logrus.Fatal(err)
		}

		idents, err := origins.Entities(log.Now())

		if err != nil {
			logrus.Fatal(err)
		}

		sort.Sort(idents)

		for _, ident := range idents {
			os.Stdout.Write([]byte(ident.Name + "\n"))
		}
	},
}

func init() {
	flags := domainsCmd.Flags()