You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
754 B
Go
44 lines
754 B
Go
2 years ago
|
package main
|
||
|
|
||
|
import (
|
||
|
"bufio"
|
||
|
"io"
|
||
|
"log"
|
||
|
"os/exec"
|
||
|
|
||
|
"aziis98.com/template-go-vitejs/backend/database"
|
||
|
"aziis98.com/template-go-vitejs/backend/server"
|
||
|
"golang.org/x/sync/errgroup"
|
||
|
)
|
||
|
|
||
|
func main() {
|
||
|
srv := server.New(server.Dependencies{
|
||
|
DB: &database.Mem{},
|
||
|
})
|
||
|
|
||
|
g := &errgroup.Group{}
|
||
|
|
||
|
g.Go(func() error {
|
||
|
log.Printf(`[develop] listening on port :4000...`)
|
||
|
return srv.Listen(":4000")
|
||
|
})
|
||
|
g.Go(func() error {
|
||
|
log.Printf(`[develop] starting vitejs development server...`)
|
||
|
|
||
|
r, w := io.Pipe()
|
||
|
cmd := exec.Command("npm", "run", "dev")
|
||
|
cmd.Stdout = w
|
||
|
stdout := bufio.NewScanner(r)
|
||
|
|
||
|
go func() {
|
||
|
for stdout.Scan() {
|
||
|
log.Printf(`[develop] [vitejs] %s`, stdout.Text())
|
||
|
}
|
||
|
}()
|
||
|
|
||
|
return cmd.Run()
|
||
|
})
|
||
|
|
||
|
log.Fatal(g.Wait())
|
||
|
}
|