From d1bb05be9538a793fca37d3dcdcb8f637134398e Mon Sep 17 00:00:00 2001 From: Shulhan Date: Sun, 17 Oct 2021 02:33:09 +0700 Subject: all: move the main program for example to internal/cmd/trunks-example The "cmd" directory on module should be reserved for installable program that can be executed outside of this repository. The trunks-example is development server should be run on root of this repository only, not installable to $GOBIN. --- Makefile | 2 +- cmd/trunks-example/main.go | 37 ------------------------------------- example/example.go | 8 ++++++-- internal/cmd/trunks-example/main.go | 37 +++++++++++++++++++++++++++++++++++++ 4 files changed, 44 insertions(+), 40 deletions(-) delete mode 100644 cmd/trunks-example/main.go create mode 100644 internal/cmd/trunks-example/main.go diff --git a/Makefile b/Makefile index 5592998..13c16a3 100644 --- a/Makefile +++ b/Makefile @@ -8,7 +8,7 @@ all: embed go test -v -race ./... run: - go run ./cmd/trunks-example + go run ./internal/cmd/trunks-example embed: tsc go run ./internal/memfs-embed diff --git a/cmd/trunks-example/main.go b/cmd/trunks-example/main.go deleted file mode 100644 index 9c340e5..0000000 --- a/cmd/trunks-example/main.go +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright 2021, Shulhan . All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// -// Program trunks provide an example how to use the Trunks module. -// -package main - -import ( - "os" - "os/signal" - "syscall" - - "github.com/shuLhan/share/lib/mlog" - - "git.sr.ht/~shulhan/trunks/example" -) - -func main() { - ex, err := example.New() - if err != nil { - mlog.Fatalf("%s\n", err) - } - - go func() { - c := make(chan os.Signal, 1) - signal.Notify(c, syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM) - <-c - ex.Stop() - }() - - err = ex.Start() - if err != nil { - mlog.Fatalf("%s\n", err) - } -} diff --git a/example/example.go b/example/example.go index 963f7e0..56f7d7c 100644 --- a/example/example.go +++ b/example/example.go @@ -1,6 +1,10 @@ // -// Package example provide an example how to use the Trunks library from setup -// to creating targets. +// Package example provide an example how to use the Trunks library from +// setting it up to creating targets. +// +// To run the example, execute +// +// $ go run ./internal/cmd/trunks-example // package example diff --git a/internal/cmd/trunks-example/main.go b/internal/cmd/trunks-example/main.go new file mode 100644 index 0000000..9c340e5 --- /dev/null +++ b/internal/cmd/trunks-example/main.go @@ -0,0 +1,37 @@ +// Copyright 2021, Shulhan . All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// +// Program trunks provide an example how to use the Trunks module. +// +package main + +import ( + "os" + "os/signal" + "syscall" + + "github.com/shuLhan/share/lib/mlog" + + "git.sr.ht/~shulhan/trunks/example" +) + +func main() { + ex, err := example.New() + if err != nil { + mlog.Fatalf("%s\n", err) + } + + go func() { + c := make(chan os.Signal, 1) + signal.Notify(c, syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM) + <-c + ex.Stop() + }() + + err = ex.Start() + if err != nil { + mlog.Fatalf("%s\n", err) + } +} -- cgit v1.3