当前位置:网站首页>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)
}
}
边栏推荐
- 生物解锁--指纹录入流程
- Assembly language learning
- 硬(磁)盘(一)
- Mysql database password modification
- People and gods are angry. Details of Tangshan "mass beating of women incident"
- [sca-cnn interpretation] spatial and channel wise attention
- Kali system -- fierce of DNS collection and analysis
- 杂记:intel11代和12代移动版支持原生Thunderbolt4接口,桌面版不支持
- Three threads print digital demo alternately
- 人神共愤,唐山“群殴女性事件”细节...
猜你喜欢

Static analysis of malicious code

What is dummy change?

Can GPU acceleration pytorch work?

Arduino controls tb6600 driver +42 stepper motor

MySQL lpad() and rpad() concatenate string functions with specified length

AOF持久化
![[JS component] browse progress bar](/img/cb/913f446db2cacdb965a3bf619aa478.jpg)
[JS component] browse progress bar

Triangle wave and triangle wave convolution

Et5.0 value type generation

kotlin 协程withContext切换线程
随机推荐
(01). Net Maui actual construction project
Aof persistence
.net core 抛异常对性能影响的求证之路
单片机串口中断以及消息收发处理——对接受信息进行判断实现控制
ImportError: cannot import name 'get_ora_doc' from partially initialized module
Four startup modes of kotlin collaboration
Opencv face recognition of ros2 foxy~galactic~humble
Triangle wave and triangle wave convolution
磁盘分区方式对比(MBR与GPT)
MCU serial port interrupt and message receiving and sending processing -- judge and control the received information
How to solve the duplication problem when MySQL inserts data in batches?
Composite key relationships using Sqlalchemy - relationships on composite keys using Sqlalchemy
Today's sleep quality record 74 points
Andersen Global通过在芬兰和丹麦的合作协议拓展北欧地区业务版图
[error] invalid use of incomplete type uses an undefined type
Canvas airplane game
Kotlin coroutine withcontext switch thread
Win10 home vs pro vs enterprise vs enterprise LTSC
Buuctf babyupload[gxyctf2019]
从ADK的WinPE自己手动构建自己的PE