ignore some unhandled errors & fix unexported returned value in exported function

Signed-off-by: andrewmatilde <davis6813585853062@outlook.com>
This commit is contained in:
andrewmatilde 2023-02-08 10:48:58 +08:00
parent 10f2fb4bcf
commit f70a0f5e43
4 changed files with 38 additions and 38 deletions

View File

@ -37,7 +37,7 @@ var (
errMissingClientCert = utils.ErrAuth.New("Sorry, but you need to provide a client certificate to continue") errMissingClientCert = utils.ErrAuth.New("Sorry, but you need to provide a client certificate to continue")
) )
func (s *httpServer) serverMode() string { func (s *HttpServer) serverMode() string {
if len(s.conf.SSLCertFile) > 0 { if len(s.conf.SSLCertFile) > 0 {
if len(s.conf.SSLClientCAFile) > 0 { if len(s.conf.SSLClientCAFile) > 0 {
return MTLSServer return MTLSServer
@ -47,7 +47,7 @@ func (s *httpServer) serverMode() string {
return HTTPServer return HTTPServer
} }
func (s *httpServer) startHttpsServer() (err error) { func (s *HttpServer) startHttpsServer() (err error) {
mode := s.serverMode() mode := s.serverMode()
if mode == HTTPServer { if mode == HTTPServer {
return nil return nil

View File

@ -22,7 +22,7 @@ import (
"github.com/chaos-mesh/chaosd/pkg/core" "github.com/chaos-mesh/chaosd/pkg/core"
) )
func (s *httpServer) listExperiments(c *gin.Context) { func (s *HttpServer) listExperiments(c *gin.Context) {
mode, ok := c.GetQuery("launch_mode") mode, ok := c.GetQuery("launch_mode")
var chaosList []*core.Experiment var chaosList []*core.Experiment
var err error var err error
@ -32,17 +32,17 @@ func (s *httpServer) listExperiments(c *gin.Context) {
chaosList, err = s.exp.List(context.Background()) chaosList, err = s.exp.List(context.Background())
} }
if err != nil { if err != nil {
c.AbortWithError(http.StatusInternalServerError, err) _ = c.AbortWithError(http.StatusInternalServerError, err)
return return
} }
c.JSON(http.StatusOK, chaosList) c.JSON(http.StatusOK, chaosList)
} }
func (s *httpServer) listExperimentRuns(c *gin.Context) { func (s *HttpServer) listExperimentRuns(c *gin.Context) {
uid := c.Param("uid") uid := c.Param("uid")
runsList, err := s.chaos.ExpRun.ListByExperimentUID(context.Background(), uid) runsList, err := s.chaos.ExpRun.ListByExperimentUID(context.Background(), uid)
if err != nil { if err != nil {
c.AbortWithError(http.StatusInternalServerError, err) _ = c.AbortWithError(http.StatusInternalServerError, err)
return return
} }
c.JSON(http.StatusOK, runsList) c.JSON(http.StatusOK, runsList)

View File

@ -30,7 +30,7 @@ import (
"github.com/chaos-mesh/chaosd/pkg/swaggerserver" "github.com/chaos-mesh/chaosd/pkg/swaggerserver"
) )
type httpServer struct { type HttpServer struct {
conf *config.Config conf *config.Config
chaos *chaosd.Server chaos *chaosd.Server
exp core.ExperimentStore exp core.ExperimentStore
@ -40,15 +40,15 @@ func NewServer(
conf *config.Config, conf *config.Config,
chaos *chaosd.Server, chaos *chaosd.Server,
exp core.ExperimentStore, exp core.ExperimentStore,
) *httpServer { ) *HttpServer {
return &httpServer{ return &HttpServer{
conf: conf, conf: conf,
chaos: chaos, chaos: chaos,
exp: exp, exp: exp,
} }
} }
func Register(s *httpServer, scheduler scheduler.Scheduler) { func Register(s *HttpServer, scheduler scheduler.Scheduler) {
if s.conf.Platform != config.LocalPlatform { if s.conf.Platform != config.LocalPlatform {
return return
} }
@ -66,7 +66,7 @@ func Register(s *httpServer, scheduler scheduler.Scheduler) {
scheduler.Start() scheduler.Start()
} }
func (s *httpServer) startHttpServer() error { func (s *HttpServer) startHttpServer() error {
httpServerAddr := s.conf.Address() httpServerAddr := s.conf.Address()
log.Info("starting HTTP server", zap.String("address", httpServerAddr)) log.Info("starting HTTP server", zap.String("address", httpServerAddr))
e := gin.Default() e := gin.Default()
@ -78,7 +78,7 @@ func (s *httpServer) startHttpServer() error {
return e.Run(httpServerAddr) return e.Run(httpServerAddr)
} }
func (s *httpServer) handler(engine *gin.Engine) { func (s *HttpServer) handler(engine *gin.Engine) {
api := engine.Group("/api") api := engine.Group("/api")
{ {
api.GET("/swagger/*any", swaggerserver.Handler()) api.GET("/swagger/*any", swaggerserver.Handler())
@ -107,7 +107,7 @@ func (s *httpServer) handler(engine *gin.Engine) {
} }
} }
func (s *httpServer) systemHandler(engine *gin.Engine) { func (s *HttpServer) systemHandler(engine *gin.Engine) {
api := engine.Group("/api") api := engine.Group("/api")
system := api.Group("/system") system := api.Group("/system")
{ {
@ -125,10 +125,10 @@ func (s *httpServer) systemHandler(engine *gin.Engine) {
// @Failure 400 {object} utils.APIError // @Failure 400 {object} utils.APIError
// @Failure 500 {object} utils.APIError // @Failure 500 {object} utils.APIError
// @Router /api/attack/process [post] // @Router /api/attack/process [post]
func (s *httpServer) createProcessAttack(c *gin.Context) { func (s *HttpServer) createProcessAttack(c *gin.Context) {
attack := core.NewProcessCommand() attack := core.NewProcessCommand()
if err := c.ShouldBindJSON(attack); err != nil { if err := c.ShouldBindJSON(attack); err != nil {
c.AbortWithError(http.StatusBadRequest, utils.ErrInternalServer.WrapWithNoMessage(err)) _ = c.AbortWithError(http.StatusBadRequest, utils.ErrInternalServer.WrapWithNoMessage(err))
return return
} }
@ -157,10 +157,10 @@ func (s *httpServer) createProcessAttack(c *gin.Context) {
// @Failure 400 {object} utils.APIError // @Failure 400 {object} utils.APIError
// @Failure 500 {object} utils.APIError // @Failure 500 {object} utils.APIError
// @Router /api/attack/network [post] // @Router /api/attack/network [post]
func (s *httpServer) createNetworkAttack(c *gin.Context) { func (s *HttpServer) createNetworkAttack(c *gin.Context) {
attack := core.NewNetworkCommand() attack := core.NewNetworkCommand()
if err := c.ShouldBindJSON(attack); err != nil { if err := c.ShouldBindJSON(attack); err != nil {
c.AbortWithError(http.StatusBadRequest, utils.ErrInternalServer.WrapWithNoMessage(err)) _ = c.AbortWithError(http.StatusBadRequest, utils.ErrInternalServer.WrapWithNoMessage(err))
return return
} }
@ -189,10 +189,10 @@ func (s *httpServer) createNetworkAttack(c *gin.Context) {
// @Failure 400 {object} utils.APIError // @Failure 400 {object} utils.APIError
// @Failure 500 {object} utils.APIError // @Failure 500 {object} utils.APIError
// @Router /api/attack/stress [post] // @Router /api/attack/stress [post]
func (s *httpServer) createStressAttack(c *gin.Context) { func (s *HttpServer) createStressAttack(c *gin.Context) {
attack := core.NewStressCommand() attack := core.NewStressCommand()
if err := c.ShouldBindJSON(attack); err != nil { if err := c.ShouldBindJSON(attack); err != nil {
c.AbortWithError(http.StatusBadRequest, utils.ErrInternalServer.WrapWithNoMessage(err)) _ = c.AbortWithError(http.StatusBadRequest, utils.ErrInternalServer.WrapWithNoMessage(err))
return return
} }
@ -221,10 +221,10 @@ func (s *httpServer) createStressAttack(c *gin.Context) {
// @Failure 400 {object} utils.APIError // @Failure 400 {object} utils.APIError
// @Failure 500 {object} utils.APIError // @Failure 500 {object} utils.APIError
// @Router /api/attack/disk [post] // @Router /api/attack/disk [post]
func (s *httpServer) createDiskAttack(c *gin.Context) { func (s *HttpServer) createDiskAttack(c *gin.Context) {
options := core.NewDiskOption() options := core.NewDiskOption()
if err := c.ShouldBindJSON(options); err != nil { if err := c.ShouldBindJSON(options); err != nil {
c.AbortWithError(http.StatusBadRequest, utils.ErrInternalServer.WrapWithNoMessage(err)) _ = c.AbortWithError(http.StatusBadRequest, utils.ErrInternalServer.WrapWithNoMessage(err))
return return
} }
@ -254,10 +254,10 @@ func (s *httpServer) createDiskAttack(c *gin.Context) {
// @Failure 400 {object} utils.APIError // @Failure 400 {object} utils.APIError
// @Failure 500 {object} utils.APIError // @Failure 500 {object} utils.APIError
// @Router /api/attack/clock [post] // @Router /api/attack/clock [post]
func (s *httpServer) createClockAttack(c *gin.Context) { func (s *HttpServer) createClockAttack(c *gin.Context) {
options := core.NewClockOption() options := core.NewClockOption()
if err := c.ShouldBindJSON(options); err != nil { if err := c.ShouldBindJSON(options); err != nil {
c.AbortWithError(http.StatusBadRequest, utils.ErrInternalServer.WrapWithNoMessage(err)) _ = c.AbortWithError(http.StatusBadRequest, utils.ErrInternalServer.WrapWithNoMessage(err))
return return
} }
@ -286,10 +286,10 @@ func (s *httpServer) createClockAttack(c *gin.Context) {
// @Failure 400 {object} utils.APIError // @Failure 400 {object} utils.APIError
// @Failure 500 {object} utils.APIError // @Failure 500 {object} utils.APIError
// @Router /api/attack/http [post] // @Router /api/attack/http [post]
func (s *httpServer) createHTTPAttack(c *gin.Context) { func (s *HttpServer) createHTTPAttack(c *gin.Context) {
attack := core.NewHTTPAttackOption() attack := core.NewHTTPAttackOption()
if err := c.ShouldBindJSON(attack); err != nil { if err := c.ShouldBindJSON(attack); err != nil {
c.AbortWithError(http.StatusBadRequest, utils.ErrInternalServer.WrapWithNoMessage(err)) _ = c.AbortWithError(http.StatusBadRequest, utils.ErrInternalServer.WrapWithNoMessage(err))
return return
} }
@ -318,10 +318,10 @@ func (s *httpServer) createHTTPAttack(c *gin.Context) {
// @Failure 400 {object} utils.APIError // @Failure 400 {object} utils.APIError
// @Failure 500 {object} utils.APIError // @Failure 500 {object} utils.APIError
// @Router /api/attack/jvm [post] // @Router /api/attack/jvm [post]
func (s *httpServer) createJVMAttack(c *gin.Context) { func (s *HttpServer) createJVMAttack(c *gin.Context) {
options := core.NewJVMCommand() options := core.NewJVMCommand()
if err := c.ShouldBindJSON(options); err != nil { if err := c.ShouldBindJSON(options); err != nil {
c.AbortWithError(http.StatusBadRequest, utils.ErrInternalServer.WrapWithNoMessage(err)) _ = c.AbortWithError(http.StatusBadRequest, utils.ErrInternalServer.WrapWithNoMessage(err))
return return
} }
@ -350,10 +350,10 @@ func (s *httpServer) createJVMAttack(c *gin.Context) {
// @Failure 400 {object} utils.APIError // @Failure 400 {object} utils.APIError
// @Failure 500 {object} utils.APIError // @Failure 500 {object} utils.APIError
// @Router /api/attack/kafka [post] // @Router /api/attack/kafka [post]
func (s *httpServer) createKafkaAttack(c *gin.Context) { func (s *HttpServer) createKafkaAttack(c *gin.Context) {
options := core.NewKafkaCommand() options := core.NewKafkaCommand()
if err := c.ShouldBindJSON(options); err != nil { if err := c.ShouldBindJSON(options); err != nil {
c.AbortWithError(http.StatusBadRequest, utils.ErrInternalServer.WrapWithNoMessage(err)) _ = c.AbortWithError(http.StatusBadRequest, utils.ErrInternalServer.WrapWithNoMessage(err))
return return
} }
@ -382,10 +382,10 @@ func (s *httpServer) createKafkaAttack(c *gin.Context) {
// @Failure 400 {object} utils.APIError // @Failure 400 {object} utils.APIError
// @Failure 500 {object} utils.APIError // @Failure 500 {object} utils.APIError
// @Router /api/attack/vm [post] // @Router /api/attack/vm [post]
func (s *httpServer) createVMAttack(c *gin.Context) { func (s *HttpServer) createVMAttack(c *gin.Context) {
options := core.NewVMOption() options := core.NewVMOption()
if err := c.ShouldBindJSON(options); err != nil { if err := c.ShouldBindJSON(options); err != nil {
c.AbortWithError(http.StatusBadRequest, utils.ErrInternalServer.WrapWithNoMessage(err)) _ = c.AbortWithError(http.StatusBadRequest, utils.ErrInternalServer.WrapWithNoMessage(err))
return return
} }
@ -414,10 +414,10 @@ func (s *httpServer) createVMAttack(c *gin.Context) {
// @Failure 400 {object} utils.APIError // @Failure 400 {object} utils.APIError
// @Failure 500 {object} utils.APIError // @Failure 500 {object} utils.APIError
// @Router /api/attack/redis [post] // @Router /api/attack/redis [post]
func (s *httpServer) createRedisAttack(c *gin.Context) { func (s *HttpServer) createRedisAttack(c *gin.Context) {
attack := core.NewRedisCommand() attack := core.NewRedisCommand()
if err := c.ShouldBindJSON(attack); err != nil { if err := c.ShouldBindJSON(attack); err != nil {
c.AbortWithError(http.StatusBadRequest, utils.ErrInternalServer.WrapWithNoMessage(err)) _ = c.AbortWithError(http.StatusBadRequest, utils.ErrInternalServer.WrapWithNoMessage(err))
return return
} }
@ -446,10 +446,10 @@ func (s *httpServer) createRedisAttack(c *gin.Context) {
// @Failure 400 {object} utils.APIError // @Failure 400 {object} utils.APIError
// @Failure 500 {object} utils.APIError // @Failure 500 {object} utils.APIError
// @Router /api/attack/user_defined [post] // @Router /api/attack/user_defined [post]
func (s *httpServer) createUserDefinedAttack(c *gin.Context) { func (s *HttpServer) createUserDefinedAttack(c *gin.Context) {
attack := core.NewUserDefinedOption() attack := core.NewUserDefinedOption()
if err := c.ShouldBindJSON(attack); err != nil { if err := c.ShouldBindJSON(attack); err != nil {
c.AbortWithError(http.StatusBadRequest, utils.ErrInternalServer.WrapWithNoMessage(err)) _ = c.AbortWithError(http.StatusBadRequest, utils.ErrInternalServer.WrapWithNoMessage(err))
return return
} }
@ -477,7 +477,7 @@ func (s *httpServer) createUserDefinedAttack(c *gin.Context) {
// @Success 200 {object} utils.Response // @Success 200 {object} utils.Response
// @Failure 500 {object} utils.APIError // @Failure 500 {object} utils.APIError
// @Router /api/attack/{uid} [delete] // @Router /api/attack/{uid} [delete]
func (s *httpServer) recoverAttack(c *gin.Context) { func (s *HttpServer) recoverAttack(c *gin.Context) {
uid := c.Param("uid") uid := c.Param("uid")
err := s.chaos.RecoverAttack(uid) err := s.chaos.RecoverAttack(uid)
if err != nil { if err != nil {

View File

@ -26,10 +26,10 @@ type healthInfo struct {
Message string `json:"message"` Message string `json:"message"`
} }
func (s *httpServer) healthcheck(c *gin.Context) { func (s *HttpServer) healthcheck(c *gin.Context) {
c.JSON(http.StatusOK, healthInfo{Status: 0}) c.JSON(http.StatusOK, healthInfo{Status: 0})
} }
func (s *httpServer) version(c *gin.Context) { func (s *HttpServer) version(c *gin.Context) {
c.JSON(http.StatusOK, version.Get()) c.JSON(http.StatusOK, version.Get())
} }