Skip to content

Commit 1ea9d98

Browse files
committed
feat: initial commit with working GET request
0 parents  commit 1ea9d98

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+5224
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
build/bin
2+
node_modules
3+
frontend/dist

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# README
2+
3+
## About
4+
5+
This is the official Wails React-TS template.
6+
7+
You can configure the project by editing `wails.json`. More information about the project settings can be found
8+
here: https://wails.io/docs/reference/project-config
9+
10+
## Live Development
11+
12+
To run in live development mode, run `wails dev` in the project directory. This will run a Vite development
13+
server that will provide very fast hot reload of your frontend changes. If you want to develop in a browser
14+
and have access to your Go methods, there is also a dev server that runs on http://localhost:34115. Connect
15+
to this in your browser, and you can call your Go code from devtools.
16+
17+
## Building
18+
19+
To build a redistributable, production mode package, use `wails build`.

app.go

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
package main
2+
3+
import (
4+
"bytes"
5+
"context"
6+
"encoding/json"
7+
"io"
8+
"net/http"
9+
"strings"
10+
"time"
11+
)
12+
13+
// App struct
14+
type App struct {
15+
ctx context.Context
16+
client *http.Client
17+
}
18+
19+
// NewApp creates a new App application struct
20+
func NewApp() *App {
21+
return &App{}
22+
}
23+
24+
// startup is called when the app starts. The context is saved
25+
// so we can call the runtime methods
26+
func (a *App) startup(ctx context.Context) {
27+
tr := &http.Transport{
28+
MaxIdleConns: 2,
29+
IdleConnTimeout: 5 * time.Second,
30+
}
31+
a.client = &http.Client{
32+
Timeout: 5 * time.Second,
33+
Transport: tr,
34+
}
35+
a.ctx = ctx
36+
}
37+
38+
func MakeRequest(c *http.Client,
39+
r *http.Request) ([]byte, *http.Response, error) {
40+
resp, err := c.Do(r)
41+
if err != nil {
42+
return nil, resp, err
43+
}
44+
45+
defer resp.Body.Close()
46+
body, err := io.ReadAll(resp.Body)
47+
if err != nil {
48+
return nil, resp, err
49+
}
50+
51+
return body, resp, nil
52+
}
53+
54+
type RequestResult struct {
55+
Body string
56+
HeadersStr string
57+
Error string
58+
}
59+
60+
// Greet returns a greeting for the given name
61+
func (a *App) MakeRequest(urlIn string, method string) RequestResult {
62+
result := RequestResult{}
63+
r, err := http.NewRequest(method, urlIn, nil)
64+
if err != nil {
65+
result.Error = err.Error()
66+
return result
67+
}
68+
res, httpResp, err := MakeRequest(a.client, r)
69+
if err != nil {
70+
result.Error = err.Error()
71+
return result
72+
}
73+
74+
headersArr := []string{}
75+
for k, v := range httpResp.Header {
76+
vals := strings.Join(v, "; ")
77+
headersArr = append(headersArr, k+": "+vals)
78+
}
79+
result.HeadersStr = strings.Join(headersArr, "\n")
80+
81+
b := bytes.NewBuffer(make([]byte, 0, len(res)))
82+
err = json.Indent(b, res, "\n", " ")
83+
if err != nil {
84+
return RequestResult{
85+
Body: string(res),
86+
Error: err.Error(),
87+
}
88+
}
89+
90+
texts := string(b.Bytes())
91+
result.Body = texts
92+
return result
93+
}

build/README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Build Directory
2+
3+
The build directory is used to house all the build files and assets for your application.
4+
5+
The structure is:
6+
7+
* bin - Output directory
8+
* darwin - macOS specific files
9+
* windows - Windows specific files
10+
11+
## Mac
12+
13+
The `darwin` directory holds files specific to Mac builds.
14+
These may be customised and used as part of the build. To return these files to the default state, simply delete them
15+
and
16+
build with `wails build`.
17+
18+
The directory contains the following files:
19+
20+
- `Info.plist` - the main plist file used for Mac builds. It is used when building using `wails build`.
21+
- `Info.dev.plist` - same as the main plist file but used when building using `wails dev`.
22+
23+
## Windows
24+
25+
The `windows` directory contains the manifest and rc files used when building with `wails build`.
26+
These may be customised for your application. To return these files to the default state, simply delete them and
27+
build with `wails build`.
28+
29+
- `icon.ico` - The icon used for the application. This is used when building using `wails build`. If you wish to
30+
use a different icon, simply replace this file with your own. If it is missing, a new `icon.ico` file
31+
will be created using the `appicon.png` file in the build directory.
32+
- `installer/*` - The files used to create the Windows installer. These are used when building using `wails build`.
33+
- `info.json` - Application details used for Windows builds. The data here will be used by the Windows installer,
34+
as well as the application itself (right click the exe -> properties -> details)
35+
- `wails.exe.manifest` - The main application manifest file.

build/appicon.png

130 KB
Loading

build/darwin/Info.dev.plist

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
2+
<plist version="1.0">
3+
<dict>
4+
<key>CFBundlePackageType</key>
5+
<string>APPL</string>
6+
<key>CFBundleName</key>
7+
<string>{{.Info.ProductName}}</string>
8+
<key>CFBundleExecutable</key>
9+
<string>{{.Name}}</string>
10+
<key>CFBundleIdentifier</key>
11+
<string>com.wails.{{.Name}}</string>
12+
<key>CFBundleVersion</key>
13+
<string>{{.Info.ProductVersion}}</string>
14+
<key>CFBundleGetInfoString</key>
15+
<string>{{.Info.Comments}}</string>
16+
<key>CFBundleShortVersionString</key>
17+
<string>{{.Info.ProductVersion}}</string>
18+
<key>CFBundleIconFile</key>
19+
<string>iconfile</string>
20+
<key>LSMinimumSystemVersion</key>
21+
<string>10.13.0</string>
22+
<key>NSHighResolutionCapable</key>
23+
<string>true</string>
24+
<key>NSHumanReadableCopyright</key>
25+
<string>{{.Info.Copyright}}</string>
26+
<key>NSAppTransportSecurity</key>
27+
<dict>
28+
<key>NSAllowsLocalNetworking</key>
29+
<true/>
30+
</dict>
31+
</dict>
32+
</plist>

build/darwin/Info.plist

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
2+
<plist version="1.0">
3+
<dict>
4+
<key>CFBundlePackageType</key>
5+
<string>APPL</string>
6+
<key>CFBundleName</key>
7+
<string>{{.Info.ProductName}}</string>
8+
<key>CFBundleExecutable</key>
9+
<string>{{.Name}}</string>
10+
<key>CFBundleIdentifier</key>
11+
<string>com.wails.{{.Name}}</string>
12+
<key>CFBundleVersion</key>
13+
<string>{{.Info.ProductVersion}}</string>
14+
<key>CFBundleGetInfoString</key>
15+
<string>{{.Info.Comments}}</string>
16+
<key>CFBundleShortVersionString</key>
17+
<string>{{.Info.ProductVersion}}</string>
18+
<key>CFBundleIconFile</key>
19+
<string>iconfile</string>
20+
<key>LSMinimumSystemVersion</key>
21+
<string>10.13.0</string>
22+
<key>NSHighResolutionCapable</key>
23+
<string>true</string>
24+
<key>NSHumanReadableCopyright</key>
25+
<string>{{.Info.Copyright}}</string>
26+
</dict>
27+
</plist>

build/windows/icon.ico

20.5 KB
Binary file not shown.

build/windows/info.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"fixed": {
3+
"file_version": "{{.Info.ProductVersion}}"
4+
},
5+
"info": {
6+
"0000": {
7+
"ProductVersion": "{{.Info.ProductVersion}}",
8+
"CompanyName": "{{.Info.CompanyName}}",
9+
"FileDescription": "{{.Info.ProductName}}",
10+
"LegalCopyright": "{{.Info.Copyright}}",
11+
"ProductName": "{{.Info.ProductName}}",
12+
"Comments": "{{.Info.Comments}}"
13+
}
14+
}
15+
}

build/windows/installer/project.nsi

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
Unicode true
2+
3+
####
4+
## Please note: Template replacements don't work in this file. They are provided with default defines like
5+
## mentioned underneath.
6+
## If the keyword is not defined, "wails_tools.nsh" will populate them with the values from ProjectInfo.
7+
## If they are defined here, "wails_tools.nsh" will not touch them. This allows to use this project.nsi manually
8+
## from outside of Wails for debugging and development of the installer.
9+
##
10+
## For development first make a wails nsis build to populate the "wails_tools.nsh":
11+
## > wails build --target windows/amd64 --nsis
12+
## Then you can call makensis on this file with specifying the path to your binary:
13+
## For a AMD64 only installer:
14+
## > makensis -DARG_WAILS_AMD64_BINARY=..\..\bin\app.exe
15+
## For a ARM64 only installer:
16+
## > makensis -DARG_WAILS_ARM64_BINARY=..\..\bin\app.exe
17+
## For a installer with both architectures:
18+
## > makensis -DARG_WAILS_AMD64_BINARY=..\..\bin\app-amd64.exe -DARG_WAILS_ARM64_BINARY=..\..\bin\app-arm64.exe
19+
####
20+
## The following information is taken from the ProjectInfo file, but they can be overwritten here.
21+
####
22+
## !define INFO_PROJECTNAME "MyProject" # Default "{{.Name}}"
23+
## !define INFO_COMPANYNAME "MyCompany" # Default "{{.Info.CompanyName}}"
24+
## !define INFO_PRODUCTNAME "MyProduct" # Default "{{.Info.ProductName}}"
25+
## !define INFO_PRODUCTVERSION "1.0.0" # Default "{{.Info.ProductVersion}}"
26+
## !define INFO_COPYRIGHT "Copyright" # Default "{{.Info.Copyright}}"
27+
###
28+
## !define PRODUCT_EXECUTABLE "Application.exe" # Default "${INFO_PROJECTNAME}.exe"
29+
## !define UNINST_KEY_NAME "UninstKeyInRegistry" # Default "${INFO_COMPANYNAME}${INFO_PRODUCTNAME}"
30+
####
31+
## !define REQUEST_EXECUTION_LEVEL "admin" # Default "admin" see also https://nsis.sourceforge.io/Docs/Chapter4.html
32+
####
33+
## Include the wails tools
34+
####
35+
!include "wails_tools.nsh"
36+
37+
# The version information for this two must consist of 4 parts
38+
VIProductVersion "${INFO_PRODUCTVERSION}.0"
39+
VIFileVersion "${INFO_PRODUCTVERSION}.0"
40+
41+
VIAddVersionKey "CompanyName" "${INFO_COMPANYNAME}"
42+
VIAddVersionKey "FileDescription" "${INFO_PRODUCTNAME} Installer"
43+
VIAddVersionKey "ProductVersion" "${INFO_PRODUCTVERSION}"
44+
VIAddVersionKey "FileVersion" "${INFO_PRODUCTVERSION}"
45+
VIAddVersionKey "LegalCopyright" "${INFO_COPYRIGHT}"
46+
VIAddVersionKey "ProductName" "${INFO_PRODUCTNAME}"
47+
48+
!include "MUI.nsh"
49+
50+
!define MUI_ICON "..\icon.ico"
51+
!define MUI_UNICON "..\icon.ico"
52+
# !define MUI_WELCOMEFINISHPAGE_BITMAP "resources\leftimage.bmp" #Include this to add a bitmap on the left side of the Welcome Page. Must be a size of 164x314
53+
!define MUI_FINISHPAGE_NOAUTOCLOSE # Wait on the INSTFILES page so the user can take a look into the details of the installation steps
54+
!define MUI_ABORTWARNING # This will warn the user if they exit from the installer.
55+
56+
!insertmacro MUI_PAGE_WELCOME # Welcome to the installer page.
57+
# !insertmacro MUI_PAGE_LICENSE "resources\eula.txt" # Adds a EULA page to the installer
58+
!insertmacro MUI_PAGE_DIRECTORY # In which folder install page.
59+
!insertmacro MUI_PAGE_INSTFILES # Installing page.
60+
!insertmacro MUI_PAGE_FINISH # Finished installation page.
61+
62+
!insertmacro MUI_UNPAGE_INSTFILES # Uinstalling page
63+
64+
!insertmacro MUI_LANGUAGE "English" # Set the Language of the installer
65+
66+
## The following two statements can be used to sign the installer and the uninstaller. The path to the binaries are provided in %1
67+
#!uninstfinalize 'signtool --file "%1"'
68+
#!finalize 'signtool --file "%1"'
69+
70+
Name "${INFO_PRODUCTNAME}"
71+
OutFile "..\..\bin\${INFO_PROJECTNAME}-${ARCH}-installer.exe" # Name of the installer's file.
72+
InstallDir "$PROGRAMFILES64\${INFO_COMPANYNAME}\${INFO_PRODUCTNAME}" # Default installing folder ($PROGRAMFILES is Program Files folder).
73+
ShowInstDetails show # This will always show the installation details.
74+
75+
Function .onInit
76+
!insertmacro wails.checkArchitecture
77+
FunctionEnd
78+
79+
Section
80+
!insertmacro wails.setShellContext
81+
82+
!insertmacro wails.webview2runtime
83+
84+
SetOutPath $INSTDIR
85+
86+
!insertmacro wails.files
87+
88+
CreateShortcut "$SMPROGRAMS\${INFO_PRODUCTNAME}.lnk" "$INSTDIR\${PRODUCT_EXECUTABLE}"
89+
CreateShortCut "$DESKTOP\${INFO_PRODUCTNAME}.lnk" "$INSTDIR\${PRODUCT_EXECUTABLE}"
90+
91+
!insertmacro wails.writeUninstaller
92+
SectionEnd
93+
94+
Section "uninstall"
95+
!insertmacro wails.setShellContext
96+
97+
RMDir /r "$AppData\${PRODUCT_EXECUTABLE}" # Remove the WebView2 DataPath
98+
99+
RMDir /r $INSTDIR
100+
101+
Delete "$SMPROGRAMS\${INFO_PRODUCTNAME}.lnk"
102+
Delete "$DESKTOP\${INFO_PRODUCTNAME}.lnk"
103+
104+
!insertmacro wails.deleteUninstaller
105+
SectionEnd

0 commit comments

Comments
 (0)