头像

SolitudeAlma




离线:2小时前


最近来访(1054)
用户头像
我不明智
用户头像
柠檬草的味道
用户头像
kkop
用户头像
熠丶
用户头像
coder_xi
用户头像
Acwer
用户头像
派大星
用户头像
阿飞被注册了
用户头像
宇哥
用户头像
有机物
用户头像
Bi08xw
用户头像
某位不愿透露姓名的金发小女孩
用户头像
我是菜狗啊啊啊啊啊
用户头像
Gzyymz
用户头像
dqwd
用户头像
yxc的小迷妹
用户头像
Bsqaq
用户头像
PerfectLife
用户头像
dade68
用户头像
草雨田yy


Gin框架中处理请求参数的零值问题

有时候参数验证需要用到类型零值,比如bool 或是标志位(0表示xxx,1表示xxx)。
这时候gin的参数验证库对struct的 json:"xxx" binding:"required" 这个tag验证是,必须带上这个参数,并且不为零值,因为不带上的话json反序列化就是零值

所以我们可以这么做


type UserInfoReq struct {
    Username string `json:"username" binding:"required"`
    Sex      *int    `json:"sex" binding:"required"`
}

这样就能真确获取想要的数据,而不会验证失败




golang复用http.request.body
[Go - Note] http.Response.Body 多次读取处理
Gin框架,body参数只能读取一次
[go] Gin中间件中获取request.body
Gin框架参数多次绑定

具体原因无非是读取body是类似读缓存区的数据,读完之后数据就是空的,最简单的做法就是读完之后把数据放回去

buf := &bytes.Buffer{}
oldBody := io.TeeReader(ctx.Request.Body, buf)
body, err := ioutil.ReadAll(oldBody)
ctx.Request.Body = ioutil.NopCloser(bytes.NewBuffer(buf))


body, err := ioutil.ReadAll(ctx.Request.Body)
ctx.Request.Body = ioutil.NopCloser(bytes.NewBuffer(body))
ctx.Request.Body.Close() // 用完记得关掉io流 可以用defer






SolitudeAlma
1个月前

今天摸鱼写微信支付的时候遇到了这样一个问题

我用了第三方的框架PowerWeChat来处理微信的服务端api。当我处理支付回调通知时,先在函数外部定义了想要的数据,然后在内部赋值,具体的看下面的代码,你就能明白了

func xxx() {
    order := &model.Order{}

    _, err := wechat.PaymentApp.HandlePaidNotify(
        r,
        func(message *request.RequestNotify, transaction *models2.Transaction, fail func(message string)) interface{} {
            var err error
            order, err := l.orderRepo.GetOrderByTradeNo(ctx, transaction.OutTradeNo) // 从数据库查询订单信息
            logx.Infof("order:%+v, transaction:%+v,  message: %+v", order, transaction, message)
            if err != nil || order.IsEmpty() {
                logx.Errorf("获取用户开通空间的订单失败", err)
                return nil
            }
            ... 其他逻辑
        },
    )
    ... 其他逻辑
    fmt.Printf("%+v", order) // 打印为空
}

大家注意一个细节,我在函数内部调用查询订单的函数时,因为go的原因,:=形式声明的变量,只要有一个未定义过就需要加上 :,但并不会为order再次声明,看上去没什么问题,然后在xxx函数最后打印的时候order为空(非nil),也就是所有字段都是零值。

我的猜想是函数内部定义与外部相同的变量时,如果遇上了 :=,那么就会降低此变量的作用域,相当于范围变小了。

以下是我的复现代码,具体原因也没有深究,感兴趣的小伙伴可以试试,知道答案的也可以在评论区留言哦~

package main

import (
    "fmt"
)

type order struct {
    ID int
}

func a(b func()) {
    b()
}

func c() (o *order, err error) {
    o = &order{ID: 1}
    return 
}

func d() (*order) {

    e := &order{}
    // 返回创建的闭包
    a(func() {
        // e, err := c() // 输出为空
        var err error
        e, err = c()
        if err != nil {
            fmt.Println(err)
        }

        e.ID += 2
    })

    return e
}


func main() {

    e := d()

    fmt.Printf("%+v", e)
}



SolitudeAlma
1个月前

yitter/IdGenerator
golang下的UUID生成
技术译文 | UUID 很火但性能不佳?今天我们细聊一聊
MySQL8索引与调优篇7-索引优化与查询优化

如果打算使用uuid做主键,建议用纯数字且单调递增的算法,并且全局唯一,那么雪花飘移算法就是你的首选

Tips: 用自增主键做关联表建立两表之间的联系时会遇到一个问题(其实就是存在关系的两张表,把它们的自增主键拿出来,在第三张表上存起来,这在我看来是比较通用的做法),这只局限于小项目,不会涉及到扩张问题。也就是说甚至不会分库分表。因为用自增主键作为主键的表,在分布式系统中,是不那么好扩容的,如果我的系统中用了4个独立的数据库,那么在设置自增主键的自增步长时,就应该是从 1,2,3,4 开始,步长为4。这样在分布式系统中就能在数据库层面上做到全局唯一的id。但是分布式系统最大的特点就是体量大,随时都会遇到需要扩容的情况,那么数据库一扩容,重新设置步长也好说,但是之前的数据咋迁移呢?所以现在分布式系统都会用到分布式id生成的算法,在代码层面做到全局唯一,而算法通常也会有机器id作为生成id的机器标识,尽管有上限,但一般都开不了那么多机器。




SolitudeAlma
1个月前


分享 三户模型

SolitudeAlma
1个月前



SolitudeAlma
3个月前



SolitudeAlma
3个月前

pushdeer仅在苹果商店上架!

彩虹屁api:https://www.tianapi.com/apiview/181
天气api:https://dev.qweather.com/docs/api/weather/weather-daily-forecast/
pushdeer:http://www.pushdeer.com/

效果:
pushdeer_demo.jpg

/**
 * @Author: SolitudeAlma
 * @Date: 2022 2022/8/31 0:34
 */

package main

import (
    "bufio"
    "crypto/rand"
    "encoding/json"
    "fmt"
    "github.com/go-co-op/gocron"
    "github.com/go-resty/resty/v2"
    "io"
    "io/ioutil"
    "math/big"
    "net/http"
    "os"
    "strconv"
    "strings"
    "time"
)

const (
    rainbowFartApiKey = ""
    weatherApiKey     = ""
    locationId        = ""
    pushKey           = ""
    anniversaryDate   = ""
)

var (
    weeks = [7]string{"一", "二", "三", "四", "五", "六", "日"}
)

type newsList struct {
    Content string `json:"content"`
}

type rainbowFart struct {
    NewsList []newsList `json:"newsList"`
}

type daily struct {
    TextDay string `json:"textDay"`
    TempMax string `json:"tempMax"`
    TempMin string `json:"tempMin"`
}

type weather struct {
    Daily []daily `json:"daily"`
}

func getRainbowFart(url string) (result rainbowFart) {
    client := resty.New()
    resp, err := client.R().
        SetHeader("Content-Type", "application/json").
        SetBody(map[string]interface{}{"key": rainbowFartApiKey}).
        Post(url)

    err = json.Unmarshal(resp.Body(), &result)
    if err != nil {
        fmt.Println("序列化json失败", err)
    }
    return result
}

func getWeather(url string) (result weather) {
    method := "GET"
    client := &http.Client{}
    req, err := http.NewRequest(method, url, nil)
    if err != nil {
        fmt.Println(err)
        return
    }
    res, err := client.Do(req)
    if err != nil {
        fmt.Println(err)
        return
    }
    defer func(Body io.ReadCloser) {
        err := Body.Close()
        if err != nil {
            return
        }
    }(res.Body)

    body, err := ioutil.ReadAll(res.Body)
    if err != nil {
        fmt.Println(err)
        return
    }

    err = json.Unmarshal(body, &result)
    if err != nil {
        fmt.Println("序列化json失败", err)
    }
    return result
}

func push(url string, body map[string]interface{}) (result string) {
    client := resty.New()
    resp, err := client.R().
        SetHeader("Content-Type", "application/json").
        SetBody(body).
        Post(url)
    if err != nil {
        fmt.Println(err)
        return
    }
    return string(resp.Body())
}

// 每日金句,一个txt,从文件读取,然后每次推送随机取一个
func randomWords() []string {
    words := make([]string, 0, 1024)
    // 创建句柄
    fi, err := os.Open("jinju.txt")
    if err != nil {
        panic(err)
    }

    // 创建 Reader
    r := bufio.NewReader(fi)

    for {
        line, err := r.ReadString('\n')
        line = strings.TrimSpace(line)
        if err != nil && err != io.EOF {
            panic(err)
        }
        if err == io.EOF {
            break
        }
        if line != "" {
            words = append(words, line)
        }
    }
    return words
}

// 计算日期差,大的日期在前
func calculateDateDifference(format string, date1Str string, date2Str string) (int, error) {
    // 转化字符串为Time格式
    date1, err := time.ParseInLocation(format, date1Str, time.Local)
    if err != nil {
        return 0, err
    }
    // 转化字符串为Time格式
    date2, err := time.ParseInLocation(format, date2Str, time.Local)
    if err != nil {
        return 0, err
    }
    //计算相差天数
    return int(date1.Sub(date2).Hours() / 24), nil
}

// 实际逻辑
func work(words []string) {
    // 拼接字符串貌似builder比较快
    var builder strings.Builder

    // 真随机数
    result, _ := rand.Int(rand.Reader, big.NewInt(int64(len(words)-1)))

    // 因为每日金句是两行,一中一英,感觉写的不是很好,有思路的小伙伴可以在评论区给出
    idx := result.Int64()
    if result.Int64() > int64(len(words))-3 {
        idx = int64(len(words)) - 3
    } else if result.Int64()%2 != 0 {
        idx = result.Int64() + 1
    }

    // api调用
    rainbowFartApiUrl := "http://api.tianapi.com/caihongpi/index?key=" + rainbowFartApiKey
    rainbowFartContent := getRainbowFart(rainbowFartApiUrl)
    weatherApiUrl := "https://devapi.qweather.com/v7/weather/3d?key=" + weatherApiKey + "&location=" + locationId
    weatherContent := getWeather(weatherApiUrl)
    title := "烦人精的宝🧚‍♀"
    currentTime := time.Now()
    year := currentTime.Year()
    month := strconv.Itoa(int(currentTime.Month()))
    day := strconv.Itoa(currentTime.Day())
    //很多语言返回的月份、日,都不会有前导零,如果格式需要可以加
    if currentTime.Month() < 10 && currentTime.Month() > 0 {
        month = "0" + month
    }
    if currentTime.Day() < 10 && currentTime.Day() > 0 {
        day = "0" + day
    }
    weekday := int(currentTime.Weekday())
    // 计算周年次数和距下一周年还差几天
    date := strconv.Itoa(year) + "-" + month + "-" + day
    date1 := strconv.Itoa(year) + "-11-01"
    days, _ := calculateDateDifference("2006-01-02", date, anniversaryDate)
    days1, _ := calculateDateDifference("2006-01-02", date1, date)
    if days1 < 0 {
        date1 = strconv.Itoa(year+1) + "-" + month + "-" + day
        days1, _ = calculateDateDifference("2006-01-02", date1, date)
    }

    var anniversaryCnt int
    for i := 2021; i <= year; i++ {
        if i == year && (days < 365 && days > 0) {
            anniversaryCnt--
        } else {
            if (i%4 == 0 && i%100 != 0) || (i%400 == 0 && i%3200 != 0) || i%172800 == 0 {
                days -= 366
            } else {
                days -= 365
            }
        }
        anniversaryCnt++
    }
    // pushdeer支持消息主题是md文档
    builder.WriteString(date + "星期" + weeks[weekday])
    builder.WriteString("\n\n")
    builder.WriteString("* 天气:")
    builder.WriteString(weatherContent.Daily[0].TextDay)
    builder.WriteString("\n\n")
    builder.WriteString("* 最低温度:")
    builder.WriteString(weatherContent.Daily[0].TempMin)
    builder.WriteString("\n\n")
    builder.WriteString("* 最高温度:")
    builder.WriteString(weatherContent.Daily[0].TempMax)
    builder.WriteString("\n\n")
    builder.WriteString("我们在一起已经" + strconv.Itoa(anniversaryCnt) + "周年啦")
    builder.WriteString("\n\n")
    builder.WriteString("距离周年纪念日还差" + strconv.Itoa(days1) + "天噢")
    builder.WriteString("\n\n")
    builder.WriteString("**" + rainbowFartContent.NewsList[0].Content + "**")
    builder.WriteString("\n\n")
    builder.WriteString("**" + words[idx+1] + "**")
    builder.WriteString("\n\n")
    builder.WriteString("**" + words[idx] + "**")
    markdownContent := builder.String()

    pushUrl := ""
    pushBody := make(map[string]interface{})
    pushBody["text"] = title
    pushBody["pushkey"] = pushKey
    pushBody["desp"] = markdownContent
    pushBody["type"] = "markdown"
    push(pushUrl, pushBody)
}

func main() {
    words := randomWords()
    timezone, _ := time.LoadLocation("Asia/Shanghai")
    s := gocron.NewScheduler(timezone)
    // 爱她就每天八点发给她
    _, err := s.Every(1).Hour().Do(func() {
        go work(words)
    })
    if err != nil {
        return
    }
    s.StartBlocking()
}

每日金句

Positive thinking initiates more happiness!
积极的思考带来更多的快乐。

Failure is the fog through which we glimpse triumph.
透过失败的迷雾,才能瞥见胜利的光辉。

Trust is earned.
信任是要靠行动争取的。

Tears will never help.
眼泪永远没办法帮上忙。

The only way to achieve the impossible is to believe it is possible.
实现“不可能”唯一的方法,就是相信它是可能的。

We all carry something with us.
我们都在负重前行。

Don't you love New Year's Day? You get to start all over!
你不喜欢过新年吗?你能一切从头开始!

Where did the time go?
时间都到哪去了?

Everybody deserves to be loved.
每个人都值得被爱。

It's no use going back to yesterday, because I was a different person then.
回顾昨天毫无用处,因为我已今非昔比。

I wish every day is merry, not just Christmas.
我希望每天都快乐,不止圣诞。

Come on and let it snow!
来吧,下一场雪!

Kept in a small bowl, the goldfish will remain small.
呆在小鱼缸里的金鱼永远不会长大。

The man who removes a mountain begins by carrying away small stones.
移开山头的人总是从搬小石头开始。

When I shiver with cold, not a snowflake is innocent.
当我冷得瑟瑟发抖时,没有一片雪花是无辜的。

However bad life may seem, there is always something you can do, and succeed at.
无论生活多么艰辛,你总会有自己的方式发光。

I'm trying everything.
我什么都要试试。

Witnesses pass, but history is eternal. - From China Daily
逝者长已矣,历史永铭记。

Everything that has a beginning has an end.
世间万物有始皆有终。

They tell me that I'm crazy, but I'll never let them change me.
就算他们叫我疯子,我也不会因此改变分毫。

I'm doing better than I ever was.
我已今非昔比。

A timely snow promises a good harvest.
瑞雪兆丰年。

I love you just the way you are.
我就喜欢原原本本真实的你。

Never give up until the fight is over.
永远不要放弃,要一直战斗到最后一秒。

What's done cannot be undone.
覆水难收。

Some rise by sin, and some by virtue fall.
有些人因罪恶而升迁,有些人因美德而没落。

We are going forward to the future, not back into the past.
我们要迈向未来,而不是沉湎于过去。

To be a sailor of the world, bound for all ports.
做世界的水手,游遍所有的港口。

A drop of water in need, shall be returned with a spring in deed.
滴水之恩,涌泉相报。

Live for the moment.
活在当下。

The greater the man, the more restrained his anger.
人越伟大,越能克制怒火。

The snow whispers around me.
雪花萦绕在我耳边,窃窃私语。

Before you meet someone who loves you more, you must love yourself well.
在遇到更爱自己的人之前,一定要好好爱自己。

If you don't walk out, you will think that this is the whole world.
走出去,才能看到更大的世界。

An open mind is a gold mine.
解放思想,黄金万两。

Life is short but its tortuous way is long.
人生不满百,常怀千岁忧。

After all, tomorrow is another day.
不管怎样,明天又是新的一天。

Words and ideas can change the world.
文字和思想能改变世界。

Pain is inevitable. Suffering is optional.
痛是难免的,苦却是甘愿的。

Ultimately, it is the desire, not the desired, that we love.
归根结底,我们爱的不是欲望之物,而是欲望本身。

Money burns a hole in my pocket!
我兜儿里的钱呢!

To infinity and beyond!
飞向宇宙,浩瀚无垠!

Studies serve for delight, for ornament and for ability.
读书足以怡情,足以博彩,足以长才。

What we call "failure" is not falling down, but the staying down.
所谓“失败”不是跌倒,而是就此躺平。

The most exhausting thing in life is being insincere.
生活中最使人筋疲力尽的事是弄虚作假。

The struggle makes everything all the more worth it.
奋斗让一切都变得更有价值。

People follow the brave, not the high.
人们追随勇敢者,而不是位高者。

The memory is a muscle that must be exercised.
记忆就像一块肌肉,必须要勤运动。

I am the master of my own destiny.
我命由我不由天。

Do you want to make a Jack-o'-lantern?
你想做个南瓜灯吗?

True masters tend to focus on one thing and do it well.
真正的大师往往专注于打磨一件事。

When you really matter to someone, that person will always make time for you.
真正在乎你的人,从来都“不忙”。

Loving parents is also a child's instinct.
爱父母,也是孩子的本能。

After all the difficult times, you will embrace a bright future.
熬过所有的艰难时刻,你将前程似锦。

Our meeting is just meaningful only if you wanna see me.
只有你想见我的时候,我们的相遇才有意义。

The better you become, the better you attract.
你若盛开,蝴蝶自来。

Don't stay mad for too long. Learn to leave things behind.
生气不宜太久,要学会放下。

At this moment, I miss you more than usual.
在这一刻,我比平时更想你。

It's hard to please everyone, so keep delightful for yourself.
众口难调,开心就好。

Everything is dangerous. If it weren't so, life wouldn't be worth living.
凡事皆有风险。若非如此,人生将不值一过。

A rose by any other name would smell as sweet.
玫瑰即使换了名字也依旧芬芳。

We turn not older with years, but newer every day.
我们并非在年复一年地变老,而是日复一日地焕然一新。

The frog in the well knows nothing of the great ocean.
井底之蛙,不知大海。

Sometimes, the right one for you is the one who was there the whole time.
有时候,对的那个人,就是始终陪伴左右的那个。

The elderly is history and drama for reference of our lives.
老人犹如历史和戏剧,可为我们的生活提供参考。

I dreamed a lot when I was a child, but now I just want to get rich overnight.
小时候的我梦想有很多,可现在我只想一夜暴富。

Those who have knocked me down, thank you! It's so comfortable to lie down.
那些曾经把我击倒的人,谢谢你们!躺平真舒服。

Love is like the moon. When it does not increase, it decreases.
爱情就像月亮,不增则减。

Everything in the past is a mirror of wisdom.
过往一切都是智慧的映射。

Things do not change. We do.
万物不变,是我们在变。

The end of the holiday feels like the end of the world.
假期结束,末日来临。

Whatever is going to happen will happen, whether we worry or not.
不管你焦虑与否,该发生的总会发生。

At the place we don't know, there is always some sadness we haven't seen.
在我们不曾了解的地方,总有些未曾看到的心酸。

Don't look at your phone for more than two hours, because it will power off.
千万不要连续看手机超过两个小时,因为那样手机会没电。

East or west, home is the best.
金窝银窝不如自家的草窝。

It's time to start living the life you've imagined!
是时候开始过自己想要的生活了!

Patriotism is deeply rooted in the instincts and emotions of human being.
爱国精神深深根植于人的本能和情感之中。

Hang in there! Victory is just around the corner!
坚持住!胜利就在前方!

I'm just an emotionless working machine.
我只是一个没有感情的工作机器。

Keep what you say and carry out what you do.
言必行,行必果。

It's easy to straighten a tree when it's small, but it's difficult to stretch a tree when it's big.
树小扶直易,树大扳伸难。

I have tried my best to live an ordinary life.
我拼劲全力,不过是为了过完平凡的一生。

Every leaf speaks bliss to me, fluttering from the autumn tree.
每一片飘落的秋叶,都在向我诉说着狂喜。

No man needs a vacation much as the man who has just had one.
没有人比刚刚过完假期的人更需要假期了。

Up the bright moon rises from the sea; I share the same moment though far from thee.
海上生明月,天涯共此时。

Don't moon away the Mid-Autumn Festival.
找点事儿做吧,不要虚度了中秋佳节。

The family is more important than the dream.
家人是比梦想更重要的事情。

From my father's perspective, the sweep of the sweeping robot is soulless.
在我爸看来,扫地机器人扫的地,没有灵魂。

You will never make money outside of your cognition.
你永远也赚不到自己认知范围之外的钱。

This world never lacks criticism and advice, but lacks reason and thinking.
这个世界从不缺批判和指教,缺的是理智和思考。

Where there is praise, there is controversy.
哪里有称赞,哪里就有争议。

I've been wet by the rain, so I want to hold an umbrella for someone else.
我淋过雨,所以也想给别人撑把伞。

It is during our darkest moments that we must focus to see the light.
越是至暗时刻,我们越要集中精神去寻找光明。

Justice has long arms.
天网恢恢,疏而不漏。

Knowledge is the eye of the mind.
知识是心灵的眼睛。

No matter what label is thrown your way, only you can define yourself.
不管你被贴上什么标签,只有你才能定义你自己。

Keep on going and never give up.
勇往直前,决不放弃。

However mean your life is, meet it and live it; do not shun it and call it hard times.
不论你的生活如何卑微,面对它,活下去,不要逃避,也不要恶语相向。

If I throw these keys away, those doors will be closed forever.
如果我把这些钥匙丢掉,那些门将永远都不会被打开。

Nothing can be accomplished without norms or standards.
没有规矩不成方圆。

A man can't ride your back unless it is bent.
你挺直腰杆,别人就不能骑到你的背上。

Don't make a permanent decision for your temporary emotion.
别因一时冲动去做影响一生的决定。

Distance doesn't ruin a relationship. Doubts do.
毁灭感情的不是距离,而是怀疑。

The whole of life already framed right there.
浮生一切,早已入画。

With great power comes great responsibility.
能力越大,责任越大。

I wonder how I ever thought you weren't perfect.
我想知道我以前怎么会觉得你不完美。

What doesn't kill you makes you stronger, stand a little taller.
一切不曾将你毁灭的都会让你变得更强大,站得更高。

We're like a pair of odd socks. And I'm the stretched-out, misshapen one.
我们好像是一双落单的袜子。我是拉长了,变了形的那只。

Perfection is not just about control. It's also about letting go.
完美不是控制出来的,是爆发出来的。

The weak can never forgive. Forgiveness is the attribute of the strong.
弱者永远都不会宽恕,宽恕乃强者特质。

How do you say goodbye to someone you can't imagine living without?
该如何与那个你无法想象失去的人说再见呢?

Good looks may fade, but a good heart keeps you beautiful forever.
芳容易逝,而善心却能令美丽永驻。

Life is like a shower. One wrong turn and you're in hot water.
生活就像淋浴,方向转错,水深火热。

Winning that ticket was the best thing that ever happened to me.
赌赢那张船票,是我一生中最幸运的事。

Whatever you do, just don't make any rash decision.
无论你想做什么,千万不要贸然行事。

Life without love is like a tree without blossoms or fruit.
缺少爱的生命,一如未开花结果的枯树。

Don't be pushed around by the fears in your mind.
不要被你内心的恐惧所左右。

Venture outside your comfort zone! The rewards are worth it.
勇敢踏出舒适圈去冒险吧!那些回报绝对值得。

Autumn is quiet, in this season you can calm down to taste the life of each section.
在静谧的秋季,你可以静下心来品味生活的每一个章节。

Friendship means understanding, not agreement.
友谊是理解,而非妥协。

The only person you should try to be better than is the person you were yesterday.
你唯一的对手,就是昨天的自己。

We are forever indebted to those who have given their lives that we might be free.
我们永远感激那些为我们的自由而献出生命的人。

If you focus on what you left behind, you will never be able to see what lies ahead.
如果你专注于过去,你将永远看不到未来。

I can't give up without a fight!
我不能不战而降!

The situation is not quite so cut and dried.
情况并非已成定局。

You must take life the way it comes at you and make the best of it.
你应该随遇而安,尽可能地享受生活。

Everyone makes mistakes, but if love is there, then there's a path to redemption.
孰能无过,但只要有爱,便有救赎之道。

No one ever made a difference by being like everyone else.
要成为有影响力的人,不能只安于和别人相同。

The rest of the world may follow the rules, but I must follow my heart.
世人也许循规蹈矩,但我必须遵从内心。

Even with two eyes, you only see half of the picture.
即便亲眼所见,也无法窥得全貌。

You have dreams,you go to protect it.
如果你有梦想,就去守护它。

A real loser is someone so afraid of not wining, they don't even try.
真正的失败者是那些害怕失败不敢尝试的人。

It hurts to remember,but it would be worse to forget.
铭记虽痛苦,但遗忘更糟糕。

If you want to understand today , you have to search yesterday.
如果你想参透今天,就必须探究昨天。

Don't ever let anything affect your life.
永远不要让任何事影响你的人生。

The higher I got, the more amazed I was by the view.
我爬得越高,越为眼前的风景所惊叹。

Take nothing on its looks, take everything on evidence. There's no better rule.
表象切莫轻信,凡事证据先行,此乃真律。

A problem well stated is a problem half solved.
问题说清楚了,就相当于解决一半了。

Our job is improving the quality of life, not just delaying death.
我们要做的是提升生活品质,而非仅仅延缓死亡。

Only through pain can you achieve your greatness.
唯有痛苦能使你伟大。

You are never wrong to do the right thing.
坚持做对的事,你永远不会错。

This world may be rough around the edges, but it’s got its charms.
这个世界可能很粗野,但有其魅力所在。

Reality doesn’t change according to your will.
现实不会因为你的意志而改变。

A man is like a novel: until the very last page you don't know how it will end.
人就像一部小说:除非翻到最后一页,否则你不知道TA有怎样的结局。

It takes a great deal of courage to stand alone even if you believe in something very strongly.
即使坚信不疑,独树一帜也需要巨大的勇气。

There’s room for sentiment but not sentimentality.
可以有感情,但不能感情用事。

Why are you trying so hard to fit in when you were born to stand out?
你生来就是要引人注目的,为什么还要如此努力地融入?

History and reality tell us that we should cherish today and strive for strength.
历史与现实告诉我们应该珍惜当下,奋发图强。

Since 1921, the Communist party of China has gone through a glorious history of 100 years.
自1921年以来,中国共产党已走过了一百年的辉煌历程。

It’s what you do right now that makes a difference.
你现在所做的是改变现状的关键。

Experience never goes out of fashion.
经验永远不会过时。

There is no certainty, only opportunity.
没有必然,只有机遇。

Take the sourest lemon that life has to offer and turn it into something resembling lemonade.
将生活带给你柠檬般的酸楚,酿成犹如柠檬汽水般的甘甜。

The more you know who you are, and what you want, the less you let things upset you.
你对你是谁以及你想要什么了解得越多,困扰你的事情就越少。

You can not live your life according to maybes.
你不能只靠「如果」来过自己的人生。

Nothing in this world that is worth having comes easy.
这世界上凡是值得拥有的东西,都不易获得。

Life is mediocre, short and long, but there is no way to know what is good or bad, gain or loss is difficult.
人生碌碌,竞短论长,却不道荣枯有数,得失难量。

I am not afraid of storms,for I am learning how to sail my ship.
我不害怕风暴, 因为我正在学习如何乘风破浪。

You make millions of decisions that mean nothing and then one day your order takes out and it changes your life.
你每天都在做很多看起来毫无意义的决定,但某天你的某个决定就能改变你的一生。

Victory won’t come to me unless I go to it.
胜利是不会向我走来的,我必须自己走向胜利。

I thought I'd make a difference,but no one knows I'm here.
我还妄想大展身手 到头来还不是默默无闻.。

Love is the one thing that transcends time and space.
只有爱可以穿越时空。

Will, work and wait are the pyramidal cornerstones for success.
意志、工作和等待是成功的金字塔的基石。

The real death is that no one in the world remembers you.
真正的死亡是世界上再没有一个人记得你。

Never give up, always have hope in frontwaiting for.
永不放弃,总有希望在前面等待。

One's real value first lies in to what degree and what sense he set himself.
一个人的真正价值首先决定于他在什么程度上和在什么意义上从自我解放出来。

Some people feel the rain. Others just get wet.
有些人能感受雨,而其他人则只是被淋湿。

Yesterday is history, tomorrow is a mystery. But today is a gift.
昨日已成往事,未来还未可知。但是今天是上天的馈赠。

The greatest gift you can give anyone is your undivided attention.
你能够给予一个人的最好礼物是你对他毫不分心的关注。

In this world, you can either do things the easy way or the right way.
在这个世界,办事情一旦偷懒就办不好。

What makes life dreary is the want of motive.
没有了目的,生活便郁闷无光。

It isn't the big pleasures that count the most; it's making a great deal out of the little ones.
最重要的不是有大快乐,而是能充分享受小快乐。

There are billions and millions of unlived days for every day we live.
我们每度过一天,都有千千万万个未曾活过的日子与我们擦肩而过。

To suffer without complaining is the only lesson that has to be learned in this life.
默默承受,是人生唯一必须懂得的道理。

Be like a duck. Calm on the surface, but always paddling like the dickens underneath.
做只鸭子吧!表面上安静镇定,而水底里却不停地打着脚掌。

Instead of holding on to those who have already left, cherish those who stayed behind.
与其执著于谁当初离你而去,不如感谢谁最后留了下来。

A lie can travel halfway around the world while the truth is still putting on its shoes.
当真理还正在穿鞋的时候,谎言就能走遍半个世界。

You are not stuck because you can't, you're stuck because you won't.
你不是不能挣脱,你只是不愿意挣脱。

Victory belongs to those who believe in it the most and believe in it the longest.
胜利属于那些意志坚强、持之以恒的人。

One can never consent to creep when one feels an impulse to soar.
当人有飞的渴望时,他绝不会满足于爬。

Any mind that is capable of a real sorrow is capable of good.
真正悲伤过的人都是心存善念的。

I feel I stand in a desert with my hands outstretched, and you are raining down upon me.
我感觉自己张开双手站在一片沙漠中,你如雨水般降临在我身上。

Art is the stored honey of the human soul, gathered on wings of misery and travail.
艺术乃贮存人类灵魂的蜂蜜,由痛苦和辛劳的翅膀采集。

Belief, like fear or love, is a force that determines the course of our lives.
信仰,就像恐惧和爱一样,是一种决定我们人生走向的力量。

It's great to be great, but it's greater to be human.
成为一个伟人很伟大,但是成为一个充满人性的人更伟大。

We're all in the gutter, but some of us are looking at the star.
身在井隅,心向璀璨。

History is apt to judge harshly those who sacrifice tomorrow for today.
历史往往对那些为了今天而牺牲明天的人作出严厉的判决。

When a man's stories are remembered, then he is immortal.
一个人的故事被记住了,他就千古不朽。

It's hard to stay mad when there's so much beauty in the world.
世界这么美,很难一直生气。

The art of being wise is knowing what to overlook.
智慧的艺术在于知道该忽略什么。

You can't sit around and wait for others to arrange your life; if you want something, fight for it yourself.
你不能等待别人来安排你的人生;自己想要的,自己争取。

Time goes on and on, never to an end but crossings.
时间一直走,没有尽头,只有路口。

The Earth is the cradle of humanity, but mankind cannot stay in the cradle forever.
地球是人类的摇篮,但人类不会永远呆在摇篮里。

The deepest principle in human nature is the craving to be appreciated.
人性中最深刻的本能就是对被欣赏的渴望。

You will see exactly what life is worth, when all the rest has gone.
当一切都消失的时候你会明白生命究竟有何价值。

The task of leadership is not to put greatness into humanity, but to elicit it.
领导者的任务不是赋予人类伟大,而是激发人类伟大。

Being too consumed in fear all the time will result in poor quality of life.
心中充斥太多的恐惧会让生活品质降低。

Sometimes it is better to lose and do the right thing than to win and do the wrong thing.
有时候做对的事而输,比做错的事而赢还要好。

The real opportunity for success lies within the person and not in the job.
成功的真正机会在于人而非工作。

Whenever people want you to do something they think it's wrong, they say it’s “reality”.
当人们想要你去做一些他们认为不对的事,他们就会说是“现实”。

Since you are like no other being ever created since the beginning of time, you are incomparable.
因为你和有史以来任何人类都不相同,所以你是无可比拟的。

In one second your whole life can change. It only takes a moment for everything to feel quite different.
生命真是瞬息万变,只要片刻,一切就截然不同了。

A decade or two will fly like that.
十年二十年一眨眼就过去了。

Problems are not stop signs, they are guidelines.
问题不是止步不前的标志,而是前进的指引。

Opportunity does not knock, it presents itself when you beat down the door.
机遇不会自己找上门来,它只会在你开门时出现。

The secret of getting ahead is getting started.
成功的秘诀是开始行动。

We all deserve a standing ovation at least once in our lives.
每个人都值得大家站起来为他鼓掌一次。

The old dreams were good dreams. They didn’t work out, but I’m glad I had them.
曾经的梦都是美梦,虽未成真,但庆幸我曾拥有过。

Simplicity is the shortest path to a solution.
简化是找到解决办法的最短途径。

The definition of the good society is one in which virtue pays.
有德的人不会吃亏,可谓之好的社会。

Standing for right when it is unpopular is a true test of moral character.
站在不受欢迎但却正确的一边,才是真正的道德考验。

You keep living in the past. You are gonna wind up alone.
你要是一直活在过去,就会孤独终老。

There are many things that seem impossible only so long as one does not attempt them.
很多事情看起来不可能只是因为没有人尝试过。

For small creatures such as we the vastness is bearable only through love.
如此渺小的我们,只有通过爱,才能承受宇宙的广漠。

It would be a privilege to have my heart broken by you.
能为你心碎是我最大的荣幸。

It’s when you start to become really afraid of death that you learn to appreciate life.
只有当你真正感受到对死亡的恐惧,你才会学到要珍惜生命。

We will all be judged by the courage of our hearts.
最终,衡量我们的是内心的勇气。

Travel can be one of the most rewarding forms of introspection.
旅行可能是最有益的自省方式之一。

All are past and gone! For truly great men Look to this age alone.
俱往矣,数风流人物,还看今朝。

Books are the bees which carry the quickening pollen from one to another mind.
书籍是蜜蜂,将花粉从一个头脑传到另一个头脑。

Any sufficiently advanced technology is indistinguishable from magic.
任何足够先进的技术都与魔法无异。

Sometimes life hits you in the head with a brick. Don't lose faith.
有时生活给你当头痛击,但是别丧失信念。

Love has no age, no limit, and no death.
爱不分年龄,没有限制,永不凋谢。

The truth is, each of us is related. It's just a question of how far back you traced your family tree.
事实上,我们每个人都是血缘关系的。看你在家谱里往回推算多远。

Education is a progressive discovery of our own ignorance.
教育是一个逐步发现自己无知的过程。

The biggest communication problem is we do not listen to understand. We listen to reply.
最大的沟通问题是,很多人聆听不是为了理解,只是为了回答。

Never let your persistence and passion turn into stubbornness and ignorance.
永远不要让你的坚持和激情变成固执和无知。

As a body everyone is single, as a soul never.
每个人的身体都是独立的,但灵魂从来不是。

It takes more than intelligence to act intelligently.
头脑聪明不代表就能明智地行事。

Sometimes it's about doing the right thing, even if it's painful inside.
有时候就是要做对的事,哪怕内心万分痛苦。

I am grateful for what I am and have. My Thanksgiving is perpetual.
我对自己的现状和所拥有的一切心存感激。对我来说每一天都是感恩节。

Focus on the details, they've always been in front of our eyes.
专注在细节上,答案就在你的眼皮底下。

Reading makes a full man, conference a ready man, and writing an exact man.
读书使人充实,讨论使人机智,笔记使人准确。

This is either madness or brilliance. It's remarkable how often those two traits coincide.
疯狂和伟大只有一线之隔,他们往往相伴而行。

He who has a why to live can bear almost any how.
一个人知道自己为什么而活,就可以忍受任何一种生活。

If opportunity doesn't knock, build a door.
如果机遇不找过来,就自己造一扇门吧。

Sarcasm is the lowest form of wit.
讽刺是最低级的智慧。

Courage is fear holding on a minute longer.
勇气,就是即使恐惧仍能继续坚持一分钟。

When you reach the end of your rope, tie a knot in it and hang on.
哪怕希望快要破灭,也要努力挣扎,坚持下去。

All things are difficult before they are easy.
所有事情在变简单前都是困难的。

There is nothing we can hold onto in this world. Only by letting go can we truly possess what is real.
把手握紧,里面什么都没有,但把手张开,就可以拥有一切。

The more one judges, the less one loves.
一个人评判的愈多,爱的就愈少。

Sometimes the right path is not the easiest one.
有时候,正确的道路并不是最轻松的。

The first step in solving any problem is recognizing there is one.
解决任何问题的第一步,是要承认问题的存在。

If Winter comes, can Spring be far behind?
如果冬天来了, 春天还会远吗?

A rolling stone gathers no moss.
滚石不生苔。

If you put off everything till you're sure of it, you'll never get anything done.
如果你把每件事都推迟到确定以后才做,那你什么都做不成。

Death smiles at us all. All a man can do is smiles back.
死神在向我们每个人微笑,我们所能做的只有回敬微笑。

Adopting the right attitude can convert a negative stress into a positive one.
正确的态度能将负面压力转换为正面压力。

Remember, you're the one who can fill the world with sunshine.
请记住,你是能让世界洒满阳光的人。

So much of what is best in us is bound up in our love of family.
我们心底所有美好的感情都凝结在我们对家人的爱里。

Now if you know what you're worth, go and get what you're worth.
如果你知道你的价值,你就前进实现你的价值。

True masters are those who have chosen to make a life rather than a living.
开创生活,而不是维持生命,这才是生命真正的主人。

We're here to put a dent in the universe. Otherwise why else even be here?
活着就是为了改变世界,难道还有其他原因吗?

Belief in the unreal can comfort the human mind, but it also weakens it.
对虚幻的信仰能抚慰人类的心,但也同样会令其软弱。

I only pray our life be long, and our souls together heavenward fly!
但愿人长久,千里共婵娟。

Real strength doesn't come from pushing other people down. It's from lifting them up.
真正的力量不是推倒别人,而是将摔倒的人扶起来。

Everything has a purpose, even machine.
万物皆有使命,即使机器也有。

My heart laments at the sight of the autumn moon above the mountain pass.
何处最伤心,关山见秋月。

Some of us may just have to find meaning in the little moments that make up life.
我们中有些人注定要在日常生活的点滴中寻找生命存在的意义。

Whatever tomorrow brings, I'm grateful to see it.
不管明天将带来什么,我都会感激。

To simply wake up every morning a better person than when I went to bed.
我只愿早上起来成为一个比入睡前更好的人。

And in the end, the greatest thief of all is time.
在变幻的生命里,岁月,原来是最大的小偷。

Everyone has his disadvantages, like the apple bitten by God.
每个人都会有缺陷,就像被上帝咬过的苹果。

If we don't end war, war will end us.
如果我们不结束战争,被终结的将是我们自己。

Opportunities are like sunrises. If you wait too long, you miss them.
机遇就像晨光,稍纵即逝。

We shall fight with growing confidence and growing strength in the air.
我们要以高涨的信心和喷涌的力量去战斗。

I have decided to stick with love. Hate is too great a burden to bear.
我决定去爱,恨是难以承受的负担。

Knowing trees, I understand the meaning of patience. Knowing grass, I can appreciate persistence.
因了解树,我懂得何谓耐心。因了解草,我才能欣赏坚持。

Keep a little fire burning; however small, however hidden.
让胸中之火燃烧,不管多微弱,不管藏得有多深。

Nothing in the world can take the place of persistence.
世界上没有什么可以取代坚持。

All over the place was six pence, but he looked up at the moon.
满地都是六便士,他却抬头看见了月亮。

Every passing minute is another chance to turn it all around.
过去的每一分钟都是改变现状的一次机会。

The hardships that I encountered in the past will help me succeed in the future.
我过去遇到的困难会在未来帮助我成功。

It's so easy to be careless, but it takes curse and courage to take cares.
想要不在乎太容易了,但要有无穷的勇气才能学会在乎。

Winners never quit and quitters never win.
退缩者永无胜利,胜利者永不退缩。

Maybe life has no meaning, and the best we can hope for is just being nice.
可能生活本来就没什么意义,我们能做到最好的就是友善对待身边的一切。

Sometimes l feel I’m fighting for a life I just ain’t got the time to live. I want it all to mean something.
我常常觉得我在为一个没时间享受的人生奋斗,我希望它能有价值。

Innocence dwells with wisdom, but never with ignorance.
纯真与智慧同在,但它决不和愚昧相关。

Work and acquire, and thou hast chained the wheel of chance.
边工作边探求,你便可拴住机会的车轮。

I don’t think that anybody can grow unless he really is accepted exactly as he is.
一个人除非真正接受自己,否则他没法成长。

Never idle a moment,but thrifty and thoughtful of others.
一刻也不要疏懒,要节俭和体谅他人。

In life, it's important to distinguish between need and want.
生活中要分清楚什么是自己想要的,什么是自己需要的。

Nothing that has meaning is easy. Easy doesn’t enter into grown-up life.
凡是有意义的事都不会容易,成年人的生活里没有容易二字。

Industry is the soul of business and the keystone of prosperity.
勤劳是事业的灵魂,繁荣的关键。

He who controls others may be powerful, but he who has mastered himself is mightier still.
胜人者有力,自胜者强。

Love all, trust a few, do wrong to none.
爱所有人,信任少许人,勿伤任何人。

I dreamed a dream in time gone by, when hope was high and life worth living.
曾几何时,我流连梦境,心比天高,人生充满希望。

The revelation of thought takes men out of servitude into freedom.
思想的解放使人们摆脱奴役获得自由。

My hope still is to leave the world a bit better than when I got here.
我的愿望仍是,这个世界在我离开之时比我来时要好一点。

Turn inward and examine yourself when you encounter difficulties in life.
行有不得,反求诸己。

You need to believe that something extraordinary is possible.
你要去相信,生命中有些特别的东西,是可能存在的。

Savages we call them because their manners differ from ours.
我们称呼他们为野蛮人,就因为他们的文明和我们的不同。

You don't know how fast time goes by until you get there.
你想不到时间过得有多快,等你明白过来已经晚了。

I often miss childhood, it is durable, good quality.
我经常怀念童年,它经久耐用,质量良好。

There should be a better way to start a day than waking up every morning.
应该有更好的方式开始新一天, 而不是千篇一律的在每个上午醒来。

He who does not punish evil commands it to be done.
不惩罪恶,无异于鼓动他人作恶。

Men are what their mothers made them.
人是母亲塑造而成的。

If you focus on results, you will never change. If you focus on change, you will get results.
把焦点放在结果,你将看不到改变;把焦点放在改变,你会得到结果。

Avoid using cigarettes, alcohol, and drugs as alternatives to being an interesting person.
拒绝烟、酒、毒,它们不能让你成为一个有趣的人。

Positive thinking will let you do everything better than negative thinking will.
比起悲观,乐观会让你把每一件事都做得更好。

Anyway the wind blows, doesn't really matter to me.
世事变迁,于我无异。

Be ashamed to die until you have won some victory for humanity.
还没有为人类赢得任何胜利便死去是可耻的。

I am not born for one corner, the whole world is my native land.
我不是生来就该待在一个角落里,全世界都是我的故乡。

Youth, even in its sorrows, always has a brilliancy of its own.
青春,即使在它的悲哀时也是辉煌的。

Of all the gin joints in all the towns in all the world, she walks into mine.
世界上有那么多的城镇,城镇中有那么多的酒馆,她却走进了我的。

Zeal without knowledge is fire without light.
没有知识的热忱犹如火之无光。

The soul selects her own society, then shuts the door, to her divine majority, present no more.
灵魂选择自己的伴侣,然后,把门紧闭,她神圣的决定,再不容干预。

The deepest love I think, later than apart, I will live as you like.
我所认为最深沉的爱,莫过于分开以后,我将自己活成了你的样子。

A man may fail many times, but he isn't a failure until he begins to blame somebody else.
一个人可能会失败很多次,然而在他开始怪罪于他人之前,他都不是失败者。

Then “real” is simply electrical signals interpreted by your brain.
所谓真实无非就是经你大脑处理过的电信号。

Love is the one thing that transcends time and space.
只有爱可以穿越时空。

You don't know about real loss...cause that only occurs when you love something more than you love yourself.
你不了解真正的失去,唯有爱别人胜于自己才能体会。

A man's feet should be planted in his country, but his eyes should survey the world.
一个人应该立足本土,放眼世界。

Beneath this mask there is more than flesh. Beneath this mask there is an idea. And ideas are bulletproof.
在这面具之下的不是血肉之躯,而是刀枪不入的理念。

For the ideal that I hold near to my heart, I'd not regret a thousand times to die.
亦余心之所善兮,虽九死其尤未悔。

Presence of mind and courage in distress are more than armies to procure success.
危难时保持理智和勇气,胜过千军万马去夺取胜利。

Sometimes a little discomfort in the beginning can save a whole lot of pain down the road.
有时起初的隐忍可以避免一路的疼痛。

Fashion is architecture: it is a matter of proportions.
时尚也是建筑学:有关比例的问题。

We can do anything we want to do if we stick to it long enough.
只要锲而不舍,我们便能做自己想做的任何事情。




SolitudeAlma
3个月前

项目介绍

Warlock是一个类MOBA的对抗游戏。玩家可以通过匹配系统与其他玩家对战,也有单机模式与机器人战斗。玩家通过释放一系列技能(如闪现、火球等)去攻击敌人。

项目仓库地址:https://github.com/solitudealma/warlock
项目在线地址:https://acapp.yt1209.com:4430

项目结构

├── api
│   └── v1
├── config
├── core
├── db
├── global
├── initialize
├── match_system
├── middleware
├── model
│   ├── request
│   └── response
├── protobuf
├── router
├── servers
├── service
├── static
│   ├── css
│   ├── images
│   └── js
├── templates
└── utils
    ├── timer
文件夹 说明 描述
api api层 api层
–v1 v1版本接口 v1版本接口
config 配置包 config.yaml对应的配置结构体
core 核心文件 核心组件(logrus, viper)的初始化
db mysql数据库文件 mysql数据库文件
global 全局对象 全局对象
initialize 初始化 router,redis
match_system 匹配系统的grpc服务端 匹配系统的grpc服务端
middleware 中间件层 用于存放 gin 中间件代码
model 模型层 模型对应数据表
–request 入参结构体 接收前端发送到后端的数据。
–response 出参结构体 返回给前端的数据结构体
protobuf grpc需要的文件 .proto后缀的文件、构建脚本以及构建后生成的文件
router 路由层 路由层
server
–page 表单生成器 表单生成器 打包后的dist
–template 模板 模板文件夹,存放的是代码生成器的模板
router 路由层 路由层
service service层 存放业务逻辑问题
source source层 存放初始化数据的函数
utils 工具包 工具函数封装
–timer timer 定时器接口封装
–upload oss oss接口封装

…未完待续