pkger/internal/examples/httpserver/main.go

44 lines
642 B
Go
Raw Normal View History

2019-07-31 00:21:26 +03:00
package main
import (
"fmt"
"io"
"log"
"net/http"
"os"
"time"
"github.com/markbates/pkger"
)
func main() {
f, err := pkger.Open("github.com/gobuffalo/buffalo")
if err != nil {
log.Fatal("1", err)
}
defer f.Close()
fmt.Println(f.Path())
go func() {
time.Sleep(1 * time.Second)
res, err := http.Get("http://127.0.0.1:3000/app.go")
if err != nil {
log.Fatal(err)
}
defer res.Body.Close()
_, err = io.Copy(os.Stdout, res.Body)
if err != nil {
log.Fatal(err)
}
if res.StatusCode >= 300 {
log.Fatal("code: ", res.StatusCode)
}
}()
log.Fatal(http.ListenAndServe(":3000", http.FileServer(f)))
}