mirror of
https://github.com/gusaul/grpcox.git
synced 2024-12-25 09:50:10 +00:00
Compare commits
7 Commits
8534ee1dc1
...
f240d0494e
Author | SHA1 | Date | |
---|---|---|---|
|
f240d0494e | ||
|
c5b61eb2d0 | ||
|
c46a882ba7 | ||
|
ca8f456f00 | ||
|
63fe96c73d | ||
|
6d348c6611 | ||
|
c2a6f5dd7f |
|
@ -137,6 +137,11 @@ func (g *GrpCox) Extend(host string) {
|
||||||
g.activeConn.extend(host, g.maxLifeConn)
|
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) {
|
func (g *GrpCox) dial(ctx context.Context, target string, plainText bool) (*grpc.ClientConn, error) {
|
||||||
dialTime := 10 * time.Second
|
dialTime := 10 * time.Second
|
||||||
ctx, cancel := context.WithTimeout(ctx, dialTime)
|
ctx, cancel := context.WithTimeout(ctx, dialTime)
|
||||||
|
|
|
@ -285,8 +285,14 @@ func (r *Resource) AddProtos(protos []Proto) error {
|
||||||
protoPath := filepath.Join(BasePath, r.clientConn.Target())
|
protoPath := filepath.Join(BasePath, r.clientConn.Target())
|
||||||
err := os.MkdirAll(protoPath, 0777)
|
err := os.MkdirAll(protoPath, 0777)
|
||||||
if os.IsExist(err) {
|
if os.IsExist(err) {
|
||||||
os.RemoveAll(protoPath)
|
err = os.RemoveAll(protoPath)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
err = os.MkdirAll(protoPath, 0777)
|
err = os.MkdirAll(protoPath, 0777)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,7 +60,7 @@ func Test_prepareImport(t *testing.T) {
|
||||||
}
|
}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
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",
|
t.Errorf("prepareImport() = %v, want %v",
|
||||||
string(got),
|
string(got),
|
||||||
string(tt.want))
|
string(tt.want))
|
||||||
|
|
|
@ -70,6 +70,26 @@ func (h *Handler) getLists(w http.ResponseWriter, r *http.Request) {
|
||||||
useTLS, _ := strconv.ParseBool(r.Header.Get("use_tls"))
|
useTLS, _ := strconv.ParseBool(r.Header.Get("use_tls"))
|
||||||
restart, _ := strconv.ParseBool(r.FormValue("restart"))
|
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)
|
res, err := h.g.GetResource(context.Background(), host, !useTLS, restart)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
writeError(w, err)
|
writeError(w, err)
|
||||||
|
@ -230,8 +250,8 @@ func (h *Handler) invokeFunction(w http.ResponseWriter, r *http.Request) {
|
||||||
var metadataStr string
|
var metadataStr string
|
||||||
for i, m := range metadataArr {
|
for i, m := range metadataArr {
|
||||||
i += 1
|
i += 1
|
||||||
if isEven := i % 2 == 0; isEven {
|
if isEven := i%2 == 0; isEven {
|
||||||
metadataStr = metadataStr+m
|
metadataStr = metadataStr + m
|
||||||
metadata = append(metadata, metadataStr)
|
metadata = append(metadata, metadataStr)
|
||||||
metadataStr = ""
|
metadataStr = ""
|
||||||
continue
|
continue
|
||||||
|
|
|
@ -231,7 +231,7 @@
|
||||||
<script type="text/javascript" src="js/popper.min.js"></script>
|
<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/bootstrap.min.js"></script>
|
||||||
<script type="text/javascript" src="js/mdb.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 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/db.js"></script>
|
||||||
<script type="text/javascript" src="js/style.js"></script>
|
<script type="text/javascript" src="js/style.js"></script>
|
||||||
|
|
|
@ -17,6 +17,12 @@ $('#get-services').click(function(){
|
||||||
use_tls = "true"
|
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
|
// determine whether the proto connection will use local proto or not
|
||||||
const use_proto = $('#local-proto').is(":checked");
|
const use_proto = $('#local-proto').is(":checked");
|
||||||
|
|
||||||
|
@ -51,6 +57,9 @@ $('#get-services').click(function(){
|
||||||
beforeSend: function(xhr){
|
beforeSend: function(xhr){
|
||||||
$('#choose-service').hide();
|
$('#choose-service').hide();
|
||||||
xhr.setRequestHeader('use_tls', use_tls);
|
xhr.setRequestHeader('use_tls', use_tls);
|
||||||
|
if(ctxUse) {
|
||||||
|
xhr.setRequestHeader('Metadata', ctxArr);
|
||||||
|
}
|
||||||
$(this).html("Loading...");
|
$(this).html("Loading...");
|
||||||
show_loading();
|
show_loading();
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue
Block a user