Created
March 7, 2026 06:56
-
-
Save Hakkadaikon/7ec61f77f32961e8c405a63150d0cc5d to your computer and use it in GitHub Desktop.
mixi2 post - golang
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "context" | |
| "crypto/tls" | |
| "log" | |
| "github.com/mixigroup/mixi2-application-sample-go/config" | |
| "github.com/mixigroup/mixi2-application-sdk-go/auth" | |
| constv1 "github.com/mixigroup/mixi2-application-sdk-go/gen/go/social/mixi/application/const/v1" | |
| application_apiv1 "github.com/mixigroup/mixi2-application-sdk-go/gen/go/social/mixi/application/service/application_api/v1" | |
| "google.golang.org/grpc" | |
| "google.golang.org/grpc/credentials" | |
| ) | |
| func main() { | |
| cfg := config.GetConfig() | |
| // Create authenticator | |
| authenticator, _ := auth.NewAuthenticator( | |
| cfg.ClientID, | |
| cfg.ClientSecret, | |
| cfg.TokenURL, | |
| ) | |
| // Create gRPC connection for API | |
| apiConn, _ := grpc.NewClient( | |
| cfg.APIAddress, | |
| grpc.WithTransportCredentials(credentials.NewTLS(&tls.Config{})), | |
| ) | |
| defer apiConn.Close() | |
| // Create API client | |
| apiClient := application_apiv1.NewApplicationServiceClient(apiConn) | |
| // Setup graceful shutdown | |
| ctx, cancel := context.WithCancel(context.Background()) | |
| defer cancel() | |
| authCtx, _ := authenticator.AuthorizedContext(ctx) | |
| resp, _ := apiClient.CreatePost(authCtx, &application_apiv1.CreatePostRequest{ | |
| Text: "ひっひっひ。", | |
| PublishingType: constv1.PostPublishingType_POST_PUBLISHING_TYPE_NOT_PUBLISHING.Enum(), | |
| }) | |
| log.Print(resp.String()) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment