Skip to content

Commit

Permalink
fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
lishenmiao committed Feb 18, 2023
1 parent 1bb9227 commit 3a7e8a8
Showing 9 changed files with 42 additions and 14 deletions.
6 changes: 5 additions & 1 deletion app.go
Original file line number Diff line number Diff line change
@@ -34,13 +34,17 @@ type Result struct {
HttpStatus string `json:"httpStatus"`
BodyContent string `json:"bodyContent"`
ErrorContent string `json:"errorContent"`
ContentType string `json:"contentType"`
}

func (a *App) Run(method string, url string, body string, contentType string) (Result, error) {
var err error
var result Result
req, err := http.NewRequest(method, url, bytes.NewReader([]byte(body)))
req.Header.Set("Content-Type", contentType)
req.Header.Set("User-Agent", "hiposter/0.0.4")
req.Header.Set("Accept", "*/*")
req.Header.Set("Connection", "keep-alive")
cli := http.Client{}
response, err := cli.Do(req)
if err != nil {
@@ -49,11 +53,11 @@ func (a *App) Run(method string, url string, body string, contentType string) (R
defer response.Body.Close()
result.StatusCode = response.StatusCode
result.HttpStatus = response.Status
result.ContentType = response.Header.Get("Content-Type")
buf, err := io.ReadAll(response.Body)
if err != nil {
return result, fmt.Errorf("read body error: %v", err)
}

result.BodyContent = string(buf)
return result, nil

2 changes: 0 additions & 2 deletions frontend/dist/assets/index.1ff9ce5b.js

This file was deleted.

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions frontend/dist/assets/index.9f43ac13.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions frontend/dist/index.html
Original file line number Diff line number Diff line change
@@ -5,8 +5,8 @@
<meta content="width=device-width, initial-scale=1.0" name="viewport"/>
<title>hiposter</title>

<script type="module" crossorigin src="/assets/index.1ff9ce5b.js"></script>
<link rel="stylesheet" href="/assets/index.4fd8d9fe.css">
<script type="module" crossorigin src="/assets/index.9f43ac13.js"></script>
<link rel="stylesheet" href="/assets/index.7b1be4d5.css">
</head>
<body>
<div id="app"></div>
10 changes: 6 additions & 4 deletions frontend/src/App.svelte
Original file line number Diff line number Diff line change
@@ -13,11 +13,12 @@
let url = "";
let bodyContent;
let result;
let contentType = "none";
let contentType = "application/none";
let btnValue = "Send";
let disabled = false;
let responseStatus;
let time;
let responseContentType;
function greet() {
Greet(name).then((result) => (resultText = result));
}
@@ -36,8 +37,9 @@
disabled = false;
btnValue = "Send";
responseStatus = res.httpStatus;
if (contentType == "application/json") {
let jsonPretty = JSON.stringify(JSON.parse(res.bodyContent), null, 8);
responseContentType = res.contentType;
if (responseContentType == "application/json") {
let jsonPretty = JSON.stringify(JSON.parse(res.bodyContent), null, 20);
return (result = jsonPretty);
} else {
@@ -56,7 +58,7 @@
bind:url
/>
<Request bind:bodyContent bind:contentType />
<Response bind:result {responseStatus} {time} />
<Response bind:result {responseStatus} {time} {responseContentType} />
</main>

<style>
24 changes: 22 additions & 2 deletions frontend/src/Response.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<script>
import "carbon-components-svelte/css/white.css";
// import JSONTree from "svelte-json-tree";
import { JsonView } from "@zerodevx/svelte-json-view";
import {
TextInput,
Button,
@@ -8,11 +10,13 @@
TextArea,
} from "carbon-components-svelte";
export let result;
export let result = "";
export let responseStatus;
export let responseContentType;
export let time;
</script>

{@debug result}
<div class="response">
{#if result}
<div>
@@ -22,7 +26,20 @@
<label>Time: <span class="statusValue">{time}</span></label>
</div>
{/if}
<textarea bind:value={result} placeholder="返回结果" rows={12} />
{#if responseContentType == "application/json"}
<!-- <div class="wrap" style="overflow: scroll;">
<JsonView calss="tree" json={JSON.parse(result)} />
</div> -->
<!-- <JsonView class="tree" json={JSON.parse(result)} /> -->
<!-- <JSONTree
class="tree"
value={JSON.parse(result)}
defaultExpandedLevel={3}
/> -->
<textarea bind:value={result} placeholder="返回结果" rows={12} />
{:else}
<textarea bind:value={result} placeholder="返回结果" rows={12} />
{/if}
</div>

<style>
@@ -45,4 +62,7 @@
.statusValue {
color: green;
}
.wrap {
overflow: scroll;
}
</style>
4 changes: 2 additions & 2 deletions frontend/src/requests/Body.svelte
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@
import { RadioButtonGroup, RadioButton } from "carbon-components-svelte";
import JsonInput from "./JsonInput.svelte";
let contentTypes = [
{ k: "none", v: "none" },
{ k: "none", v: "application/none" },
{ k: "form-data", v: "application/form-data" },
{ k: "x-www-from-urlencoded", v: "application/x-www-from-urlencoded" },
{ k: "JSON", v: "application/json" },
@@ -13,7 +13,7 @@
{ k: "JavaScript", v: "application/javaScript" },
{ k: "binary", v: "application/binary" },
];
export let contentType = "none";
export let contentType = "application/none";
export let value;
</script>

2 changes: 2 additions & 0 deletions frontend/wailsjs/go/models.ts
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@ export namespace main {
httpStatus: string;
bodyContent: string;
errorContent: string;
contentType: string;

static createFrom(source: any = {}) {
return new Result(source);
@@ -16,6 +17,7 @@ export namespace main {
this.httpStatus = source["httpStatus"];
this.bodyContent = source["bodyContent"];
this.errorContent = source["errorContent"];
this.contentType = source["contentType"];
}
}

0 comments on commit 3a7e8a8

Please # to comment.