-
Notifications
You must be signed in to change notification settings - Fork 1
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
1 parent
d46a130
commit 66886e2
Showing
11 changed files
with
237 additions
and
8 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,37 @@ | ||
package api | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
"os" | ||
"strconv" | ||
|
||
"github.com/gin-gonic/gin" | ||
"github.com/splitio/go-toolkit/v5/logging" | ||
"github.com/splitio/splitd/splitio/api/controllers" | ||
"github.com/splitio/splitd/splitio/link" | ||
"github.com/splitio/splitd/splitio/link/client" | ||
) | ||
|
||
func Setup(host string, port int, logger logging.LoggerInterface, listenerCfG link.ListenerOptions) (*http.Server, error) { | ||
|
||
router := gin.Default() | ||
mainAPI := router.Group("/api") | ||
|
||
healthCtrl := controllers.NewHealthController(logger, link.ConsumerOptions{ | ||
Transfer: listenerCfG.Transfer, | ||
Consumer: client.Options{ | ||
ID: strconv.Itoa(os.Getpid()), | ||
Protocol: listenerCfG.Protocol, | ||
ImpressionsFeedback: false, | ||
}, | ||
Serialization: listenerCfG.Serialization, | ||
}) | ||
|
||
healthCtrl.Register(mainAPI) | ||
|
||
return &http.Server{ | ||
Addr: fmt.Sprintf("%s:%d", host, port), | ||
Handler: router, | ||
}, nil | ||
} |
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,58 @@ | ||
package controllers | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/gin-gonic/gin" | ||
"github.com/splitio/go-toolkit/v5/logging" | ||
"github.com/splitio/splitd/splitio/link" | ||
"github.com/splitio/splitd/splitio/link/client" | ||
"github.com/splitio/splitd/splitio/link/serializer" | ||
"github.com/splitio/splitd/splitio/link/transfer" | ||
) | ||
|
||
type HealthCheckController struct { | ||
connParams link.ConsumerOptions | ||
logger logging.LoggerInterface | ||
} | ||
|
||
func (c *HealthCheckController) Register(router gin.IRouter) { | ||
router.GET("/health", c.isHealthy) | ||
router.GET("/ready", c.isReady) | ||
} | ||
|
||
func (c *HealthCheckController) isHealthy(ctx *gin.Context) { | ||
ctx.Status(200) | ||
} | ||
|
||
func (c *HealthCheckController) isReady(ctx *gin.Context) { | ||
conn, err := transfer.NewClientConn(c.logger, &c.connParams.Transfer) | ||
if conn != nil { | ||
defer conn.Shutdown() | ||
} | ||
if err != nil { | ||
ctx.AbortWithError(500, fmt.Errorf("error creating raw connection: %w", err)) | ||
return | ||
} | ||
|
||
serial, err := serializer.Setup(c.connParams.Serialization) | ||
if err != nil { | ||
ctx.AbortWithError(500, fmt.Errorf("error setting up serializer: %w", err)) | ||
return | ||
} | ||
|
||
_, err = client.New(c.logger, conn, serial, c.connParams.Consumer) | ||
if err != nil { | ||
ctx.AbortWithError(500, fmt.Errorf("error setting up client: %w", err)) | ||
return | ||
} | ||
|
||
ctx.Status(200) | ||
} | ||
|
||
func NewHealthController(logger logging.LoggerInterface, connParams link.ConsumerOptions) *HealthCheckController { | ||
return &HealthCheckController{ | ||
connParams: connParams, | ||
logger: logger, | ||
} | ||
} |
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,3 +1,3 @@ | ||
package splitio | ||
|
||
const CommitSHA = "3f5eb7e" | ||
const CommitSHA = "d46a130" |
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,3 +1,3 @@ | ||
package splitio | ||
|
||
const Version = "1.4.0" | ||
const Version = "1.5.0" |