simplenotification

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

README

sacloud/simple-notification-api-go

Go Reference Tests Go Report Card

さくらのクラウド シンプル通知 Go言語向け APIライブラリ

マニュアル: https://manual.sakura.ad.jp/cloud/appliance/simplenotification/

概要

sacloud/simple-notification-api-goはさくらのクラウド シンプル通知 APIをGo言語から利用するためのAPIライブラリです。

利用イメージ

通知先&通知グループ登録
import (
	"context"
	"os"

	"github.com/sacloud/saclient-go"
	simplenotification "github.com/sacloud/simple-notification-api-go"
	v1 "github.com/sacloud/simple-notification-api-go/apis/v1"
)

func main() {
	// デフォルトでusacloud互換プロファイル or 環境変数(SAKURA_ACCESS_TOKEN{_SECRET})が利用される
	var theClient saclient.Client
	ctx := context.Background()

	simplenotificationClient, err := simplenotification.NewClient(&theClient)
	if err != nil {
		panic(err)
	}

	//使用する通知先のメールアドレスは環境変数から取得
	mailAddress := os.Getenv("SAKURA_SIMPLE_NOTIFICATION_MAILADDRESS")

	// 通知先を作成
	destAPI := simplenotification.NewDestinationOp(simplenotificationClient)
	destReq := v1.PostCommonServiceItemRequest{
		CommonServiceItem: v1.PostCommonServiceItemRequestCommonServiceItem{
			Name:        "my-destination",
			Description: "my destination description",
			Tags:        []string{"tag1", "tag2"},
			Settings: v1.CommonServiceItemSettings{
				Type: v1.DestinationSettingsCommonServiceItemSettings,
				DestinationSettings: v1.DestinationSettings{
					Type:  v1.DestinationSettingsTypeEmail,
					Value: mailAddress,
				},
			},
			Icon: v1.NilCommonServiceItemIcon{
				Null: false,
				Value: v1.CommonServiceItemIcon{
					ID: "112901627732", //Debian icon ID
				},
			},
		},
	}
	destResp, err := destAPI.Create(ctx, destReq)
	if err != nil {
		panic(err)
	}
	println("Created Destination ID:", destResp.CommonServiceItem.ID)

	//通知グループを作成
	groupAPI := simplenotification.NewGroupOp(simplenotificationClient)
	groupReq := v1.PostCommonServiceItemRequest{
		CommonServiceItem: v1.PostCommonServiceItemRequestCommonServiceItem{
			Name:        "my-group",
			Description: "my group description",
			Tags:        []string{"tag1", "tag2"},
			Settings: v1.CommonServiceItemSettings{
				Type: v1.GroupSettingsCommonServiceItemSettings,
				GroupSettings: v1.GroupSettings{
					Destinations: []string{destResp.CommonServiceItem.ID}, //先ほど作成した通知先をグループに追加
				},
			},
		},
	}
	groupResp, err := groupAPI.Create(ctx, groupReq)
	if err != nil {
		panic(err)
	}
	println("Created Group ID:", groupResp.CommonServiceItem.ID)
}
通知メッセージの送信(通知先がメールの場合は事前に本登録手続きが必要)
import (
	"context"
	"fmt"
	"os"

	"github.com/sacloud/saclient-go"
	simplenotification "github.com/sacloud/simple-notification-api-go"
	v1 "github.com/sacloud/simple-notification-api-go/apis/v1"
)

func main() {
	// デフォルトでusacloud互換プロファイル or 環境変数(SAKURA_ACCESS_TOKEN{_SECRET})が利用される
	var theClient saclient.Client
	ctx := context.Background()

	simplenotificationClient, err := simplenotification.NewClient(&theClient)
	if err != nil {
		panic(err)
	}
	groupAPI := simplenotification.NewGroupOp(simplenotificationClient)

	//使用する送信先のグループIDは環境変数から取得
	groupID := os.Getenv("SAKURA_SIMPLE_NOTIFICATION_GROUPID")

	// 通知メッセージを送信
	// なお、通知先がメールの場合は、事前にメールされる本登録手続きが必要
	messageReq := v1.SendNotificationMessageRequest{
		Message: "Hello, Simple Notification API!", //送信するメッセージ
	}
	resp, err := groupAPI.SendMessage(ctx, groupID, messageReq)
	if err != nil {
		panic(err)
	}
	fmt.Println("Message sent successfully", resp)
}

⚠️ v1.0に達するまでは互換性のない形で変更される可能性がありますのでご注意ください。

License

simple-notification-api-go Copyright (C) 2026- The sacloud/simple-notification-api-go authors. This project is published under Apache 2.0 License.

Documentation

Overview

Copyright 2026- The sacloud/simple-notification-api-go Authors

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

View Source
const Version = "0.3.0"

Variables

This section is empty.

Functions

func NewClient

func NewClient(client *saclient.Client) (*v1.Client, error)

NewClient creates a new simple-notification API client with default settings

func NewClientWithAPIRootURL

func NewClientWithAPIRootURL(client *saclient.Client, apiRootURL string) (*v1.Client, error)

NewClientWithAPIRootURL creates a new simple-notification API client with a custom API root URL

Types

type DestinationOp

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

func (*DestinationOp) Create

func (*DestinationOp) Delete

func (o *DestinationOp) Delete(ctx context.Context, id string) error

func (*DestinationOp) List

func (*DestinationOp) Read

func (*DestinationOp) ReadStatus

func (*DestinationOp) Update

type Error

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

func NewAPIError

func NewAPIError(method string, code int, err error) *Error

func NewError

func NewError(msg string, err error) *Error

func (*Error) Error

func (e *Error) Error() string

func (*Error) Unwrap

func (e *Error) Unwrap() error

type GroupOp

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

func (*GroupOp) Delete

func (o *GroupOp) Delete(ctx context.Context, id string) error

func (*GroupOp) List

func (*GroupOp) Read

func (*GroupOp) Update

type HistoryAPI

func NewHistoryOp

func NewHistoryOp(client *v1.Client) HistoryAPI

type HistoryOp

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

func (*HistoryOp) List

func (*HistoryOp) Read

type RoutingOp

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

func (*RoutingOp) Delete

func (o *RoutingOp) Delete(ctx context.Context, id string) error

func (*RoutingOp) List

func (*RoutingOp) ListSource

func (o *RoutingOp) ListSource(ctx context.Context) (*v1.ListSourcesResponse, error)

func (*RoutingOp) Read

func (*RoutingOp) Update

Directories

Path Synopsis
apis
v1

Jump to

Keyboard shortcuts

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