-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d004663
commit e2ed70e
Showing
12 changed files
with
172,610 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,7 @@ vendor/ | |
bin/ | ||
.vscode/ | ||
go.sum | ||
embed | ||
binary | ||
code | ||
/embed | ||
/binary | ||
/code | ||
Makefile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.