Add package doc for the root package…

… and an example showing one usage of it as a library.
The example is executable *and* will be tested when running `go test`.

Signed-off-by: Vincent Demeester <vincent@sbr.pm>
This commit is contained in:
Vincent Demeester 2018-09-06 16:39:39 +02:00
Родитель b84d35f884
Коммит cc43dfd057
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 083CC6FD6EB699A3
2 изменённых файлов: 56 добавлений и 0 удалений

8
doc.go
Просмотреть файл

@ -1 +1,9 @@
// Package app provides experimental utilities to make Compose files more
// reusable and sharable.
//
// The `cmd/docker-app` package generates the `docker-app` binary,
// see https://github.com/docker/app for more information about it.
//
// It can also be used as a library to be integrated in your tools.
// Usage examples are provided inline with their full documentation.
package app

48
examples_test.go Normal file
Просмотреть файл

@ -0,0 +1,48 @@
package app
import (
"fmt"
"os"
"github.com/docker/app/loader"
"github.com/docker/app/render"
yaml "gopkg.in/yaml.v2"
)
func Example() {
// Load the file (single-file format, there is multiple format)
f, err := os.Open("./examples/hello-world/hello-world.dockerapp")
if err != nil {
panic("cannot read application")
}
defer f.Close()
app, err := loader.LoadFromSingleFile("myApp", f)
if err != nil {
panic("cannot load application")
}
// Render the app to a composefile format, using some user provided settings
c, err := render.Render(app, map[string]string{
"text": "hello examples!",
})
if err != nil {
panic("cannot render application")
}
// Marshal it to yaml (to display it)
s, err := yaml.Marshal(c)
if err != nil {
panic("cannot marshall the composefile in yaml")
}
fmt.Print(string(s))
// Output: version: "3.6"
// services:
// hello:
// command:
// - -text
// - hello examples!
// image: hashicorp/http-echo
// ports:
// - mode: ingress
// target: 5678
// published: 8080
// protocol: tcp
}