PostgreSQL 의존성 및 내부 유틸리티 추가:
Some checks failed
Build Push and Restart Compose / deploy (push) Failing after 1m47s

- `github.com/lib/pq` PostgreSQL 드라이버 vendor 디렉토리에 추가.
- PostgreSQL 관련 내부 패키지(`pqsql`, `proto`, `pqtime`, `pgpass`, `pgservice`, `pqutil`) 구현:
  - SQL 어휘 처리, 프로토콜 상수 및 구조 정의, 시간 파서/포맷터(`Parse`, `Format`).
  - `.pgpass` 파일 및 `pg_service.conf` 관리 기능 추가.
  - 파일/사용자 권한 검증 및 플랫폼별 사용자 정보 조회 기능 포함.
- 데이터베이스 초기화 로직 추가 (`services/db.go`):
  - PostgreSQL 연결 설정 및 초기 스키마 생성.
- 자동매매 관련 DB 레포지토리(`services/autotrade_repo.go`) 구현:
  - 자동매매 규칙 및 포지션 관리 로직 추가 (`dbInsertRule`, `dbLoadRules` 등).
This commit is contained in:
hayato5246
2026-04-08 19:07:32 +09:00
parent 5aeb5f2b80
commit ba18887ed8
48 changed files with 10459 additions and 0 deletions

View File

@@ -0,0 +1,70 @@
package pgservice
import (
"bufio"
"fmt"
"os"
"strings"
"github.com/lib/pq/internal/pqutil"
)
func FindService(path string, service string) (map[string]string, error) {
fp, err := os.Open(path)
if err != nil {
if pqutil.ErrNotExists(err) {
// libpq just returns "definition of service not found" if the
// default file doesn't exist, but IMO that's confusing.
return nil, fmt.Errorf("service file %q not found", path)
}
return nil, err
}
defer fp.Close()
var (
scan = bufio.NewScanner(fp)
i int
)
for scan.Scan() {
i++
line := strings.TrimSpace(scan.Text())
if line == "" || line[0] == '#' {
continue
}
// [service] header that we want.
if line[0] == '[' && line[len(line)-1] == ']' && strings.TrimSpace(line[1:len(line)-1]) == service {
opts := make(map[string]string)
for scan.Scan() {
i++
line := strings.TrimSpace(scan.Text())
if line == "" || line[0] == '#' {
continue
}
// Next header: our work here is done.
if line[0] == '[' && line[len(line)-1] == ']' {
return opts, nil
}
k, v, ok := strings.Cut(line, "=")
if !ok {
return nil, fmt.Errorf("line %d: missing '=' in %q", i, line)
}
k, v = strings.TrimSpace(k), strings.TrimSpace(v)
if k == "" {
return nil, fmt.Errorf("line %d: no value before '=' in %q", i, line)
}
opts[k] = v
}
if scan.Err() != nil {
return nil, scan.Err()
}
return opts, nil
}
}
if scan.Err() != nil {
return nil, scan.Err()
}
return nil, fmt.Errorf("definition of service %q not found", service)
}