mirror of
https://github.com/MizuchiLabs/mantrae.git
synced 2025-12-17 20:34:36 -06:00
44 lines
1.0 KiB
Go
44 lines
1.0 KiB
Go
package service
|
|
|
|
import (
|
|
"context"
|
|
|
|
"connectrpc.com/connect"
|
|
|
|
"github.com/mizuchilabs/mantrae/internal/config"
|
|
"github.com/mizuchilabs/mantrae/pkg/build"
|
|
"github.com/mizuchilabs/mantrae/pkg/util"
|
|
mantraev1 "github.com/mizuchilabs/mantrae/proto/gen/mantrae/v1"
|
|
)
|
|
|
|
type UtilService struct {
|
|
app *config.App
|
|
}
|
|
|
|
func NewUtilService(app *config.App) *UtilService {
|
|
return &UtilService{app: app}
|
|
}
|
|
|
|
func (s *UtilService) GetVersion(
|
|
ctx context.Context,
|
|
req *connect.Request[mantraev1.GetVersionRequest],
|
|
) (*connect.Response[mantraev1.GetVersionResponse], error) {
|
|
return connect.NewResponse(&mantraev1.GetVersionResponse{
|
|
Version: build.Version,
|
|
}), nil
|
|
}
|
|
|
|
func (s *UtilService) GetPublicIP(
|
|
ctx context.Context,
|
|
req *connect.Request[mantraev1.GetPublicIPRequest],
|
|
) (*connect.Response[mantraev1.GetPublicIPResponse], error) {
|
|
ips, err := util.GetPublicIPs()
|
|
if err != nil {
|
|
return nil, connect.NewError(connect.CodeInternal, err)
|
|
}
|
|
return connect.NewResponse(&mantraev1.GetPublicIPResponse{
|
|
Ipv4: ips.IPv4,
|
|
Ipv6: ips.IPv6,
|
|
}), nil
|
|
}
|