Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

github.com/WuLianN/go-blog-service

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/WuLianN/go-blog-service

  • v0.0.0-20210520070649-0df225e6452e
  • Source
  • Go
  • Socket score

Version published
Created
Source

开始使用

  • 安装依赖,go install
  • 执行程序,go run main.go

链路追踪

需要安装 Jaeger

https://www.jaegertracing.io/


windows 使用 Jaeger

  1. 解压下载的 Jaeger 压缩包
  2. cd 到解压的目录,执行 jaeger-all-in-one.exe

将本地图片写入到数据库

package main

import (
	"database/sql"
	"io/ioutil"
	"strings"
	"time"

	_ "github.com/go-sql-driver/mysql"
)

var db *sql.DB

func main() {
	var err error
	// db, err := sql.Open("mysql", "root:123456@tcp(127.0.0.1:3306)/blog")
	db, err = sql.Open("mysql", "root:123456@/blog")

	err = db.Ping()
	if err != nil {
		panic(err.Error())
	}

	db.SetConnMaxLifetime(time.Minute * 3)
	db.SetMaxOpenConns(10)
	db.SetMaxIdleConns(10)

	defer db.Close()

	const dirname = `C:\Users\smile 8\Desktop\beauty`

	files, _ := ioutil.ReadDir(dirname)

	sqlStr := "INSERT INTO blog_picture (name, file_name, state, is_del) VALUES "
	vals := []interface{}{}

	for _, file := range files {
		if !file.IsDir() {
			// 文件名 abc.jpg
			fileName := file.Name()

			// 去除后缀 abc
			name := strings.Split(fileName, ".")[0]

			sqlStr += "(?, ?, ?, ?),"

			vals = append(vals, name, fileName, 1, 0)
		}
	}

	// trim the last ,
	sqlStr = sqlStr[0 : len(sqlStr)-1]

	// prepare the statement
	stmt, _ := db.Prepare(sqlStr)

	// format all vals at once
	stmt.Exec(vals...)
}

FAQs

Package last updated on 20 May 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc