Documentation ¶
Index ¶
- Constants
- Variables
- func BasicAuth(r *gin.Engine) *gin.RouterGroup
- func Convert(text string, isDeleteReturns bool) string
- func EarthquakeHandler(c gin.Context) error
- func FormatDepth(d *int) string
- func FormatLatLonDepth(lat float64, lon float64, depth *int) string
- func FormatMagnitude(m *jma.Magnitude) string
- func GetIfModifiedSince(url url.URL, d time.Time) (*http.Response, error)
- func Init(mode string)
- func InitConfig(mode string) error
- func InitPublishConfig() error
- func NewConnectMySQL(ctx context.Context) (*sql.DB, error)
- func ParseCoordinate(v string) (float64, float64, int, error)
- func ParseDate(d string) (time.Time, error)
- func ParseEventID(eventId string) ([]uint64, error)
- func ParsePosition(position float64) float64
- func Routes(r *gin.RouterGroup, h *Handler)
- func Server()
- func ServerMiddleWare(r *gin.Engine)
- func Template(fileName string, obj any) (string, error)
- func ValidModified(url url.URL, m string) (bool, error)
- type Config
- type Content
- type Earthquake
- func (c *Earthquake) Assembly(ctx context.Context, db *sql.DB) error
- func (c *Earthquake) GetEventId() ([]uint64, error)
- func (c *Earthquake) GetImages() []string
- func (c *Earthquake) GetInfoType() jma.InfoType
- func (c *Earthquake) GetTargetDate() (time.Time, error)
- func (c *Earthquake) GetText() (string, error)
- func (c *Earthquake) GetTitle() string
- func (c *Earthquake) GetType() EarthquakeType
- func (c *Earthquake) SetImages() error
- type EarthquakeActivity
- func (e *EarthquakeActivity) Assembly(ctx context.Context, db *sql.DB) error
- func (e *EarthquakeActivity) GetEventId() ([]uint64, error)
- func (e *EarthquakeActivity) GetImages() []string
- func (e *EarthquakeActivity) GetInfoType() jma.InfoType
- func (e *EarthquakeActivity) GetTargetDate() (time.Time, error)
- func (e *EarthquakeActivity) GetText() (string, error)
- func (e *EarthquakeActivity) GetTitle() string
- func (e *EarthquakeActivity) SetImages() error
- type EarthquakeCount
- func (e *EarthquakeCount) Assembly(ctx context.Context, db *sql.DB) error
- func (e *EarthquakeCount) GetEventId() ([]uint64, error)
- func (e *EarthquakeCount) GetImages() []string
- func (e *EarthquakeCount) GetInfoType() jma.InfoType
- func (e *EarthquakeCount) GetTargetDate() (time.Time, error)
- func (e *EarthquakeCount) GetText() (string, error)
- func (e *EarthquakeCount) GetTitle() string
- func (e *EarthquakeCount) SetImages() error
- func (e *EarthquakeCount) TempCountText() *EarthquakeCountDetail
- func (e *EarthquakeCount) TempFreeFormComment() string
- type EarthquakeCountDetail
- type EarthquakeType
- type EarthquakeUpdate
- func (e *EarthquakeUpdate) Assembly(ctx context.Context, db *sql.DB) error
- func (e *EarthquakeUpdate) GetEventId() ([]uint64, error)
- func (e *EarthquakeUpdate) GetImages() []string
- func (e *EarthquakeUpdate) GetInfoType() jma.InfoType
- func (e *EarthquakeUpdate) GetOldEarthquakes(ctx context.Context, db *sql.DB, eventId uint64) (*models.Earthquake, error)
- func (e *EarthquakeUpdate) GetOldEpicenter() string
- func (e *EarthquakeUpdate) GetOldMagnitude() string
- func (e *EarthquakeUpdate) GetTargetDate() (time.Time, error)
- func (e *EarthquakeUpdate) GetText() (string, error)
- func (e *EarthquakeUpdate) GetTitle() string
- func (e *EarthquakeUpdate) InsertUpdateDB(ctx context.Context, db *sql.DB, eventId uint64, targetDate time.Time) error
- func (e *EarthquakeUpdate) ParseEpicenter() error
- func (e *EarthquakeUpdate) SetImages() error
- type Epicenter
- type ErrorResponse
- type Handler
- type PublishConfig
- type PublishConfigClientCommon
- type Tsunami
Constants ¶
const EARTHQUAKE_ACTIVITY_TEMPLATE_FILE = "earthquake_activity.gtpl"
const EARTHQUAKE_COMMENTS_TEMPLATE_FILE = "earthquake_comments.gtpl"
const EARTHQUAKE_COUNT_CANCEL_TEMPLATE_FILE = "earthquake_count.gtpl"
const EARTHQUAKE_COUNT_TEMPLATE_FILE = "earthquake_count.gtpl"
const EARTHQUAKE_EPICENTER_TEMPLATE_FILE = "earthquake_epicenter.gtpl"
const EARTHQUAKE_INFO_TEMPLATE_FILE = "earthquake_info.gtpl"
const EARTHQUAKE_REPORT_TEMPLATE_FILE = "earthquake_report.gtpl"
const EARTHQUAKE_UPDATE_TEMPLATE_FILE = "earthquake_update.gtpl"
const FILE_PATH = "../templates"
Variables ¶
var COORDINATE_REGEXP = regexp.MustCompile(`([+-][0-9.]+)([+-][0-9.]+)([+-][0-9]+)?/`)
var LocalConfig = &Config{ Mode: "local", DatabaseConfig: &mysql.Config{ DBName: "earthquake-alert", User: "docker", Passwd: "docker", Addr: "localhost:3306", Net: "tcp", ParseTime: true, AllowNativePasswords: true, }, PublishConfigName: "publish_config.yaml", PublishConfigPath: ".", PublishConfig: nil, JmaXmlUrl: "", AuthenticationUser: "user", AuthenticationPw: "password", }
ローカルの設定 `go run .`をしたときはこの設定が使用されます。
var ProdConfig = &Config{ Mode: "prod", DatabaseConfig: &mysql.Config{ DBName: "earthquake-alert", User: "docker", Passwd: "docker", Addr: "localhost:3306", Net: "tcp", ParseTime: true, AllowNativePasswords: true, }, PublishConfigName: "publish_config.yaml", PublishConfigPath: ".", PublishConfig: nil, JmaXmlUrl: "", AuthenticationUser: "", AuthenticationPw: "", }
本番環境の設定 Docker内部で実行するときなどはこの設定が使用されます。
var TestConfig = &Config{ Mode: "test", DatabaseConfig: &mysql.Config{ DBName: "earthquake-alert-test", User: "docker", Passwd: "docker", Addr: "localhost:3306", Net: "tcp", ParseTime: true, AllowNativePasswords: true, }, PublishConfigName: "publish_config_test.yaml", PublishConfigPath: ".", PublishConfig: nil, JmaXmlUrl: "", AuthenticationUser: "", AuthenticationPw: "", }
テストの設定 `./scripts/test.sh`を使用してGoのテストを走らせたときにこの設定が使用されます。
Functions ¶
func Convert ¶
文字列をイイカンジに整形する
- 全ての改行を消す (isDeleteReturnsがtrueの場合) - 全角英数字を半角英数字に変換する - 全角スペースを半角スペースに変換する
func EarthquakeHandler ¶
func FormatLatLonDepth ¶
日本測地系の緯度経度をいい感じにする lat, lonは度分秒で表す
func GetIfModifiedSince ¶
[If-Modified-Since](https://developer.mozilla.org/ja/docs/Web/HTTP/Headers/If-Modified-Since)リクエストヘッダを付与した条件付きGETリクエストをします。 リソースが変更されていない場合、ステータスは304で返されます。
func ParseCoordinate ¶
震源要素を解析する。 例: "-17.2+178.6-570000/" --> (-17.2, 178.6, -570000, nil)
returns: (lat, lon, depth, error) depthは不明の場合は1、ごく浅い場合は0
func ParsePosition ¶
度分秒の緯度経度十進度に変換する = 度 + (分 / 60) + (秒 / 60) 引数は、00.00の形式で、[度].[分]となる。
func Routes ¶
func Routes(r *gin.RouterGroup, h *Handler)
func ValidModified ¶
HEADリクエストを送り、[Last-Modified](https://developer.mozilla.org/ja/docs/Web/HTTP/Headers/Last-Modified)を引数と比較する
Types ¶
type Config ¶
type Config struct { Mode string // MySQLの設定 DatabaseConfig *mysql.Config // 公開先の設定ファイル名 PublishConfigName string // 公開先のファイルパス PublishConfigPath string PublishConfig *PublishConfig // タイムゾーン TimeLocation *time.Location // 気象庁XML電文のURL JmaXmlUrl string // これを設定するとWebサーバーはBasic認証をします // Webサーバーを外部に公開する際には必ず設定してください AuthenticationUser string AuthenticationPw string }
var C *Config
設定項目です この変数はデフォルトでnilですが、init()で上書きしています。
type Content ¶
type Content interface { // DBに格納したり、DBから関連の地震・津波情報を取得してくるメソッド Assembly(ctx context.Context, db *sql.DB) error // 震度分布図など様々な画像を生成するためのメソッド // // 並列で生成したいので`Assembly`と分けている SetImages() error // タイトルを返す GetTitle() string // 対象の基点時刻を返す GetTargetDate() (time.Time, error) // 運用種別を返す GetInfoType() jma.InfoType // 本文を返す GetText() (string, error) // 画像を返す GetImages() []string // EventIDを返す GetEventId() ([]uint64, error) }
type Earthquake ¶
type Earthquake struct { Row string Parsed *jma.EarthquakeJmaXml Images []string }
震度速報、震源に関する情報、震源・震度に関する情報
func ParseEarthquake ¶
func ParseEarthquake(row []byte) (*Earthquake, error)
func (*Earthquake) GetEventId ¶
func (c *Earthquake) GetEventId() ([]uint64, error)
func (*Earthquake) GetImages ¶
func (c *Earthquake) GetImages() []string
func (*Earthquake) GetInfoType ¶
func (c *Earthquake) GetInfoType() jma.InfoType
func (*Earthquake) GetTargetDate ¶
func (c *Earthquake) GetTargetDate() (time.Time, error)
func (*Earthquake) GetText ¶
func (c *Earthquake) GetText() (string, error)
func (*Earthquake) GetTitle ¶
func (c *Earthquake) GetTitle() string
func (*Earthquake) GetType ¶
func (c *Earthquake) GetType() EarthquakeType
func (*Earthquake) SetImages ¶
func (c *Earthquake) SetImages() error
type EarthquakeActivity ¶
type EarthquakeActivity struct { Row string Parsed *jma.EarthquakeActivityJmaXml }
地震の活動状況等に関する情報
func ParseEarthquakeActivity ¶
func ParseEarthquakeActivity(row []byte) (*EarthquakeActivity, error)
func (*EarthquakeActivity) GetEventId ¶
func (e *EarthquakeActivity) GetEventId() ([]uint64, error)
func (*EarthquakeActivity) GetImages ¶
func (e *EarthquakeActivity) GetImages() []string
画像は生成しないので空
func (*EarthquakeActivity) GetInfoType ¶
func (e *EarthquakeActivity) GetInfoType() jma.InfoType
func (*EarthquakeActivity) GetTargetDate ¶
func (e *EarthquakeActivity) GetTargetDate() (time.Time, error)
func (*EarthquakeActivity) GetText ¶
func (e *EarthquakeActivity) GetText() (string, error)
func (*EarthquakeActivity) GetTitle ¶
func (e *EarthquakeActivity) GetTitle() string
タイトル 取り消し報の場合`【取消】`を付与する
func (*EarthquakeActivity) SetImages ¶
func (e *EarthquakeActivity) SetImages() error
画像は生成しないのでなにもしない
type EarthquakeCount ¶
type EarthquakeCount struct { Row string Parsed *jma.EarthquakeCountInfoJmaXml }
地震回数に関する情報
func ParseEarthquakeCount ¶
func ParseEarthquakeCount(row []byte) (*EarthquakeCount, error)
func (*EarthquakeCount) GetEventId ¶
func (e *EarthquakeCount) GetEventId() ([]uint64, error)
func (*EarthquakeCount) GetInfoType ¶
func (e *EarthquakeCount) GetInfoType() jma.InfoType
func (*EarthquakeCount) GetTargetDate ¶
func (e *EarthquakeCount) GetTargetDate() (time.Time, error)
func (*EarthquakeCount) GetText ¶
func (e *EarthquakeCount) GetText() (string, error)
func (*EarthquakeCount) GetTitle ¶
func (e *EarthquakeCount) GetTitle() string
func (*EarthquakeCount) TempCountText ¶
func (e *EarthquakeCount) TempCountText() *EarthquakeCountDetail
テンプレートで使うやつ
func (*EarthquakeCount) TempFreeFormComment ¶
func (e *EarthquakeCount) TempFreeFormComment() string
type EarthquakeCountDetail ¶
type EarthquakeType ¶
type EarthquakeType int
const ( EarthquakeReport EarthquakeType = 0 EarthquakeEpicenter EarthquakeType = 1 EarthquakeInfo EarthquakeType = 2 EarthquakeCancel EarthquakeType = 3 )
type EarthquakeUpdate ¶
type EarthquakeUpdate struct { Row string Parsed *jma.EarthquakeUpdateInfoJmaXml Images []string // 通常のHypocenterの型と違うため独自で定義する // 取消報の場合は空になる NewName string NewLat *float64 NewLon *float64 NewDepth *int NewLatLonStr string NewMagnitude string // 更新前の地震情報 LatestEarthquake *models.Earthquake }
顕著な地震の震源要素更新のお知らせ
func ParseEarthquakeUpdate ¶
func ParseEarthquakeUpdate(row []byte) (*EarthquakeUpdate, error)
func (*EarthquakeUpdate) GetEventId ¶
func (e *EarthquakeUpdate) GetEventId() ([]uint64, error)
func (*EarthquakeUpdate) GetImages ¶
func (e *EarthquakeUpdate) GetImages() []string
func (*EarthquakeUpdate) GetInfoType ¶
func (e *EarthquakeUpdate) GetInfoType() jma.InfoType
func (*EarthquakeUpdate) GetOldEarthquakes ¶
func (e *EarthquakeUpdate) GetOldEarthquakes(ctx context.Context, db *sql.DB, eventId uint64) (*models.Earthquake, error)
更新前の地震情報を取得する
func (*EarthquakeUpdate) GetOldEpicenter ¶
func (e *EarthquakeUpdate) GetOldEpicenter() string
前回の震源情報を返す
func (*EarthquakeUpdate) GetOldMagnitude ¶
func (e *EarthquakeUpdate) GetOldMagnitude() string
前回のマグニチュードを返す DBに格納されているマグニチュード表記はフォーマットしたものであるため存在している場合はそのまま返す
func (*EarthquakeUpdate) GetTargetDate ¶
func (e *EarthquakeUpdate) GetTargetDate() (time.Time, error)
func (*EarthquakeUpdate) GetText ¶
func (e *EarthquakeUpdate) GetText() (string, error)
func (*EarthquakeUpdate) GetTitle ¶
func (e *EarthquakeUpdate) GetTitle() string
func (*EarthquakeUpdate) InsertUpdateDB ¶
func (e *EarthquakeUpdate) InsertUpdateDB(ctx context.Context, db *sql.DB, eventId uint64, targetDate time.Time) error
EarthquakeUpdates テーブルにinsertする
func (*EarthquakeUpdate) ParseEpicenter ¶
func (e *EarthquakeUpdate) ParseEpicenter() error
Coordinateを取得してパースする
func (*EarthquakeUpdate) SetImages ¶
func (e *EarthquakeUpdate) SetImages() error
type Epicenter ¶
type Epicenter struct { // 緯度経度 // 震源要素が不明な場合はnilになる Lat *float64 Lon *float64 // 日本測地系かどうか IsDatumJapan bool // 深さ // 震源要素が不明だったり、深さ不明だった場合はnilになる Depth *int Name string // 遠地地震の場合、ここに震源決定機関が入る Source string H *jma.Hypocenter }
func ParseEpicenter ¶
func ParseEpicenter(h *jma.Hypocenter) (*Epicenter, error)
type ErrorResponse ¶
type PublishConfig ¶
type PublishConfig struct { Twitter []struct { // TODO: Twitter API v2のトークンどうなんだろう…? Token string `yaml:"token"` PublishConfigClientCommon `yaml:",inline"` } `yaml:"twitter,omitempty"` Discord []struct { // DiscordWebhook URL WebhookURL string `yaml:"webhook_url"` PublishConfigClientCommon `yaml:",inline"` } `yaml:"discord,omitempty"` Slack []struct { // SlackWebhook URL WebhookURL string `yaml:"webhook_url"` // 送信するSlackチャンネル Channel string `yaml:"channel"` PublishConfigClientCommon `yaml:",inline"` } `yaml:"slack,omitempty"` LineNotify []struct { // LINE Notify トークン Token string `yaml:"token"` PublishConfigClientCommon `yaml:",inline"` } `yaml:"line_notify,omitempty"` }
公開先の設定など
type PublishConfigClientCommon ¶
type PublishConfigClientCommon struct { ClientName string `yaml:"name"` // 送信する最低震度 // 指定しない場合、全ての地震を送信する MinInt jma.EarthquakeIntensity `yaml:"min_int,omitempty"` // 送信する対象都道府県 // これを指定すると、この地域で震度1以上の地震を観測したときのみ送信します。 // 指定しないと、全ての都道府県の情報を送信します。 Areas []string `yaml:"areas,omitempty"` // 津波情報を送信するか // デフォルトfalse IsTsunami bool `yaml:"is_tsunami,omitempty"` }
公開先の共通設定項目