forked from jinyaoMa/my-app
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
303 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package model | ||
|
||
import "gorm.io/gorm" | ||
|
||
type MyOption struct { | ||
gorm.Model | ||
Name string `gorm:"unique"` // Option name | ||
Value string `` // Option value associated with name | ||
} | ||
|
||
func (mo *MyOption) Update(newValue string) *gorm.DB { | ||
return db.Model(mo).Where(mo).Updates(MyOption{ | ||
Value: newValue, | ||
}) | ||
} | ||
|
||
type MyOptions []MyOption | ||
|
||
func (mos MyOptions) Load() *gorm.DB { | ||
return db.Find(&mos) | ||
} | ||
|
||
func (mos MyOptions) Save() *gorm.DB { | ||
return db.Save(&mos) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,25 @@ | ||
package web | ||
|
||
import "flag" | ||
import ( | ||
// "context" | ||
"flag" | ||
// "time" | ||
) | ||
|
||
// for API service test purpose, testing with air | ||
// For API service test purpose, testing with air | ||
// Uncomment code below to run http redirector | ||
func (w *web) Air() { | ||
var flagAir int | ||
flag.IntVar(&flagAir, "air", 0, "set `-air 1` to enable web.Air function") | ||
flag.Parse() | ||
if flagAir == 1 { | ||
w.reset() | ||
// go w.http.ListenAndServe() | ||
w.https.ListenAndServeTLS("", "") | ||
|
||
// ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) | ||
// defer cancel() | ||
// w.http.Shutdown(ctx) | ||
// <-ctx.Done() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package test | ||
|
||
import ( | ||
"net/http" | ||
|
||
"github.com/gin-gonic/gin" | ||
) | ||
|
||
// @Summary Pass | ||
// @Description Test pass path | ||
// @Tags Test | ||
// @Accept json | ||
// @Produce json | ||
// @Success 200 {string} string "Pass Path" | ||
// @Router /test [get] | ||
func Test() gin.HandlerFunc { | ||
return func(ctx *gin.Context) { | ||
ctx.String(http.StatusOK, "Pass "+ctx.Request.URL.Path) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package auth | ||
|
||
import ( | ||
"net/http" | ||
|
||
"github.com/gin-gonic/gin" | ||
) | ||
|
||
// @Summary Login | ||
// @Description Login and get access token | ||
// @Tags Auth | ||
// @Accept x-www-form-urlencoded | ||
// @Produce json | ||
// @Param username formData string true "Username" | ||
// @Param password formData string true "Password" | ||
// @Router /auth/login [post] | ||
func Login() gin.HandlerFunc { | ||
return func(ctx *gin.Context) { | ||
ctx.JSON(http.StatusOK, gin.H{}) | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package web | ||
|
||
const ( | ||
CfgPortHttp = Package + ".PortHttp" | ||
CfgPortHttps = Package + ".PortHttps" | ||
CfgDirCerts = Package + ".DirCerts" | ||
) | ||
|
||
type Config struct { | ||
PortHttp string | ||
PortHttps string | ||
DirCerts string | ||
} | ||
|
||
func DefaultConfig() Config { | ||
return Config{ | ||
PortHttp: ":10080", | ||
PortHttps: ":10443", | ||
DirCerts: "", | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,8 @@ const docTemplate = `{ | |
"title": "{{.Title}}", | ||
"contact": { | ||
"name": "Github Issues", | ||
"url": "https://github.com/jinyaoMa/my-app/issues" | ||
"url": "https://github.com/jinyaoMa/my-app/issues", | ||
"email": "[email protected]" | ||
}, | ||
"license": { | ||
"name": "MIT", | ||
|
@@ -22,9 +23,34 @@ const docTemplate = `{ | |
}, | ||
"host": "{{.Host}}", | ||
"basePath": "{{.BasePath}}", | ||
"paths": {}, | ||
"paths": { | ||
"/test": { | ||
"get": { | ||
"description": "Test pass path", | ||
"consumes": [ | ||
"application/json" | ||
], | ||
"produces": [ | ||
"application/json" | ||
], | ||
"tags": [ | ||
"Test" | ||
], | ||
"summary": "Pass", | ||
"responses": { | ||
"200": { | ||
"description": "Pass Path", | ||
"schema": { | ||
"type": "string" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"securityDefinitions": { | ||
"BearerToken": { | ||
"description": "Authorization Header should contain value started with \"Bearer \" and followed by a JSON Web Token.", | ||
"type": "apiKey", | ||
"name": "Authorization", | ||
"in": "header" | ||
|
@@ -37,7 +63,7 @@ var SwaggerInfo = &swag.Spec{ | |
Version: "1.0.0", | ||
Host: "", | ||
BasePath: "/api", | ||
Schemes: []string{}, | ||
Schemes: []string{"https"}, | ||
Title: "My App (backend/web/router.go)", | ||
Description: "\"My App is a continuously updated personal service collection.\"", | ||
InfoInstanceName: "swagger", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,15 @@ | ||
{ | ||
"schemes": [ | ||
"https" | ||
], | ||
"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" | ||
"url": "https://github.com/jinyaoMa/my-app/issues", | ||
"email": "[email protected]" | ||
}, | ||
"license": { | ||
"name": "MIT", | ||
|
@@ -14,9 +18,34 @@ | |
"version": "1.0.0" | ||
}, | ||
"basePath": "/api", | ||
"paths": {}, | ||
"paths": { | ||
"/test": { | ||
"get": { | ||
"description": "Test pass path", | ||
"consumes": [ | ||
"application/json" | ||
], | ||
"produces": [ | ||
"application/json" | ||
], | ||
"tags": [ | ||
"Test" | ||
], | ||
"summary": "Pass", | ||
"responses": { | ||
"200": { | ||
"description": "Pass Path", | ||
"schema": { | ||
"type": "string" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"securityDefinitions": { | ||
"BearerToken": { | ||
"description": "Authorization Header should contain value started with \"Bearer \" and followed by a JSON Web Token.", | ||
"type": "apiKey", | ||
"name": "Authorization", | ||
"in": "header" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
basePath: /api | ||
info: | ||
contact: | ||
email: [email protected] | ||
name: Github Issues | ||
url: https://github.com/jinyaoMa/my-app/issues | ||
description: '"My App is a continuously updated personal service collection."' | ||
|
@@ -9,9 +10,28 @@ info: | |
url: https://github.com/jinyaoMa/my-app/blob/main/LICENSE | ||
title: My App (backend/web/router.go) | ||
version: 1.0.0 | ||
paths: {} | ||
paths: | ||
/test: | ||
get: | ||
consumes: | ||
- application/json | ||
description: Test pass path | ||
produces: | ||
- application/json | ||
responses: | ||
"200": | ||
description: Pass Path | ||
schema: | ||
type: string | ||
summary: Pass | ||
tags: | ||
- Test | ||
schemes: | ||
- https | ||
securityDefinitions: | ||
BearerToken: | ||
description: Authorization Header should contain value started with "Bearer " | ||
and followed by a JSON Web Token. | ||
in: header | ||
name: Authorization | ||
type: apiKey | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package middleware | ||
|
||
import "github.com/gin-gonic/gin" | ||
|
||
func Auth() gin.HandlerFunc { | ||
return func(ctx *gin.Context) { | ||
ctx.Next() | ||
} | ||
} |
Oops, something went wrong.