-
Notifications
You must be signed in to change notification settings - Fork 19
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
Showing
13 changed files
with
1,497 additions
and
22 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
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
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
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
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
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
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,70 @@ | ||
// (c) Cartesi and individual authors (see AUTHORS) | ||
// SPDX-License-Identifier: Apache-2.0 (see LICENSE) | ||
|
||
package nonodo | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"log" | ||
"net" | ||
"net/http" | ||
|
||
"github.com/gligneul/nonodo/internal/model" | ||
"github.com/gligneul/nonodo/internal/rollup" | ||
"github.com/labstack/echo/v4" | ||
"github.com/labstack/echo/v4/middleware" | ||
) | ||
|
||
// The inputter reads inputs from anvil and puts them in the model. | ||
type echoService struct { | ||
ready chan struct{} | ||
port int | ||
model *model.NonodoModel | ||
} | ||
|
||
// Creates a new inputter from opts. | ||
func newEchoService(model *model.NonodoModel, port int) *echoService { | ||
return &echoService{ | ||
ready: make(chan struct{}), | ||
port: port, | ||
model: model, | ||
} | ||
} | ||
|
||
func (s *echoService) Start(ctx context.Context) error { | ||
// setup routes | ||
e := echo.New() | ||
e.Use(middleware.CORS()) | ||
rollup.Register(e, s.model) | ||
|
||
// create server | ||
addr := fmt.Sprintf("127.0.0.1:%d", s.port) | ||
server := http.Server{ | ||
Addr: addr, | ||
Handler: e, | ||
} | ||
ln, err := net.Listen("tcp", addr) | ||
if err != nil { | ||
return err | ||
} | ||
log.Printf("listening on %v", addr) | ||
s.ready <- struct{}{} | ||
|
||
// create goroutine to shutdown server | ||
go func() { | ||
<-ctx.Done() | ||
server.Shutdown(ctx) | ||
}() | ||
|
||
// serve | ||
err = server.Serve(ln) | ||
if err != http.ErrServerClosed { | ||
return err | ||
} | ||
return nil | ||
} | ||
|
||
func (s *echoService) Ready() <-chan struct{} { | ||
return s.ready | ||
} |
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
Oops, something went wrong.