Skip to content

Commit

Permalink
fix ci
Browse files Browse the repository at this point in the history
  • Loading branch information
beihai0xff committed Jun 18, 2024
1 parent d852628 commit cd2b825
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 5 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
- name: Download Go Module
run: make bootstrap
- name: golangci-lint
uses: actions/golangci-lint-action@v3
uses: golangci/golangci-lint-action@v6
with:
version: latest

Expand All @@ -47,9 +47,9 @@ jobs:
uses: actions/checkout@v4

- name: Set up QEMU
uses: actions/setup-qemu-action@v3
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: actions/setup-buildx-action@v3
uses: docker/setup-buildx-action@v3
- name: Run Unittest
run: make test

Expand All @@ -67,9 +67,9 @@ jobs:
# filter: tree:0
#
# - name: Set up QEMU
# uses: actions/setup-qemu-action@v3
# uses: docker/setup-qemu-action@v3
# - name: Set up Docker Buildx
# uses: actions/setup-buildx-action@v3
# uses: docker/setup-buildx-action@v3
#
# - name: Build Docker Image
# run: make build/docker BUILD_PLATFORMS=linux/amd64
55 changes: 55 additions & 0 deletions pkg/db/turl.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package db

import (
"time"

"gorm.io/gorm"
)

// TURL is the table of tiny-url
type TURL struct {
gorm.Model
LongURL string `gorm:"type:varchar;not null;unique" json:"long_url"`
}

// TinyURL is the interface of tiny-url table
type TinyURL interface {
Insert(shortID uint, longURL string) error
GetByShortID(shortID uint) (*TURL, error)
}

// tinyURL is the implementation of TinyURL
type tinyURL struct {
conn *gorm.DB
}

// NewTinyURL returns a new TinyURL
func NewTinyURL(dsn string) (TinyURL, error) {
conn, err := NewDB(dsn)
if err != nil {
return nil, err
}

return &tinyURL{conn: conn}, nil
}

func (db *tinyURL) Insert(shortID uint, longURL string) error {
t := TURL{
Model: gorm.Model{
ID: shortID,
CreatedAt: time.Now(),
},
LongURL: longURL,
}

return db.conn.Create(&t).Error
}

func (db *tinyURL) GetByShortID(shortID uint) (*TURL, error) {
var t TURL
if err := db.conn.First(&t, shortID).Error; err != nil {
return nil, err
}

return &t, nil
}

0 comments on commit cd2b825

Please sign in to comment.