示例#1
0
文件: twitter.go 项目: Madrigal/GoUDP
func main() {
	fmt.Println("Hola tuiter")
	client, err := twitterWrapper.NewClient()
	if err != nil {
		log.Println("Twitter creation failed, reason", err)
	}
	fmt.Println(client)
	client.Update("Hola desde mi aplicacion", url.Values{})
}
示例#2
0
文件: GoUDP.go 项目: Madrigal/GoUDP
// handleUserInput dispatches whatever the user writes
func handleUserInput(line string) {
	line = strings.TrimRight(line, "\n")
	arr := strings.Split(line, " ")
	l := arr[0]
	length := len(arr)
	switch {
	case l == "/nick":
		if length <= 1 {
			fmt.Println("Missing arguments")
			return
		}
		nick := arr[1]
		m := message.NewLogin(nick)
		// You can do this but the server will
		// reject you if there is an error
		myAlias = nick
		sendXmlToServer(m)

	case l == "/names":
		m := message.NewUGetConnected()
		sendXmlToServer(m)

	case l == "/msg":
		if length <= 2 {
			fmt.Println("Missing arguments")
			return
		}
		to := arr[1]
		msg := strings.Join(arr[2:length], " ")
		m := message.NewDirectMessage(to, msg)
		sendXmlToServer(m)

	case l == "/send":
		if length <= 2 {
			fmt.Println("Missing arguments")
			return
		}
		to := arr[1]
		filename := arr[2]
		fileSender(to, filename)

	case l == "/block":
		if length <= 1 {
			fmt.Println("Missing arguments")
			return
		}
		who := arr[1]
		m := message.NewBlock(myAlias, who)
		sendXmlToServer(m)

	case l == "/twitter":
		if length < 2 {
			fmt.Println("Missing arguments")
			return
		}
		message := strings.Join(arr[1:length], " ")
		client, err := twitterWrapper.NewClient()
		if err != nil {
			log.Println("Twitter creation failed, reason", err)
		}
		client.Update(message, url.Values{})

	case l == "/quit":
		m := message.NewExit()
		sendXmlToServer(m)

	case l == "/help":
		displayHelpMessage()

	case l == "/admin":
		if length != 2 {
			fmt.Println("Incorrect arguments")
			return
		}
		action := arr[1]
		switch {
		case action == "start":
			s := ServerPetition{GlobalPort}
			startServer <- s
		case action == "stop":
			s := ServerPetition{}
			stopServer <- s
		default:
			fmt.Println("Unkwon admin action")
		}

	default:
		m := message.NewBroadcast(line)
		sendXmlToServer(m)
	}
}