Skip to content
This repository was archived by the owner on Jul 18, 2025. It is now read-only.

Commit 66ee35d

Browse files
authored
Merge pull request #377 from vdemeester/add-godoc
Add package doc for the root package…
2 parents df53244 + cc43dfd commit 66ee35d

2 files changed

Lines changed: 56 additions & 0 deletions

File tree

doc.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,9 @@
1+
// Package app provides experimental utilities to make Compose files more
2+
// reusable and sharable.
3+
//
4+
// The `cmd/docker-app` package generates the `docker-app` binary,
5+
// see https://github.com/docker/app for more information about it.
6+
//
7+
// It can also be used as a library to be integrated in your tools.
8+
// Usage examples are provided inline with their full documentation.
19
package app

examples_test.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package app
2+
3+
import (
4+
"fmt"
5+
"os"
6+
7+
"github.com/docker/app/loader"
8+
"github.com/docker/app/render"
9+
yaml "gopkg.in/yaml.v2"
10+
)
11+
12+
func Example() {
13+
// Load the file (single-file format, there is multiple format)
14+
f, err := os.Open("./examples/hello-world/hello-world.dockerapp")
15+
if err != nil {
16+
panic("cannot read application")
17+
}
18+
defer f.Close()
19+
app, err := loader.LoadFromSingleFile("myApp", f)
20+
if err != nil {
21+
panic("cannot load application")
22+
}
23+
// Render the app to a composefile format, using some user provided settings
24+
c, err := render.Render(app, map[string]string{
25+
"text": "hello examples!",
26+
})
27+
if err != nil {
28+
panic("cannot render application")
29+
}
30+
// Marshal it to yaml (to display it)
31+
s, err := yaml.Marshal(c)
32+
if err != nil {
33+
panic("cannot marshall the composefile in yaml")
34+
}
35+
fmt.Print(string(s))
36+
// Output: version: "3.6"
37+
// services:
38+
// hello:
39+
// command:
40+
// - -text
41+
// - hello examples!
42+
// image: hashicorp/http-echo
43+
// ports:
44+
// - mode: ingress
45+
// target: 5678
46+
// published: 8080
47+
// protocol: tcp
48+
}

0 commit comments

Comments
 (0)