Skip to content

Commit

Permalink
1.0.0 (#602)
Browse files Browse the repository at this point in the history
* V1.0.0 Changes (#588)

* [feature] cors support options request (#591)

* V1.0.0 Changes

* [feature] cors support options request

* Move Pixiu cmd files in /cmd/pixiu to pkg/cmd (#596)

* remove unused types JTypeMapper check & support default types. (#597)
  • Loading branch information
mark4z authored Dec 20, 2023
1 parent 8046280 commit 4ff167d
Show file tree
Hide file tree
Showing 10 changed files with 231 additions and 235 deletions.
70 changes: 0 additions & 70 deletions cmd/pixiu/gateway.go

This file was deleted.

146 changes: 5 additions & 141 deletions cmd/pixiu/pixiu.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@
package main

import (
"fmt"
_ "net/http/pprof"
"runtime"
"strconv"
"time"
)
Expand All @@ -30,45 +28,15 @@ import (
)

import (
"github.com/apache/dubbo-go-pixiu/pixiu/pkg/common/constant"
pxruntime "github.com/apache/dubbo-go-pixiu/pixiu/pkg/common/runtime"
"github.com/apache/dubbo-go-pixiu/pixiu/pkg/config"
"github.com/apache/dubbo-go-pixiu/pixiu/pkg/logger"
"github.com/apache/dubbo-go-pixiu/pixiu/pkg/model"
"github.com/apache/dubbo-go-pixiu/pixiu/pkg/cmd"
_ "github.com/apache/dubbo-go-pixiu/pixiu/pkg/pluginregistry"
"github.com/apache/dubbo-go-pixiu/pixiu/pkg/server"
)

var (
const (
// Version pixiu version
Version = "0.6.0"

flagToLogLevel = map[string]string{
"trace": "TRACE",
"debug": "DEBUG",
"info": "INFO",
"warning": "WARN",
"error": "ERROR",
"critical": "FATAL",
}

configPath string
apiConfigPath string
logConfigPath string
logLevel string

// CURRENTLY USELESS
logFormat string

limitCpus string

// Currently default set to false, wait for up coming support
initFromRemote = false
Version = "1.0.0"
)

// deploy server deployment
var deploy = &DefaultDeployer{}

// main pixiu run method
func main() {
app := getRootCmd()
Expand All @@ -88,112 +56,8 @@ func getRootCmd() *cobra.Command {
Version: Version,
}

rootCmd.AddCommand(gatewayCmd)
rootCmd.AddCommand(sideCarCmd)
rootCmd.AddCommand(cmd.GatewayCmd)
rootCmd.AddCommand(cmd.SideCarCmd)

return rootCmd
}

type DefaultDeployer struct {
bootstrap *model.Bootstrap
configManger *config.ConfigManager
}

func (d *DefaultDeployer) initialize() error {

err := initLog()
if err != nil {
logger.Warnf("[startGatewayCmd] failed to init logger, %s", err.Error())
}

// load Bootstrap config
d.bootstrap = d.configManger.LoadBootConfig(configPath)
if err != nil {
panic(fmt.Errorf("[startGatewayCmd] failed to get api meta config, %s", err.Error()))
}

err = initLimitCpus()
if err != nil {
logger.Errorf("[startCmd] failed to get limit cpu number, %s", err.Error())
}

return err
}

func (d *DefaultDeployer) start() error {
server.Start(d.bootstrap)
return nil
}

func (d *DefaultDeployer) stop() error {
//TODO implement me
panic("implement me")
}

// initDefaultValue If not set both in args and env, set default values
func initDefaultValue() {
if configPath == "" {
configPath = constant.DefaultConfigPath
}

if apiConfigPath == "" {
apiConfigPath = constant.DefaultApiConfigPath
}

if logConfigPath == "" {
logConfigPath = constant.DefaultLogConfigPath
}

if logLevel == "" {
logLevel = constant.DefaultLogLevel
}

if limitCpus == "" {
limitCpus = constant.DefaultLimitCpus
}

if logFormat == "" {
logFormat = constant.DefaultLogFormat
}
}

// initLog
func initLog() error {
err := logger.InitLog(logConfigPath)
if err != nil {
// cause `logger.InitLog` already handle init failed, so just use logger to log
return err
}

if level, ok := flagToLogLevel[logLevel]; ok {
logger.SetLoggerLevel(level)
} else {
logger.SetLoggerLevel(flagToLogLevel[constant.DefaultLogLevel])
return fmt.Errorf("logLevel is invalid, set log level to default: %s", constant.DefaultLogLevel)
}
return nil
}

// initApiConfig return value of the bool is for the judgment of whether is a api meta data error, a kind of silly (?)
func initApiConfig() (*model.Bootstrap, error) {
bootstrap := config.Load(configPath)
return bootstrap, nil
}

func initLimitCpus() error {
limitCpuNumberFromEnv, err := strconv.ParseInt(limitCpus, 10, 64)
if err != nil {
return err
}
limitCpuNumber := int(limitCpuNumberFromEnv)
if limitCpuNumber <= 0 {
limitCpuNumber = pxruntime.GetCPUNum()
}
runtime.GOMAXPROCS(limitCpuNumber)
logger.Infof("GOMAXPROCS set to %v", limitCpuNumber)
return nil
}

func init() {
deploy.configManger = config.NewConfigManger()
}
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -328,3 +328,4 @@ require (
)

replace google.golang.org/protobuf v1.28.1 => google.golang.org/protobuf v1.28.0

21 changes: 8 additions & 13 deletions pixiu/pkg/client/dubbo/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,24 +186,19 @@ type paramTypesOpt struct{}
// Action for paramTypesOpt override the other param types mapping/config.
// The val must be string(e.g. "int, object"), and will then assign to the target.(dubboTarget).Types
func (opt *paramTypesOpt) Action(target, val interface{}) error {
v, ok := val.(string)
if !ok {
return errors.New("The val type must be string")
}
types := strings.Split(v, ",")
dubboTarget, ok := target.(*dubboTarget)
if !ok {
return errors.New("Target is not dubboTarget in target parameter")
}
for i := range types {
trimType := strings.TrimSpace(types[i])
if len(trimType) == 0 {
continue
}
if _, ok = constant.JTypeMapper[trimType]; !ok {
return errors.Errorf("Types invalid %s", trimType)
// empty types for func like func()
types := make([]string, 0)
if v, ok := val.(string); ok {
if len(v) > 0 {
types = strings.Split(v, ",")
for i := range types {
types[i] = strings.TrimSpace(types[i])
}
}
types[i] = trimType
}
dubboTarget.Types = types
return nil
Expand Down
7 changes: 4 additions & 3 deletions pixiu/pkg/client/dubbo/option_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,15 @@ func TestParamTypesOptAction(t *testing.T) {
assert.Equal(t, "string", target.Types[1])

err = opt.Action(target, "object,whatsoever")
assert.EqualError(t, err, "Types invalid whatsoever")
assert.Nil(t, err)

err = opt.Action("target", []string{})
assert.EqualError(t, err, "The val type must be string")
assert.EqualError(t, err, "Target is not dubboTarget in target parameter")
err = opt.Action(target, "object,")
assert.Nil(t, err)
assert.Equal(t, "object", target.Types[0])
err = opt.Action(target, "object")

err = opt.Action(target, "object ")
assert.Nil(t, err)
assert.Equal(t, "object", target.Types[0])
}
2 changes: 1 addition & 1 deletion cmd/pixiu/deployer.go → pixiu/pkg/cmd/deployer.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

package main
package cmd

type Deployer interface {
initialize() error
Expand Down
Loading

0 comments on commit 4ff167d

Please sign in to comment.