mirror of
				https://github.com/matrix-org/gomatrix
				synced 2025-11-03 22:08:04 +00:00 
			
		
		
		
	Test example file
This commit is contained in:
		
							parent
							
								
									9c35a1edb8
								
							
						
					
					
						commit
						76fa23b9a4
					
				
					 2 changed files with 17 additions and 12 deletions
				
			
		
							
								
								
									
										12
									
								
								client.go
									
										
									
									
									
								
							
							
						
						
									
										12
									
								
								client.go
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -1,18 +1,6 @@
 | 
			
		|||
// Package gomatrix implements the Matrix Client-Server API.
 | 
			
		||||
//
 | 
			
		||||
// Specification can be found at http://matrix.org/docs/spec/client_server/r0.2.0.html
 | 
			
		||||
//
 | 
			
		||||
// Example usage of this library: (blocking version)
 | 
			
		||||
// 	cli, _ := gomatrix.NewClient("https://matrix.org", "@example:matrix.org", "MDAefhiuwehfuiwe")
 | 
			
		||||
//	syncer := cli.Syncer.(*gomatrix.DefaultSyncer)
 | 
			
		||||
//	syncer.OnEventType("m.room.message", func(ev *gomatrix.Event) {
 | 
			
		||||
//		fmt.Println("Message: ", ev)
 | 
			
		||||
//	})
 | 
			
		||||
//	if err := cli.Sync(); err != nil {
 | 
			
		||||
//		fmt.Println("Sync() returned ", err)
 | 
			
		||||
//	}
 | 
			
		||||
//
 | 
			
		||||
// To make the example non-blocking, call Sync() in a goroutine.
 | 
			
		||||
package gomatrix
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										17
									
								
								example_test.go
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								example_test.go
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,17 @@
 | 
			
		|||
package gomatrix
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"fmt"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func Example() {
 | 
			
		||||
	cli, _ := NewClient("https://matrix.org", "@example:matrix.org", "MDAefhiuwehfuiwe")
 | 
			
		||||
	syncer := cli.Syncer.(*DefaultSyncer)
 | 
			
		||||
	syncer.OnEventType("m.room.message", func(ev *Event) {
 | 
			
		||||
		fmt.Println("Message: ", ev)
 | 
			
		||||
	})
 | 
			
		||||
	// To make the example non-blocking, call Sync() in a goroutine.
 | 
			
		||||
	if err := cli.Sync(); err != nil {
 | 
			
		||||
		fmt.Println("Sync() returned ", err)
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue