Exemplo n.º 1
0
func (c *AppContext) ui(w http.ResponseWriter, r *http.Request) {
	log.Println(REGISTRY_HOST_ADDR)
	log.Println(REGISTRY_PORT_ADDR)
	url := fmt.Sprintf("http://%s:%s/v2/_catalog", REGISTRY_HOST_ADDR, REGISTRY_PORT_ADDR)
	resp, err := http.Get(url)
	if err != nil {
		log.Println(err)
		return
	}
	if resp.StatusCode != 200 {
		log.Println(resp.Status)
		str, err := ioutil.ReadAll(resp.Body)
		if err != nil {
			return
		}
		log.Println(string(str))
	}
	var catalog Catalog
	decoder := json.NewDecoder(resp.Body)
	err = decoder.Decode(&catalog)
	if err != nil {
		return
	}
	context.Set(r, "repositories", catalog.Repositories)
	ctx, ok := context.GetAllOk(r)
	if !ok {
		return
	}
	yield.HTML(w, http.StatusOK, "index", ctx, c.layout)
}
Exemplo n.º 2
0
func (c *AppContext) loginHandler(w http.ResponseWriter, r *http.Request) {
	ctx, ok := context.GetAllOk(r)
	if !ok {
		return
	}
	yield.HTML(w, http.StatusOK, "login", ctx, c.layout)
}
Exemplo n.º 3
0
func (c *AppContext) newUser(w http.ResponseWriter, r *http.Request) {
	ctx, ok := context.GetAllOk(r)
	if !ok {
		return
	}
	yield.HTML(w, http.StatusOK, "users/new", ctx, c.layout)
}
Exemplo n.º 4
0
func (c *AppContext) repoShow(w http.ResponseWriter, r *http.Request) {
	name := mux.Vars(r)["name"]
	url := fmt.Sprintf("http://%s:%s/v2/%s/tags/list",
		REGISTRY_HOST_ADDR,
		REGISTRY_PORT_ADDR,
		name)
	resp, err := http.Get(url)
	if err != nil {
		log.Println(err)
		return
	}
	if resp.StatusCode != 200 {
		log.Println(resp.Status)
		str, err := ioutil.ReadAll(resp.Body)
		if err != nil {
			return
		}
		log.Println(string(str))
	}
	var tagList TagList
	decoder := json.NewDecoder(resp.Body)
	err = decoder.Decode(&tagList)
	if err != nil {
		return
	}
	context.Set(r, "tagList", tagList)
	ctx, ok := context.GetAllOk(r)
	if !ok {
		return
	}
	yield.HTML(w, http.StatusOK, "show", ctx, c.layout)
}
Exemplo n.º 5
0
func (c *AppContext) users(w http.ResponseWriter, r *http.Request) {
	var users []string
	err := c.db.View(func(tx *bolt.Tx) error {
		b := tx.Bucket([]byte("auth"))
		b.ForEach(func(k, v []byte) error {
			users = append(users, string(k))
			return nil
		})
		return nil
	})
	if err != nil {
		log.Println(err)
		return
	}
	context.Set(r, "users", users)
	ctx, ok := context.GetAllOk(r)
	if !ok {
		return
	}
	yield.HTML(w, http.StatusOK, "users/index", ctx, c.layout)
}