上药三品,神与气精

曾因酒醉鞭名马 生怕情多累美人


  • 首页

  • 关于

  • 分类

  • 标签

  • 归档

  • 搜索

2019-go-23

发表于 2019-03-14 | 分类于 beego | 阅读次数:
字数统计: 195 | 阅读时长 ≈ 1

beego 模块化设计之logs

用来处理日志的库,它的设计思路来自于 database/sql,目前支持的引擎有 file、console、net、smtp,

使用

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
logs.SetLogger(logs.AdapterFile,`{"filename":"project.log","level":7,"maxlines":0,"maxsize":0,"daily":true,"maxdays":10,"color":true}`)

package main

import (
"github.com/astaxie/beego/logs"
)

func main() {
//an official log.Logger
l := logs.GetLogger()
l.Println("this is a message of http")
//an official log.Logger with prefix ORM
logs.GetLogger("ORM").Println("this is a message of orm")

logs.Debug("my book is bought in the year of ", 2016)
logs.Info("this %s cat is %v years old", "yellow", 3)
logs.Warn("json is a type of kv like", map[string]int{"key": 2016})
logs.Error(1024, "is a very", "good game")
logs.Critical("oh,crash")
}

2019-go-22

发表于 2019-03-14 | 分类于 golang | 阅读次数:
字数统计: 125 | 阅读时长 ≈ 1

beego 模块化设计之cache

beego 的 cache 模块是用来做数据缓存的,设计思路来自于 database/sql,目前支持 file、memcache、memory 和 redis 四种引擎,安装方式如下:

go get github.com/astaxie/beego/cache
go get -u github.com/astaxie/beego/cache/memcache
import _ "github.com/astaxie/beego/cache/memcache"

使用先初始化 然后 增删改缓存即可

bm, err := cache.NewCache("memory", `{"interval":60}`)

bm.Put("astaxie", 1, 10*time.Second)
bm.Get("astaxie")
bm.IsExist("astaxie")
bm.Delete("astaxie")

2019-go-21

发表于 2019-03-14 | 分类于 golang | 阅读次数:
字数统计: 258 | 阅读时长 ≈ 1

panic 被引用到程序终止运行的大致过程是什么

某个函数中的某行代码有意或无意地引发了一个panic

这时 panic详情会被建立起来

程序的控制权立即从此行代码转移至调用其所属函数的那一行代码上 也就是调用栈的上一级

此行所属函数的执行随即终止 控制权不会有片刻的停留立即转移至再上一级

控制权一级一级沿着调用栈的反方向传播至顶端 也就是编写的最外层函数那里

对于goroutine 来说 就是main函数 但是控制权也不会停留 而是被go语言运行时系统收回

程序崩溃并终止运行 承载程序这次运行的进程也会随之死亡并消失 在控制权传播的过程中 panic详情会被逐渐地积累和完善 并会在程序终止之前被打印出来

leetcode-0002

发表于 2019-03-13 | 阅读次数:
字数统计: 88 | 阅读时长 ≈ 1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28

# Definition for singly-linked list.
class ListNode(object):
def __init__(self, x):
self.val = x
self.next = None

class Solution(object):
def addTwoNumbers(self, l1, l2):
"""
:type l1: ListNode
:type l2: ListNode
:rtype: ListNode
"""
carry = 0
root = n = ListNode(0)
while l1 or l2 or carry:
v1 = v2 = 0
if l1:
v1 = l1.val
l1 = l1.next
if l2:
v2 = l2.val
l2 = l2.next
carry, val = divmod(v1+v2+carry, 10)
n.next = ListNode(val)
n = n.next
return root.next

leetcode-0001

发表于 2019-03-13 | 阅读次数:
字数统计: 34 | 阅读时长 ≈ 1
1
2
3
4
5
6
7
8
9

class Solution:
# @return a tuple, (index1, index2)
def twoSum(self, num, target):
d = {}
for i, n in enumerate(num):
if target-n in d:
return (d[target-n], i)
d[n] = i
1…303132…109
John Cheung

John Cheung

improve your python skills

543 日志
33 分类
45 标签
RSS
GitHub Email
© 2020 John Cheung
本站访客数:
|
主题 — NexT.Pisces v5.1.4
博客全站共226.3k字