Skip to content

Commit

Permalink
feat: Implement loader things
Browse files Browse the repository at this point in the history
  • Loading branch information
h0n9 committed Sep 25, 2024
1 parent 9f1d192 commit 7ebea52
Showing 1 changed file with 43 additions and 3 deletions.
46 changes: 43 additions & 3 deletions cli/tools/loader/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (

"github.com/spf13/cobra"

"github.com/postie-labs/go-postie-lib/crypto"

"github.com/h0n9/msg-lake/client"
)

Expand All @@ -27,8 +29,8 @@ var (
topicID string
nickname string

intervalStr string // "1s"
loadCount int // 0 means unlimited
interval time.Duration
loadCount int // 0 means unlimited
)

func runE(cmd *cobra.Command, args []string) error {
Expand Down Expand Up @@ -63,6 +65,44 @@ func runE(cmd *cobra.Command, args []string) error {
}
}()

/////////////////////////////////
// real things begin from here //
/////////////////////////////////

// init privKey
privKey, err := crypto.GenPrivKeyFromSeed([]byte(nickname))
if err != nil {
return err
}
// pubKeyBytes := privKey.PubKey().Bytes()

// init msg lake client
msgLakeClient, err = client.NewClient(privKey, hostAddr, tlsEnabled)
if err != nil {
return err
}

wg.Add(1)
go func() {
defer wg.Done()

// init ticker with interval
ticker := time.NewTicker(interval)
defer ticker.Stop()

i := 0

for {
select {
case <-ctx.Done():
return
case <-ticker.C:
fmt.Println(i)
i += 1
}
}
}()

wg.Wait()

return nil
Expand All @@ -76,6 +116,6 @@ func init() {
Cmd.Flags().StringVar(&topicID, "topic", "life is beautiful", "topic id")
Cmd.Flags().StringVarP(&nickname, "nickname", "n", fmt.Sprintf("alien-%d", r), "consumer id")

Cmd.Flags().StringVar(&intervalStr, "interval", "1s", "interval")
Cmd.Flags().DurationVar(&interval, "interval", 1*time.Second, "interval")
Cmd.Flags().IntVarP(&loadCount, "count", "c", 100, "load count")
}

0 comments on commit 7ebea52

Please sign in to comment.