本文整理匯總了Golang中github.com/ovh/tatcli/internal.Client函數的典型用法代碼示例。如果您正苦於以下問題:Golang Client函數的具體用法?Golang Client怎麽用?Golang Client使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Client函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: topicTruncate
func topicTruncate(topic string) {
j := tat.TopicNameJSON{Topic: topic}
if force {
out, err := internal.Client().TopicTruncate(j)
internal.Check(err)
if internal.Verbose {
internal.Print(out)
}
} else {
fmt.Print("Are you really sure ? You will delete all messages even if a user has a message in his tasks. Please enter again topic name to confirm: ")
var confirmTopic string
fmt.Scanln(&confirmTopic)
if confirmTopic == topic {
fmt.Printf("Please enter 'yes' to confirm removing all messages from %s: ", topic)
var confirmYes string
fmt.Scanln(&confirmYes)
if confirmYes == "yes" {
out, err := internal.Client().TopicTruncate(j)
internal.Check(err)
internal.Print(out)
return
}
} else {
fmt.Printf("Error. You enter %s instead of %s\n", confirmTopic, topic)
}
fmt.Println("Nothing done")
}
}
示例2: sendSimpleActionMsg
func (ui *tatui) sendSimpleActionMsg() {
t := strings.TrimSpace(ui.send.Text[1:])
var err error
var msg *tat.MessageJSONOut
switch t {
case "voteup":
msg, err = internal.Client().MessageVoteUP(ui.currentTopic.Topic, ui.currentListMessages[ui.selectedPaneMessages][ui.uilists[uiMessages][ui.selectedPaneMessages].position].ID)
case "votedown":
msg, err = internal.Client().MessageVoteDown(ui.currentTopic.Topic, ui.currentListMessages[ui.selectedPaneMessages][ui.uilists[uiMessages][ui.selectedPaneMessages].position].ID)
case "unvoteup":
msg, err = internal.Client().MessageUnVoteUP(ui.currentTopic.Topic, ui.currentListMessages[ui.selectedPaneMessages][ui.uilists[uiMessages][ui.selectedPaneMessages].position].ID)
case "unvotedown":
msg, err = internal.Client().MessageUnVoteDown(ui.currentTopic.Topic, ui.currentListMessages[ui.selectedPaneMessages][ui.uilists[uiMessages][ui.selectedPaneMessages].position].ID)
case "like":
msg, err = internal.Client().MessageLike(ui.currentTopic.Topic, ui.currentListMessages[ui.selectedPaneMessages][ui.uilists[uiMessages][ui.selectedPaneMessages].position].ID)
case "unlike":
msg, err = internal.Client().MessageUnlike(ui.currentTopic.Topic, ui.currentListMessages[ui.selectedPaneMessages][ui.uilists[uiMessages][ui.selectedPaneMessages].position].ID)
case "task":
msg, err = internal.Client().MessageTask(ui.currentTopic.Topic, ui.currentListMessages[ui.selectedPaneMessages][ui.uilists[uiMessages][ui.selectedPaneMessages].position].ID)
case "untask":
msg, err = internal.Client().MessageUntask(ui.currentTopic.Topic, ui.currentListMessages[ui.selectedPaneMessages][ui.uilists[uiMessages][ui.selectedPaneMessages].position].ID)
}
if err != nil {
ui.msg.Text = err.Error()
} else {
ui.uilists[uiMessages][ui.selectedPaneMessages].list.Items[ui.uilists[uiMessages][ui.selectedPaneMessages].position] = ui.formatMessage(msg.Message, true)
ui.addMarker(ui.uilists[uiMessages][ui.selectedPaneMessages], ui.selectedPaneMessages)
}
if msg.Info != "" {
ui.msg.Text = msg.Info
}
}
示例3: updateTopics
func (ui *tatui) updateTopics() {
start := time.Now().UnixNano()
nbPerPage := ui.getNbPerPage()
c := ui.currentFilterTopics
if c == nil {
c = &tat.TopicCriteria{}
}
if ui.onlyUnread {
c.Skip = 0
c.Limit = 1000
} else {
c.Skip = ui.uilists[uiTopics][0].page * nbPerPage
c.Limit = nbPerPage
}
c.OnlyFavorites = ui.onlyFavorites
c.GetNbMsgUnread = "true"
topicsJSON, err := internal.Client().TopicList(c)
if err != nil {
ui.msg.Text = err.Error()
return
}
var strs []string
topics := []tat.Topic{}
ui.currentListUnreadTopics = topicsJSON.TopicsMsgUnread
privateTasksTopic := fmt.Sprintf("/Private/%s/Tasks", viper.GetString("username"))
for _, topic := range topicsJSON.Topics {
if topic.Topic == privateTasksTopic {
continue
}
topicLine, isUnread := ui.formatTopic(topic, true)
if !ui.onlyUnread || isUnread {
strs = append(strs, topicLine)
topics = append(topics, topic)
}
}
if ui.onlyUnread {
max := nbPerPage - 1
if len(topics) < nbPerPage {
max = len(topics) - 1
}
if ui.uilists[uiTopics][0].page*nbPerPage > len(topics) {
return
}
ui.currentListTopic = topics[ui.uilists[uiTopics][0].page*nbPerPage : max]
ui.uilists[uiTopics][0].list.Items = strs[ui.uilists[uiTopics][0].page*nbPerPage : max]
} else {
ui.currentListTopic = topics
ui.uilists[uiTopics][0].list.Items = strs
}
ui.msg.Text = ""
ui.addMarker(ui.uilists[uiTopics][0], 0)
delta := int64((time.Now().UnixNano() - start) / 1000000)
ui.lastRefresh.Text = fmt.Sprintf("%s (%dms)", time.Now().Format(time.Stamp), delta)
ui.render()
}
示例4: sendMsg
func (ui *tatui) sendMsg() {
if ui.current != uiMessage && ui.current != uiMessages {
return
}
if len(strings.TrimSpace(ui.send.Text)) == 0 {
return
}
var err error
var msg *tat.MessageJSONOut
switch ui.current {
case uiMessages:
msg, err = message.Create(ui.currentTopic.Topic, ui.send.Text)
case uiMessage:
msg, err = internal.Client().MessageReply(ui.currentTopic.Topic, ui.currentMessage.ID, ui.send.Text)
}
if err != nil {
ui.msg.Text = err.Error()
return
}
if msg.Info != "" {
ui.msg.Text = msg.Info
}
ui.send.Text = ""
ui.render()
ui.updateMessages()
}
示例5: updateMessagesPane
func (ui *tatui) updateMessagesPane(pane int, criteria *tat.MessageCriteria) {
// check if ui.uilists[uiMessages] has changed
if pane >= len(ui.uilists[uiMessages]) {
return
}
messagesJSON, err := internal.Client().MessageList(criteria.Topic, criteria)
if err != nil {
ui.msg.Text = err.Error()
return
}
var strs []string
for _, msg := range messagesJSON.Messages {
strs = append(strs, ui.formatMessage(msg, true))
}
ui.uilists[uiMessages][pane].list.Items = strs
ui.currentListMessages[pane] = messagesJSON.Messages
ui.msg.Text = ""
if ui.selectedPaneMessages == pane {
ui.addMarker(ui.uilists[uiMessages][pane], pane)
}
ui.render()
}
示例6: updateMessage
func (ui *tatui) updateMessage() {
start := time.Now().UnixNano()
c := &tat.MessageCriteria{
IDMessage: ui.currentMessage.ID,
Topic: ui.currentTopic.Topic,
TreeView: "onetree",
}
messagesJSON, err := internal.Client().MessageList(ui.currentTopic.Topic, c)
if err != nil {
ui.msg.Text = err.Error()
ui.render()
return
}
thread := []string{}
for _, msg := range messagesJSON.Messages {
thread = ui.addMessage(msg, 0)
}
ui.uilists[uiMessage][0].list.Items = thread
ui.uilists[uiMessage][0].list.BorderLabel = " View Message, Ctrl+b to return back "
delta := int64((time.Now().UnixNano() - start) / 1000000)
ui.lastRefresh.Text = fmt.Sprintf("%s (%dms)", time.Now().Format(time.Stamp), delta)
ui.msg.Text = ""
}
示例7: removeLabel
func (ui *tatui) removeLabel(msg tat.Message, label string) error {
var err error
if label == "doing" && msg.ContainsLabel("doing") {
internal.Client().MessageUntask(msg.Topic, msg.ID)
} else {
internal.Client().MessageUnlabel(msg.Topic, msg.ID, label)
if label == "done" {
for _, l := range msg.Labels {
if strings.HasPrefix(l.Text, "done:") {
internal.Client().MessageUnlabel(msg.Topic, msg.ID, l.Text)
}
}
}
}
return err
}
示例8: monitoringActionOnMessage
func (ui *tatui) monitoringActionOnMessage() {
if _, ok := ui.uilists[uiMessages][ui.selectedPaneMessages]; !ok {
return
}
if ui.uilists[uiMessages][ui.selectedPaneMessages].position >= len(ui.currentListMessages[ui.selectedPaneMessages]) {
return
}
msg := ui.currentListMessages[ui.selectedPaneMessages][ui.uilists[uiMessages][ui.selectedPaneMessages].position]
var erradd, errdel error
// #d04437 red open
// #14892c green done
// #5484ed blue doing
// TODO use relabel
if msg.ContainsLabel("AL") {
// set to doing
if !msg.ContainsLabel("UP") {
_, erradd = internal.Client().MessageLabel(msg.Topic, msg.ID, tat.Label{Text: "UP", Color: hexColorGreen})
}
_, errdel = internal.Client().MessageUnlabel(msg.Topic, msg.ID, "AL")
} else {
// set to AL
if !msg.ContainsLabel("AL") {
_, erradd = internal.Client().MessageLabel(msg.Topic, msg.ID, tat.Label{Text: "AL", Color: hexColorRed})
}
if msg.ContainsLabel("UP") {
_, errdel = internal.Client().MessageUnlabel(msg.Topic, msg.ID, "UP")
}
}
ui.msg.Text = ""
if erradd != nil {
ui.msg.Text += "add:" + erradd.Error()
}
if errdel != nil {
ui.msg.Text += " del:" + errdel.Error()
return
}
msg.Text = "please wait, updating message..."
ui.render()
ui.updateMessages()
}
示例9: topicAddParameter
func topicAddParameter(topic string, parameters []string) {
for _, param := range parameters {
parameterSplitted := strings.Split(param, ":")
if len(parameterSplitted) != 2 {
continue
}
_, err := internal.Client().TopicAddParameter(topic, parameterSplitted[0], parameterSplitted[1], recursive)
internal.Check(err)
}
}
示例10: showVersion
func (ui *tatui) showVersion() {
ui.msg.Text = ""
//body, err := internal.Request("GET", http.StatusOK, "/version", nil)
body, err := internal.Client().Version()
if err != nil {
ui.msg.Text = err.Error()
return
}
ui.showResult("tatcli version -> GET on "+viper.GetString("url")+"/version ", string(body))
ui.msg.Text = "Tatcli:" + internal.VERSION
}
示例11: sendUnlabel
func (ui *tatui) sendUnlabel() {
if len(strings.TrimSpace(ui.send.Text)) == 0 {
return
}
// "/unlabel " : 8 char
labelToRemove := strings.TrimSpace(ui.send.Text[8:])
msg, err := internal.Client().MessageUnlabel(ui.currentTopic.Topic, ui.currentListMessages[ui.selectedPaneMessages][ui.uilists[uiMessages][ui.selectedPaneMessages].position].ID, labelToRemove)
if err != nil {
ui.msg.Text = err.Error()
}
if msg.Info != "" {
ui.msg.Text = msg.Info
}
}
示例12: Create
// Create creates a message in specified topic
func Create(topic, message string) (*tat.MessageJSONOut, error) {
m := tat.MessageJSON{Text: message, Topic: topic}
if dateCreation > 0 {
m.DateCreation = float64(dateCreation)
}
for _, label := range cmdLabel {
s := strings.Split(label, ";")
if len(s) == 2 {
m.Labels = append(m.Labels, tat.Label{Text: s[1], Color: s[0]})
} else {
return nil, fmt.Errorf("Invalid argument label %s to add a message: tatcli msg add --help\n", label)
}
}
return internal.Client().MessageAdd(m)
}
示例13: showMe
func (ui *tatui) showMe() {
ui.msg.Text = ""
//body, err := internal.Request("GET", http.StatusOK, "/user/me", nil)
body, err := internal.Client().UserMe()
if err != nil {
ui.msg.Text = err.Error()
return
}
out, err := tat.Sprint(body)
if err != nil {
ui.msg.Text = err.Error()
return
}
ui.showResult("tatcli user me -> GET on /user/me ", string(out))
}
示例14: loadArgs
// loadArgs load args form command line and return topic, filter, command
func (ui *tatui) loadArgs(args []string) []string {
// example :
// /YourTopic/SubTopic /split label:open label:doing label:done /save
// /YourTopic/SubTopic /run CD
// /YourTopic/SubTopic /run CD /save
// /YourTopic/SubTopic /monitoring /save
if len(args) < 1 {
return []string{}
}
topicName := ""
if strings.HasPrefix(args[0], "/") {
topicName = args[0]
}
c := &tat.TopicCriteria{Topic: strings.TrimSpace(topicName)}
//topicsB, err := internal.Request("GET", 200, topic.TopicsListURL(c), nil)
topicsJSON, err := internal.Client().TopicList(c)
if err != nil {
internal.Exit("Error while loading topic %s error:%s", args[0], err.Error())
}
if len(topicsJSON.Topics) != 1 {
internal.Exit("Args on tatcli ui should begin with topic name. Please check it on %s", args[0])
}
ui.currentTopic = topicsJSON.Topics[0]
commands := []string{}
cmd := ""
for i := 1; i < len(args); i++ {
if strings.HasPrefix(args[i], "/") {
if cmd != "" {
commands = append(commands, cmd)
}
cmd = args[i]
} else {
cmd += " " + args[i]
}
}
if cmd != "" {
commands = append(commands, cmd)
}
return commands
}
示例15: userVerify
func userVerify(username, tokenVerify string) {
verifyJSON, err := internal.Client().UserVerify(username, tokenVerify)
internal.Check(err)
// Display return to user (contains clear password)
internal.Print(verifyJSON)
if save && verifyJSON.Password != "" && verifyJSON.Username != "" && verifyJSON.URL != "" {
verifyJSON.Message = ""
jsonStr, err := json.MarshalIndent(verifyJSON, "", " ")
internal.Check(err)
jsonStr = append(jsonStr, '\n')
filename := internal.ConfigFile
dir := path.Dir(filename)
if _, err := os.Stat(dir); os.IsNotExist(err) {
internal.Check(os.Mkdir(dir, 0740))
}
internal.Check(ioutil.WriteFile(filename, jsonStr, 0600))
}
}