Skip to content

Commit

Permalink
0
Browse files Browse the repository at this point in the history
  • Loading branch information
logoove committed Mar 22, 2022
1 parent 75356bc commit 7225631
Show file tree
Hide file tree
Showing 40 changed files with 699 additions and 2 deletions.
22 changes: 21 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,26 @@ db.Exec(`CREATE TABLE users (
fmt.Println(rows)
~~~

goframe中只需在boot 下面go文件里面加上 `_ github.com/logoove/sqlite`即可在orm使用,不需要任何其他修改
goframe1.16中只需在boot 下面go文件里面加上 `_ github.com/logoove/sqlite`即可在orm使用,不需要任何其他修改
goframe2.0中,在manifeat/config/config.yaml配置
~~~
# 数据库连接配置
database:
logger:
path: "./temp/logs/sql"
level: "all"
stdout: true
ctxKeys: ["RequestId"]
default:
type: "sqlite"
link: "./resource/db.db" #数据库路径根据自己的填写
debug: true
~~~
,在internel/cmd/cmd.go 中加入_ "github.com/logoove/sqlite"即可,已经将驱动改成sqlite3,所以能够直接在goframe中使用.
插入数据
~~~
id, _ := g.Model("user").Data(g.Map{"name": "john", "age": 1}).InsertAndGetId()
~~~
### 更新日志
2022-3-22 v1.15.3 新增win amd64编译,解决内存泄漏问题.
2021-11-3 v1.13.0 新增更多系统编译,支持sqlite 3.36.0
20 changes: 20 additions & 0 deletions examples/gflay/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
.buildpath
.hgignore.swp
.project
.orig
.swp
.idea/
.settings/
.vscode/
vendor/
composer.lock
gitpush.sh
pkg/
bin/
cbuild
**/.DS_Store
.vscode/
.test/
main
output/
manifest/output/
21 changes: 21 additions & 0 deletions examples/gflay/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2022 yoby

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
5 changes: 5 additions & 0 deletions examples/gflay/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# goframe2.0例子
编译
go build
访问
http://127.0.0.1:8000/hello
12 changes: 12 additions & 0 deletions examples/gflay/api/v1/hello.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package v1

import (
"github.com/gogf/gf/v2/frame/g"
)

type HelloReq struct {
g.Meta `path:"/hello" tags:"Hello" method:"get" summary:"You first hello api"`
}
type HelloRes struct {
g.Meta `mime:"text/html" example:"string"`
}
10 changes: 10 additions & 0 deletions examples/gflay/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module gflay

go 1.15

require (
github.com/gogf/gf/v2 v2.0.0-rc.0.20220117131058-9345eb5e946f
github.com/logoove/sqlite v1.13.0
github.com/russross/blackfriday/v2 v2.1.0
modernc.org/sqlite v1.15.3 // indirect
)
310 changes: 310 additions & 0 deletions examples/gflay/go.sum

Large diffs are not rendered by default.

30 changes: 30 additions & 0 deletions examples/gflay/internal/cmd/cmd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package cmd

import (
"context"

"gflay/internal/controller"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/net/ghttp"
"github.com/gogf/gf/v2/os/gcmd"
_ "github.com/logoove/sqlite"
)

var (
Main = gcmd.Command{
Name: "main",
Usage: "main",
Brief: "start http server",
Func: func(ctx context.Context, parser *gcmd.Parser) (err error) {
s := g.Server()
s.Group("/", func(group *ghttp.RouterGroup) {
group.Middleware(ghttp.MiddlewareHandlerResponse)
group.Bind(
controller.Hello,
)
})
s.Run()
return nil
},
}
)
1 change: 1 addition & 0 deletions examples/gflay/internal/consts/consts.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package consts
20 changes: 20 additions & 0 deletions examples/gflay/internal/controller/hello.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package controller

import (
"context"
"gflay/api/v1"

"github.com/gogf/gf/v2/frame/g"
)

var (
Hello = cHello{}
)

type cHello struct{}

func (h *cHello) Hello(ctx context.Context, req *v1.HelloReq) (res *v1.HelloRes, err error) {
id, _ := g.Model("user").Data(g.Map{"name": "john", "age": 1}).InsertAndGetId()
g.RequestFromCtx(ctx).Response.Writeln("Hello World!", id)
return
}
Empty file.
Empty file.
1 change: 1 addition & 0 deletions examples/gflay/internal/packed/packed.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package packed
Empty file.
Empty file.
Empty file.
12 changes: 12 additions & 0 deletions examples/gflay/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package main

import (
_ "gflay/internal/packed"

"github.com/gogf/gf/v2/os/gctx"
"gflay/internal/cmd"
)

func main() {
cmd.Main.Run(gctx.New())
}
43 changes: 43 additions & 0 deletions examples/gflay/manifest/config/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
server:
address: ":8000"
openapiPath: "/api.json"
swaggerPath: "/swagger"
serverRoot: "resource/public"
dumpRouterMap: true
routeOverWrite: true
accessLogEnabled: false
accessLogPattern: "access-{Ymd}.log"
sessionPath: "./temp/sessions" # Session文件存储目录
logger:
level : "all"
stdout: true
path: "./temp/logs/default"
ctxKeys: ["RequestId"]
# 数据库连接配置
database:
logger:
path: "./temp/logs/sql"
level: "all"
stdout: true
ctxKeys: ["RequestId"]

default:
type: "sqlite"
# link: "mysql:root:mysql@tcp(127.0.0.1:3306)/gflay"
link: "./resource/db.db"
debug: true
# 模板引擎配置
viewer:
indexLayout: "index/index.html"
adminHomeLayout: "admin/home.html"
adminLayout: "admin/index.html"
# 内容设置
setting:
title: "拾人拾物"
keywords: "寻人寻物"
description: "寻人寻物平台"
adminId: 1 # 管理员ID

# 文件上传设置
upload:
path: "upload"
21 changes: 21 additions & 0 deletions examples/gflay/manifest/deploy/kustomize/base/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: template-single
labels:
app: template-single
spec:
replicas: 1
selector:
matchLabels:
app: template-single
template:
metadata:
labels:
app: template-single
spec:
containers:
- name : main
image: template-single
imagePullPolicy: Always

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- deployment.yaml
- service.yaml



12 changes: 12 additions & 0 deletions examples/gflay/manifest/deploy/kustomize/base/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: v1
kind: Service
metadata:
name: template-single
spec:
ports:
- port: 80
protocol: TCP
targetPort: 8000
selector:
app: template-single

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: template-single-configmap
data:
config.yaml: |
server:
address: ":8000"
openapiPath: "/api.json"
swaggerPath: "/swagger"
logger:
level : "all"
stdout: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: template-single
spec:
template:
spec:
containers:
- name : main
image: template-single:develop
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

resources:
- ../../base
- configmap.yaml

patchesStrategicMerge:
- deployment.yaml

namespace: default



19 changes: 19 additions & 0 deletions examples/gflay/manifest/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
FROM loads/alpine:3.8

###############################################################################
# INSTALLATION
###############################################################################

ENV WORKDIR /app

ADD resource $WORKDIR/

ADD ./bin/linux_amd64/main $WORKDIR/main

RUN chmod +x $WORKDIR/main

###############################################################################
# START
###############################################################################
WORKDIR $WORKDIR
CMD ./main
8 changes: 8 additions & 0 deletions examples/gflay/manifest/docker/docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

# This shell is executed before docker build.





Binary file added examples/gflay/resource/db.db
Binary file not shown.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file added examples/gflay/utility/.gitkeep
Empty file.
55 changes: 55 additions & 0 deletions examples/gflay/utility/response/response.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package response

import (
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/net/ghttp"
)

// JsonRes 数据返回通用JSON数据结构
type JsonRes struct {
Code int `json:"code"` // 错误码((0:成功, 1:失败, >1:错误码))
Message string `json:"message"` // 提示信息
Data interface{} `json:"data"` // 返回数据(业务接口定义具体数据结构)
Redirect string `json:"redirect"` // 引导客户端跳转到指定路由
}

// Json 返回标准JSON数据。
func Json(r *ghttp.Request, code int, message string, data ...interface{}) {
var responseData interface{}
if len(data) > 0 {
responseData = data[0]
} else {
responseData = g.Map{}
}
r.Response.WriteJson(JsonRes{
Code: code,
Message: message,
Data: responseData,
})
}

// JsonExit 返回标准JSON数据并退出当前HTTP执行函数。
func JsonExit(r *ghttp.Request, code int, message string, data ...interface{}) {
Json(r, code, message, data...)
r.Exit()
}

// JsonRedirect 返回标准JSON数据引导客户端跳转。
func JsonRedirect(r *ghttp.Request, code int, message, redirect string, data ...interface{}) {
responseData := interface{}(nil)
if len(data) > 0 {
responseData = data[0]
}
r.Response.WriteJson(JsonRes{
Code: code,
Message: message,
Data: responseData,
Redirect: redirect,
})
}

// JsonRedirectExit 返回标准JSON数据引导客户端跳转,并退出当前HTTP执行函数。
func JsonRedirectExit(r *ghttp.Request, code int, message, redirect string, data ...interface{}) {
JsonRedirect(r, code, message, redirect, data...)
r.Exit()
}
10 changes: 10 additions & 0 deletions examples/gflay/utility/utils/utils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package utils

import (
"github.com/russross/blackfriday/v2"
)

// MarkdownToHtml 解析markdown为html
func MarkdownToHtml(mdContent string) string {
return string(blackfriday.Run([]byte(mdContent)))
}
Loading

0 comments on commit 7225631

Please sign in to comment.