feat: 数据库超时时间设置

This commit is contained in:
meilin.huang
2023-11-30 15:02:48 +08:00
parent 070c8ac0da
commit b347bd7ef5
5 changed files with 10 additions and 8 deletions

View File

@@ -18,7 +18,7 @@ WORKDIR /mayfly
# Copy the go source for building server
COPY server .
RUN go mod download
RUN go mod tidy && go mod download
COPY --from=fe-builder /mayfly/dist /mayfly/static/static

View File

@@ -132,7 +132,7 @@ import { nextTick, onMounted, ref, toRefs, reactive, computed } from 'vue';
import { useRoute, useRouter } from 'vue-router';
import { ElMessage } from 'element-plus';
import { initRouter } from '@/router/index';
import { saveToken, saveUser, setSession } from '@/common/utils/storage';
import { saveToken, saveUser } from '@/common/utils/storage';
import { formatAxis } from '@/common/utils/format';
import openApi from '@/common/openApi';
import { RsaEncrypt } from '@/common/rsa';

View File

@@ -42,9 +42,9 @@ const viteConfig: UserConfig = {
chunkSizeWarningLimit: 1500,
rollupOptions: {
output: {
entryFileNames: `assets/[hash].[name].js`,
chunkFileNames: `assets/[hash].[name].js`,
assetFileNames: `assets/[name].[hash].[ext]`,
entryFileNames: `assets/[name]-[hash].js`,
chunkFileNames: `assets/[name]-[hash].js`,
assetFileNames: `assets/[name]-[hash].[ext]`,
compact: true,
manualChunks: {
vue: ['vue', 'vue-router', 'pinia'],

View File

@@ -8,6 +8,7 @@ import (
"mayfly-go/pkg/errorx"
"mayfly-go/pkg/utils/anyx"
"mayfly-go/pkg/utils/collx"
"mayfly-go/pkg/utils/netx"
"net"
"strings"
"time"
@@ -41,7 +42,7 @@ func getPgsqlDB(d *DbInfo) (*sql.DB, error) {
}
}
dsn := fmt.Sprintf("host=%s port=%d user=%s password=%s %s sslmode=disable", d.Host, d.Port, d.Username, d.Password, dbParam)
dsn := fmt.Sprintf("host=%s port=%d user=%s password=%s %s sslmode=disable connect_timeout=8", d.Host, d.Port, d.Username, d.Password, dbParam)
// 存在额外指定参数,则拼接该连接参数
if d.Params != "" {
// 存在指定的db则需要将dbInstance配置中的parmas排除掉dbname和search_path
@@ -79,7 +80,8 @@ func (pd *PqSqlDialer) Dial(network, address string) (net.Conn, error) {
return nil, err
}
if sshConn, err := sshTunnel.GetDialConn("tcp", address); err == nil {
return sshConn, nil
// 将ssh conn包装否则会返回错误: ssh: tcpChan: deadline not supported
return &netx.WrapSshConn{Conn: sshConn}, nil
} else {
return nil, err
}

View File

@@ -26,7 +26,7 @@ func (c *WrapSshConn) RemoteAddr() net.Addr {
return c.Conn.RemoteAddr()
}
func (c *WrapSshConn) SetDeadline(t time.Time) error {
return c.Conn.SetDeadline(t)
return nil
}
func (c *WrapSshConn) SetReadDeadline(t time.Time) error {
return nil