DevilKing's blog

冷灯看剑,剑上几分功名?炉香无需计苍生,纵一穿烟逝,万丈云埋,孤阳还照古陵

0%

悲苦心刻藏骨髓,韶华去四季暗中追随

梦如人生试问谁能料

本周完成:

  • arpu和roi部分的计算

  • 关于数据的一些检查部分

  • bidder log部分的一些解析

未完成:

  • 相关文档的沉淀

  • 渠道监控部分的完结

下周计划:

  • 渠道监控部分整体的完结

  • bidder log的扩展

  • 相关的一些数据bug的追查

本周所得:

  • golang的cli部分的使用,但跟beego的使用有冲突?

  • 关于hbase的一些时间戳的新的做法

  • 关于spark编写代码的一些重构

工作和生活部分的平衡,需要把控下,技术文章方面不要拉下

数据部分,找些业界的方式,尝试对相关架构进行改进。。

电影方面还行,不过书部分,还需要加强。。。

restful api 设计的相关原则

设计的相关5个动作

  • GET

  • PUT

  • DELETE

  • POST

  • PATCH

Custom Methods

Design Custom Methods

custom methods的http设计:

1
2
https://service.name/v1/some/resource/name:customVerb

采用:代替/的理由在于,可以支持任意的路径

关于custom methods部分,遵循下面几个原则

  • 应尽量使用POST方法,因为其支持灵活的语义

  • 即使要使用其他动作的话,也需尽量符合其对应的语义学

  • GET方法,需要保持独立以及幂等

  • 关于body的一些建议

代码部分的示例:

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
29
30
31
32
// This is a service level custom method.
rpc Watch(WatchRequest) returns (WatchResponse) {
// Custom method maps to HTTP POST. All request parameters go into body.
option (google.api.http) = {
post: "/v1:watch"
body: "*"
};
}

// This is a collection level custom method.
rpc ClearEvents(ClearEventsRequest) returns (ClearEventsResponse) {
option (google.api.http) = {
post: "/v3/events:clear"
body: "*"
};
}

// This is a resource level custom method.
rpc CancelEvent(CancelEventRequest) returns (CancelEventResponse) {
option (google.api.http) = {
post: "/v3/{name=events/*}:cancel"
body: "*"
};
}

// This is a batch get custom method.
rpc BatchGetEvents(BatchGetEventsRequest) returns (BatchGetEventsResponse) {
// The batch get method maps to HTTP GET verb.
option (google.api.http) = {
get: "/v3/events:batchGet"
};
}

GraphQL是facebook提出,准备替代Restful API?

这里列举一些golang的一些小技巧

Behavior Of Missing The OK Optional Return Value

Basic Rule:

Whether or not the ok return value is present will not affect program behavior.

Exception:

Missing the ok optional return value will make current goroutine panic if a type assertion fails.

1
2
3
4
5
6

var v interface{} = "abc"
_, ok = v.(int) // will not panic
_ = v.(int) // will panic!


这里提供了一种思路,在interface的转化部分

1
2
3
4
5

var m = map[int]int{}
_, ok = m[123] // will not panic
_ = m[123] // will not panic

关于第二句?

Types Of Values

Basic Rule:

Values should have either a type or a default type.

Exception:

Untyped nil has neither a type nor a default type.

1
2
3
4
5

var v interface{}
fmt.Printf("type of %v is %T \n", v, v) // type of <nil> is <nil>
var _ interface{} = v.(interface{}) // will panic

注意inteface的default value是nil

The Blank Composite Literals

If a type T support composite literal values, then T{} is its zero value.

For a map or a slice type T, T{} isn’t its zero value. Its zero value is represented with nil.

Comparison

Most types in Go support comparison.

Map, slice and function types don’t support comparison. but, Map, slice and function values can be compared to the nil identifier.

Modify Unaddressable Values

Unaddressable values can’t be modified.

Although map element values are unaddressable, but their value can be modified if their types are numeric or string types.

主要是针对map部分?

1
2
3
4
5
6
7

var mt = map[string]T{"abc": {123}}
_ = mt
// mt["abc"].x *= 2 // error: mt["abc"].x is not changeable
mt["abc"] = T{mt["abc"].x * 2} // map elements are unaddressable
// but replaceable

随着带来的问题

Map elements are not addressable, even if they can be overwritten.

map的value可以改写,但是无法给出地址

how to design large scale system

Summaries of various system design topics, including pros and cons. Everything is a trade-off.

Each section contains links to more in-depth resources.

可用性与一致性

CAP理论

  • CP

一致性模型:

  • 弱一致性

  • 最终一致性

  • 强一致性