1
0
mirror of https://github.com/gusaul/grpcox.git synced 2024-12-26 02:40:10 +00:00

Compare commits

..

7 Commits

Author SHA1 Message Date
Muhammad Auliya
f240d0494e
Merge pull request #36 from beruangcoklat/master
handle error when remove and create directory
2022-10-18 17:38:06 +07:00
Muhammad Auliya
c5b61eb2d0
Merge pull request #39 from lilac/master
Update the url of code-prettify
2022-10-18 17:34:41 +07:00
Muhammad Auliya
c46a882ba7
Merge pull request #38 from petragabriela/f_petra_reflection-headers
feat: 🎸 allow using metadata as reflection headers
2022-10-18 17:33:00 +07:00
Junjun Deng
ca8f456f00 Update the url of code-prettify 2022-09-29 12:26:15 +08:00
Petra
63fe96c73d feat: 🎸 allow using metadata as reflection headers 2022-07-30 12:22:19 +07:00
beruangcoklat
6d348c6611 fix broken unit test 2022-05-26 08:00:15 +07:00
beruangcoklat
c2a6f5dd7f handling error in AddProtos 2022-05-26 08:00:05 +07:00
6 changed files with 45 additions and 5 deletions

View File

@ -137,6 +137,11 @@ func (g *GrpCox) Extend(host string) {
g.activeConn.extend(host, g.maxLifeConn)
}
// SetReflectHeaders sets grpcox reflection headers
func (g *GrpCox) SetReflectHeaders(headers ...string) {
g.reflectHeaders = headers
}
func (g *GrpCox) dial(ctx context.Context, target string, plainText bool) (*grpc.ClientConn, error) {
dialTime := 10 * time.Second
ctx, cancel := context.WithTimeout(ctx, dialTime)

View File

@ -285,8 +285,14 @@ func (r *Resource) AddProtos(protos []Proto) error {
protoPath := filepath.Join(BasePath, r.clientConn.Target())
err := os.MkdirAll(protoPath, 0777)
if os.IsExist(err) {
os.RemoveAll(protoPath)
err = os.RemoveAll(protoPath)
if err != nil {
return err
}
err = os.MkdirAll(protoPath, 0777)
if err != nil {
return err
}
} else if err != nil {
return err
}

View File

@ -60,7 +60,7 @@ func Test_prepareImport(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := prepareImport(tt.args.proto, ""); !reflect.DeepEqual(got, tt.want) {
if got := prepareImport(tt.args.proto); !reflect.DeepEqual(got, tt.want) {
t.Errorf("prepareImport() = %v, want %v",
string(got),
string(tt.want))

View File

@ -70,6 +70,26 @@ func (h *Handler) getLists(w http.ResponseWriter, r *http.Request) {
useTLS, _ := strconv.ParseBool(r.Header.Get("use_tls"))
restart, _ := strconv.ParseBool(r.FormValue("restart"))
// treat metadata as reflection headers
metadataHeader := r.Header.Get("Metadata")
metadataArr := strings.Split(metadataHeader, ",")
// construct array of strings with "key: value" form to be used in the reflection headers
var metadata []string
var metadataStr string
for i, m := range metadataArr {
i += 1
if isEven := i%2 == 0; isEven {
metadataStr = metadataStr + m
metadata = append(metadata, metadataStr)
metadataStr = ""
continue
}
metadataStr = fmt.Sprintf("%s:", m)
}
h.g.SetReflectHeaders(metadata...)
res, err := h.g.GetResource(context.Background(), host, !useTLS, restart)
if err != nil {
writeError(w, err)
@ -230,8 +250,8 @@ func (h *Handler) invokeFunction(w http.ResponseWriter, r *http.Request) {
var metadataStr string
for i, m := range metadataArr {
i += 1
if isEven := i % 2 == 0; isEven {
metadataStr = metadataStr+m
if isEven := i%2 == 0; isEven {
metadataStr = metadataStr + m
metadata = append(metadata, metadataStr)
metadataStr = ""
continue

View File

@ -231,7 +231,7 @@
<script type="text/javascript" src="js/popper.min.js"></script>
<script type="text/javascript" src="js/bootstrap.min.js"></script>
<script type="text/javascript" src="js/mdb.min.js"></script>
<script src="https://cdn.rawgit.com/google/code-prettify/master/loader/run_prettify.js"></script>
<script src="https://cdn.jsdelivr.net/gh/google/code-prettify@master/loader/run_prettify.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.4.1/ace.js"></script>
<script type="text/javascript" src="js/db.js"></script>
<script type="text/javascript" src="js/style.js"></script>

View File

@ -17,6 +17,12 @@ $('#get-services').click(function(){
use_tls = "true"
}
// use metadata if there is any
ctxArr = [];
$(".ctx-metadata-input-field").each(function(index, val){
ctxArr.push($(val).text())
});
// determine whether the proto connection will use local proto or not
const use_proto = $('#local-proto').is(":checked");
@ -51,6 +57,9 @@ $('#get-services').click(function(){
beforeSend: function(xhr){
$('#choose-service').hide();
xhr.setRequestHeader('use_tls', use_tls);
if(ctxUse) {
xhr.setRequestHeader('Metadata', ctxArr);
}
$(this).html("Loading...");
show_loading();
},