-
-
Notifications
You must be signed in to change notification settings - Fork 140
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(api,pkg): create generic server package for services
- Loading branch information
1 parent
542130b
commit 79c02d4
Showing
7 changed files
with
200 additions
and
46 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,17 @@ | ||
package routes | ||
|
||
import ( | ||
svc "github.com/shellhub-io/shellhub/api/services" | ||
"github.com/shellhub-io/shellhub/api/services" | ||
) | ||
|
||
type Handler struct { | ||
service svc.Service | ||
service services.Service | ||
} | ||
|
||
func NewHandler(s svc.Service) *Handler { | ||
func (h *Handler) GetService() any { | ||
return h.service | ||
} | ||
|
||
func NewHandler(s services.Service) *Handler { | ||
return &Handler{service: s} | ||
} |
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,32 @@ | ||
package server | ||
|
||
import ( | ||
"github.com/labstack/echo/v4" | ||
) | ||
|
||
// Echo is a wrapper around the Echo HTTP server with simplified lifecycle management. | ||
type Echo struct { | ||
echo *echo.Echo | ||
} | ||
|
||
var _ Server[*echo.Echo] = new(Echo) | ||
|
||
// Underlying returns the underlying HTTP server. | ||
func (s *Echo) Underlying() *echo.Echo { | ||
return s.echo | ||
} | ||
|
||
// Close closes the server. | ||
func (s *Echo) Close() error { | ||
return s.echo.Close() | ||
} | ||
|
||
// Start starts the server at a given address. | ||
func (s *Echo) Start(addr string) error { | ||
return s.echo.Start(addr) | ||
} | ||
|
||
// Listen starts the HTTP server, listing for connections in [ServerListenDefaultAddress]. | ||
func (s *Echo) Listen() error { | ||
return s.echo.Start(ServerListenDefaultAddress) | ||
} |
Oops, something went wrong.