events

package
v0.2.4-r12 Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2023 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Copyright © 2021-2022 Nikita Ivanovski info@slnt-opp.xyz

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.

Copyright © 2021-2022 Nikita Ivanovski info@slnt-opp.xyz

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.

Copyright © 2021-2022 Nikita Ivanovski info@slnt-opp.xyz

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.

Copyright © 2021-2022 Nikita Ivanovski info@slnt-opp.xyz

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.

Copyright © 2021-2022 Nikita Ivanovski info@slnt-opp.xyz

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

This section is empty.

Variables

View Source
var CancelCmd = &cobra.Command{
	Use:     "cancel [[flags]]",
	Aliases: []string{"canc", "abort", "remove", "purge"},
	Short:   "Cance Event from Event Bus",
	Args:    cobra.ExactArgs(0),
	RunE: func(cmd *cobra.Command, args []string) error {
		ctx, client := MakeEventsServiceClientOrFail()

		req := &pb.CancelRequest{}

		t, err := cmd.Flags().GetString("type")
		if err != nil {
			return err
		} else {
			req.Type = t
		}

		uuid, err := cmd.Flags().GetString("uuid")
		if err != nil {
			return err
		} else {
			req.Uuid = uuid
		}

		id, err := cmd.Flags().GetString("id")
		if err != nil {
			return err
		} else {
			req.Id = id
		}

		if _, err := client.Cancel(ctx, req); err != nil {
			return err
		}

		fmt.Println("Successfully removed event from the event bus.")

		return nil
	},
}

GetCmd represents the list command

View Source
var ListCmd = &cobra.Command{
	Use:     "list [[flags]]",
	Aliases: []string{"ls", "list"},
	Short:   "List Events",
	Args:    cobra.ExactArgs(0),
	RunE: func(cmd *cobra.Command, args []string) error {
		ctx, client := MakeEventsServiceClientOrFail()

		req := &pb.ConsumeRequest{}

		t, err := cmd.Flags().GetString("type")
		if err != nil {
			return err
		} else {
			req.Type = t
		}

		uuid, err := cmd.Flags().GetString("uuid")
		if err != nil {
			return err
		} else {
			req.Uuid = uuid
		}

		events, err := client.List(ctx, req)
		if err != nil {
			return err
		}

		for _, event := range events.Events {
			fmt.Printf("%v\n", event)
		}

		return nil
	},
}

GetCmd represents the list command

View Source
var PubCmd = &cobra.Command{
	Use:     "pub [template] [[flags]]",
	Aliases: []string{"publish", "send"},
	Short:   "Publishes Event",
	Args:    cobra.ExactArgs(1),
	RunE: func(cmd *cobra.Command, args []string) error {
		ctx, client := MakeEventsServiceClientOrFail()

		var format string
		{
			pathSlice := strings.Split(args[0], ".")
			format = pathSlice[len(pathSlice)-1]
		}

		template, err := os.ReadFile(args[0])
		if err != nil {
			fmt.Println("Error reading template file")
			return err
		}

		switch format {
		case "json":
		case "yml", "yaml":
			template, err = yaml.YAMLToJSON(template)
			if err != nil {
				return err
			}
		default:
			return errors.New("Unsupported template format " + format)
		}

		event := &pb.Event{}
		err = json.Unmarshal(template, &event)
		if err != nil {
			return err
		}

		t, err := cmd.Flags().GetString("type")
		if err != nil {
			return err
		} else {
			event.Type = t
		}

		uuid, err := cmd.Flags().GetString("uuid")
		if err != nil {
			return err
		} else {
			event.Uuid = uuid
		}

		response, err := client.Publish(ctx, event)
		if err != nil {
			return err
		}

		ok, err := tools.PrintJsonDataQ(cmd, response)
		if err != nil {
			return err
		}
		if !ok {
			fmt.Println("Successfully sent event")
		}

		return nil
	},
}

GetCmd represents the list command

View Source
var SubCmd = &cobra.Command{
	Use:     "sub [[flags]]",
	Aliases: []string{"subscribe", "consume"},
	Short:   "Consume Events",
	Args:    cobra.ExactArgs(0),
	RunE: func(cmd *cobra.Command, args []string) error {
		ctx, client := MakeEventsServiceClientOrFail()

		req := &pb.ConsumeRequest{}

		t, err := cmd.Flags().GetString("type")
		if err != nil {
			return err
		} else {
			req.Type = t
		}

		uuid, err := cmd.Flags().GetString("uuid")
		if err != nil {
			return err
		} else {
			req.Uuid = uuid
		}

		stream, err := client.Consume(ctx, req)
		if err != nil {
			return err
		}

		for {
			msg, err := stream.Recv()
			if err != nil {
				return err
			}

			ok, err := tools.PrintJsonDataQ(cmd, msg)
			if err != nil {
				return err
			}
			if !ok {
				fmt.Println(msg)
			}
		}
	},
}

GetCmd represents the list command

Functions

func MakeEventsServiceClientOrFail

func MakeEventsServiceClientOrFail() (context.Context, pb.EventsServiceClient)

Types

This section is empty.

Jump to

Keyboard shortcuts

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