libanemos

package module
v0.3.1-alpha Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 7, 2024 License: MIT Imports: 5 Imported by: 1

README

Hello Shiron / Solufit GO Template

ABOUT

このテンプレートはSolufit / Shiron間で共通のベースリポジトリを用いて作成されています。
各Orgで変更を加える場合はこのREADMEファイルの末尾に説明を加えるか、変更を加えた箇所の説明文章を取り消し線で消し追記してください。

Created by sasanqua and solufit developers

環境

  • 6000 Go API
    • Gin
    • xo
    • dbmate
  • 6080 Swagger API
  • Maria DB

ディレクトリ構成

tree 
|- .devcontainer
|- devcontainer.json                # devcontainerの設定
    |- docker-compose.yml           # 開発コンテナ関連のコンテナ立ち上げ
    |- Dockerfile                   # Go APIコンテナのビルド
|- .github
    |- dependabot.yml
    |- workflows
        |- actions.yml              # Lint / Generate / Build / Test
|- .vscode
    |- settings.json                # vscode 設定
|- batch
    |- main.go                      # バッチ処理用
|- db
    |- migrations
        |- xxxxxxxxxxxxxx_xxxxx.sql # マイグレートデータ
    |- seed
        |- 00000000000000_init.sql  # 初期データ
|- docs                             # swagger関連の自動生成ファイル
    |- docs.go
    |- swagger.json
    |- swagger.yaml
|- internal                         # メインのコード記述部分
    |- middleware
    |- pkg
    |- presenter
        |- server.go                # エンドポイント定義
    |- repository                   # db関連処理(CRUDはmodelsでやる)
    |- service                      # エンドポイントごとの処理
        |- version
            |- handler.go
|- models                           # xoが生成したDBのスキーマに基づくCRUDデータ
|- .gitignore
|- go.mod                           # Goのパッケージデータ
|- go.sun
|- main.go                          # サーバー起動エントリーポイント
|- README

API

エンドポイントの追加
  1. internal/service配下にフォルダーを追加する
  2. 作成したフォルダーは以下にhandler.goを作成する
  3. persenter/server.goにエンドポイントに関する記述を追記する
ドキュメントの作成
swag init ./main.go
2024/09/19 04:19:51 Generate swagger docs....
2024/09/19 04:19:51 Generate general API Info, search dir:./
2024/09/19 04:19:52 Generating version.Response
2024/09/19 04:19:52 create docs.go at docs/docs.go
2024/09/19 04:19:52 create swagger.json at docs/swagger.json
2024/09/19 04:19:52 create swagger.yaml at docs/swagger.yaml
テストの実行
go test -cover ./... -coverprofile=cover.out
go tool cover -html=cover.out -o cover.html
open cover.html

DB

テーブルの作成
sqlファイルの作成
dbmate new
sqlファイルの適用
dbmate --url mysql://root:root@db:3306/test -s db/schema.sql up 
初期データの投入
db/seedフォルダー配下に.sqlファイルを配置します

db/seed/sample.sql

-- migrate:up
INSERT INTO users (id, name, email, created_At, updated_at)
VALUES ('01F8MECHZX3TBDSZ7XY8E9ZHDH', '須藤史郎', 'sudo.shiron@solufit.net', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)

-- migrate:down
マイグレート状態の確認
dbmate --url mysql://root:root@db:3306/test status
^[[3~[X] 00000000000000_init.sql
[X] 20240919030921_init.sql

Applied: 2
Pending: 0
マイグレーションの適用
dbmate --url mysql://root:root@db:3306/test -d db/seed -s db/schema.sql up
スキーマファイルの作成
xo schema mysql://root:root@db:3306/test

ファイル構成

tree
anemos-public-api-library # Please put code user can import in root directory
├── anemos_public_api_library.go # package Root
├── go.mod
├── go.sum
├── internal
│   └── cache
│       ├── cache.go # Write Cache
│       ├── cache_test.go # Write Cache Test
│       ├── readCache.go # Read Cache
│       └── readCache_test.go # Read Cache Test
├── LICENSE
├── README.md
└── scripts
    └── coverage.sh

4 directories, 10 files

Documentation

Overview

Package libanemos provides structures and functions to work with Anemos data.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateCache

func CreateCache(client *redis.Client, anemosData []interface{}) error

Types

type AnemosGet

type AnemosGet struct {
	Data []anemosData[any]
}

AnemosGet is a structure that holds a slice of anemosData of any type.

func NewAnemosGet

func NewAnemosGet() *AnemosGet

NewAnemosGet initializes and returns a pointer to an AnemosGet instance with an empty slice of anemosData.

type Earthquake

type Earthquake struct {
	// contains filtered or unexported fields
}

type FilterOptions

type FilterOptions struct {
	PostCode  optional.Option[PostCode]
	StartTime optional.Option[time.Time]
	EndTime   optional.Option[time.Time]
}

FilterOptions is a structure that holds optional values for filtering anemosData.

type Forecast

type Forecast struct {
	// contains filtered or unexported fields
}

type PostCode

type PostCode string

PostCode is a type alias for a string representing a postal code.

type Warning

type Warning struct {
	// contains filtered or unexported fields
}

type WeatherEarthquake

type WeatherEarthquake struct {
	// contains filtered or unexported fields
}

type WeatherEarthquakelist

type WeatherEarthquakelist struct {
	// contains filtered or unexported fields
}

func (WeatherEarthquakelist) Filter

type WeatherForecast

type WeatherForecast struct {
	// contains filtered or unexported fields
}

type WeatherForecastlist

type WeatherForecastlist struct {
	// contains filtered or unexported fields
}

func (WeatherForecastlist) Filter

func (m WeatherForecastlist) Filter(filterOption FilterOptions) WeatherForecastlist

type WeatherWarning

type WeatherWarning struct {
	// contains filtered or unexported fields
}

type WeatherWarninglist

type WeatherWarninglist struct {
	// contains filtered or unexported fields
}

func (WeatherWarninglist) Filter

func (m WeatherWarninglist) Filter(filterOption FilterOptions) WeatherWarninglist

func (WeatherWarninglist) WeatherWarningFilter

func (m WeatherWarninglist) WeatherWarningFilter(filterOption FilterOptions) WeatherWarninglist

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL