Github Oauth2 首先,在github上申请一个Oauth App, 获取client id / secret 需要这些信息,下边的代码是放在环境变量中 AUTH_URL = os.Getenv("AUTH_URL") // github authorization url TOKEN_URL = os.Getenv("TOKEN_URL") // github token url CLIENT_ID = os.Getenv("CLIENT_ID") // client id CLIENT_SECRET = os.Getenv("CLIENT_SECRET") // client secret REDIRECT_URL = os.Getenv("REDIRECT_URL") // the redirect url 在包的初始化代码中,初始化 var ( oauth2Config *oauth2.Config ) init() { oauth2Config = &oauth2.Config{ ClientID: CLIENT_ID, ClientSecret: CLIENT_SECRET, RedirectURL: REDIRECT_URL, // Discovery returns the OAuth2 endpoints. Endpoint: oauth2.Endpoint{ AuthURL: AUTH_URL, TokenURL: TOKEN_URL, AuthStyle: oauth2.AuthStyleInHeader, }, Scopes: []string{"openid", "email", "site_admin", "repo", "admin:org", "user"}, } Login……
Continue reading
channel to terminate 在 main.go中, 创建一个channel接收os.Signal sigChan := make(chan os.Signal, 1) // ctrl+c->SIGINT, kill -9 -> SIGKILL signal.Notify(sigChan, syscall.SIGINT, syscall.SIGKILL) 在main.go快结束的位置,加上 <-sigChan log.Info("exit") 如果用户有发送kill -9 或者ctrl+c, 会接收到这个信号。……
Continue reading
cron in golang 在golang中,有个包github.com/robfig/cron/v3可以实现linux中类似的cron功能,使用也比较简单。 官方文档中比较详细,这里只是简单记录一下。 c := cron.New() schlTime := "0 2 * * ?" // send reminder for org members c.AddFunc(schlTime, func() { log.Info("Send reminder for org member expiration job started") defer func() { log.Info("Send reminder for org member expiration job finished") }() log.Info("started to remind expired org members") err = task.RemindExpiredOrgMember(14) if err !=……
Continue reading
JWT in golang golang中的jwt包一般是使用 github.com/dgrijalva/jwt-go, 而且godoc中已经有些example,这里只是记录一下使用 jwt.StandardClaims的情况。 func parseToken(tokenString string) (*jwt.StandardClaims, error) { token, err := jwt.ParseWithClaims(tokenString, &jwt.StandardClaims{}, func(t *jwt.Token) (interface{}, error) { return jwtKey, nil }) if err != nil { log.Errorf("error: %v", err) return nil, fmt.Errorf("failed to parse the token string: %s", tokenString) } log.Printf("claims: %v", token.Claims) if claims, ok := token.Claims.(*jwt.StandardClaims); ok && token.Valid { return claims, nil } else { return nil, errors.Wrap(fmt.Errorf("failed to valiate the token"), "failed") } }……
Continue reading
Gap - TLS version 1.0/1.1 detected 如果在做security scan的时候,有这两个gap,需要修改两个地方 liberty profile server.xml add sslProtocol="TLSv1.2" to ssl <ssl id="defaultSSLConfig" sslProtocol="TLSv1.2" keyStoreRef="defaultKeyStore" securityLevel="CUSTOM" enabledCiphers="TLS_RSA_WITH_AES_128_CBC_SHA TLS_RSA_WITH_AES_128_CBC_SHA256 "/> server.env add JVM_ARGS=-Dhttps.protocols=TLSv1.2……
Continue reading
Prerequesite node javascript html css es6 code editor create-react-app npm install -g create-react-app create-react-app app-name React component state class component里面管理状态使用state class Counter extends Component { state = { counter: 10, title: "this is demo", products: [ { id: 1, name: "ok", }, { id: 2, name: "bad", }, ], }; // ..... other } render jsx expression attributes list/array conditional rendering handle events binding event handlers updating state event arguments passing data to component passing children debug react app props vs state raising and handle events multiple component in sync lifting state up functional component destructure arguments lifecycle hooks……
Continue reading
背景 有时候需要添加第三方的jar包到spring boot工程中,因为不能从maven repository直接下载,所以需要包含在代码库中。 一般需要在 src/main 目录下,可以建个新目录 lib, 然后把jar文件放到这个目录下,也就是 src/main/lib下. 然后在pom.xml中需要添加 group……
Continue reading
背景 有时候我们需要备份 schema或者包括数据,然后恢复到另外一个postgres db中。 备份 可以使用 pg_dump 来备份,或者加上 –schema-only 只备份schema. pg_dump --file "/root/repo/uat-copy.tar" --host "db host name" --port "23123" --username "admin" --password --verbose --format=t --blobs --schema-only "compose" 恢复 同样的,可以使用pg_restore来恢复 pg_restore --host "hostname here" --port "31090" --username "usernamehere" --password --dbname "ibmclouddb" --verbose "/root/repo/uat-copy.tar" 不管备份还是恢复,都会要求输入密……
Continue reading
配置方法,做个小记录 server 上要配置允许 用户电脑 在 .ssh/config 文件中 Host * AddKeysToAgent yes UseKeychain yes IdentityFile ~/.ssh/id_rsa Host xxx HostName xx.xx.xx.xx User jerry 把pub key传到server ssh-copy-id -i ~/.ssh/id_rsa.pub xx@xx.xx.xx.x 可以了……
Continue reading
File download 如果spring boot的写法是我在另外一个文章, 返回的response其实是一个Blob, 这一点要记住 this.axios.get(url, { responseType: 'blob', timeout: 0 }).then(response => { // response is Blob <------- const url = window.URL.createObjectURL(response) const a = document.createElement('a') a.style.display = 'none' a.href = url a.setAttribute('download','file.xlsx') document.body.appendChild(a) a.click() document.body.removeChild(a); window.URL.revokeObjectURL(url); });……
Continue reading
-
Previous
-
1
-
2
-
3
-
4
-
5
-
6
-
7
-
8
-
9
-
10
-
Next