Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
jinyaoMa committed Sep 15, 2022
1 parent a78e641 commit f60df2b
Show file tree
Hide file tree
Showing 17 changed files with 526 additions and 23 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Auto detect text files and perform LF normalization
* text=auto
build/** linguist-generated
backend/web/certs/** linguist-generated
27 changes: 16 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,29 @@

My App is a continuously updated personal service collection.

Prepare and install environment for development?
## Setup

Prepare and install environment for development in Window 10/11?

- Go v1.19+, https://go.dev/
- Node.js v16+, https://nodejs.org/
- PNPM v7+, https://pnpm.io/
- VS Code v1.71+, https://code.visualstudio.com/
- WebView2 v104+, https://developer.microsoft.com/en-us/microsoft-edge/webview2/

> Run command `pnpm install` at project root directory to setup.
## Technologies

| Technology | Role | Sources |
| :--------- | :--------------------------------------------------- | :------------------------------------ |
| Go | Backend programming language | https://pkg.go.dev/std |
| TypeScript | Frontend programming language | https://typescriptlang.org |
| Vite | Next Generation Frontend Tooling | https://vitejs.dev/ |
| Vue 3 | Progressive JavaScript Framework | https://vuejs.org/ |
| Wails | Build cross-platform desktop applications using Go | https://wails.io/ |
| UPX | Ultimate packer for executables | https://upx.github.io/ |
| Swaggo | Converts Go annotations to Swagger Documentation 2.0 | https://github.com/swaggo/swag |
| Systray | A cross platfrom system tray using Go | https://github.com/getlantern/systray |
| Technology | Role | Sources |
| :---------- | :---------------------------------------------------- | :------------------------------------ |
| Go | Backend programming language | https://pkg.go.dev/std |
| TypeScript | Frontend programming language | https://typescriptlang.org |
| Vite | Next Generation Frontend Tooling | https://vitejs.dev/ |
| Vue 3 | Progressive JavaScript Framework | https://vuejs.org/ |
| Wails | Build cross-platform desktop applications using Go | https://wails.io/ |
| UPX | Ultimate packer for executables | https://upx.github.io/ |
| Systray | A cross platfrom system tray using Go | https://github.com/getlantern/systray |
| Gin | A HTTP web framework using Go | https://gin-gonic.com/ |
| Gin Swagger | Gin middleware for API documentation with Swagger 2.0 | https://github.com/swaggo/gin-swagger |
| Swaggo | Converts Go annotations to Swagger Documentation 2.0 | https://github.com/swaggo/swag |
4 changes: 4 additions & 0 deletions backend/i18n/locale.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ type Locale struct {
Swagger string `json:"swagger"`
Start string `json:"start"`
Stop string `json:"stop"`
Dialog struct {
Start string `json:"start"`
Stop string `json:"stop"`
} `json:"dialog"`
} `json:"api_service"`
QuitDialog struct {
Message string `json:"message"`
Expand Down
6 changes: 5 additions & 1 deletion backend/i18n/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@
"api_service": {
"swagger": "Open API docs",
"start": "Enable API service",
"stop": "Disable API service"
"stop": "Disable API service",
"dialog": {
"start": "API service has been started.",
"stop": "API service has been stopped."
}
},
"quit_dialog": {
"message": "Are you sure to quit?",
Expand Down
6 changes: 5 additions & 1 deletion backend/i18n/locales/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@
"api_service": {
"swagger": "打开 API 文档",
"start": "开启 API 服务",
"stop": "关闭 API 服务"
"stop": "关闭 API 服务",
"dialog": {
"start": "已开启 API 服务。",
"stop": "已关闭API 服务。"
}
},
"quit_dialog": {
"message": "确认退出 我的应用程序 吗?",
Expand Down
8 changes: 5 additions & 3 deletions backend/tray/tray.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"log"
"my-app/backend/i18n"
"my-app/backend/tray/menus"
"my-app/backend/web"
"sync"

"github.com/getlantern/systray"
Expand Down Expand Up @@ -104,15 +105,15 @@ func (t *tray) onReady() {
SetIconStop(iconApiStop, iconApiStop).
Watch(menus.ApiServiceListener{
OnStart: func() bool {
return true
return web.Web().Start()
},
OnStop: func() bool {
return true
return web.Web().Stop()
},
OnOpenSwagger: func() {
runtime.BrowserOpenURL(
t.wailsCtx,
"https://www.baidu.com",
"https://localhost:10443/swagger/index.html",
)
},
})
Expand Down Expand Up @@ -187,5 +188,6 @@ func (t *tray) onQuit() {
t.colorTheme.StopWatch()
t.quit.StopWatch()

web.Web().Stop()
runtime.Quit(t.wailsCtx)
}
23 changes: 23 additions & 0 deletions backend/web/certs/localhost.crt

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

28 changes: 28 additions & 0 deletions backend/web/certs/localhost.key

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

49 changes: 49 additions & 0 deletions backend/web/docs/docs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Package docs GENERATED BY SWAG; DO NOT EDIT
// This file was generated by swaggo/swag
package docs

import "github.com/swaggo/swag"

const docTemplate = `{
"schemes": {{ marshal .Schemes }},
"swagger": "2.0",
"info": {
"description": "{{escape .Description}}",
"title": "{{.Title}}",
"contact": {
"name": "Github Issues",
"url": "https://github.com/jinyaoMa/my-app/issues"
},
"license": {
"name": "MIT",
"url": "https://github.com/jinyaoMa/my-app/blob/main/LICENSE"
},
"version": "{{.Version}}"
},
"host": "{{.Host}}",
"basePath": "{{.BasePath}}",
"paths": {},
"securityDefinitions": {
"BearerToken": {
"type": "apiKey",
"name": "Authorization",
"in": "header"
}
}
}`

// SwaggerInfo holds exported Swagger Info so clients can modify it
var SwaggerInfo = &swag.Spec{
Version: "1.0.0",
Host: "",
BasePath: "/api",
Schemes: []string{},
Title: "My App (backend/web/router.go)",
Description: "\"My App is a continuously updated personal service collection.\"",
InfoInstanceName: "swagger",
SwaggerTemplate: docTemplate,
}

func init() {
swag.Register(SwaggerInfo.InstanceName(), SwaggerInfo)
}
25 changes: 25 additions & 0 deletions backend/web/docs/swagger.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"swagger": "2.0",
"info": {
"description": "\"My App is a continuously updated personal service collection.\"",
"title": "My App (backend/web/router.go)",
"contact": {
"name": "Github Issues",
"url": "https://github.com/jinyaoMa/my-app/issues"
},
"license": {
"name": "MIT",
"url": "https://github.com/jinyaoMa/my-app/blob/main/LICENSE"
},
"version": "1.0.0"
},
"basePath": "/api",
"paths": {},
"securityDefinitions": {
"BearerToken": {
"type": "apiKey",
"name": "Authorization",
"in": "header"
}
}
}
18 changes: 18 additions & 0 deletions backend/web/docs/swagger.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
basePath: /api
info:
contact:
name: Github Issues
url: https://github.com/jinyaoMa/my-app/issues
description: '"My App is a continuously updated personal service collection."'
license:
name: MIT
url: https://github.com/jinyaoMa/my-app/blob/main/LICENSE
title: My App (backend/web/router.go)
version: 1.0.0
paths: {}
securityDefinitions:
BearerToken:
in: header
name: Authorization
type: apiKey
swagger: "2.0"
46 changes: 46 additions & 0 deletions backend/web/router.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package web

import (
_ "my-app/backend/web/docs"
"net/http"

"github.com/gin-gonic/gin"
swaggerfiles "github.com/swaggo/files"
ginSwagger "github.com/swaggo/gin-swagger"
)

// @title My App (backend/web/router.go)
// @version 1.0.0
// @description "My App is a continuously updated personal service collection."

// @contact.name Github Issues
// @contact.url https://github.com/jinyaoMa/my-app/issues

// @license.name MIT
// @license.url https://github.com/jinyaoMa/my-app/blob/main/LICENSE

// @BasePath /api

// @securityDefinitions.apikey BearerToken
// @in header
// @name Authorization

func router() *gin.Engine {
r := gin.Default()

r.GET("/", func(ctx *gin.Context) {
ctx.JSON(http.StatusOK, gin.H{
"Author": "pong",
})
})

r.GET(
"/swagger/*any",
ginSwagger.WrapHandler(
swaggerfiles.Handler,
ginSwagger.PersistAuthorization(true),
),
)

return r
}
Loading

0 comments on commit f60df2b

Please sign in to comment.