Skip to content

Commit 4ff167d

Browse files
authored
1.0.0 (#602)
* 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)
1 parent 8046280 commit 4ff167d

File tree

10 files changed

+231
-235
lines changed

10 files changed

+231
-235
lines changed

cmd/pixiu/gateway.go

-70
This file was deleted.

cmd/pixiu/pixiu.go

+5-141
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@
1818
package main
1919

2020
import (
21-
"fmt"
2221
_ "net/http/pprof"
23-
"runtime"
2422
"strconv"
2523
"time"
2624
)
@@ -30,45 +28,15 @@ import (
3028
)
3129

3230
import (
33-
"github.com/apache/dubbo-go-pixiu/pixiu/pkg/common/constant"
34-
pxruntime "github.com/apache/dubbo-go-pixiu/pixiu/pkg/common/runtime"
35-
"github.com/apache/dubbo-go-pixiu/pixiu/pkg/config"
36-
"github.com/apache/dubbo-go-pixiu/pixiu/pkg/logger"
37-
"github.com/apache/dubbo-go-pixiu/pixiu/pkg/model"
31+
"github.com/apache/dubbo-go-pixiu/pixiu/pkg/cmd"
3832
_ "github.com/apache/dubbo-go-pixiu/pixiu/pkg/pluginregistry"
39-
"github.com/apache/dubbo-go-pixiu/pixiu/pkg/server"
4033
)
4134

42-
var (
35+
const (
4336
// Version pixiu version
44-
Version = "0.6.0"
45-
46-
flagToLogLevel = map[string]string{
47-
"trace": "TRACE",
48-
"debug": "DEBUG",
49-
"info": "INFO",
50-
"warning": "WARN",
51-
"error": "ERROR",
52-
"critical": "FATAL",
53-
}
54-
55-
configPath string
56-
apiConfigPath string
57-
logConfigPath string
58-
logLevel string
59-
60-
// CURRENTLY USELESS
61-
logFormat string
62-
63-
limitCpus string
64-
65-
// Currently default set to false, wait for up coming support
66-
initFromRemote = false
37+
Version = "1.0.0"
6738
)
6839

69-
// deploy server deployment
70-
var deploy = &DefaultDeployer{}
71-
7240
// main pixiu run method
7341
func main() {
7442
app := getRootCmd()
@@ -88,112 +56,8 @@ func getRootCmd() *cobra.Command {
8856
Version: Version,
8957
}
9058

91-
rootCmd.AddCommand(gatewayCmd)
92-
rootCmd.AddCommand(sideCarCmd)
59+
rootCmd.AddCommand(cmd.GatewayCmd)
60+
rootCmd.AddCommand(cmd.SideCarCmd)
9361

9462
return rootCmd
9563
}
96-
97-
type DefaultDeployer struct {
98-
bootstrap *model.Bootstrap
99-
configManger *config.ConfigManager
100-
}
101-
102-
func (d *DefaultDeployer) initialize() error {
103-
104-
err := initLog()
105-
if err != nil {
106-
logger.Warnf("[startGatewayCmd] failed to init logger, %s", err.Error())
107-
}
108-
109-
// load Bootstrap config
110-
d.bootstrap = d.configManger.LoadBootConfig(configPath)
111-
if err != nil {
112-
panic(fmt.Errorf("[startGatewayCmd] failed to get api meta config, %s", err.Error()))
113-
}
114-
115-
err = initLimitCpus()
116-
if err != nil {
117-
logger.Errorf("[startCmd] failed to get limit cpu number, %s", err.Error())
118-
}
119-
120-
return err
121-
}
122-
123-
func (d *DefaultDeployer) start() error {
124-
server.Start(d.bootstrap)
125-
return nil
126-
}
127-
128-
func (d *DefaultDeployer) stop() error {
129-
//TODO implement me
130-
panic("implement me")
131-
}
132-
133-
// initDefaultValue If not set both in args and env, set default values
134-
func initDefaultValue() {
135-
if configPath == "" {
136-
configPath = constant.DefaultConfigPath
137-
}
138-
139-
if apiConfigPath == "" {
140-
apiConfigPath = constant.DefaultApiConfigPath
141-
}
142-
143-
if logConfigPath == "" {
144-
logConfigPath = constant.DefaultLogConfigPath
145-
}
146-
147-
if logLevel == "" {
148-
logLevel = constant.DefaultLogLevel
149-
}
150-
151-
if limitCpus == "" {
152-
limitCpus = constant.DefaultLimitCpus
153-
}
154-
155-
if logFormat == "" {
156-
logFormat = constant.DefaultLogFormat
157-
}
158-
}
159-
160-
// initLog
161-
func initLog() error {
162-
err := logger.InitLog(logConfigPath)
163-
if err != nil {
164-
// cause `logger.InitLog` already handle init failed, so just use logger to log
165-
return err
166-
}
167-
168-
if level, ok := flagToLogLevel[logLevel]; ok {
169-
logger.SetLoggerLevel(level)
170-
} else {
171-
logger.SetLoggerLevel(flagToLogLevel[constant.DefaultLogLevel])
172-
return fmt.Errorf("logLevel is invalid, set log level to default: %s", constant.DefaultLogLevel)
173-
}
174-
return nil
175-
}
176-
177-
// initApiConfig return value of the bool is for the judgment of whether is a api meta data error, a kind of silly (?)
178-
func initApiConfig() (*model.Bootstrap, error) {
179-
bootstrap := config.Load(configPath)
180-
return bootstrap, nil
181-
}
182-
183-
func initLimitCpus() error {
184-
limitCpuNumberFromEnv, err := strconv.ParseInt(limitCpus, 10, 64)
185-
if err != nil {
186-
return err
187-
}
188-
limitCpuNumber := int(limitCpuNumberFromEnv)
189-
if limitCpuNumber <= 0 {
190-
limitCpuNumber = pxruntime.GetCPUNum()
191-
}
192-
runtime.GOMAXPROCS(limitCpuNumber)
193-
logger.Infof("GOMAXPROCS set to %v", limitCpuNumber)
194-
return nil
195-
}
196-
197-
func init() {
198-
deploy.configManger = config.NewConfigManger()
199-
}

go.mod

+1
Original file line numberDiff line numberDiff line change
@@ -328,3 +328,4 @@ require (
328328
)
329329

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

pixiu/pkg/client/dubbo/option.go

+8-13
Original file line numberDiff line numberDiff line change
@@ -186,24 +186,19 @@ type paramTypesOpt struct{}
186186
// Action for paramTypesOpt override the other param types mapping/config.
187187
// The val must be string(e.g. "int, object"), and will then assign to the target.(dubboTarget).Types
188188
func (opt *paramTypesOpt) Action(target, val interface{}) error {
189-
v, ok := val.(string)
190-
if !ok {
191-
return errors.New("The val type must be string")
192-
}
193-
types := strings.Split(v, ",")
194189
dubboTarget, ok := target.(*dubboTarget)
195190
if !ok {
196191
return errors.New("Target is not dubboTarget in target parameter")
197192
}
198-
for i := range types {
199-
trimType := strings.TrimSpace(types[i])
200-
if len(trimType) == 0 {
201-
continue
202-
}
203-
if _, ok = constant.JTypeMapper[trimType]; !ok {
204-
return errors.Errorf("Types invalid %s", trimType)
193+
// empty types for func like func()
194+
types := make([]string, 0)
195+
if v, ok := val.(string); ok {
196+
if len(v) > 0 {
197+
types = strings.Split(v, ",")
198+
for i := range types {
199+
types[i] = strings.TrimSpace(types[i])
200+
}
205201
}
206-
types[i] = trimType
207202
}
208203
dubboTarget.Types = types
209204
return nil

pixiu/pkg/client/dubbo/option_test.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,15 @@ func TestParamTypesOptAction(t *testing.T) {
8484
assert.Equal(t, "string", target.Types[1])
8585

8686
err = opt.Action(target, "object,whatsoever")
87-
assert.EqualError(t, err, "Types invalid whatsoever")
87+
assert.Nil(t, err)
8888

8989
err = opt.Action("target", []string{})
90-
assert.EqualError(t, err, "The val type must be string")
90+
assert.EqualError(t, err, "Target is not dubboTarget in target parameter")
9191
err = opt.Action(target, "object,")
9292
assert.Nil(t, err)
9393
assert.Equal(t, "object", target.Types[0])
94-
err = opt.Action(target, "object")
94+
95+
err = opt.Action(target, "object ")
9596
assert.Nil(t, err)
9697
assert.Equal(t, "object", target.Types[0])
9798
}

cmd/pixiu/deployer.go pixiu/pkg/cmd/deployer.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* limitations under the License.
1616
*/
1717

18-
package main
18+
package cmd
1919

2020
type Deployer interface {
2121
initialize() error

0 commit comments

Comments
 (0)