This repository has been archived by the owner on May 25, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
images.go
81 lines (68 loc) · 2.1 KB
/
images.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// Copyright (C) 2020, Oracle and/or its affiliates.
// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
package images
import (
"encoding/json"
"net/http"
"strconv"
"github.com/golang/glog"
"github.com/gorilla/mux"
)
// This file is very similar to applications.go - please see comments there
// which equally apply to this file
// Image is a structure providing the image metadata
type Image struct {
ID string `json:"id"`
Format string `json:"format"`
WebLogicVersion string `json:"weblogic_version"`
JDKVersion string `json:"jdk_version"`
WebLogicPSU string `json:"weblogic_psu"`
Patches string `json:"patches"`
Name string `json:"name"`
Tag string `json:"tag"`
Description string `json:"description"`
Status string `json:"status"`
}
// Images is the available set of images
var Images []Image
// Init creates an empty slice of images
func Init() {
Images = []Image{}
//Images = []Image{
// Image{
// Id: "1",
// Format: "docker",
// WebLogicVersion: "12.2.1.3.0",
// JDKVersion: "8u161",
// WebLogicPSU: "OCT PSU",
// Patches: "28186730,28298734,28076014",
// Name: "container-registry.oracle.com/weblogicdev/my-great-domain",
// Tag: "1.0",
// Description: "WebLogic image with my domain in it",
// Status: "PROVISIONING",
// },
//}
}
// ReturnAllImages returns all images available
func ReturnAllImages(w http.ResponseWriter, r *http.Request) {
glog.V(4).Info("GET /images")
w.Header().Set("X-Total-Count", strconv.FormatInt(int64(len(Images)), 10))
json.NewEncoder(w).Encode(Images)
}
// ReturnSingleImage returns the image identified by the supplied key. If no image
// is found, sets the 404/NotFound HTTP status header
func ReturnSingleImage(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
key := vars["id"]
glog.V(4).Info("GET /images/" + key)
found := false
for _, images := range Images {
if images.ID == key {
found = true
json.NewEncoder(w).Encode(images)
}
}
if !found {
w.WriteHeader(http.StatusNotFound)
}
}