Skip to content

Commit

Permalink
Add examples folder
Browse files Browse the repository at this point in the history
  • Loading branch information
MylesCagney committed Feb 16, 2020
1 parent d004663 commit e2ed70e
Show file tree
Hide file tree
Showing 12 changed files with 172,610 additions and 3 deletions.
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ vendor/
bin/
.vscode/
go.sum
embed
binary
code
/embed
/binary
/code
Makefile
18 changes: 18 additions & 0 deletions examples/binary/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package main

//go:generate go run ../../cmd/embed/cmd.go -pkg=main -nolocalfs -fileserver -o static ../../testdata

import (
"fmt"
"log"
"net/http"
)

var srv *http.Server

func main() {
fmt.Println("Open link http://localhost:8080/")
// FileHandler() is created by embed and returns a http.Handler.
srv = &http.Server{Addr: ":8080", Handler: FileHandler()}
log.Print(srv.ListenAndServe())
}
28 changes: 28 additions & 0 deletions examples/binary/main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package main

import (
"net/http"
"testing"
"time"
)

func TestExample(t *testing.T) {
go closeWhenUp()

main()
}

func closeWhenUp() {
for {
time.Sleep(time.Microsecond * 100)

if resp, err := http.Get("http://localhost:8080/"); err == nil {
if resp.Body != nil {
resp.Body.Close()
}
if resp.StatusCode == http.StatusOK {
srv.Close()
}
}
}
}
Loading

0 comments on commit e2ed70e

Please sign in to comment.