当前位置:网站首页>Go simple read database
Go simple read database
2022-06-13 00:50:00 【Small fish game development】
/* go-sqlite3 is cgo package. If you want to build your app using go-sqlite3, you need gcc. However, after you have built and installed go-sqlite3 with go install github.com/mattn/go-sqlite3 (which requires gcc), you can build your app without relying on gcc in future. Important: because this is a CGO enabled package, you are required to set the environment variable CGO_ENABLED=1 and have a gcc compile present within your path. */
package main
import (
"database/sql"
"fmt"
"io"
"log"
"net/http"
_ "github.com/mattn/go-sqlite3"
)
var databasePath = "./data.db3"
type SoInfo struct {
id int
build_id int
branch string
resversion string
currenttime string
}
func checkError(err error) {
if err != nil {
log.Fatal(err)
}
}
func handler(w http.ResponseWriter, r *http.Request) {
r.ParseForm()
if len(r.Form) > 0 {
job_name := r.Form.Get("job_name")
if len(job_name) != 0 {
db, err := sql.Open("sqlite3", databasePath)
checkError(err)
defer db.Close()
sql := fmt.Sprintf("select id,build_id,branch,resversion,currenttime from so_records where job_name='%s' order by cast(build_id as '999999') desc limit 20", job_name)
rows, err := db.Query(sql)
checkError(err)
defer rows.Close()
for rows.Next() {
var line SoInfo
rows.Scan(&line.id, &line.build_id, &line.branch, &line.resversion, &line.currenttime)
stringLine := fmt.Sprintf("BuildID: %d | BRANCH: %s | RESVERSION:%s | Time: %s | ID: %d\n", line.build_id, line.branch, line.resversion, line.currenttime, line.id)
io.WriteString(w, stringLine)
}
}
}
}
func main() {
http.HandleFunc("/findso", handler)
err := http.ListenAndServe(":8080", nil)
if err != nil {
log.Fatal("ListenAndServe: ", err)
}
}
边栏推荐
- 深度学习每周期的步数多少合适?
- Comparison of disk partition modes (MBR and GPT)
- Self use notes for problem brushing learning
- .net core 抛异常对性能影响的求证之路
- Buuctf babyupload[gxyctf2019]
- 今日睡眠质量记录74分
- Tree - delete all leaf nodes
- [sca-cnn interpretation] spatial and channel wise attention
- 硬(磁)盘(二)
- MySQL locates the position of the character in the string String substitution
猜你喜欢
Kalix system - use of information collection gadgets
[JS component] dazzle radio box and multi box
Buuctf babyupload[gxyctf2019]
antdPro - ProTable 实现两个选择框联动效果
gpu加速pytorch能用吗?
Physical orbit simulation
Kali system -- host, dig, dnsenum, imtry for DNS collection and analysis
Introduction to ROS from introduction to mastery (zero) tutorial
Kotlin 协程的作用域构建器 coroutineScope与runBlocking 与supervisorScope,协程同步运行,协程挂掉的时候其他协程如何不被挂掉。
Hard (magnetic) disk (II)
随机推荐
pytorch和tensorflow有什么区别?
Binary tree -- using hierarchical sequence and middle sequence to determine a tree
[buglist] serial port programming does not read data
蓝桥杯单片机第七届决赛
Hard (magnetic) disk (II)
Aof persistence
[sca-cnn interpretation] spatial and channel wise attention
[ciscn2019 North China Day2 web1]hack world --buuctf
Assembly language learning
[JS] battle chess
市值破万亿,连续三个月销量破10万,比亚迪会成为最强国产品牌?
硬(磁)盘(二)
Zhouchuankai, Bank of Tianjin: from 0 to 1, my experience in implementing distributed databases
Mysql批量插入数据时如何解决重复问题?
Leetcode weekly -- April to May
ROS从入门到精通(零) 教程导读
Arduino uses esp8266+ lighting technology + Xiaoai audio to realize voice control switch
People and gods are angry. Details of Tangshan "mass beating of women incident"
Deep learning model pruning
Four startup modes of kotlin collaboration