Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/gui v2 20211129 #2

Merged
merged 8 commits into from
Dec 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ BINARY=ptg
GOBUILD=go build -ldflags "-s -w" -o ${BINARY}
GOCLEAN=go clean
RMTARGZ=rm -rf *.gz
VERSION=0.0.2
VERSION=1.0.1

# Build
build:
Expand Down Expand Up @@ -47,6 +47,11 @@ gen-go-proto:
--go-grpc_out=. --go-grpc_opt=paths=source_relative \
reflect/gen/user.proto

gen-log-proto:
@protoc --go_out=. --go_opt=paths=source_relative \
--go-grpc_out=. --go-grpc_opt=paths=source_relative \
gui/io/log.proto

pkg-win:
fyne package -os windows -src gui/ -icon pic/gopher.png -name ${BINARY} -appVersion $(VERSION)

Expand Down
21 changes: 11 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,20 @@ Performance testing tool (Go), It is also a **GUI** `gRPC` client.
Test the `gRPC` service like `postman`.

![](pic/show.gif)
![](pic/ptg.gif)
![](pic/ptg-min.gif)


# Features
- [x] Cli performance test support.
- [x] GUI support.
- [x] Metadata support.
- [x] Data persistence.
- [ ] Stream call.
- [ ] Benchmark GUI.

# Install

## cli app
## Cli app
```go
go get github.com/crossoverJie/ptg
```
Expand Down Expand Up @@ -93,11 +102,3 @@ Number of Errors: 0
```


# TODO

- [x] cli support.
- [x] GUI support.
- [ ] metadata support.
- [ ] stream call.
- [ ] Data persistence.
- [ ] benchmark GUI.
36 changes: 23 additions & 13 deletions gui/app.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
package main

const (
AppName = "PTG gRPC client"
AppWeight = 1000
AppHeight = 500
HelpUrl = "https://github.com/crossoverJie/ptg"
RequestEntryPlaceHolder = "Input request json"
TargetInputText = "127.0.0.1:6001"
RequestButtonText = "RUN"
ResponseLabelText = "Response:"
AppName = "PTG gRPC client"
AppWeight = 1000
AppHeight = 500
HelpUrl = "https://github.com/crossoverJie/ptg"
TargetFormText = "Target:"
TargetFormHintText = "Input target url"
RequestEntryPlaceHolder = "Input request json"
MetaDataAccordion = "metadata"
MetaDataInputPlaceHolder = "Input metadata json"
TargetInputText = "127.0.0.1:6001"
RequestButtonText = "RUN"
ResponseLabelText = "Response:"
)

type App struct {
Expand All @@ -20,8 +24,10 @@ type App struct {
}

type RightRequest struct {
RequestEntryPlaceHolder, TargetInputText string
RequestButtonText string
TargetFormText, TargetFormHintText string
RequestEntryPlaceHolder, TargetInputText string
MetaDataAccordionTitle, MetaDataInputPlaceHolder string
RequestButtonText string
}

type RightResponse struct {
Expand All @@ -35,9 +41,13 @@ func InitApp() *App {
AppHeight: AppHeight,
HelpUrl: HelpUrl,
RightRequest: &RightRequest{
RequestEntryPlaceHolder: RequestEntryPlaceHolder,
TargetInputText: TargetInputText,
RequestButtonText: RequestButtonText,
TargetFormText: TargetFormText,
TargetFormHintText: TargetFormHintText,
RequestEntryPlaceHolder: RequestEntryPlaceHolder,
TargetInputText: TargetInputText,
MetaDataAccordionTitle: MetaDataAccordion,
MetaDataInputPlaceHolder: MetaDataInputPlaceHolder,
RequestButtonText: RequestButtonText,
},
RightResponse: &RightResponse{ResponseLabelText: ResponseLabelText},
}
Expand Down
182 changes: 182 additions & 0 deletions gui/io/log.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions gui/io/log.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
syntax = "proto3";
option go_package = "github.com/crossoverJie/ptg/gui/io";

package io;

message Log{
repeated string filenames = 1;
string target = 2;
string request = 3;
string metadata = 4;
string response = 5;
}
61 changes: 61 additions & 0 deletions gui/io/serialize.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package io

import (
"github.com/golang/protobuf/proto"
"io/ioutil"
"os"
"os/user"
)

func SaveLog(data []byte) error {
filename, err := initLog()
if err != nil {
return err
}

return ioutil.WriteFile(filename, data, 0666)
}

func initLog() (string, error) {
home, err := user.Current()
if err != nil {
return "", err
}

filename := home.HomeDir + "/.ptg/ptg.log"

if !exist(filename) {
err := os.MkdirAll(home.HomeDir+"/.ptg/", 0777)
if err != nil {
return "", err
}
_, err = os.Create(filename)
if err != nil {
return "", err
}
}
return filename, nil
}

func LoadLog() ([]byte, error) {
filename, err := initLog()
if err != nil {
return nil, err
}
return ioutil.ReadFile(filename)
}

func LoadLogWithStruct() (*Log, error) {
bytes, err := LoadLog()
var read Log
err = proto.Unmarshal(bytes, &read)
if err != nil {
return nil, err
}
return &read, nil
}

func exist(filename string) bool {
_, err := os.Stat(filename)
return err == nil || os.IsExist(err)
}
Loading