diff --git a/deployment.yml b/deployment.yml index 4731502b51512b844554822b2d84f28b0b824130..721baa73a2915b01ec85627306c6e4e841613fc7 100644 --- a/deployment.yml +++ b/deployment.yml @@ -17,6 +17,10 @@ spec: labels: app: demo-openshift spec: + volumes: + - name: data + persistentVolumeClaim: + claimName: pvc-01-ns-demo-d01-claim containers: - name: demo-openshift-app image: registry.forge.grandlyon.com/npernoud/demo-openshift:latest @@ -40,6 +44,9 @@ spec: limits: memory: "128Mi" cpu: 500m + volumeMounts: + - mountPath: "/app/data" + name: "data" imagePullSecrets: - name: forge-secret --- diff --git a/main.go b/main.go index 4ebe24dd7e94a16c41a1cd77e80a5549172dcb79..b65814d6f7902e136c8fe1e9030b5c7cae6d4b7b 100644 --- a/main.go +++ b/main.go @@ -4,12 +4,32 @@ import ( "fmt" "log" "net/http" + "os" + "strings" ) func main() { // API routes http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { - fmt.Fprintf(w, "Bonjour la Métropole du Grand Lyon") + fmt.Fprintf(w, "Hello world") + }) + + http.HandleFunc("/writefile/", func(w http.ResponseWriter, r *http.Request) { + // create the file + f, err := os.Create("data/test.txt") + if err != nil { + fmt.Println(err) + } + // close the file with defer + defer f.Close() + + // write a string + str := strings.TrimPrefix(r.URL.Path, "/writefile/") + f.WriteString("Donnée enregistrée : " + str) + }) + + http.HandleFunc("/readfile/", func(w http.ResponseWriter, r *http.Request) { + http.ServeFile(w, r, "data/test.txt") }) port := ":8080"