自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(19)
  • 收藏
  • 关注

原创 rust异步

异步web服务器

2023-02-22 18:58:52 130

原创 安卓上运行go服务

安卓运行golang

2021-12-17 17:12:00 2112

原创 go net/http实现路由函数转换的方法

package mainimport "fmt"type MHandler interface { ServeMyHTTP(req string, res string)}type MHandlerFunc func(req string, res string)func (f MHandlerFunc) ServeMyHTTP(req string, res string) { f(req, res)}func main() { h := func(req string.

2021-12-14 20:01:38 2007

原创 grpc使用多个中间件的转换

参考go-grpc-middleware的实现,将多个中间件转换为单个

2021-12-07 16:28:38 395

原创 Gin中间件实现原理

gin中实现中间件的方法,实际处理的handle应该放到最后

2021-12-07 11:51:17 189

原创 简单背包问题

package mainimport ( "fmt" "sort")type Item struct { Weight int Value int Ratio float64}func NewItem(weight int, value int) Item { item := Item { Weight: weight, Value: value, } item.Ratio = float64(value) / float64(weight) return ite.

2021-10-25 12:20:34 51

原创 mysql开启慢查询

查看是否开启慢查询show variables like 'slow_query_log%';show variables like 'long_query_time%';永久生效 修改`/etc/my.cnf`文件,添加一下配置,然后重启服务[mysqld]slow_query_log=1slow_query_log_file=/var/lib/mysql/slow-log.loglong_query_time=1...

2021-09-07 11:06:26 41

原创 git rebase 合并多个commit

当我们在某个分支上提交了多次`commit`的时候,如果直接推送到远程分支会污染提交历史。这时我们可以把多次`commit`合并成一次。 首先创建三个文件,每次都执行`git add .`和`git commit -m "xxx"` 命令。然后执行`git log`查看提交历史。touch 1.txtgit add .git commit -m "add 1"touch 2.txtgit add .git commit -m "add 2"touch 3....

2021-08-25 15:40:28 219

原创 go接口型函数

如何将一个函数(函数签名与F一致)转化为接口A: 定义一个函数类型 F,并且实现接口 A 的方法,然后在这个方法中调用自己。package mainimport "fmt"type A interface { Hello(k string, v string)}func B(k string, v string) { fmt.Println("B: ", k, v)}type C func(k string, v string)func (c C) Hel...

2021-08-12 15:05:48 150

原创 go web服务优雅关闭

package mainimport ( "context" "log" "net/http" "os" "os/signal" "time")func hello(w http.ResponseWriter, r *http.Request) { time.Sleep(20 * time.Second) w.Write([]byte("hello-v1")) log.Println("v1", r.RemoteAddr)}func main() { http.Han.

2021-07-26 03:13:09 296

原创 golang rsa签名与验签

package mainimport ( "crypto" "crypto/rand" "crypto/rsa" "crypto/sha256" "crypto/x509" "encoding/hex" "encoding/pem" "errors" "fmt")const ( publicKey = `-----BEGIN PUBLIC KEY-----MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCyPWejY7A+stkupI5Ow1aq.

2021-07-21 22:50:47 491

原创 golang Functional Options Pattern

type options struct { PanicWhenInitFail bool Debug bool}type optionFunc func(*options)func WithPanicWhenInitFail() optionFunc { return func(o *options) { o.PanicWhenInitFail = true }}func WithDebug() optionFunc { return func(o *.

2021-07-15 23:39:10 96

原创 go http中间件实现

```type DecoratorHandler func(http.HandlerFunc) http.HandlerFuncfunc MiddlewareHandlerFunc(hp http.HandlerFunc, decors ...DecoratorHandler) http.HandlerFunc { for d := range decors { dp := decors[len(decors)-1-d] hp = dp(hp) } ret

2021-07-13 18:15:41 173

原创 golang实现中间件

```type MiddlewareFunc func(HandlerFunc) HandlerFunctype HandlerFunc func() errorfunc applyMiddleware(h HandlerFunc, middleware MiddlewareFunc) HandlerFunc { h = middleware(h) return h}func main() { h := func() error { time.Sleep(

2021-07-07 16:06:34 254

原创 同步时间服务

centos定时同步时间服务器```*/5 * * * * root /usr/sbin/ntpdate ntp1.aliyun.com```在`/etc/cron.d`目录下创建文件`ntp.cron`然后写入以上内容即可,每五分钟执行一遍同步服务.

2021-03-05 10:25:13 71 1

原创 linux清空json文件并写入内容

tee hello.json >/dev/null <<EOF{"hello": "world"}EOF

2020-05-08 16:53:20 690

原创 linux获取本机ipaddress或hostname

获取iphostname -I | cut -d" " -f 1获取hostnamehostname -f

2020-05-08 16:39:06 674

原创 react hooks demo

先上个demo看下import React, { useState } from "react";function Example() { const [count, setCount] = useState(0); return ( <> Count: {count} <button onClick={() =&g...

2020-04-29 16:03:58 121

原创 快递鸟查询demo

快递鸟查询demoimport jsonfrom pprint import pprintimport requestsimport hashlibfrom base64 import b64encodeclass KdNiaoAPI: """快递鸟查询接口""" def __init__(self): # ID和Key请到官网申请:http://www....

2019-07-05 17:31:33 601

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除