github.com/masterhung0112/hk_server/v5@v5.0.0-20220302090640-ec71aef15e1c/app/plugin_api_tests/manual.test_load_configuration_plugin/main.go (about)

     1  // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
     2  // See LICENSE.txt for license information.
     3  
     4  package main
     5  
     6  import (
     7  	"fmt"
     8  
     9  	"github.com/masterhung0112/hk_server/v5/app/plugin_api_tests"
    10  	"github.com/masterhung0112/hk_server/v5/model"
    11  	"github.com/masterhung0112/hk_server/v5/plugin"
    12  )
    13  
    14  type configuration struct {
    15  	plugin_api_tests.BasicConfig
    16  
    17  	MyStringSetting string
    18  	MyIntSetting    int
    19  	MyBoolSetting   bool
    20  }
    21  
    22  type MyPlugin struct {
    23  	plugin.MattermostPlugin
    24  
    25  	configuration configuration
    26  }
    27  
    28  func (p *MyPlugin) OnConfigurationChange() error {
    29  	if err := p.API.LoadPluginConfiguration(&p.configuration); err != nil {
    30  		return err
    31  	}
    32  
    33  	return nil
    34  }
    35  
    36  func (p *MyPlugin) MessageWillBePosted(_ *plugin.Context, _ *model.Post) (*model.Post, string) {
    37  	if p.configuration.MyStringSetting != "str" {
    38  		return nil, "MyStringSetting has invalid value"
    39  	}
    40  	if p.configuration.MyIntSetting != 32 {
    41  		return nil, fmt.Sprintf("MyIntSetting has invalid value %v != %v", p.configuration.MyIntSetting, 32)
    42  	}
    43  	if !p.configuration.MyBoolSetting {
    44  		return nil, "MyBoolSetting has invalid value"
    45  	}
    46  	return nil, "OK"
    47  }
    48  
    49  func main() {
    50  	plugin.ClientMain(&MyPlugin{})
    51  }