Golang grpc服务中 接受json 并解析参数
package main
import (
"encoding/json"
"context"
"xxxxx/grpc"
"githum.com/mitchellh/mapstructure"
)
type JsonTypeRequest struct {
Id int `mapstructure:"id"`
Title string `mapstructure:"title"`
}
func main(ctx context.Context, req *grpc.ParamRequest) (*JsonTypeRequest, error) {
var param map[string]interface{}
err := json.Unmarshal([]byte(req.Request), ¶m)
fmt.Println ...
go 配置 grpc
*.proto
syntax = "proto3";
package grpc;
option go_package = "./;grpc";
service Genter {
rpc List (ParamRequest) returns (DataResponse) {}
}
message ParamRequest {
string request = 1;
}
message DataResponse {
string response = 1;
}
生成路径protoc --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative *.proto
快速生成模型gentool -dsn "username:password@tcp(127.0.0.1:3306)/database?ch ...
go 递归实现 无限极分类
// RecursiveList 递归处理list
func RecursiveList(list []model.XfArticleCategory, pid int) []model.XfArticleCategory {
res := make([]model.XfArticleCategory, 0)
for _, v := range list {
if v.Category_pid == pid {
v.Child = RecursiveList(list, v.Id)
if v.Child == nil {
v.Child = make([]model.XfArticleCategory, 0)
}
res = append(res, v)
}
}
return res
}
Golang GORM 增删改查
创建结构体
type User struct {
Id int `gorm:"column:id;primaryKey;autoIncrement:true" json:"id"`
UserName string `gorm:"column:user_name" json:"user_name"`
CreatedAt int `gorm:"column:created_at" json:"created_at"`
UpdatedAt int `gorm:"column:updated_at" json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"column:deleted_at" json:"-"`
}
新增
user := User{} ...
GO中 interface{} 转string
第一种
var test interface{}
str := fmt.Sprintf("%v",test) //强制转为字符串
第二种
func GetInterfaceToString(value interface{}) string {
// interface 转 string
var key string
if value == nil {
return key
}
switch value.(type) {
case float64:
ft := value.(float64)
key = strconv.FormatFloat(ft, 'f', -1, 64)
case float32:
ft := value.(float32)
key = strconv.FormatFloat(float64(ft), ...
gorm 生成 查询条件
package models
import (
"fmt"
"strings"
)
type NullType byte
const (
_ NullType = iota
// IsNull the same as `is null`
IsNull
// IsNotNull the same as `is not null`
IsNotNull
)
// sql build where
func WhereBuild(where map[string]interface{}) (whereSQL string, vals []interface{}, err error) {
for k, v := range where {
ks := strings.Split(k, " ")
if len(ks) > 2 {
retur ...
thinkphp 使用TCPDF把html转pdf
`composer require tecnickcom/tcpdf`
<?php
namespace app\api\controller;
use think\facade\Env;
use think\facade\Db;
use TCPDF;
class FilesController extends BaseController
{
public function index()
{
$url = 'uploads'.DIRECTORY_SEPARATOR.'paper'.DIRECTORY_SEPARATOR.'1.pdf';
// 生成PDF
$pdf = new TCPDF('P', 'mm', 'A4', true, 'UTF-8', false);
$pdf->SetMargins(15, 15, 15);
$pdf-&g ...
Hello World
Welcome to Hexo! This is your very first post. Check documentation for more info. If you get any problems when using Hexo, you can find the answer in troubleshooting or you can ask me on GitHub.
Quick StartCreate a new post1$ hexo new "My New Post"
More info: Writing
Run server1$ hexo server
More info: Server
Generate static files1$ hexo generate
More info: Generating
Deploy to remote sites1$ hexo deploy
More info: Deployment